国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
phpcms V9 首頁(yè)模板文件解析(轉(zhuǎn)),
Home Backend Development PHP Tutorial phpcms V9 home page template file analysis (transfer), _PHP tutorial

phpcms V9 home page template file analysis (transfer), _PHP tutorial

Jul 12, 2016 am 08:49 AM
http phpcms document template parse change front page

phpcms V9 首頁(yè)模板文件解析(轉(zhuǎn)),

轉(zhuǎn)自:http://www.cnblogs.com/Braveliu/p/5100018.html

轉(zhuǎn)在了解了《phpcms V9 URL訪問(wèn)解析》之后,我們已經(jīng)知道首頁(yè)最終執(zhí)行的是content模塊下index控制器的init方法。

下面, 我們逐步分析過(guò)程如下:

第一、首頁(yè)默認(rèn)執(zhí)行的是index.php?m=content&c=index&a=init

如下代碼(路徑:phpcms\modules\content\index.php),先從init函數(shù)分析:

phpcms V9 home page template file analysis (transfer), _PHP tutorial

 1 class index 
 2 {
 3     private $db;
 4     function __construct() 
 5     {
 6         $this->db = pc_base::load_model('content_model');
 7         $this->_userid = param::get_cookie('_userid');
 8         $this->_username = param::get_cookie('_username');
 9         $this->_groupid = param::get_cookie('_groupid');
10     }
11     //首頁(yè)
12     public function init() 
13     {
14         if(isset($_GET['siteid'])) 
15         {
16             $siteid = intval($_GET['siteid']); //當(dāng)前站點(diǎn)id  函數(shù)intval作用變量轉(zhuǎn)成整數(shù)類型
17         } 
18         else 
19         {
20             $siteid = 1;
21         }
22         $siteid = $GLOBALS['siteid'] = max($siteid,1);
23         define('SITEID', $siteid);
24         $_userid = $this->_userid;
25         $_username = $this->_username;
26         $_groupid = $this->_groupid;
27         //SEO 搜索引擎優(yōu)化信息
28         $SEO = seo($siteid); //調(diào)用第二步,獲取當(dāng)前站點(diǎn)當(dāng)前欄目下生成的SEO信息
29         $sitelist  = getcache('sitelist','commons'); //緩存后臺(tái)設(shè)置的所有站點(diǎn)配置信息
30         $default_style = $sitelist[$siteid]['default_style']; //當(dāng)前站點(diǎn)默認(rèn)模板風(fēng)格配置
31         $CATEGORYS = getcache('category_content_'.$siteid,'commons'); //當(dāng)前站點(diǎn)所有欄目詳細(xì)配置信息
32         include template('content','index',$default_style); //調(diào)用第三步:模板調(diào)用
33     }

phpcms V9 home page template file analysis (transfer), _PHP tutorial

第二、獲取SEO信息:phpcms/libs/functions/global.func.php

phpcms V9 home page template file analysis (transfer), _PHP tutorial

 1 /**
 2  * 生成SEO
 3  * @param $siteid       站點(diǎn)ID
 4  * @param $catid        欄目ID
 5  * @param $title        標(biāo)題
 6  * @param $description  描述
 7  * @param $keyword      關(guān)鍵詞
 8  */
 9 function seo($siteid, $catid = '', $title = '', $description = '', $keyword = '') 
10 {
11     if (!empty($title))
12         $title = strip_tags($title); //過(guò)濾title。 strip_tags() 函數(shù)剝?nèi)プ址械?HTML、XML 以及 PHP 的標(biāo)簽。
13     if (!empty($description)) 
14         $description = strip_tags($description); //過(guò)濾description
15     if (!empty($keyword)) 
16         $keyword = str_replace(' ', ',', strip_tags($keyword)); //過(guò)濾keyword
17     $sites = getcache('sitelist', 'commons'); //獲取所有站點(diǎn)詳細(xì)配置信息
18     $site = $sites[$siteid];    //當(dāng)前站點(diǎn)詳細(xì)配置信息
19     $cat = array();
20     if (!empty($catid))     //欄目ID不為空
21     {
22         $siteids = getcache('category_content','commons'); //獲取所有欄目對(duì)應(yīng)的站點(diǎn)ID緩存文件,格式:欄目ID=>站點(diǎn)ID
23         $siteid = $siteids[$catid]; //當(dāng)前欄目對(duì)應(yīng)的站點(diǎn)ID
24         $categorys = getcache('category_content_'.$siteid,'commons'); //獲取當(dāng)前站點(diǎn)下所有欄目的詳細(xì)配置信息
25         $cat = $categorys[$catid];    //當(dāng)前站點(diǎn)下當(dāng)前欄目的詳細(xì)配置信息 
26         $cat['setting'] = string2array($cat['setting']); //當(dāng)前站點(diǎn)當(dāng)前欄目詳細(xì)配置信息的setting設(shè)置信息,轉(zhuǎn)化為數(shù)組
27     }
28     //站點(diǎn)title
29     $seo['site_title'] =isset($site['site_title']) && !empty($site['site_title']) ? $site['site_title'] : $site['name'];
30     //關(guān)鍵字
31     $seo['keyword'] = !empty($keyword) ? $keyword : $site['keywords'];
32     //描述
33     $seo['description'] = isset($description) && !empty($description) ? $description : (isset($cat['setting']['meta_description']) && !empty($cat['setting']['meta_description']) ? $cat['setting']['meta_description'] : (isset($site['description']) && !empty($site['description']) ? $site['description'] : ''));
34     //標(biāo)題
35     $seo['title'] =  (isset($title) && !empty($title) ? $title.' - ' : '').(isset($cat['setting']['meta_title']) && !empty($cat['setting']['meta_title']) ? $cat['setting']['meta_title'].' - ' : (isset($cat['catname']) && !empty($cat['catname']) ? $cat['catname'].' - ' : ''));
36     foreach ($seo as $k=>$v) 
37     {
38         $seo[$k] = str_replace(array("\n","\r"),    '', $v); //將seo信息中\(zhòng)n和\r替換為空
39     }
40     return $seo;    //返回seo數(shù)組信息
41 }

phpcms V9 home page template file analysis (transfer), _PHP tutorial

第三、模板調(diào)用:phpcms/libs/functions/global.func.php

phpcms V9 home page template file analysis (transfer), _PHP tutorial

 1 /**
 2  * 模板調(diào)用
 3  *
 4  * @param $module 默認(rèn)為content
 5  * @param $template 默認(rèn)為index
 6  * @param $istag
 7  * @return unknown_type
 8  */
 9 function template($module = 'content', $template = 'index', $style = '') 
10 {
11     if(strpos($module, 'plugin/')!== false) 
12     { // 檢測(cè)模塊里面是否包含plugin字符,這里進(jìn)行了對(duì)插件模板的判斷,插件模板需要調(diào)用p_template過(guò)程解析
13         $plugin = str_replace('plugin/', '', $module);
14         return p_template($plugin, $template,$style);
15     }
16     $module = str_replace('/', DIRECTORY_SEPARATOR, $module);
17     if(!empty($style) && preg_match('/([a-z0-9\-_]+)/is',$style)) 
18     {
19     } 
20     elseif (empty($style) && !defined('STYLE')) 
21     {
22         if(defined('SITEID'))  // 是否定義了SITEID常量
23         {
24             $siteid = SITEID;
25         } 
26         else 
27         {
28             $siteid = param::get_cookie('siteid');
29         }
30         if (!$siteid) $siteid = 1;
31         $sitelist = getcache('sitelist','commons'); //獲取所有站點(diǎn)的詳細(xì)配置信息
32         if(!empty($siteid)) 
33         {
34             $style = $sitelist[$siteid]['default_style']; //獲取當(dāng)前站點(diǎn)的默認(rèn)模板風(fēng)格
35         }
36     } 
37     elseif (empty($style) && defined('STYLE')) 
38     {
39         $style = STYLE;
40     } 
41     else 
42     {
43         $style = 'default';
44     }
45     if(!$style) 
46         $style = 'default';
47     //模板解析類,文件路徑:phpcms/libs/classes/template_cache.class.php
48     $template_cache = pc_base::load_sys_class('template_cache');
49     //編譯文件緩存路徑:根目錄/caches/caches_template/default/content/index.php
50     $compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php';
51     //首頁(yè)模板文件,如文件路徑:phpcms/templates/dafault/content/index.html
52     if(file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html')) 
53     {
54         //如果編譯文件不存在或者說(shuō)模板文件的創(chuàng)建時(shí)間大于編譯文件的生成時(shí)間,則重新編譯
55         if(!file_exists($compiledtplfile) || (@filemtime(PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') > @filemtime($compiledtplfile))) 
56         {
57             $template_cache->template_compile($module, $template, $style); //調(diào)用第四步:適用模板風(fēng)格不是default的情況
58         }
59     } 
60     else 
61     {
62         //編譯文件緩存路徑:根目錄/caches/caches_template/default/content/index.php 
63         $compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php';
64         //如果編譯文件不存在或者說(shuō)前臺(tái)公共的模板文件存在,并且前臺(tái)公共模板文件的創(chuàng)建時(shí)間大于編譯文件的生成時(shí)間
65         if(!file_exists($compiledtplfile) || (file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') && filemtime(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') > filemtime($compiledtplfile))) 
66         {
67             //重新編譯
68             $template_cache->template_compile($module, $template, 'default');
69         } 
70         elseif (!file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html')) 
71         {  //如果前臺(tái)公共的模板文件不存在的話,則提示模板不存在
72             showmessage('Template does not exist.'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html');
73         }
74     }
75     //返回編譯文件
76     return $compiledtplfile;
77 }

phpcms V9 home page template file analysis (transfer), _PHP tutorial

第四、模板解析:phpcms/libs/classes/template_cache.class.php

phpcms V9 home page template file analysis (transfer), _PHP tutorial

 1 /**
 2  *  模板解析緩存
 3  */
 4 final class template_cache 
 5 {
 6     
 7     /**
 8      * 編譯模板
 9      *
10      * @param $module    模塊名稱
11      * @param $template    模板文件名
12      * @param $istag    是否為標(biāo)簽?zāi)0?13      * @return unknown
14      */
15     
16     public function template_compile($module, $template, $style = 'default') 
17     {
18         if(strpos($module, '/')=== false) // 如果“/”不存在
19         {
20             //路徑:phpcms/templates/default/content/index.html 如:首頁(yè)公共模板文件  
21             $tplfile = $_tpl = PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html';
22         } 
23         elseif (strpos($module, 'yp/') !== false) 
24         {
25             $module = str_replace('/', DIRECTORY_SEPARATOR, $module);
26             $tplfile = $_tpl = PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html';
27         } 
28         else 
29         {
30             $plugin = str_replace('plugin/', '', $module);
31             $module = str_replace('/', DIRECTORY_SEPARATOR, $module);
32             $tplfile = $_tpl = PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.html';
33         }
34         if ($style != 'default' && !file_exists ( $tplfile )) 
35         {
36             $style = 'default';
37             $tplfile = PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html';
38         }
39         if (! file_exists ( $tplfile ))
40         {
41             //如果公共模板文件不存在,則提示模板文件不存在,如:/templates/default/content/index.html is not exists!
42             showmessage ( "templates".DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.".html is not exists!" );
43         }
44         //獲取公共模板文件中的內(nèi)容
45         $content = @file_get_contents ( $tplfile );
46         //要生成的編譯文件所在目錄
47         $filepath = CACHE_PATH.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR;
48         if(!is_dir($filepath)) 
49         {
50             //如果目錄不存在,則層級(jí)創(chuàng)建所有目錄
51             mkdir($filepath, 0777, true);
52         }
53         //編譯文件的全路徑
54         $compiledtplfile = $filepath.$template.'.php';
55         //解析公共模板文件中的內(nèi)容及標(biāo)簽,并返回解析后的內(nèi)容  
56         $content = $this->template_parse($content); // 調(diào)用下一個(gè)過(guò)程
57         //將解析后的公共模板文件內(nèi)容寫入到要生成的編譯文件中
58         $strlen = file_put_contents ( $compiledtplfile, $content );
59         //給生成的編譯文件設(shè)置權(quán)限
60         chmod ( $compiledtplfile, 0777 );
61         //返回寫入編譯文件的字節(jié)數(shù)
62         return $strlen;
63     }
64 
65     /**
66      * 解析模板
67      *
68      * @param $str    模板內(nèi)容
69      * @return ture
70      */
71     public function template_parse($str) {
72         $str = preg_replace ( "/\{template\s+(.+)\}/", "<?php include template(\\1); ?>", $str );
73         $str = preg_replace ( "/\{include\s+(.+)\}/", "<?php include \\1; ?>", $str );
74         $str = preg_replace ( "/\{php\s+(.+)\}/", "<?php \\1?>", $str );
75         $str = preg_replace ( "/\{if\s+(.+?)\}/", "<?php if(\\1) { ?>", $str );
76         $str = preg_replace ( "/\{else\}/", "<?php } else { ?>", $str );
77         $str = preg_replace ( "/\{elseif\s+(.+?)\}/", "<?php } elseif (\\1) { ?>", $str );
78         $str = preg_replace ( "/\{\/if\}/", "<?php } ?>", $str );
79         //for 循環(huán)
80         $str = preg_replace("/\{for\s+(.+?)\}/","<?php for(\\1) { ?>",$str);
81         $str = preg_replace("/\{\/for\}/","<?php } ?>",$str);
82         //++ --
83         $str = preg_replace("/\{\+\+(.+?)\}/","<?php ++\\1; ?>",$str);
84         $str = preg_replace("/\{\-\-(.+?)\}/","<?php ++\\1; ?>",$str);
85         $str = preg_replace("/\{(.+?)\+\+\}/","<?php \\1++; ?>",$str);
86         $str = preg_replace("/\{(.+?)\-\-\}/","<?php \\1--; ?>",$str);
87         $str = preg_replace ( "/\{loop\s+(\S+)\s+(\S+)\}/", "<?php \$n=1;if(is_array(\\1)) foreach(\\1 AS \\2) { ?>", $str );
88         $str = preg_replace ( "/\{loop\s+(\S+)\s+(\S+)\s+(\S+)\}/", "<?php \$n=1; if(is_array(\\1)) foreach(\\1 AS \\2 => \\3) { ?>", $str );
89         $str = preg_replace ( "/\{\/loop\}/", "<?php \$n++;}unset(\$n); ?>", $str );
90         $str = preg_replace ( "/\{([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/", "<?php echo \\1;?>", $str );
91         $str = preg_replace ( "/\{\\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/", "<?php echo \\1;?>", $str );
92         $str = preg_replace ( "/\{(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}/", "<?php echo \\1;?>", $str );
93         $str = preg_replace("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/es", "\$this->addquote('<?php echo \\1;?>')",$str);
94         $str = preg_replace ( "/\{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)\}/s", "<?php echo \\1;?>", $str );
95         $str = preg_replace("/\{pc:(\w+)\s+([^}]+)\}/ie", "self::pc_tag('$1','$2', '$0')", $str);
96         $str = preg_replace("/\{\/pc\}/ie", "self::end_pc_tag()", $str);
97         $str = "<?php defined('IN_PHPCMS') or exit('No permission resources.'); ?>" . $str;
98         return $str;
99     }

phpcms V9 home page template file analysis (transfer), _PHP tutorial

第五、PC標(biāo)簽的解析:phpcms/libs/classes/template_cache.class.php 文件

phpcms V9 home page template file analysis (transfer), _PHP tutorial

  1 /**
  2      * 解析PC標(biāo)簽
  3      * @param string $op 操作方式
  4      * @param string $data 參數(shù)
  5      * @param string $html 匹配到的所有的HTML代碼
  6      */
  7     public static function pc_tag($op, $data, $html) 
  8     {
  9         preg_match_all("/([a-z]+)\=[\"]?([^\"]+)[\"]?/i", stripslashes($data), $matches, PREG_SET_ORDER);
 10         $arr = array('action','num','cache','page', 'pagesize', 'urlrule', 'return', 'start');
 11         $tools = array('json', 'xml', 'block', 'get');
 12         $datas = array();
 13         $tag_id = md5(stripslashes($html));
 14         //可視化條件
 15         $str_datas = 'op='.$op.'&tag_md5='.$tag_id;
 16         foreach ($matches as $v) 
 17         {
 18             $str_datas .= $str_datas ? "&$v[1]=".($op == 'block' && strpos($v[2], '$') === 0 ? $v[2] : urlencode($v[2])) : "$v[1]=".(strpos($v[2], '$') === 0 ? $v[2] : urlencode($v[2]));
 19             if(in_array($v[1], $arr)) 
 20             {
 21                 $$v[1] = $v[2];//如果pc標(biāo)簽中參數(shù)在默認(rèn)參數(shù)數(shù)組$arr中存在,則將參數(shù)轉(zhuǎn)換為變量,如:$page=value等 
 22                 continue;
 23             }
 24             $datas[$v[1]] = $v[2];//如果pc標(biāo)簽中參數(shù)不在默認(rèn)參數(shù)數(shù)組$arr中存在,則直接將其放置到$datas[參數(shù)名]=value中 
 25         }
 26         $str = '';
 27         $num = isset($num) && intval($num) ? intval($num) : 20;
 28         $cache = isset($cache) && intval($cache) ? intval($cache) : 0;
 29         $return = isset($return) && trim($return) ? trim($return) : 'data';
 30         if (!isset($urlrule)) $urlrule = '';
 31         if (!empty($cache) && !isset($page)) 
 32         {
 33             $str .= '$tag_cache_name = md5(implode(\'&\','.self::arr_to_html($datas).').\''.$tag_id.'\');if(!$'.$return.' = tpl_cache($tag_cache_name,'.$cache.')){';
 34         }
 35         if (in_array($op,$tools)) 
 36         { //pc標(biāo)簽分兩大類:工具類和模塊類。工具類執(zhí)行如下代碼
 37             switch ($op) 
 38             {
 39                 case 'json':
 40                         if (isset($datas['url']) && !empty($datas['url'])) 
 41                         {
 42                             $str .= '$json = @file_get_contents(\''.$datas['url'].'\');';
 43                             $str .= '$'.$return.' = json_decode($json, true);';
 44                         }
 45                     break;
 46                     
 47                 case 'xml':
 48                         $str .= '$xml = pc_base::load_sys_class(\'xml\');';
 49                         $str .= '$xml_data = @file_get_contents(\''.$datas['url'].'\');';
 50                         $str .= '$'.$return.' = $xml->xml_unserialize($xml_data);';
 51                     break;
 52                     
 53                 case 'get':
 54                         $str .= 'pc_base::load_sys_class("get_model", "model", 0);';
 55                         if ($datas['dbsource']) 
 56                         {
 57                             $dbsource = getcache('dbsource', 'commons');
 58                             if (isset($dbsource[$datas['dbsource']])) 
 59                             {
 60                                 $str .= '$get_db = new get_model('.var_export($dbsource,true).', \''.$datas['dbsource'].'\');';
 61                             } 
 62                             else 
 63                             {
 64                                 return false;
 65                             }
 66                         } 
 67                         else 
 68                         {
 69                             $str .= '$get_db = new get_model();';
 70                         }
 71                         $num = isset($num) && intval($num) > 0 ? intval($num) : 20;
 72                         if (isset($start) && intval($start)) 
 73                         {
 74                             $limit = intval($start).','.$num;
 75                         } 
 76                         else 
 77                         {
 78                             $limit = $num;
 79                         }
 80                         if (isset($page)) 
 81                         {
 82                             $str .= '$pagesize = '.$num.';';
 83                             $str .= '$page = intval('.$page.') ? intval('.$page.') : 1;if($page<=0){$page=1;}';
 84                             $str .= '$offset = ($page - 1) * $pagesize;';
 85                             $limit = '$offset,$pagesize';
 86                             $sql = 'SELECT COUNT(*) as count FROM ('.$datas['sql'].') T';
 87                             $str .= '$r = $get_db->sql_query("'.$sql.'");$s = $get_db->fetch_next();$pages=pages($s[\'count\'], $page, $pagesize, $urlrule);';
 88                         }
 89                         
 90                         $str .= '$r = $get_db->sql_query("'.$datas['sql'].' LIMIT '.$limit.'");while(($s = $get_db->fetch_next()) != false) {$a[] = $s;}$'.$return.' = $a;unset($a);';
 91                     break;
 92                     
 93                 case 'block':
 94                     $str .= '$block_tag = pc_base::load_app_class(\'block_tag\', \'block\');';
 95                     $str .= 'echo $block_tag->pc_tag('.self::arr_to_html($datas).');';
 96                     break;
 97             }
 98         } 
 99         else 
100         {    //pc標(biāo)簽分兩大類:工具類和模塊類。模塊類執(zhí)行如下代碼
101             if (!isset($action) || empty($action)) 
102                 return false;
103             //content模塊:phpcms/modules/content/classes/content_tag.class.php  
104             if (module_exists($op) && file_exists(PC_PATH.DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR.$op.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.$op.'_tag.class.php')) 
105             {
106                 //content_tag.class.php  檢查content_tag類中是否存在的某方法
107                 $str .= '$'.$op.'_tag = pc_base::load_app_class("'.$op.'_tag", "'.$op.'");if (method_exists($'.$op.'_tag, \''.$action.'\')) {';    
108                 if (isset($start) && intval($start)) 
109                 {
110                     $datas['limit'] = intval($start).','.$num; //如:limit 0 , 10
111                 } 
112                 else 
113                 {
114                     $datas['limit'] = $num; //如:limit 10
115                 }
116                 if (isset($page)) //分頁(yè)參數(shù)
117                 {
118                     $str .= '$pagesize = '.$num.';'; //每頁(yè)顯示數(shù)據(jù)量
119                     $str .= '$page = intval('.$page.') ? intval('.$page.') : 1;if($page<=0){$page=1;}';//當(dāng)前頁(yè)碼
120                     $str .= '$offset = ($page - 1) * $pagesize;';//要查詢數(shù)據(jù)的開(kāi)始位置
121                     $datas['limit'] = '$offset.",".$pagesize';
122                     $datas['action'] = $action; //方法,如,content_tag.class.php中的lists方法 
123                     $str .= '$'.$op.'_total = $'.$op.'_tag->count('.self::arr_to_html($datas).');';//分頁(yè)方法
124                     $str .= '$pages = pages($'.$op.'_total, $page, $pagesize, $urlrule);';
125                 }
126                 //調(diào)用第七步:content_tag.class.php中方法
127                 $str .= '$'.$return.' = $'.$op.'_tag->'.$action.'('.self::arr_to_html($datas).');';
128                 $str .= '}';
129             } 
130         }
131         if (!empty($cache) && !isset($page)) 
132         {
133             $str .= 'if(!empty($'.$return.')){setcache($tag_cache_name, $'.$return.', \'tpl_data\');}';
134             $str .= '}';
135         }
136         /**  
137          * 解析結(jié)果大概如下所示:  
138          <?php  
139          if(defined('IN_ADMIN')  && !defined('HTML')) 
140          {  
141             echo "<div class=\"admin_piao\" pc_action=\"content\" data=\"op=content&tag_md5=2d4b9e3c7c2cc4bd0cec8b1fac9ae764&action=position&posid=12&thumb=1&order=listorder+DESC&num=10\">  
142             <a href=\"javascript:void(0)\" class=\"admin_piao_edit\">編輯</a>";  
143          }  
144          $content_tag = pc_base::load_app_class("content_tag", "content");  
145          if (method_exists($content_tag, 'position')) 
146          {  
147             $data = $content_tag->position(array('posid'=>'12','thumb'=>'1','order'=>'listorder DESC','limit'=>'10',));  
148          }
149         ?>
150          */
151         return "<"."?php if(defined('IN_ADMIN')  && !defined('HTML')) {echo \"<div class=\\\"admin_piao\\\" pc_action=\\\"".$op."\\\" data=\\\"".$str_datas."\\\"><a href=\\\"javascript:void(0)\\\" class=\\\"admin_piao_edit\\\">".($op=='block' ? L('block_add') : L('edit'))."</a>\";}".$str."?".">";
152     }

phpcms V9 home page template file analysis (transfer), _PHP tutorial

第六、PC標(biāo)簽類。文件路徑:phpcms/modules/content/classes/content_tag.class.php

phpcms V9 home page template file analysis (transfer), _PHP tutorial

  1 class content_tag 
  2 {
  3     private $db;
  4     public function __construct() 
  5     {
  6         $this->db = pc_base::load_model('content_model'); //調(diào)用第七步,數(shù)據(jù)模型,對(duì)應(yīng)數(shù)據(jù)表為news和news_data
  7         $this->position = pc_base::load_model('position_data_model'); //數(shù)據(jù)模型
  8     }
  9     /**
 10      * 初始化模型
 11      * @param $catid
 12      */
 13     public function set_modelid($catid) 
 14     {
 15         static $CATS;
 16         $siteids = getcache('category_content','commons'); //獲取所有欄目所屬的站點(diǎn)id
 17         if(!$siteids[$catid]) 
 18             return false; //不存在此欄目,返回false
 19         $siteid = $siteids[$catid]; //當(dāng)前欄目所屬站點(diǎn)id
 20         if ($CATS[$siteid]) 
 21         {
 22             $this->category = $CATS[$siteid];
 23         } 
 24         else 
 25         {
 26             //獲取當(dāng)前站點(diǎn)id下所有欄目的配置信息
 27             $CATS[$siteid] = $this->category = getcache('category_content_'.$siteid,'commons');
 28         }
 29         if($this->category[$catid]['type']!=0) 
 30             return false; //如果不為內(nèi)部欄目,返回false  0-內(nèi)部欄目 1-單網(wǎng)頁(yè) 2-外部鏈接
 31         $this->modelid = $this->category[$catid]['modelid']; //獲取當(dāng)前欄目所屬模型id 
 32         $this->db->set_model($this->modelid); //調(diào)用第七步
 33         $this->tablename = $this->db->table_name; //數(shù)據(jù)表名
 34         if(empty($this->category)) 
 35         {
 36             //當(dāng)前站點(diǎn)id下所有欄目的配置信息
 37             return false;
 38         } 
 39         else
 40         {
 41             return true;
 42         }
 43     }
 44     /**
 45      * 分頁(yè)統(tǒng)計(jì)
 46      * @param $data
 47      */
 48     public function count($data) 
 49     {
 50         if($data['action'] == 'lists') 
 51         {
 52             $catid = intval($data['catid']);
 53             if(!$this->set_modelid($catid)) return false;
 54             if(isset($data['where'])) 
 55             {
 56                 $sql = $data['where'];
 57             } 
 58             else 
 59             {
 60                 if($this->category[$catid]['child']) 
 61                 {
 62                     $catids_str = $this->category[$catid]['arrchildid'];
 63                     $pos = strpos($catids_str,',')+1;
 64                     $catids_str = substr($catids_str, $pos);
 65                     $sql = "status=99 AND catid IN ($catids_str)";
 66                 } 
 67                 else 
 68                 {
 69                     $sql = "status=99 AND catid='$catid'";
 70                 }
 71             }
 72             return $this->db->count($sql);
 73         }
 74     }
 75     
 76     /**
 77      * 列表頁(yè)標(biāo)簽
 78      * @param $data
 79      */
 80     public function lists($data) 
 81     {
 82         $catid = intval($data['catid']);
 83         if(!$this->set_modelid($catid)) 
 84             return false;
 85         if(isset($data['where'])) //如果pc標(biāo)簽中設(shè)置了條件
 86         {
 87             $sql = $data['where']; //pc標(biāo)簽中的條件
 88         } 
 89         else 
 90         {
 91             $thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
 92             if($this->category[$catid]['child']) 
 93             {
 94                 $catids_str = $this->category[$catid]['arrchildid'];
 95                 $pos = strpos($catids_str,',')+1;
 96                 $catids_str = substr($catids_str, $pos);
 97                 $sql = "status=99 AND catid IN ($catids_str)".$thumb;
 98             } 
 99             else 
100             {
101                 $sql = "status=99 AND catid='$catid'".$thumb;
102             }
103         }
104         $order = $data['order']; //pc標(biāo)簽中排序字段
105 
106         //從數(shù)據(jù)庫(kù)中獲取主表數(shù)據(jù),使用的也是sql語(yǔ)句查詢
107         $return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id');
108                         
109         //調(diào)用副表的數(shù)據(jù)
110         if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) 
111         {
112             $ids = array();
113             foreach ($return as $v) 
114             {
115                 if (isset($v['id']) && !empty($v['id'])) 
116                 {
117                     $ids[] = $v['id'];
118                 } 
119                 else
120                 {
121                     continue;
122                 }
123             }
124             if (!empty($ids)) 
125             {
126                 $this->db->table_name = $this->db->table_name.'_data';//副表名
127                 $ids = implode('\',\'', $ids);
128                 $r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id');
129                 if (!empty($r)) 
130                 {
131                     foreach ($r as $k=>$v) 
132                     {
133                         if (isset($return[$k])) 
134                             $return[$k] = array_merge($v, $return[$k]); //主表中數(shù)據(jù)與副表中數(shù)據(jù)合并
135                     }
136                 }
137             }
138         }
139         return $return;  //返回查詢到的數(shù)據(jù)
140     }

phpcms V9 home page template file analysis (transfer), _PHP tutorial

注意:由以上分析可知,pc標(biāo)簽內(nèi)部原理也是通過(guò)sql語(yǔ)句來(lái)獲取數(shù)據(jù)的。

另外,PC標(biāo)簽分模塊來(lái)使用,內(nèi)容模塊PC標(biāo)簽可用來(lái)完成如下功能:

(1)獲取內(nèi)容列表:lists 方法 (如上)

(2)獲取點(diǎn)擊排行榜:hits 方法 (詳細(xì)見(jiàn)文件content_tag.class.php)

(3)獲取相關(guān)文章:relation 方法 (詳細(xì)見(jiàn)文件content_tag.class.php)

(4)獲取欄目列表:category 方法 (詳細(xì)見(jiàn)文件content_tag.class.php)

第七、content_model類。文件路徑:phpcms/model/content_model.class.php

phpcms V9 home page template file analysis (transfer), _PHP tutorial

 1 /**
 2  * 內(nèi)容模型數(shù)據(jù)庫(kù)操作類
 3  */
 4 pc_base::load_sys_class('model', '', 0);
 5 class content_model extends model 
 6 {
 7     public $table_name = ''; // 數(shù)據(jù)庫(kù)表名
 8     public $category = ''; // 欄目
 9     public function __construct() 
10     {
11         $this->db_config = pc_base::load_config('database');  //加載數(shù)據(jù)庫(kù)配置信息
12         $this->db_setting = 'default'; // 加載數(shù)據(jù)庫(kù)默認(rèn)的配置信息
13         parent::__construct();  // 調(diào)用父類的構(gòu)造函數(shù)
14         $this->url = pc_base::load_app_class('url', 'content');
15         $this->siteid = get_siteid(); //獲取當(dāng)前站點(diǎn)id
16     }
17     public function set_model($modelid)
18     {
19         //獲取所有模型的配置信息  1-文檔模型 2-下載模型 3-圖片模型  跟后臺(tái)設(shè)置有關(guān)
20         $this->model = getcache('model', 'commons');
21         //當(dāng)前模型id
22         $this->modelid = $modelid;
23         //模型所對(duì)應(yīng)的數(shù)據(jù)表(文檔模型->news  圖片模型->picture 下載模型->download) 
24         $this->table_name = $this->db_tablepre.$this->model[$modelid]['tablename'];
25         $this->model_tablename = $this->model[$modelid]['tablename'];
26     }

phpcms V9 home page template file analysis (transfer), _PHP tutorial

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1137572.htmlTechArticlephpcms V9 首頁(yè)模板文件解析(轉(zhuǎn)), 轉(zhuǎn)自:http://www.cnblogs.com/Braveliu/p/5100018.html 轉(zhuǎn)在了解了《phpcms V9 URL訪問(wèn)解析》之后,我們已經(jīng)知道首頁(yè)最...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. Mar 21, 2024 pm 09:17 PM

When deleting or decompressing a folder on your computer, sometimes a prompt dialog box &quot;Error 0x80004005: Unspecified Error&quot; will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

Full analysis of Go language file renaming operation Full analysis of Go language file renaming operation Apr 08, 2024 pm 03:30 PM

The os.Rename function is used in Go language to rename files. The syntax is: funcRename(oldpath,newpathstring)error. This function renames the file specified by oldpath to the file specified by newpath. Examples include simple renaming, moving files to different directories, and ignoring error handling. The Rename function performs an atomic operation and may only update directory entries when the two files are in the same directory. Renames may fail across volumes or while a file is in use.

What framework is phpcms? What framework is phpcms? Apr 20, 2024 pm 10:51 PM

PHP CMS is a PHP-based open source content management system for managing website content. Its features include ease of use, powerful functionality, scalability, high security, and free open source. It can save time, improve website quality, enhance collaboration and reduce development costs, and is widely used in various websites such as news websites, blogs, corporate websites, e-commerce websites and community forums.

Analysis of the meaning and usage of midpoint in PHP Analysis of the meaning and usage of midpoint in PHP Mar 27, 2024 pm 08:57 PM

[Analysis of the meaning and usage of midpoint in PHP] In PHP, midpoint (.) is a commonly used operator used to connect two strings or properties or methods of objects. In this article, we’ll take a deep dive into the meaning and usage of midpoints in PHP, illustrating them with concrete code examples. 1. Connect string midpoint operator. The most common usage in PHP is to connect two strings. By placing . between two strings, you can splice them together to form a new string. $string1=&qu

How to implement HTTP streaming using C++? How to implement HTTP streaming using C++? May 31, 2024 am 11:06 AM

How to implement HTTP streaming in C++? Create an SSL stream socket using Boost.Asio and the asiohttps client library. Connect to the server and send an HTTP request. Receive HTTP response headers and print them. Receives the HTTP response body and prints it.

Effects of C++ template specialization on function overloading and overriding Effects of C++ template specialization on function overloading and overriding Apr 20, 2024 am 09:09 AM

C++ template specializations affect function overloading and rewriting: Function overloading: Specialized versions can provide different implementations of a specific type, thus affecting the functions the compiler chooses to call. Function overriding: The specialized version in the derived class will override the template function in the base class, affecting the behavior of the derived class object when calling the function.

What are the common applications of C++ templates in actual development? What are the common applications of C++ templates in actual development? Jun 05, 2024 pm 05:09 PM

C++ templates are widely used in actual development, including container class templates, algorithm templates, generic function templates and metaprogramming templates. For example, a generic sorting algorithm can sort arrays of different types of data.

Analysis of new features of Win11: How to skip logging in to Microsoft account Analysis of new features of Win11: How to skip logging in to Microsoft account Mar 27, 2024 pm 05:24 PM

Analysis of new features of Win11: How to skip logging in to a Microsoft account. With the release of Windows 11, many users have found that it brings more convenience and new features. However, some users may not like having their system tied to a Microsoft account and wish to skip this step. This article will introduce some methods to help users skip logging in to a Microsoft account in Windows 11 and achieve a more private and autonomous experience. First, let’s understand why some users are reluctant to log in to their Microsoft account. On the one hand, some users worry that they

See all articles