|
|
<?php
|
|
|
if (! defined('BASEPATH')) {
|
|
|
exit('No direct script access allowed');
|
|
|
}
|
|
|
|
|
|
class infofix extends CI_Controller {
|
|
|
public $site_code = '';
|
|
|
|
|
|
public function __construct() {
|
|
|
parent::__construct();
|
|
|
$this->load->model('Information_model');
|
|
|
$this->load->model('infoContents_model');
|
|
|
$this->load->model('infoMetas_model');
|
|
|
$this->load->model('logs_model');
|
|
|
$this->site_code = $this->input->get('site_code') ? $this->input->get('site_code') : $this->config->item('site_code');
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据关键词搜索信息
|
|
|
*/
|
|
|
public function list_info_by_keys() {
|
|
|
// 防止超时
|
|
|
set_time_limit(0);
|
|
|
|
|
|
// json参数
|
|
|
$site = $this->input->get_post('site');
|
|
|
$keys = $this->input->get_post('keys');
|
|
|
$key_arr = explode(',', $keys);
|
|
|
|
|
|
// 容错
|
|
|
if (
|
|
|
empty($site)
|
|
|
|| empty($keys)
|
|
|
// || mb_stripos($keys, '/') === false
|
|
|
) {
|
|
|
echo json_encode([]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 关键字信息
|
|
|
$rs = $this->Information_model->list_by_keywords($site, $key_arr);
|
|
|
|
|
|
// 调整数据
|
|
|
foreach ($rs as $info) {
|
|
|
$key_with_content = [];
|
|
|
foreach ($key_arr as $key) {
|
|
|
|
|
|
// 链接
|
|
|
$sub_url = mb_stripos($info->ic_url, $key) !== false ? $info->ic_url : '';
|
|
|
if ($sub_url) {
|
|
|
$sub_url = str_replace($key, '@@@' . $key . '@@@', $sub_url);
|
|
|
$sub_url = explode('@@@', $sub_url);
|
|
|
}
|
|
|
|
|
|
// 图片
|
|
|
$sub_ic_photo = mb_stripos($info->ic_photo, $key) !== false ? $info->ic_photo : '';
|
|
|
if ($sub_ic_photo) {
|
|
|
$sub_ic_photo = str_replace($key, '@@@' . $key . '@@@', $sub_ic_photo);
|
|
|
$sub_ic_photo = explode('@@@', $sub_ic_photo);
|
|
|
}
|
|
|
|
|
|
$limitStr = 100;
|
|
|
// 信息内容
|
|
|
$pos_content = 0;
|
|
|
$pos_content = mb_stripos($info->ic_content, $key);
|
|
|
$sub_content = [];
|
|
|
while ($pos_content) {
|
|
|
$_str = '[...' . mb_substr($info->ic_content, $pos_content - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]';
|
|
|
$_str = str_replace($key, '@@@' . $key . '@@@', $_str);
|
|
|
$_str = explode('@@@', $_str);
|
|
|
array_push($sub_content, $_str);
|
|
|
$pos_content = mb_stripos($info->ic_content, $key, $pos_content + mb_strlen($key));
|
|
|
}
|
|
|
|
|
|
// amp_json
|
|
|
$sub_content2 = [];
|
|
|
// if ($info->amp_json) {
|
|
|
// $pos_content2 = 0;
|
|
|
// $pos_content2 = mb_stripos($info->amp_json, $key);
|
|
|
// while ($pos_content2) {
|
|
|
// $_str = '[...' . mb_substr($info->amp_json, $pos_content2 - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]';
|
|
|
// $_str = str_replace($key, '@@@' . $key . '@@@', $_str);
|
|
|
// $_str = explode('@@@', $_str);
|
|
|
// array_push($sub_content2, $_str);
|
|
|
// $pos_content2 = mb_stripos($info->amp_json, $key, $pos_content2 + mb_strlen($key));
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
// amp_body
|
|
|
$sub_content3 = [];
|
|
|
// if ($info->amp_body) {
|
|
|
// $pos_content3 = 0;
|
|
|
// $pos_content3 = mb_stripos($info->amp_body, $key);
|
|
|
// while ($pos_content3) {
|
|
|
// $_str = '[...' . mb_substr($info->amp_body, $pos_content3 - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]';
|
|
|
// $_str = str_replace($key, '@@@' . $key . '@@@', $_str);
|
|
|
// $_str = explode('@@@', $_str);
|
|
|
// array_push($sub_content3, $_str);
|
|
|
// $pos_content3 = mb_stripos($info->amp_body, $key, $pos_content3 + mb_strlen($key));
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
if ($sub_url != '' || $sub_ic_photo != '' || count($sub_content) != 0 || count($sub_content2) != 0 || count($sub_content3) != 0) {
|
|
|
array_push(
|
|
|
$key_with_content,
|
|
|
[
|
|
|
'key' => $key,
|
|
|
'sub_url' => $sub_url,
|
|
|
'sub_ic_photo' => $sub_ic_photo,
|
|
|
'sub_content' => $sub_content,
|
|
|
'sub_json' => $sub_content2,
|
|
|
'sub_body' => $sub_content3,
|
|
|
]
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$info->ic_content = $key_with_content;
|
|
|
unset($info->amp_json);
|
|
|
unset($info->amp_body);
|
|
|
}
|
|
|
echo json_encode($rs);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新含有关键的信息
|
|
|
*/
|
|
|
public function update_info_by_keys() {
|
|
|
// json参数
|
|
|
$site = $this->input->get_post('site');
|
|
|
$keys = $this->input->get_post('keys');
|
|
|
$keyArr = explode('@', $keys); // ic_id@oldurl@newurl@is_id
|
|
|
|
|
|
//sleep(2);
|
|
|
//echo ($keys);
|
|
|
//return true;
|
|
|
|
|
|
// 容错1
|
|
|
if (
|
|
|
empty($site) ||
|
|
|
count($keyArr) != 4 ||
|
|
|
// mb_stripos($keys, '/') === false ||
|
|
|
mb_stripos($keys, 'undefined') !== false ||
|
|
|
mb_stripos($keys, 'null') !== false ||
|
|
|
mb_stripos($keys, '@@') !== false ||
|
|
|
mb_stripos($keys, '@ @') !== false
|
|
|
) {
|
|
|
echo json_encode(['err' => '容错1']);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 参数解析
|
|
|
$ic_id = $keyArr[0];
|
|
|
$oldStr = $keyArr[1];
|
|
|
$newStr = $keyArr[2];
|
|
|
$is_id = $keyArr[3];
|
|
|
|
|
|
// 容错2
|
|
|
if (
|
|
|
empty($ic_id)
|
|
|
|| empty($is_id)
|
|
|
|| empty($newStr)
|
|
|
|| empty($oldStr)
|
|
|
// || mb_stripos($newStr, '/') === false
|
|
|
// || mb_stripos($oldStr, '/') === false
|
|
|
) {
|
|
|
echo json_encode(['err' => '容错2']);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// ic_info
|
|
|
$ic = $this->infoContents_model->get_ic_contents2($ic_id);
|
|
|
if (! empty($ic)) {
|
|
|
$ic->ic_content = str_ireplace($oldStr, $newStr, $ic->ic_content);
|
|
|
$this->infoContents_model->force_update($ic_id, $ic->ic_content);
|
|
|
$ic->ic_url = str_ireplace($oldStr, $newStr, $ic->ic_url);
|
|
|
$this->infoContents_model->force_update_url($ic_id, $ic->ic_url);
|
|
|
$ic->ic_photo = str_ireplace($oldStr, $newStr, $ic->ic_photo);
|
|
|
$this->infoContents_model->force_update_ic_photo($ic_id, $ic->ic_photo);
|
|
|
}
|
|
|
|
|
|
// amp_json
|
|
|
// $meta = $this->infoMetas_model->get($ic_id, 'AMP_JSON');
|
|
|
// if (! empty($meta)) {
|
|
|
// $meta = str_ireplace($oldStr, $newStr, $meta);
|
|
|
// $this->infoMetas_model->update($ic_id, 'AMP_JSON', $meta);
|
|
|
// }
|
|
|
|
|
|
// amp_body_pc
|
|
|
// $meta = $this->infoMetas_model->get($ic_id, 'AMP_BODY_PC');
|
|
|
// if (! empty($meta)) {
|
|
|
// $meta = str_ireplace($oldStr, $newStr, $meta);
|
|
|
// $this->infoMetas_model->update($ic_id, 'AMP_BODY_PC', $meta);
|
|
|
// }
|
|
|
|
|
|
echo json_encode($keyArr);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据关键词移除信息内容中的链接
|
|
|
* @param string $html
|
|
|
* @param string $keys 字符串,每个key用@分隔
|
|
|
* @return string
|
|
|
*/
|
|
|
function removeLinksByKeys($html, $keys) {
|
|
|
// 拆分$keys为数组
|
|
|
$keysArr = explode('@', $keys);
|
|
|
// 遍历每个key,依次移除包含该key的a标签
|
|
|
foreach ($keysArr as $key) {
|
|
|
if (empty($key)) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
$pattern = '/<a\s[^>]*href=["\']([^"\']*' . preg_quote($key, '/') . '[^"\']*)["\'][^>]*>(.*?)<\/a>/i';
|
|
|
$html = preg_replace($pattern, '$2', $html);
|
|
|
}
|
|
|
// 替换为纯文本内容(第二个捕获组)
|
|
|
return $html;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据ic_id和key更新信息内容
|
|
|
*/
|
|
|
public function update_info_by_icid_keys() {
|
|
|
$ic_id = $this->input->get_post('ic_id');
|
|
|
$keys = $this->input->get_post('keys');
|
|
|
|
|
|
// 容错
|
|
|
if (empty($ic_id) || empty($keys)) {
|
|
|
echo json_encode(['err' => 'para_参数错误']);
|
|
|
return false;
|
|
|
}
|
|
|
// echo $ic_id . ' - ' . $keys . "\n";
|
|
|
|
|
|
// 更新信息
|
|
|
$ic = $this->infoContents_model->get_ic_contents2($ic_id);
|
|
|
// print_r($ic);
|
|
|
|
|
|
if (! empty($ic)) {
|
|
|
$ic->ic_content = $this->removeLinksByKeys($ic->ic_content, $keys);
|
|
|
$this->infoContents_model->force_update($ic_id, $ic->ic_content);
|
|
|
echo json_encode(['status' => 1]);
|
|
|
} else {
|
|
|
echo json_encode(['err' => 'icid_' . $ic_id . '_未找到信息内容']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 无条件获取信息内容
|
|
|
* @param mixed $ic_id
|
|
|
*/
|
|
|
public function get_by_icid($ic_id) {
|
|
|
$ic = $this->infoContents_model->get_ic_contents2($ic_id);
|
|
|
$json = json_decode($this->infoMetas_model->get($ic_id, 'AMP_JSON'));
|
|
|
$use = $this->infoMetas_model->get($ic_id, 'AMP_BODY_PC_STATUS');
|
|
|
if ($ic) {
|
|
|
echo json_encode(
|
|
|
[
|
|
|
'state' => 0,
|
|
|
'ic_url' => $ic->ic_url,
|
|
|
'ic_sitecode' => $ic->ic_sitecode,
|
|
|
'ic_content' => $ic->ic_content,
|
|
|
'pc_use' => $use,
|
|
|
'json' => [], //$json,
|
|
|
]
|
|
|
);
|
|
|
} else {
|
|
|
echo json_encode(
|
|
|
[
|
|
|
'state' => -1,
|
|
|
'msg' => 'not content by ' . $ic_id,
|
|
|
]
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 无条件更新信息内容(上线前内容)
|
|
|
*/
|
|
|
public function update_by_icid() {
|
|
|
$ic_id = $this->input->get_post('ic_id');
|
|
|
$ic_content = $this->input->get_post('ic_content');
|
|
|
$backup = $this->input->get_post('backup');
|
|
|
|
|
|
// 先备份 - 测试时不备份
|
|
|
if ($backup == 'backup') {
|
|
|
$is = $this->infoContents_model->get_isid_by_icid($ic_id);
|
|
|
$ic = $this->infoContents_model->get_ic_contents2($ic_id);
|
|
|
$this->logs_model->backup($is->is_id, $ic->ic_content);
|
|
|
}
|
|
|
|
|
|
$rs = $this->infoContents_model->force_update($ic_id, $ic_content);
|
|
|
echo json_encode(['status' => 1]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 无条件更新信息内容(上线前内容)
|
|
|
*/
|
|
|
public function isid_by_icid2() {
|
|
|
$ic_id = $this->input->get_post('ic_id');
|
|
|
$is = $this->infoContents_model->get_isid_by_icid($ic_id);
|
|
|
|
|
|
if (isset($is->is_id)) {
|
|
|
echo json_encode(['status' => 1, 'isid' => $is->is_id]);
|
|
|
} else {
|
|
|
echo json_encode(['status' => 0, 'isid' => $is->$ic_id]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 列举使用旧版构建工具的信息,用于批量替换更新。
|
|
|
* @param mixed $site
|
|
|
*/
|
|
|
public function list_use_hb() {
|
|
|
$site = $this->input->get('site');
|
|
|
$api = $this->input->get('api');
|
|
|
$rs = $this->infoContents_model->list_use_hb($site);
|
|
|
if ($api) {
|
|
|
$_rs = [];
|
|
|
foreach ($rs as $value) {
|
|
|
array_push($_rs, [
|
|
|
'id' => $value->ic_id,
|
|
|
'data' => $value->ic_url,
|
|
|
'status' => 0,
|
|
|
]);
|
|
|
}
|
|
|
$rs = $_rs;
|
|
|
}
|
|
|
echo json_encode($rs);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 转化旧版构建工具数据(上线前的准备)- 不使用。
|
|
|
* @param mixed $ic_id
|
|
|
*/
|
|
|
public function migrate_hb($dev = 'prod') {
|
|
|
$ic_id = $this->input->get('id');
|
|
|
// 本地测试参数
|
|
|
$api = 'https://hmk.arachina.com/beta/3733/server_render2';
|
|
|
if ($dev == 'dev') {
|
|
|
$api = 'http://127.0.0.1:3733/server_render2';
|
|
|
// sleep(1);
|
|
|
}
|
|
|
|
|
|
// 请求api
|
|
|
$json = $this->infoMetas_model->get($ic_id, 'AMP_JSON');
|
|
|
if (! empty($json)) {
|
|
|
// 请求转化服务器
|
|
|
$post_data = 'json=' . urlencode($json);
|
|
|
$ch = curl_init();
|
|
|
curl_setopt($ch, CURLOPT_URL, $api);
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //禁止直接显示获取的内容
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
|
$curl_rs = curl_exec($ch);
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
if ($curl_rs && ($httpCode == 200 || $httpCode == 201)) {
|
|
|
// 先备份 - 测试时不备份
|
|
|
if ($dev != 'dev') {
|
|
|
$is = $this->infoContents_model->get_isid_by_icid($ic_id);
|
|
|
$ic = $this->infoContents_model->get_ic_contents2($ic_id);
|
|
|
$this->logs_model->backup($is->is_id, $ic->ic_content);
|
|
|
}
|
|
|
// 移除外部包裹标签
|
|
|
$curl_rs = str_replace(['<my_lmr_tpl>', '</my_lmr_tpl>'], '', $curl_rs);
|
|
|
//cdn域名替换res
|
|
|
$curl_rs = str_replace('//cdn.chinahighlights.ru', '//res.chinahighlights.ru', $curl_rs);
|
|
|
$curl_rs = str_replace('//cdn.arachina.com', '//res.arachina.com', $curl_rs);
|
|
|
$curl_rs = str_replace('//cdn.chinarundreisen.com', '//res.chinarundreisen.com', $curl_rs);
|
|
|
$curl_rs = str_replace('//cdn.voyageschine.com', '//res.voyageschine.com', $curl_rs);
|
|
|
$curl_rs = str_replace('//cdn.viaje-a-china.com', '//res.viaje-a-china.com', $curl_rs);
|
|
|
$curl_rs = str_replace('//cdn.viaggio-in-cina.it', '//res.viaggio-in-cina.it', $curl_rs);
|
|
|
|
|
|
// 强制更新信息内容
|
|
|
$this->infoContents_model->force_update($ic_id, $curl_rs);
|
|
|
echo json_encode(['status' => 1]);
|
|
|
} else {
|
|
|
echo json_encode(['status' => -1, 'msg' => 'err1']);
|
|
|
}
|
|
|
} else {
|
|
|
echo json_encode(['status' => -1, 'msg' => 'err2']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//end of infofix
|