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

目次
phpcms V9 首頁模板文件解析(轉),
ホームページ バックエンド開発 PHPチュートリアル phpcms V9 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

phpcms V9 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

Jul 12, 2016 am 08:49 AM
http phpcms 書類 テンプレート 解析する 変化 表紙

phpcms V9 首頁模板文件解析(轉),

轉自:http://www.cnblogs.com/Braveliu/p/5100018.html

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

下面, 我們逐步分析過程如下:

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

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

phpcms V9 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

 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     //首頁
12     public function init() 
13     {
14         if(isset($_GET['siteid'])) 
15         {
16             $siteid = intval($_GET['siteid']); //當前站點id  函數(shù)intval作用變量轉成整數(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); //調用第二步,獲取當前站點當前欄目下生成的SEO信息
29         $sitelist  = getcache('sitelist','commons'); //緩存后臺設置的所有站點配置信息
30         $default_style = $sitelist[$siteid]['default_style']; //當前站點默認模板風格配置
31         $CATEGORYS = getcache('category_content_'.$siteid,'commons'); //當前站點所有欄目詳細配置信息
32         include template('content','index',$default_style); //調用第三步:模板調用
33     }

phpcms V9 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

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

phpcms V9 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

 1 /**
 2  * 生成SEO
 3  * @param $siteid       站點ID
 4  * @param $catid        欄目ID
 5  * @param $title        標題
 6  * @param $description  描述
 7  * @param $keyword      關鍵詞
 8  */
 9 function seo($siteid, $catid = '', $title = '', $description = '', $keyword = '') 
10 {
11     if (!empty($title))
12         $title = strip_tags($title); //過濾title。 strip_tags() 函數(shù)剝去字符串中的 HTML、XML 以及 PHP 的標簽。
13     if (!empty($description)) 
14         $description = strip_tags($description); //過濾description
15     if (!empty($keyword)) 
16         $keyword = str_replace(' ', ',', strip_tags($keyword)); //過濾keyword
17     $sites = getcache('sitelist', 'commons'); //獲取所有站點詳細配置信息
18     $site = $sites[$siteid];    //當前站點詳細配置信息
19     $cat = array();
20     if (!empty($catid))     //欄目ID不為空
21     {
22         $siteids = getcache('category_content','commons'); //獲取所有欄目對應的站點ID緩存文件,格式:欄目ID=>站點ID
23         $siteid = $siteids[$catid]; //當前欄目對應的站點ID
24         $categorys = getcache('category_content_'.$siteid,'commons'); //獲取當前站點下所有欄目的詳細配置信息
25         $cat = $categorys[$catid];    //當前站點下當前欄目的詳細配置信息 
26         $cat['setting'] = string2array($cat['setting']); //當前站點當前欄目詳細配置信息的setting設置信息,轉化為數(shù)組
27     }
28     //站點title
29     $seo['site_title'] =isset($site['site_title']) && !empty($site['site_title']) ? $site['site_title'] : $site['name'];
30     //關鍵字
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     //標題
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 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

第三、模板調用:phpcms/libs/functions/global.func.php

phpcms V9 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

 1 /**
 2  * 模板調用
 3  *
 4  * @param $module 默認為content
 5  * @param $template 默認為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     { // 檢測模塊里面是否包含plugin字符,這里進行了對插件模板的判斷,插件模板需要調用p_template過程解析
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'); //獲取所有站點的詳細配置信息
32         if(!empty($siteid)) 
33         {
34             $style = $sitelist[$siteid]['default_style']; //獲取當前站點的默認模板風格
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     //首頁模板文件,如文件路徑: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         //如果編譯文件不存在或者說模板文件的創(chuàng)建時間大于編譯文件的生成時間,則重新編譯
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); //調用第四步:適用模板風格不是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         //如果編譯文件不存在或者說前臺公共的模板文件存在,并且前臺公共模板文件的創(chuàng)建時間大于編譯文件的生成時間
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         {  //如果前臺公共的模板文件不存在的話,則提示模板不存在
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 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

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

phpcms V9 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

 1 /**
 2  *  模板解析緩存
 3  */
 4 final class template_cache 
 5 {
 6     
 7     /**
 8      * 編譯模板
 9      *
10      * @param $module    模塊名稱
11      * @param $template    模板文件名
12      * @param $istag    是否為標簽模板
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 如:首頁公共模板文件  
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         //獲取公共模板文件中的內容
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             //如果目錄不存在,則層級創(chuàng)建所有目錄
51             mkdir($filepath, 0777, true);
52         }
53         //編譯文件的全路徑
54         $compiledtplfile = $filepath.$template.'.php';
55         //解析公共模板文件中的內容及標簽,并返回解析后的內容  
56         $content = $this->template_parse($content); // 調用下一個過程
57         //將解析后的公共模板文件內容寫入到要生成的編譯文件中
58         $strlen = file_put_contents ( $compiledtplfile, $content );
59         //給生成的編譯文件設置權限
60         chmod ( $compiledtplfile, 0777 );
61         //返回寫入編譯文件的字節(jié)數(shù)
62         return $strlen;
63     }
64 
65     /**
66      * 解析模板
67      *
68      * @param $str    模板內容
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 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

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

phpcms V9 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

  1 /**
  2      * 解析PC標簽
  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標簽中參數(shù)在默認參數(shù)數(shù)組$arr中存在,則將參數(shù)轉換為變量,如:$page=value等 
 22                 continue;
 23             }
 24             $datas[$v[1]] = $v[2];//如果pc標簽中參數(shù)不在默認參數(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標簽分兩大類:工具類和模塊類。工具類執(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標簽分兩大類:工具類和模塊類。模塊類執(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)) //分頁參數(shù)
117                 {
118                     $str .= '$pagesize = '.$num.';'; //每頁顯示數(shù)據(jù)量
119                     $str .= '$page = intval('.$page.') ? intval('.$page.') : 1;if($page<=0){$page=1;}';//當前頁碼
120                     $str .= '$offset = ($page - 1) * $pagesize;';//要查詢數(shù)據(jù)的開始位置
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).');';//分頁方法
124                     $str .= '$pages = pages($'.$op.'_total, $page, $pagesize, $urlrule);';
125                 }
126                 //調用第七步: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          * 解析結果大概如下所示:  
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 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

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

phpcms V9 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

  1 class content_tag 
  2 {
  3     private $db;
  4     public function __construct() 
  5     {
  6         $this->db = pc_base::load_model('content_model'); //調用第七步,數(shù)據(jù)模型,對應數(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'); //獲取所有欄目所屬的站點id
 17         if(!$siteids[$catid]) 
 18             return false; //不存在此欄目,返回false
 19         $siteid = $siteids[$catid]; //當前欄目所屬站點id
 20         if ($CATS[$siteid]) 
 21         {
 22             $this->category = $CATS[$siteid];
 23         } 
 24         else 
 25         {
 26             //獲取當前站點id下所有欄目的配置信息
 27             $CATS[$siteid] = $this->category = getcache('category_content_'.$siteid,'commons');
 28         }
 29         if($this->category[$catid]['type']!=0) 
 30             return false; //如果不為內部欄目,返回false  0-內部欄目 1-單網(wǎng)頁 2-外部鏈接
 31         $this->modelid = $this->category[$catid]['modelid']; //獲取當前欄目所屬模型id 
 32         $this->db->set_model($this->modelid); //調用第七步
 33         $this->tablename = $this->db->table_name; //數(shù)據(jù)表名
 34         if(empty($this->category)) 
 35         {
 36             //當前站點id下所有欄目的配置信息
 37             return false;
 38         } 
 39         else
 40         {
 41             return true;
 42         }
 43     }
 44     /**
 45      * 分頁統(tǒng)計
 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      * 列表頁標簽
 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標簽中設置了條件
 86         {
 87             $sql = $data['where']; //pc標簽中的條件
 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標簽中排序字段
105 
106         //從數(shù)據(jù)庫中獲取主表數(shù)據(jù),使用的也是sql語句查詢
107         $return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id');
108                         
109         //調用副表的數(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 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

注意:由以上分析可知,pc標簽內部原理也是通過sql語句來獲取數(shù)據(jù)的。

另外,PC標簽分模塊來使用,內容模塊PC標簽可用來完成如下功能:

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

(2)獲取點擊排行榜:hits 方法 (詳細見文件content_tag.class.php)

(3)獲取相關文章:relation 方法 (詳細見文件content_tag.class.php)

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

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

phpcms V9 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

 1 /**
 2  * 內容模型數(shù)據(jù)庫操作類
 3  */
 4 pc_base::load_sys_class('model', '', 0);
 5 class content_model extends model 
 6 {
 7     public $table_name = ''; // 數(shù)據(jù)庫表名
 8     public $category = ''; // 欄目
 9     public function __construct() 
10     {
11         $this->db_config = pc_base::load_config('database');  //加載數(shù)據(jù)庫配置信息
12         $this->db_setting = 'default'; // 加載數(shù)據(jù)庫默認的配置信息
13         parent::__construct();  // 調用父類的構造函數(shù)
14         $this->url = pc_base::load_app_class('url', 'content');
15         $this->siteid = get_siteid(); //獲取當前站點id
16     }
17     public function set_model($modelid)
18     {
19         //獲取所有模型的配置信息  1-文檔模型 2-下載模型 3-圖片模型  跟后臺設置有關
20         $this->model = getcache('model', 'commons');
21         //當前模型id
22         $this->modelid = $modelid;
23         //模型所對應的數(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 ホームページ テンプレート ファイル分析 (転送)、_PHP チュートリアル

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1137572.htmlTechArticlephpcms V9 首頁模板文件解析(轉), 轉自:http://www.cnblogs.com/Braveliu/p/5100018.html 轉在了解了《phpcms V9 URL訪問解析》之后,我們已經(jīng)知道首頁最...
このウェブサイトの聲明
この記事の內容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰屬します。このサイトは、それに相當する法的責任を負いません。盜作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undress AI Tool

Undress AI Tool

脫衣畫像を無料で

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード寫真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

寫真から衣服を削除するオンライン AI ツール。

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中國語版

SublimeText3 中國語版

中國語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統(tǒng)合開発環(huán)境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

0x80004005 エラー コードが表示された場合の対処方法 エディターは、0x80004005 エラー コードを解決する方法を説明します。 0x80004005 エラー コードが表示された場合の対処方法 エディターは、0x80004005 エラー コードを解決する方法を説明します。 Mar 21, 2024 pm 09:17 PM

パソコン上のフォルダーを削除または解凍するときに、「エラー 0x80004005: 不明なエラー」というダイアログ ボックスが表示されることがあります。この狀況はどう解決すればよいでしょうか?エラー コード 0x80004005 が表示される理由は実際にはたくさんありますが、そのほとんどはウイルスによって引き起こされます。DLL を再登録して問題を解決できます。以下では、エディターがエラー コード 0x80004005 の処理體験を説明します。 。一部のユーザーは、コンピュータの使用時にエラー コード 0X80004005 を表示されます。0x80004005 エラーは主に、コンピュータが特定のダイナミック リンク ライブラリ ファイルを正しく登録していないこと、またはファイアウォールがコンピュータとインターネット間の HTTPS 接続を許可していないことが原因で発生します。それでどうですか

Go 言語ファイルの名前変更操作の完全な分析 Go 言語ファイルの名前変更操作の完全な分析 Apr 08, 2024 pm 03:30 PM

os.Rename 関數(shù)は Go 言語でファイルの名前を変更するために使用されます。構文は funcRename(oldpath,newpathstring)error です。この関數(shù)は、oldpath で指定されたファイルの名前を newpath で指定されたファイルに変更します。例としては、単純な名前変更、ファイルの別のディレクトリへの移動、エラー処理の無視などが挙げられます。名前変更機能はアトミック操作を実行し、2 つのファイルが同じディレクトリにある場合にのみディレクトリ エントリを更新する可能性があります。名前変更はボリューム間またはファイルの使用中に失敗する可能性があります。

C++ を使用して HTTP ストリーミングを実裝するにはどうすればよいですか? C++ を使用して HTTP ストリーミングを実裝するにはどうすればよいですか? May 31, 2024 am 11:06 AM

C++ で HTTP ストリーミングを実裝するにはどうすればよいですか? Boost.Asio と asiohttps クライアント ライブラリを使用して、SSL ストリーム ソケットを作成します。サーバーに接続し、HTTP リクエストを送信します。 HTTP 応答ヘッダーを受信して??出力します。 HTTP 応答本文を受信して??出力します。

PHPにおけるmidpointの意味と使い方の分析 PHPにおけるmidpointの意味と使い方の分析 Mar 27, 2024 pm 08:57 PM

【PHPにおけるミッドポイントの意味と使い方の分析】 PHPでは、ミッドポイント(.)は2つの文字列やオブジェクトのプロパティやメソッドを接続するためによく使われる演算子です。この記事では、PHP における中間點の意味と使用法を詳しく掘り下げ、具體的なコード例を示して説明します。 1. 文字列中間點演算子の接続 PHP での最も一般的な使用法は、2 つの文字列を接続することです。 2 つの文字列の間に . を置くと、それらをつなぎ合わせて新しい文字列を形成できます。 $string1=&qu

phpcmsとはどのようなフレームワークですか? phpcmsとはどのようなフレームワークですか? Apr 20, 2024 pm 10:51 PM

PHP CMS は、Web サイトのコンテンツを管理するための PHP ベースのオープンソース コンテンツ管理システムであり、使いやすさ、強力な機能、拡張性、高いセキュリティ、無料のオープンソースが特徴です。時間を節(jié)約し、Web サイトの品質を向上させ、コラボレーションを強化し、開発コストを削減することができ、ニュース Web サイト、ブログ、企業(yè) Web サイト、電子商取引 Web サイト、コミュニティ フォーラムなどのさまざまな Web サイトで広く使用されています。

C++ テンプレートの特殊化が関數(shù)のオーバーロードとオーバーライドに及ぼす影響 C++ テンプレートの特殊化が関數(shù)のオーバーロードとオーバーライドに及ぼす影響 Apr 20, 2024 am 09:09 AM

C++ テンプレートの特殊化は、関數(shù)のオーバーロードと書き換えに影響します。 関數(shù)のオーバーロード: 特殊化されたバージョンでは、特定の型のさまざまな実裝が提供されるため、コンパイラーが呼び出すことを選択する関數(shù)に影響します。関數(shù)のオーバーライド: 派生クラスの特殊バージョンは、基本クラスのテンプレート関數(shù)をオーバーライドし、関數(shù)呼び出し時の派生クラス オブジェクトの動作に影響を與えます。

実際の開発における C++ テンプレートの一般的な用途は何ですか? 実際の開発における C++ テンプレートの一般的な用途は何ですか? Jun 05, 2024 pm 05:09 PM

C++ テンプレートは、コンテナ クラス テンプレート、アルゴリズム テンプレート、汎用関數(shù)テンプレート、メタプログラミング テンプレートなど、実際の開発で広く使用されています。たとえば、汎用の並べ替えアルゴリズムを使用して、さまざまな種類のデータの配列を並べ替えることができます。

WeChat ログイン統(tǒng)合ガイド: PHPCMS 実踐的な戦闘 WeChat ログイン統(tǒng)合ガイド: PHPCMS 実踐的な戦闘 Mar 29, 2024 am 09:18 AM

タイトル: WeChat ログイン統(tǒng)合ガイド: PHPCMS の実踐 今日のインターネット時代において、ソーシャル ログインは Web サイトの重要な機能の 1 つになりました。中國で最も人気のあるソーシャル プラットフォームの 1 つである WeChat のログイン機能は、ますます多くの Web サイトでも使用されています。この記事では、WeChat ログイン機能を PHPCMS Web サイトに統(tǒng)合する方法と、具體的なコード例を紹介します。ステップ 1: WeChat オープン プラットフォーム アカウントを登録する まず、WeChat オープン プラットフォームに開発者アカウントを登録し、対応する開発権限を申請する必要があります。ログイン [WeChatオープンプラットフォーム]

See all articles