function template($file, $templateid = 0, $tpldir = '', $gettplfile = 0, $primaltpl = '') { global $_G; static $_init_style = false; if ($_init_style === false) { ext::app()->_init_style(); $_init_style = true; } $oldfile = $file; if (strpos($file, ':') !== false) { $clonefile = ''; list($templateid, $file, $clonefile) = explode(':', $file); $oldfile = $file; $file = empty($clonefile) ? $file : $file . '_' . $clonefile; if ($templateid == 'diy') { $indiy = false; $_G['style']['tpldirectory'] = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : ''); $_G['style']['prefile'] = ''; $diypath = SITE_ROOT . './data/diy/' . $_G['style']['tpldirectory'] . '/'; //DIY模板文件目录 $preend = '_diy_preview'; $_GET['preview'] = !empty($_GET['preview']) ? $_GET['preview'] : ''; $curtplname = $oldfile; $basescript = $_G['mod'] == 'viewthread' && !empty($_G['thread']) ? 'forum' : $_G['basescript']; if (isset($_G['cache']['diytemplatename' . $basescript])) { $diytemplatename =& $_G['cache']['diytemplatename' . $basescript]; } else { if (!isset($_G['cache']['diytemplatename'])) { loadcache('diytemplatename'); } $diytemplatename =& $_G['cache']['diytemplatename']; } $tplsavemod = 0; 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')) { $tpldir = 'data/diy/' . $_G['style']['tpldirectory'] . '/'; !$gettplfile && ($_G['style']['tplsavemod'] = $tplsavemod); $curtplname = $file; if (isset($_GET['diy']) && $_GET['diy'] == 'yes' || isset($_GET['diy']) && $_GET['preview'] == 'yes') { //DIY模式或预览模式下做以下判断 $flag = file_exists($diypath . $file . $preend . '.htm'); if ($_GET['preview'] == 'yes') { $file .= $flag ? $preend : ''; } else { $_G['style']['prefile'] = $flag ? 1 : ''; } } $indiy = true; } else { $file = $primaltpl ? $primaltpl : $oldfile; } $tplrefresh = $_G['config']['output']['tplrefresh']; if ($indiy && ($tplrefresh == 1 || $tplrefresh > 1 && !($_G['timestamp'] % $tplrefresh)) && filemtime($diypath . $file . '.htm') < filemtime(SITE_ROOT . $_G['style']['tpldirectory'] . '/' . ($primaltpl ? $primaltpl : $oldfile) . '.htm')) { if (!updatediytemplate($file, $_G['style']['tpldirectory'])) { unlink($diypath . $file . '.htm'); $tpldir = ''; } } if (!$gettplfile && empty($_G['style']['tplfile'])) { $_G['style']['tplfile'] = empty($clonefile) ? $curtplname : $oldfile . ':' . $clonefile; } $_G['style']['prefile'] = !empty($_GET['preview']) && $_GET['preview'] == 'yes' ? '' : $_G['style']['prefile']; } else { $tpldir = './source/plugin/' . $templateid . '/template'; } } $file .= !empty($_G['inajax']) && ($file == 'common/header' || $file == 'common/footer') ? '_ajax' : ''; $tpldir = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : ''); $templateid = $templateid ? $templateid : (defined('TEMPLATEID') ? TEMPLATEID : ''); $filebak = $file; if (defined('IN_MOBILE') && !defined('TPL_DEFAULT') && strpos($file, 'mobile/') === false || isset($_G['forcemobilemessage']) && $_G['forcemobilemessage']) { $file = 'mobile/' . $oldfile; } if (!$tpldir) { $tpldir = './template/default'; } $tplfile = $tpldir . '/' . $file . '.htm'; $file == 'common/header' && defined('CURMODULE') && CURMODULE && ($file = 'common/header_' . $_G['basescript'] . '_' . CURMODULE); if (defined('IN_MOBILE') && !defined('TPL_DEFAULT')) { if (strpos($tpldir, 'plugin')) { if (!file_exists(SITE_ROOT . $tpldir . '/' . $file . '.htm') && !file_exists(SITE_ROOT . $tpldir . '/' . $file . '.php')) { core_error::template_error('template_notfound', $tpldir . '/' . $file . '.htm'); } else { $mobiletplfile = $tpldir . '/' . $file . '.htm'; } } !$mobiletplfile && ($mobiletplfile = $file . '.htm'); if (strpos($tpldir, 'plugin') && (file_exists(SITE_ROOT . $mobiletplfile) || file_exists(substr(SITE_ROOT . $mobiletplfile, 0, -4) . '.php'))) { $tplfile = $mobiletplfile; } elseif (!file_exists(SITE_ROOT . TPLDIR . '/' . $mobiletplfile) && !file_exists(substr(SITE_ROOT . TPLDIR . '/' . $mobiletplfile, 0, -4) . '.php')) { $mobiletplfile = './template/default/' . $mobiletplfile; if (!file_exists(SITE_ROOT . $mobiletplfile) && !$_G['forcemobilemessage']) { $tplfile = str_replace('mobile/', '', $tplfile); $file = str_replace('mobile/', '', $file); define('TPL_DEFAULT', true); } else { $tplfile = $mobiletplfile; } } else { $tplfile = TPLDIR . '/' . $mobiletplfile; } } $cachefile = './data/template/' . SITE_LANG . '_' . (defined('STYLEID') ? STYLEID . '_' : '_') . $templateid . '_' . str_replace('/', '_', $file) . '.tpl.php'; if ($templateid != 1 && !file_exists(SITE_ROOT . $tplfile) && !file_exists(substr(SITE_ROOT . $tplfile, 0, -4) . '.php') && !file_exists(SITE_ROOT . ($tplfile = $tpldir . $filebak . '.htm'))) { $tplfile = './template/default/' . $filebak . '.htm'; } if ($gettplfile) { return $tplfile; } checktplrefresh($tplfile, $tplfile, @filemtime(SITE_ROOT . $cachefile), $templateid, $cachefile, $tpldir, $file); return SITE_ROOT . $cachefile; }
function error($message, $tplname) { core_error::template_error($message, $tplname); }
function template($file, $templateid = 0, $tpldir = '', $gettplfile = 0, $primaltpl = '') { global $_G; static $_init_style = false; if ($_init_style === false) { ext::app()->_init_style(); $_init_style = true; } $oldfile = $file; if (strpos($file, ':') !== false) { $clonefile = ''; list($templateid, $file, $clonefile) = explode(':', $file); $oldfile = $file; $file = empty($clonefile) ? $file : $file . '_' . $clonefile; } $file .= !empty($_G['inajax']) && ($file == 'global/header' || $file == 'global/footer') ? '_ajax' : ''; //DEBUG 判断加载前台还是后台模版 $is_admin_path = $_G['config']['admin_folder'] . '/'; $is_admin = strpos($_G['PHP_SELF'], $is_admin_path); if (!$is_admin) { $tpldir = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : ''); $is_admin_path = ''; } else { $is_admin_str = ''; $tpldir = $tpldir ? $tpldir : (defined('ADMIN_TPLDIR') ? ADMIN_TPLDIR : ''); $tpldir = $is_admin_path . trim($tpldir, './'); } $templateid = $templateid ? $templateid : (defined('TEMPLATEID') ? TEMPLATEID : ''); $filebak = $file; if (defined('IN_MOBILE') && !defined('TPL_DEFAULT') && strpos($file, 'mobile/') === false || isset($_G['forcemobilemessage']) && $_G['forcemobilemessage']) { $file = 'mobile/' . $oldfile; } if (!$tpldir) { $tpldir = $is_admin_path . './template/default'; } $tplfile = $tpldir . '/' . $file . '.htm'; $file == 'global/header' && defined('CURMODULE') && CURMODULE && ($file = 'global/header_' . $_G['basescript'] . '_' . CURMODULE); if (defined('IN_MOBILE') && !defined('TPL_DEFAULT')) { if (strpos($tpldir, 'plugin')) { if (!file_exists(SITE_ROOT . $tpldir . '/' . $file . '.htm') && !file_exists(SITE_ROOT . $tpldir . '/' . $file . '.php')) { core_error::template_error('template_notfound', $tpldir . '/' . $file . '.htm'); } else { $mobiletplfile = $tpldir . '/' . $file . '.htm'; } } !$mobiletplfile && ($mobiletplfile = $file . '.htm'); if (strpos($tpldir, 'plugin') && (file_exists(SITE_ROOT . $mobiletplfile) || file_exists(substr(SITE_ROOT . $mobiletplfile, 0, -4) . '.php'))) { $tplfile = $mobiletplfile; } elseif (!file_exists(SITE_ROOT . TPLDIR . '/' . $mobiletplfile) && !file_exists(substr(SITE_ROOT . TPLDIR . '/' . $mobiletplfile, 0, -4) . '.php')) { $mobiletplfile = $is_admin_path . './template/default/' . $mobiletplfile; if (!file_exists(SITE_ROOT . $mobiletplfile) && !$_G['forcemobilemessage']) { $tplfile = str_replace('mobile/', '', $tplfile); $file = str_replace('mobile/', '', $file); define('TPL_DEFAULT', true); } else { $tplfile = $mobiletplfile; } } else { $tplfile = TPLDIR . '/' . $mobiletplfile; } } $cachefile = $is_admin_path . './data/template/' . SITE_LANG . '_' . (defined('STYLEID') ? STYLEID . '_' : '_') . $templateid . '_' . str_replace('/', '_', $file) . '.tpl.php'; if ($templateid != 1 && !file_exists(SITE_ROOT . $tplfile) && !file_exists(substr(SITE_ROOT . $tplfile, 0, -4) . '.php') && !file_exists(SITE_ROOT . ($tplfile = $tpldir . $filebak . '.htm'))) { $tplfile = $is_admin_path . './template/default/' . $filebak . '.htm'; } if ($gettplfile) { return $tplfile; } checktplrefresh($tplfile, $tplfile, @filemtime(SITE_ROOT . $cachefile), $templateid, $cachefile, $tpldir, $file); return SITE_ROOT . $cachefile; }