|
|
|
<?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->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');
|
|
|
|
$keyArr = explode(',', $keys);
|
|
|
|
|
|
|
|
// 容错
|
|
|
|
if (empty($site) || empty($keys) || strpos($keys, '/') === false) {
|
|
|
|
echo json_encode(array());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 关键字信息
|
|
|
|
$rs = $this->Information_model->list_by_keywords($site, $keyArr);
|
|
|
|
|
|
|
|
// 调整数据
|
|
|
|
foreach ($rs as $info) {
|
|
|
|
$keycount = array();
|
|
|
|
foreach ($keyArr 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 : '';
|
|
|
|
$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 - 20, mb_strlen($key) + 20 * 2) . '...]');
|
|
|
|
$pos_content = mb_stripos($info->ic_content, $key, $pos_content + mb_strlen($key));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sub_url != '' || count($sub_content) != 0) {
|
|
|
|
array_push($keycount, array('key' => $key, 'sub_url' => $sub_url, 'sub_content' => $sub_content));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$info->ic_content = $keycount;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// 容错
|
|
|
|
if (empty($site) || empty($keys) || strpos($keys, '/') === false) {
|
|
|
|
echo json_encode(array());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//end of infofix
|