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

569 lines
21 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');
$this->load->model('Logs_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');
3 years ago
$schema = $this->input->get_post('schema');
7 years ago
$script = $this->input->get_post('script');
$status = $this->input->get_post('status');
7 years ago
//如果源信息的内容为空,则插入内容。
/*
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
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);
}
$this->Logs_model->backup_meta($icid, $json, 'AMP_JSON');
7 years ago
//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);
}
3 years ago
//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
));
3 years ago
} catch (Exception $e) {
7 years ago
echo json_encode(array(
"succ" => false,
3 years ago
"message" => "save_amp() -> " . $e->getMessage()
7 years ago
));
}
} 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;
}
3 years ago
7 years ago
$json = $this->InfoMetas_model->get($icid, 'AMP_JSON');
$status = $this->InfoMetas_model->get($icid, 'AMP_STATUS');
3 years ago
$schema = $this->InfoMetas_model->get($icid, 'AMP_SCHEMA');
7 years ago
if ($json) {
echo json_encode(array(
"succ" => true,
"icid" => $icid,
3 years ago
"icurl" => $site . $ic->ic_url,
7 years ago
"json" => $json,
3 years ago
"schema" => $schema,
7 years ago
"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 {
3 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;
}
3 years ago
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 {
3 years ago
$use_photo = $this->config->item('site_image_url') . $ic->ic_photo;
7 years ago
}
7 years ago
echo json_encode(array(
"succ" => true,
3 years ago
"info" => $ic->ic_content ? $ic->ic_content : "<p>" . $ic->ic_seo_description . "</p>",
"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
3 years ago
public function handel_png_source()
{
//ini_set('memory_limit', '50M');
7 years ago
$png_base64 = $this->input->post('png_base64');
//$png_base64 = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABlBMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDrEX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
3 years ago
$file = md5($png_base64) . '.jpg';
$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);
3 years ago
if ($png_base64 && $size) {
echo (json_encode(array(
7 years ago
'status' => 'success',
3 years ago
'path' => '/information-view/information/word_img/' . $file,
7 years ago
'width' => $size[0],
'height' => $size[1]
)));
} else {
3 years ago
echo (json_encode(array(
7 years ago
'status' => 'error'
7 years ago
)));
}
}
7 years ago
3 years ago
public function handel_image_source()
{
@ini_set('memory_limit', '256M');
$file = $_FILES['file'];
if (!$file) {
3 years ago
echo (json_encode(array(
'status' => 'error',
'msg' => "图片上传失败。"
)));
return;
}
$usr = $this->input->post('usr');
$icid = $this->input->post('icid');
//转移文件
3 years ago
$md5_file = md5($usr . $icid . $file['name']);
//ext
3 years ago
$ext = mb_strtolower(strrchr($file["name"], '.'));
if ($ext != '.jpg') {
3 years ago
echo (json_encode(array(
'status' => 'error',
'msg' => '只能接收(.jpg)图片。',
'filename' => $file["name"]
)));
return;
}
3 years ago
$md5_name = $md5_file . $ext;
//临时docx文件
3 years ago
$image_path = realpath('../cht-system/views/information/word_img') . '/' . basename($md5_name);
$html = 'to use mammoth';
if (move_uploaded_file($file['tmp_name'], $image_path)) {
//图片处理
$im = imagecreatefromjpeg($image_path);
imagejpeg($im, $image_path);
imagedestroy($im);
$size = getimagesize($image_path);
3 years ago
if ($size) {
echo (json_encode(array(
'status' => 'success',
3 years ago
'path' => '/information-view/information/word_img/' . $md5_name,
'width' => $size[0],
'height' => $size[1]
)));
} else {
3 years ago
echo (json_encode(array(
'status' => 'error'
)));
}
} else {
3 years ago
echo (json_encode(array(
'status' => 'error',
'msg' => "图片文件解析失败。"
)));
}
}
3 years ago
public function handel_word_source()
{
@ini_set('memory_limit', '256M');
7 years ago
$file = $_FILES['file'];
if (!$file) {
3 years ago
echo (json_encode(array(
'status' => 'error',
'msg' => "文件上传失败。"
)));
return;
}
$usr = $this->input->post('usr');
$icid = $this->input->post('icid');
7 years ago
//转移文件
3 years ago
$md5_file = md5($usr . $icid . $file['name']);
//ext
3 years ago
$ext = mb_strtolower(strrchr($file["name"], '.'));
if ($ext != '.docx') {
3 years ago
echo (json_encode(array(
'status' => 'error',
'msg' => '只能接收word(.docx)文档。'
)));
return;
}
3 years ago
$md5_name = $md5_file . $ext;
7 years ago
//临时docx文件
3 years ago
$docx_path = realpath('../cht-system/views/information/word_source') . '/' . basename($md5_name);
7 years ago
$html = 'to use mammoth';
7 years ago
if (move_uploaded_file($file['tmp_name'], $docx_path)) {
7 years ago
$docx_dir = realpath('../cht-system/views/information/word_source');
7 years ago
//图片及html目录
3 years ago
$img_dir = $docx_dir . '/' . $md5_file;
7 years ago
is_dir($img_dir) || mkdir($img_dir, 0777);
//临时html文件
3 years ago
$docx_parh = $img_dir . '/' . $md5_name;
7 years ago
$html_parh = str_ireplace('.docx', '.html', $docx_parh);
7 years ago
//运行docx转化插件
7 years ago
if ($_SERVER['SERVER_NAME'] == 'localhost' || $_SERVER['SERVER_NAME'] == '202.103.68.62') {
$yarnbin = 'C:\Users\cht77\AppData\Local\Yarn\bin\mammoth ';
$test_host = '//202.103.68.62:9096';
} else {
3 years ago
$yarnbin = 'C:\Users\lmr\AppData\Roaming\npm\mammoth ';
7 years ago
$test_host = '';
}
3 years ago
$command = $yarnbin . $docx_path . ' --output-dir=' . $img_dir . ' 2>&1';
//$command = 'C:\Users\lmr\AppData\Local\Yarn\bin\mammoth -h 2>&1';
7 years ago
exec($command, $rs, $st);
7 years ago
//图片处理
$scan_img = scandir($img_dir);
$tmp = '';
3 years ago
foreach ($scan_img as $f) {
7 years ago
$tmp_ext = mb_strtolower(strrchr($f, '.'));
if ($tmp_ext == '.jpeg') {
3 years ago
$tmp_img = $img_dir . '/' . $f;
7 years ago
$tmp_jpg = str_ireplace('.jpeg', '.jpg', $tmp_img);
$im = imagecreatefromjpeg($tmp_img);
imagejpeg($im, $tmp_jpg);
imagedestroy($im);
//删除临时图片
@unlink($tmp_img);
7 years ago
//$tmp .= $f . ' # ';
7 years ago
}
}
//html处理
if (file_exists($html_parh)) {
$html = file_get_contents($html_parh);
} else {
3 years ago
echo (json_encode(array(
'status' => 'error',
3 years ago
'html' => $command . ' # ' . $html_parh,
'rs' => print_r($rs, true) . ' # ' . $st
)));
return;
}
3 years ago
$html = preg_replace('/src="([\d]+).jpeg"/i', 'src="' . $test_host . '/information-view/information/word_source/' . $md5_file . '/$1.jpg"', $html);
7 years ago
//删除临时html
@unlink($html_parh);
7 years ago
//删除docx文档
@unlink($docx_path);
7 years ago
if ($html) {
3 years ago
echo (json_encode(array(
7 years ago
'status' => 'success',
7 years ago
'path' => $docx_path,
7 years ago
'html' => $html
)));
}
7 years ago
} else {
3 years ago
echo (json_encode(array(
7 years ago
'status' => 'error',
'msg' => "word文件解析失败。"
7 years ago
)));
}
}
5 years ago
3 years ago
public function save_history()
{
5 years ago
$json = $this->input->get_post('json');
$icid = $this->input->get_post('icid');
3 years ago
$action = $this->input->get_post('action') ? '_' . $this->input->get_post('action') : '';
5 years ago
if ($json && $icid) {
3 years ago
$code = $this->Logs_model->backup_meta($icid, $json, 'AMP_HISTORY' . $action);
echo json_encode(array(
"succ" => true,
5 years ago
"info" => $this->Logs_model->pick_backup_meta($code)
));
5 years ago
} else {
echo json_encode(array(
"succ" => false,
"message" => "save_history() -> 参数传递错误。"
));
5 years ago
}
}
3 years ago
public function list_history()
{
5 years ago
$icid = $this->input->get_post('icid');
if ($icid) {
echo json_encode(array(
"succ" => true,
"info" => $this->Logs_model->list_backup_meta($icid, 'AMP_HISTORY')
));
5 years ago
} else {
echo json_encode(array(
"succ" => false,
"message" => "list_history() -> 参数传递错误。"
));
5 years ago
}
}
3 years ago
public function pick_history()
{
$log_action_id = $this->input->get_post('log_action_id');
if ($log_action_id) {
echo json_encode(array(
"succ" => true,
"info" => $this->Logs_model->pick_backup_meta($log_action_id)
));
5 years ago
} else {
echo json_encode(array(
"succ" => false,
"message" => "pick_history() -> 参数传递错误。"
));
5 years ago
}
}
7 years ago
}