XOOPS  2.6.0
template.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
32 class XoopsTpl extends Smarty
33 {
37  public $currentTheme = null;
38 
39  public function __construct()
40  {
41  parent::__construct(); // SMARTY_PLUGINS_DIR is initialized into parent
43  $xoops->preload()->triggerEvent('core.template.construct.start', array($this));
44  $this->left_delimiter = '<{';
45  $this->right_delimiter = '}>';
46  $this->setTemplateDir(\XoopsBaseConfig::get('themes-path'));
47  $this->setCacheDir(\XoopsBaseConfig::get('smarty-cache'));
48  $this->setCompileDir(\XoopsBaseConfig::get('smarty-compile'));
49  $this->compile_check = ($xoops->getConfig('theme_fromfile') == 1);
50  $this->setPluginsDir(\XoopsBaseConfig::get('smarty-xoops-plugins'));
51  $this->addPluginsDir(SMARTY_PLUGINS_DIR);
52  $this->setCompileId();
53  $this->assign(
54  array('xoops_url' => \XoopsBaseConfig::get('url'),
55  'xoops_rootpath' => \XoopsBaseConfig::get('root-path'),
56  'xoops_langcode' => XoopsLocale::getLangCode(),
57  'xoops_charset' => XoopsLocale::getCharset(),
58  'xoops_version' => \Xoops::VERSION,
59  'xoops_upload_url' => \XoopsBaseConfig::get('uploads-url'))
60  );
61  }
62 
71  public function fetchFromData($tplSource, $display = false, $vars = null)
72  {
73  $oldVars = $this->_tpl_vars;
74  if (isset($vars)) {
75  $this->assign($vars);
76  }
77  if ($display) {
78  $out = $this->display('eval:'.$tplSource);
79  } else {
80  $out = $this->fetch('eval:'.$tplSource);
81  }
82  $this->_tpl_vars = $oldVars;
83  return $out;
84  }
85 
92  public function touch($resourceName)
93  {
94  $isForced = $this->force_compile;
95  $this->force_compile = true;
96  $this->clearCache($resourceName);
97  $result = true; // $this->_compile_resource($resourceName, $this->_get_compile_path($resourceName));
98  $this->force_compile = $isForced;
99  return $result;
100  }
101 
109  public function _get_auto_id($cache_id = null, $compile_id = null)
110  {
111  if (isset($cache_id)) {
112  return (isset($compile_id)) ? $compile_id . '-' . $cache_id : $cache_id;
113  } else {
114  if (isset($compile_id)) {
115  return $compile_id;
116  } else {
117  return null;
118  }
119  }
120  }
121 
130  public function setCompileId($module_dirname = null, $theme_set = null, $template_set = null)
131  {
133 
134  $template_set = empty($template_set) ? $xoops->getConfig('template_set') : $template_set;
135  $theme_set = empty($theme_set) ? $xoops->getConfig('theme_set') : $theme_set;
136  $module_dirname = empty($module_dirname) ? $xoops->moduleDirname : $module_dirname;
137  $this->compile_id = substr(md5(\XoopsBaseConfig::get('url')), 0, 8) . '-' . $module_dirname . '-' . $theme_set . '-' . $template_set;
138  //$this->_compile_id = $this->compile_id;
139  }
140 
153  public function clearModuleCompileCache($module_dirname = null, $theme_set = null, $template_set = null)
154  {
155  $hold_compile_id = $this->compile_id;
156  // $this->setCompileId($module_dirname, $template_set, $theme_set);
157  // TODO - should handle $use_sub_dirs
158  $this->setCompileId($module_dirname, '*', '*');
159  $compile_id = $this->compile_id;
160  $this->compile_id = $hold_compile_id;
161  $compile_id = preg_replace('![^\w\|]+!', '_', $compile_id);
162  $glob = $compile_id . '*.php';
163  $count=0;
164  $files = glob($this->compile_dir . '/' . $glob);
165  foreach ($files as $filename) {
166  $count += unlink($filename) ? 1 : 0;
167  }
168  $files = glob($this->cache_dir . '/*' . $glob);
169  foreach ($files as $filename) {
170  $count += unlink($filename) ? 1 : 0;
171  }
172  return $count;
173  }
174 
191  public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
192  {
193  \Xoops::getInstance()->deprecated('XoopsTpl::clearCache() is potentially ambiguous');
194  return parent::clearCache($template_name, $cache_id, $compile_id, $exp_time, $type);
195  }
196 }
static getInstance()
Definition: Xoops.php:160
$result
Definition: pda.php:33
touch($resourceName)
Definition: template.php:92
const VERSION
Definition: Xoops.php:28
$files
Definition: index.php:35
_get_auto_id($cache_id=null, $compile_id=null)
Definition: template.php:109
$xoops
Definition: admin.php:25
clearCache($template_name, $cache_id=null, $compile_id=null, $exp_time=null, $type=null)
Definition: template.php:191
static get($name)
fetchFromData($tplSource, $display=false, $vars=null)
Definition: template.php:71
$type
Definition: misc.php:33
static getLangCode()
Definition: Abstract.php:68
setCompileId($module_dirname=null, $theme_set=null, $template_set=null)
Definition: template.php:130
$currentTheme
Definition: template.php:37
clearModuleCompileCache($module_dirname=null, $theme_set=null, $template_set=null)
Definition: template.php:153
__construct()
Definition: template.php:39