国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > PhpCMS > 正文

【phpcms-v9】前臺content模塊控制器index.php文件分析-內容詳情頁

2024-09-10 07:15:44
字體:
來源:轉載
供稿:網友

【phpcms-v9】前臺content模塊控制器index.php文件分析-內容詳情頁代碼分析.

  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(!emptyempty($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  //Vevb.com 
  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 && !emptyempty($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(emptyempty($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(emptyempty($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. }  

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北票市| 北流市| 平安县| 青神县| 锦屏县| 霍州市| 慈溪市| 平凉市| 隆昌县| 玉门市| 九台市| 赤水市| 通许县| 新龙县| 和顺县| 厦门市| 东海县| 鸡西市| 永州市| 开阳县| 南丰县| 怀化市| 东乌珠穆沁旗| 泾源县| 台南县| 金华市| 尚志市| 鹿泉市| 平乐县| 舞阳县| 宁夏| 宝鸡市| 黄浦区| 绥江县| 白河县| 托克逊县| 白朗县| 社旗县| 镇巴县| 汝南县| 宝坻区|