14if (!defined(
'SMARTY_DIR')) {
20require_once SMARTY_DIR.
'Smarty.class.php';
23class XoopsTpl
extends Smarty
39 $this->compile_id = XOOPS_URL;
40 if (1 == $xoopsConfig[
'theme_fromfile']) {
41 $this->_canUpdateFromFile =
true;
42 $this->compile_check =
false;
43 $this->force_compile =
true;
46 $this->_canUpdateFromFile =
false;
47 $this->compile_check =
false;
48 $this->force_compile =
false;
50 $this->left_delimiter =
'<{';
51 $this->right_delimiter =
'}>';
52 $this->template_dir = XOOPS_THEME_PATH;
53 $this->cache_dir = XOOPS_CACHE_PATH;
54 $this->compile_dir = XOOPS_COMPILE_PATH;
57 $this->plugins_dir = [SMARTY_DIR .
'plugins'];
60 $this->use_sub_dirs =
false;
64 if (isset($GLOBALS[
'xoopsUserIsAdmin'])) {
65 $isadmin[
'xoops_isadmin']=$GLOBALS[
'xoopsUserIsAdmin'];
67 $isadmin[
'xoops_isadmin']=
false;
72 'xoops_url' => XOOPS_URL,
73 'xoops_rootpath' => XOOPS_ROOT_PATH,
74 'xoops_langcode' => _LANGCODE,
75 'xoops_charset' => _CHARSET,
76 'xoops_version' => XOOPS_VERSION,
77 'xoops_upload_url' => XOOPS_UPLOAD_URL,
81 if (empty($this->debug_tpl)) {
83 $this->debug_tpl = XOOPS_ROOT_PATH.
'/modules/legacy/templates/xoops_debug.tpl';
84 if ($this->security && is_file($this->debug_tpl)) {
85 $this->secure_dir[] = realpath($this->debug_tpl);
88 if ($xoopsConfig[
'debug_mode'] == 3) {
89 $this->debugging =
true;
91 $this->debug_tpl =
'file:' . XOOPS_ROOT_PATH.
'/modules/legacy/templates/xoops_debug.tpl';
99 XCube_DelegateUtils::call(
'XoopsTpl.New',
new XCube_Ref($this));
113 $this->template_dir = $dirname;
123 return $this->template_dir;
133 $this->debugging = is_bool($flag) ? $flag :
false;
143 $this->caching = (int)$num;
157 $this->cache_lifetime = $num;
168 $this->compile_dir = $dirname;
178 $this->cache_dir = $dirname;
191 $dummyfile = XOOPS_CACHE_PATH.
'/dummy_'.time();
192 $fp = fopen($dummyfile,
'w');
195 $fetched = $this->fetch(
'file:'.$dummyfile);
197 $this->clear_compiled_tpl(
'file:'.$dummyfile);
209 public function &fetchBlock($template, $bid)
211 $ret = $this->fetch(
'db:'.$template, $bid);
215 public function isBlockCached($template, $bid)
217 return $this->is_cached(
'db:'.$template,
'blk_'.$bid);
220 public function isModuleCached($templateName, $dirname)
222 if (!$templateName) {
223 $templateName=
'system_dummy.html';
226 return $this->is_cached(
'db:'.$templateName, $this->getModuleCachedTemplateId($dirname));
229 public function fetchModule($templateName, $dirname)
231 if (!$templateName) {
232 $templateName=
'system_dummy.html';
235 return $this->fetch(
'db:'.$templateName, $this->getModuleCachedTemplateId($dirname));
238 public function getModuleCachedTemplateId($dirname)
240 return 'mod_'.$dirname.
'|'.md5(str_replace(XOOPS_URL,
'', $GLOBALS[
'xoopsRequestUri']));
250 if ($this->debugging) {
253 require_once(SMARTY_CORE_DIR .
'core.get_microtime.php');
254 $this->_smarty_debug_info[$_included_tpls_idx][
'exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time);
255 require_once(SMARTY_CORE_DIR .
'core.display_debug_console.php');
256 return smarty_core_display_debug_console($_params, $this);
269function xoops_template_touch($tpl_id, $clear_old =
true)
278 XCube_DelegateUtils::call(
'Legacy.XoopsTpl.TemplateTouch', $tpl_id, $clear_old,
new XCube_Ref($result));
280 if (
null == $result) {
282 $tpl->force_compile =
true;
283 $tplfile_handler =& xoops_gethandler(
'tplfile');
284 $tplfile =& $tplfile_handler->get($tpl_id);
285 if (is_object($tplfile)) {
286 $file = $tplfile->getVar(
'tpl_file');
288 $tpl->clear_cache(
'db:'.$file);
289 $tpl->clear_compiled_tpl(
'db:'.$file);
312function xoops_template_create($resource_type, $resource_name, &$template_source, &$template_timestamp, &$smarty_obj)
314 if (
'db' == $resource_type) {
315 $file_handler =& xoops_gethandler(
'tplfile');
316 $tpl =& $file_handler->find(
'default',
null,
null,
null, $resource_name,
true);
317 if (count($tpl) > 0 && is_object($tpl[0])) {
318 $template_source = $tpl[0]->getSource();
319 $template_timestamp = $tpl[0]->getLastModified();
335 function xoops_template_clear_module_cache($mid)
337 $block_arr =& XoopsBlock::sGetByModule($mid);
338 $count = count($block_arr);
341 $xoopsTpl->xoops_setCaching(2);
342 foreach ($block_arr as $iValue) {
343 if (
'' !== $iValue->getVar(
'template')) {
344 $xoopsTpl->clear_cache(
'db:'. $iValue->getVar(
'template'),
'blk_'. $iValue->getVar(
'bid'));
xoops_canUpdateFromFile()
xoops_setTemplateDir(string $dirname)
xoops_setCompileDir($dirname)
xoops_setCacheTime($num=0)
xoops_fetchFromData(&$data)
xoops_setDebugging($flag=false)
xoops_setCacheDir($dirname)