- <?php
- /**
- * special_tag.class.php 專題標簽調用類
- * @author
- *
- */
- class special_tag {
- private $db, $c;
- public function __construct() {
- $this->db = pc_base::load_model('special_model');//專題表:special
- $this->c = pc_base::load_model('special_content_model');//專題文章表:spscial_content
- }
- /**
- * lists調用方法
- * @param array $data 標簽配置傳遞過來的配置數組,根據配置生成sql
- */
- public function lists($data) {
- $siteid = $data['siteid'] ? intval($data['siteid']) : get_siteid();//當前站點id
- $where .= "`siteid`='".$siteid."'";//pc標簽的siteid屬性:當前站點專題
- if ($data['elite']) $where .= " AND `elite`='1'";//pc標簽的elite屬性:推薦專題
- if ($data['thumb']) $where .= " AND `thumb`!=''"; //pc標簽的thumb屬性:有縮略圖的專題
- if ($data['disable']) {
- $where .= " AND `disabled`='".$data['disable']."'";//是否啟用:0-啟用 1-禁用
- }else{
- $where .= " AND `disabled`='0'";//默認顯示,正常顯示的專題。
- }
- //專題的排序方式:0-按照id升序 1-按id降序 2-按listorder升序,id降序 3-按listorder降序,id降序
- $listorder = array('`id` ASC', '`id` DESC', '`listorder` ASC, `id` DESC', '`listorder` DESC, `id` DESC');
- //查詢專題表
- return $this->db->select($where, '*', $data['limit'], $listorder[$data['listorder']]);
- }
- /**
- * 標簽中計算分頁的方法,解析標簽時會通過此方法計算分頁信息
- * @param array $data 標簽配置數組,根據數組計算出分頁
- */
- public function count($data) {
- $where = '1';
- if($data['action'] == 'lists') {
- $where = '1';
- if ($data['siteid']) $where .= " AND `siteid`='".$data['siteid']."'";//站點id
- if ($data['elite']) $where .= " AND `elite`='1'";//推薦專題
- if ($data['thumb']) $where .= " AND `thumb`!=''"; //縮略圖
- //相當于 select count(id) as totle from gt_special $where
- $r = $this->db->get_one($where, 'COUNT(id) AS total');//專題總數
- } elseif ($data['action'] == 'content_list') {//如果要調用專題文章列表
- if ($data['specialid']) $where .= " AND `specialid`='".$data['specialid']."'";//專題id
- if ($data['typeid']) $where .= " AND `typeid`='".$data['typeid']."'";//類別id
- if ($data['thumb']) $where .= " AND `thumb`!=''";//縮略圖
- $r = $this->c->get_one($where, 'COUNT(id) AS total');//查詢到的專題文章總數
- } elseif ($data['action'] == 'hits') {//如果要調用點擊量信息
- $hitsid = 'special-c';
- if ($data['specialid']) $hitsid .= $data['specialid'].'-';
- else $hitsid .= '%-';
- $hitsid = $hitsid .= '%';
- $hits_db = pc_base::load_model('hits_model');
- $sql = "hitsid LIKE '$hitsid'";
- $r = $hits_db->get_one($sql, 'COUNT(*) AS total');//點擊排行文章總數
- }
- return $r['total'];
- }
- /**
- * 點擊排行調用方法
- * @param array $data 標簽配置數組
- */
- public function hits($data) {
- $hitsid = 'special-c-';//hits表中hitsid字段的組成
- if ($data['specialid']) $hitsid .= $data['specialid'].'-';//如果專題id存在,則查詢當前專題下的專題文章
- else $hitsid .= '%-';//如果專題id不存在,則查詢所有的專題文章
- $hitsid = $hitsid .= '%';
- $this->hits_db = pc_base::load_model('hits_model');//hits表
- $sql = "hitsid LIKE '$hitsid'";//拼接sql
- //排序方式:0-按總訪問量降序排列 1-按昨日訪問量降序排列 2-按今日訪問量降序排列 3-按本周訪問量降序排列 4-按本月訪問量降序排列
- $listorders = array('views DESC', 'yesterdayviews DESC', 'dayviews DESC', 'weekviews DESC', 'monthviews DESC');
- //查詢點擊量表
- $result = $this->hits_db->select($sql, '*', $data['limit'], $listorders[$data['listorder']]);
- foreach ($result as $key => $r) {
- $ids = explode('-', $r['hitsid']);//hits表中hitsid字段拆分,如:special-c-1-1
- $id = $ids[3];//當前專題文章的id
- //查詢專題文章主表
- $re = $this->c->get_one(array('id'=>$id));//從專題文章表special_content中獲取當前專題文章的內容
- $result[$key]['title'] = $re['title'];//專題文章的標題
- $result[$key]['url'] = $re['url'];//專題文章的url
- }
- return $result;
- }
- /**
- * 內容列表調用方法
- * @param array $data 標簽配置數組
- */
- public function content_list($data) {
- $where = '1';
- if ($data['specialid']) $where .= " AND `specialid`='".$data['specialid']."'";//專題id
- if ($data['typeid']) $where .= " AND `typeid`='".$data['typeid']."'";//專題類別id
- if ($data['thumb']) $where .= " AND `thumb`!=''";//縮略圖
- //排序方式:0-id升序 1-id降序 2-listorder升序 3-listorder降序
- $listorder = array('`id` ASC', '`id` DESC', '`listorder` ASC', '`listorder` DESC');
- //查詢專題文章主表
- $result = $this->c->select($where, '*', $data['limit'], $listorder[$data['listorder']]);
- if (is_array($result)) {
- foreach($result as $k => $r) {
- if ($r['curl']) {//是否為信息導入:導入原文章的欄目id和文章id
- $content_arr = explode('|', $r['curl']);
- $r['url'] = go($content_arr['1'], $content_arr['0']);//參數1:欄目id 參數2:文章id
- }
- $res[$k] = $r;//專題文章主表中的記錄
- }
- } else {
- $res = array();
- }
- return $res; //返回專題文章表中查詢到的記錄
- }
- /**
- * 獲取專題分類方法
- * @param intval $specialid 專題ID
- * @param string $value 默認選中值
- * @param intval $id onchange影響HTML的ID
- *
- */
- public function get_type($specialid = 0, $value = '', $id = '') {
- $type_db = pc_base::load_model('type_model');//類別表
- $data = $arr = array();
- //查詢類別表
- $data = $type_db->select(array('module'=>'special', 'parentid'=>$specialid));
- //表單類
- pc_base::load_sys_class('form', '', 0);
- foreach($data as $r) {
- $arr[$r['typeid']] = $r['name'];//類別名稱
- }
- $html = $id ? ' id="typeid" onchange="$(/'#'.$id.'/').val(this.value);"' : 'name="typeid", id="typeid"';
- return form::select($arr, $value, $html, L('please_select'));//請選擇所屬類別
- }
- /**
- * 標簽生成方法
- */
- public function pc_tag() {
- //獲取站點
- $sites = pc_base::load_app_class('sites','admin');
- $sitelist = $sites->pc_tag_list();
- $result = getcache('special', 'commons');
- if(is_array($result)) {
- $specials = array(L('please_select'));
- foreach($result as $r) {
- if($r['siteid']!=get_siteid()) continue;
- $specials[$r['id']] = $r['title'];
- }
- }
- return array(
- 'action'=>array('lists'=>L('special_list', '', 'special'), 'content_list'=>L('content_list', '', 'special'), 'hits'=>L('hits_order','','special')),
- 'lists'=>array(
- 'siteid'=>array('name'=>L('site_id','','comment'), 'htmltype'=>'input_select', 'data'=>$sitelist),
- 'elite'=>array('name'=>L('iselite', '', 'special'), 'htmltype'=>'radio', 'defaultvalue'=>'0', 'data'=>array(L('no'), L('yes'))),
- 'thumb'=>array('name'=>L('get_thumb', '', 'special'), 'htmltype'=>'radio','defaultvalue'=>'0','data'=>array(L('no'), L('yes'))),
- 'listorder'=>array('name'=>L('order_type', '', 'special'), 'htmltype'=>'select', 'defaultvalue'=>'3', 'data'=>array(L('id_asc', '', 'special'), L('id_desc', '','special'), L('order_asc','','special'), L('order_desc', '','special'))),
- ),
- 'content_list'=>array(
- 'specialid'=>array('name'=>L('special_id','','special'),'htmltype'=>'input_select', 'data'=>$specials, 'ajax'=>array('name'=>L('for_type','','special'), 'action'=>'get_type', 'id'=>'typeid')),
- 'thumb'=>array('name'=>L('content_thumb','','special'),'htmltype'=>'radio','defaultvalue'=>'0','data'=>array(L('no'), L('yes'))),
- 'listorder'=>array('name'=>L('order_type', '', 'special'), 'htmltype'=>'select', 'defaultvalue'=>'3', 'data'=>array(L('id_asc', '', 'special'), L('id_desc', '','special'), L('order_asc','','special'), L('order_desc', '','special'))), //開源軟件:Vevb.com
- ),
- 'hits' => array(
- 'specialid' => array('name'=>L('special_id','','special'), 'htmltype'=>'input_select', 'data'=>$specials),
- 'listorder' => array('name' => L('order_type', '', 'special'), 'htmltype' => 'select', 'data'=>array(L('total','','special'), L('yesterday', '','special'), L('today','','special'), L('week','','special'), L('month','','special'))),
- ),
- );
- }
- }
- ?>
新聞熱點
疑難解答