00001 <?php
00002
00033
00034
00038 if(!defined('DIR_SEP')) {
00039 define('DIR_SEP', DIRECTORY_SEPARATOR);
00040 }
00041
00048 if (!defined('SMARTY_DIR')) {
00049 define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
00050 }
00051
00052 if (!defined('SMARTY_CORE_DIR')) {
00053 define('SMARTY_CORE_DIR', SMARTY_DIR . 'internals' . DIRECTORY_SEPARATOR);
00054 }
00055
00056 define('SMARTY_PHP_PASSTHRU', 0);
00057 define('SMARTY_PHP_QUOTE', 1);
00058 define('SMARTY_PHP_REMOVE', 2);
00059 define('SMARTY_PHP_ALLOW', 3);
00060
00064 class Smarty
00065 {
00075 var $template_dir = 'templates';
00076
00082 var $compile_dir = 'templates_c';
00083
00089 var $config_dir = 'configs';
00090
00096 var $plugins_dir = array('plugins');
00097
00105 var $debugging = false;
00106
00112 var $error_reporting = null;
00113
00120 var $debug_tpl = '';
00121
00131 var $debugging_ctrl = 'NONE';
00132
00141 var $compile_check = true;
00142
00149 var $force_compile = false;
00150
00160 var $caching = 0;
00161
00167 var $cache_dir = 'cache';
00168
00178 var $cache_lifetime = 3600;
00179
00188 var $cache_modified_check = false;
00189
00202 var $php_handling = SMARTY_PHP_PASSTHRU;
00203
00212 var $security = false;
00213
00221 var $secure_dir = array();
00222
00229 var $security_settings = array(
00230 'PHP_HANDLING' => false,
00231 'IF_FUNCS' => array('array', 'list',
00232 'isset', 'empty',
00233 'count', 'sizeof',
00234 'in_array', 'is_array',
00235 'true', 'false', 'null'),
00236 'INCLUDE_ANY' => false,
00237 'PHP_TAGS' => false,
00238 'MODIFIER_FUNCS' => array('count'),
00239 'ALLOW_CONSTANTS' => false
00240 );
00241
00248 var $trusted_dir = array();
00249
00255 var $left_delimiter = '{';
00256
00262 var $right_delimiter = '}';
00263
00271 var $request_vars_order = 'EGPCS';
00272
00281 var $request_use_auto_globals = true;
00282
00291 var $compile_id = null;
00292
00301 var $use_sub_dirs = false;
00302
00310 var $default_modifiers = array();
00311
00324 var $default_resource_type = 'file';
00325
00331 var $cache_handler_func = null;
00332
00338 var $autoload_filters = array();
00339
00347 var $config_overwrite = true;
00348
00354 var $config_booleanize = true;
00355
00362 var $config_read_hidden = false;
00363
00368 var $config_fix_newlines = true;
00377 var $default_template_handler_func = '';
00378
00385 var $compiler_file = 'Smarty_Compiler.class.php';
00386
00392 var $compiler_class = 'Smarty_Compiler';
00393
00399 var $config_class = 'Config_File';
00400
00411 var $_tpl_vars = array();
00412
00418 var $_smarty_vars = null;
00419
00425 var $_sections = array();
00426
00432 var $_foreach = array();
00433
00439 var $_tag_stack = array();
00440
00446 var $_conf_obj = null;
00447
00453 var $_config = array(array('vars' => array(), 'files' => array()));
00454
00460 var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f';
00461
00467 var $_version = '2.6.10';
00468
00474 var $_inclusion_depth = 0;
00475
00481 var $_compile_id = null;
00482
00488 var $_smarty_debug_id = 'SMARTY_DEBUG';
00489
00495 var $_smarty_debug_info = array();
00496
00502 var $_cache_info = array();
00503
00509 var $_file_perms = 0644;
00510
00516 var $_dir_perms = 0771;
00517
00523 var $_reg_objects = array();
00524
00530 var $_plugins = array(
00531 'modifier' => array(),
00532 'function' => array(),
00533 'block' => array(),
00534 'compiler' => array(),
00535 'prefilter' => array(),
00536 'postfilter' => array(),
00537 'outputfilter' => array(),
00538 'resource' => array(),
00539 'insert' => array());
00540
00541
00547 var $_cache_serials = array();
00548
00554 var $_cache_include = null;
00555
00562 var $_cache_including = false;
00563
00568 function Smarty()
00569 {
00570 $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME']
00571 : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
00572 }
00573
00580 function assign($tpl_var, $value = null)
00581 {
00582 if (is_array($tpl_var)){
00583 foreach ($tpl_var as $key => $val) {
00584 if ($key != '') {
00585 $this->_tpl_vars[$key] = $val;
00586 }
00587 }
00588 } else {
00589 if ($tpl_var != '')
00590 $this->_tpl_vars[$tpl_var] = $value;
00591 }
00592 }
00593
00600 function assign_by_ref($tpl_var, &$value)
00601 {
00602 if ($tpl_var != '')
00603 $this->_tpl_vars[$tpl_var] = &$value;
00604 }
00605
00612 function append($tpl_var, $value=null, $merge=false)
00613 {
00614 if (is_array($tpl_var)) {
00615
00616 foreach ($tpl_var as $_key => $_val) {
00617 if ($_key != '') {
00618 if(!@is_array($this->_tpl_vars[$_key])) {
00619 settype($this->_tpl_vars[$_key],'array');
00620 }
00621 if($merge && is_array($_val)) {
00622 foreach($_val as $_mkey => $_mval) {
00623 $this->_tpl_vars[$_key][$_mkey] = $_mval;
00624 }
00625 } else {
00626 $this->_tpl_vars[$_key][] = $_val;
00627 }
00628 }
00629 }
00630 } else {
00631 if ($tpl_var != '' && isset($value)) {
00632 if(!@is_array($this->_tpl_vars[$tpl_var])) {
00633 settype($this->_tpl_vars[$tpl_var],'array');
00634 }
00635 if($merge && is_array($value)) {
00636 foreach($value as $_mkey => $_mval) {
00637 $this->_tpl_vars[$tpl_var][$_mkey] = $_mval;
00638 }
00639 } else {
00640 $this->_tpl_vars[$tpl_var][] = $value;
00641 }
00642 }
00643 }
00644 }
00645
00652 function append_by_ref($tpl_var, &$value, $merge=false)
00653 {
00654 if ($tpl_var != '' && isset($value)) {
00655 if(!@is_array($this->_tpl_vars[$tpl_var])) {
00656 settype($this->_tpl_vars[$tpl_var],'array');
00657 }
00658 if ($merge && is_array($value)) {
00659 foreach($value as $_key => $_val) {
00660 $this->_tpl_vars[$tpl_var][$_key] = &$value[$_key];
00661 }
00662 } else {
00663 $this->_tpl_vars[$tpl_var][] = &$value;
00664 }
00665 }
00666 }
00667
00668
00674 function clear_assign($tpl_var)
00675 {
00676 if (is_array($tpl_var))
00677 foreach ($tpl_var as $curr_var)
00678 unset($this->_tpl_vars[$curr_var]);
00679 else
00680 unset($this->_tpl_vars[$tpl_var]);
00681 }
00682
00683
00690 function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null)
00691 {
00692 $this->_plugins['function'][$function] =
00693 array($function_impl, null, null, false, $cacheable, $cache_attrs);
00694
00695 }
00696
00702 function unregister_function($function)
00703 {
00704 unset($this->_plugins['function'][$function]);
00705 }
00706
00716 function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
00717 {
00718 settype($allowed, 'array');
00719 settype($smarty_args, 'boolean');
00720 $this->_reg_objects[$object] =
00721 array(&$object_impl, $allowed, $smarty_args, $block_methods);
00722 }
00723
00729 function unregister_object($object)
00730 {
00731 unset($this->_reg_objects[$object]);
00732 }
00733
00734
00741 function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)
00742 {
00743 $this->_plugins['block'][$block] =
00744 array($block_impl, null, null, false, $cacheable, $cache_attrs);
00745 }
00746
00752 function unregister_block($block)
00753 {
00754 unset($this->_plugins['block'][$block]);
00755 }
00756
00763 function register_compiler_function($function, $function_impl, $cacheable=true)
00764 {
00765 $this->_plugins['compiler'][$function] =
00766 array($function_impl, null, null, false, $cacheable);
00767 }
00768
00774 function unregister_compiler_function($function)
00775 {
00776 unset($this->_plugins['compiler'][$function]);
00777 }
00778
00785 function register_modifier($modifier, $modifier_impl)
00786 {
00787 $this->_plugins['modifier'][$modifier] =
00788 array($modifier_impl, null, null, false);
00789 }
00790
00796 function unregister_modifier($modifier)
00797 {
00798 unset($this->_plugins['modifier'][$modifier]);
00799 }
00800
00807 function register_resource($type, $functions)
00808 {
00809 if (count($functions)==4) {
00810 $this->_plugins['resource'][$type] =
00811 array($functions, false);
00812
00813 } elseif (count($functions)==5) {
00814 $this->_plugins['resource'][$type] =
00815 array(array(array(&$functions[0], $functions[1])
00816 ,array(&$functions[0], $functions[2])
00817 ,array(&$functions[0], $functions[3])
00818 ,array(&$functions[0], $functions[4]))
00819 ,false);
00820
00821 } else {
00822 $this->trigger_error("malformed function-list for '$type' in register_resource");
00823
00824 }
00825 }
00826
00832 function unregister_resource($type)
00833 {
00834 unset($this->_plugins['resource'][$type]);
00835 }
00836
00843 function register_prefilter($function)
00844 {
00845 $_name = (is_array($function)) ? $function[1] : $function;
00846 $this->_plugins['prefilter'][$_name]
00847 = array($function, null, null, false);
00848 }
00849
00855 function unregister_prefilter($function)
00856 {
00857 unset($this->_plugins['prefilter'][$function]);
00858 }
00859
00866 function register_postfilter($function)
00867 {
00868 $_name = (is_array($function)) ? $function[1] : $function;
00869 $this->_plugins['postfilter'][$_name]
00870 = array($function, null, null, false);
00871 }
00872
00878 function unregister_postfilter($function)
00879 {
00880 unset($this->_plugins['postfilter'][$function]);
00881 }
00882
00889 function register_outputfilter($function)
00890 {
00891 $_name = (is_array($function)) ? $function[1] : $function;
00892 $this->_plugins['outputfilter'][$_name]
00893 = array($function, null, null, false);
00894 }
00895
00901 function unregister_outputfilter($function)
00902 {
00903 unset($this->_plugins['outputfilter'][$function]);
00904 }
00905
00912 function load_filter($type, $name)
00913 {
00914 switch ($type) {
00915 case 'output':
00916 $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false)));
00917 require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
00918 smarty_core_load_plugins($_params, $this);
00919 break;
00920
00921 case 'pre':
00922 case 'post':
00923 if (!isset($this->_plugins[$type . 'filter'][$name]))
00924 $this->_plugins[$type . 'filter'][$name] = false;
00925 break;
00926 }
00927 }
00928
00938 function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
00939 {
00940
00941 if (!isset($compile_id))
00942 $compile_id = $this->compile_id;
00943
00944 if (!isset($tpl_file))
00945 $compile_id = null;
00946
00947 $_auto_id = $this->_get_auto_id($cache_id, $compile_id);
00948
00949 if (!empty($this->cache_handler_func)) {
00950 return call_user_func_array($this->cache_handler_func,
00951 array('clear', &$this, &$dummy, $tpl_file, $cache_id, $compile_id, $exp_time));
00952 } else {
00953 $_params = array('auto_base' => $this->cache_dir,
00954 'auto_source' => $tpl_file,
00955 'auto_id' => $_auto_id,
00956 'exp_time' => $exp_time);
00957 require_once(SMARTY_CORE_DIR . 'core.rm_auto.php');
00958 return smarty_core_rm_auto($_params, $this);
00959 }
00960
00961 }
00962
00963
00970 function clear_all_cache($exp_time = null)
00971 {
00972 return $this->clear_cache(null, null, null, $exp_time);
00973 }
00974
00975
00984 function is_cached($tpl_file, $cache_id = null, $compile_id = null)
00985 {
00986 if (!$this->caching)
00987 return false;
00988
00989 if (!isset($compile_id))
00990 $compile_id = $this->compile_id;
00991
00992 $_params = array(
00993 'tpl_file' => $tpl_file,
00994 'cache_id' => $cache_id,
00995 'compile_id' => $compile_id
00996 );
00997 require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php');
00998 return smarty_core_read_cache_file($_params, $this);
00999 }
01000
01001
01006 function clear_all_assign()
01007 {
01008 $this->_tpl_vars = array();
01009 }
01010
01021 function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
01022 {
01023 if (!isset($compile_id)) {
01024 $compile_id = $this->compile_id;
01025 }
01026 $_params = array('auto_base' => $this->compile_dir,
01027 'auto_source' => $tpl_file,
01028 'auto_id' => $compile_id,
01029 'exp_time' => $exp_time,
01030 'extensions' => array('.inc', '.php'));
01031 require_once(SMARTY_CORE_DIR . 'core.rm_auto.php');
01032 return smarty_core_rm_auto($_params, $this);
01033 }
01034
01041 function template_exists($tpl_file)
01042 {
01043 $_params = array('resource_name' => $tpl_file, 'quiet'=>true, 'get_source'=>false);
01044 return $this->_fetch_resource_info($_params);
01045 }
01046
01054 function &get_template_vars($name=null)
01055 {
01056 if(!isset($name)) {
01057 return $this->_tpl_vars;
01058 }
01059 if(isset($this->_tpl_vars[$name])) {
01060 return $this->_tpl_vars[$name];
01061 }
01062 }
01063
01071 function &get_config_vars($name=null)
01072 {
01073 if(!isset($name) && is_array($this->_config[0])) {
01074 return $this->_config[0]['vars'];
01075 } else if(isset($this->_config[0]['vars'][$name])) {
01076 return $this->_config[0]['vars'][$name];
01077 }
01078 }
01079
01086 function trigger_error($error_msg, $error_type = E_USER_WARNING)
01087 {
01088 trigger_error("Smarty error: $error_msg", $error_type);
01089 }
01090
01091
01099 function display($resource_name, $cache_id = null, $compile_id = null)
01100 {
01101 $this->fetch($resource_name, $cache_id, $compile_id, true);
01102 }
01103
01112 function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)
01113 {
01114 static $_cache_info = array();
01115
01116 $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting)
01117 ? $this->error_reporting : error_reporting() & ~E_NOTICE);
01118
01119 if (!$this->debugging && $this->debugging_ctrl == 'URL') {
01120 $_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'];
01121 if (@strstr($_query_string, $this->_smarty_debug_id)) {
01122 if (@strstr($_query_string, $this->_smarty_debug_id . '=on')) {
01123
01124 @setcookie('SMARTY_DEBUG', true);
01125 $this->debugging = true;
01126 } elseif (@strstr($_query_string, $this->_smarty_debug_id . '=off')) {
01127
01128 @setcookie('SMARTY_DEBUG', false);
01129 $this->debugging = false;
01130 } else {
01131
01132 $this->debugging = true;
01133 }
01134 } else {
01135 $this->debugging = (bool)($this->request_use_auto_globals ? @$_COOKIE['SMARTY_DEBUG'] : @$GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']);
01136 }
01137 }
01138
01139 if ($this->debugging) {
01140
01141 $_params = array();
01142 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
01143 $_debug_start_time = smarty_core_get_microtime($_params, $this);
01144 $this->_smarty_debug_info[] = array('type' => 'template',
01145 'filename' => $resource_name,
01146 'depth' => 0);
01147 $_included_tpls_idx = count($this->_smarty_debug_info) - 1;
01148 }
01149
01150 if (!isset($compile_id)) {
01151 $compile_id = $this->compile_id;
01152 }
01153
01154 $this->_compile_id = $compile_id;
01155 $this->_inclusion_depth = 0;
01156
01157 if ($this->caching) {
01158
01159 array_push($_cache_info, $this->_cache_info);
01160 $this->_cache_info = array();
01161 $_params = array(
01162 'tpl_file' => $resource_name,
01163 'cache_id' => $cache_id,
01164 'compile_id' => $compile_id,
01165 'results' => null
01166 );
01167 require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php');
01168 if (smarty_core_read_cache_file($_params, $this)) {
01169 $_smarty_results = $_params['results'];
01170 if (!empty($this->_cache_info['insert_tags'])) {
01171 $_params = array('plugins' => $this->_cache_info['insert_tags']);
01172 require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
01173 smarty_core_load_plugins($_params, $this);
01174 $_params = array('results' => $_smarty_results);
01175 require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php');
01176 $_smarty_results = smarty_core_process_cached_inserts($_params, $this);
01177 }
01178 if (!empty($this->_cache_info['cache_serials'])) {
01179 $_params = array('results' => $_smarty_results);
01180 require_once(SMARTY_CORE_DIR . 'core.process_compiled_include.php');
01181 $_smarty_results = smarty_core_process_compiled_include($_params, $this);
01182 }
01183
01184
01185 if ($display) {
01186 if ($this->debugging)
01187 {
01188
01189 $_params = array();
01190 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
01191 $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time;
01192 require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');
01193 $_smarty_results .= smarty_core_display_debug_console($_params, $this);
01194 }
01195 if ($this->cache_modified_check) {
01196 $_server_vars = ($this->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
01197 $_last_modified_date = @substr($_server_vars['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
01198 $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';
01199 if (@count($this->_cache_info['insert_tags']) == 0
01200 && !$this->_cache_serials
01201 && $_gmt_mtime == $_last_modified_date) {
01202 if (php_sapi_name()=='cgi')
01203 header('Status: 304 Not Modified');
01204 else
01205 header('HTTP/1.1 304 Not Modified');
01206
01207 } else {
01208 header('Last-Modified: '.$_gmt_mtime);
01209 echo $_smarty_results;
01210 }
01211 } else {
01212 echo $_smarty_results;
01213 }
01214 error_reporting($_smarty_old_error_level);
01215
01216 $this->_cache_info = array_pop($_cache_info);
01217 return true;
01218 } else {
01219 error_reporting($_smarty_old_error_level);
01220
01221 $this->_cache_info = array_pop($_cache_info);
01222 return $_smarty_results;
01223 }
01224 } else {
01225 $this->_cache_info['template'][$resource_name] = true;
01226 if ($this->cache_modified_check && $display) {
01227 header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
01228 }
01229 }
01230 }
01231
01232
01233 if (count($this->autoload_filters)) {
01234 foreach ($this->autoload_filters as $_filter_type => $_filters) {
01235 foreach ($_filters as $_filter) {
01236 $this->load_filter($_filter_type, $_filter);
01237 }
01238 }
01239 }
01240
01241 $_smarty_compile_path = $this->_get_compile_path($resource_name);
01242
01243
01244
01245 $_cache_including = $this->_cache_including;
01246 $this->_cache_including = false;
01247 if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {
01248 if ($this->_is_compiled($resource_name, $_smarty_compile_path)
01249 || $this->_compile_resource($resource_name, $_smarty_compile_path))
01250 {
01251 include($_smarty_compile_path);
01252 }
01253 } else {
01254 ob_start();
01255 if ($this->_is_compiled($resource_name, $_smarty_compile_path)
01256 || $this->_compile_resource($resource_name, $_smarty_compile_path))
01257 {
01258 include($_smarty_compile_path);
01259 }
01260 $_smarty_results = ob_get_contents();
01261 ob_end_clean();
01262
01263 foreach ((array)$this->_plugins['outputfilter'] as $_output_filter) {
01264 $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this));
01265 }
01266 }
01267
01268 if ($this->caching) {
01269 $_params = array('tpl_file' => $resource_name,
01270 'cache_id' => $cache_id,
01271 'compile_id' => $compile_id,
01272 'results' => $_smarty_results);
01273 require_once(SMARTY_CORE_DIR . 'core.write_cache_file.php');
01274 smarty_core_write_cache_file($_params, $this);
01275 require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php');
01276 $_smarty_results = smarty_core_process_cached_inserts($_params, $this);
01277
01278 if ($this->_cache_serials) {
01279
01280 $_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s'
01281 ,''
01282 ,$_smarty_results);
01283 }
01284
01285 $this->_cache_info = array_pop($_cache_info);
01286 }
01287 $this->_cache_including = $_cache_including;
01288
01289 if ($display) {
01290 if (isset($_smarty_results)) { echo $_smarty_results; }
01291 if ($this->debugging) {
01292
01293 $_params = array();
01294 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
01295 $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time);
01296 require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');
01297 echo smarty_core_display_debug_console($_params, $this);
01298 }
01299 error_reporting($_smarty_old_error_level);
01300 return;
01301 } else {
01302 error_reporting($_smarty_old_error_level);
01303 if (isset($_smarty_results)) { return $_smarty_results; }
01304 }
01305 }
01306
01314 function config_load($file, $section = null, $scope = 'global')
01315 {
01316 require_once($this->_get_plugin_filepath('function', 'config_load'));
01317 smarty_function_config_load(array('file' => $file, 'section' => $section, 'scope' => $scope), $this);
01318 }
01319
01326 function &get_registered_object($name) {
01327 if (!isset($this->_reg_objects[$name]))
01328 $this->_trigger_fatal_error("'$name' is not a registered object");
01329
01330 if (!is_object($this->_reg_objects[$name][0]))
01331 $this->_trigger_fatal_error("registered '$name' is not an object");
01332
01333 return $this->_reg_objects[$name][0];
01334 }
01335
01341 function clear_config($var = null)
01342 {
01343 if(!isset($var)) {
01344
01345 $this->_config = array(array('vars' => array(),
01346 'files' => array()));
01347 } else {
01348 unset($this->_config[0]['vars'][$var]);
01349 }
01350 }
01351
01359 function _get_plugin_filepath($type, $name)
01360 {
01361 $_params = array('type' => $type, 'name' => $name);
01362 require_once(SMARTY_CORE_DIR . 'core.assemble_plugin_filepath.php');
01363 return smarty_core_assemble_plugin_filepath($_params, $this);
01364 }
01365
01373 function _is_compiled($resource_name, $compile_path)
01374 {
01375 if (!$this->force_compile && file_exists($compile_path)) {
01376 if (!$this->compile_check) {
01377
01378 return true;
01379 } else {
01380
01381 $_params = array('resource_name' => $resource_name, 'get_source'=>false);
01382 if (!$this->_fetch_resource_info($_params)) {
01383 return false;
01384 }
01385 if ($_params['resource_timestamp'] <= filemtime($compile_path)) {
01386
01387 return true;
01388 } else {
01389
01390 return false;
01391 }
01392 }
01393 } else {
01394
01395 return false;
01396 }
01397 }
01398
01406 function _compile_resource($resource_name, $compile_path)
01407 {
01408
01409 $_params = array('resource_name' => $resource_name);
01410 if (!$this->_fetch_resource_info($_params)) {
01411 return false;
01412 }
01413
01414 $_source_content = $_params['source_content'];
01415 $_cache_include = substr($compile_path, 0, -4).'.inc';
01416
01417 if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) {
01418
01419 if ($this->_cache_include_info) {
01420 require_once(SMARTY_CORE_DIR . 'core.write_compiled_include.php');
01421 smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content, 'resource_name'=>$resource_name)), $this);
01422 }
01423
01424 $_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content);
01425 require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php');
01426 smarty_core_write_compiled_resource($_params, $this);
01427
01428 return true;
01429 } else {
01430 return false;
01431 }
01432
01433 }
01434
01443 function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null)
01444 {
01445 if (file_exists(SMARTY_DIR . $this->compiler_file)) {
01446 require_once(SMARTY_DIR . $this->compiler_file);
01447 } else {
01448
01449 require_once($this->compiler_file);
01450 }
01451
01452
01453 $smarty_compiler = new $this->compiler_class;
01454
01455 $smarty_compiler->template_dir = $this->template_dir;
01456 $smarty_compiler->compile_dir = $this->compile_dir;
01457 $smarty_compiler->plugins_dir = $this->plugins_dir;
01458 $smarty_compiler->config_dir = $this->config_dir;
01459 $smarty_compiler->force_compile = $this->force_compile;
01460 $smarty_compiler->caching = $this->caching;
01461 $smarty_compiler->php_handling = $this->php_handling;
01462 $smarty_compiler->left_delimiter = $this->left_delimiter;
01463 $smarty_compiler->right_delimiter = $this->right_delimiter;
01464 $smarty_compiler->_version = $this->_version;
01465 $smarty_compiler->security = $this->security;
01466 $smarty_compiler->secure_dir = $this->secure_dir;
01467 $smarty_compiler->security_settings = $this->security_settings;
01468 $smarty_compiler->trusted_dir = $this->trusted_dir;
01469 $smarty_compiler->use_sub_dirs = $this->use_sub_dirs;
01470 $smarty_compiler->_reg_objects = &$this->_reg_objects;
01471 $smarty_compiler->_plugins = &$this->_plugins;
01472 $smarty_compiler->_tpl_vars = &$this->_tpl_vars;
01473 $smarty_compiler->default_modifiers = $this->default_modifiers;
01474 $smarty_compiler->compile_id = $this->_compile_id;
01475 $smarty_compiler->_config = $this->_config;
01476 $smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals;
01477
01478 if (isset($cache_include_path) && isset($this->_cache_serials[$cache_include_path])) {
01479 $smarty_compiler->_cache_serial = $this->_cache_serials[$cache_include_path];
01480 }
01481 $smarty_compiler->_cache_include = $cache_include_path;
01482
01483
01484 $_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content);
01485
01486 if ($smarty_compiler->_cache_serial) {
01487 $this->_cache_include_info = array(
01488 'cache_serial'=>$smarty_compiler->_cache_serial
01489 ,'plugins_code'=>$smarty_compiler->_plugins_code
01490 ,'include_file_path' => $cache_include_path);
01491
01492 } else {
01493 $this->_cache_include_info = null;
01494
01495 }
01496
01497 return $_results;
01498 }
01499
01506 function _get_compile_path($resource_name)
01507 {
01508 return $this->_get_auto_filename($this->compile_dir, $resource_name,
01509 $this->_compile_id) . '.php';
01510 }
01511
01526 function _fetch_resource_info(&$params)
01527 {
01528 if(!isset($params['get_source'])) { $params['get_source'] = true; }
01529 if(!isset($params['quiet'])) { $params['quiet'] = false; }
01530
01531 $_return = false;
01532 $_params = array('resource_name' => $params['resource_name']) ;
01533 if (isset($params['resource_base_path']))
01534 $_params['resource_base_path'] = $params['resource_base_path'];
01535 else
01536 $_params['resource_base_path'] = $this->template_dir;
01537
01538 if ($this->_parse_resource_name($_params)) {
01539 $_resource_type = $_params['resource_type'];
01540 $_resource_name = $_params['resource_name'];
01541 switch ($_resource_type) {
01542 case 'file':
01543 if ($params['get_source']) {
01544 $params['source_content'] = $this->_read_file($_resource_name);
01545 }
01546 $params['resource_timestamp'] = filemtime($_resource_name);
01547 $_return = is_file($_resource_name);
01548 break;
01549
01550 default:
01551
01552 if ($params['get_source']) {
01553 $_source_return = isset($this->_plugins['resource'][$_resource_type]) &&
01554 call_user_func_array($this->_plugins['resource'][$_resource_type][0][0],
01555 array($_resource_name, &$params['source_content'], &$this));
01556 } else {
01557 $_source_return = true;
01558 }
01559
01560 $_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) &&
01561 call_user_func_array($this->_plugins['resource'][$_resource_type][0][1],
01562 array($_resource_name, &$params['resource_timestamp'], &$this));
01563
01564 $_return = $_source_return && $_timestamp_return;
01565 break;
01566 }
01567 }
01568
01569 if (!$_return) {
01570
01571 if (!empty($this->default_template_handler_func)) {
01572 if (!is_callable($this->default_template_handler_func)) {
01573 $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist.");
01574 } else {
01575 $_return = call_user_func_array(
01576 $this->default_template_handler_func,
01577 array($_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this));
01578 }
01579 }
01580 }
01581
01582 if (!$_return) {
01583 if (!$params['quiet']) {
01584 $this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"');
01585 }
01586 } else if ($_return && $this->security) {
01587 require_once(SMARTY_CORE_DIR . 'core.is_secure.php');
01588 if (!smarty_core_is_secure($_params, $this)) {
01589 if (!$params['quiet'])
01590 $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed');
01591 $params['source_content'] = null;
01592 $params['resource_timestamp'] = null;
01593 return false;
01594 }
01595 }
01596 return $_return;
01597 }
01598
01599
01610 function _parse_resource_name(&$params)
01611 {
01612
01613
01614 $_resource_name_parts = explode(':', $params['resource_name'], 2);
01615
01616 if (count($_resource_name_parts) == 1) {
01617
01618 $params['resource_type'] = $this->default_resource_type;
01619 $params['resource_name'] = $_resource_name_parts[0];
01620 } else {
01621 if(strlen($_resource_name_parts[0]) == 1) {
01622
01623 $params['resource_type'] = $this->default_resource_type;
01624 $params['resource_name'] = $params['resource_name'];
01625 } else {
01626 $params['resource_type'] = $_resource_name_parts[0];
01627 $params['resource_name'] = $_resource_name_parts[1];
01628 }
01629 }
01630
01631 if ($params['resource_type'] == 'file') {
01632 if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $params['resource_name'])) {
01633
01634
01635 foreach ((array)$params['resource_base_path'] as $_curr_path) {
01636 $_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name'];
01637 if (file_exists($_fullpath) && is_file($_fullpath)) {
01638 $params['resource_name'] = $_fullpath;
01639 return true;
01640 }
01641
01642 $_params = array('file_path' => $_fullpath);
01643 require_once(SMARTY_CORE_DIR . 'core.get_include_path.php');
01644 if(smarty_core_get_include_path($_params, $this)) {
01645 $params['resource_name'] = $_params['new_file_path'];
01646 return true;
01647 }
01648 }
01649 return false;
01650 } else {
01651
01652 return file_exists($params['resource_name']);
01653 }
01654 } elseif (empty($this->_plugins['resource'][$params['resource_type']])) {
01655 $_params = array('type' => $params['resource_type']);
01656 require_once(SMARTY_CORE_DIR . 'core.load_resource_plugin.php');
01657 smarty_core_load_resource_plugin($_params, $this);
01658 }
01659
01660 return true;
01661 }
01662
01663
01671 function _run_mod_handler()
01672 {
01673 $_args = func_get_args();
01674 list($_modifier_name, $_map_array) = array_splice($_args, 0, 2);
01675 list($_func_name, $_tpl_file, $_tpl_line) =
01676 $this->_plugins['modifier'][$_modifier_name];
01677
01678 $_var = $_args[0];
01679 foreach ($_var as $_key => $_val) {
01680 $_args[0] = $_val;
01681 $_var[$_key] = call_user_func_array($_func_name, $_args);
01682 }
01683 return $_var;
01684 }
01685
01692 function _dequote($string)
01693 {
01694 if (($string{0} == "'" || $string{0} == '"') &&
01695 $string{strlen($string)-1} == $string{0})
01696 return substr($string, 1, -1);
01697 else
01698 return $string;
01699 }
01700
01701
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720 function _read_file($filename)
01721 {
01722 $res = false;
01723 if (file_exists($filename)) {
01724 if (function_exists('ioncube_read_file')) {
01725 $res = ioncube_read_file($filename);
01726 if (is_int($res)) $res = false;
01727 }
01728 else if ( ($fd = @fopen($filename, 'rb')) ) {
01729 $res = ($size = filesize($filename)) ? fread($fd, $size) : '';
01730 fclose($fd);
01731 }
01732 }
01733
01734 return $res;
01735 }
01736
01747 function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null)
01748 {
01749 $_compile_dir_sep = $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';
01750 $_return = $auto_base . DIRECTORY_SEPARATOR;
01751
01752 if(isset($auto_id)) {
01753
01754 $auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id)));
01755
01756 $_return .= $auto_id . $_compile_dir_sep;
01757 }
01758
01759 if(isset($auto_source)) {
01760
01761 $_filename = urlencode(basename($auto_source));
01762 $_crc32 = sprintf('%08X', crc32($auto_source));
01763
01764
01765 $_crc32 = substr($_crc32, 0, 2) . $_compile_dir_sep .
01766 substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32;
01767 $_return .= '%%' . $_crc32 . '%%' . $_filename;
01768 }
01769
01770 return $_return;
01771 }
01772
01779 function _unlink($resource, $exp_time = null)
01780 {
01781 if(isset($exp_time)) {
01782 if(time() - @filemtime($resource) >= $exp_time) {
01783 return @unlink($resource);
01784 }
01785 } else {
01786 return @unlink($resource);
01787 }
01788 }
01789
01797 function _get_auto_id($cache_id=null, $compile_id=null) {
01798 if (isset($cache_id))
01799 return (isset($compile_id)) ? $cache_id . '|' . $compile_id : $cache_id;
01800 elseif(isset($compile_id))
01801 return $compile_id;
01802 else
01803 return null;
01804 }
01805
01816 function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null,
01817 $file = null, $line = null, $error_type = E_USER_ERROR)
01818 {
01819 if(isset($file) && isset($line)) {
01820 $info = ' ('.basename($file).", line $line)";
01821 } else {
01822 $info = '';
01823 }
01824 if (isset($tpl_line) && isset($tpl_file)) {
01825 $this->trigger_error('[in ' . $tpl_file . ' line ' . $tpl_line . "]: $error_msg$info", $error_type);
01826 } else {
01827 $this->trigger_error($error_msg . $info, $error_type);
01828 }
01829 }
01830
01831
01836 function _process_compiled_include_callback($match) {
01837 $_func = '_smarty_tplfunc_'.$match[2].'_'.$match[3];
01838 ob_start();
01839 $_func($this);
01840 $_ret = ob_get_contents();
01841 ob_end_clean();
01842 return $_ret;
01843 }
01844
01845
01853
01854
01855 function _smarty_include($params)
01856 {
01857 if ($this->debugging) {
01858 $_params = array();
01859 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
01860 $debug_start_time = smarty_core_get_microtime($_params, $this);
01861 $this->_smarty_debug_info[] = array('type' => 'template',
01862 'filename' => $params['smarty_include_tpl_file'],
01863 'depth' => ++$this->_inclusion_depth);
01864 $included_tpls_idx = count($this->_smarty_debug_info) - 1;
01865 }
01866
01867 $this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']);
01868
01869
01870
01871 array_unshift($this->_config, $this->_config[0]);
01872
01873 $_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']);
01874
01875
01876 if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path)
01877 || $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path))
01878 {
01879 include($_smarty_compile_path);
01880 }
01881
01882
01883 array_shift($this->_config);
01884
01885 $this->_inclusion_depth--;
01886
01887 if ($this->debugging) {
01888
01889 $_params = array();
01890 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
01891 $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time;
01892 }
01893
01894 if ($this->caching) {
01895 $this->_cache_info['template'][$params['smarty_include_tpl_file']] = true;
01896 }
01897 }
01898
01899
01905 function &_smarty_cache_attrs($cache_serial, $count) {
01906 $_cache_attrs =& $this->_cache_info['cache_attrs'][$cache_serial][$count];
01907
01908 if ($this->_cache_including) {
01909
01910 $_return = current($_cache_attrs);
01911 next($_cache_attrs);
01912 return $_return;
01913
01914 } else {
01915
01916 $_cache_attrs[] = array();
01917 return $_cache_attrs[count($_cache_attrs)-1];
01918
01919 }
01920
01921 }
01922
01923
01928 function _include($filename, $once=false, $params=null)
01929 {
01930 if ($once) {
01931 return include_once($filename);
01932 } else {
01933 return include($filename);
01934 }
01935 }
01936
01937
01942 function _eval($code, $params=null)
01943 {
01944 return eval($code);
01945 }
01948 }
01949
01950
01951
01952 ?>