找回密码
 注册账号

QQ登录

只需一步,快速开始

《泰拉瑞亚下载-1.4.2.3版》 泰拉瑞亚服务器 - MOD模组下载

入驻泰拉战网 新手指引 - 升级 - 师徒

泰拉瑞亚合成表 泰拉卡牌 - 泰拉江湖 - 泰拉刺客

联系泰拉开发组👈进入 积分市场 - 房产交易 - 水晶获取

查看: 2179|回复: 0

Discuz template 函数 解析加载模板

[复制链接]

498

主题

18

回帖

5

广播

论坛版主

积分
257
泰拉
22
水晶
1
铜钥匙
0
银钥匙
0
金钥匙
0

【江湖新秀】【宝剑回鞘】【泰拉达人】【奥运选手】

发表于 2020-9-29 13:15:45 | 显示全部楼层 |阅读模式

  1. /**
  2. * 解析模板
  3. * @return 返回域名
  4. * 1、模板文件
  5. * 2、模板类型,如:diy模板和普通模板,diy模板位于data/diy,普通模板位于 template/default/下
  6. * 3、生成的tpl模板文件的存放位置
  7. * 4、是否返回模板文件的路径,0-返回编译后的php文件
  8. * 5、原始的模板文件
  9. */
复制代码


  1. function template($file, $templateid = 0, $tpldir = '', $gettplfile = 0, $primaltpl='') {
  2.         global $_G;

  3.         if($_G['setting']['plugins']['func'][HOOKTYPE]['template']) {
  4.                 $param = func_get_args();
  5.                 $hookreturn = hookscript('template', 'global', 'funcs', array('param' => $param, 'caller' => 'template'), 'template');
  6.                 if($hookreturn) {
  7.                         return $hookreturn;
  8.                 }
  9.         }

  10.         static $_init_style = false;
  11.         if($_init_style === false) {
  12.                 C::app()->_init_style();
  13.                 $_init_style = true;
  14.         }
  15.         $oldfile = $file;
  16.         if(strpos($file, ':') !== false) {
  17.                 $clonefile = '';
  18.                 list($templateid, $file, $clonefile) = explode(':', $file);
  19.                 $oldfile = $file;
  20.                 $file = empty($clonefile) ? $file : $file.'_'.$clonefile;
  21.                 if($templateid == 'diy') {
  22.                         $indiy = false;
  23.                         $_G['style']['tpldirectory'] = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : '');
  24.                         $_G['style']['prefile'] = '';
  25.                         $diypath = DISCUZ_ROOT.'./data/diy/'.$_G['style']['tpldirectory'].'/'; //DIY模板文件目录
  26.                         $preend = '_diy_preview';
  27.                         $_GET['preview'] = !empty($_GET['preview']) ? $_GET['preview'] : '';
  28.                         $curtplname = $oldfile;
  29.                         $basescript = $_G['mod'] == 'viewthread' && !empty($_G['thread']) ? 'forum' : $_G['basescript'];
  30.                         if(isset($_G['cache']['diytemplatename'.$basescript])) {
  31.                                 $diytemplatename = &$_G['cache']['diytemplatename'.$basescript];
  32.                         } else {
  33.                                 if(!isset($_G['cache']['diytemplatename'])) {
  34.                                         loadcache('diytemplatename');
  35.                                 }
  36.                                 $diytemplatename = &$_G['cache']['diytemplatename'];
  37.                         }
  38.                         $tplsavemod = 0;
  39.                         if(isset($diytemplatename[$file]) && file_exists($diypath.$file.'.htm') && ($tplsavemod = 1) || empty($_G['forum']['styleid']) && ($file = $primaltpl ? $primaltpl : $oldfile) && isset($diytemplatename[$file]) && file_exists($diypath.$file.'.htm')) {
  40.                                 $tpldir = 'data/diy/'.$_G['style']['tpldirectory'].'/';
  41.                                 !$gettplfile && $_G['style']['tplsavemod'] = $tplsavemod;
  42.                                 $curtplname = $file;
  43.                                 if(isset($_GET['diy']) && $_GET['diy'] == 'yes' || isset($_GET['diy']) && $_GET['preview'] == 'yes') { //DIY模式或预览模式下做以下判断
  44.                                         $flag = file_exists($diypath.$file.$preend.'.htm');
  45.                                         if($_GET['preview'] == 'yes') {
  46.                                                 $file .= $flag ? $preend : '';
  47.                                         } else {
  48.                                                 $_G['style']['prefile'] = $flag ? 1 : '';
  49.                                         }
  50.                                 }
  51.                                 $indiy = true;
  52.                         } else {
  53.                                 $file = $primaltpl ? $primaltpl : $oldfile;
  54.                         }
  55.                         $tplrefresh = $_G['config']['output']['tplrefresh'];
  56.                         if($indiy && ($tplrefresh ==1 || ($tplrefresh > 1 && !($_G['timestamp'] % $tplrefresh))) && filemtime($diypath.$file.'.htm') < filemtime(DISCUZ_ROOT.$_G['style']['tpldirectory'].'/'.($primaltpl ? $primaltpl : $oldfile).'.htm')) {
  57.                                 if (!updatediytemplate($file, $_G['style']['tpldirectory'])) {
  58.                                         unlink($diypath.$file.'.htm');
  59.                                         $tpldir = '';
  60.                                 }
  61.                         }

  62.                         if (!$gettplfile && empty($_G['style']['tplfile'])) {
  63.                                 $_G['style']['tplfile'] = empty($clonefile) ? $curtplname : $oldfile.':'.$clonefile;
  64.                         }

  65.                         $_G['style']['prefile'] = !empty($_GET['preview']) && $_GET['preview'] == 'yes' ? '' : $_G['style']['prefile'];

  66.                 } else {
  67.                         $tpldir = './source/plugin/'.$templateid.'/template';
  68.                 }
  69.         }

  70.         $file .= !empty($_G['inajax']) && ($file == 'common/header' || $file == 'common/footer') ? '_ajax' : '';
  71.         $tpldir = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : '');
  72.         $templateid = $templateid ? $templateid : (defined('TEMPLATEID') ? TEMPLATEID : '');
  73.         $filebak = $file;

  74.         if(defined('IN_MOBILE') && !defined('TPL_DEFAULT') && strpos($file, $_G['mobiletpl'][IN_MOBILE].'/') === false || (isset($_G['forcemobilemessage']) && $_G['forcemobilemessage'])) {
  75.                 if(IN_MOBILE == 2) {
  76.                         $oldfile .= !empty($_G['inajax']) && ($oldfile == 'common/header' || $oldfile == 'common/footer') ? '_ajax' : '';
  77.                 }
  78.                 $file = $_G['mobiletpl'][IN_MOBILE].'/'.$oldfile;
  79.         }

  80.         if(!$tpldir) {
  81.                 $tpldir = './template/default';
  82.         }
  83.         $tplfile = $tpldir.'/'.$file.'.htm';

  84.         $file == 'common/header' && defined('CURMODULE') && CURMODULE && $file = 'common/header_'.$_G['basescript'].'_'.CURMODULE;

  85.         if(defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
  86.                 if(strpos($tpldir, 'plugin')) {
  87.                         if(!file_exists(DISCUZ_ROOT.$tpldir.'/'.$file.'.htm') && !file_exists(DISCUZ_ROOT.$tpldir.'/'.$file.'.php')) {
  88.                                 $url = $_SERVER['REQUEST_URI'].(strexists($_SERVER['REQUEST_URI'], '?') ? '&' : '?').'mobile=no';
  89.                                 showmessage('mobile_template_no_found', '', array('url' => $url));
  90.                         } else {
  91.                                 $mobiletplfile = $tpldir.'/'.$file.'.htm';
  92.                         }
  93.                 }
  94.                 !$mobiletplfile && $mobiletplfile = $file.'.htm';
  95.                 if(strpos($tpldir, 'plugin') && (file_exists(DISCUZ_ROOT.$mobiletplfile) || file_exists(substr(DISCUZ_ROOT.$mobiletplfile, 0, -4).'.php'))) {
  96.                         $tplfile = $mobiletplfile;
  97.                 } elseif(!file_exists(DISCUZ_ROOT.TPLDIR.'/'.$mobiletplfile) && !file_exists(substr(DISCUZ_ROOT.TPLDIR.'/'.$mobiletplfile, 0, -4).'.php')) {
  98.                         $mobiletplfile = './template/default/'.$file.'.htm';
  99.                         if(!file_exists(DISCUZ_ROOT.$mobiletplfile) && !$_G['forcemobilemessage']) {
  100.                                 $tplfile = str_replace($_G['mobiletpl'][IN_MOBILE].'/', '', $tplfile);
  101.                                 $file = str_replace($_G['mobiletpl'][IN_MOBILE].'/', '', $file);
  102.                                 define('TPL_DEFAULT', true);
  103.                         } else {
  104.                                 $tplfile = $mobiletplfile;
  105.                         }
  106.                 } else {
  107.                         $tplfile = TPLDIR.'/'.$mobiletplfile;
  108.                 }
  109.         }

  110.         $cachefile = './data/template/'.(defined('STYLEID') ? STYLEID.'_' : '_').$templateid.'_'.str_replace('/', '_', $file).'.tpl.php';
  111.         if($templateid != 1 && !file_exists(DISCUZ_ROOT.$tplfile) && !file_exists(substr(DISCUZ_ROOT.$tplfile, 0, -4).'.php')
  112.                         && !file_exists(DISCUZ_ROOT.($tplfile = $tpldir.$filebak.'.htm'))) {
  113.                 $tplfile = './template/default/'.$filebak.'.htm';
  114.         }

  115.         if($gettplfile) {
  116.                 return $tplfile;
  117.         }
  118.         checktplrefresh($tplfile, $tplfile, @filemtime(DISCUZ_ROOT.$cachefile), $templateid, $cachefile, $tpldir, $file);
  119.         return DISCUZ_ROOT.$cachefile;
  120. }
复制代码
[发帖际遇]: 君山 被钱袋砸中进医院,看病花了 11 泰拉. 幸运榜 / 衰神榜
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

QQ|友链申请|Archiver|手机版|小黑屋|游芯沙盒 ( 陕ICP备11006283号-1 )

GMT+8, 2024-5-3 06:14 , Processed in 0.107979 second(s), 36 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表