You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
information-system/application/controllers/info_amp.php

413 lines
16 KiB
PHTML

7 years ago
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Info_amp extends CI_Controller
{
function __construct()
{
parent::__construct();
//$this->permission->is_admin();
$this->load->model('InfoMetas_model');
$this->load->model('InfoContents_model');
7 years ago
$this->load->model('Information_model');
7 years ago
$this->site_code = $this->config->item('site_code');
7 years ago
//CORS
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS');
header('Access-Control-Allow-Headers:Content-Type,Authorization,Content-Length,X-Requested-With,Accept,x-csrf-token,origin');
7 years ago
}
public function save_amp()
{
7 years ago
$icid = $this->input->get_post('icid');
$json = $this->input->get_post('json');
$html = $this->input->get_post('html');
$pc_html = $this->input->get_post('pc_html');
$pc_css = $this->input->get_post('pc_css');
7 years ago
$css = $this->input->get_post('css');
$schema = $this->input->get_post('schema');
$script = $this->input->get_post('script');
$status = $this->input->get_post('status');
7 years ago
//如果源信息的内容为空,则插入内容。
$info = $this->InfoContents_model->get_ic_contents2($icid);
if ($info && empty($info->ic_content)) {
7 years ago
$this->InfoContents_model->force_update($icid, '<style>'.$pc_css.'</style>'.$pc_html);
7 years ago
}
7 years ago
if ($icid && $json && $html) {
try {
//html
7 years ago
$meta = $this->InfoMetas_model->get($icid, 'AMP_BODY');
if ($meta === FALSE) {
7 years ago
$this->InfoMetas_model->add($icid, 'AMP_BODY', $html);
} else {
$this->InfoMetas_model->update($icid, 'AMP_BODY', $html);
}
//pc_html
$meta = $this->InfoMetas_model->get($icid, 'AMP_BODY_PC');
if ($meta === FALSE) {
$this->InfoMetas_model->add($icid, 'AMP_BODY_PC', $pc_html);
} else {
$this->InfoMetas_model->update($icid, 'AMP_BODY_PC', $pc_html);
}
//pc_css
$meta = $this->InfoMetas_model->get($icid, 'AMP_CSS_PC');
if ($meta === FALSE) {
$this->InfoMetas_model->add($icid, 'AMP_CSS_PC', $pc_css);
} else {
$this->InfoMetas_model->update($icid, 'AMP_CSS_PC', $pc_css);
}
7 years ago
//json
7 years ago
$meta = $this->InfoMetas_model->get($icid, 'AMP_JSON');
if ($meta === FALSE) {
7 years ago
$this->InfoMetas_model->add($icid, 'AMP_JSON', $json);
} else {
$this->InfoMetas_model->update($icid, 'AMP_JSON', $json);
}
//css
7 years ago
$meta = $this->InfoMetas_model->get($icid, 'AMP_CSS');
if ($meta === FALSE) {
7 years ago
$this->InfoMetas_model->add($icid, 'AMP_CSS', $css);
} else {
$this->InfoMetas_model->update($icid, 'AMP_CSS', $css);
}
//script
7 years ago
$meta = $this->InfoMetas_model->get($icid, 'AMP_SCRIPT');
if ($meta === FALSE) {
7 years ago
$this->InfoMetas_model->add($icid, 'AMP_SCRIPT', $script);
} else {
$this->InfoMetas_model->update($icid, 'AMP_SCRIPT', $script);
}
//schema
7 years ago
$meta = $this->InfoMetas_model->get($icid, 'AMP_SCHEMA');
if ($meta === FALSE) {
7 years ago
$this->InfoMetas_model->add($icid, 'AMP_SCHEMA', $schema);
} else {
$this->InfoMetas_model->update($icid, 'AMP_SCHEMA', $schema);
}
//status
7 years ago
$meta = $this->InfoMetas_model->get($icid, 'AMP_STATUS');
if ($meta === FALSE) {
7 years ago
$this->InfoMetas_model->add($icid, 'AMP_STATUS', $status);
} else {
$this->InfoMetas_model->update($icid, 'AMP_STATUS', $status);
}
echo json_encode(array(
"succ" => true
));
} catch(Exception $e) {
echo json_encode(array(
"succ" => false,
"message" => "save_amp() -> ".$e->getMessage()
));
}
} else {
echo json_encode(array(
"succ" => false,
"message" => "save_amp() -> 参数传递错误。"
));
}
}
public function load_amp()
{
7 years ago
$icid = $this->input->get_post('icid');
7 years ago
if (!$icid) {
echo json_encode(array(
"succ" => false,
"message" => "load_amp() -> 参数传递错误。"
));
return false;
}
7 years ago
//信息~返回信息
7 years ago
$ic = $this->InfoContents_model->get_ic_contents2($icid);
if (empty($ic)) {
echo json_encode(array(
"succ" => false,
"message" => "load_amp() -> 无信息"
));
return false;
}
7 years ago
switch (strtolower($ic->ic_sitecode)) {
7 years ago
case 'vac':
$site = 'https://www.viaje-a-china.com';
break;
case 'vc':
$site = 'https://www.voyageschine.com';
break;
case 'jp':
$site = 'https://www.arachina.com';
break;
case 'ru':
$site = 'https://www.chinahighlights.ru';
break;
case 'it':
$site = 'https://www.viaggio-in-cina.it';
break;
case 'cht':
$site = 'https://www.chinahighlights.com';
break;
case 'gm':
$site = 'https://www.chinarundreisen.com/';
break;
default:
$site = '';
break;
}
7 years ago
$json = $this->InfoMetas_model->get($icid, 'AMP_JSON');
$status = $this->InfoMetas_model->get($icid, 'AMP_STATUS');
$schema = $this->InfoMetas_model->get($icid, 'AMP_SCHEMA');
7 years ago
if ($json) {
echo json_encode(array(
"succ" => true,
"icid" => $icid,
7 years ago
"icurl" => $site.$ic->ic_url,
7 years ago
"json" => $json,
"schema" => $schema,
"status" => $status
));
} else {
echo json_encode(array(
"succ" => false,
"message" => "load_amp() -> 无数据返回。"
));
}
}
7 years ago
public function list_amp()
{
$site = $this->input->get_post('site');
switch ($site) {
case 'https://www.viaje-a-china.com':
$site_code = 'vac';
break;
case 'https://www.voyageschine.com':
$site_code = 'vc';
break;
case 'https://www.arachina.com':
$site_code = 'jp';
break;
case 'https://www.chinahighlights.ru':
$site_code = 'ru';
break;
7 years ago
case 'https://www.viaggio-in-cina.it':
7 years ago
$site_code = 'it';
break;
case 'https://www.chinahighlights.com':
$site_code = 'cht';
break;
case 'https://www.chinarundreisen.com/':
$site_code = 'gm';
break;
default:
$site_code = false;
break;
}
if (!$site_code) {
echo json_encode(array(
"succ" => false,
"message" => "list_amp() -> 参数传递错误。"
));
return false;
}
7 years ago
$rs = $this->InfoMetas_model->list_amp($site_code);
7 years ago
if (!empty($rs)) {
echo json_encode($rs);
} else {
echo json_encode(array(
"succ" => false,
"message" => "load_amp() -> 无数据返回。"
7 years ago
));
}
}
public function list_info_children()
{
$site = $this->input->get_post('site');
switch ($site) {
case 'https://www.viaje-a-china.com':
$site_code = 'vac';
break;
case 'https://www.voyageschine.com':
$site_code = 'vc';
break;
case 'https://www.arachina.com':
$site_code = 'jp';
break;
case 'https://www.chinahighlights.ru':
$site_code = 'ru';
break;
case 'https://www.viaggio-in-cina.it':
$site_code = 'it';
break;
case 'https://www.chinahighlights.com':
$site_code = 'cht';
break;
case 'https://www.chinarundreisen.com/':
$site_code = 'gm';
break;
default:
$site_code = false;
break;
}
$is_path = $this->input->get_post('is_path'); // '25693,278002094,'
if (!$site_code || !$is_path) {
echo json_encode(array(
'succ' => false,
'message' => 'list_info_children() -> 参数传递错误。'
));
return false;
}
7 years ago
$rs = $this->InfoMetas_model->list_info_by_path_with_meta($is_path, $site_code);
7 years ago
if (!empty($rs)) {
$newrs = array();
foreach ($rs as $info) {
7 years ago
$show_photo_meta = $this->InfoMetas_model->get($info->ic_id, 'meta_use_list_picture');
if ($show_photo_meta == 'no') {
$use_photo = '';
} else {
7 years ago
$use_photo = $this->config->item('site_image_url').$info->ic_photo;
7 years ago
}
7 years ago
if ($info->ic_type === 'c_attraction' || $info->ic_template === 'city_info_attractions_list' || $info->ic_template === 'r_tpl_empty_navi1p') {
7 years ago
$list_info = true;
} else {
$list_info = false;
}
if ($list_info || !empty($info->ic_content) && !empty($info->ic_url) && stripos($info->ic_url, '/test/')===false) {
array_push($newrs, array(
7 years ago
'is_path' => $info->is_path,
'ic_url' => $info->ic_url,
'ic_id' => $info->ic_id,
'title' => $info->ic_title,
7 years ago
'photo' => $use_photo,
7 years ago
'im_id' => $info->im_id
));
}
7 years ago
}
echo json_encode($newrs);
} else {
echo json_encode(array(
"succ" => false,
"message" => "list_info_children() -> 无数据返回。"
7 years ago
));
}
}
7 years ago
public function load_info()
{
7 years ago
$icid = $this->input->get_post('icid');
7 years ago
if ($icid) {
$ic = $this->InfoContents_model->get_ic_contents2($icid);
if ($ic) {
7 years ago
$show_photo_meta = $this->InfoMetas_model->get($icid, 'meta_use_list_picture');
7 years ago
if ($show_photo_meta == 'no') {
7 years ago
$use_photo = '';
} else {
$use_photo = $this->config->item('site_image_url').$ic->ic_photo;
}
7 years ago
echo json_encode(array(
"succ" => true,
7 years ago
"info" => $ic->ic_content ? $ic->ic_content : "<p>".$ic->ic_seo_description."</p>",
7 years ago
"title" => $ic->ic_title,
7 years ago
"photo" => $use_photo,
7 years ago
"url" => $ic->ic_url,
"site" => $this->config->item('site_url')
7 years ago
));
} else {
echo json_encode(array(
"succ" => false,
"message" => "load_info() -> 无数据返回。"
));
}
} else {
echo json_encode(array(
"succ" => false,
"message" => "load_info() -> 参数传递错误。"
));
}
}
7 years ago
public function handel_png_source() {
$png_base64 = $this->input->post('png_base64');
//$png_base64 = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABlBMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDrEX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$file = md5($png_base64).'.jpg';
7 years ago
$path = realpath('../cht-system/views/information/word_img').'/'.$file;
7 years ago
$png_base64 = str_replace('data:image/png;base64,', '', $png_base64);
$png_base64 = str_replace('data:image/jpg;base64,', '', $png_base64);
$png_base64 = base64_decode($png_base64);
$im = imagecreatefromstring($png_base64);
//保存图像
imagejpeg($im, $path);
//释放内存
imagedestroy($im);
$size = getimagesize($path);
7 years ago
if($png_base64 && $size) {
7 years ago
echo(json_encode(array(
'status' => 'success',
7 years ago
'path' => '/information-view/information/word_img/'.$file,
7 years ago
'width' => $size[0],
'height' => $size[1]
)));
} else {
echo(json_encode(array(
7 years ago
'status' => 'error'
7 years ago
)));
}
}
7 years ago
public function handel_word_source() {
$file = $_FILES['file'];
if (!$file) {
echo(json_encode(array(
'status' => 'error',
'msg' => "文件上传失败。"
)));
return;
}
7 years ago
//转移文件
$md5_file = md5($file['name'].$file['size']);
//ext
$ext = mb_strtolower(strrchr($file["name"],'.'));
if ($ext != '.docx') {
echo(json_encode(array(
'status' => 'error',
'msg' => '只能接收word(.docx)文档。'
)));
return;
}
$md5_name = $md5_file.$ext;
7 years ago
$path = realpath('../cht-system/views/information/word_source').'/'.basename($md5_name);
7 years ago
$html = realpath(APPPATH.'/libraries/composer/vendor/');
7 years ago
if (move_uploaded_file($file['tmp_name'], $path)) {
$this->load->library('wordphp');
$rt = new WordPHP();
$rt->img_dir = realpath('../cht-system/views/information/word_img');
$rt->img_prex = $md5_file;
$html = $rt->readDocument($path);
$html = str_ireplace($rt->img_dir, '//202.103.68.62:9096/information-view/information/word_img', $html);
7 years ago
/*//phpWord转HTML
require_once($html.'/autoload.php');
$phpWord = \PhpOffice\PhpWord\IOFactory::load($path);
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, "HTML");
$xmlWriter->save($path.'.html');
*/
7 years ago
echo(json_encode(array(
'status' => 'success',
'path' => $path,
'html' => $html
7 years ago
)));
} else {
echo(json_encode(array(
'status' => 'error',
'msg' => "word文件解析失败。"
7 years ago
)));
}
}
7 years ago
7 years ago
}