【phpcms-v9】前台content模块控制器index.php文件分析-内容详情页代码分析

[html]  view plain  copy
 print ?
  1. //内容页:文章内容详情页、图片详情页、下载详情页走的都是show()方法  
  2. //路径:phpcms/modules/content/index.php控制器  
  3. public function show() {  
  4.         $catid = intval($_GET['catid']);                                //栏目id  
  5.         $id = intval($_GET['id']);                                      //新闻id  
  6.         //如果栏目id不存在或新闻id不存在,则给出提示信息  
  7.         if(!$catid || !$id) showmessage(L('information_does_not_exist'),'blank');  
  8.         $_userid = $this->_userid;                                       //用户id  
  9.         $_username = $this->_username;                                   //用户名  
  10.         $_groupid = $this->_groupid;                                 //用户会员组id  
  11.   
  12.         $page = intval($_GET['page']);                                  //当前页码  
  13.         $page = max($page,1);                                           //保证最小页码为1  
  14.         $siteids = getcache('category_content','commons');              //获取所有栏目所对应的站点id  
  15.         $siteid = $siteids[$catid];                                     //获取当前栏目的站点id  
  16.         $CATEGORYS = getcache('category_content_'.$siteid,'commons');   //获取当前站点下所有栏目的详细配置信息  
  17.           
  18.         if(!isset($CATEGORYS[$catid]) || $CATEGORYS[$catid]['type']!=0) showmessage(L('information_does_not_exist'),'blank');  
  19.         $this->category = $CAT = $CATEGORYS[$catid];                 //获取当前栏目的详细配置信息  
  20.         $this->category_setting = $CAT['setting'] = string2array($this->category['setting']);//当前栏目的setting配置信息  
  21.         $siteid = $GLOBALS['siteid'] = $CAT['siteid'];                  //当前栏目站点id  
  22.           
  23.         $MODEL = getcache('model','commons');                           //所有模型配置信息 1-文章模型 2-下载模型 3-图片模型  
  24.         $modelid = $CAT['modelid'];                                     //当前栏目所属模型id  
  25.         //当前模型id所对应的主表名称:文章模型-news ,下载模型-download , 图片模型-picture    
  26.         $tablename = $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];//当前模型id对应的主表名  
  27.         $r = $this->db->get_one(array('id'=>$id));                     //返回的主表数据,条件:where id=$id  
  28.         if(!$r || $r['status'] != 99) showmessage(L('info_does_not_exists'),'blank');  
  29.         //当前模型id所对应的副表名  
  30.         $this->db->table_name = $tablename.'_data';                       //当前模型id所对应的副表名  
  31.         $r2 = $this->db->get_one(array('id'=>$id));                        //返回的副表数据,条件:where id=$id  
  32.         $rs = $r2 ? array_merge($r,$r2) : $r;                           //如果有返回副表数据,则将主表数据与副表数据合并后再返回,否则返回主表数据  
  33.         //再次重新赋值,以数据库为准  
  34.         $catid = $CATEGORYS[$r['catid']]['catid'];                      //栏目id  
  35.         $modelid = $CATEGORYS[$catid]['modelid'];                       //模型id  
  36.           
  37.         require_once CACHE_MODEL_PATH.'content_output.class.php';  
  38.         $content_output = new content_output($modelid,$catid,$CATEGORYS);//主要用来对查询到的记录做一下过滤,仅此而已  
  39.         $data = $content_output->get($rs);                               //参数:查询到的数据  
  40.         //很重要的代码  
  41.         extract($data);                                                 //从数组中将变量导入到当前的符号表  
  42.           
  43.         //检查文章会员组权限  
  44.         //阅读权限字段的值,如果在添加内容时没有设置阅读权限,那么阅读权限groupids_view字段在数据库中的值为空,否则值为会员组id  
  45.         if($groupids_view && is_array($groupids_view)) {  
  46.             $_groupid = param::get_cookie('_groupid');                  //获取会员组id  
  47.             $_groupid = intval($_groupid);                              //会员组id  
  48.             if(!$_groupid) {                                            //如果没有登录  
  49.                 $forward = urlencode(get_url());                        //跳转网址  
  50.                 //如果没有登录,则给出提示信息  
  51.                 showmessage(L('login_website'),APP_PATH.'index.php?m=member&c=index&a=login&forward='.$forward);  
  52.             }  
  53.             //用户登录,但是没有在阅读权限的会员组中,则给出没有权限的提示信息  
  54.             if(!in_array($_groupid,$groupids_view)) showmessage(L('no_priv'));  
  55.         } else {//如果在添加内容时没有设置阅读权限,则会去判断栏目的访问权限                                                     //如果  
  56.             //根据栏目访问权限判断权限  
  57.             $_priv_data = $this->_category_priv($catid);  
  58.             if($_priv_data=='-1') {  
  59.                 $forward = urlencode(get_url());  
  60.                 showmessage(L('login_website'),APP_PATH.'index.php?m=member&c=index&a=login&forward='.$forward);  
  61.             } elseif($_priv_data=='-2') {  
  62.                 showmessage(L('no_priv'));  
  63.             }  
  64.         }  
  65.         if(module_exists('comment')) {                                  //判断模块是否安装  
  66.             $allow_comment = isset($allow_comment) ? $allow_comment : 1;//是否允许评论,默认情况下是允许评论的  
  67.         } else {  
  68.             $allow_comment = 0;                                         //如果评论模块不存在,则不允许评论  
  69.         }  
  70.         //阅读收费 类型     0-按点收费     1-按元收费     
  71.         $paytype = $rs['paytype'];  
  72.         $readpoint = $rs['readpoint'];                                  //收费多少                            
  73.         $allow_visitor = 1;                                             //是否支付过  
  74.         //$this->category_setting['defaultchargepoint']:默认收取点数或元数 ,在添加栏目时设置  
  75.         if($readpoint || $this->category_setting['defaultchargepoint']) {//一个条件为真即可  
  76.             if(!$readpoint) {//如果在添加内容时没有设置收费点数,则将添加栏目时设置的收费点数赋值给$readpoint  
  77.                 $readpoint = $this->category_setting['defaultchargepoint'];  //默认收费点数  
  78.                 $paytype = $this->category_setting['paytype'];               //默认支付类型 0-点  1-元  
  79.             }  
  80.               
  81.             //检查是否支付过  
  82.             $allow_visitor = self::_check_payment($catid.'_'.$id,$paytype);  
  83.             if(!$allow_visitor) {  
  84.                 $http_referer = urlencode(get_url());  
  85.                 $allow_visitor = sys_auth($catid.'_'.$id.'|'.$readpoint.'|'.$paytype).'&http_referer='.$http_referer;  
  86.             } else {  
  87.                 $allow_visitor = 1;  
  88.             }  
  89.         }  
  90.         //最顶级栏目ID  
  91.         $arrparentid = explode(',', $CAT['arrparentid']);                   //所有的父级栏目id数组  
  92.         $top_parentid = $arrparentid[1] ? $arrparentid[1] : $catid;         //最顶级栏目id  
  93.         //如果添加内容时未设定内容详情模板页,则按添加栏目时设置的内容详情模板页  
  94.         $template = $template ? $template : $CAT['setting']['show_template'];  
  95.         if(!$template) $template = 'show';  
  96.         //SEO  
  97.         $seo_keywords = '';  
  98.         //如果当前内容的关键字不为空,则以逗号连接成一个字符串,如:"我的,影子,奔跑 "  
  99.         if(!empty($keywords)) $seo_keywords = implode(',',$keywords);  
  100.         $SEO = seo($siteid, $catid, $title, $description, $seo_keywords);  
  101.           
  102.         define('STYLE',$CAT['setting']['template_list']);//模板风格  
  103.         if(isset($rs['paginationtype'])) {//分页类型:0-不分页           1-自动分页           2-手动分页  
  104.             $paginationtype = $rs['paginationtype'];  
  105.             $maxcharperpage = $rs['maxcharperpage'];//每页最大显示的字符数,默认为10000,自动分页会生效  
  106.         }  
  107.         $pages = $titles = '';  
  108.         if($rs['paginationtype']==1) {//1-自动分页  
  109.             //自动分页  
  110.             if($maxcharperpage < 10) $maxcharperpage = 500;  
  111.             $contentpage = pc_base::load_app_class('contentpage');      //文章内容分页类  
  112.             $content = $contentpage->get_data($content,$maxcharperpage);//处理并返回字符串  
  113.         }  
  114.         if($rs['paginationtype']!=0) {  
  115.             //手动分页  
  116.             $CONTENT_POS = strpos($content, '[page]');  
  117.             if($CONTENT_POS !== false) {          
  118.                 $this->url = pc_base::load_app_class('url', 'content');        
  119.                 //将内容$content以[page]分割为一个数组  
  120.                 //[0]=>...   [1] => 全体与众嘉宾合影[/page]...     [2] => 张静初[/page]...          
  121.                 $contents = array_filter(explode('[page]', $content));//以[page]分割为一个数组  
  122.                 $pagenumber = count($contents);//分割成了多少页  
  123.                 if (strpos($content, '[/page]')!==false && ($CONTENT_POS<7)) {//判断[page]出现的位置是否在第一位  
  124.                     $pagenumber--;  
  125.                 }  
  126.                 /**  
  127.                  * $pageurls大概格式如下:  
  128.                  * Array  
  129.                  *  (  
  130.                  *      [1] => Array  
  131.                  *          (  
  132.                  *              [1] => http://zhencms.com/index.php?m=content&c=index&a=show&catid=18&id=8  
  133.                  *              [0] => http://zhencms.com/index.php?m=content&c=index&a=show&catid=18&id=8  
  134.                  *          )  
  135.                  *    
  136.                  *      [2] => Array  
  137.                  *          (  
  138.                  *              [1] => http://zhencms.com/index.php?m=content&c=index&a=show&catid=18&id=8&page=2  
  139.                  *              [0] => http://zhencms.com/index.php?m=content&c=index&a=show&catid=18&id=8&page=2  
  140.                  *          )  
  141.                  *    
  142.                  *      [3] => Array  
  143.                  *          (  
  144.                  *              [1] => http://zhencms.com/index.php?m=content&c=index&a=show&catid=18&id=8&page=3  
  145.                  *              [0] => http://zhencms.com/index.php?m=content&c=index&a=show&catid=18&id=8&page=3  
  146.                  *          )  
  147.                  *    
  148.                  *  )  
  149.   
  150.                  */  
  151.                 for($i=1; $i<=$pagenumber; $i++) {  
  152.                     //参数1:内容id   参数2:当前页        参数3:栏目id     参数4:添加时间  
  153.                     //作用:替换urlrules重写规则中的变量,如:index.php?m=content&c=index&a=lists&catid={$catid}|index.php?m=content&c=index&a=lists&catid={$catid}&page={$page}  
  154.                     $pageurls[$i] = $this->url->show($id, $i, $catid, $rs['inputtime']);//内容页的链接  
  155.                 }  
  156.                   
  157.                 $END_POS = strpos($content, '[/page]');//标题的象征  
  158.                 if($END_POS !== false) {  
  159.                     if($CONTENT_POS>7) {  
  160.                         //如:[page]《我的影子在奔跑》开机 张静初演隐忍母亲[/page]  
  161.                         $content = '[page]'.$title.'[/page]'.$content;  
  162.                     }  
  163.                     if(preg_match_all("|
    page
    (.*)
    /page
    |U", $content, $m, PREG_PATTERN_ORDER)) {  
  164.                         foreach($m[1] as $k=>$v) {  
  165.                             $p = $k+1;  
  166.                             $titles[$p]['title'] = strip_tags($v);  
  167.                             $titles[$p]['url'] = $pageurls[$p][0];  
  168.                         }  
  169.                     }  
  170.                     /**  
  171.                      *print_r($titles)  
  172.                      *Array  
  173.                      *  (  
  174.                      *      [1] => Array  
  175.                      *          (  
  176.                      *              [title] => 《我的影子在奔跑》开机 张静初演隐忍母亲  
  177.                      *              [url] => http://zhencms.com/index.php?m=content&c=index&a=show&catid=18&id=8  
  178.                      *          )  
  179.                      *    
  180.                      *      [2] => Array  
  181.                      *          (  
  182.                      *              [title] => 全体与众嘉宾合影  
  183.                      *              [url] => http://zhencms.com/index.php?m=content&c=index&a=show&catid=18&id=8&page=2  
  184.                      *          )  
  185.                      *    
  186.                      *      [3] => Array  
  187.                      *          (  
  188.                      *              [title] => 张静初  
  189.                      *              [url] => http://zhencms.com/index.php?m=content&c=index&a=show&catid=18&id=8&page=3  
  190.                      *          )  
  191.                      *    
  192.                      *  )  
  193.   
  194.                      */  
  195.                 }  
  196.                 //当不存在 [/page]时,则使用下面分页         只有分页,没有子标题时  
  197.                 //参数1:总页码              参数2:当前页码            参数3:链接地址  
  198.                 $pages = content_pages($pagenumber,$page, $pageurls);//分页函数,路径:phpcms/modules/content/functions/util.func.php  
  199.                   
  200.                 //判断[page]出现的位置是否在第一位   
  201.                 if($CONTENT_POS<7) {  
  202.                     $content = $contents[$page];//$contents:内容段数组    $contents[$page]:第几页内容  
  203.                 } else {  
  204.                     if ($page==1 && !empty($titles)) {  
  205.                         //如:《我的影子在奔跑》开机 张静初演隐忍母亲[/page]导演方刚亮  
  206.                         $content = $title.'[/page]'.$contents[$page-1];  
  207.                     } else {  
  208.                         //如:全体与众嘉宾合影[/page]全体与众嘉宾合影  
  209.                         $content = $contents[$page-1];  
  210.                     }  
  211.                 }  
  212.                 /**  
  213.                  * echo $content;  
  214.                  * 如:全体与众嘉宾合影[/page]全体与众嘉宾合影  
  215.                  */  
  216.                 if($titles) {//子标题  
  217.                     list($title, $content) = explode('[/page]', $content);//$title-子标题      $content-内容  
  218.                     $content = trim($content);//内容  
  219.                     if(strpos($content,'</p>')===0) {  
  220.                         $content = '<p>'.$content;//左补齐  
  221.                     }  
  222.                     if(stripos($content,'<p>')===0) {  
  223.                         $content = $content.'</p>';//右补齐  
  224.                     }  
  225.                 }  
  226.             }  
  227.         }  
  228.         $this->db->table_name = $tablename;//主表  
  229.         //上一篇  
  230.         $previous_page = $this->db->get_one("`catid` = '$catid' AND `id`<'$id' AND `status`=99",'*','id DESC');  
  231.         //下一篇  
  232.         $next_page = $this->db->get_one("`catid`= '$catid' AND `id`>'$id' AND `status`=99");  
  233.   
  234.         if(empty($previous_page)) {//如果 上一篇 为空 ,则显示 第一页  
  235.             $previous_page = array('title'=>L('first_page'), 'thumb'=>IMG_PATH.'nopic_small.gif', 'url'=>'javascript:alert(\''.L('first_page').'\');');  
  236.         }  
  237.   
  238.         if(empty($next_page)) {//如果 下一篇 为空,则显示 最后一页  
  239.             $next_page = array('title'=>L('last_page'), 'thumb'=>IMG_PATH.'nopic_small.gif', 'url'=>'javascript:alert(\''.L('last_page').'\');');  
  240.         }  
  241.         include template('content',$template);//显示content模块的$template模板  
  242. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值