|
|
|
<?php
|
|
|
|
if (!defined('BASEPATH'))
|
|
|
|
exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class infofix extends CI_Controller
|
|
|
|
{
|
|
|
|
var $site_code = '';
|
|
|
|
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->load->model('Information_model');
|
|
|
|
$this->load->model('infoContents_model');
|
|
|
|
$this->load->model('infoMetas_model');
|
|
|
|
$this->site_code = $this->input->get('site_code') ? $this->input->get('site_code') : $this->config->item('site_code');
|
|
|
|
}
|
|
|
|
|
|
|
|
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) || strpos($keys, '/') === false) {
|
|
|
|
echo json_encode(array());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 关键字信息
|
|
|
|
$rs = $this->Information_model->list_by_keywords($site, $key_arr);
|
|
|
|
|
|
|
|
// 调整数据
|
|
|
|
foreach ($rs as $info) {
|
|
|
|
$key_with_content = array();
|
|
|
|
$key_with_json = array();
|
|
|
|
foreach ($key_arr as $key) {
|
|
|
|
// $info->ic_content = utf8_encode($info->ic_content);
|
|
|
|
// $info->ic_url = utf8_encode($info->ic_url);
|
|
|
|
|
|
|
|
// 链接
|
|
|
|
$sub_url = $info->ic_url == $key ? $info->ic_url : '';
|
|
|
|
$limitStr = 30;
|
|
|
|
|
|
|
|
// 信息内容
|
|
|
|
$pos_content = 0;
|
|
|
|
$pos_content = mb_stripos($info->ic_content, $key);
|
|
|
|
$sub_content = array();
|
|
|
|
while ($pos_content) {
|
|
|
|
array_push($sub_content, '[...' . mb_substr($info->ic_content, $pos_content - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]');
|
|
|
|
$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) {
|
|
|
|
array_push($sub_content2, '[...' . mb_substr($info->amp_json, $pos_content2 - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]');
|
|
|
|
$pos_content2 = mb_stripos($info->amp_json, $key, $pos_content2 + mb_strlen($key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// amp_body
|
|
|
|
$sub_content3 = array();
|
|
|
|
if ($info->amp_body) {
|
|
|
|
$pos_content3 = 0;
|
|
|
|
$pos_content3 = mb_stripos($info->amp_body, $key);
|
|
|
|
while ($pos_content3) {
|
|
|
|
array_push($sub_content3, '[...' . mb_substr($info->amp_body, $pos_content3 - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]');
|
|
|
|
$pos_content3 = mb_stripos($info->amp_body, $key, $pos_content3 + mb_strlen($key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sub_url != '' || count($sub_content) != 0) {
|
|
|
|
array_push(
|
|
|
|
$key_with_content,
|
|
|
|
array(
|
|
|
|
'key' => $key,
|
|
|
|
'sub_url' => $sub_url,
|
|
|
|
'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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// 容错
|
|
|
|
if (empty($site) || count($keyArr) != 4 || strpos($keys, '/') === false) {
|
|
|
|
echo json_encode(array());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 参数解析
|
|
|
|
$ic_id = $keyArr[0];
|
|
|
|
$oldStr = $keyArr[1];
|
|
|
|
$newStr = $keyArr[2];
|
|
|
|
$is_id = $keyArr[3];
|
|
|
|
|
|
|
|
// ic_content
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// amp_json
|
|
|
|
$meta = $this->infoMetas_model->get($ic_id, 'AMP_JSON');
|
|
|
|
if (!empty($meta)) {
|
|
|
|
$meta->im_value = str_ireplace($oldStr, $newStr, $meta->im_value);
|
|
|
|
$this->infoMetas_model->update($is_id, 'AMP_JSON', $meta->im_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// amp_body_pc
|
|
|
|
$meta = $this->infoMetas_model->get($ic_id, 'AMP_BODY_PC');
|
|
|
|
if (!empty($meta)) {
|
|
|
|
$meta->im_value = str_ireplace($oldStr, $newStr, $meta->im_value);
|
|
|
|
$this->infoMetas_model->update($is_id, 'AMP_BODY_PC', $meta->im_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
print_r($keyArr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//end of infofix
|