Пример #1
0
 public function lists()
 {
     $parentids = array();
     $WAP = $this->wap;
     $TYPE = $this->types;
     $WAP_SETTING = string2array($WAP['setting']);
     $GLOBALS['siteid'] = $siteid = max($this->siteid, 1);
     $typeid = intval($_GET['typeid']);
     if (!$typeid) {
         exit(L('parameter_error'));
     }
     $catid = $this->types[$typeid]['cat'];
     $siteids = getcache('category_content', 'commons');
     $siteid = $siteids[$catid];
     $CATEGORYS = getcache('category_content_' . $siteid, 'commons');
     if (!isset($CATEGORYS[$catid])) {
         exit(L('parameter_error'));
     }
     $CAT = $CATEGORYS[$catid];
     $siteid = $GLOBALS['siteid'] = $CAT['siteid'];
     extract($CAT);
     foreach ($TYPE as $_t) {
         $parentids[] = $_t['parentid'];
     }
     $template = $TYPE[$typeid]['parentid'] == 0 && in_array($typeid, array_unique($parentids)) ? $WAP_SETTING['category_template'] : $WAP_SETTING['list_template'];
     $MODEL = getcache('model', 'commons');
     $modelid = $CAT['modelid'];
     $tablename = $this->db->table_name = $this->db->db_tablepre . $MODEL[$modelid]['tablename'];
     $total = $this->db->count(array('status' => '99', 'catid' => $catid));
     $page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
     $pagesize = $WAP_SETTING['listnum'] ? intval($WAP_SETTING['listnum']) : 20;
     $offset = ($page - 1) * $pagesize;
     $list = $this->db->select(array('status' => '99', 'catid' => $catid), '*', $offset . ',' . $pagesize, 'inputtime DESC');
     //构造wap url规则
     define('URLRULE', 'index.php?m=wap&c=index&a=lists&typeid={$typeid}~index.php?m=wap&c=index&a=lists&typeid={$typeid}&page={$page}');
     $GLOBALS['URL_ARRAY'] = array('typeid' => $typeid);
     $pages = wpa_pages($total, $page, $pagesize);
     include template('wap', $template);
 }
Пример #2
0
 public function search()
 {
     $this->db = pc_base::load_model('search_model');
     $q = safe_replace(trim($_POST['title']));
     $typeid = isset($_GET['typeid']) ? intval($_GET['typeid']) : 58;
     $siteid = isset($_GET['siteid']) ? intval($_GET['siteid']) : 1;
     $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
     $q = htmlspecialchars(strip_tags($q));
     $q = str_replace('%', '', $q);
     // 过滤'%',用户全文搜索
     $search_q = $q;
     // 搜索原内容
     $time = empty($_GET['time']) || !in_array($_GET['time'], array('all', 'day', 'month', 'year')) ? 'all' : trim($_GET['time']);
     if ($time == 'day') {
         $search_time = SYS_TIME - 86400;
         $sql_time = ' AND adddate > ' . $search_time;
     } elseif ($time == 'week') {
         $search_time = SYS_TIME - 604800;
         $sql_time = ' AND adddate > ' . $search_time;
     } elseif ($time == 'month') {
         $search_time = SYS_TIME - 2592000;
         $sql_time = ' AND adddate > ' . $search_time;
     } elseif ($time == 'year') {
         $search_time = SYS_TIME - 31536000;
         $sql_time = ' AND adddate > ' . $search_time;
     } else {
         $search_time = 0;
         $sql_time = '';
     }
     if ($page == 1 && !$setting['sphinxenable']) {
         // 精确搜索
         $commend = $this->db->get_one("`typeid` = '{$typeid}' {$sql_time} AND `data` like '%{$q}%'");
     } else {
         $commend = '';
     }
     pc_base::load_sys_class('segment', '', 0);
     $segment = new segment();
     // 分词结果
     $segment_q = $segment->get_keyword($segment->split_result($q));
     // 如果分词结果为空
     if (!empty($segment_q)) {
         $sql = "`siteid`= '{$siteid}' AND `typeid` = '{$typeid}' {$sql_time} AND MATCH (`data`) AGAINST ('{$segment_q}' IN BOOLEAN MODE)";
     } else {
         $sql = "`siteid`= '{$siteid}' AND `typeid` = '{$typeid}' {$sql_time} AND `data` like '%{$q}%'";
     }
     $result = $this->db->listinfo($sql, 'searchid DESC', $page, 7);
     if (!empty($result) || !empty($commend['id'])) {
         //开启sphinx后文章id取法不同
         if ($setting['sphinxenable']) {
             foreach ($result as $_v) {
                 $sids[] = $_v['attrs']['id'];
             }
         } else {
             foreach ($result as $_v) {
                 $sids[] = $_v['id'];
             }
         }
         if (!empty($commend['id'])) {
             $sids[] = $commend['id'];
         }
         $sids = array_unique($sids);
         $where = to_sqls($sids, '', 'id');
         //获取模型id
         $model_type_cache = getcache('type_model_' . $siteid, 'search');
         $model_type_cache = array_flip($model_type_cache);
         $modelid = $model_type_cache[$typeid];
         //是否读取其他模块接口
         if ($modelid) {
             $this->content_db->set_model($modelid);
             /**
              * 如果表名为空,则为黄页模型
              */
             if (empty($this->content_db->model_tablename)) {
                 $this->content_db = pc_base::load_model('yp_content_model');
                 $this->content_db->set_model($modelid);
             }
             if ($setting['sphinxenable']) {
                 $data = $this->content_db->listinfo($where, 'id DESC', 1, $pagesize);
                 $pages = wpa_pages($totalnums, $page, $pagesize);
             } else {
                 $data = $this->content_db->select($where, '*');
                 $pages = $this->db->pages;
                 $totalnums = $this->db->number;
             }
             //如果分词结果为空
             if (!empty($segment_q)) {
                 $replace = explode(' ', $segment_q);
                 foreach ($replace as $replace_arr_v) {
                     $replace_arr[] = '<font color=red>' . $replace_arr_v . '</font>';
                 }
                 foreach ($data as $_k => $_v) {
                     $data[$_k]['title'] = str_replace($replace, $replace_arr, $_v['title']);
                     $data[$_k]['description'] = str_replace($replace, $replace_arr, $_v['description']);
                 }
             } else {
                 foreach ($data as $_k => $_v) {
                     $data[$_k]['title'] = str_replace($q, '<font color=red>' . $q . '</font>', $_v['title']);
                     $data[$_k]['description'] = str_replace($q, '<font color=red>' . $q . '</font>', $_v['description']);
                 }
             }
         } else {
             //读取专辑搜索接口
             $special_api = pc_base::load_app_class('search_api', 'special');
             $data = $special_api->get_search_data($sids);
             $totalnums = count($data);
         }
     }
     $execute_time = execute_time();
     $totalnums = isset($totalnums) ? $totalnums : 0;
     $totalpage = $totalnums / 7;
     $pagesi = wpa_pages($totalpage, $page, 7);
     $data = isset($data) ? $data : '';
     include template('wap', 'list_search');
 }