3 * Project: Smarty: the PHP compiling template engine
4 * File: Smarty.class.php
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * For questions, help, comments, discussion, etc., please join the
21 * Smarty mailing list. Send a blank e-mail to
22 * smarty-general-subscribe@lists.php.net
24 * You may contact the authors of Smarty by e-mail at:
30 * Director of Technology, ispi
31 * 237 S. 70th suite 220
34 * The latest version of Smarty can be obtained from:
35 * http://smarty.php.net/
37 * @link http://smarty.php.net/
38 * @copyright 2001-2003 ispi of Lincoln, Inc.
39 * @author Monte Ohrt <monte@ispi.net>
40 * @author Andrei Zmievski <andrei@php.net>
45 /* $Id: Smarty.class.php,v 1.450 2003/10/08 23:43:34 mohrt Exp $ */
48 * DIR_SEP isn't used anymore, but third party apps might
50 if(!defined('DIR_SEP')) {
51 define('DIR_SEP', DIRECTORY_SEPARATOR
);
55 * set SMARTY_DIR to absolute path to Smarty library files.
56 * if not defined, include_path will be used. Sets SMARTY_DIR only if user
57 * application has not already defined it.
60 if (!defined('SMARTY_DIR')) {
61 define('SMARTY_DIR', dirname(__FILE__
) . DIRECTORY_SEPARATOR
);
64 define('SMARTY_PHP_PASSTHRU', 0);
65 define('SMARTY_PHP_QUOTE', 1);
66 define('SMARTY_PHP_REMOVE', 2);
67 define('SMARTY_PHP_ALLOW', 3);
75 * Smarty Configuration Section
79 * The name of the directory where templates are located.
83 var $template_dir = 'templates';
86 * The directory where compiled templates are located.
90 var $compile_dir = 'templates_c';
93 * The directory where config files are located.
97 var $config_dir = 'configs';
100 * An array of directories searched for plugins.
104 var $plugins_dir = array('plugins');
107 * If debugging is enabled, a debug console window will display
108 * when the page loads (make sure your browser allows unrequested
113 var $debugging = false;
116 * This is the path to the debug console template. If not set,
117 * the default one will be used.
124 * This determines if debugging is enable-able from the browser.
126 * <li>NONE => no debugging control allowed</li>
127 * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li>
129 * @link http://www.foo.dom/index.php?SMARTY_DEBUG
132 var $debugging_ctrl = 'NONE';
135 * This tells Smarty whether to check for recompiling or not. Recompiling
136 * does not need to happen unless a template or config file is changed.
137 * Typically you enable this during development, and disable for
142 var $compile_check = true;
145 * This forces templates to compile every time. Useful for development
150 var $force_compile = false;
153 * This enables template caching.
155 * <li>0 = no caching</li>
156 * <li>1 = use class cache_lifetime value</li>
157 * <li>2 = use cache_lifetime in cache file</li>
164 * The name of the directory for cache files.
168 var $cache_dir = 'cache';
171 * This is the number of seconds cached content will persist.
173 * <li>0 = always regenerate cache</li>
174 * <li>-1 = never expires</li>
179 var $cache_lifetime = 3600;
182 * Only used when $caching is enabled. If true, then If-Modified-Since headers
183 * are respected with cached content, and appropriate HTTP headers are sent.
184 * This way repeated hits to a cached page do not send the entire page to the
189 var $cache_modified_check = false;
192 * This determines how Smarty handles "<?php ... ?>" tags in templates.
195 * <li>SMARTY_PHP_PASSTHRU -> print tags as plain text</li>
196 * <li>SMARTY_PHP_QUOTE -> escape tags as entities</li>
197 * <li>SMARTY_PHP_REMOVE -> remove php tags</li>
198 * <li>SMARTY_PHP_ALLOW -> execute php tags</li>
203 var $php_handling = SMARTY_PHP_PASSTHRU
;
206 * This enables template security. When enabled, many things are restricted
207 * in the templates that normally would go unchecked. This is useful when
208 * untrusted parties are editing templates and you want a reasonable level
209 * of security. (no direct execution of PHP in templates for example)
213 var $security = false;
216 * This is the list of template directories that are considered secure. This
217 * is used only if {@link $security} is enabled. One directory per array
218 * element. {@link $template_dir} is in this list implicitly.
222 var $secure_dir = array();
225 * These are the security settings for Smarty. They are used only when
226 * {@link $security} is enabled.
230 var $security_settings = array(
231 'PHP_HANDLING' => false,
232 'IF_FUNCS' => array('array', 'list',
235 'in_array', 'is_array',
237 'INCLUDE_ANY' => false,
239 'MODIFIER_FUNCS' => array('count'),
240 'ALLOW_CONSTANTS' => false
244 * This is an array of directories where trusted php scripts reside.
245 * {@link $security} is disabled during their inclusion/execution.
249 var $trusted_dir = array();
252 * The left delimiter used for the template tags.
256 var $left_delimiter = '{';
259 * The right delimiter used for the template tags.
263 var $right_delimiter = '}';
266 * The order in which request variables are registered, similar to
267 * variables_order in php.ini E = Environment, G = GET, P = POST,
268 * C = Cookies, S = Server
272 var $request_vars_order = "EGPCS";
275 * Indicates wether $HTTP_*_VARS[] (request_use_auto_globals=false)
276 * are uses as request-vars or $_*[]-vars. note: if
277 * request_use_auto_globals is true, then $request_vars_order has
278 * no effect, but the php-ini-value "gpc_order"
282 var $request_use_auto_globals = false;
285 * Set this if you want different sets of compiled files for the same
286 * templates. This is useful for things like different languages.
287 * Instead of creating separate sets of templates per language, you
288 * set different compile_ids like 'en' and 'de'.
292 var $compile_id = null;
295 * This tells Smarty whether or not to use sub dirs in the cache/ and
296 * templates_c/ directories. sub directories better organized, but
297 * may not work well with PHP safe mode enabled.
302 var $use_sub_dirs = true;
305 * This is a list of the modifiers to apply to all template variables.
306 * Put each modifier in a separate array element in the order you want
307 * them applied. example: <code>array('escape:"htmlall"');</code>
311 var $default_modifiers = array();
314 * This is the resource type to be used when not specified
315 * at the beginning of the resource path. examples:
316 * $smarty->display('file:index.tpl');
317 * $smarty->display('db:index.tpl');
318 * $smarty->display('index.tpl'); // will use default resource type
319 * {include file="file:index.tpl"}
320 * {include file="db:index.tpl"}
321 * {include file="index.tpl"} {* will use default resource type *}
325 var $default_resource_type = 'file';
328 * The function used for cache file handling. If not set, built-in caching is used.
330 * @var null|string function name
332 var $cache_handler_func = null;
335 * These are the variables from the globals array that are
336 * assigned to all templates automatically. This isn't really
337 * necessary any more, you can use the $smarty var to access them
342 var $global_assign = array('HTTP_SERVER_VARS' => array('SCRIPT_NAME'));
345 * The value of "undefined". Leave it alone :-)
349 var $undefined = null;
352 * This indicates which filters are automatically loaded into Smarty.
354 * @var array array of filter names
356 var $autoload_filters = array();
362 * This tells if config file vars of the same name overwrite each other or not.
363 * if disabled, same name variables are accumulated in an array.
365 var $config_overwrite = true;
368 * This tells whether or not to automatically booleanize config file variables.
369 * If enabled, then the strings "on", "true", and "yes" are treated as boolean
370 * true, and "off", "false" and "no" are treated as boolean false.
372 var $config_booleanize = true;
375 * This tells whether hidden sections [.foobar] are readable from the
376 * tempalates or not. Normally you would never allow this since that is
377 * the point behind hidden sections: the application can access them, but
378 * the templates cannot.
380 var $config_read_hidden = false;
383 * This tells whether or not automatically fix newlines in config files.
384 * It basically converts \r (mac) or \r\n (dos) to \n
386 var $config_fix_newlines = true;
390 * If a template cannot be found, this PHP function will be executed.
391 * Useful for creating templates on-the-fly or other special action.
393 * @var string function name
395 var $default_template_handler_func = '';
398 * The file that contains the compiler class. This can a full
399 * pathname, or relative to the php_include path.
403 var $compiler_file = 'Smarty_Compiler.class.php';
406 * The class used for compiling templates.
410 var $compiler_class = 'Smarty_Compiler';
413 * The class used to load config vars.
417 var $config_class = 'Config_File';
420 * END Smarty Configuration Section
421 * There should be no need to touch anything below this line.
425 * error messages. true/false
429 var $_error_msg = false;
432 * where assigned template vars are kept
436 var $_tpl_vars = array();
439 * stores run-time $smarty.* vars
443 var $_smarty_vars = null;
446 * keeps track of sections
450 var $_sections = array();
453 * keeps track of foreach blocks
457 var $_foreach = array();
460 * keeps track of tag hierarchy
464 var $_tag_stack = array();
467 * configuration object
471 var $_conf_obj = null;
474 * loaded configuration settings
478 var $_config = array(array('vars' => array(), 'files' => array()));
481 * md5 checksum of the string 'Smarty'
485 var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f';
488 * Smarty version number
492 var $_version = '2.6.0-RC2';
495 * current template inclusion depth
499 var $_inclusion_depth = 0;
502 * for different compiled templates
506 var $_compile_id = null;
509 * text in URL to enable debug mode
513 var $_smarty_debug_id = 'SMARTY_DEBUG';
516 * debugging information for debug console
520 var $_smarty_debug_info = array();
523 * info that makes up a cache file
527 var $_cache_info = array();
530 * default file permissions
534 var $_file_perms = 0644;
537 * default dir permissions
541 var $_dir_perms = 0771;
548 var $_reg_objects = array();
551 * table keeping track of plugins
555 var $_plugins = array(
556 'modifier' => array(),
557 'function' => array(),
559 'compiler' => array(),
560 'prefilter' => array(),
561 'postfilter' => array(),
562 'outputfilter' => array(),
563 'resource' => array(),
564 'insert' => array());
572 var $_cache_serials = array();
575 * name of optional cache include file
579 var $_cache_include = null;
582 * indicate if the current code is used in a compiled
587 var $_cache_including = false;
591 * The class constructor.
593 * @uses $global_assign uses {@link assign()} to assign each corresponding
594 * value from $GLOBALS to the template vars
598 foreach ($this->global_assign
as $key => $var_name) {
599 if (is_array($var_name)) {
600 foreach ($var_name as $var) {
601 if (isset($GLOBALS[$key][$var])) {
602 $this->assign($var, $GLOBALS[$key][$var]);
604 $this->assign($var, $this->undefined
);
608 if (isset($GLOBALS[$var_name])) {
609 $this->assign($var_name, $GLOBALS[$var_name]);
611 $this->assign($var_name, $this->undefined
);
619 * assigns values to template variables
621 * @param array|string $tpl_var the template variable name(s)
622 * @param mixed $value the value to assign
624 function assign($tpl_var, $value = null)
626 if (is_array($tpl_var)){
627 foreach ($tpl_var as $key => $val) {
629 $this->_tpl_vars
[$key] = $val;
634 $this->_tpl_vars
[$tpl_var] = $value;
639 * assigns values to template variables by reference
641 * @param string $tpl_var the template variable name
642 * @param mixed $value the referenced value to assign
644 function assign_by_ref($tpl_var, &$value)
647 $this->_tpl_vars
[$tpl_var] = &$value;
651 * appends values to template variables
653 * @param array|string $tpl_var the template variable name(s)
654 * @param mixed $value the value to append
656 function append($tpl_var, $value=null, $merge=false)
658 if (is_array($tpl_var)) {
659 // $tpl_var is an array, ignore $value
660 foreach ($tpl_var as $_key => $_val) {
662 if(!@is_array
($this->_tpl_vars
[$_key])) {
663 settype($this->_tpl_vars
[$_key],'array');
665 if($merge && is_array($_val)) {
666 foreach($_val as $_mkey => $_mval) {
667 $this->_tpl_vars
[$_key][$_mkey] = $_mval;
670 $this->_tpl_vars
[$_key][] = $_val;
675 if ($tpl_var != '' && isset($value)) {
676 if(!@is_array
($this->_tpl_vars
[$tpl_var])) {
677 settype($this->_tpl_vars
[$tpl_var],'array');
679 if($merge && is_array($value)) {
680 foreach($value as $_mkey => $_mval) {
681 $this->_tpl_vars
[$tpl_var][$_mkey] = $_mval;
684 $this->_tpl_vars
[$tpl_var][] = $value;
691 * appends values to template variables by reference
693 * @param string $tpl_var the template variable name
694 * @param mixed $value the referenced value to append
696 function append_by_ref($tpl_var, &$value, $merge=false)
698 if ($tpl_var != '' && isset($value)) {
699 if(!@is_array
($this->_tpl_vars
[$tpl_var])) {
700 settype($this->_tpl_vars
[$tpl_var],'array');
702 if ($merge && is_array($value)) {
703 foreach($value as $_key => $_val) {
704 $this->_tpl_vars
[$tpl_var][$_key] = &$value[$_key];
707 $this->_tpl_vars
[$tpl_var][] = &$value;
714 * clear the given assigned template variable.
716 * @param string $tpl_var the template variable to clear
718 function clear_assign($tpl_var)
720 if (is_array($tpl_var))
721 foreach ($tpl_var as $curr_var)
722 unset($this->_tpl_vars
[$curr_var]);
724 unset($this->_tpl_vars
[$tpl_var]);
729 * Registers custom function to be used in templates
731 * @param string $function the name of the template function
732 * @param string $function_impl the name of the PHP function to register
734 function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null)
736 $this->_plugins
['function'][$function] =
737 array($function_impl, null, null, false, $cacheable, $cache_attrs);
742 * Unregisters custom function
744 * @param string $function name of template function
746 function unregister_function($function)
748 unset($this->_plugins
['function'][$function]);
752 * Registers object to be used in templates
754 * @param string $object name of template object
755 * @param object &$object_impl the referenced PHP object to register
756 * @param null|array $allowed list of allowed methods (empty = all)
757 * @param boolean $smarty_args smarty argument format, else traditional
758 * @param null|array $block_functs list of methods that are block format
760 function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
762 settype($allowed, 'array');
763 settype($smarty_args, 'boolean');
764 $this->_reg_objects
[$object] =
765 array(&$object_impl, $allowed, $smarty_args, $block_methods);
771 * @param string $object name of template object
773 function unregister_object($object)
775 unset($this->_reg_objects
[$object]);
780 * Registers block function to be used in templates
782 * @param string $block name of template block
783 * @param string $block_impl PHP function to register
785 function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)
787 $this->_plugins
['block'][$block] =
788 array($block_impl, null, null, false, $cacheable, $cache_attrs);
792 * Unregisters block function
794 * @param string $block name of template function
796 function unregister_block($block)
798 unset($this->_plugins
['block'][$block]);
802 * Registers compiler function
804 * @param string $function name of template function
805 * @param string $function_impl name of PHP function to register
807 function register_compiler_function($function, $function_impl, $cacheable=true)
809 $this->_plugins
['compiler'][$function] =
810 array($function_impl, null, null, false, $cacheable);
814 * Unregisters compiler function
816 * @param string $function name of template function
818 function unregister_compiler_function($function)
820 unset($this->_plugins
['compiler'][$function]);
824 * Registers modifier to be used in templates
826 * @param string $modifier name of template modifier
827 * @param string $modifier_impl name of PHP function to register
829 function register_modifier($modifier, $modifier_impl)
831 $this->_plugins
['modifier'][$modifier] =
832 array($modifier_impl, null, null, false);
836 * Unregisters modifier
838 * @param string $modifier name of template modifier
840 function unregister_modifier($modifier)
842 unset($this->_plugins
['modifier'][$modifier]);
846 * Registers a resource to fetch a template
848 * @param string $type name of resource
849 * @param array $functions array of functions to handle resource
851 function register_resource($type, $functions)
853 if (count($functions)==4) {
854 $this->_plugins
['resource'][$type] =
855 array($functions, false);
857 } elseif (count($functions)==5) {
858 $this->_plugins
['resource'][$type] =
859 array(array(array(&$functions[0], $functions[1])
860 ,array(&$functions[0], $functions[2])
861 ,array(&$functions[0], $functions[3])
862 ,array(&$functions[0], $functions[4]))
866 $this->trigger_error("malformed function-list for '$type' in register_resource");
872 * Unregisters a resource
874 * @param string $type name of resource
876 function unregister_resource($type)
878 unset($this->_plugins
['resource'][$type]);
882 * Registers a prefilter function to apply
883 * to a template before compiling
885 * @param string $function name of PHP function to register
887 function register_prefilter($function)
889 $_name = (is_array($function)) ?
$function[1] : $function;
890 $this->_plugins
['prefilter'][$_name]
891 = array($function, null, null, false);
895 * Unregisters a prefilter function
897 * @param string $function name of PHP function
899 function unregister_prefilter($function)
901 unset($this->_plugins
['prefilter'][$function]);
905 * Registers a postfilter function to apply
906 * to a compiled template after compilation
908 * @param string $function name of PHP function to register
910 function register_postfilter($function)
912 $_name = (is_array($function)) ?
$function[1] : $function;
913 $this->_plugins
['postfilter'][$_name]
914 = array($function, null, null, false);
918 * Unregisters a postfilter function
920 * @param string $function name of PHP function
922 function unregister_postfilter($function)
924 unset($this->_plugins
['postfilter'][$function]);
928 * Registers an output filter function to apply
929 * to a template output
931 * @param string $function name of PHP function
933 function register_outputfilter($function)
935 $_name = (is_array($function)) ?
$function[1] : $function;
936 $this->_plugins
['outputfilter'][$_name]
937 = array($function, null, null, false);
941 * Unregisters an outputfilter function
943 * @param string $function name of PHP function
945 function unregister_outputfilter($function)
947 unset($this->_plugins
['outputfilter'][$function]);
951 * load a filter of specified type and name
953 * @param string $type filter type
954 * @param string $name filter name
956 function load_filter($type, $name)
960 $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false)));
961 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.load_plugins.php');
962 smarty_core_load_plugins($_params, $this);
967 if (!isset($this->_plugins
[$type . 'filter'][$name]))
968 $this->_plugins
[$type . 'filter'][$name] = false;
974 * clear cached content for the given template and cache id
976 * @param string $tpl_file name of template file
977 * @param string $cache_id name of cache_id
978 * @param string $compile_id name of compile_id
979 * @param string $exp_time expiration time
982 function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
985 if (!isset($compile_id))
986 $compile_id = $this->compile_id
;
988 if (!isset($tpl_file))
991 $_auto_id = $this->_get_auto_id($cache_id, $compile_id);
993 if (!empty($this->cache_handler_func
)) {
994 return call_user_func_array($this->cache_handler_func
,
995 array('clear', &$this, &$dummy, $tpl_file, $cache_id, $compile_id));
997 $_params = array('auto_base' => $this->cache_dir
,
998 'auto_source' => $tpl_file,
999 'auto_id' => $_auto_id,
1000 'exp_time' => $exp_time);
1001 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.rm_auto.php');
1002 return smarty_core_rm_auto($_params, $this);
1009 * clear the entire contents of cache (all templates)
1011 * @param string $exp_time expire time
1012 * @return boolean results of {@link smarty_core_rm_auto()}
1014 function clear_all_cache($exp_time = null)
1016 if (!empty($this->cache_handler_func
)) {
1017 call_user_func_array($this->cache_handler_func
,
1018 array('clear', &$this, &$dummy));
1020 $_params = array('auto_base' => $this->cache_dir
,
1021 'auto_source' => null,
1023 'exp_time' => $exp_time);
1024 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.rm_auto.php');
1025 return smarty_core_rm_auto($_params, $this);
1031 * test to see if valid cache exists for this template
1033 * @param string $tpl_file name of template file
1034 * @param string $cache_id
1035 * @param string $compile_id
1036 * @return string|false results of {@link _read_cache_file()}
1038 function is_cached($tpl_file, $cache_id = null, $compile_id = null)
1040 if (!$this->caching
)
1043 if (!isset($compile_id))
1044 $compile_id = $this->compile_id
;
1047 'tpl_file' => $tpl_file,
1048 'cache_id' => $cache_id,
1049 'compile_id' => $compile_id
1051 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.read_cache_file.php');
1052 return smarty_core_read_cache_file($_params, $this);
1057 * clear all the assigned template variables.
1060 function clear_all_assign()
1062 $this->_tpl_vars
= array();
1066 * clears compiled version of specified template resource,
1067 * or all compiled template files if one is not specified.
1068 * This function is for advanced use only, not normally needed.
1070 * @param string $tpl_file
1071 * @param string $compile_id
1072 * @param string $exp_time
1073 * @return boolean results of {@link smarty_core_rm_auto()}
1075 function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
1077 if (!isset($compile_id)) {
1078 $compile_id = $this->compile_id
;
1080 $_params = array('auto_base' => $this->compile_dir
,
1081 'auto_source' => $tpl_file,
1082 'auto_id' => $compile_id,
1083 'exp_time' => $exp_time,
1084 'extensions' => array('.inc', '.php'));
1085 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.rm_auto.php');
1086 return smarty_core_rm_auto($_params, $this);
1090 * Checks whether requested template exists.
1092 * @param string $tpl_file
1095 function template_exists($tpl_file)
1097 $_params = array('resource_name' => $tpl_file, 'quiet'=>true, 'get_source'=>false);
1098 return $this->_fetch_resource_info($_params);
1102 * Returns an array containing template variables
1104 * @param string $name
1105 * @param string $type
1108 function &get_template_vars($name=null)
1111 return $this->_tpl_vars
;
1113 if(isset($this->_tpl_vars
[$name])) {
1114 return $this->_tpl_vars
[$name];
1119 * Returns an array containing config variables
1121 * @param string $name
1122 * @param string $type
1125 function &get_config_vars($name=null)
1127 if(!isset($name) && is_array($this->_config
[0])) {
1128 return $this->_config
[0]['vars'];
1129 } else if(isset($this->_config
[0]['vars'][$name])) {
1130 return $this->_config
[0]['vars'][$name];
1135 * trigger Smarty error
1137 * @param string $error_msg
1138 * @param integer $error_type
1140 function trigger_error($error_msg, $error_type = E_USER_WARNING
)
1142 trigger_error("Smarty error: $error_msg", $error_type);
1147 * executes & displays the template results
1149 * @param string $resource_name
1150 * @param string $cache_id
1151 * @param string $compile_id
1153 function display($resource_name, $cache_id = null, $compile_id = null)
1155 $this->fetch($resource_name, $cache_id, $compile_id, true);
1159 * executes & returns or displays the template results
1161 * @param string $resource_name
1162 * @param string $cache_id
1163 * @param string $compile_id
1164 * @param boolean $display
1166 function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)
1168 static $_cache_info = array();
1170 $_smarty_old_error_level = $this->debugging ?
error_reporting() : error_reporting(error_reporting() & ~E_NOTICE
);
1172 if($this->security
&& !in_array($this->template_dir
, $this->secure_dir
)) {
1173 // add template_dir to secure_dir array
1174 array_unshift($this->secure_dir
, $this->template_dir
);
1177 if (!$this->debugging
&& $this->debugging_ctrl
== 'URL'
1178 && @strstr
($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'], $this->_smarty_debug_id
)) {
1179 // enable debugging from URL
1180 $this->debugging
= true;
1183 if ($this->debugging
) {
1184 // capture time for debugging info
1186 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.get_microtime.php');
1187 $_debug_start_time = smarty_core_get_microtime($_params, $this);
1188 $this->_smarty_debug_info
[] = array('type' => 'template',
1189 'filename' => $resource_name,
1191 $_included_tpls_idx = count($this->_smarty_debug_info
) - 1;
1194 if (!isset($compile_id)) {
1195 $compile_id = $this->compile_id
;
1198 $this->_compile_id
= $compile_id;
1199 $this->_inclusion_depth
= 0;
1201 if ($this->caching
) {
1202 // save old cache_info, initialize cache_info
1203 array_push($_cache_info, $this->_cache_info
);
1204 $this->_cache_info
= array();
1206 'tpl_file' => $resource_name,
1207 'cache_id' => $cache_id,
1208 'compile_id' => $compile_id,
1211 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.read_cache_file.php');
1212 if (smarty_core_read_cache_file($_params, $this)) {
1213 $_smarty_results = $_params['results'];
1214 if (@count
($this->_cache_info
['insert_tags'])) {
1215 $_params = array('plugins' => $this->_cache_info
['insert_tags']);
1216 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.load_plugins.php');
1217 smarty_core_load_plugins($_params, $this);
1218 $_params = array('results' => $_smarty_results);
1219 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.process_cached_inserts.php');
1220 $_smarty_results = smarty_core_process_cached_inserts($_params, $this);
1222 if (@count
($this->_cache_info
['cache_serials'])) {
1223 $_params = array('results' => $_smarty_results);
1224 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.process_compiled_include.php');
1225 $_smarty_results = smarty_core_process_compiled_include($_params, $this);
1230 if ($this->debugging
)
1232 // capture time for debugging info
1234 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.get_microtime.php');
1235 $this->_smarty_debug_info
[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time;
1236 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.display_debug_console.php');
1237 $_smarty_results .= smarty_core_display_debug_console($_params, $this);
1239 if ($this->cache_modified_check
) {
1240 $_last_modified_date = @substr
($GLOBALS['HTTP_SERVER_VARS']['HTTP_IF_MODIFIED_SINCE'], 0, strpos($GLOBALS['HTTP_SERVER_VARS']['HTTP_IF_MODIFIED_SINCE'], 'GMT') +
3);
1241 $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info
['timestamp']).' GMT';
1242 if (@count
($this->_cache_info
['insert_tags']) == 0
1243 && !$this->_cache_serials
1244 && $_gmt_mtime == $_last_modified_date) {
1245 if (php_sapi_name()=='cgi')
1246 header("Status: 304 Not Modified");
1248 header("HTTP/1.1 304 Not Modified");
1251 header("Last-Modified: ".$_gmt_mtime);
1252 echo $_smarty_results;
1255 echo $_smarty_results;
1257 error_reporting($_smarty_old_error_level);
1258 // restore initial cache_info
1259 $this->_cache_info
= array_pop($_cache_info);
1262 error_reporting($_smarty_old_error_level);
1263 // restore initial cache_info
1264 $this->_cache_info
= array_pop($_cache_info);
1265 return $_smarty_results;
1268 $this->_cache_info
['template'][$resource_name] = true;
1269 if ($this->cache_modified_check
) {
1270 header("Last-Modified: ".gmdate('D, d M Y H:i:s', time()).' GMT');
1275 // load filters that are marked as autoload
1276 if (count($this->autoload_filters
)) {
1277 foreach ($this->autoload_filters
as $_filter_type => $_filters) {
1278 foreach ($_filters as $_filter) {
1279 $this->load_filter($_filter_type, $_filter);
1284 $_smarty_compile_path = $this->_get_compile_path($resource_name);
1286 // if we just need to display the results, don't perform output
1287 // buffering - for speed
1288 $_cache_including = $this->_cache_including
;
1289 $this->_cache_including
= false;
1290 if ($display && !$this->caching
&& count($this->_plugins
['outputfilter']) == 0) {
1291 if ($this->_is_compiled($resource_name, $_smarty_compile_path)
1292 ||
$this->_compile_resource($resource_name, $_smarty_compile_path))
1294 include($_smarty_compile_path);
1299 if ($this->_is_compiled($resource_name, $_smarty_compile_path)
1300 ||
$this->_compile_resource($resource_name, $_smarty_compile_path))
1302 include($_smarty_compile_path);
1304 $_smarty_results = ob_get_contents();
1307 foreach ((array)$this->_plugins
['outputfilter'] as $_output_filter) {
1308 $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this));
1312 if ($this->caching
) {
1313 $_params = array('tpl_file' => $resource_name,
1314 'cache_id' => $cache_id,
1315 'compile_id' => $compile_id,
1316 'results' => $_smarty_results);
1317 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.write_cache_file.php');
1318 smarty_core_write_cache_file($_params, $this);
1319 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.process_cached_inserts.php');
1320 $_smarty_results = smarty_core_process_cached_inserts($_params, $this);
1322 if ($this->_cache_serials
) {
1323 // strip nocache-tags from output
1324 $_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s'
1328 // restore initial cache_info
1329 $this->_cache_info
= array_pop($_cache_info);
1331 $this->_cache_including
= $_cache_including;
1334 global $timer_start;
1337 if (isset($_smarty_results)) { echo $_smarty_results; }
1339 if ($this->debugging
) {
1340 // capture time for debugging info
1342 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.get_microtime.php');
1343 $this->_smarty_debug_info
[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time);
1344 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.display_debug_console.php');
1345 echo smarty_core_display_debug_console($_params, $this);
1347 error_reporting($_smarty_old_error_level);
1351 error_reporting($_smarty_old_error_level);
1352 if (isset($_smarty_results)) { return $_smarty_results; }
1357 * load configuration values
1359 * @param string $file
1360 * @param string $section
1361 * @param string $scope
1363 function config_load($file, $section = null, $scope = 'global')
1365 require_once($this->_get_plugin_filepath('function', 'config_load'));
1366 smarty_function_config_load(array('file' => $file, 'section' => $section, 'scope' => $scope), $this);
1370 * return a reference to a registered object
1372 * @param string $name
1375 function &get_registered_object($name) {
1376 if (!isset($this->_reg_objects
[$name]))
1377 $this->_trigger_fatal_error("'$name' is not a registered object");
1379 if (!is_object($this->_reg_objects
[$name][0]))
1380 $this->_trigger_fatal_error("registered '$name' is not an object");
1382 return $this->_reg_objects
[$name][0];
1386 * clear configuration values
1388 * @param string $var
1390 function clear_config($var = null)
1394 $this->_config
= array(array('vars' => array(),
1395 'files' => array()));
1397 unset($this->_config
[0]['vars'][$var]);
1402 * Quote subpattern references
1404 * @param string $string
1407 function quote_replace($string)
1409 return preg_replace('![\\$]\d!', '\\\\\\0', $string);
1413 * get filepath of requested plugin
1415 * @param string $type
1416 * @param string $name
1417 * @return string|false
1419 function _get_plugin_filepath($type, $name)
1421 $_params = array('type' => $type, 'name' => $name);
1422 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.assemble_plugin_filepath.php');
1423 return smarty_core_assemble_plugin_filepath($_params, $this);
1427 * test if resource needs compiling
1429 * @param string $resource_name
1430 * @param string $compile_path
1433 function _is_compiled($resource_name, $compile_path)
1435 if (!$this->force_compile
&& file_exists($compile_path)) {
1436 if (!$this->compile_check
) {
1437 // no need to check compiled file
1440 // get file source and timestamp
1441 $_params = array('resource_name' => $resource_name, 'get_source'=>false);
1442 if (!$this->_fetch_resource_info($_params, $this)) {
1445 if ($_params['resource_timestamp'] <= filemtime($compile_path)) {
1446 // template not expired, no recompile
1454 // compiled template does not exist, or forced compile
1460 * compile the template
1462 * @param string $resource_name
1463 * @param string $compile_path
1466 function _compile_resource($resource_name, $compile_path)
1469 $_params = array('resource_name' => $resource_name);
1470 if (!$this->_fetch_resource_info($_params)) {
1474 $_source_content = $_params['source_content'];
1475 $_resource_timestamp = $_params['resource_timestamp'];
1476 $_cache_include = substr($compile_path, 0, -4).'.inc';
1478 if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) {
1479 // if a _cache_serial was set, we also have to write an include-file:
1480 if ($this->_cache_include_info
) {
1481 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.write_compiled_include.php');
1482 smarty_core_write_compiled_include(array_merge($this->_cache_include_info
, array('compiled_content'=>$_compiled_content)), $this);
1485 $_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content, 'resource_timestamp' => $_resource_timestamp);
1486 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.write_compiled_resource.php');
1487 smarty_core_write_compiled_resource($_params, $this);
1491 $this->trigger_error($smarty_compiler->_error_msg
);
1498 * compile the given source
1500 * @param string $resource_name
1501 * @param string $source_content
1502 * @param string $compiled_content
1505 function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null)
1507 if (file_exists(SMARTY_DIR
. $this->compiler_file
)) {
1508 require_once(SMARTY_DIR
. $this->compiler_file
);
1511 require_once($this->compiler_file
);
1515 $smarty_compiler = new $this->compiler_class
;
1517 $smarty_compiler->template_dir
= $this->template_dir
;
1518 $smarty_compiler->compile_dir
= $this->compile_dir
;
1519 $smarty_compiler->plugins_dir
= $this->plugins_dir
;
1520 $smarty_compiler->config_dir
= $this->config_dir
;
1521 $smarty_compiler->force_compile
= $this->force_compile
;
1522 $smarty_compiler->caching
= $this->caching
;
1523 $smarty_compiler->php_handling
= $this->php_handling
;
1524 $smarty_compiler->left_delimiter
= $this->left_delimiter
;
1525 $smarty_compiler->right_delimiter
= $this->right_delimiter
;
1526 $smarty_compiler->_version
= $this->_version
;
1527 $smarty_compiler->security
= $this->security
;
1528 $smarty_compiler->secure_dir
= $this->secure_dir
;
1529 $smarty_compiler->security_settings
= $this->security_settings
;
1530 $smarty_compiler->trusted_dir
= $this->trusted_dir
;
1531 $smarty_compiler->_reg_objects
= &$this->_reg_objects
;
1532 $smarty_compiler->_plugins
= &$this->_plugins
;
1533 $smarty_compiler->_tpl_vars
= &$this->_tpl_vars
;
1534 $smarty_compiler->default_modifiers
= $this->default_modifiers
;
1535 $smarty_compiler->compile_id
= $this->_compile_id
;
1536 $smarty_compiler->_config
= $this->_config
;
1537 $smarty_compiler->request_use_auto_globals
= $this->request_use_auto_globals
;
1539 $smarty_compiler->_cache_serial
= null;
1540 $smarty_compiler->_cache_include
= $cache_include_path;
1543 $_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content);
1545 if ($smarty_compiler->_cache_serial
) {
1546 $this->_cache_include_info
= array(
1547 'cache_serial'=>$smarty_compiler->_cache_serial
1548 ,'plugins_code'=>$smarty_compiler->_plugins_code
1549 ,'include_file_path' => $cache_include_path);
1552 $this->_cache_include_info
= null;
1560 * Get the compile path for this resource
1562 * @param string $resource_name
1563 * @return string results of {@link _get_auto_filename()}
1565 function _get_compile_path($resource_name)
1567 return $this->_get_auto_filename($this->compile_dir
, $resource_name,
1568 $this->_compile_id
) . '.php';
1572 * fetch the template info. Gets timestamp, and source
1573 * if get_source is true
1575 * sets $source_content to the source of the template, and
1576 * $resource_timestamp to its time stamp
1577 * @param string $resource_name
1578 * @param string $source_content
1579 * @param integer $resource_timestamp
1580 * @param boolean $get_source
1581 * @param boolean $quiet
1585 function _fetch_resource_info(&$params)
1587 if(!isset($params['get_source'])) { $params['get_source'] = true; }
1588 if(!isset($params['quiet'])) { $params['quiet'] = false; }
1591 $_params = array('resource_name' => $params['resource_name']) ;
1592 if (isset($params['resource_base_path']))
1593 $_params['resource_base_path'] = $params['resource_base_path'];
1595 if ($this->_parse_resource_name($_params)) {
1596 $_resource_type = $_params['resource_type'];
1597 $_resource_name = $_params['resource_name'];
1598 switch ($_resource_type) {
1600 if ($params['get_source']) {
1601 $params['source_content'] = $this->_read_file($_resource_name);
1603 $params['resource_timestamp'] = filemtime($_resource_name);
1604 $_return = is_file($_resource_name);
1608 // call resource functions to fetch the template source and timestamp
1609 if ($params['get_source']) {
1610 $_source_return = isset($this->_plugins
['resource'][$_resource_type]) &&
1611 call_user_func_array($this->_plugins
['resource'][$_resource_type][0][0],
1612 array($_resource_name, &$params['source_content'], &$this));
1614 $_source_return = true;
1617 $_timestamp_return = isset($this->_plugins
['resource'][$_resource_type]) &&
1618 call_user_func_array($this->_plugins
['resource'][$_resource_type][0][1],
1619 array($_resource_name, &$params['resource_timestamp'], &$this));
1621 $_return = $_source_return && $_timestamp_return;
1627 // see if we can get a template with the default template handler
1628 if (!empty($this->default_template_handler_func
)) {
1629 if (!is_callable($this->default_template_handler_func
)) {
1630 $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist.");
1632 $_return = call_user_func_array(
1633 $this->default_template_handler_func
,
1634 array($_resource_type, $_resource_name, &$params['source_content'], &$params['resource_timestamp'], &$this));
1640 if (!$params['quiet']) {
1641 $this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"');
1643 } else if ($_return && $this->security
) {
1644 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.is_secure.php');
1645 if (!smarty_core_is_secure($_params, $this)) {
1646 if (!$params['quiet'])
1647 $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed');
1648 $params['source_content'] = null;
1649 $params['resource_timestamp'] = null;
1658 * parse out the type and name from the resource
1660 * @param string $resource_base_path
1661 * @param string $resource_name
1662 * @param string $resource_type
1663 * @param string $resource_name
1667 function _parse_resource_name(&$params)
1670 // split tpl_path by the first colon
1671 $_resource_name_parts = explode(':', $params['resource_name'], 2);
1673 if (count($_resource_name_parts) == 1) {
1674 // no resource type given
1675 $params['resource_type'] = $this->default_resource_type
;
1676 $params['resource_name'] = $_resource_name_parts[0];
1678 if(strlen($_resource_name_parts[0]) == 1) {
1679 // 1 char is not resource type, but part of filepath
1680 $params['resource_type'] = $this->default_resource_type
;
1681 $params['resource_name'] = $params['resource_name'];
1683 $params['resource_type'] = $_resource_name_parts[0];
1684 $params['resource_name'] = $_resource_name_parts[1];
1688 if ($params['resource_type'] == 'file') {
1689 if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $params['resource_name'])) {
1690 // relative pathname to $params['resource_base_path']
1691 // use the first directory where the file is found
1692 if (isset($params['resource_base_path'])) {
1693 $_resource_base_path = (array)$params['resource_base_path'];
1695 $_resource_base_path = (array)$this->template_dir
;
1696 $_resource_base_path[] = '.';
1698 foreach ($_resource_base_path as $_curr_path) {
1699 $_fullpath = $_curr_path . DIRECTORY_SEPARATOR
. $params['resource_name'];
1700 if (file_exists($_fullpath) && is_file($_fullpath)) {
1701 $params['resource_name'] = $_fullpath;
1704 // didn't find the file, try include_path
1705 $_params = array('file_path' => $_fullpath);
1706 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.get_include_path.php');
1707 if(smarty_core_get_include_path($_params, $this)) {
1708 $params['resource_name'] = $_params['new_file_path'];
1715 $_params = array('type' => $params['resource_type']);
1716 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.load_resource_plugin.php');
1717 smarty_core_load_resource_plugin($_params, $this);
1727 * @param string|null $modifier_name
1728 * @param array|null $map_array
1729 * @return string result of modifiers
1731 function _run_mod_handler()
1733 $_args = func_get_args();
1734 list($_modifier_name, $_map_array) = array_splice($_args, 0, 2);
1735 list($_func_name, $_tpl_file, $_tpl_line) =
1736 $this->_plugins
['modifier'][$_modifier_name];
1739 foreach ($_var as $_key => $_val) {
1741 $_var[$_key] = call_user_func_array($_func_name, $_args);
1747 * Remove starting and ending quotes from the string
1749 * @param string $string
1752 function _dequote($string)
1754 if (($string{0} == "'" ||
$string{0} == '"') &&
1755 $string{strlen($string)-1} == $string{0})
1756 return substr($string, 1, -1);
1763 * read in a file from line $start for $lines.
1764 * read the entire file if $start and $lines are null.
1766 * @param string $filename
1767 * @param integer $start
1768 * @param integer $lines
1771 function _read_file($filename, $start=null, $lines=null)
1773 if (!($fd = @fopen
($filename, 'r'))) {
1776 flock($fd, LOCK_SH
);
1777 if ($start == null && $lines == null) {
1778 // read the entire file
1779 $contents = fread($fd, filesize($filename));
1782 // skip the first lines before $start
1783 for ($loop=1; $loop < $start; $loop++
) {
1787 if ( $lines == null ) {
1788 // read the rest of the file
1789 while (!feof($fd)) {
1790 $contents .= fgets($fd, 65536);
1793 // read up to $lines lines
1794 for ($loop=0; $loop < $lines; $loop++
) {
1795 $contents .= fgets($fd, 65536);
1807 * get a concrete filename for automagically created content
1809 * @param string $auto_base
1810 * @param string $auto_source
1811 * @param string $auto_id
1813 * @staticvar string|null
1814 * @staticvar string|null
1816 function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null)
1818 $_compile_dir_sep = $this->use_sub_dirs ? DIRECTORY_SEPARATOR
: '^';
1820 if(@is_dir
($auto_base)) {
1821 $_return = $auto_base . DIRECTORY_SEPARATOR
;
1823 // auto_base not found, try include_path
1824 $_params = array('file_path' => $auto_base);
1825 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.get_include_path.php');
1826 smarty_core_get_include_path($_params, $this);
1827 $_return = isset($_params['new_file_path']) ?
$_params['new_file_path'] . DIRECTORY_SEPARATOR
: null;
1830 if(isset($auto_id)) {
1831 // make auto_id safe for directory names
1832 $auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id)));
1833 // split into separate directories
1834 $_return .= $auto_id . $_compile_dir_sep;
1837 if(isset($auto_source)) {
1838 // make source name safe for filename
1839 $_filename = urlencode(basename($auto_source));
1840 $_crc32 = crc32($auto_source) . $_compile_dir_sep;
1841 // prepend %% to avoid name conflicts with
1842 // with $params['auto_id'] names
1843 $_crc32 = '%%' . substr($_crc32,0,3) . $_compile_dir_sep . '%%' . $_crc32;
1844 $_return .= $_crc32 . $_filename;
1851 * unlink a file, possibly using expiration time
1853 * @param string $resource
1854 * @param integer $exp_time
1856 function _unlink($resource, $exp_time = null)
1858 if(isset($exp_time)) {
1859 if(time() - @filemtime
($resource) >= $exp_time) {
1860 return @unlink
($resource);
1863 return @unlink
($resource);
1868 * returns an auto_id for auto-file-functions
1870 * @param string $cache_id
1871 * @param string $compile_id
1872 * @return string|null
1874 function _get_auto_id($cache_id=null, $compile_id=null) {
1875 if (isset($cache_id))
1876 return (isset($compile_id)) ?
$cache_id . '|' . $compile_id : $cache_id;
1877 elseif(isset($compile_id))
1884 * trigger Smarty plugin error
1886 * @param string $error_msg
1887 * @param string $tpl_file
1888 * @param integer $tpl_line
1889 * @param string $file
1890 * @param integer $line
1891 * @param integer $error_type
1893 function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null,
1894 $file = null, $line = null, $error_type = E_USER_ERROR
)
1896 if(isset($file) && isset($line)) {
1897 $info = ' ('.basename($file).", line $line)";
1901 if (isset($tpl_line) && isset($tpl_file)) {
1902 trigger_error("Smarty error: [in " . $tpl_file . " line " .
1903 $tpl_line . "]: $error_msg$info", $error_type);
1905 trigger_error("Smarty error: $error_msg$info", $error_type);
1911 * callback function for preg_replace, to call a non-cacheable block
1914 function _process_compiled_include_callback($match) {
1915 $_func = '_smarty_tplfunc_'.$match[2].'_'.$match[3];
1918 $_ret = ob_get_contents();
1925 * called for included templates
1927 * @param string $_smarty_include_tpl_file
1928 * @param string $_smarty_include_vars
1931 // $_smarty_include_tpl_file, $_smarty_include_vars
1933 function _smarty_include($params)
1935 if ($this->debugging
) {
1937 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.get_microtime.php');
1938 $debug_start_time = smarty_core_get_microtime($_params, $this);
1939 $this->_smarty_debug_info
[] = array('type' => 'template',
1940 'filename' => $params['smarty_include_tpl_file'],
1941 'depth' => ++
$this->_inclusion_depth
);
1942 $included_tpls_idx = count($this->_smarty_debug_info
) - 1;
1945 // by kybu, inkluduju sa iba .tpl
1946 if (substr($params['smarty_include_tpl_file'], -3) != 'tpl')
1949 $this->_tpl_vars
= array_merge($this->_tpl_vars
, $params['smarty_include_vars']);
1951 // config vars are treated as local, so push a copy of the
1952 // current ones onto the front of the stack
1953 array_unshift($this->_config
, $this->_config
[0]);
1955 $_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']);
1958 if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path)
1959 ||
$this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path))
1961 include($_smarty_compile_path);
1964 // pop the local vars off the front of the stack
1965 array_shift($this->_config
);
1967 $this->_inclusion_depth
--;
1969 if ($this->debugging
) {
1970 // capture time for debugging info
1972 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.get_microtime.php');
1973 $this->_smarty_debug_info
[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time;
1976 if ($this->caching
) {
1977 $this->_cache_info
['template'][$params['smarty_include_tpl_file']] = true;
1983 * get or set an array of cached attributes for function that is
1987 function &_smarty_cache_attrs($cache_serial, $count) {
1988 $_cache_attrs =& $this->_cache_info
['cache_attrs'][$cache_serial][$count];
1990 if ($this->_cache_including
) {
1991 /* return next set of cache_attrs */
1992 $_return =& current($_cache_attrs);
1993 next($_cache_attrs);
1997 /* add a reference to a new set of cache_attrs */
1998 $_cache_attrs[] = array();
1999 return $_cache_attrs[count($_cache_attrs)-1];
2007 * wrapper for include() retaining $this
2010 function _include($filename, $once=false, $vars=null)
2012 if (is_array($vars))
2013 extract($vars, EXTR_PREFIX_SAME
, 'include_php_');
2016 return include_once($filename);
2018 return include($filename);
2024 * wrapper for eval() retaining $this
2027 function _eval($code, $vars=null)
2029 if (is_array($vars))
2030 extract($vars, EXTR_PREFIX_SAME
, 'include_php_');
2038 /* vim: set expandtab: */