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/infofix.php

225 lines
6.4 KiB
PHTML

1 year ago
<?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');
1 year ago
$this->load->model('infoContents_model');
$this->load->model('infoMetas_model');
1 year ago
$this->site_code = $this->input->get('site_code') ? $this->input->get('site_code') : $this->config->item('site_code');
11 months ago
header('Access-Control-Allow-Origin: *');
1 year ago
}
1 year ago
function list_info_by_keys()
1 year ago
{
1 year ago
// 防止超时
set_time_limit(0);
// json参数
$site = $this->input->get_post('site');
$keys = $this->input->get_post('keys');
1 year ago
$key_arr = explode(',', $keys);
1 year ago
// 容错
if (
empty($site) ||
empty($keys) ||
1 year ago
mb_stripos($keys, '/') === false
) {
1 year ago
echo json_encode(array());
1 year ago
return false;
}
1 year ago
// 关键字信息
1 year ago
$rs = $this->Information_model->list_by_keywords($site, $key_arr);
1 year ago
// 调整数据
1 year ago
foreach ($rs as $info) {
1 year ago
$key_with_content = array();
foreach ($key_arr as $key) {
1 year ago
1 year ago
// 链接
1 year ago
$sub_url = mb_stripos($info->ic_url, $key) !== false ? $info->ic_url : '';
1 year ago
if ($sub_url) {
11 months ago
$sub_url = str_replace($key, '@@@' . $key . '@@@', $sub_url);
$sub_url = explode('@@@', $sub_url);
1 year ago
}
1 year ago
1 year ago
$limitStr = 100;
1 year ago
// 信息内容
1 year ago
$pos_content = 0;
$pos_content = mb_stripos($info->ic_content, $key);
1 year ago
$sub_content = array();
while ($pos_content) {
1 year ago
$_str = '[...' . mb_substr($info->ic_content, $pos_content - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]';
11 months ago
$_str = str_replace($key, '@@@' . $key . '@@@', $_str);
$_str = explode('@@@', $_str);
1 year ago
array_push($sub_content, $_str);
$pos_content = mb_stripos($info->ic_content, $key, $pos_content + mb_strlen($key));
1 year ago
}
1 year ago
// amp_json
$sub_content2 = array();
if ($info->amp_json) {
$pos_content2 = 0;
$pos_content2 = mb_stripos($info->amp_json, $key);
while ($pos_content2) {
1 year ago
$_str = '[...' . mb_substr($info->amp_json, $pos_content2 - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]';
11 months ago
$_str = str_replace($key, '@@@' . $key . '@@@', $_str);
$_str = explode('@@@', $_str);
1 year ago
array_push($sub_content2, $_str);
1 year ago
$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) {
1 year ago
$_str = '[...' . mb_substr($info->amp_body, $pos_content3 - $limitStr, mb_strlen($key) + $limitStr * 2) . '...]';
11 months ago
$_str = str_replace($key, '@@@' . $key . '@@@', $_str);
$_str = explode('@@@', $_str);
1 year ago
array_push($sub_content3, $_str);
1 year ago
$pos_content3 = mb_stripos($info->amp_body, $key, $pos_content3 + mb_strlen($key));
}
}
1 year ago
if ($sub_url != '' || count($sub_content) != 0 || count($sub_content2) != 0 || count($sub_content3) != 0) {
1 year ago
array_push(
$key_with_content,
array(
'key' => $key,
'sub_url' => $sub_url,
'sub_content' => $sub_content,
'sub_json' => $sub_content2,
'sub_body' => $sub_content3
)
);
1 year ago
}
1 year ago
}
1 year ago
$info->ic_content = $key_with_content;
1 year ago
unset($info->amp_json);
unset($info->amp_body);
1 year ago
}
echo json_encode($rs);
1 year ago
}
function update_info_by_keys()
{
// json参数
$site = $this->input->get_post('site');
$keys = $this->input->get_post('keys');
1 year ago
$keyArr = explode('@', $keys); // ic_id@oldurl@newurl@is_id
1 year ago
1 year ago
//sleep(2);
//echo ($keys);
//return true;
// 容错1
1 year ago
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
1 year ago
) {
echo json_encode(array('err' => '容错1'));
return false;
}
1 year ago
// 参数解析
$ic_id = $keyArr[0];
$oldStr = $keyArr[1];
$newStr = $keyArr[2];
$is_id = $keyArr[3];
1 year ago
// 容错2
1 year ago
if (
empty($ic_id) ||
empty($is_id) ||
empty($newStr) ||
empty($oldStr) ||
mb_stripos($newStr, '/') === false ||
mb_stripos($oldStr, '/') === false
) {
echo json_encode(array('err' => '容错2'));
1 year ago
return false;
}
// ic_content
$ic = $this->infoContents_model->get_ic_contents2($ic_id);
1 year ago
if (!empty($ic)) {
$ic->ic_content = str_ireplace($oldStr, $newStr, $ic->ic_content);
$this->infoContents_model->force_update($ic_id, $ic->ic_content);
1 year ago
$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');
1 year ago
if (!empty($meta)) {
1 year ago
$meta = str_ireplace($oldStr, $newStr, $meta);
1 year ago
$this->infoMetas_model->update($ic_id, 'AMP_JSON', $meta);
}
1 year ago
// amp_body_pc
$meta = $this->infoMetas_model->get($ic_id, 'AMP_BODY_PC');
1 year ago
if (!empty($meta)) {
1 year ago
$meta = str_ireplace($oldStr, $newStr, $meta);
1 year ago
$this->infoMetas_model->update($ic_id, 'AMP_BODY_PC', $meta);
}
1 year ago
1 year ago
echo json_encode($keyArr);
11 months ago
}
11 months ago
/**
* 无条件获取内容
* @param mixed $ic_id
* @return void
*/
11 months ago
function get_by_icid($ic_id)
{
$ic = $this->infoContents_model->get_ic_contents2($ic_id);
11 months ago
$json = $this->infoMetas_model->get($ic_id, 'AMP_JSON');
11 months ago
$use = $this->infoMetas_model->get($ic_id, 'AMP_BODY_PC_STATUS');
11 months ago
if ($ic) {
echo json_encode(
array(
'state' => 0,
11 months ago
'ic_content' => $ic->ic_content,
11 months ago
'pc_use' => $use,
11 months ago
'json' => json_encode($json)
11 months ago
)
);
} else {
echo json_encode(
array(
'state' => -1,
'msg' => 'not content by ' . $ic_id
)
);
}
}
1 year ago
11 months ago
function update_by_icid()
{
$ic_id = $this->input->get_post('ic_id');
$ic_content = $this->input->get_post('ic_content');
$this->infoContents_model->force_update($ic_id, $ic_content);
}
1 year ago
}
1 year ago
//end of infofix