1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: |
|
20: |
|
21: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
22: |
|
23: | xoops_loadLanguage('global');
|
24: |
|
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: |
|
33: | class XoopsTpl extends SmartyBC
|
34: | {
|
35: |
|
36: | public $currentTheme;
|
37: | |
38: | |
39: |
|
40: | public function __construct()
|
41: | {
|
42: | global $xoopsConfig;
|
43: |
|
44: | parent::__construct();
|
45: |
|
46: | $this->setLeftDelimiter('<{');
|
47: | $this->setRightDelimiter('}>');
|
48: | $this->setTemplateDir(XOOPS_THEME_PATH);
|
49: | $this->setCacheDir(XOOPS_VAR_PATH . '/caches/smarty_cache');
|
50: | $this->setCompileDir(XOOPS_VAR_PATH . '/caches/smarty_compile');
|
51: | $this->compile_check = \Smarty::COMPILECHECK_ON;
|
52: | $this->addPluginsDir(XOOPS_ROOT_PATH . '/class/smarty3_plugins');
|
53: | if ($xoopsConfig['debug_mode']) {
|
54: | $this->debugging_ctrl = 'URL';
|
55: |
|
56: | if ($xoopsConfig['debug_mode'] == 3) {
|
57: | $this->debugging = true;
|
58: | }
|
59: | }
|
60: | $this->setCompileId();
|
61: | $this->assign(array(
|
62: | 'xoops_url' => XOOPS_URL,
|
63: | 'xoops_rootpath' => XOOPS_ROOT_PATH,
|
64: | 'xoops_langcode' => _LANGCODE,
|
65: | 'xoops_charset' => _CHARSET,
|
66: | 'xoops_version' => XOOPS_VERSION,
|
67: | 'xoops_upload_url' => XOOPS_UPLOAD_URL));
|
68: | $xoopsPreload = XoopsPreload::getInstance();
|
69: | $xoopsPreload->triggerEvent('core.class.template.new', array($this));
|
70: | }
|
71: |
|
72: | |
73: | |
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: |
|
81: | public function fetchFromData($tplSource, $display = false, $vars = null)
|
82: | {
|
83: | if (!function_exists('smarty_function_eval')) {
|
84: | require_once SMARTY_DIR . '/plugins/function.eval.php';
|
85: | }
|
86: | if (isset($vars)) {
|
87: | $oldVars = $this->_tpl_vars;
|
88: | $this->assign($vars);
|
89: | $out = smarty_function_eval(array(
|
90: | 'var' => $tplSource), $this);
|
91: | $this->_tpl_vars = $oldVars;
|
92: |
|
93: | return $out;
|
94: | }
|
95: |
|
96: | return smarty_function_eval(array(
|
97: | 'var' => $tplSource), $this);
|
98: | }
|
99: |
|
100: | |
101: | |
102: | |
103: | |
104: | |
105: |
|
106: | public function xoopsTouch($resourceName)
|
107: | {
|
108: |
|
109: | $this->clearCache($resourceName);
|
110: | return true;
|
111: | }
|
112: |
|
113: | |
114: | |
115: | |
116: | |
117: | |
118: | |
119: |
|
120: | public function _get_auto_id($cache_id = null, $compile_id = null)
|
121: | {
|
122: | if (isset($cache_id)) {
|
123: | return isset($compile_id) ? $compile_id . '-' . $cache_id : $cache_id;
|
124: | } elseif (isset($compile_id)) {
|
125: | return $compile_id;
|
126: | } else {
|
127: | return null;
|
128: | }
|
129: | }
|
130: |
|
131: | |
132: | |
133: | |
134: | |
135: | |
136: | |
137: | |
138: |
|
139: | public function setCompileId($module_dirname = null, $theme_set = null, $template_set = null)
|
140: | {
|
141: | global $xoopsConfig;
|
142: |
|
143: | $template_set = empty($template_set) ? $xoopsConfig['template_set'] : $template_set;
|
144: | $theme_set = empty($theme_set) ? $xoopsConfig['theme_set'] : $theme_set;
|
145: | if (class_exists('XoopsSystemCpanel', false)) {
|
146: | $cPrefix = 'cp-';
|
147: | $theme_set = isset($xoopsConfig['cpanel']) ? $cPrefix .$xoopsConfig['cpanel'] : $cPrefix . 'default';
|
148: | }
|
149: | $module_dirname = empty($module_dirname) ? (empty($GLOBALS['xoopsModule']) ? 'system' : $GLOBALS['xoopsModule']->getVar('dirname', 'n')) : $module_dirname;
|
150: | $this->compile_id = substr(md5(XOOPS_URL), 0, 8) . '-' . $module_dirname . '-' . $theme_set . '-' . $template_set;
|
151: |
|
152: | }
|
153: |
|
154: | |
155: | |
156: | |
157: | |
158: | |
159: | |
160: | |
161: |
|
162: | public function xoopsClearCache($module_dirname = null, $theme_set = null, $template_set = null)
|
163: | {
|
164: | $compile_id = $this->compile_id;
|
165: | $this->setCompileId($module_dirname, $template_set, $theme_set);
|
166: | return $this->clearCompiledTemplate(null, $compile_id);
|
167: | }
|
168: |
|
169: | |
170: | |
171: | |
172: | |
173: |
|
174: | public function xoops_setTemplateDir($dirname)
|
175: | {
|
176: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . '($value) is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->template_dir=$value;\' instead.');
|
177: |
|
178: | $this->template_dir = $dirname;
|
179: | }
|
180: |
|
181: | |
182: | |
183: | |
184: |
|
185: | public function xoops_getTemplateDir()
|
186: | {
|
187: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . '() is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->template_dir;\' instead.');
|
188: |
|
189: | return $this->template_dir;
|
190: | }
|
191: |
|
192: | |
193: | |
194: | |
195: |
|
196: | public function xoops_setDebugging($flag = false)
|
197: | {
|
198: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . '($value) is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->debugging=$value;\' instead.');
|
199: |
|
200: | $this->debugging = is_bool($flag) ? $flag : false;
|
201: | }
|
202: |
|
203: | |
204: | |
205: | |
206: |
|
207: | public function xoops_setCaching($num = 0)
|
208: | {
|
209: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . '($value) is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->caching=$value;\' instead.');
|
210: |
|
211: | $this->caching = (int)$num;
|
212: | }
|
213: |
|
214: | |
215: | |
216: | |
217: |
|
218: | public function xoops_setCompileDir($dirname)
|
219: | {
|
220: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . '($value) is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->compile_dir=$value;\' instead.');
|
221: |
|
222: | $this->compile_dir = $dirname;
|
223: | }
|
224: |
|
225: | |
226: | |
227: | |
228: |
|
229: | public function xoops_setCacheDir($dirname)
|
230: | {
|
231: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . '($value) is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->cache_dir=$value;\' instead.');
|
232: |
|
233: | $this->cache_dir = $dirname;
|
234: | }
|
235: |
|
236: | |
237: | |
238: | |
239: |
|
240: | public function xoops_canUpdateFromFile()
|
241: | {
|
242: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . '($value) is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->compile_check;\' instead.');
|
243: |
|
244: | return $this->compile_check;
|
245: | }
|
246: |
|
247: | |
248: | |
249: | |
250: | |
251: | |
252: |
|
253: | public function xoops_fetchFromData($data)
|
254: | {
|
255: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . '($value) is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->fetchFromData($value);\' instead.');
|
256: |
|
257: | return $this->fetchFromData($data);
|
258: | }
|
259: |
|
260: | |
261: | |
262: | |
263: |
|
264: | public function xoops_setCacheTime($num = 0)
|
265: | {
|
266: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . '($value) is deprecated since XOOPS 2.5.4, please use \'$xoopsTpl->cache_lifetime=$value;\' instead.');
|
267: |
|
268: | if (($num = (int)$num) <= 0) {
|
269: | $this->caching = 0;
|
270: | } else {
|
271: | $this->cache_lifetime = $num;
|
272: | }
|
273: | }
|
274: |
|
275: | |
276: | |
277: | |
278: | |
279: | |
280: |
|
281: | public function assign_by_ref($tpl_var, &$value)
|
282: | {
|
283: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use assignByRef");
|
284: | $this->assignByRef($tpl_var, $value);
|
285: | }
|
286: |
|
287: | |
288: | |
289: | |
290: | |
291: | |
292: | |
293: |
|
294: | public function append_by_ref($tpl_var, &$value, $merge = false)
|
295: | {
|
296: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use appendByRef");
|
297: | $this->appendByRef($tpl_var, $value, $merge);
|
298: | }
|
299: |
|
300: | |
301: | |
302: | |
303: | |
304: |
|
305: | public function clear_assign($tpl_var)
|
306: | {
|
307: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use clearAssign");
|
308: | $this->clearAssign($tpl_var);
|
309: | }
|
310: |
|
311: | |
312: | |
313: | |
314: | |
315: | |
316: | |
317: | |
318: | |
319: | |
320: |
|
321: | public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null)
|
322: | {
|
323: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use registerPlugin");
|
324: | $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
|
325: | }
|
326: |
|
327: | |
328: | |
329: | |
330: | |
331: |
|
332: | public function unregister_function($function)
|
333: | {
|
334: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use unregisterPlugin");
|
335: | $this->unregisterPlugin('function', $function);
|
336: | }
|
337: |
|
338: | |
339: | |
340: | |
341: | |
342: | |
343: | |
344: | |
345: | |
346: | |
347: | |
348: | |
349: |
|
350: | public function register_object(
|
351: | $object,
|
352: | $object_impl,
|
353: | $allowed = array(),
|
354: | $smarty_args = true,
|
355: | $block_methods = array()
|
356: | ) {
|
357: | settype($allowed, 'array');
|
358: | settype($smarty_args, 'boolean');
|
359: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use registerObject");
|
360: | $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
|
361: | }
|
362: |
|
363: | |
364: | |
365: | |
366: | |
367: |
|
368: | public function unregister_object($object)
|
369: | {
|
370: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use unregisterObject");
|
371: | $this->unregisterObject($object);
|
372: | }
|
373: |
|
374: | |
375: | |
376: | |
377: | |
378: | |
379: | |
380: | |
381: | |
382: | |
383: |
|
384: | public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null)
|
385: | {
|
386: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use registerPlugin");
|
387: | $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
|
388: | }
|
389: |
|
390: | |
391: | |
392: | |
393: | |
394: |
|
395: | public function unregister_block($block)
|
396: | {
|
397: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use unregisterPlugin");
|
398: | $this->unregisterPlugin('block', $block);
|
399: | }
|
400: |
|
401: | |
402: | |
403: | |
404: | |
405: | |
406: | |
407: | |
408: | |
409: |
|
410: | public function register_compiler_function($function, $function_impl, $cacheable = true)
|
411: | {
|
412: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use registerPlugin");
|
413: | $this->registerPlugin('compiler', $function, $function_impl, $cacheable);
|
414: | }
|
415: |
|
416: | |
417: | |
418: | |
419: | |
420: |
|
421: | public function unregister_compiler_function($function)
|
422: | {
|
423: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use unregisterPlugin");
|
424: | $this->unregisterPlugin('compiler', $function);
|
425: | }
|
426: |
|
427: | |
428: | |
429: | |
430: | |
431: | |
432: | |
433: | |
434: |
|
435: | public function register_modifier($modifier, $modifier_impl)
|
436: | {
|
437: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use registerPlugin");
|
438: | $this->registerPlugin('modifier', $modifier, $modifier_impl);
|
439: | }
|
440: |
|
441: | |
442: | |
443: | |
444: | |
445: |
|
446: | public function unregister_modifier($modifier)
|
447: | {
|
448: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use unregisterPlugin");
|
449: | $this->unregisterPlugin('modifier', $modifier);
|
450: | }
|
451: |
|
452: | |
453: | |
454: | |
455: | |
456: | |
457: |
|
458: | public function register_resource($type, $functions)
|
459: | {
|
460: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use registerResource");
|
461: | $this->registerResource($type, $functions);
|
462: | }
|
463: |
|
464: | |
465: | |
466: | |
467: | |
468: |
|
469: | public function unregister_resource($type)
|
470: | {
|
471: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use unregisterResource");
|
472: | $this->unregisterResource($type);
|
473: | }
|
474: |
|
475: | |
476: | |
477: | |
478: | |
479: | |
480: | |
481: |
|
482: | public function register_prefilter($function)
|
483: | {
|
484: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use registerFilter");
|
485: | $this->registerFilter('pre', $function);
|
486: | }
|
487: |
|
488: | |
489: | |
490: | |
491: | |
492: |
|
493: | public function unregister_prefilter($function)
|
494: | {
|
495: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use unregisterFilter");
|
496: | $this->unregisterFilter('pre', $function);
|
497: | }
|
498: |
|
499: | |
500: | |
501: | |
502: | |
503: | |
504: | |
505: |
|
506: | public function register_postfilter($function)
|
507: | {
|
508: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use registerFilter");
|
509: | $this->registerFilter('post', $function);
|
510: | }
|
511: |
|
512: | |
513: | |
514: | |
515: | |
516: |
|
517: | public function unregister_postfilter($function)
|
518: | {
|
519: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use unregisterFilter");
|
520: | $this->unregisterFilter('post', $function);
|
521: | }
|
522: |
|
523: | |
524: | |
525: | |
526: | |
527: | |
528: | |
529: |
|
530: | public function register_outputfilter($function)
|
531: | {
|
532: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use registerFilter");
|
533: | $this->registerFilter('output', $function);
|
534: | }
|
535: |
|
536: | |
537: | |
538: | |
539: | |
540: |
|
541: | public function unregister_outputfilter($function)
|
542: | {
|
543: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use unregisterFilter");
|
544: | $this->unregisterFilter('output', $function);
|
545: | }
|
546: |
|
547: | |
548: | |
549: | |
550: | |
551: | |
552: | |
553: | |
554: |
|
555: | public function load_filter($type, $name)
|
556: | {
|
557: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use loadFilter");
|
558: | $this->loadFilter($type, $name);
|
559: | }
|
560: |
|
561: | |
562: | |
563: | |
564: | |
565: | |
566: | |
567: | |
568: | |
569: | |
570: |
|
571: | public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
|
572: | {
|
573: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use clearCache");
|
574: | return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
|
575: | }
|
576: |
|
577: | |
578: | |
579: | |
580: | |
581: | |
582: | |
583: |
|
584: | public function clear_all_cache($exp_time = null)
|
585: | {
|
586: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use clearCache");
|
587: | return $this->clearCache(null, null, null, $exp_time);
|
588: | }
|
589: |
|
590: | |
591: | |
592: | |
593: | |
594: | |
595: | |
596: | |
597: | |
598: | |
599: | |
600: |
|
601: | public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
|
602: | {
|
603: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use isCached");
|
604: | return $this->isCached($tpl_file, $cache_id, $compile_id);
|
605: | }
|
606: |
|
607: | |
608: | |
609: |
|
610: | public function clear_all_assign()
|
611: | {
|
612: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use clearAllAssign");
|
613: | $this->clearAllAssign();
|
614: | }
|
615: |
|
616: | |
617: | |
618: | |
619: | |
620: | |
621: | |
622: | |
623: | |
624: |
|
625: | public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
|
626: | {
|
627: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use clearCompiledTemplate");
|
628: | return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
|
629: | }
|
630: |
|
631: | |
632: | |
633: | |
634: | |
635: | |
636: | |
637: | |
638: |
|
639: | public function template_exists($tpl_file)
|
640: | {
|
641: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use templateExists");
|
642: | return $this->templateExists($tpl_file);
|
643: | }
|
644: |
|
645: | |
646: | |
647: | |
648: | |
649: | |
650: | |
651: |
|
652: | public function get_template_vars($name = null)
|
653: | {
|
654: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use getTemplateVars");
|
655: | return $this->getTemplateVars($name);
|
656: | }
|
657: |
|
658: | |
659: | |
660: | |
661: | |
662: | |
663: | |
664: |
|
665: | public function get_config_vars($name = null)
|
666: | {
|
667: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use getConfigVars");
|
668: | return $this->getConfigVars($name);
|
669: | }
|
670: |
|
671: | |
672: | |
673: | |
674: | |
675: | |
676: | |
677: |
|
678: | public function config_load($file, $section = null, $scope = 'global')
|
679: | {
|
680: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use ConfigLoad");
|
681: | $this->ConfigLoad($file, $section, $scope);
|
682: | }
|
683: |
|
684: | |
685: | |
686: | |
687: | |
688: | |
689: | |
690: |
|
691: | public function get_registered_object($name)
|
692: | {
|
693: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use getRegisteredObject");
|
694: | return $this->getRegisteredObject($name);
|
695: | }
|
696: |
|
697: | |
698: | |
699: | |
700: | |
701: |
|
702: | public function clear_config($var = null)
|
703: | {
|
704: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated, please use clearConfig");
|
705: | $this->clearConfig($var);
|
706: | }
|
707: | }
|
708: |
|
709: | |
710: | |
711: | |
712: | |
713: | |
714: | |
715: |
|
716: | function xoops_template_touch($tpl_id)
|
717: | {
|
718: | $tplfile_handler = xoops_getHandler('tplfile');
|
719: | $tplfile = $tplfile_handler->get((int)$tpl_id);
|
720: |
|
721: | if (is_object($tplfile)) {
|
722: | $file = $tplfile->getVar('tpl_file', 'n');
|
723: | $tpl = new XoopsTpl();
|
724: |
|
725: | return $tpl->xoopsTouch('db:' . $file);
|
726: | }
|
727: |
|
728: | return false;
|
729: | }
|
730: |
|
731: | |
732: | |
733: | |
734: | |
735: | |
736: |
|
737: | function xoops_template_clear_module_cache($mid)
|
738: | {
|
739: | $block_arr = XoopsBlock::getByModule($mid);
|
740: | $count = count($block_arr);
|
741: | if ($count > 0) {
|
742: | $xoopsTpl = new XoopsTpl();
|
743: | $xoopsTpl->caching = 2;
|
744: | for ($i = 0; $i < $count; ++$i) {
|
745: | if ($block_arr[$i]->getVar('template') != '') {
|
746: | $xoopsTpl->clearCache('db:' . $block_arr[$i]->getVar('template'), 'blk_' . $block_arr[$i]->getVar('bid'));
|
747: | }
|
748: | }
|
749: | }
|
750: | }
|
751: | |