Commit | Line | Data |
---|---|---|
e586807d | 1 | <?php |
b42b2bf9 | 2 | |
e586807d H |
3 | /** |
4 | * Project: Smarty: the PHP compiling template engine | |
5 | * File: Smarty.class.php | |
6 | * | |
7 | * This library is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2.1 of the License, or (at your option) any later version. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
18 | * License along with this library; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | * | |
21 | * For questions, help, comments, discussion, etc., please join the | |
22 | * Smarty mailing list. Send a blank e-mail to | |
23 | * smarty-general-subscribe@lists.php.net | |
24 | * | |
e586807d | 25 | * @link http://smarty.php.net/ |
b42b2bf9 H |
26 | * @copyright 2001-2005 New Digital Group, Inc. |
27 | * @author Monte Ohrt <monte at ohrt dot com> | |
e586807d H |
28 | * @author Andrei Zmievski <andrei@php.net> |
29 | * @package Smarty | |
b42b2bf9 | 30 | * @version 2.6.10 |
e586807d H |
31 | */ |
32 | ||
b42b2bf9 | 33 | /* $Id: Smarty.class.php,v 1.516 2005/07/18 08:43:53 messju Exp $ */ |
e586807d H |
34 | |
35 | /** | |
36 | * DIR_SEP isn't used anymore, but third party apps might | |
37 | */ | |
38 | if(!defined('DIR_SEP')) { | |
b42b2bf9 | 39 | define('DIR_SEP', DIRECTORY_SEPARATOR); |
e586807d H |
40 | } |
41 | ||
42 | /** | |
43 | * set SMARTY_DIR to absolute path to Smarty library files. | |
44 | * if not defined, include_path will be used. Sets SMARTY_DIR only if user | |
45 | * application has not already defined it. | |
46 | */ | |
47 | ||
48 | if (!defined('SMARTY_DIR')) { | |
49 | define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); | |
50 | } | |
51 | ||
b42b2bf9 H |
52 | if (!defined('SMARTY_CORE_DIR')) { |
53 | define('SMARTY_CORE_DIR', SMARTY_DIR . 'internals' . DIRECTORY_SEPARATOR); | |
54 | } | |
55 | ||
e586807d H |
56 | define('SMARTY_PHP_PASSTHRU', 0); |
57 | define('SMARTY_PHP_QUOTE', 1); | |
58 | define('SMARTY_PHP_REMOVE', 2); | |
59 | define('SMARTY_PHP_ALLOW', 3); | |
60 | ||
61 | /** | |
62 | * @package Smarty | |
63 | */ | |
64 | class Smarty | |
65 | { | |
66 | /**#@+ | |
67 | * Smarty Configuration Section | |
68 | */ | |
69 | ||
70 | /** | |
71 | * The name of the directory where templates are located. | |
72 | * | |
73 | * @var string | |
74 | */ | |
75 | var $template_dir = 'templates'; | |
76 | ||
77 | /** | |
78 | * The directory where compiled templates are located. | |
79 | * | |
80 | * @var string | |
81 | */ | |
82 | var $compile_dir = 'templates_c'; | |
83 | ||
84 | /** | |
85 | * The directory where config files are located. | |
86 | * | |
87 | * @var string | |
88 | */ | |
89 | var $config_dir = 'configs'; | |
90 | ||
91 | /** | |
92 | * An array of directories searched for plugins. | |
93 | * | |
94 | * @var array | |
95 | */ | |
96 | var $plugins_dir = array('plugins'); | |
97 | ||
98 | /** | |
99 | * If debugging is enabled, a debug console window will display | |
100 | * when the page loads (make sure your browser allows unrequested | |
101 | * popup windows) | |
102 | * | |
103 | * @var boolean | |
104 | */ | |
105 | var $debugging = false; | |
106 | ||
b42b2bf9 H |
107 | /** |
108 | * When set, smarty does uses this value as error_reporting-level. | |
109 | * | |
110 | * @var boolean | |
111 | */ | |
112 | var $error_reporting = null; | |
113 | ||
e586807d H |
114 | /** |
115 | * This is the path to the debug console template. If not set, | |
116 | * the default one will be used. | |
117 | * | |
118 | * @var string | |
119 | */ | |
120 | var $debug_tpl = ''; | |
121 | ||
122 | /** | |
123 | * This determines if debugging is enable-able from the browser. | |
124 | * <ul> | |
125 | * <li>NONE => no debugging control allowed</li> | |
126 | * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li> | |
127 | * </ul> | |
128 | * @link http://www.foo.dom/index.php?SMARTY_DEBUG | |
129 | * @var string | |
130 | */ | |
131 | var $debugging_ctrl = 'NONE'; | |
132 | ||
133 | /** | |
134 | * This tells Smarty whether to check for recompiling or not. Recompiling | |
135 | * does not need to happen unless a template or config file is changed. | |
136 | * Typically you enable this during development, and disable for | |
137 | * production. | |
138 | * | |
139 | * @var boolean | |
140 | */ | |
141 | var $compile_check = true; | |
142 | ||
143 | /** | |
144 | * This forces templates to compile every time. Useful for development | |
145 | * or debugging. | |
146 | * | |
147 | * @var boolean | |
148 | */ | |
149 | var $force_compile = false; | |
150 | ||
151 | /** | |
152 | * This enables template caching. | |
153 | * <ul> | |
154 | * <li>0 = no caching</li> | |
155 | * <li>1 = use class cache_lifetime value</li> | |
156 | * <li>2 = use cache_lifetime in cache file</li> | |
157 | * </ul> | |
158 | * @var integer | |
159 | */ | |
160 | var $caching = 0; | |
161 | ||
162 | /** | |
163 | * The name of the directory for cache files. | |
164 | * | |
165 | * @var string | |
166 | */ | |
167 | var $cache_dir = 'cache'; | |
168 | ||
169 | /** | |
170 | * This is the number of seconds cached content will persist. | |
171 | * <ul> | |
172 | * <li>0 = always regenerate cache</li> | |
173 | * <li>-1 = never expires</li> | |
174 | * </ul> | |
175 | * | |
176 | * @var integer | |
177 | */ | |
178 | var $cache_lifetime = 3600; | |
179 | ||
180 | /** | |
181 | * Only used when $caching is enabled. If true, then If-Modified-Since headers | |
182 | * are respected with cached content, and appropriate HTTP headers are sent. | |
183 | * This way repeated hits to a cached page do not send the entire page to the | |
184 | * client every time. | |
185 | * | |
186 | * @var boolean | |
187 | */ | |
188 | var $cache_modified_check = false; | |
189 | ||
190 | /** | |
191 | * This determines how Smarty handles "<?php ... ?>" tags in templates. | |
192 | * possible values: | |
193 | * <ul> | |
194 | * <li>SMARTY_PHP_PASSTHRU -> print tags as plain text</li> | |
195 | * <li>SMARTY_PHP_QUOTE -> escape tags as entities</li> | |
196 | * <li>SMARTY_PHP_REMOVE -> remove php tags</li> | |
197 | * <li>SMARTY_PHP_ALLOW -> execute php tags</li> | |
198 | * </ul> | |
199 | * | |
200 | * @var integer | |
201 | */ | |
202 | var $php_handling = SMARTY_PHP_PASSTHRU; | |
203 | ||
204 | /** | |
205 | * This enables template security. When enabled, many things are restricted | |
206 | * in the templates that normally would go unchecked. This is useful when | |
207 | * untrusted parties are editing templates and you want a reasonable level | |
208 | * of security. (no direct execution of PHP in templates for example) | |
209 | * | |
210 | * @var boolean | |
211 | */ | |
b42b2bf9 | 212 | var $security = true; |
e586807d H |
213 | |
214 | /** | |
215 | * This is the list of template directories that are considered secure. This | |
216 | * is used only if {@link $security} is enabled. One directory per array | |
217 | * element. {@link $template_dir} is in this list implicitly. | |
218 | * | |
219 | * @var array | |
220 | */ | |
221 | var $secure_dir = array(); | |
222 | ||
223 | /** | |
224 | * These are the security settings for Smarty. They are used only when | |
225 | * {@link $security} is enabled. | |
226 | * | |
227 | * @var array | |
228 | */ | |
229 | var $security_settings = array( | |
230 | 'PHP_HANDLING' => false, | |
231 | 'IF_FUNCS' => array('array', 'list', | |
232 | 'isset', 'empty', | |
233 | 'count', 'sizeof', | |
234 | 'in_array', 'is_array', | |
b42b2bf9 | 235 | 'true', 'false', 'null'), |
e586807d H |
236 | 'INCLUDE_ANY' => false, |
237 | 'PHP_TAGS' => false, | |
238 | 'MODIFIER_FUNCS' => array('count'), | |
b42b2bf9 | 239 | 'ALLOW_CONSTANTS' => false |
e586807d H |
240 | ); |
241 | ||
242 | /** | |
243 | * This is an array of directories where trusted php scripts reside. | |
244 | * {@link $security} is disabled during their inclusion/execution. | |
245 | * | |
246 | * @var array | |
247 | */ | |
248 | var $trusted_dir = array(); | |
249 | ||
250 | /** | |
251 | * The left delimiter used for the template tags. | |
252 | * | |
253 | * @var string | |
254 | */ | |
255 | var $left_delimiter = '{'; | |
256 | ||
257 | /** | |
258 | * The right delimiter used for the template tags. | |
259 | * | |
260 | * @var string | |
261 | */ | |
262 | var $right_delimiter = '}'; | |
263 | ||
264 | /** | |
265 | * The order in which request variables are registered, similar to | |
266 | * variables_order in php.ini E = Environment, G = GET, P = POST, | |
267 | * C = Cookies, S = Server | |
268 | * | |
269 | * @var string | |
270 | */ | |
b42b2bf9 | 271 | var $request_vars_order = 'EGPCS'; |
e586807d H |
272 | |
273 | /** | |
274 | * Indicates wether $HTTP_*_VARS[] (request_use_auto_globals=false) | |
275 | * are uses as request-vars or $_*[]-vars. note: if | |
276 | * request_use_auto_globals is true, then $request_vars_order has | |
277 | * no effect, but the php-ini-value "gpc_order" | |
278 | * | |
279 | * @var boolean | |
280 | */ | |
b42b2bf9 | 281 | var $request_use_auto_globals = true; |
e586807d H |
282 | |
283 | /** | |
284 | * Set this if you want different sets of compiled files for the same | |
285 | * templates. This is useful for things like different languages. | |
286 | * Instead of creating separate sets of templates per language, you | |
287 | * set different compile_ids like 'en' and 'de'. | |
288 | * | |
289 | * @var string | |
290 | */ | |
291 | var $compile_id = null; | |
292 | ||
293 | /** | |
294 | * This tells Smarty whether or not to use sub dirs in the cache/ and | |
295 | * templates_c/ directories. sub directories better organized, but | |
296 | * may not work well with PHP safe mode enabled. | |
297 | * | |
298 | * @var boolean | |
299 | * | |
300 | */ | |
b42b2bf9 | 301 | var $use_sub_dirs = false; |
e586807d H |
302 | |
303 | /** | |
304 | * This is a list of the modifiers to apply to all template variables. | |
305 | * Put each modifier in a separate array element in the order you want | |
306 | * them applied. example: <code>array('escape:"htmlall"');</code> | |
307 | * | |
308 | * @var array | |
309 | */ | |
310 | var $default_modifiers = array(); | |
311 | ||
312 | /** | |
313 | * This is the resource type to be used when not specified | |
b42b2bf9 H |
314 | * at the beginning of the resource path. examples: |
315 | * $smarty->display('file:index.tpl'); | |
316 | * $smarty->display('db:index.tpl'); | |
317 | * $smarty->display('index.tpl'); // will use default resource type | |
318 | * {include file="file:index.tpl"} | |
319 | * {include file="db:index.tpl"} | |
320 | * {include file="index.tpl"} {* will use default resource type *} | |
e586807d H |
321 | * |
322 | * @var array | |
323 | */ | |
324 | var $default_resource_type = 'file'; | |
325 | ||
326 | /** | |
327 | * The function used for cache file handling. If not set, built-in caching is used. | |
328 | * | |
329 | * @var null|string function name | |
330 | */ | |
331 | var $cache_handler_func = null; | |
332 | ||
e586807d H |
333 | /** |
334 | * This indicates which filters are automatically loaded into Smarty. | |
335 | * | |
336 | * @var array array of filter names | |
337 | */ | |
338 | var $autoload_filters = array(); | |
339 | ||
340 | /**#@+ | |
341 | * @var boolean | |
342 | */ | |
343 | /** | |
344 | * This tells if config file vars of the same name overwrite each other or not. | |
345 | * if disabled, same name variables are accumulated in an array. | |
346 | */ | |
347 | var $config_overwrite = true; | |
348 | ||
349 | /** | |
350 | * This tells whether or not to automatically booleanize config file variables. | |
351 | * If enabled, then the strings "on", "true", and "yes" are treated as boolean | |
352 | * true, and "off", "false" and "no" are treated as boolean false. | |
353 | */ | |
354 | var $config_booleanize = true; | |
355 | ||
356 | /** | |
357 | * This tells whether hidden sections [.foobar] are readable from the | |
358 | * tempalates or not. Normally you would never allow this since that is | |
359 | * the point behind hidden sections: the application can access them, but | |
360 | * the templates cannot. | |
361 | */ | |
362 | var $config_read_hidden = false; | |
363 | ||
364 | /** | |
365 | * This tells whether or not automatically fix newlines in config files. | |
366 | * It basically converts \r (mac) or \r\n (dos) to \n | |
367 | */ | |
368 | var $config_fix_newlines = true; | |
369 | /**#@-*/ | |
370 | ||
371 | /** | |
372 | * If a template cannot be found, this PHP function will be executed. | |
373 | * Useful for creating templates on-the-fly or other special action. | |
374 | * | |
375 | * @var string function name | |
376 | */ | |
377 | var $default_template_handler_func = ''; | |
378 | ||
379 | /** | |
380 | * The file that contains the compiler class. This can a full | |
381 | * pathname, or relative to the php_include path. | |
382 | * | |
383 | * @var string | |
384 | */ | |
385 | var $compiler_file = 'Smarty_Compiler.class.php'; | |
386 | ||
387 | /** | |
388 | * The class used for compiling templates. | |
389 | * | |
390 | * @var string | |
391 | */ | |
392 | var $compiler_class = 'Smarty_Compiler'; | |
393 | ||
394 | /** | |
395 | * The class used to load config vars. | |
396 | * | |
397 | * @var string | |
398 | */ | |
399 | var $config_class = 'Config_File'; | |
400 | ||
401 | /**#@+ | |
402 | * END Smarty Configuration Section | |
403 | * There should be no need to touch anything below this line. | |
404 | * @access private | |
405 | */ | |
e586807d H |
406 | /** |
407 | * where assigned template vars are kept | |
408 | * | |
409 | * @var array | |
410 | */ | |
411 | var $_tpl_vars = array(); | |
412 | ||
413 | /** | |
414 | * stores run-time $smarty.* vars | |
415 | * | |
416 | * @var null|array | |
417 | */ | |
418 | var $_smarty_vars = null; | |
419 | ||
420 | /** | |
421 | * keeps track of sections | |
422 | * | |
423 | * @var array | |
424 | */ | |
425 | var $_sections = array(); | |
426 | ||
427 | /** | |
428 | * keeps track of foreach blocks | |
429 | * | |
430 | * @var array | |
431 | */ | |
432 | var $_foreach = array(); | |
433 | ||
434 | /** | |
435 | * keeps track of tag hierarchy | |
436 | * | |
437 | * @var array | |
438 | */ | |
439 | var $_tag_stack = array(); | |
440 | ||
441 | /** | |
442 | * configuration object | |
443 | * | |
444 | * @var Config_file | |
445 | */ | |
446 | var $_conf_obj = null; | |
447 | ||
448 | /** | |
449 | * loaded configuration settings | |
450 | * | |
451 | * @var array | |
452 | */ | |
453 | var $_config = array(array('vars' => array(), 'files' => array())); | |
454 | ||
455 | /** | |
456 | * md5 checksum of the string 'Smarty' | |
457 | * | |
458 | * @var string | |
459 | */ | |
460 | var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; | |
461 | ||
462 | /** | |
463 | * Smarty version number | |
464 | * | |
465 | * @var string | |
466 | */ | |
b42b2bf9 | 467 | var $_version = '2.6.10'; |
e586807d H |
468 | |
469 | /** | |
470 | * current template inclusion depth | |
471 | * | |
472 | * @var integer | |
473 | */ | |
474 | var $_inclusion_depth = 0; | |
475 | ||
476 | /** | |
477 | * for different compiled templates | |
478 | * | |
479 | * @var string | |
480 | */ | |
481 | var $_compile_id = null; | |
482 | ||
483 | /** | |
484 | * text in URL to enable debug mode | |
485 | * | |
486 | * @var string | |
487 | */ | |
488 | var $_smarty_debug_id = 'SMARTY_DEBUG'; | |
489 | ||
490 | /** | |
491 | * debugging information for debug console | |
492 | * | |
493 | * @var array | |
494 | */ | |
495 | var $_smarty_debug_info = array(); | |
496 | ||
497 | /** | |
498 | * info that makes up a cache file | |
499 | * | |
500 | * @var array | |
501 | */ | |
502 | var $_cache_info = array(); | |
503 | ||
504 | /** | |
505 | * default file permissions | |
506 | * | |
507 | * @var integer | |
508 | */ | |
509 | var $_file_perms = 0644; | |
510 | ||
511 | /** | |
512 | * default dir permissions | |
513 | * | |
514 | * @var integer | |
515 | */ | |
516 | var $_dir_perms = 0771; | |
517 | ||
518 | /** | |
519 | * registered objects | |
520 | * | |
521 | * @var array | |
522 | */ | |
523 | var $_reg_objects = array(); | |
524 | ||
525 | /** | |
526 | * table keeping track of plugins | |
527 | * | |
528 | * @var array | |
529 | */ | |
530 | var $_plugins = array( | |
531 | 'modifier' => array(), | |
532 | 'function' => array(), | |
533 | 'block' => array(), | |
534 | 'compiler' => array(), | |
535 | 'prefilter' => array(), | |
536 | 'postfilter' => array(), | |
537 | 'outputfilter' => array(), | |
538 | 'resource' => array(), | |
539 | 'insert' => array()); | |
540 | ||
541 | ||
542 | /** | |
543 | * cache serials | |
544 | * | |
545 | * @var array | |
546 | */ | |
547 | var $_cache_serials = array(); | |
548 | ||
549 | /** | |
550 | * name of optional cache include file | |
551 | * | |
552 | * @var string | |
553 | */ | |
554 | var $_cache_include = null; | |
555 | ||
556 | /** | |
557 | * indicate if the current code is used in a compiled | |
558 | * include | |
559 | * | |
560 | * @var string | |
561 | */ | |
562 | var $_cache_including = false; | |
563 | ||
564 | /**#@-*/ | |
565 | /** | |
566 | * The class constructor. | |
e586807d H |
567 | */ |
568 | function Smarty() | |
569 | { | |
b42b2bf9 H |
570 | $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] |
571 | : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']); | |
e586807d H |
572 | } |
573 | ||
e586807d H |
574 | /** |
575 | * assigns values to template variables | |
576 | * | |
577 | * @param array|string $tpl_var the template variable name(s) | |
578 | * @param mixed $value the value to assign | |
579 | */ | |
580 | function assign($tpl_var, $value = null) | |
581 | { | |
582 | if (is_array($tpl_var)){ | |
583 | foreach ($tpl_var as $key => $val) { | |
584 | if ($key != '') { | |
585 | $this->_tpl_vars[$key] = $val; | |
586 | } | |
587 | } | |
588 | } else { | |
589 | if ($tpl_var != '') | |
590 | $this->_tpl_vars[$tpl_var] = $value; | |
591 | } | |
592 | } | |
593 | ||
594 | /** | |
595 | * assigns values to template variables by reference | |
596 | * | |
597 | * @param string $tpl_var the template variable name | |
598 | * @param mixed $value the referenced value to assign | |
599 | */ | |
600 | function assign_by_ref($tpl_var, &$value) | |
601 | { | |
602 | if ($tpl_var != '') | |
603 | $this->_tpl_vars[$tpl_var] = &$value; | |
604 | } | |
605 | ||
606 | /** | |
607 | * appends values to template variables | |
608 | * | |
609 | * @param array|string $tpl_var the template variable name(s) | |
610 | * @param mixed $value the value to append | |
611 | */ | |
612 | function append($tpl_var, $value=null, $merge=false) | |
613 | { | |
614 | if (is_array($tpl_var)) { | |
b42b2bf9 | 615 | // $tpl_var is an array, ignore $value |
e586807d H |
616 | foreach ($tpl_var as $_key => $_val) { |
617 | if ($_key != '') { | |
b42b2bf9 H |
618 | if(!@is_array($this->_tpl_vars[$_key])) { |
619 | settype($this->_tpl_vars[$_key],'array'); | |
620 | } | |
621 | if($merge && is_array($_val)) { | |
622 | foreach($_val as $_mkey => $_mval) { | |
623 | $this->_tpl_vars[$_key][$_mkey] = $_mval; | |
624 | } | |
625 | } else { | |
626 | $this->_tpl_vars[$_key][] = $_val; | |
627 | } | |
e586807d H |
628 | } |
629 | } | |
630 | } else { | |
631 | if ($tpl_var != '' && isset($value)) { | |
b42b2bf9 H |
632 | if(!@is_array($this->_tpl_vars[$tpl_var])) { |
633 | settype($this->_tpl_vars[$tpl_var],'array'); | |
634 | } | |
635 | if($merge && is_array($value)) { | |
636 | foreach($value as $_mkey => $_mval) { | |
637 | $this->_tpl_vars[$tpl_var][$_mkey] = $_mval; | |
638 | } | |
639 | } else { | |
640 | $this->_tpl_vars[$tpl_var][] = $value; | |
641 | } | |
e586807d H |
642 | } |
643 | } | |
644 | } | |
645 | ||
646 | /** | |
647 | * appends values to template variables by reference | |
648 | * | |
649 | * @param string $tpl_var the template variable name | |
650 | * @param mixed $value the referenced value to append | |
651 | */ | |
652 | function append_by_ref($tpl_var, &$value, $merge=false) | |
653 | { | |
654 | if ($tpl_var != '' && isset($value)) { | |
b42b2bf9 H |
655 | if(!@is_array($this->_tpl_vars[$tpl_var])) { |
656 | settype($this->_tpl_vars[$tpl_var],'array'); | |
657 | } | |
658 | if ($merge && is_array($value)) { | |
659 | foreach($value as $_key => $_val) { | |
660 | $this->_tpl_vars[$tpl_var][$_key] = &$value[$_key]; | |
661 | } | |
662 | } else { | |
663 | $this->_tpl_vars[$tpl_var][] = &$value; | |
664 | } | |
e586807d H |
665 | } |
666 | } | |
667 | ||
668 | ||
669 | /** | |
670 | * clear the given assigned template variable. | |
671 | * | |
672 | * @param string $tpl_var the template variable to clear | |
673 | */ | |
674 | function clear_assign($tpl_var) | |
675 | { | |
676 | if (is_array($tpl_var)) | |
677 | foreach ($tpl_var as $curr_var) | |
678 | unset($this->_tpl_vars[$curr_var]); | |
679 | else | |
680 | unset($this->_tpl_vars[$tpl_var]); | |
681 | } | |
682 | ||
683 | ||
684 | /** | |
685 | * Registers custom function to be used in templates | |
686 | * | |
687 | * @param string $function the name of the template function | |
688 | * @param string $function_impl the name of the PHP function to register | |
689 | */ | |
690 | function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null) | |
691 | { | |
692 | $this->_plugins['function'][$function] = | |
693 | array($function_impl, null, null, false, $cacheable, $cache_attrs); | |
694 | ||
695 | } | |
696 | ||
697 | /** | |
698 | * Unregisters custom function | |
699 | * | |
700 | * @param string $function name of template function | |
701 | */ | |
702 | function unregister_function($function) | |
703 | { | |
704 | unset($this->_plugins['function'][$function]); | |
705 | } | |
706 | ||
707 | /** | |
708 | * Registers object to be used in templates | |
709 | * | |
710 | * @param string $object name of template object | |
711 | * @param object &$object_impl the referenced PHP object to register | |
712 | * @param null|array $allowed list of allowed methods (empty = all) | |
713 | * @param boolean $smarty_args smarty argument format, else traditional | |
714 | * @param null|array $block_functs list of methods that are block format | |
715 | */ | |
716 | function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) | |
717 | { | |
718 | settype($allowed, 'array'); | |
719 | settype($smarty_args, 'boolean'); | |
720 | $this->_reg_objects[$object] = | |
721 | array(&$object_impl, $allowed, $smarty_args, $block_methods); | |
722 | } | |
723 | ||
724 | /** | |
725 | * Unregisters object | |
726 | * | |
727 | * @param string $object name of template object | |
728 | */ | |
729 | function unregister_object($object) | |
730 | { | |
731 | unset($this->_reg_objects[$object]); | |
732 | } | |
733 | ||
734 | ||
735 | /** | |
736 | * Registers block function to be used in templates | |
737 | * | |
738 | * @param string $block name of template block | |
739 | * @param string $block_impl PHP function to register | |
740 | */ | |
741 | function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null) | |
742 | { | |
743 | $this->_plugins['block'][$block] = | |
744 | array($block_impl, null, null, false, $cacheable, $cache_attrs); | |
745 | } | |
746 | ||
747 | /** | |
748 | * Unregisters block function | |
749 | * | |
750 | * @param string $block name of template function | |
751 | */ | |
752 | function unregister_block($block) | |
753 | { | |
754 | unset($this->_plugins['block'][$block]); | |
755 | } | |
756 | ||
757 | /** | |
758 | * Registers compiler function | |
759 | * | |
760 | * @param string $function name of template function | |
761 | * @param string $function_impl name of PHP function to register | |
762 | */ | |
763 | function register_compiler_function($function, $function_impl, $cacheable=true) | |
764 | { | |
765 | $this->_plugins['compiler'][$function] = | |
766 | array($function_impl, null, null, false, $cacheable); | |
767 | } | |
768 | ||
769 | /** | |
770 | * Unregisters compiler function | |
771 | * | |
772 | * @param string $function name of template function | |
773 | */ | |
774 | function unregister_compiler_function($function) | |
775 | { | |
776 | unset($this->_plugins['compiler'][$function]); | |
777 | } | |
778 | ||
779 | /** | |
780 | * Registers modifier to be used in templates | |
781 | * | |
782 | * @param string $modifier name of template modifier | |
783 | * @param string $modifier_impl name of PHP function to register | |
784 | */ | |
785 | function register_modifier($modifier, $modifier_impl) | |
786 | { | |
787 | $this->_plugins['modifier'][$modifier] = | |
788 | array($modifier_impl, null, null, false); | |
789 | } | |
790 | ||
791 | /** | |
792 | * Unregisters modifier | |
793 | * | |
794 | * @param string $modifier name of template modifier | |
795 | */ | |
796 | function unregister_modifier($modifier) | |
797 | { | |
798 | unset($this->_plugins['modifier'][$modifier]); | |
799 | } | |
800 | ||
801 | /** | |
802 | * Registers a resource to fetch a template | |
803 | * | |
804 | * @param string $type name of resource | |
805 | * @param array $functions array of functions to handle resource | |
806 | */ | |
807 | function register_resource($type, $functions) | |
808 | { | |
809 | if (count($functions)==4) { | |
810 | $this->_plugins['resource'][$type] = | |
811 | array($functions, false); | |
812 | ||
813 | } elseif (count($functions)==5) { | |
814 | $this->_plugins['resource'][$type] = | |
815 | array(array(array(&$functions[0], $functions[1]) | |
816 | ,array(&$functions[0], $functions[2]) | |
817 | ,array(&$functions[0], $functions[3]) | |
818 | ,array(&$functions[0], $functions[4])) | |
819 | ,false); | |
820 | ||
821 | } else { | |
822 | $this->trigger_error("malformed function-list for '$type' in register_resource"); | |
823 | ||
824 | } | |
825 | } | |
826 | ||
827 | /** | |
828 | * Unregisters a resource | |
829 | * | |
830 | * @param string $type name of resource | |
831 | */ | |
832 | function unregister_resource($type) | |
833 | { | |
834 | unset($this->_plugins['resource'][$type]); | |
835 | } | |
836 | ||
837 | /** | |
838 | * Registers a prefilter function to apply | |
839 | * to a template before compiling | |
840 | * | |
841 | * @param string $function name of PHP function to register | |
842 | */ | |
843 | function register_prefilter($function) | |
844 | { | |
b42b2bf9 | 845 | $_name = (is_array($function)) ? $function[1] : $function; |
e586807d H |
846 | $this->_plugins['prefilter'][$_name] |
847 | = array($function, null, null, false); | |
848 | } | |
849 | ||
850 | /** | |
851 | * Unregisters a prefilter function | |
852 | * | |
853 | * @param string $function name of PHP function | |
854 | */ | |
855 | function unregister_prefilter($function) | |
856 | { | |
857 | unset($this->_plugins['prefilter'][$function]); | |
858 | } | |
859 | ||
860 | /** | |
861 | * Registers a postfilter function to apply | |
862 | * to a compiled template after compilation | |
863 | * | |
864 | * @param string $function name of PHP function to register | |
865 | */ | |
866 | function register_postfilter($function) | |
867 | { | |
b42b2bf9 | 868 | $_name = (is_array($function)) ? $function[1] : $function; |
e586807d H |
869 | $this->_plugins['postfilter'][$_name] |
870 | = array($function, null, null, false); | |
871 | } | |
872 | ||
873 | /** | |
874 | * Unregisters a postfilter function | |
875 | * | |
876 | * @param string $function name of PHP function | |
877 | */ | |
878 | function unregister_postfilter($function) | |
879 | { | |
880 | unset($this->_plugins['postfilter'][$function]); | |
881 | } | |
882 | ||
883 | /** | |
884 | * Registers an output filter function to apply | |
885 | * to a template output | |
886 | * | |
887 | * @param string $function name of PHP function | |
888 | */ | |
889 | function register_outputfilter($function) | |
890 | { | |
b42b2bf9 | 891 | $_name = (is_array($function)) ? $function[1] : $function; |
e586807d H |
892 | $this->_plugins['outputfilter'][$_name] |
893 | = array($function, null, null, false); | |
894 | } | |
895 | ||
896 | /** | |
897 | * Unregisters an outputfilter function | |
898 | * | |
899 | * @param string $function name of PHP function | |
900 | */ | |
901 | function unregister_outputfilter($function) | |
902 | { | |
903 | unset($this->_plugins['outputfilter'][$function]); | |
904 | } | |
905 | ||
906 | /** | |
907 | * load a filter of specified type and name | |
908 | * | |
909 | * @param string $type filter type | |
910 | * @param string $name filter name | |
911 | */ | |
912 | function load_filter($type, $name) | |
913 | { | |
914 | switch ($type) { | |
915 | case 'output': | |
b42b2bf9 H |
916 | $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false))); |
917 | require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); | |
e586807d H |
918 | smarty_core_load_plugins($_params, $this); |
919 | break; | |
920 | ||
921 | case 'pre': | |
922 | case 'post': | |
923 | if (!isset($this->_plugins[$type . 'filter'][$name])) | |
924 | $this->_plugins[$type . 'filter'][$name] = false; | |
925 | break; | |
926 | } | |
927 | } | |
928 | ||
929 | /** | |
930 | * clear cached content for the given template and cache id | |
931 | * | |
932 | * @param string $tpl_file name of template file | |
933 | * @param string $cache_id name of cache_id | |
934 | * @param string $compile_id name of compile_id | |
935 | * @param string $exp_time expiration time | |
936 | * @return boolean | |
937 | */ | |
938 | function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) | |
939 | { | |
940 | ||
941 | if (!isset($compile_id)) | |
942 | $compile_id = $this->compile_id; | |
943 | ||
b42b2bf9 H |
944 | if (!isset($tpl_file)) |
945 | $compile_id = null; | |
e586807d | 946 | |
b42b2bf9 | 947 | $_auto_id = $this->_get_auto_id($cache_id, $compile_id); |
e586807d H |
948 | |
949 | if (!empty($this->cache_handler_func)) { | |
950 | return call_user_func_array($this->cache_handler_func, | |
b42b2bf9 | 951 | array('clear', &$this, &$dummy, $tpl_file, $cache_id, $compile_id, $exp_time)); |
e586807d | 952 | } else { |
b42b2bf9 H |
953 | $_params = array('auto_base' => $this->cache_dir, |
954 | 'auto_source' => $tpl_file, | |
955 | 'auto_id' => $_auto_id, | |
956 | 'exp_time' => $exp_time); | |
957 | require_once(SMARTY_CORE_DIR . 'core.rm_auto.php'); | |
958 | return smarty_core_rm_auto($_params, $this); | |
e586807d H |
959 | } |
960 | ||
961 | } | |
962 | ||
963 | ||
964 | /** | |
965 | * clear the entire contents of cache (all templates) | |
966 | * | |
967 | * @param string $exp_time expire time | |
968 | * @return boolean results of {@link smarty_core_rm_auto()} | |
969 | */ | |
970 | function clear_all_cache($exp_time = null) | |
971 | { | |
b42b2bf9 | 972 | return $this->clear_cache(null, null, null, $exp_time); |
e586807d H |
973 | } |
974 | ||
975 | ||
976 | /** | |
977 | * test to see if valid cache exists for this template | |
978 | * | |
979 | * @param string $tpl_file name of template file | |
980 | * @param string $cache_id | |
981 | * @param string $compile_id | |
982 | * @return string|false results of {@link _read_cache_file()} | |
983 | */ | |
984 | function is_cached($tpl_file, $cache_id = null, $compile_id = null) | |
985 | { | |
986 | if (!$this->caching) | |
987 | return false; | |
988 | ||
989 | if (!isset($compile_id)) | |
990 | $compile_id = $this->compile_id; | |
991 | ||
b42b2bf9 H |
992 | $_params = array( |
993 | 'tpl_file' => $tpl_file, | |
994 | 'cache_id' => $cache_id, | |
995 | 'compile_id' => $compile_id | |
996 | ); | |
997 | require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php'); | |
e586807d H |
998 | return smarty_core_read_cache_file($_params, $this); |
999 | } | |
1000 | ||
1001 | ||
1002 | /** | |
1003 | * clear all the assigned template variables. | |
1004 | * | |
1005 | */ | |
1006 | function clear_all_assign() | |
1007 | { | |
1008 | $this->_tpl_vars = array(); | |
1009 | } | |
1010 | ||
1011 | /** | |
1012 | * clears compiled version of specified template resource, | |
1013 | * or all compiled template files if one is not specified. | |
1014 | * This function is for advanced use only, not normally needed. | |
1015 | * | |
1016 | * @param string $tpl_file | |
1017 | * @param string $compile_id | |
1018 | * @param string $exp_time | |
1019 | * @return boolean results of {@link smarty_core_rm_auto()} | |
1020 | */ | |
1021 | function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) | |
1022 | { | |
1023 | if (!isset($compile_id)) { | |
b42b2bf9 H |
1024 | $compile_id = $this->compile_id; |
1025 | } | |
1026 | $_params = array('auto_base' => $this->compile_dir, | |
1027 | 'auto_source' => $tpl_file, | |
1028 | 'auto_id' => $compile_id, | |
e586807d H |
1029 | 'exp_time' => $exp_time, |
1030 | 'extensions' => array('.inc', '.php')); | |
b42b2bf9 H |
1031 | require_once(SMARTY_CORE_DIR . 'core.rm_auto.php'); |
1032 | return smarty_core_rm_auto($_params, $this); | |
e586807d H |
1033 | } |
1034 | ||
1035 | /** | |
1036 | * Checks whether requested template exists. | |
1037 | * | |
1038 | * @param string $tpl_file | |
1039 | * @return boolean | |
1040 | */ | |
1041 | function template_exists($tpl_file) | |
1042 | { | |
b42b2bf9 | 1043 | $_params = array('resource_name' => $tpl_file, 'quiet'=>true, 'get_source'=>false); |
e586807d H |
1044 | return $this->_fetch_resource_info($_params); |
1045 | } | |
1046 | ||
1047 | /** | |
1048 | * Returns an array containing template variables | |
1049 | * | |
1050 | * @param string $name | |
1051 | * @param string $type | |
1052 | * @return array | |
1053 | */ | |
1054 | function &get_template_vars($name=null) | |
1055 | { | |
b42b2bf9 H |
1056 | if(!isset($name)) { |
1057 | return $this->_tpl_vars; | |
1058 | } | |
1059 | if(isset($this->_tpl_vars[$name])) { | |
1060 | return $this->_tpl_vars[$name]; | |
1061 | } | |
e586807d H |
1062 | } |
1063 | ||
1064 | /** | |
1065 | * Returns an array containing config variables | |
1066 | * | |
1067 | * @param string $name | |
1068 | * @param string $type | |
1069 | * @return array | |
1070 | */ | |
1071 | function &get_config_vars($name=null) | |
1072 | { | |
b42b2bf9 H |
1073 | if(!isset($name) && is_array($this->_config[0])) { |
1074 | return $this->_config[0]['vars']; | |
1075 | } else if(isset($this->_config[0]['vars'][$name])) { | |
1076 | return $this->_config[0]['vars'][$name]; | |
1077 | } | |
e586807d H |
1078 | } |
1079 | ||
1080 | /** | |
1081 | * trigger Smarty error | |
1082 | * | |
1083 | * @param string $error_msg | |
1084 | * @param integer $error_type | |
1085 | */ | |
1086 | function trigger_error($error_msg, $error_type = E_USER_WARNING) | |
1087 | { | |
1088 | trigger_error("Smarty error: $error_msg", $error_type); | |
1089 | } | |
1090 | ||
1091 | ||
1092 | /** | |
1093 | * executes & displays the template results | |
1094 | * | |
1095 | * @param string $resource_name | |
1096 | * @param string $cache_id | |
1097 | * @param string $compile_id | |
1098 | */ | |
1099 | function display($resource_name, $cache_id = null, $compile_id = null) | |
1100 | { | |
1101 | $this->fetch($resource_name, $cache_id, $compile_id, true); | |
1102 | } | |
1103 | ||
1104 | /** | |
1105 | * executes & returns or displays the template results | |
1106 | * | |
1107 | * @param string $resource_name | |
1108 | * @param string $cache_id | |
1109 | * @param string $compile_id | |
1110 | * @param boolean $display | |
1111 | */ | |
1112 | function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false) | |
1113 | { | |
1114 | static $_cache_info = array(); | |
1115 | ||
b42b2bf9 H |
1116 | $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting) |
1117 | ? $this->error_reporting : error_reporting() & ~E_NOTICE); | |
1118 | ||
1119 | if (!$this->debugging && $this->debugging_ctrl == 'URL') { | |
1120 | $_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']; | |
1121 | if (@strstr($_query_string, $this->_smarty_debug_id)) { | |
1122 | if (@strstr($_query_string, $this->_smarty_debug_id . '=on')) { | |
1123 | // enable debugging for this browser session | |
1124 | @setcookie('SMARTY_DEBUG', true); | |
1125 | $this->debugging = true; | |
1126 | } elseif (@strstr($_query_string, $this->_smarty_debug_id . '=off')) { | |
1127 | // disable debugging for this browser session | |
1128 | @setcookie('SMARTY_DEBUG', false); | |
1129 | $this->debugging = false; | |
1130 | } else { | |
1131 | // enable debugging for this page | |
1132 | $this->debugging = true; | |
1133 | } | |
1134 | } else { | |
1135 | $this->debugging = (bool)($this->request_use_auto_globals ? @$_COOKIE['SMARTY_DEBUG'] : @$GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']); | |
1136 | } | |
e586807d H |
1137 | } |
1138 | ||
1139 | if ($this->debugging) { | |
1140 | // capture time for debugging info | |
b42b2bf9 H |
1141 | $_params = array(); |
1142 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); | |
e586807d H |
1143 | $_debug_start_time = smarty_core_get_microtime($_params, $this); |
1144 | $this->_smarty_debug_info[] = array('type' => 'template', | |
1145 | 'filename' => $resource_name, | |
1146 | 'depth' => 0); | |
1147 | $_included_tpls_idx = count($this->_smarty_debug_info) - 1; | |
1148 | } | |
1149 | ||
1150 | if (!isset($compile_id)) { | |
1151 | $compile_id = $this->compile_id; | |
1152 | } | |
1153 | ||
1154 | $this->_compile_id = $compile_id; | |
1155 | $this->_inclusion_depth = 0; | |
1156 | ||
1157 | if ($this->caching) { | |
1158 | // save old cache_info, initialize cache_info | |
1159 | array_push($_cache_info, $this->_cache_info); | |
1160 | $this->_cache_info = array(); | |
b42b2bf9 H |
1161 | $_params = array( |
1162 | 'tpl_file' => $resource_name, | |
1163 | 'cache_id' => $cache_id, | |
1164 | 'compile_id' => $compile_id, | |
1165 | 'results' => null | |
1166 | ); | |
1167 | require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php'); | |
e586807d | 1168 | if (smarty_core_read_cache_file($_params, $this)) { |
b42b2bf9 H |
1169 | $_smarty_results = $_params['results']; |
1170 | if (!empty($this->_cache_info['insert_tags'])) { | |
1171 | $_params = array('plugins' => $this->_cache_info['insert_tags']); | |
1172 | require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); | |
1173 | smarty_core_load_plugins($_params, $this); | |
1174 | $_params = array('results' => $_smarty_results); | |
1175 | require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php'); | |
e586807d H |
1176 | $_smarty_results = smarty_core_process_cached_inserts($_params, $this); |
1177 | } | |
b42b2bf9 | 1178 | if (!empty($this->_cache_info['cache_serials'])) { |
e586807d | 1179 | $_params = array('results' => $_smarty_results); |
b42b2bf9 | 1180 | require_once(SMARTY_CORE_DIR . 'core.process_compiled_include.php'); |
e586807d H |
1181 | $_smarty_results = smarty_core_process_compiled_include($_params, $this); |
1182 | } | |
1183 | ||
1184 | ||
1185 | if ($display) { | |
1186 | if ($this->debugging) | |
1187 | { | |
1188 | // capture time for debugging info | |
b42b2bf9 H |
1189 | $_params = array(); |
1190 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); | |
e586807d | 1191 | $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time; |
b42b2bf9 | 1192 | require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php'); |
e586807d H |
1193 | $_smarty_results .= smarty_core_display_debug_console($_params, $this); |
1194 | } | |
1195 | if ($this->cache_modified_check) { | |
b42b2bf9 H |
1196 | $_server_vars = ($this->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; |
1197 | $_last_modified_date = @substr($_server_vars['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3); | |
e586807d H |
1198 | $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT'; |
1199 | if (@count($this->_cache_info['insert_tags']) == 0 | |
1200 | && !$this->_cache_serials | |
1201 | && $_gmt_mtime == $_last_modified_date) { | |
1202 | if (php_sapi_name()=='cgi') | |
b42b2bf9 | 1203 | header('Status: 304 Not Modified'); |
e586807d | 1204 | else |
b42b2bf9 | 1205 | header('HTTP/1.1 304 Not Modified'); |
e586807d H |
1206 | |
1207 | } else { | |
b42b2bf9 | 1208 | header('Last-Modified: '.$_gmt_mtime); |
e586807d H |
1209 | echo $_smarty_results; |
1210 | } | |
1211 | } else { | |
1212 | echo $_smarty_results; | |
1213 | } | |
1214 | error_reporting($_smarty_old_error_level); | |
1215 | // restore initial cache_info | |
1216 | $this->_cache_info = array_pop($_cache_info); | |
1217 | return true; | |
1218 | } else { | |
1219 | error_reporting($_smarty_old_error_level); | |
1220 | // restore initial cache_info | |
1221 | $this->_cache_info = array_pop($_cache_info); | |
1222 | return $_smarty_results; | |
1223 | } | |
1224 | } else { | |
1225 | $this->_cache_info['template'][$resource_name] = true; | |
b42b2bf9 H |
1226 | if ($this->cache_modified_check && $display) { |
1227 | header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); | |
e586807d H |
1228 | } |
1229 | } | |
1230 | } | |
1231 | ||
b42b2bf9 | 1232 | // load filters that are marked as autoload |
e586807d | 1233 | if (count($this->autoload_filters)) { |
b42b2bf9 H |
1234 | foreach ($this->autoload_filters as $_filter_type => $_filters) { |
1235 | foreach ($_filters as $_filter) { | |
1236 | $this->load_filter($_filter_type, $_filter); | |
1237 | } | |
1238 | } | |
e586807d H |
1239 | } |
1240 | ||
1241 | $_smarty_compile_path = $this->_get_compile_path($resource_name); | |
1242 | ||
1243 | // if we just need to display the results, don't perform output | |
1244 | // buffering - for speed | |
1245 | $_cache_including = $this->_cache_including; | |
1246 | $this->_cache_including = false; | |
1247 | if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) { | |
1248 | if ($this->_is_compiled($resource_name, $_smarty_compile_path) | |
b42b2bf9 | 1249 | || $this->_compile_resource($resource_name, $_smarty_compile_path)) |
e586807d H |
1250 | { |
1251 | include($_smarty_compile_path); | |
1252 | } | |
1253 | } else { | |
e586807d H |
1254 | ob_start(); |
1255 | if ($this->_is_compiled($resource_name, $_smarty_compile_path) | |
b42b2bf9 | 1256 | || $this->_compile_resource($resource_name, $_smarty_compile_path)) |
e586807d H |
1257 | { |
1258 | include($_smarty_compile_path); | |
1259 | } | |
1260 | $_smarty_results = ob_get_contents(); | |
1261 | ob_end_clean(); | |
1262 | ||
1263 | foreach ((array)$this->_plugins['outputfilter'] as $_output_filter) { | |
1264 | $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this)); | |
1265 | } | |
1266 | } | |
1267 | ||
1268 | if ($this->caching) { | |
b42b2bf9 H |
1269 | $_params = array('tpl_file' => $resource_name, |
1270 | 'cache_id' => $cache_id, | |
1271 | 'compile_id' => $compile_id, | |
1272 | 'results' => $_smarty_results); | |
1273 | require_once(SMARTY_CORE_DIR . 'core.write_cache_file.php'); | |
1274 | smarty_core_write_cache_file($_params, $this); | |
1275 | require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php'); | |
1276 | $_smarty_results = smarty_core_process_cached_inserts($_params, $this); | |
e586807d H |
1277 | |
1278 | if ($this->_cache_serials) { | |
1279 | // strip nocache-tags from output | |
1280 | $_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s' | |
1281 | ,'' | |
1282 | ,$_smarty_results); | |
1283 | } | |
1284 | // restore initial cache_info | |
1285 | $this->_cache_info = array_pop($_cache_info); | |
1286 | } | |
1287 | $this->_cache_including = $_cache_including; | |
1288 | ||
1289 | if ($display) { | |
e586807d | 1290 | if (isset($_smarty_results)) { echo $_smarty_results; } |
e586807d H |
1291 | if ($this->debugging) { |
1292 | // capture time for debugging info | |
b42b2bf9 H |
1293 | $_params = array(); |
1294 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); | |
e586807d | 1295 | $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time); |
b42b2bf9 | 1296 | require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php'); |
e586807d H |
1297 | echo smarty_core_display_debug_console($_params, $this); |
1298 | } | |
1299 | error_reporting($_smarty_old_error_level); | |
e586807d H |
1300 | return; |
1301 | } else { | |
1302 | error_reporting($_smarty_old_error_level); | |
1303 | if (isset($_smarty_results)) { return $_smarty_results; } | |
1304 | } | |
1305 | } | |
1306 | ||
1307 | /** | |
1308 | * load configuration values | |
1309 | * | |
1310 | * @param string $file | |
1311 | * @param string $section | |
1312 | * @param string $scope | |
1313 | */ | |
1314 | function config_load($file, $section = null, $scope = 'global') | |
1315 | { | |
b42b2bf9 H |
1316 | require_once($this->_get_plugin_filepath('function', 'config_load')); |
1317 | smarty_function_config_load(array('file' => $file, 'section' => $section, 'scope' => $scope), $this); | |
e586807d H |
1318 | } |
1319 | ||
1320 | /** | |
1321 | * return a reference to a registered object | |
1322 | * | |
1323 | * @param string $name | |
1324 | * @return object | |
1325 | */ | |
b42b2bf9 H |
1326 | function &get_registered_object($name) { |
1327 | if (!isset($this->_reg_objects[$name])) | |
1328 | $this->_trigger_fatal_error("'$name' is not a registered object"); | |
e586807d | 1329 | |
b42b2bf9 H |
1330 | if (!is_object($this->_reg_objects[$name][0])) |
1331 | $this->_trigger_fatal_error("registered '$name' is not an object"); | |
e586807d | 1332 | |
b42b2bf9 H |
1333 | return $this->_reg_objects[$name][0]; |
1334 | } | |
e586807d H |
1335 | |
1336 | /** | |
1337 | * clear configuration values | |
1338 | * | |
1339 | * @param string $var | |
1340 | */ | |
1341 | function clear_config($var = null) | |
1342 | { | |
1343 | if(!isset($var)) { | |
1344 | // clear all values | |
1345 | $this->_config = array(array('vars' => array(), | |
1346 | 'files' => array())); | |
1347 | } else { | |
1348 | unset($this->_config[0]['vars'][$var]); | |
1349 | } | |
1350 | } | |
1351 | ||
e586807d H |
1352 | /** |
1353 | * get filepath of requested plugin | |
1354 | * | |
1355 | * @param string $type | |
1356 | * @param string $name | |
1357 | * @return string|false | |
1358 | */ | |
1359 | function _get_plugin_filepath($type, $name) | |
1360 | { | |
b42b2bf9 H |
1361 | $_params = array('type' => $type, 'name' => $name); |
1362 | require_once(SMARTY_CORE_DIR . 'core.assemble_plugin_filepath.php'); | |
1363 | return smarty_core_assemble_plugin_filepath($_params, $this); | |
e586807d H |
1364 | } |
1365 | ||
1366 | /** | |
1367 | * test if resource needs compiling | |
1368 | * | |
1369 | * @param string $resource_name | |
1370 | * @param string $compile_path | |
1371 | * @return boolean | |
1372 | */ | |
1373 | function _is_compiled($resource_name, $compile_path) | |
1374 | { | |
1375 | if (!$this->force_compile && file_exists($compile_path)) { | |
1376 | if (!$this->compile_check) { | |
1377 | // no need to check compiled file | |
1378 | return true; | |
1379 | } else { | |
1380 | // get file source and timestamp | |
b42b2bf9 H |
1381 | $_params = array('resource_name' => $resource_name, 'get_source'=>false); |
1382 | if (!$this->_fetch_resource_info($_params)) { | |
e586807d H |
1383 | return false; |
1384 | } | |
1385 | if ($_params['resource_timestamp'] <= filemtime($compile_path)) { | |
1386 | // template not expired, no recompile | |
1387 | return true; | |
1388 | } else { | |
b42b2bf9 | 1389 | // compile template |
e586807d H |
1390 | return false; |
1391 | } | |
1392 | } | |
1393 | } else { | |
1394 | // compiled template does not exist, or forced compile | |
1395 | return false; | |
1396 | } | |
1397 | } | |
1398 | ||
1399 | /** | |
1400 | * compile the template | |
1401 | * | |
1402 | * @param string $resource_name | |
1403 | * @param string $compile_path | |
1404 | * @return boolean | |
1405 | */ | |
1406 | function _compile_resource($resource_name, $compile_path) | |
1407 | { | |
1408 | ||
b42b2bf9 | 1409 | $_params = array('resource_name' => $resource_name); |
e586807d H |
1410 | if (!$this->_fetch_resource_info($_params)) { |
1411 | return false; | |
1412 | } | |
1413 | ||
b42b2bf9 | 1414 | $_source_content = $_params['source_content']; |
e586807d H |
1415 | $_cache_include = substr($compile_path, 0, -4).'.inc'; |
1416 | ||
1417 | if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) { | |
1418 | // if a _cache_serial was set, we also have to write an include-file: | |
1419 | if ($this->_cache_include_info) { | |
b42b2bf9 H |
1420 | require_once(SMARTY_CORE_DIR . 'core.write_compiled_include.php'); |
1421 | smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content, 'resource_name'=>$resource_name)), $this); | |
e586807d H |
1422 | } |
1423 | ||
b42b2bf9 H |
1424 | $_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content); |
1425 | require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php'); | |
1426 | smarty_core_write_compiled_resource($_params, $this); | |
e586807d H |
1427 | |
1428 | return true; | |
1429 | } else { | |
e586807d H |
1430 | return false; |
1431 | } | |
1432 | ||
1433 | } | |
1434 | ||
1435 | /** | |
1436 | * compile the given source | |
1437 | * | |
1438 | * @param string $resource_name | |
1439 | * @param string $source_content | |
1440 | * @param string $compiled_content | |
1441 | * @return boolean | |
1442 | */ | |
1443 | function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null) | |
1444 | { | |
1445 | if (file_exists(SMARTY_DIR . $this->compiler_file)) { | |
1446 | require_once(SMARTY_DIR . $this->compiler_file); | |
1447 | } else { | |
1448 | // use include_path | |
1449 | require_once($this->compiler_file); | |
1450 | } | |
1451 | ||
1452 | ||
1453 | $smarty_compiler = new $this->compiler_class; | |
1454 | ||
1455 | $smarty_compiler->template_dir = $this->template_dir; | |
1456 | $smarty_compiler->compile_dir = $this->compile_dir; | |
1457 | $smarty_compiler->plugins_dir = $this->plugins_dir; | |
1458 | $smarty_compiler->config_dir = $this->config_dir; | |
1459 | $smarty_compiler->force_compile = $this->force_compile; | |
1460 | $smarty_compiler->caching = $this->caching; | |
1461 | $smarty_compiler->php_handling = $this->php_handling; | |
1462 | $smarty_compiler->left_delimiter = $this->left_delimiter; | |
1463 | $smarty_compiler->right_delimiter = $this->right_delimiter; | |
1464 | $smarty_compiler->_version = $this->_version; | |
1465 | $smarty_compiler->security = $this->security; | |
1466 | $smarty_compiler->secure_dir = $this->secure_dir; | |
1467 | $smarty_compiler->security_settings = $this->security_settings; | |
1468 | $smarty_compiler->trusted_dir = $this->trusted_dir; | |
b42b2bf9 | 1469 | $smarty_compiler->use_sub_dirs = $this->use_sub_dirs; |
e586807d H |
1470 | $smarty_compiler->_reg_objects = &$this->_reg_objects; |
1471 | $smarty_compiler->_plugins = &$this->_plugins; | |
1472 | $smarty_compiler->_tpl_vars = &$this->_tpl_vars; | |
1473 | $smarty_compiler->default_modifiers = $this->default_modifiers; | |
1474 | $smarty_compiler->compile_id = $this->_compile_id; | |
b42b2bf9 | 1475 | $smarty_compiler->_config = $this->_config; |
e586807d H |
1476 | $smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals; |
1477 | ||
b42b2bf9 H |
1478 | if (isset($cache_include_path) && isset($this->_cache_serials[$cache_include_path])) { |
1479 | $smarty_compiler->_cache_serial = $this->_cache_serials[$cache_include_path]; | |
1480 | } | |
e586807d H |
1481 | $smarty_compiler->_cache_include = $cache_include_path; |
1482 | ||
1483 | ||
b42b2bf9 | 1484 | $_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content); |
e586807d H |
1485 | |
1486 | if ($smarty_compiler->_cache_serial) { | |
1487 | $this->_cache_include_info = array( | |
1488 | 'cache_serial'=>$smarty_compiler->_cache_serial | |
1489 | ,'plugins_code'=>$smarty_compiler->_plugins_code | |
1490 | ,'include_file_path' => $cache_include_path); | |
1491 | ||
1492 | } else { | |
1493 | $this->_cache_include_info = null; | |
1494 | ||
1495 | } | |
1496 | ||
b42b2bf9 H |
1497 | return $_results; |
1498 | } | |
e586807d H |
1499 | |
1500 | /** | |
1501 | * Get the compile path for this resource | |
1502 | * | |
1503 | * @param string $resource_name | |
1504 | * @return string results of {@link _get_auto_filename()} | |
1505 | */ | |
1506 | function _get_compile_path($resource_name) | |
1507 | { | |
1508 | return $this->_get_auto_filename($this->compile_dir, $resource_name, | |
1509 | $this->_compile_id) . '.php'; | |
1510 | } | |
1511 | ||
1512 | /** | |
1513 | * fetch the template info. Gets timestamp, and source | |
1514 | * if get_source is true | |
1515 | * | |
1516 | * sets $source_content to the source of the template, and | |
1517 | * $resource_timestamp to its time stamp | |
1518 | * @param string $resource_name | |
1519 | * @param string $source_content | |
1520 | * @param integer $resource_timestamp | |
1521 | * @param boolean $get_source | |
1522 | * @param boolean $quiet | |
1523 | * @return boolean | |
1524 | */ | |
1525 | ||
1526 | function _fetch_resource_info(&$params) | |
1527 | { | |
1528 | if(!isset($params['get_source'])) { $params['get_source'] = true; } | |
1529 | if(!isset($params['quiet'])) { $params['quiet'] = false; } | |
1530 | ||
1531 | $_return = false; | |
1532 | $_params = array('resource_name' => $params['resource_name']) ; | |
1533 | if (isset($params['resource_base_path'])) | |
1534 | $_params['resource_base_path'] = $params['resource_base_path']; | |
b42b2bf9 H |
1535 | else |
1536 | $_params['resource_base_path'] = $this->template_dir; | |
e586807d H |
1537 | |
1538 | if ($this->_parse_resource_name($_params)) { | |
1539 | $_resource_type = $_params['resource_type']; | |
1540 | $_resource_name = $_params['resource_name']; | |
1541 | switch ($_resource_type) { | |
1542 | case 'file': | |
1543 | if ($params['get_source']) { | |
1544 | $params['source_content'] = $this->_read_file($_resource_name); | |
1545 | } | |
1546 | $params['resource_timestamp'] = filemtime($_resource_name); | |
1547 | $_return = is_file($_resource_name); | |
1548 | break; | |
1549 | ||
1550 | default: | |
1551 | // call resource functions to fetch the template source and timestamp | |
1552 | if ($params['get_source']) { | |
1553 | $_source_return = isset($this->_plugins['resource'][$_resource_type]) && | |
1554 | call_user_func_array($this->_plugins['resource'][$_resource_type][0][0], | |
1555 | array($_resource_name, &$params['source_content'], &$this)); | |
1556 | } else { | |
1557 | $_source_return = true; | |
1558 | } | |
1559 | ||
1560 | $_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) && | |
1561 | call_user_func_array($this->_plugins['resource'][$_resource_type][0][1], | |
1562 | array($_resource_name, &$params['resource_timestamp'], &$this)); | |
1563 | ||
1564 | $_return = $_source_return && $_timestamp_return; | |
1565 | break; | |
1566 | } | |
1567 | } | |
1568 | ||
1569 | if (!$_return) { | |
1570 | // see if we can get a template with the default template handler | |
1571 | if (!empty($this->default_template_handler_func)) { | |
1572 | if (!is_callable($this->default_template_handler_func)) { | |
1573 | $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist."); | |
1574 | } else { | |
1575 | $_return = call_user_func_array( | |
1576 | $this->default_template_handler_func, | |
b42b2bf9 | 1577 | array($_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this)); |
e586807d H |
1578 | } |
1579 | } | |
1580 | } | |
1581 | ||
1582 | if (!$_return) { | |
1583 | if (!$params['quiet']) { | |
1584 | $this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"'); | |
1585 | } | |
1586 | } else if ($_return && $this->security) { | |
b42b2bf9 | 1587 | require_once(SMARTY_CORE_DIR . 'core.is_secure.php'); |
e586807d H |
1588 | if (!smarty_core_is_secure($_params, $this)) { |
1589 | if (!$params['quiet']) | |
1590 | $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed'); | |
1591 | $params['source_content'] = null; | |
1592 | $params['resource_timestamp'] = null; | |
1593 | return false; | |
1594 | } | |
1595 | } | |
1596 | return $_return; | |
1597 | } | |
1598 | ||
1599 | ||
1600 | /** | |
1601 | * parse out the type and name from the resource | |
1602 | * | |
1603 | * @param string $resource_base_path | |
1604 | * @param string $resource_name | |
1605 | * @param string $resource_type | |
1606 | * @param string $resource_name | |
1607 | * @return boolean | |
1608 | */ | |
1609 | ||
1610 | function _parse_resource_name(&$params) | |
1611 | { | |
1612 | ||
1613 | // split tpl_path by the first colon | |
1614 | $_resource_name_parts = explode(':', $params['resource_name'], 2); | |
1615 | ||
1616 | if (count($_resource_name_parts) == 1) { | |
1617 | // no resource type given | |
1618 | $params['resource_type'] = $this->default_resource_type; | |
1619 | $params['resource_name'] = $_resource_name_parts[0]; | |
1620 | } else { | |
1621 | if(strlen($_resource_name_parts[0]) == 1) { | |
1622 | // 1 char is not resource type, but part of filepath | |
1623 | $params['resource_type'] = $this->default_resource_type; | |
1624 | $params['resource_name'] = $params['resource_name']; | |
1625 | } else { | |
1626 | $params['resource_type'] = $_resource_name_parts[0]; | |
1627 | $params['resource_name'] = $_resource_name_parts[1]; | |
1628 | } | |
1629 | } | |
1630 | ||
1631 | if ($params['resource_type'] == 'file') { | |
b42b2bf9 | 1632 | if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $params['resource_name'])) { |
e586807d H |
1633 | // relative pathname to $params['resource_base_path'] |
1634 | // use the first directory where the file is found | |
b42b2bf9 | 1635 | foreach ((array)$params['resource_base_path'] as $_curr_path) { |
e586807d H |
1636 | $_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name']; |
1637 | if (file_exists($_fullpath) && is_file($_fullpath)) { | |
1638 | $params['resource_name'] = $_fullpath; | |
1639 | return true; | |
1640 | } | |
1641 | // didn't find the file, try include_path | |
1642 | $_params = array('file_path' => $_fullpath); | |
b42b2bf9 | 1643 | require_once(SMARTY_CORE_DIR . 'core.get_include_path.php'); |
e586807d H |
1644 | if(smarty_core_get_include_path($_params, $this)) { |
1645 | $params['resource_name'] = $_params['new_file_path']; | |
1646 | return true; | |
1647 | } | |
1648 | } | |
1649 | return false; | |
b42b2bf9 H |
1650 | } else { |
1651 | /* absolute path */ | |
1652 | return file_exists($params['resource_name']); | |
e586807d | 1653 | } |
b42b2bf9 | 1654 | } elseif (empty($this->_plugins['resource'][$params['resource_type']])) { |
e586807d | 1655 | $_params = array('type' => $params['resource_type']); |
b42b2bf9 | 1656 | require_once(SMARTY_CORE_DIR . 'core.load_resource_plugin.php'); |
e586807d H |
1657 | smarty_core_load_resource_plugin($_params, $this); |
1658 | } | |
1659 | ||
1660 | return true; | |
1661 | } | |
1662 | ||
1663 | ||
1664 | /** | |
1665 | * Handle modifiers | |
1666 | * | |
1667 | * @param string|null $modifier_name | |
1668 | * @param array|null $map_array | |
1669 | * @return string result of modifiers | |
1670 | */ | |
1671 | function _run_mod_handler() | |
1672 | { | |
1673 | $_args = func_get_args(); | |
1674 | list($_modifier_name, $_map_array) = array_splice($_args, 0, 2); | |
1675 | list($_func_name, $_tpl_file, $_tpl_line) = | |
1676 | $this->_plugins['modifier'][$_modifier_name]; | |
1677 | ||
1678 | $_var = $_args[0]; | |
1679 | foreach ($_var as $_key => $_val) { | |
1680 | $_args[0] = $_val; | |
1681 | $_var[$_key] = call_user_func_array($_func_name, $_args); | |
1682 | } | |
1683 | return $_var; | |
1684 | } | |
1685 | ||
1686 | /** | |
1687 | * Remove starting and ending quotes from the string | |
1688 | * | |
1689 | * @param string $string | |
1690 | * @return string | |
1691 | */ | |
1692 | function _dequote($string) | |
1693 | { | |
1694 | if (($string{0} == "'" || $string{0} == '"') && | |
1695 | $string{strlen($string)-1} == $string{0}) | |
1696 | return substr($string, 1, -1); | |
1697 | else | |
1698 | return $string; | |
1699 | } | |
1700 | ||
1701 | ||
1702 | /** | |
b42b2bf9 | 1703 | * read in a file |
e586807d H |
1704 | * |
1705 | * @param string $filename | |
e586807d H |
1706 | * @return string |
1707 | */ | |
b42b2bf9 | 1708 | function _read_file($filename) |
e586807d | 1709 | { |
b42b2bf9 H |
1710 | if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) { |
1711 | $contents = ($size = filesize($filename)) ? fread($fd, $size) : ''; | |
1712 | fclose($fd); | |
1713 | return $contents; | |
e586807d | 1714 | } else { |
b42b2bf9 | 1715 | return false; |
e586807d | 1716 | } |
e586807d H |
1717 | } |
1718 | ||
1719 | /** | |
1720 | * get a concrete filename for automagically created content | |
1721 | * | |
1722 | * @param string $auto_base | |
1723 | * @param string $auto_source | |
1724 | * @param string $auto_id | |
1725 | * @return string | |
1726 | * @staticvar string|null | |
1727 | * @staticvar string|null | |
1728 | */ | |
1729 | function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null) | |
1730 | { | |
1731 | $_compile_dir_sep = $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; | |
b42b2bf9 | 1732 | $_return = $auto_base . DIRECTORY_SEPARATOR; |
e586807d H |
1733 | |
1734 | if(isset($auto_id)) { | |
1735 | // make auto_id safe for directory names | |
1736 | $auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id))); | |
1737 | // split into separate directories | |
1738 | $_return .= $auto_id . $_compile_dir_sep; | |
1739 | } | |
1740 | ||
1741 | if(isset($auto_source)) { | |
1742 | // make source name safe for filename | |
1743 | $_filename = urlencode(basename($auto_source)); | |
b42b2bf9 | 1744 | $_crc32 = sprintf('%08X', crc32($auto_source)); |
e586807d H |
1745 | // prepend %% to avoid name conflicts with |
1746 | // with $params['auto_id'] names | |
b42b2bf9 H |
1747 | $_crc32 = substr($_crc32, 0, 2) . $_compile_dir_sep . |
1748 | substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32; | |
1749 | $_return .= '%%' . $_crc32 . '%%' . $_filename; | |
e586807d H |
1750 | } |
1751 | ||
1752 | return $_return; | |
1753 | } | |
1754 | ||
1755 | /** | |
1756 | * unlink a file, possibly using expiration time | |
1757 | * | |
1758 | * @param string $resource | |
1759 | * @param integer $exp_time | |
1760 | */ | |
1761 | function _unlink($resource, $exp_time = null) | |
1762 | { | |
1763 | if(isset($exp_time)) { | |
1764 | if(time() - @filemtime($resource) >= $exp_time) { | |
1765 | return @unlink($resource); | |
1766 | } | |
1767 | } else { | |
1768 | return @unlink($resource); | |
1769 | } | |
1770 | } | |
1771 | ||
1772 | /** | |
1773 | * returns an auto_id for auto-file-functions | |
1774 | * | |
1775 | * @param string $cache_id | |
1776 | * @param string $compile_id | |
1777 | * @return string|null | |
1778 | */ | |
1779 | function _get_auto_id($cache_id=null, $compile_id=null) { | |
b42b2bf9 H |
1780 | if (isset($cache_id)) |
1781 | return (isset($compile_id)) ? $cache_id . '|' . $compile_id : $cache_id; | |
1782 | elseif(isset($compile_id)) | |
1783 | return $compile_id; | |
1784 | else | |
1785 | return null; | |
e586807d H |
1786 | } |
1787 | ||
1788 | /** | |
1789 | * trigger Smarty plugin error | |
1790 | * | |
1791 | * @param string $error_msg | |
1792 | * @param string $tpl_file | |
1793 | * @param integer $tpl_line | |
1794 | * @param string $file | |
1795 | * @param integer $line | |
1796 | * @param integer $error_type | |
1797 | */ | |
1798 | function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null, | |
1799 | $file = null, $line = null, $error_type = E_USER_ERROR) | |
1800 | { | |
1801 | if(isset($file) && isset($line)) { | |
1802 | $info = ' ('.basename($file).", line $line)"; | |
1803 | } else { | |
b42b2bf9 | 1804 | $info = ''; |
e586807d H |
1805 | } |
1806 | if (isset($tpl_line) && isset($tpl_file)) { | |
b42b2bf9 | 1807 | $this->trigger_error('[in ' . $tpl_file . ' line ' . $tpl_line . "]: $error_msg$info", $error_type); |
e586807d | 1808 | } else { |
b42b2bf9 | 1809 | $this->trigger_error($error_msg . $info, $error_type); |
e586807d H |
1810 | } |
1811 | } | |
1812 | ||
1813 | ||
1814 | /** | |
1815 | * callback function for preg_replace, to call a non-cacheable block | |
1816 | * @return string | |
1817 | */ | |
1818 | function _process_compiled_include_callback($match) { | |
1819 | $_func = '_smarty_tplfunc_'.$match[2].'_'.$match[3]; | |
1820 | ob_start(); | |
1821 | $_func($this); | |
1822 | $_ret = ob_get_contents(); | |
1823 | ob_end_clean(); | |
1824 | return $_ret; | |
1825 | } | |
1826 | ||
1827 | ||
1828 | /** | |
1829 | * called for included templates | |
1830 | * | |
1831 | * @param string $_smarty_include_tpl_file | |
1832 | * @param string $_smarty_include_vars | |
1833 | */ | |
1834 | ||
1835 | // $_smarty_include_tpl_file, $_smarty_include_vars | |
1836 | ||
1837 | function _smarty_include($params) | |
1838 | { | |
1839 | if ($this->debugging) { | |
1840 | $_params = array(); | |
b42b2bf9 | 1841 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); |
e586807d H |
1842 | $debug_start_time = smarty_core_get_microtime($_params, $this); |
1843 | $this->_smarty_debug_info[] = array('type' => 'template', | |
1844 | 'filename' => $params['smarty_include_tpl_file'], | |
1845 | 'depth' => ++$this->_inclusion_depth); | |
1846 | $included_tpls_idx = count($this->_smarty_debug_info) - 1; | |
1847 | } | |
1848 | ||
1849 | $this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']); | |
1850 | ||
1851 | // config vars are treated as local, so push a copy of the | |
1852 | // current ones onto the front of the stack | |
1853 | array_unshift($this->_config, $this->_config[0]); | |
1854 | ||
1855 | $_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']); | |
1856 | ||
1857 | ||
1858 | if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path) | |
1859 | || $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path)) | |
1860 | { | |
1861 | include($_smarty_compile_path); | |
1862 | } | |
1863 | ||
1864 | // pop the local vars off the front of the stack | |
1865 | array_shift($this->_config); | |
1866 | ||
1867 | $this->_inclusion_depth--; | |
1868 | ||
1869 | if ($this->debugging) { | |
1870 | // capture time for debugging info | |
1871 | $_params = array(); | |
b42b2bf9 | 1872 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); |
e586807d H |
1873 | $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time; |
1874 | } | |
1875 | ||
1876 | if ($this->caching) { | |
1877 | $this->_cache_info['template'][$params['smarty_include_tpl_file']] = true; | |
1878 | } | |
1879 | } | |
1880 | ||
1881 | ||
1882 | /** | |
1883 | * get or set an array of cached attributes for function that is | |
1884 | * not cacheable | |
1885 | * @return array | |
1886 | */ | |
1887 | function &_smarty_cache_attrs($cache_serial, $count) { | |
1888 | $_cache_attrs =& $this->_cache_info['cache_attrs'][$cache_serial][$count]; | |
1889 | ||
1890 | if ($this->_cache_including) { | |
1891 | /* return next set of cache_attrs */ | |
b42b2bf9 | 1892 | $_return = current($_cache_attrs); |
e586807d H |
1893 | next($_cache_attrs); |
1894 | return $_return; | |
1895 | ||
1896 | } else { | |
1897 | /* add a reference to a new set of cache_attrs */ | |
1898 | $_cache_attrs[] = array(); | |
1899 | return $_cache_attrs[count($_cache_attrs)-1]; | |
1900 | ||
1901 | } | |
1902 | ||
1903 | } | |
1904 | ||
1905 | ||
1906 | /** | |
1907 | * wrapper for include() retaining $this | |
1908 | * @return mixed | |
1909 | */ | |
b42b2bf9 | 1910 | function _include($filename, $once=false, $params=null) |
e586807d | 1911 | { |
e586807d H |
1912 | if ($once) { |
1913 | return include_once($filename); | |
1914 | } else { | |
1915 | return include($filename); | |
1916 | } | |
1917 | } | |
1918 | ||
1919 | ||
1920 | /** | |
1921 | * wrapper for eval() retaining $this | |
1922 | * @return mixed | |
1923 | */ | |
b42b2bf9 | 1924 | function _eval($code, $params=null) |
e586807d | 1925 | { |
e586807d H |
1926 | return eval($code); |
1927 | } | |
1928 | /**#@-*/ | |
1929 | ||
1930 | } | |
1931 | ||
1932 | /* vim: set expandtab: */ | |
1933 | ||
1934 | ?> |