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

52 lines
1.3 KiB
PHP

<?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($site = '', $keys = [])
{
$site = 'cht';
$keys = ['/beijing/', '/yangshuo/'];
// 容错
if (empty($site) || empty($keys)) {
echo json_encode(
array(
'data' => []
)
);
return false;
}
$rs = $this->Information_model->list_by_keywords($site, $keys);
foreach ($rs as $info) {
$keycount = array();
foreach ($keys as $key) {
$pos_url = stripos($info->ic_url, $key);
$sub_url = $info->ic_url == $key ? $info->ic_url : '';
$pos_content = stripos($info->ic_content, $key);
$sub_content = '[...' . substr($info->ic_content, $pos_content - 20, strlen($key) + 20 * 2) . '...]';
if ($pos_url !== false || $pos_content !== false) {
array_push($keycount, array('key' => $key, 'sub_url' => $sub_url, 'sub_content' => $sub_content));
}
}
$info->ic_content = $keycount;
}
echo json_encode($rs);
}
}
//end of infofix