XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
template.php
Go to the documentation of this file.
1 <?php
22 defined('XOOPS_ROOT_PATH') or die('Restricted access');
26 define('SMARTY_DIR', XOOPS_ROOT_PATH . '/class/smarty/');
27 require_once SMARTY_DIR . 'Smarty.class.php';
28 
37 class XoopsTpl extends Smarty
38 {
39  function XoopsTpl()
40  {
41  global $xoopsConfig;
42 
43  $this->left_delimiter = '<{';
44  $this->right_delimiter = '}>';
45  $this->template_dir = XOOPS_THEME_PATH;
46  $this->cache_dir = XOOPS_VAR_PATH . '/caches/smarty_cache';
47  $this->compile_dir = XOOPS_VAR_PATH . '/caches/smarty_compile';
48  $this->compile_check = ($xoopsConfig['theme_fromfile'] == 1);
49  $this->plugins_dir = array(
50  XOOPS_ROOT_PATH . '/class/smarty/xoops_plugins' ,
51  XOOPS_ROOT_PATH . '/class/smarty/plugins');
52  if ($xoopsConfig['debug_mode']) {
53  $this->debugging_ctrl = 'URL';
54  if ($xoopsConfig['debug_mode'] == 3) {
55  $this->debugging = true;
56  }
57  }
58  $this->Smarty();
59  $this->setCompileId();
60  $this->assign(array(
61  'xoops_url' => XOOPS_URL ,
62  'xoops_rootpath' => XOOPS_ROOT_PATH ,
63  'xoops_langcode' => _LANGCODE ,
64  'xoops_charset' => _CHARSET ,
65  'xoops_version' => XOOPS_VERSION ,
66  'xoops_upload_url' => XOOPS_UPLOAD_URL));
67  }
68 
76  function fetchFromData($tplSource, $display = false, $vars = null)
77  {
78  if (!function_exists('smarty_function_eval')) {
79  require_once SMARTY_DIR . '/plugins/function.eval.php';
80  }
81  if (isset($vars)) {
82  $oldVars = $this->_tpl_vars;
83  $this->assign($vars);
84  $out = smarty_function_eval(array(
85  'var' => $tplSource), $this);
86  $this->_tpl_vars = $oldVars;
87  return $out;
88  }
89  return smarty_function_eval(array(
90  'var' => $tplSource), $this);
91  }
92 
99  function touch($resourceName)
100  {
101  $isForced = $this->force_compile;
102  $this->force_compile = true;
103  $this->clear_cache($resourceName);
104  $result = $this->_compile_resource($resourceName, $this->_get_compile_path($resourceName));
105  $this->force_compile = $isForced;
106  return $result;
107  }
108 
116  function _get_auto_id($cache_id = null, $compile_id = null)
117  {
118  if (isset($cache_id)) {
119  return (isset($compile_id)) ? $compile_id . '-' . $cache_id : $cache_id;
120  } else if (isset($compile_id)) {
121  return $compile_id;
122  } else {
123  return null;
124  }
125  }
126 
135  function setCompileId($module_dirname = null, $theme_set = null, $template_set = null)
136  {
137  global $xoopsConfig;
138 
139  $template_set = empty($template_set) ? $xoopsConfig['template_set'] : $template_set;
140  $theme_set = empty($theme_set) ? $xoopsConfig['theme_set'] : $theme_set;
141  $module_dirname = empty($module_dirname) ? (empty($GLOBALS['xoopsModule']) ? 'system' : $GLOBALS['xoopsModule']->getVar('dirname', 'n')) : $module_dirname;
142  $this->compile_id = substr(md5(XOOPS_URL), 0, 8) . '-' . $module_dirname . '-' . $theme_set . '-' . $template_set;
143  $this->_compile_id = $this->compile_id;
144  }
145 
154  function clearCache($module_dirname = null, $theme_set = null, $template_set = null)
155  {
156  $compile_id = $this->compile_id;
157  $this->setCompileId($module_dirname, $template_set, $theme_set);
158  $_params = array(
159  'auto_base' => $this->cache_dir ,
160  'auto_source' => null ,
161  'auto_id' => $this->compile_id,
162  'exp_time' => null,
163  );
164  $this->_compile_id = $this->compile_id = $compile_id;
165  require_once SMARTY_CORE_DIR . 'core.rm_auto.php';
166  return smarty_core_rm_auto($_params, $this);
167  }
168 
173  function xoops_setTemplateDir($dirname)
174  {
175  $GLOBALS['xoopsLogger']->addDeprecated('\'$xoopsTpl->xoops_setTemplateDir($value)\' is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->template_dir=$value;\' instead.');
176 
177  $this->template_dir = $dirname;
178  }
179  function xoops_getTemplateDir()
180  {
181  $GLOBALS['xoopsLogger']->addDeprecated('\'$xoopsTpl->xoops_getTemplateDir()\' is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->template_dir;\' instead.');
182 
183  return $this->template_dir;
184  }
185  function xoops_setDebugging($flag = false)
186  {
187  $GLOBALS['xoopsLogger']->addDeprecated('\'$xoopsTpl->xoops_setDebugging($value)\' is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->debugging=$value;\' instead.');
188 
189  $this->debugging = is_bool($flag) ? $flag : false;
190  }
191  function xoops_setCaching($num = 0)
192  {
193  $GLOBALS['xoopsLogger']->addDeprecated('\'$xoopsTpl->xoops_setCaching($value)\' is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->caching=$value;\' instead.');
194 
195  $this->caching = (int) $num;
196  }
197  function xoops_setCompileDir($dirname)
198  {
199  $GLOBALS['xoopsLogger']->addDeprecated('\'$xoopsTpl->xoops_setCompileDir($value)\' is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->compile_dir=$value;\' instead.');
200 
201  $this->compile_dir = $dirname;
202  }
203  function xoops_setCacheDir($dirname)
204  {
205  $GLOBALS['xoopsLogger']->addDeprecated('\'$xoopsTpl->xoops_setCacheDir($value)\' is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->cache_dir=$value;\' instead.');
206 
207  $this->cache_dir = $dirname;
208  }
209  function xoops_canUpdateFromFile()
210  {
211  $GLOBALS['xoopsLogger']->addDeprecated('\'$xoopsTpl->xoops_canUpdateFromFile()\' is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->compile_check;\' instead.');
212 
213  return $this->compile_check;
214  }
215  function xoops_fetchFromData($data)
216  {
217  $GLOBALS['xoopsLogger']->addDeprecated('\'$xoopsTpl->xoops_fetchFromData($value)\' is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->fetchFromData($value);\' instead.');
218 
219  return $this->fetchFromData($data);
220  }
221  function xoops_setCacheTime($num = 0)
222  {
223  $GLOBALS['xoopsLogger']->addDeprecated('\'$xoopsTpl->xoops_setCacheTime($value)\' is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->cache_lifetime=$value;\' instead.');
224 
225  if (($num = (int) $num) <= 0) {
226  $this->caching = 0;
227  } else {
228  $this->cache_lifetime = $num;
229  }
230  }
231 }
232 
240 function xoops_template_touch($tpl_id, $clear_old = true)
241 {
242  $tplfile_handler = &xoops_gethandler('tplfile');
243  $tplfile =& $tplfile_handler->get($tpl_id);
244 
245  if (is_object($tplfile)) {
246  $file = $tplfile->getVar('tpl_file', 'n');
247  $tpl = new XoopsTpl();
248  return $tpl->touch('db:' . $file);
249  }
250  return false;
251 }
252 
260 {
261  $block_arr = XoopsBlock::getByModule($mid);
262  $count = count($block_arr);
263  if ($count > 0) {
264  $xoopsTpl = new XoopsTpl();
265  $xoopsTpl->caching = 2;
266  for ($i = 0; $i < $count; $i++) {
267  if ($block_arr[$i]->getVar('template') != '') {
268  $xoopsTpl->clear_cache('db:' . $block_arr[$i]->getVar('template'), 'blk_' . $block_arr[$i]->getVar('bid'));
269  }
270  }
271  }
272 }
273 
274 ?>