Ejemplo n.º 1
0
 public function find($page = 1)
 {
     $limit = 10;
     $vdata = array('status' => 0, 'msg' => '未输入关键词!');
     if ($str = $this->input->get('w')) {
         // 元个数大于5
         if (mstrlen($str) > 5) {
             $str = get_str_tags(html2txt($str));
         }
         if ($data = $this->model->find_list($str, $limit, $limit * ($page - 1))) {
             $vdata = $data;
             $vdata['status'] = 1;
             $vdata['msg'] = "获取数据共" . $vdata['count'] . "条";
             //分页
             $this->load->library('pagination');
             $this->pagination->initialize(page_config($limit, $vdata['count'], site_url('tags/find/')));
             $vdata['pages'] = $this->pagination->create_links();
         }
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($vdata));
 }
Ejemplo n.º 2
0
 /**
  * 通过关键词查找文章
  * @param  string $tags 关键词
  * @param int $type 查询类型 
  * @return array        文章信息结构
  */
 public function find_list($tags = '', $limit = 10, $start = 0, $order = false)
 {
     if (is_string($tags)) {
         $tags = explode(',', str_replace(array(',', ' ', ' ', '|'), ',', $tags));
     }
     $table = $this->table;
     $tags_id = array();
     // 类似的,拼音相同的,后缀不同的
     $like = array();
     foreach ($tags as $tag) {
         $it = $this->db->select('id')->where(array('len' => mstrlen($tag), 'tag' => $tag))->from($table)->get()->row_array();
         if ($it) {
             array_push($tags_id, $it['id']);
         }
     }
     //如果没有结果则模糊查询
     if (!$tags_id) {
         foreach ($tags as $tag) {
             $list = $this->db->select('id')->like('tag', $tag)->from($table)->get()->result_array();
             if ($list) {
                 foreach ($list as $it) {
                     array_push($tags_id, $it['id']);
                 }
             }
         }
     }
     // 返回结果
     $re = false;
     // 查询文章链接
     if ($tags_id) {
         $this->db->select('tid')->where_in('tid', $tags_id)->group_by('aid,cid')->get('tags_list')->row_array();
         if ($re['count'] = $this->db->affected_rows()) {
             $re['list'] = $this->db->select('tags_list.*,count(' . $this->db->dbprefix . 'tags_list.cid) as c,columns.path')->join('columns', 'tags_list.cid = columns.id', 'left')->where_in('tid', $tags_id)->group_by('aid,cid')->order_by('tags_list.type', 'asc')->order_by('tags_list.timeline', 'desc')->limit($limit, $start)->get('tags_list')->result_array();
         }
     }
     return $re;
 }
Ejemplo n.º 3
0
 public function checkLength($data, $min = NULL, $max = NULL)
 {
     $len = mstrlen($data);
     $rmin = true;
     $rmax = true;
     if ($min != NULL) {
         if ($len >= $min) {
             $rmin = true;
         } else {
             $rmin = false;
         }
     }
     if ($max != NULL) {
         if ($len <= $max) {
             $rmax = true;
         } else {
             $rmax = false;
         }
     }
     return $rmin & $rmax;
 }