00001 <?php 00002 00033 /* $Id: Smarty.class.php 3163 2009-06-17 14:39:24Z monte.ohrt $ */ 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 'ALLOW_SUPER_GLOBALS' => true 00241 ); 00242 00249 var $trusted_dir = array(); 00250 00256 var $left_delimiter = '{'; 00257 00263 var $right_delimiter = '}'; 00264 00272 var $request_vars_order = 'EGPCS'; 00273 00282 var $request_use_auto_globals = true; 00283 00292 var $compile_id = null; 00293 00302 var $use_sub_dirs = false; 00303 00311 var $default_modifiers = array(); 00312 00325 var $default_resource_type = 'file'; 00326 00332 var $cache_handler_func = null; 00333 00339 var $autoload_filters = array(); 00340 00348 var $config_overwrite = true; 00349 00355 var $config_booleanize = true; 00356 00363 var $config_read_hidden = false; 00364 00369 var $config_fix_newlines = true; 00378 var $default_template_handler_func = ''; 00379 00386 var $compiler_file = 'Smarty_Compiler.class.php'; 00387 00393 var $compiler_class = 'Smarty_Compiler'; 00394 00400 var $config_class = 'Config_File'; 00401 00412 var $_tpl_vars = array(); 00413 00419 var $_smarty_vars = null; 00420 00426 var $_sections = array(); 00427 00433 var $_foreach = array(); 00434 00440 var $_tag_stack = array(); 00441 00447 var $_conf_obj = null; 00448 00454 var $_config = array(array('vars' => array(), 'files' => array())); 00455 00461 var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; 00462 00468 var $_version = '2.6.26'; 00469 00475 var $_inclusion_depth = 0; 00476 00482 var $_compile_id = null; 00483 00489 var $_smarty_debug_id = 'SMARTY_DEBUG'; 00490 00496 var $_smarty_debug_info = array(); 00497 00503 var $_cache_info = array(); 00504 00510 var $_file_perms = 0644; 00511 00517 var $_dir_perms = 0771; 00518 00524 var $_reg_objects = array(); 00525 00531 var $_plugins = array( 00532 'modifier' => array(), 00533 'function' => array(), 00534 'block' => array(), 00535 'compiler' => array(), 00536 'prefilter' => array(), 00537 'postfilter' => array(), 00538 'outputfilter' => array(), 00539 'resource' => array(), 00540 'insert' => array()); 00541 00542 00548 var $_cache_serials = array(); 00549 00555 var $_cache_include = null; 00556 00563 var $_cache_including = false; 00564 00569 function Smarty() 00570 { 00571 $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] 00572 : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']); 00573 } 00574 00581 function assign($tpl_var, $value = null) 00582 { 00583 if (is_array($tpl_var)){ 00584 foreach ($tpl_var as $key => $val) { 00585 if ($key != '') { 00586 $this->_tpl_vars[$key] = $val; 00587 } 00588 } 00589 } else { 00590 if ($tpl_var != '') 00591 $this->_tpl_vars[$tpl_var] = $value; 00592 } 00593 } 00594 00601 function assign_by_ref($tpl_var, &$value) 00602 { 00603 if ($tpl_var != '') 00604 $this->_tpl_vars[$tpl_var] = &$value; 00605 } 00606 00613 function append($tpl_var, $value=null, $merge=false) 00614 { 00615 if (is_array($tpl_var)) { 00616 // $tpl_var is an array, ignore $value 00617 foreach ($tpl_var as $_key => $_val) { 00618 if ($_key != '') { 00619 if(!@is_array($this->_tpl_vars[$_key])) { 00620 settype($this->_tpl_vars[$_key],'array'); 00621 } 00622 if($merge && is_array($_val)) { 00623 foreach($_val as $_mkey => $_mval) { 00624 $this->_tpl_vars[$_key][$_mkey] = $_mval; 00625 } 00626 } else { 00627 $this->_tpl_vars[$_key][] = $_val; 00628 } 00629 } 00630 } 00631 } else { 00632 if ($tpl_var != '' && isset($value)) { 00633 if(!@is_array($this->_tpl_vars[$tpl_var])) { 00634 settype($this->_tpl_vars[$tpl_var],'array'); 00635 } 00636 if($merge && is_array($value)) { 00637 foreach($value as $_mkey => $_mval) { 00638 $this->_tpl_vars[$tpl_var][$_mkey] = $_mval; 00639 } 00640 } else { 00641 $this->_tpl_vars[$tpl_var][] = $value; 00642 } 00643 } 00644 } 00645 } 00646 00653 function append_by_ref($tpl_var, &$value, $merge=false) 00654 { 00655 if ($tpl_var != '' && isset($value)) { 00656 if(!@is_array($this->_tpl_vars[$tpl_var])) { 00657 settype($this->_tpl_vars[$tpl_var],'array'); 00658 } 00659 if ($merge && is_array($value)) { 00660 foreach($value as $_key => $_val) { 00661 $this->_tpl_vars[$tpl_var][$_key] = &$value[$_key]; 00662 } 00663 } else { 00664 $this->_tpl_vars[$tpl_var][] = &$value; 00665 } 00666 } 00667 } 00668 00669 00675 function clear_assign($tpl_var) 00676 { 00677 if (is_array($tpl_var)) 00678 foreach ($tpl_var as $curr_var) 00679 unset($this->_tpl_vars[$curr_var]); 00680 else 00681 unset($this->_tpl_vars[$tpl_var]); 00682 } 00683 00684 00691 function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null) 00692 { 00693 $this->_plugins['function'][$function] = 00694 array($function_impl, null, null, false, $cacheable, $cache_attrs); 00695 00696 } 00697 00703 function unregister_function($function) 00704 { 00705 unset($this->_plugins['function'][$function]); 00706 } 00707 00717 function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) 00718 { 00719 settype($allowed, 'array'); 00720 settype($smarty_args, 'boolean'); 00721 $this->_reg_objects[$object] = 00722 array(&$object_impl, $allowed, $smarty_args, $block_methods); 00723 } 00724 00730 function unregister_object($object) 00731 { 00732 unset($this->_reg_objects[$object]); 00733 } 00734 00735 00742 function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null) 00743 { 00744 $this->_plugins['block'][$block] = 00745 array($block_impl, null, null, false, $cacheable, $cache_attrs); 00746 } 00747 00753 function unregister_block($block) 00754 { 00755 unset($this->_plugins['block'][$block]); 00756 } 00757 00764 function register_compiler_function($function, $function_impl, $cacheable=true) 00765 { 00766 $this->_plugins['compiler'][$function] = 00767 array($function_impl, null, null, false, $cacheable); 00768 } 00769 00775 function unregister_compiler_function($function) 00776 { 00777 unset($this->_plugins['compiler'][$function]); 00778 } 00779 00786 function register_modifier($modifier, $modifier_impl) 00787 { 00788 $this->_plugins['modifier'][$modifier] = 00789 array($modifier_impl, null, null, false); 00790 } 00791 00797 function unregister_modifier($modifier) 00798 { 00799 unset($this->_plugins['modifier'][$modifier]); 00800 } 00801 00808 function register_resource($type, $functions) 00809 { 00810 if (count($functions)==4) { 00811 $this->_plugins['resource'][$type] = 00812 array($functions, false); 00813 00814 } elseif (count($functions)==5) { 00815 $this->_plugins['resource'][$type] = 00816 array(array(array(&$functions[0], $functions[1]) 00817 ,array(&$functions[0], $functions[2]) 00818 ,array(&$functions[0], $functions[3]) 00819 ,array(&$functions[0], $functions[4])) 00820 ,false); 00821 00822 } else { 00823 $this->trigger_error("malformed function-list for '$type' in register_resource"); 00824 00825 } 00826 } 00827 00833 function unregister_resource($type) 00834 { 00835 unset($this->_plugins['resource'][$type]); 00836 } 00837 00844 function register_prefilter($function) 00845 { 00846 $this->_plugins['prefilter'][$this->_get_filter_name($function)] 00847 = array($function, null, null, false); 00848 } 00849 00855 function unregister_prefilter($function) 00856 { 00857 unset($this->_plugins['prefilter'][$this->_get_filter_name($function)]); 00858 } 00859 00866 function register_postfilter($function) 00867 { 00868 $this->_plugins['postfilter'][$this->_get_filter_name($function)] 00869 = array($function, null, null, false); 00870 } 00871 00877 function unregister_postfilter($function) 00878 { 00879 unset($this->_plugins['postfilter'][$this->_get_filter_name($function)]); 00880 } 00881 00888 function register_outputfilter($function) 00889 { 00890 $this->_plugins['outputfilter'][$this->_get_filter_name($function)] 00891 = array($function, null, null, false); 00892 } 00893 00899 function unregister_outputfilter($function) 00900 { 00901 unset($this->_plugins['outputfilter'][$this->_get_filter_name($function)]); 00902 } 00903 00910 function load_filter($type, $name) 00911 { 00912 switch ($type) { 00913 case 'output': 00914 $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false))); 00915 require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); 00916 smarty_core_load_plugins($_params, $this); 00917 break; 00918 00919 case 'pre': 00920 case 'post': 00921 if (!isset($this->_plugins[$type . 'filter'][$name])) 00922 $this->_plugins[$type . 'filter'][$name] = false; 00923 break; 00924 } 00925 } 00926 00936 function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) 00937 { 00938 00939 if (!isset($compile_id)) 00940 $compile_id = $this->compile_id; 00941 00942 if (!isset($tpl_file)) 00943 $compile_id = null; 00944 00945 $_auto_id = $this->_get_auto_id($cache_id, $compile_id); 00946 00947 if (!empty($this->cache_handler_func)) { 00948 return call_user_func_array($this->cache_handler_func, 00949 array('clear', &$this, &$dummy, $tpl_file, $cache_id, $compile_id, $exp_time)); 00950 } else { 00951 $_params = array('auto_base' => $this->cache_dir, 00952 'auto_source' => $tpl_file, 00953 'auto_id' => $_auto_id, 00954 'exp_time' => $exp_time); 00955 require_once(SMARTY_CORE_DIR . 'core.rm_auto.php'); 00956 return smarty_core_rm_auto($_params, $this); 00957 } 00958 00959 } 00960 00961 00968 function clear_all_cache($exp_time = null) 00969 { 00970 return $this->clear_cache(null, null, null, $exp_time); 00971 } 00972 00973 00982 function is_cached($tpl_file, $cache_id = null, $compile_id = null) 00983 { 00984 if (!$this->caching) 00985 return false; 00986 00987 if (!isset($compile_id)) 00988 $compile_id = $this->compile_id; 00989 00990 $_params = array( 00991 'tpl_file' => $tpl_file, 00992 'cache_id' => $cache_id, 00993 'compile_id' => $compile_id 00994 ); 00995 require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php'); 00996 return smarty_core_read_cache_file($_params, $this); 00997 } 00998 00999 01004 function clear_all_assign() 01005 { 01006 $this->_tpl_vars = array(); 01007 } 01008 01019 function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) 01020 { 01021 if (!isset($compile_id)) { 01022 $compile_id = $this->compile_id; 01023 } 01024 $_params = array('auto_base' => $this->compile_dir, 01025 'auto_source' => $tpl_file, 01026 'auto_id' => $compile_id, 01027 'exp_time' => $exp_time, 01028 'extensions' => array('.inc', '.php')); 01029 require_once(SMARTY_CORE_DIR . 'core.rm_auto.php'); 01030 return smarty_core_rm_auto($_params, $this); 01031 } 01032 01039 function template_exists($tpl_file) 01040 { 01041 $_params = array('resource_name' => $tpl_file, 'quiet'=>true, 'get_source'=>false); 01042 return $this->_fetch_resource_info($_params); 01043 } 01044 01052 function &get_template_vars($name=null) 01053 { 01054 if(!isset($name)) { 01055 return $this->_tpl_vars; 01056 } elseif(isset($this->_tpl_vars[$name])) { 01057 return $this->_tpl_vars[$name]; 01058 } else { 01059 // var non-existant, return valid reference 01060 $_tmp = null; 01061 return $_tmp; 01062 } 01063 } 01064 01072 function &get_config_vars($name=null) 01073 { 01074 if(!isset($name) && is_array($this->_config[0])) { 01075 return $this->_config[0]['vars']; 01076 } else if(isset($this->_config[0]['vars'][$name])) { 01077 return $this->_config[0]['vars'][$name]; 01078 } else { 01079 // var non-existant, return valid reference 01080 $_tmp = null; 01081 return $_tmp; 01082 } 01083 } 01084 01091 function trigger_error($error_msg, $error_type = E_USER_WARNING) 01092 { 01093 trigger_error("Smarty error: $error_msg", $error_type); 01094 } 01095 01096 01104 function display($resource_name, $cache_id = null, $compile_id = null) 01105 { 01106 $this->fetch($resource_name, $cache_id, $compile_id, true); 01107 } 01108 01117 function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false) 01118 { 01119 static $_cache_info = array(); 01120 01121 $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting) 01122 ? $this->error_reporting : error_reporting() & ~E_NOTICE); 01123 01124 if (!$this->debugging && $this->debugging_ctrl == 'URL') { 01125 $_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']; 01126 if (@strstr($_query_string, $this->_smarty_debug_id)) { 01127 if (@strstr($_query_string, $this->_smarty_debug_id . '=on')) { 01128 // enable debugging for this browser session 01129 @setcookie('SMARTY_DEBUG', true); 01130 $this->debugging = true; 01131 } elseif (@strstr($_query_string, $this->_smarty_debug_id . '=off')) { 01132 // disable debugging for this browser session 01133 @setcookie('SMARTY_DEBUG', false); 01134 $this->debugging = false; 01135 } else { 01136 // enable debugging for this page 01137 $this->debugging = true; 01138 } 01139 } else { 01140 $this->debugging = (bool)($this->request_use_auto_globals ? @$_COOKIE['SMARTY_DEBUG'] : @$GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']); 01141 } 01142 } 01143 01144 if ($this->debugging) { 01145 // capture time for debugging info 01146 $_params = array(); 01147 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 01148 $_debug_start_time = smarty_core_get_microtime($_params, $this); 01149 $this->_smarty_debug_info[] = array('type' => 'template', 01150 'filename' => $resource_name, 01151 'depth' => 0); 01152 $_included_tpls_idx = count($this->_smarty_debug_info) - 1; 01153 } 01154 01155 if (!isset($compile_id)) { 01156 $compile_id = $this->compile_id; 01157 } 01158 01159 $this->_compile_id = $compile_id; 01160 $this->_inclusion_depth = 0; 01161 01162 if ($this->caching) { 01163 // save old cache_info, initialize cache_info 01164 array_push($_cache_info, $this->_cache_info); 01165 $this->_cache_info = array(); 01166 $_params = array( 01167 'tpl_file' => $resource_name, 01168 'cache_id' => $cache_id, 01169 'compile_id' => $compile_id, 01170 'results' => null 01171 ); 01172 require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php'); 01173 if (smarty_core_read_cache_file($_params, $this)) { 01174 $_smarty_results = $_params['results']; 01175 if (!empty($this->_cache_info['insert_tags'])) { 01176 $_params = array('plugins' => $this->_cache_info['insert_tags']); 01177 require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); 01178 smarty_core_load_plugins($_params, $this); 01179 $_params = array('results' => $_smarty_results); 01180 require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php'); 01181 $_smarty_results = smarty_core_process_cached_inserts($_params, $this); 01182 } 01183 if (!empty($this->_cache_info['cache_serials'])) { 01184 $_params = array('results' => $_smarty_results); 01185 require_once(SMARTY_CORE_DIR . 'core.process_compiled_include.php'); 01186 $_smarty_results = smarty_core_process_compiled_include($_params, $this); 01187 } 01188 01189 01190 if ($display) { 01191 if ($this->debugging) 01192 { 01193 // capture time for debugging info 01194 $_params = array(); 01195 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 01196 $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time; 01197 require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php'); 01198 $_smarty_results .= smarty_core_display_debug_console($_params, $this); 01199 } 01200 if ($this->cache_modified_check) { 01201 $_server_vars = ($this->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; 01202 $_last_modified_date = @substr($_server_vars['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3); 01203 $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT'; 01204 if (@count($this->_cache_info['insert_tags']) == 0 01205 && !$this->_cache_serials 01206 && $_gmt_mtime == $_last_modified_date) { 01207 if (php_sapi_name()=='cgi') 01208 header('Status: 304 Not Modified'); 01209 else 01210 header('HTTP/1.1 304 Not Modified'); 01211 01212 } else { 01213 header('Last-Modified: '.$_gmt_mtime); 01214 echo $_smarty_results; 01215 } 01216 } else { 01217 echo $_smarty_results; 01218 } 01219 error_reporting($_smarty_old_error_level); 01220 // restore initial cache_info 01221 $this->_cache_info = array_pop($_cache_info); 01222 return true; 01223 } else { 01224 error_reporting($_smarty_old_error_level); 01225 // restore initial cache_info 01226 $this->_cache_info = array_pop($_cache_info); 01227 return $_smarty_results; 01228 } 01229 } else { 01230 $this->_cache_info['template'][$resource_name] = true; 01231 if ($this->cache_modified_check && $display) { 01232 header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); 01233 } 01234 } 01235 } 01236 01237 // load filters that are marked as autoload 01238 if (count($this->autoload_filters)) { 01239 foreach ($this->autoload_filters as $_filter_type => $_filters) { 01240 foreach ($_filters as $_filter) { 01241 $this->load_filter($_filter_type, $_filter); 01242 } 01243 } 01244 } 01245 01246 $_smarty_compile_path = $this->_get_compile_path($resource_name); 01247 01248 // if we just need to display the results, don't perform output 01249 // buffering - for speed 01250 $_cache_including = $this->_cache_including; 01251 $this->_cache_including = false; 01252 if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) { 01253 if ($this->_is_compiled($resource_name, $_smarty_compile_path) 01254 || $this->_compile_resource($resource_name, $_smarty_compile_path)) 01255 { 01256 include($_smarty_compile_path); 01257 } 01258 } else { 01259 ob_start(); 01260 if ($this->_is_compiled($resource_name, $_smarty_compile_path) 01261 || $this->_compile_resource($resource_name, $_smarty_compile_path)) 01262 { 01263 include($_smarty_compile_path); 01264 } 01265 $_smarty_results = ob_get_contents(); 01266 ob_end_clean(); 01267 01268 foreach ((array)$this->_plugins['outputfilter'] as $_output_filter) { 01269 $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this)); 01270 } 01271 } 01272 01273 if ($this->caching) { 01274 $_params = array('tpl_file' => $resource_name, 01275 'cache_id' => $cache_id, 01276 'compile_id' => $compile_id, 01277 'results' => $_smarty_results); 01278 require_once(SMARTY_CORE_DIR . 'core.write_cache_file.php'); 01279 smarty_core_write_cache_file($_params, $this); 01280 require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php'); 01281 $_smarty_results = smarty_core_process_cached_inserts($_params, $this); 01282 01283 if ($this->_cache_serials) { 01284 // strip nocache-tags from output 01285 $_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s' 01286 ,'' 01287 ,$_smarty_results); 01288 } 01289 // restore initial cache_info 01290 $this->_cache_info = array_pop($_cache_info); 01291 } 01292 $this->_cache_including = $_cache_including; 01293 01294 if ($display) { 01295 if (isset($_smarty_results)) { echo $_smarty_results; } 01296 if ($this->debugging) { 01297 // capture time for debugging info 01298 $_params = array(); 01299 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 01300 $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time); 01301 require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php'); 01302 echo smarty_core_display_debug_console($_params, $this); 01303 } 01304 error_reporting($_smarty_old_error_level); 01305 return; 01306 } else { 01307 error_reporting($_smarty_old_error_level); 01308 if (isset($_smarty_results)) { return $_smarty_results; } 01309 } 01310 } 01311 01319 function config_load($file, $section = null, $scope = 'global') 01320 { 01321 require_once($this->_get_plugin_filepath('function', 'config_load')); 01322 smarty_function_config_load(array('file' => $file, 'section' => $section, 'scope' => $scope), $this); 01323 } 01324 01331 function &get_registered_object($name) { 01332 if (!isset($this->_reg_objects[$name])) 01333 $this->_trigger_fatal_error("'$name' is not a registered object"); 01334 01335 if (!is_object($this->_reg_objects[$name][0])) 01336 $this->_trigger_fatal_error("registered '$name' is not an object"); 01337 01338 return $this->_reg_objects[$name][0]; 01339 } 01340 01346 function clear_config($var = null) 01347 { 01348 if(!isset($var)) { 01349 // clear all values 01350 $this->_config = array(array('vars' => array(), 01351 'files' => array())); 01352 } else { 01353 unset($this->_config[0]['vars'][$var]); 01354 } 01355 } 01356 01364 function _get_plugin_filepath($type, $name) 01365 { 01366 $_params = array('type' => $type, 'name' => $name); 01367 require_once(SMARTY_CORE_DIR . 'core.assemble_plugin_filepath.php'); 01368 return smarty_core_assemble_plugin_filepath($_params, $this); 01369 } 01370 01378 function _is_compiled($resource_name, $compile_path) 01379 { 01380 if (!$this->force_compile && file_exists($compile_path)) { 01381 if (!$this->compile_check) { 01382 // no need to check compiled file 01383 return true; 01384 } else { 01385 // get file source and timestamp 01386 $_params = array('resource_name' => $resource_name, 'get_source'=>false); 01387 if (!$this->_fetch_resource_info($_params)) { 01388 return false; 01389 } 01390 if ($_params['resource_timestamp'] <= filemtime($compile_path)) { 01391 // template not expired, no recompile 01392 return true; 01393 } else { 01394 // compile template 01395 return false; 01396 } 01397 } 01398 } else { 01399 // compiled template does not exist, or forced compile 01400 return false; 01401 } 01402 } 01403 01411 function _compile_resource($resource_name, $compile_path) 01412 { 01413 01414 $_params = array('resource_name' => $resource_name); 01415 if (!$this->_fetch_resource_info($_params)) { 01416 return false; 01417 } 01418 01419 $_source_content = $_params['source_content']; 01420 $_cache_include = substr($compile_path, 0, -4).'.inc'; 01421 01422 if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) { 01423 // if a _cache_serial was set, we also have to write an include-file: 01424 if ($this->_cache_include_info) { 01425 require_once(SMARTY_CORE_DIR . 'core.write_compiled_include.php'); 01426 smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content, 'resource_name'=>$resource_name)), $this); 01427 } 01428 01429 $_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content); 01430 require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php'); 01431 smarty_core_write_compiled_resource($_params, $this); 01432 01433 return true; 01434 } else { 01435 return false; 01436 } 01437 01438 } 01439 01448 function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null) 01449 { 01450 if (file_exists(SMARTY_DIR . $this->compiler_file)) { 01451 require_once(SMARTY_DIR . $this->compiler_file); 01452 } else { 01453 // use include_path 01454 require_once($this->compiler_file); 01455 } 01456 01457 01458 $smarty_compiler = new $this->compiler_class; 01459 01460 $smarty_compiler->template_dir = $this->template_dir; 01461 $smarty_compiler->compile_dir = $this->compile_dir; 01462 $smarty_compiler->plugins_dir = $this->plugins_dir; 01463 $smarty_compiler->config_dir = $this->config_dir; 01464 $smarty_compiler->force_compile = $this->force_compile; 01465 $smarty_compiler->caching = $this->caching; 01466 $smarty_compiler->php_handling = $this->php_handling; 01467 $smarty_compiler->left_delimiter = $this->left_delimiter; 01468 $smarty_compiler->right_delimiter = $this->right_delimiter; 01469 $smarty_compiler->_version = $this->_version; 01470 $smarty_compiler->security = $this->security; 01471 $smarty_compiler->secure_dir = $this->secure_dir; 01472 $smarty_compiler->security_settings = $this->security_settings; 01473 $smarty_compiler->trusted_dir = $this->trusted_dir; 01474 $smarty_compiler->use_sub_dirs = $this->use_sub_dirs; 01475 $smarty_compiler->_reg_objects = &$this->_reg_objects; 01476 $smarty_compiler->_plugins = &$this->_plugins; 01477 $smarty_compiler->_tpl_vars = &$this->_tpl_vars; 01478 $smarty_compiler->default_modifiers = $this->default_modifiers; 01479 $smarty_compiler->compile_id = $this->_compile_id; 01480 $smarty_compiler->_config = $this->_config; 01481 $smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals; 01482 01483 if (isset($cache_include_path) && isset($this->_cache_serials[$cache_include_path])) { 01484 $smarty_compiler->_cache_serial = $this->_cache_serials[$cache_include_path]; 01485 } 01486 $smarty_compiler->_cache_include = $cache_include_path; 01487 01488 01489 $_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content); 01490 01491 if ($smarty_compiler->_cache_serial) { 01492 $this->_cache_include_info = array( 01493 'cache_serial'=>$smarty_compiler->_cache_serial 01494 ,'plugins_code'=>$smarty_compiler->_plugins_code 01495 ,'include_file_path' => $cache_include_path); 01496 01497 } else { 01498 $this->_cache_include_info = null; 01499 01500 } 01501 01502 return $_results; 01503 } 01504 01511 function _get_compile_path($resource_name) 01512 { 01513 return $this->_get_auto_filename($this->compile_dir, $resource_name, 01514 $this->_compile_id) . '.php'; 01515 } 01516 01531 function _fetch_resource_info(&$params) 01532 { 01533 if(!isset($params['get_source'])) { $params['get_source'] = true; } 01534 if(!isset($params['quiet'])) { $params['quiet'] = false; } 01535 01536 $_return = false; 01537 $_params = array('resource_name' => $params['resource_name']) ; 01538 if (isset($params['resource_base_path'])) 01539 $_params['resource_base_path'] = $params['resource_base_path']; 01540 else 01541 $_params['resource_base_path'] = $this->template_dir; 01542 01543 if ($this->_parse_resource_name($_params)) { 01544 $_resource_type = $_params['resource_type']; 01545 $_resource_name = $_params['resource_name']; 01546 switch ($_resource_type) { 01547 case 'file': 01548 if ($params['get_source']) { 01549 $params['source_content'] = $this->_read_file($_resource_name); 01550 } 01551 $params['resource_timestamp'] = filemtime($_resource_name); 01552 $_return = is_file($_resource_name) && is_readable($_resource_name); 01553 break; 01554 01555 default: 01556 // call resource functions to fetch the template source and timestamp 01557 if ($params['get_source']) { 01558 $_source_return = isset($this->_plugins['resource'][$_resource_type]) && 01559 call_user_func_array($this->_plugins['resource'][$_resource_type][0][0], 01560 array($_resource_name, &$params['source_content'], &$this)); 01561 } else { 01562 $_source_return = true; 01563 } 01564 01565 $_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) && 01566 call_user_func_array($this->_plugins['resource'][$_resource_type][0][1], 01567 array($_resource_name, &$params['resource_timestamp'], &$this)); 01568 01569 $_return = $_source_return && $_timestamp_return; 01570 break; 01571 } 01572 } 01573 01574 if (!$_return) { 01575 // see if we can get a template with the default template handler 01576 if (!empty($this->default_template_handler_func)) { 01577 if (!is_callable($this->default_template_handler_func)) { 01578 $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist."); 01579 } else { 01580 $_return = call_user_func_array( 01581 $this->default_template_handler_func, 01582 array($_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this)); 01583 } 01584 } 01585 } 01586 01587 if (!$_return) { 01588 if (!$params['quiet']) { 01589 $this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"'); 01590 } 01591 } else if ($_return && $this->security) { 01592 require_once(SMARTY_CORE_DIR . 'core.is_secure.php'); 01593 if (!smarty_core_is_secure($_params, $this)) { 01594 if (!$params['quiet']) 01595 $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed'); 01596 $params['source_content'] = null; 01597 $params['resource_timestamp'] = null; 01598 return false; 01599 } 01600 } 01601 return $_return; 01602 } 01603 01604 01615 function _parse_resource_name(&$params) 01616 { 01617 01618 // split tpl_path by the first colon 01619 $_resource_name_parts = explode(':', $params['resource_name'], 2); 01620 01621 if (count($_resource_name_parts) == 1) { 01622 // no resource type given 01623 $params['resource_type'] = $this->default_resource_type; 01624 $params['resource_name'] = $_resource_name_parts[0]; 01625 } else { 01626 if(strlen($_resource_name_parts[0]) == 1) { 01627 // 1 char is not resource type, but part of filepath 01628 $params['resource_type'] = $this->default_resource_type; 01629 $params['resource_name'] = $params['resource_name']; 01630 } else { 01631 $params['resource_type'] = $_resource_name_parts[0]; 01632 $params['resource_name'] = $_resource_name_parts[1]; 01633 } 01634 } 01635 01636 if ($params['resource_type'] == 'file') { 01637 if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $params['resource_name'])) { 01638 // relative pathname to $params['resource_base_path'] 01639 // use the first directory where the file is found 01640 foreach ((array)$params['resource_base_path'] as $_curr_path) { 01641 $_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name']; 01642 if (file_exists($_fullpath) && is_file($_fullpath)) { 01643 $params['resource_name'] = $_fullpath; 01644 return true; 01645 } 01646 // didn't find the file, try include_path 01647 $_params = array('file_path' => $_fullpath); 01648 require_once(SMARTY_CORE_DIR . 'core.get_include_path.php'); 01649 if(smarty_core_get_include_path($_params, $this)) { 01650 $params['resource_name'] = $_params['new_file_path']; 01651 return true; 01652 } 01653 } 01654 return false; 01655 } else { 01656 /* absolute path */ 01657 return file_exists($params['resource_name']); 01658 } 01659 } elseif (empty($this->_plugins['resource'][$params['resource_type']])) { 01660 $_params = array('type' => $params['resource_type']); 01661 require_once(SMARTY_CORE_DIR . 'core.load_resource_plugin.php'); 01662 smarty_core_load_resource_plugin($_params, $this); 01663 } 01664 01665 return true; 01666 } 01667 01668 01676 function _run_mod_handler() 01677 { 01678 $_args = func_get_args(); 01679 list($_modifier_name, $_map_array) = array_splice($_args, 0, 2); 01680 list($_func_name, $_tpl_file, $_tpl_line) = 01681 $this->_plugins['modifier'][$_modifier_name]; 01682 01683 $_var = $_args[0]; 01684 foreach ($_var as $_key => $_val) { 01685 $_args[0] = $_val; 01686 $_var[$_key] = call_user_func_array($_func_name, $_args); 01687 } 01688 return $_var; 01689 } 01690 01697 function _dequote($string) 01698 { 01699 if ((substr($string, 0, 1) == "'" || substr($string, 0, 1) == '"') && 01700 substr($string, -1) == substr($string, 0, 1)) 01701 return substr($string, 1, -1); 01702 else 01703 return $string; 01704 } 01705 01706 01713 function _read_file($filename) 01714 { 01715 if ( file_exists($filename) && is_readable($filename) && ($fd = @fopen($filename, 'rb')) ) { 01716 $contents = ''; 01717 while (!feof($fd)) { 01718 $contents .= fread($fd, 8192); 01719 } 01720 fclose($fd); 01721 return $contents; 01722 } else { 01723 return false; 01724 } 01725 } 01726 01737 function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null) 01738 { 01739 $_compile_dir_sep = $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; 01740 $_return = $auto_base . DIRECTORY_SEPARATOR; 01741 01742 if(isset($auto_id)) { 01743 // make auto_id safe for directory names 01744 $auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id))); 01745 // split into separate directories 01746 $_return .= $auto_id . $_compile_dir_sep; 01747 } 01748 01749 if(isset($auto_source)) { 01750 // make source name safe for filename 01751 $_filename = urlencode(basename($auto_source)); 01752 $_crc32 = sprintf('%08X', crc32($auto_source)); 01753 // prepend %% to avoid name conflicts with 01754 // with $params['auto_id'] names 01755 $_crc32 = substr($_crc32, 0, 2) . $_compile_dir_sep . 01756 substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32; 01757 $_return .= '%%' . $_crc32 . '%%' . $_filename; 01758 } 01759 01760 return $_return; 01761 } 01762 01769 function _unlink($resource, $exp_time = null) 01770 { 01771 if(isset($exp_time)) { 01772 if(time() - @filemtime($resource) >= $exp_time) { 01773 return @unlink($resource); 01774 } 01775 } else { 01776 return @unlink($resource); 01777 } 01778 } 01779 01787 function _get_auto_id($cache_id=null, $compile_id=null) { 01788 if (isset($cache_id)) 01789 return (isset($compile_id)) ? $cache_id . '|' . $compile_id : $cache_id; 01790 elseif(isset($compile_id)) 01791 return $compile_id; 01792 else 01793 return null; 01794 } 01795 01806 function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null, 01807 $file = null, $line = null, $error_type = E_USER_ERROR) 01808 { 01809 if(isset($file) && isset($line)) { 01810 $info = ' ('.basename($file).", line $line)"; 01811 } else { 01812 $info = ''; 01813 } 01814 if (isset($tpl_line) && isset($tpl_file)) { 01815 $this->trigger_error('[in ' . $tpl_file . ' line ' . $tpl_line . "]: $error_msg$info", $error_type); 01816 } else { 01817 $this->trigger_error($error_msg . $info, $error_type); 01818 } 01819 } 01820 01821 01826 function _process_compiled_include_callback($match) { 01827 $_func = '_smarty_tplfunc_'.$match[2].'_'.$match[3]; 01828 ob_start(); 01829 $_func($this); 01830 $_ret = ob_get_contents(); 01831 ob_end_clean(); 01832 return $_ret; 01833 } 01834 01835 01843 // $_smarty_include_tpl_file, $_smarty_include_vars 01844 01845 function _smarty_include($params) 01846 { 01847 if ($this->debugging) { 01848 $_params = array(); 01849 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 01850 $debug_start_time = smarty_core_get_microtime($_params, $this); 01851 $this->_smarty_debug_info[] = array('type' => 'template', 01852 'filename' => $params['smarty_include_tpl_file'], 01853 'depth' => ++$this->_inclusion_depth); 01854 $included_tpls_idx = count($this->_smarty_debug_info) - 1; 01855 } 01856 01857 $this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']); 01858 01859 // config vars are treated as local, so push a copy of the 01860 // current ones onto the front of the stack 01861 array_unshift($this->_config, $this->_config[0]); 01862 01863 $_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']); 01864 01865 01866 if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path) 01867 || $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path)) 01868 { 01869 include($_smarty_compile_path); 01870 } 01871 01872 // pop the local vars off the front of the stack 01873 array_shift($this->_config); 01874 01875 $this->_inclusion_depth--; 01876 01877 if ($this->debugging) { 01878 // capture time for debugging info 01879 $_params = array(); 01880 require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 01881 $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time; 01882 } 01883 01884 if ($this->caching) { 01885 $this->_cache_info['template'][$params['smarty_include_tpl_file']] = true; 01886 } 01887 } 01888 01889 01895 function &_smarty_cache_attrs($cache_serial, $count) { 01896 $_cache_attrs =& $this->_cache_info['cache_attrs'][$cache_serial][$count]; 01897 01898 if ($this->_cache_including) { 01899 /* return next set of cache_attrs */ 01900 $_return = current($_cache_attrs); 01901 next($_cache_attrs); 01902 return $_return; 01903 01904 } else { 01905 /* add a reference to a new set of cache_attrs */ 01906 $_cache_attrs[] = array(); 01907 return $_cache_attrs[count($_cache_attrs)-1]; 01908 01909 } 01910 01911 } 01912 01913 01918 function _include($filename, $once=false, $params=null) 01919 { 01920 if ($once) { 01921 return include_once($filename); 01922 } else { 01923 return include($filename); 01924 } 01925 } 01926 01927 01932 function _eval($code, $params=null) 01933 { 01934 return eval($code); 01935 } 01936 01943 function _get_filter_name($function) 01944 { 01945 if (is_array($function)) { 01946 $_class_name = (is_object($function[0]) ? 01947 get_class($function[0]) : $function[0]); 01948 return $_class_name . '_' . $function[1]; 01949 } 01950 else { 01951 return $function; 01952 } 01953 } 01954 01957 } 01958 01959 /* vim: set expandtab: */ 01960
| Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|
