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

首頁 > CMS > PhpCMS > 正文

【phpcms-v9】index.php文件分析-前臺首頁模板文件的解析過程

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

第一步:前臺首頁默認執行的是:index.php?m=content&c=index&a=init:

  1. //首頁   
  2. public function init() {   
  3.         if(isset($_GET['siteid'])) {   
  4.             $siteid = intval($_GET['siteid']);          //當前站點ID   
  5.         } else {   
  6.             $siteid = 1;                        //當前站點ID   
  7.         }   
  8.         $siteid = $GLOBALS['siteid'] = max($siteid,1);   
  9.         define('SITEID'$siteid);   
  10.         $_userid = $this->_userid;   
  11.         $_username = $this->_username;   
  12.         $_groupid = $this->_groupid;   
  13.         $SEO = seo($siteid);                        //查看第二步,獲取當前站點當前欄目下生成的SEO信息   
  14.         $sitelist  = getcache('sitelist','commons');                //緩存后臺設置的所有站點配置信息   
  15.         $default_style = $sitelist[$siteid]['default_style'];       //當前站點默認模板風格配置   
  16.         $CATEGORYS = getcache('category_content_'.$siteid,'commons');   //當前站點所有欄目詳細配置信息   
  17.         include template('content','index',$default_style);     //查看第三步:模版調用   
  18. }   

第二步:獲取SEO信息:phpcms/libs/functions/global.func.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.     if (!emptyempty($title))$title = strip_tags($title);                     //過濾title   
  11.     if (!emptyempty($description)) $description = strip_tags($description);  //過濾description   
  12.     if (!emptyempty($keyword)) $keyword = str_replace(' '','strip_tags($keyword));//過濾keyword   
  13.     $sites = getcache('sitelist''commons');                           //所有站點詳細配置信息   
  14.     $site = $sites[$siteid];                                            //當前站點詳細配置信息   
  15.     $cat = array();   
  16.     if (!emptyempty($catid)) {                                               //欄目ID不為空   
  17.         $siteids = getcache('category_content','commons');              //所有欄目對應的站點ID緩存文件,格式:欄目ID=>站點ID   
  18.         $siteid = $siteids[$catid];                                     //當前欄目對應的站點ID   
  19.         $categorys = getcache('category_content_'.$siteid,'commons');   //當前站點下所有欄目的詳細配置信息   
  20.         $cat = $categorys[$catid];                                      //當前站點下當前欄目的詳細配置信息                       
  21.         $cat['setting'] = string2array($cat['setting']);                //當前站點當前欄目詳細配置信息的setting設置信息,轉化為數組   
  22.     }   
  23.     //站點title   
  24.     $seo['site_title'] =isset($site['site_title']) && !emptyempty($site['site_title']) ? $site['site_title'] : $site['name'];   
  25.     //關鍵詞   
  26.     $seo['keyword'] = !emptyempty($keyword) ? $keyword : $site['keywords'];   
  27.     //描述   
  28.     $seo['description'] = isset($description) && !emptyempty($description) ? $description : (isset($cat['setting']['meta_description']) && !emptyempty($cat['setting']['meta_description']) ? $cat['setting']['meta_description'] : (isset($site['description']) && !emptyempty($site['description']) ? $site['description'] : ''));   
  29.     //標題   
  30.     $seo['title'] =  (isset($title) && !emptyempty($title) ? $title.' - ' : '').(isset($cat['setting']['meta_title']) && !emptyempty($cat['setting']['meta_title']) ? $cat['setting']['meta_title'].' - ' : (isset($cat['catname']) && !emptyempty($cat['catname']) ? $cat['catname'].' - ' : ''));   
  31.     foreach ($seo as $k=>$v) {   
  32.         $seo[$k] = str_replace(array("/n","/r"),    ''$v);            //將seo信息中/n和/r替換為空   
  33.     }   
  34.     return $seo;                                                        //返回seo數組信息   

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

  1. /**   
  2.  * 模板調用   
  3.  *   
  4.  * @param $module   
  5.  * @param $template   
  6.  * @param $istag   
  7.  * @return unknown_type   
  8.  */   
  9. function template($module = 'content'$template = 'index'$style = '') {   
  10.    
  11.     if(strpos($module'plugin/')!== false) { //一般情況下不會執行if里面的代碼   
  12.         $plugin = str_replace('plugin/'''$module);   
  13.         return p_template($plugin$template,$style);   
  14.     }   
  15.     $module = str_replace('/', DIRECTORY_SEPARATOR, $module);   
  16.     if(!emptyempty($style) && preg_match('/([a-z0-9/-_]+)/is',$style)) {//如果模板風格不為空   
  17.     } elseif (emptyempty($style) && !defined('STYLE')) {                //如果模板風格為空   
  18.         if(defined('SITEID')) {                                    //是否定義了SITEID常量   
  19.             $siteid = SITEID;   
  20.         } else {   
  21.             $siteid = param::get_cookie('siteid');   
  22.         }   
  23.         if (!$siteid$siteid = 1;   
  24.         $sitelist = getcache('sitelist','commons');                 //獲取所有站點的詳細配置信息   
  25.         if(!emptyempty($siteid)) {   
  26.             $style = $sitelist[$siteid]['default_style'];           //獲取當前站點的默認模板風格   
  27.         }   
  28.     } elseif (emptyempty($style) && defined('STYLE')) {   
  29.         $style = STYLE;   
  30.     } else {   
  31.         $style = 'default';   
  32.     }   
  33.     if(!$style$style = 'default';   
  34.     $template_cache = pc_base::load_sys_class('template_cache');//模板解析類,路徑:phpcms/libs/classes/template_cache.class.php   
  35.     //編譯文件緩存路徑:根目錄/caches/caches_template/default/content/index.php   
  36.     $compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php';  
  37.     //路徑:phpcms/templates/dafault/content/index.html ,如:首頁模板文件   
  38.     if(file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html')) {   
  39.         //如果編譯文件不存在或者說模板文件的創建時間大于編譯文件的生成時間,則重新編譯   
  40.         if(!file_exists($compiledtplfile) || (@filemtime(PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') > @filemtime($compiledtplfile))) {   
  41.             $template_cache->template_compile($module$template$style);//查看第四步:適用模板風格不是default的情況   
  42.         }   
  43.     } else {   
  44.         //編譯文件緩存路徑:根目錄/caches/caches_template/default/content/index.php   
  45.         $compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php';   
  46.         //如果編譯文件不存在或者說前臺公共的模板文件存在,并且前臺公共模板文件的創建時間大于編譯文件的生成時間   
  47.         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))) {   
  48.             //重新編譯   
  49.             $template_cache->template_compile($module$template'default');//查看第四步:適用于模板風格為default的情況   
  50.         } elseif (!file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html')) {  //Vevb.com 
  51.             //如果前臺公共的模板文件不存在的話,則提示模板不存在   
  52.             showmessage('Template does not exist.'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html');   
  53.         }   
  54.     }   
  55.     //返回編譯文件   
  56.     return $compiledtplfile;   

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

  1. /**   
  2.  * 編譯模板   
  3.  *   
  4.  * @param $module   模塊名稱   
  5.  * @param $template 模板文件名   
  6.  * @param $istag    是否為標簽模板   
  7.  * @return unknown   
  8.  */   
  9.    
  10. public function template_compile($module$template$style = 'default') {   
  11.     if(strpos($module'/')=== false) {//如果"/"不存在   
  12.         //路徑:phpcms/templates/default/content/index.html ,如:首頁公共模板文件   
  13.         $tplfile = $_tpl = PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html';   
  14.     } elseif (strpos($module'yp/') !== false) {   
  15.         $module = str_replace('/', DIRECTORY_SEPARATOR, $module);   
  16.         $tplfile = $_tpl = PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html';   
  17.     } else {   
  18.         $plugin = str_replace('plugin/'''$module);   
  19.         $module = str_replace('/', DIRECTORY_SEPARATOR, $module);   
  20.         $tplfile = $_tpl = PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.html';   
  21.     }   
  22.     if ($style != 'default' && !file_exists ( $tplfile )) {   
  23.         $style = 'default';   
  24.         $tplfile = PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html';   
  25.     }   
  26.     if (! file_exists ( $tplfile )) {   
  27.         //如果公共模板文件不存在,則提示模板文件不存在,如:/templates/default/content/index.html is not exists!   
  28.         showmessage ( "templates".DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.".html is not exists!" );   
  29.     }   
  30.     //獲取公共模板文件中的內容   
  31.     $content = @file_get_contents ( $tplfile );   
  32.     //要生成的編譯文件所在目錄   
  33.     $filepath = CACHE_PATH.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR;   
  34.     if(!is_dir($filepath)) {   
  35.         //如果目錄不存在,則層級創建所有目錄   
  36.         mkdir($filepath, 0777, true);   
  37.     }   
  38.     //編譯文件的全路徑   
  39.     $compiledtplfile = $filepath.$template.'.php';   
  40.     //解析公共模板文件中的內容及標簽,并返回解析后的內容   
  41.     $content = $this->template_parse($content);//查看第五步   
  42.     //將解析后的公共模板文件內容寫入到要生成的編譯文件中   
  43.     $strlen = file_put_contents ( $compiledtplfile$content );   
  44.     //給生成的編譯文件設置權限   
  45.     chmod ( $compiledtplfile, 0777 );   
  46.     return $strlen;//返回寫入編譯文件的字節數   
  47. }   

第五步:模板解析:phpcms/libs/classes/template_cache.class.php

  1.  /**   
  2.  * 解析模板   
  3.  *   
  4.  * @param $str  模板內容   
  5.  * @return ture   
  6.  */   
  7. public function template_parse($str) {   
  8.     $str = preg_replace ( "//{template/s+(.+)/}/""<?php include template(//1); ?>"$str );   
  9.     $str = preg_replace ( "//{include/s+(.+)/}/""<?php include //1; ?>"$str );   
  10.     $str = preg_replace ( "//{php/s+(.+)/}/""<?php //1?>"$str );   
  11.     $str = preg_replace ( "//{if/s+(.+?)/}/""<?php if(//1) { ?>"$str );  
  12.     $str = preg_replace ( "//{else/}/""<?php } else { ?>"$str );   
  13.     $str = preg_replace ( "//{elseif/s+(.+?)/}/""<?php } elseif (//1) { ?>"$str );   
  14.     $str = preg_replace ( "//{//if/}/""<?php } ?>"$str );   
  15.     //for 循環   
  16.     $str = preg_replace("//{for/s+(.+?)/}/","<?php for(//1) { ?>",$str);   
  17.     $str = preg_replace("//{//for/}/","<?php } ?>",$str);   
  18.     //++ --   
  19.     $str = preg_replace("//{/+/+(.+?)/}/","<?php ++//1; ?>",$str);   
  20.     $str = preg_replace("//{/-/-(.+?)/}/","<?php ++//1; ?>",$str);   
  21.     $str = preg_replace("//{(.+?)/+/+/}/","<?php //1++; ?>",$str);   
  22.     $str = preg_replace("//{(.+?)/-/-/}/","<?php //1--; ?>",$str);   
  23.     $str = preg_replace ( "//{loop/s+(/S+)/s+(/S+)/}/""<?php /$n=1;if(is_array(//1)) foreach(//1 AS //2) { ?>"$str );   
  24.     $str = preg_replace ( "//{loop/s+(/S+)/s+(/S+)/s+(/S+)/}/""<?php /$n=1; if(is_array(//1)) foreach(//1 AS //2 => //3) { ?>"$str );   
  25.     $str = preg_replace ( "//{//loop/}/""<?php /$n++;}unset(/$n); ?>"$str );   
  26.     $str = preg_replace ( "//{([a-zA-Z_/x7f-/xff][a-zA-Z0-9_/x7f-/xff:]*/(([^{}]*)/))/}/""<?php echo //1;?>"$str );   
  27.     $str = preg_replace ( "//{//$([a-zA-Z_/x7f-/xff][a-zA-Z0-9_/x7f-/xff:]*/(([^{}]*)/))/}/""<?php echo //1;?>"$str );   
  28.     $str = preg_replace ( "//{(//$[a-zA-Z_/x7f-/xff][a-zA-Z0-9_/x7f-/xff]*)/}/""<?php echo //1;?>"$str );   
  29.     $str = preg_replace("//{(//$[a-zA-Z0-9_/[/]/'/"/$/x7f-/xff]+)/}/es""/$this->addquote('<?php echo //1;?>')",$str);   
  30.     $str = preg_replace ( "//{([A-Z_/x7f-/xff][A-Z0-9_/x7f-/xff]*)/}/s""<?php echo //1;?>"$str );   
  31.     $str = preg_replace("//{pc:(/w+)/s+([^}]+)/}/ie""self::pc_tag('$1','$2', '$0')"$str);//查看第六步:解析pc標簽的開始標簽   
  32.     $str = preg_replace("//{//pc/}/ie""self::end_pc_tag()"$str);//查看第六步:解析pc標簽的結束標簽   
  33.     $str = "<?php defined('IN_PHPCMS') or exit('No permission resources.'); ?>" . $str;   
  34.     return $str;   
  35. }  

第六步:pc標簽的解析:

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

第七步:pc標簽類,路徑:phpcms/modules/content/classes/content_tag.class.php

  1. private $db;   
  2. public function __construct() {   
  3.     $this->db = pc_base::load_model('content_model');//查看第八步:數據模型,對應數據表news 和 news_data   
  4.     $this->position = pc_base::load_model('position_data_model');//數據模型  
  5. }   
  6. /**   
  7.  * 初始化模型   
  8.  * @param $catid   
  9.  */   
  10. public function set_modelid($catid) {   
  11.     $siteids = getcache('category_content','commons');//獲取所有欄目所屬的站點id   
  12.     if(!$siteids[$catid]) return false;//不存在此欄目,返回false   
  13.     $siteid = $siteids[$catid];//當前欄目所屬站點id   
  14.     $this->category = getcache('category_content_'.$siteid,'commons');//獲取當前站點id下所有欄目的配置信息   
  15.     if($this->category[$catid]['type']!=0) return false;//如果不為內部欄目,返回false  0-內部欄目 1-單網頁 2-外部鏈接   
  16.     $this->modelid = $this->category[$catid]['modelid'];//獲取當前欄目所屬模型id   
  17.     $this->db->set_model($this->modelid);//查看第八步   
  18.     $this->tablename = $this->db->table_name;//數據表名   
  19.     if(emptyempty($this->category)) {//當前站點id下所有欄目的配置信息   
  20.         return false;   
  21.     } else {   
  22.         return true;   
  23.     }   
  24. }   
  25. [html] view plaincopy 
  26.        /**   
  27.  * 列表頁標簽   
  28.  * @param $data   
  29.  */   
  30. public function lists($data) {   
  31.     $catid = intval($data['catid']);   
  32.     if(!$this->set_modelid($catid)) return false;   
  33.     if(isset($data['where'])) {//如果pc標簽中設置了條件   
  34.         $sql = $data['where'];//pc標簽中的條件   
  35.     } else {//如果pc標簽中沒有設置條件   
  36.         $thumb = intval($data['thumb']) ? " AND thumb != ''" : '';   
  37.         if($this->category[$catid]['child']) {   
  38.             $catids_str = $this->category[$catid]['arrchildid'];   
  39.             $pos = strpos($catids_str,',')+1;   
  40.             $catids_str = substr($catids_str$pos);   
  41.             $sql = "status=99 AND catid IN ($catids_str)".$thumb;   
  42.         } else {   
  43.             $sql = "status=99 AND catid='$catid'".$thumb;   
  44.         }   
  45.     }   
  46.     $order = $data['order'];//pc標簽中排序字段   
  47.    
  48.     $return = $this->db->select($sql'*'$data['limit'], $order'''id');//從數據庫中獲取主表數據,使用的也是sql語句查詢   
  49.                        
  50.     //調用副表的數據   
  51.     if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {   
  52.         $ids = array();   
  53.         foreach ($return as $v) {   
  54.             if (isset($v['id']) && !emptyempty($v['id'])) {   
  55.                 $ids[] = $v['id'];   
  56.             } else {   
  57.                 continue;   
  58.             }   
  59.         }   
  60.         if (!emptyempty($ids)) {   
  61.             $this->db->table_name = $this->db->table_name.'_data';//副表名   
  62.             $ids = implode('/',/''$ids);   
  63.             $r = $this->db->select("`id` IN ('$ids')"'*''''''''id');   
  64.             if (!emptyempty($r)) {   
  65.                 foreach ($r as $k=>$v) {   
  66.                     if (isset($return[$k])) $return[$k] = array_merge($v$return[$k]);//主表中數據與副表中數據合并   
  67.                 }   
  68.             }   
  69.         }   
  70.     }   
  71.     return $return;//返回查詢到的數據   
  72. }   

第八步:content_model類,路徑:phpcms/model/content_model.class.php

  1. public $table_name = '';//數據庫表名   
  2. public $category = '';   
  3. public function __construct() {   
  4.     $this->db_config = pc_base::load_config('database');//加載數據庫配置信息   
  5.     $this->db_setting = 'default';//加載數據庫默認的配置信息   
  6.     parent::__construct();   
  7.     $this->url = pc_base::load_app_class('url''content');   
  8.     $this->siteid = get_siteid();//得到當前站點id   
  9. }   
  10. public function set_model($modelid) {   
  11.     $this->model = getcache('model''commons');//獲取所有模型的配置信息  1-文檔模型 2-下載模型 3-圖片模型    跟后臺設置有關   
  12.     $this->modelid = $modelid;//當前模型id   
  13.                $this->table_name = $this->db_tablepre.$this->model[$modelid]['tablename'];//模型所對應的數據表 文檔模型-news  圖片模型-picture 下載模型-download   
  14.     $this->model_tablename = $this->model[$modelid]['tablename'];   
  15. }   

總結:pc標簽內部機制也是通過sql語句來返回數據的.


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蒙自县| 谷城县| 个旧市| 罗甸县| 营山县| 秭归县| 台南县| 观塘区| 汉源县| 德惠市| 清水河县| 门源| 东丽区| 清水县| 阿拉善盟| 眉山市| 金塔县| 丹凤县| 绩溪县| 平罗县| 鄯善县| 松滋市| 南漳县| 枞阳县| 理塘县| 龙门县| 南康市| 杨浦区| 大石桥市| 香河县| 南木林县| 奉节县| 珲春市| 承德市| 福清市| 平湖市| 上栗县| 清镇市| 青浦区| 白沙| 日土县|