master
LMR 10 months ago
parent 25727d79c2
commit 01d126c115

@ -1,287 +1,287 @@
<?php <?php
if (!defined('BASEPATH')) if (!defined('BASEPATH')) {
exit('No direct script access allowed'); exit('No direct script access allowed');
}
class infofix extends CI_Controller class infofix extends CI_Controller
{ {
var $site_code = ''; public $site_code = '';
function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
$this->load->model('Information_model'); $this->load->model('Information_model');
$this->load->model('infoContents_model'); $this->load->model('infoContents_model');
$this->load->model('infoMetas_model'); $this->load->model('infoMetas_model');
$this->load->model('logs_model'); $this->load->model('logs_model');
$this->site_code = $this->input->get('site_code') ? $this->input->get('site_code') : $this->config->item('site_code'); $this->site_code = $this->input->get('site_code') ? $this->input->get('site_code') : $this->config->item('site_code');
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
} }
/** /**
* 根据关键词搜索信息 * 根据关键词搜索信息
*/ */
function list_info_by_keys() public function list_info_by_keys()
{ {
// 防止超时 // 防止超时
set_time_limit(0); set_time_limit(0);
// json参数 // json参数
$site = $this->input->get_post('site'); $site = $this->input->get_post('site');
$keys = $this->input->get_post('keys'); $keys = $this->input->get_post('keys');
$key_arr = explode(',', $keys); $key_arr = explode(',', $keys);
// 容错 // 容错
if ( if (
empty($site) || empty($site) ||
empty($keys) || empty($keys) ||
mb_stripos($keys, '/') === false mb_stripos($keys, '/') === false
) { ) {
echo json_encode(array()); echo json_encode(array());
return false; return false;
} }
// 关键字信息 // 关键字信息
$rs = $this->Information_model->list_by_keywords($site, $key_arr); $rs = $this->Information_model->list_by_keywords($site, $key_arr);
// 调整数据 // 调整数据
foreach ($rs as $info) { foreach ($rs as $info) {
$key_with_content = array(); $key_with_content = array();
foreach ($key_arr as $key) { foreach ($key_arr as $key) {
// 链接 // 链接
$sub_url = mb_stripos($info->ic_url, $key) !== false ? $info->ic_url : ''; $sub_url = mb_stripos($info->ic_url, $key) !== false ? $info->ic_url : '';
if ($sub_url) { if ($sub_url) {
$sub_url = str_replace($key, '@@@' . $key . '@@@', $sub_url); $sub_url = str_replace($key, '@@@' . $key . '@@@', $sub_url);
$sub_url = explode('@@@', $sub_url); $sub_url = explode('@@@', $sub_url);
} }
$limitStr = 100; $limitStr = 100;
// 信息内容 // 信息内容
$pos_content = 0; $pos_content = 0;
$pos_content = mb_stripos($info->ic_content, $key); $pos_content = mb_stripos($info->ic_content, $key);
$sub_content = array(); $sub_content = array();
while ($pos_content) { while ($pos_content) {
$_str = '[...' . mb_substr($info->ic_content, $pos_content - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]'; $_str = '[...' . mb_substr($info->ic_content, $pos_content - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]';
$_str = str_replace($key, '@@@' . $key . '@@@', $_str); $_str = str_replace($key, '@@@' . $key . '@@@', $_str);
$_str = explode('@@@', $_str); $_str = explode('@@@', $_str);
array_push($sub_content, $_str); array_push($sub_content, $_str);
$pos_content = mb_stripos($info->ic_content, $key, $pos_content + mb_strlen($key)); $pos_content = mb_stripos($info->ic_content, $key, $pos_content + mb_strlen($key));
} }
// amp_json
$sub_content2 = array();
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_json // amp_body
$sub_content2 = array(); $sub_content3 = array();
if ($info->amp_json) { if ($info->amp_body) {
$pos_content2 = 0; $pos_content3 = 0;
$pos_content2 = mb_stripos($info->amp_json, $key); $pos_content3 = mb_stripos($info->amp_body, $key);
while ($pos_content2) { while ($pos_content3) {
$_str = '[...' . mb_substr($info->amp_json, $pos_content2 - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]'; $_str = '[...' . mb_substr($info->amp_body, $pos_content3 - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]';
$_str = str_replace($key, '@@@' . $key . '@@@', $_str); $_str = str_replace($key, '@@@' . $key . '@@@', $_str);
$_str = explode('@@@', $_str); $_str = explode('@@@', $_str);
array_push($sub_content2, $_str); array_push($sub_content3, $_str);
$pos_content2 = mb_stripos($info->amp_json, $key, $pos_content2 + mb_strlen($key)); $pos_content3 = mb_stripos($info->amp_body, $key, $pos_content3 + mb_strlen($key));
} }
} }
// amp_body if ($sub_url != '' || count($sub_content) != 0 || count($sub_content2) != 0 || count($sub_content3) != 0) {
$sub_content3 = array(); array_push(
if ($info->amp_body) { $key_with_content,
$pos_content3 = 0; array(
$pos_content3 = mb_stripos($info->amp_body, $key); 'key' => $key,
while ($pos_content3) { 'sub_url' => $sub_url,
$_str = '[...' . mb_substr($info->amp_body, $pos_content3 - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]'; 'sub_content' => $sub_content,
$_str = str_replace($key, '@@@' . $key . '@@@', $_str); 'sub_json' => $sub_content2,
$_str = explode('@@@', $_str); 'sub_body' => $sub_content3,
array_push($sub_content3, $_str); )
$pos_content3 = mb_stripos($info->amp_body, $key, $pos_content3 + mb_strlen($key)); );
} }
} }
if ($sub_url != '' || count($sub_content) != 0 || count($sub_content2) != 0 || count($sub_content3) != 0) { $info->ic_content = $key_with_content;
array_push( unset($info->amp_json);
$key_with_content, unset($info->amp_body);
array(
'key' => $key,
'sub_url' => $sub_url,
'sub_content' => $sub_content,
'sub_json' => $sub_content2,
'sub_body' => $sub_content3
)
);
} }
} echo json_encode($rs);
$info->ic_content = $key_with_content;
unset($info->amp_json);
unset($info->amp_body);
} }
echo json_encode($rs);
}
/** /**
* 更新含有关键的信息 * 更新含有关键的信息
*/ */
function update_info_by_keys() public function update_info_by_keys()
{ {
// json参数 // json参数
$site = $this->input->get_post('site'); $site = $this->input->get_post('site');
$keys = $this->input->get_post('keys'); $keys = $this->input->get_post('keys');
$keyArr = explode('@', $keys); // ic_id@oldurl@newurl@is_id $keyArr = explode('@', $keys); // ic_id@oldurl@newurl@is_id
//sleep(2); //sleep(2);
//echo ($keys); //echo ($keys);
//return true; //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(array('err' => '容错1'));
return false;
}
// 参数解析 // 容错1
$ic_id = $keyArr[0]; if (
$oldStr = $keyArr[1]; empty($site) ||
$newStr = $keyArr[2]; count($keyArr) != 4 ||
$is_id = $keyArr[3]; 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(array('err' => '容错1'));
return false;
}
// 容错2 // 参数解析
if ( $ic_id = $keyArr[0];
empty($ic_id) || $oldStr = $keyArr[1];
empty($is_id) || $newStr = $keyArr[2];
empty($newStr) || $is_id = $keyArr[3];
empty($oldStr) ||
mb_stripos($newStr, '/') === false ||
mb_stripos($oldStr, '/') === false
) {
echo json_encode(array('err' => '容错2'));
return false;
}
// ic_content // 容错2
$ic = $this->infoContents_model->get_ic_contents2($ic_id); if (
if (!empty($ic)) { empty($ic_id) ||
$ic->ic_content = str_ireplace($oldStr, $newStr, $ic->ic_content); empty($is_id) ||
$this->infoContents_model->force_update($ic_id, $ic->ic_content); empty($newStr) ||
$ic->ic_url = str_ireplace($oldStr, $newStr, $ic->ic_url); empty($oldStr) ||
$this->infoContents_model->force_update_url($ic_id, $ic->ic_url); mb_stripos($newStr, '/') === false ||
} mb_stripos($oldStr, '/') === false
) {
echo json_encode(array('err' => '容错2'));
return false;
}
// amp_json // ic_content
$meta = $this->infoMetas_model->get($ic_id, 'AMP_JSON'); $ic = $this->infoContents_model->get_ic_contents2($ic_id);
if (!empty($meta)) { if (!empty($ic)) {
$meta = str_ireplace($oldStr, $newStr, $meta); $ic->ic_content = str_ireplace($oldStr, $newStr, $ic->ic_content);
$this->infoMetas_model->update($ic_id, 'AMP_JSON', $meta); $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);
}
// amp_body_pc // amp_json
$meta = $this->infoMetas_model->get($ic_id, 'AMP_BODY_PC'); $meta = $this->infoMetas_model->get($ic_id, 'AMP_JSON');
if (!empty($meta)) { if (!empty($meta)) {
$meta = str_ireplace($oldStr, $newStr, $meta); $meta = str_ireplace($oldStr, $newStr, $meta);
$this->infoMetas_model->update($ic_id, 'AMP_BODY_PC', $meta); $this->infoMetas_model->update($ic_id, 'AMP_JSON', $meta);
} }
echo json_encode($keyArr); // 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 mixed $ic_id
*/
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(
array(
'state' => 0,
'ic_content' => $ic->ic_content,
'pc_use' => $use,
'json' => $json
)
);
} else {
echo json_encode(
array(
'state' => -1,
'msg' => 'not content by ' . $ic_id
)
);
} }
}
/** /**
* 无条件更新信息内容(上线前内容) * 无条件获取信息内容
*/ * @param mixed $ic_id
function update_by_icid() */
{ public function get_by_icid($ic_id)
$ic_id = $this->input->get_post('ic_id'); {
$ic_content = $this->input->get_post('ic_content'); $ic = $this->infoContents_model->get_ic_contents2($ic_id);
$this->infoContents_model->force_update($ic_id, $ic_content); $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(
array(
'state' => 0,
'ic_content' => $ic->ic_content,
'pc_use' => $use,
'json' => $json,
)
);
} else {
echo json_encode(
array(
'state' => -1,
'msg' => 'not content by ' . $ic_id,
)
);
}
}
/** /**
* 列举使用旧版构建工具的信息,用于批量替换更新。 * 无条件更新信息内容(上线前内容)
* @param mixed $site */
*/ public function update_by_icid()
function list_use_hb($site) {
{ $ic_id = $this->input->get_post('ic_id');
$rs = $this->infoContents_model->list_use_hb($site); $ic_content = $this->input->get_post('ic_content');
echo json_encode($rs); $this->infoContents_model->force_update($ic_id, $ic_content);
} }
/** /**
* 转化旧版构建工具数据(上线前的准备) * 列举使用旧版构建工具的信息,用于批量替换更新。
* @param mixed $ic_id * @param mixed $site
*/ */
function migrate_hb($ic_id, $dev = 'prod') public function list_use_hb($site)
{ {
// 本地测试参数 $rs = $this->infoContents_model->list_use_hb($site);
$api = 'https://hmk.arachina.com/beta/3733/server_render2'; echo json_encode($rs);
if ($dev == 'dev') {
$api = 'http://127.0.0.1:3733/server_render2';
} }
// 请求api /**
$json = $this->infoMetas_model->get($ic_id, 'AMP_JSON'); * 转化旧版构建工具数据(上线前的准备)
if (!empty($json)) { * @param mixed $ic_id
// 请求转化服务器 */
$post_data = 'json=' . urlencode($json); public function migrate_hb($ic_id, $dev = 'prod')
$ch = curl_init(); {
curl_setopt($ch, CURLOPT_URL, $api); // 本地测试参数
curl_setopt($ch, CURLOPT_POST, 1); $api = 'https://hmk.arachina.com/beta/3733/server_render2';
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); if ($dev == 'dev') {
curl_setopt($ch, CURLOPT_TIMEOUT, 120); $api = 'http://127.0.0.1:3733/server_render2';
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //禁止直接显示获取的内容 }
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 请求api
$curl_rs = curl_exec($ch); $json = $this->infoMetas_model->get($ic_id, 'AMP_JSON');
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (!empty($json)) {
if ($curl_rs && ($httpCode == 200 || $httpCode == 201)) { // 请求转化服务器
// 先备份 $post_data = 'json=' . urlencode($json);
$is = $this->infoContents_model->get_isid_by_icid($ic_id); $ch = curl_init();
$ic = $this->infoContents_model->get_ic_contents2($ic_id); curl_setopt($ch, CURLOPT_URL, $api);
$this->logs_model->backup($is->is_id, $ic->ic_content); curl_setopt($ch, CURLOPT_POST, 1);
// 移除外部包裹标签 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$curl_rs = str_replace(array('<my_lmr_tpl>', '</my_lmr_tpl>'), '', $curl_rs); curl_setopt($ch, CURLOPT_TIMEOUT, 120);
// 强制更新信息内容 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //禁止直接显示获取的内容
$this->infoContents_model->force_update($ic_id, $curl_rs); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
echo $ic_id + ' @ ok @ '; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
} else { $curl_rs = curl_exec($ch);
echo $ic_id + ' @ error @ '; $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
} if ($curl_rs && ($httpCode == 200 || $httpCode == 201)) {
// 先备份
$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(array('<my_lmr_tpl>', '</my_lmr_tpl>'), '', $curl_rs);
// 强制更新信息内容
$this->infoContents_model->force_update($ic_id, $curl_rs);
echo $ic_id+' @ ok @ ';
} else {
echo $ic_id+' @ error @ ';
}
}
} }
}
} }
//end of infofix //end of infofix
Loading…
Cancel
Save