用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - php代码库

【phpcms-v9】前台{pc}专题标签调用类分析

2016-11-03 作者: fanke4999举报

[php]代码库

[php] view plain copy print?
<?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'))),  
            ),  
            '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'))),  
            ),  
        );  
    }  
}  
?>  


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...