--- nfo/php/libs/net.php.smarty/Smarty.class.php 2002/12/19 16:40:20 1.2 +++ nfo/php/libs/net.php.smarty/Smarty.class.php 2004/06/16 21:58:11 1.3 @@ -1,12 +1,8 @@ - * Andrei Zmievski - * - * Version: 2.3.1 - * Copyright: 2001,2002 ispi of Lincoln, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -26,28 +22,31 @@ * Smarty mailing list. Send a blank e-mail to * smarty-general-subscribe@lists.php.net * - * You may contact the authors of Smarty by e-mail at: - * monte@ispi.net - * andrei@php.net - * - * Or, write to: - * Monte Ohrt - * Director of Technology, ispi - * 237 S. 70th suite 220 - * Lincoln, NE 68510 - * - * The latest version of Smarty can be obtained from: - * http://www.phpinsider.com/ - * + * @link http://smarty.php.net/ + * @copyright 2001-2004 ispi of Lincoln, Inc. + * @author Monte Ohrt + * @author Andrei Zmievski + * @package Smarty + * @version 2.6.3 */ -// set SMARTY_DIR to absolute path to Smarty library files. -// if not defined, include_path will be used. +/* $Id: Smarty.class.php,v 1.3 2004/06/16 21:58:11 joko Exp $ */ -define('DIR_SEP', DIRECTORY_SEPARATOR); +/** + * DIR_SEP isn't used anymore, but third party apps might + */ +if(!defined('DIR_SEP')) { + define('DIR_SEP', DIRECTORY_SEPARATOR); +} + +/** + * set SMARTY_DIR to absolute path to Smarty library files. + * if not defined, include_path will be used. Sets SMARTY_DIR only if user + * application has not already defined it. + */ if (!defined('SMARTY_DIR')) { - define('SMARTY_DIR', dirname(__FILE__) . DIR_SEP); + define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); } define('SMARTY_PHP_PASSTHRU', 0); @@ -55,130 +54,475 @@ define('SMARTY_PHP_REMOVE', 2); define('SMARTY_PHP_ALLOW', 3); +/** + * @package Smarty + */ class Smarty { - -/**************************************************************************/ -/* BEGIN SMARTY CONFIGURATION SECTION */ -/* Set the following config variables to your liking. */ -/**************************************************************************/ - - // public vars - var $template_dir = 'templates'; // name of directory for templates - var $compile_dir = 'templates_c'; // name of directory for compiled templates - var $config_dir = 'configs'; // directory where config files are located - var $plugins_dir = array('plugins'); // plugin directories - - var $debugging = false; // enable debugging console true/false - var $debug_tpl = ''; // path to debug console template - // (this gets set in the constructor) - var $debugging_ctrl = 'NONE'; // Possible values: - // NONE - no debug control allowed - // URL - enable debugging when keyword - // SMARTY_DEBUG is found in $QUERY_STRING - - var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' ) - ); // variables from the GLOBALS array - // that are implicitly assigned - // to all templates - var $undefined = null; // undefined variables in $global_assign will be - // created with this value - var $autoload_filters = array(); // indicates which filters will be auto-loaded - - var $compile_check = true; // whether to check for compiling step or not: - // This is generally set to false once the - // application is entered into production and - // initially compiled. Leave set to true - // during development. true/false default true. - - var $force_compile = false; // force templates to compile every time, - // overrides cache settings. default false. - - var $caching = 0; // enable caching. can be one of 0/1/2. - // 0 = no caching - // 1 = use class cache_lifetime value - // 2 = use cache_lifetime in cache file - // default = 0. - var $cache_dir = 'cache'; // name of directory for template cache files - var $cache_lifetime = 3600; // number of seconds cached content will persist. - // 0 = always regenerate cache, - // -1 = never expires. default is one hour (3600) - var $cache_handler_func = null; // function used for cached content. this is - // an alternative to using the built-in file - // based caching. - var $cache_modified_check = false; // respect If-Modified-Since headers on cached content - - - var $default_template_handler_func = ''; // function to handle missing templates - + /**#@+ + * Smarty Configuration Section + */ + + /** + * The name of the directory where templates are located. + * + * @var string + */ + var $template_dir = 'templates'; + + /** + * The directory where compiled templates are located. + * + * @var string + */ + var $compile_dir = 'templates_c'; + + /** + * The directory where config files are located. + * + * @var string + */ + var $config_dir = 'configs'; + + /** + * An array of directories searched for plugins. + * + * @var array + */ + var $plugins_dir = array('plugins'); + + /** + * If debugging is enabled, a debug console window will display + * when the page loads (make sure your browser allows unrequested + * popup windows) + * + * @var boolean + */ + var $debugging = false; + + /** + * When set, smarty does uses this value as error_reporting-level. + * + * @var boolean + */ + var $error_reporting = null; + + /** + * This is the path to the debug console template. If not set, + * the default one will be used. + * + * @var string + */ + var $debug_tpl = ''; + + /** + * This determines if debugging is enable-able from the browser. + *
    + *
  • NONE => no debugging control allowed
  • + *
  • URL => enable debugging when SMARTY_DEBUG is found in the URL.
  • + *
+ * @link http://www.foo.dom/index.php?SMARTY_DEBUG + * @var string + */ + var $debugging_ctrl = 'NONE'; + + /** + * This tells Smarty whether to check for recompiling or not. Recompiling + * does not need to happen unless a template or config file is changed. + * Typically you enable this during development, and disable for + * production. + * + * @var boolean + */ + var $compile_check = true; + + /** + * This forces templates to compile every time. Useful for development + * or debugging. + * + * @var boolean + */ + var $force_compile = false; + + /** + * This enables template caching. + *
    + *
  • 0 = no caching
  • + *
  • 1 = use class cache_lifetime value
  • + *
  • 2 = use cache_lifetime in cache file
  • + *
+ * @var integer + */ + var $caching = 0; + + /** + * The name of the directory for cache files. + * + * @var string + */ + var $cache_dir = 'cache'; + + /** + * This is the number of seconds cached content will persist. + *
    + *
  • 0 = always regenerate cache
  • + *
  • -1 = never expires
  • + *
+ * + * @var integer + */ + var $cache_lifetime = 3600; + + /** + * Only used when $caching is enabled. If true, then If-Modified-Since headers + * are respected with cached content, and appropriate HTTP headers are sent. + * This way repeated hits to a cached page do not send the entire page to the + * client every time. + * + * @var boolean + */ + var $cache_modified_check = false; + + /** + * This determines how Smarty handles "" tags in templates. + * possible values: + *
    + *
  • SMARTY_PHP_PASSTHRU -> print tags as plain text
  • + *
  • SMARTY_PHP_QUOTE -> escape tags as entities
  • + *
  • SMARTY_PHP_REMOVE -> remove php tags
  • + *
  • SMARTY_PHP_ALLOW -> execute php tags
  • + *
+ * + * @var integer + */ var $php_handling = SMARTY_PHP_PASSTHRU; - // how smarty handles php tags in the templates - // possible values: - // SMARTY_PHP_PASSTHRU -> echo tags as is - // SMARTY_PHP_QUOTE -> escape tags as entities - // SMARTY_PHP_REMOVE -> remove php tags - // SMARTY_PHP_ALLOW -> execute php tags - // default: SMARTY_PHP_PASSTHRU - - var $security = false; // enable template security (default false) - var $secure_dir = array('templates'); // array of directories considered secure + /** + * This enables template security. When enabled, many things are restricted + * in the templates that normally would go unchecked. This is useful when + * untrusted parties are editing templates and you want a reasonable level + * of security. (no direct execution of PHP in templates for example) + * + * @var boolean + */ + var $security = false; + + /** + * This is the list of template directories that are considered secure. This + * is used only if {@link $security} is enabled. One directory per array + * element. {@link $template_dir} is in this list implicitly. + * + * @var array + */ + var $secure_dir = array(); + + /** + * These are the security settings for Smarty. They are used only when + * {@link $security} is enabled. + * + * @var array + */ var $security_settings = array( 'PHP_HANDLING' => false, 'IF_FUNCS' => array('array', 'list', 'isset', 'empty', 'count', 'sizeof', - 'in_array', 'is_array'), + 'in_array', 'is_array', + 'true','false'), 'INCLUDE_ANY' => false, 'PHP_TAGS' => false, 'MODIFIER_FUNCS' => array('count') ); - var $trusted_dir = array(); // directories where trusted templates & php scripts - // reside ($security is disabled during their - // inclusion/execution). - var $left_delimiter = '{'; // template tag delimiters. + /** + * This is an array of directories where trusted php scripts reside. + * {@link $security} is disabled during their inclusion/execution. + * + * @var array + */ + var $trusted_dir = array(); + + /** + * The left delimiter used for the template tags. + * + * @var string + */ + var $left_delimiter = '{'; + + /** + * The right delimiter used for the template tags. + * + * @var string + */ var $right_delimiter = '}'; - var $compiler_class = 'Smarty_Compiler'; // the compiler class used by - // Smarty to compile templates - - var $request_vars_order = "EGPCS"; // the order in which request variables are - // registered, similar to variables_order - // in php.ini - - var $compile_id = null; // persistent compile identifier - var $use_sub_dirs = true; // use sub dirs for cache and compiled files? - // sub directories are more efficient, but - // you can set this to false if your PHP environment - // does not allow the creation of them. - var $default_modifiers = array(); - // modifiers to implicitly append to every var - // example: array('escape:"htmlall"'); - -/**************************************************************************/ -/* END SMARTY CONFIGURATION SECTION */ -/* There should be no need to touch anything below this line. */ -/**************************************************************************/ - - // internal vars - var $_error_msg = false; // error messages. true/false - var $_tpl_vars = array(); // where assigned template vars are kept - var $_smarty_vars = null; // stores run-time $smarty.* vars - var $_sections = array(); // keeps track of sections - var $_foreach = array(); // keeps track of foreach blocks - var $_tag_stack = array(); // keeps track of tag hierarchy - var $_conf_obj = null; // configuration object - var $_config = array(); // loaded configuration settings - var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' - var $_version = '2.3.1'; // Smarty version number - var $_extract = false; // flag for custom functions - var $_inclusion_depth = 0; // current template inclusion depth - var $_compile_id = null; // for different compiled templates - var $_smarty_debug_id = 'SMARTY_DEBUG'; // text in URL to enable debug mode - var $_smarty_debug_info = array(); // debugging information for debug console - var $_cache_info = array(); // info that makes up a cache file - var $_plugins = array( // table keeping track of plugins + /** + * The order in which request variables are registered, similar to + * variables_order in php.ini E = Environment, G = GET, P = POST, + * C = Cookies, S = Server + * + * @var string + */ + var $request_vars_order = "EGPCS"; + + /** + * Indicates wether $HTTP_*_VARS[] (request_use_auto_globals=false) + * are uses as request-vars or $_*[]-vars. note: if + * request_use_auto_globals is true, then $request_vars_order has + * no effect, but the php-ini-value "gpc_order" + * + * @var boolean + */ + var $request_use_auto_globals = true; + + /** + * Set this if you want different sets of compiled files for the same + * templates. This is useful for things like different languages. + * Instead of creating separate sets of templates per language, you + * set different compile_ids like 'en' and 'de'. + * + * @var string + */ + var $compile_id = null; + + /** + * This tells Smarty whether or not to use sub dirs in the cache/ and + * templates_c/ directories. sub directories better organized, but + * may not work well with PHP safe mode enabled. + * + * @var boolean + * + */ + var $use_sub_dirs = false; + + /** + * This is a list of the modifiers to apply to all template variables. + * Put each modifier in a separate array element in the order you want + * them applied. example: array('escape:"htmlall"'); + * + * @var array + */ + var $default_modifiers = array(); + + /** + * This is the resource type to be used when not specified + * at the beginning of the resource path. examples: + * $smarty->display('file:index.tpl'); + * $smarty->display('db:index.tpl'); + * $smarty->display('index.tpl'); // will use default resource type + * {include file="file:index.tpl"} + * {include file="db:index.tpl"} + * {include file="index.tpl"} {* will use default resource type *} + * + * @var array + */ + var $default_resource_type = 'file'; + + /** + * The function used for cache file handling. If not set, built-in caching is used. + * + * @var null|string function name + */ + var $cache_handler_func = null; + + /** + * This indicates which filters are automatically loaded into Smarty. + * + * @var array array of filter names + */ + var $autoload_filters = array(); + + /**#@+ + * @var boolean + */ + /** + * This tells if config file vars of the same name overwrite each other or not. + * if disabled, same name variables are accumulated in an array. + */ + var $config_overwrite = true; + + /** + * This tells whether or not to automatically booleanize config file variables. + * If enabled, then the strings "on", "true", and "yes" are treated as boolean + * true, and "off", "false" and "no" are treated as boolean false. + */ + var $config_booleanize = true; + + /** + * This tells whether hidden sections [.foobar] are readable from the + * tempalates or not. Normally you would never allow this since that is + * the point behind hidden sections: the application can access them, but + * the templates cannot. + */ + var $config_read_hidden = false; + + /** + * This tells whether or not automatically fix newlines in config files. + * It basically converts \r (mac) or \r\n (dos) to \n + */ + var $config_fix_newlines = true; + /**#@-*/ + + /** + * If a template cannot be found, this PHP function will be executed. + * Useful for creating templates on-the-fly or other special action. + * + * @var string function name + */ + var $default_template_handler_func = ''; + + /** + * The file that contains the compiler class. This can a full + * pathname, or relative to the php_include path. + * + * @var string + */ + var $compiler_file = 'Smarty_Compiler.class.php'; + + /** + * The class used for compiling templates. + * + * @var string + */ + var $compiler_class = 'Smarty_Compiler'; + + /** + * The class used to load config vars. + * + * @var string + */ + var $config_class = 'Config_File'; + +/**#@+ + * END Smarty Configuration Section + * There should be no need to touch anything below this line. + * @access private + */ + /** + * where assigned template vars are kept + * + * @var array + */ + var $_tpl_vars = array(); + + /** + * stores run-time $smarty.* vars + * + * @var null|array + */ + var $_smarty_vars = null; + + /** + * keeps track of sections + * + * @var array + */ + var $_sections = array(); + + /** + * keeps track of foreach blocks + * + * @var array + */ + var $_foreach = array(); + + /** + * keeps track of tag hierarchy + * + * @var array + */ + var $_tag_stack = array(); + + /** + * configuration object + * + * @var Config_file + */ + var $_conf_obj = null; + + /** + * loaded configuration settings + * + * @var array + */ + var $_config = array(array('vars' => array(), 'files' => array())); + + /** + * md5 checksum of the string 'Smarty' + * + * @var string + */ + var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; + + /** + * Smarty version number + * + * @var string + */ + var $_version = '2.6.3'; + + /** + * current template inclusion depth + * + * @var integer + */ + var $_inclusion_depth = 0; + + /** + * for different compiled templates + * + * @var string + */ + var $_compile_id = null; + + /** + * text in URL to enable debug mode + * + * @var string + */ + var $_smarty_debug_id = 'SMARTY_DEBUG'; + + /** + * debugging information for debug console + * + * @var array + */ + var $_smarty_debug_info = array(); + + /** + * info that makes up a cache file + * + * @var array + */ + var $_cache_info = array(); + + /** + * default file permissions + * + * @var integer + */ + var $_file_perms = 0644; + + /** + * default dir permissions + * + * @var integer + */ + var $_dir_perms = 0771; + + /** + * registered objects + * + * @var array + */ + var $_reg_objects = array(); + + /** + * table keeping track of plugins + * + * @var array + */ + var $_plugins = array( 'modifier' => array(), 'function' => array(), 'block' => array(), @@ -190,113 +534,138 @@ 'insert' => array()); -/*======================================================================*\ - Function: Smarty - Purpose: Constructor -\*======================================================================*/ + /** + * cache serials + * + * @var array + */ + var $_cache_serials = array(); + + /** + * name of optional cache include file + * + * @var string + */ + var $_cache_include = null; + + /** + * indicate if the current code is used in a compiled + * include + * + * @var string + */ + var $_cache_including = false; + + /**#@-*/ + /** + * The class constructor. + */ function Smarty() { - foreach ($this->global_assign as $key => $var_name) { - if (is_array($var_name)) { - foreach ($var_name as $var) { - if (isset($GLOBALS[$key][$var])) { - $this->assign($var, $GLOBALS[$key][$var]); - } else { - $this->assign($var, $this->undefined); - } - } - } else { - if (isset($GLOBALS[$var_name])) { - $this->assign($var_name, $GLOBALS[$var_name]); - } else { - $this->assign($var_name, $this->undefined); - } - } - } - - if(empty($this->debug_tpl)) { - // set path to debug template from SMARTY_DIR - $this->debug_tpl = 'file:'.SMARTY_DIR.'debug.tpl'; - } + $this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] + : @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']); } - -/*======================================================================*\ - Function: assign() - Purpose: assigns values to template variables -\*======================================================================*/ - function assign($tpl_var, $value = NULL) + /** + * assigns values to template variables + * + * @param array|string $tpl_var the template variable name(s) + * @param mixed $value the value to assign + */ + function assign($tpl_var, $value = null) { if (is_array($tpl_var)){ foreach ($tpl_var as $key => $val) { - if ($key != '' && isset($val)) { + if ($key != '') { $this->_tpl_vars[$key] = $val; } } } else { - if ($tpl_var != '' && isset($value)) + if ($tpl_var != '') $this->_tpl_vars[$tpl_var] = $value; } - $this->_extract = true; } -/*======================================================================*\ - Function: assign_by_ref() - Purpose: assigns values to template variables by reference -\*======================================================================*/ + /** + * assigns values to template variables by reference + * + * @param string $tpl_var the template variable name + * @param mixed $value the referenced value to assign + */ function assign_by_ref($tpl_var, &$value) { - if ($tpl_var != '' && isset($value)) + if ($tpl_var != '') $this->_tpl_vars[$tpl_var] = &$value; - $this->_extract = true; } - -/*======================================================================*\ - Function: append - Purpose: appends values to template variables -\*======================================================================*/ - function append($tpl_var, $value = NULL) + + /** + * appends values to template variables + * + * @param array|string $tpl_var the template variable name(s) + * @param mixed $value the value to append + */ + function append($tpl_var, $value=null, $merge=false) { if (is_array($tpl_var)) { - foreach ($tpl_var as $key => $val) { - if ($key != '') { - if(!@is_array($this->_tpl_vars[$key])) { - settype($this->_tpl_vars[$key],'array'); - } - $this->_tpl_vars[$key][] = $val; + // $tpl_var is an array, ignore $value + foreach ($tpl_var as $_key => $_val) { + if ($_key != '') { + if(!@is_array($this->_tpl_vars[$_key])) { + settype($this->_tpl_vars[$_key],'array'); + } + if($merge && is_array($_val)) { + foreach($_val as $_mkey => $_mval) { + $this->_tpl_vars[$_key][$_mkey] = $_mval; + } + } else { + $this->_tpl_vars[$_key][] = $_val; + } } } } else { if ($tpl_var != '' && isset($value)) { - if(!@is_array($this->_tpl_vars[$tpl_var])) { - settype($this->_tpl_vars[$tpl_var],'array'); - } - $this->_tpl_vars[$tpl_var][] = $value; + if(!@is_array($this->_tpl_vars[$tpl_var])) { + settype($this->_tpl_vars[$tpl_var],'array'); + } + if($merge && is_array($value)) { + foreach($value as $_mkey => $_mval) { + $this->_tpl_vars[$tpl_var][$_mkey] = $_mval; + } + } else { + $this->_tpl_vars[$tpl_var][] = $value; + } } } - $this->_extract = true; } -/*======================================================================*\ - Function: append_by_ref - Purpose: appends values to template variables by reference -\*======================================================================*/ - function append_by_ref($tpl_var, &$value) + /** + * appends values to template variables by reference + * + * @param string $tpl_var the template variable name + * @param mixed $value the referenced value to append + */ + function append_by_ref($tpl_var, &$value, $merge=false) { if ($tpl_var != '' && isset($value)) { - if(!@is_array($this->_tpl_vars[$tpl_var])) { - settype($this->_tpl_vars[$tpl_var],'array'); - } - $this->_tpl_vars[$tpl_var][] = &$value; + if(!@is_array($this->_tpl_vars[$tpl_var])) { + settype($this->_tpl_vars[$tpl_var],'array'); + } + if ($merge && is_array($value)) { + foreach($value as $_key => $_val) { + $this->_tpl_vars[$tpl_var][$_key] = &$value[$_key]; + } + } else { + $this->_tpl_vars[$tpl_var][] = &$value; + } } - $this->_extract = true; } -/*======================================================================*\ - Function: clear_assign() - Purpose: clear the given assigned template variable. -\*======================================================================*/ + /** + * clear the given assigned template variable. + * + * @param string $tpl_var the template variable to clear + */ function clear_assign($tpl_var) { if (is_array($tpl_var)) @@ -307,170 +676,241 @@ } -/*======================================================================*\ - Function: register_function - Purpose: Registers custom function to be used in templates -\*======================================================================*/ - function register_function($function, $function_impl) + /** + * Registers custom function to be used in templates + * + * @param string $function the name of the template function + * @param string $function_impl the name of the PHP function to register + */ + function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null) { $this->_plugins['function'][$function] = - array($function_impl, null, null, false); + array($function_impl, null, null, false, $cacheable, $cache_attrs); + } -/*======================================================================*\ - Function: unregister_function - Purpose: Unregisters custom function -\*======================================================================*/ + /** + * Unregisters custom function + * + * @param string $function name of template function + */ function unregister_function($function) { unset($this->_plugins['function'][$function]); } -/*======================================================================*\ - Function: register_block - Purpose: Registers block function to be used in templates -\*======================================================================*/ - function register_block($block, $block_impl) + /** + * Registers object to be used in templates + * + * @param string $object name of template object + * @param object &$object_impl the referenced PHP object to register + * @param null|array $allowed list of allowed methods (empty = all) + * @param boolean $smarty_args smarty argument format, else traditional + * @param null|array $block_functs list of methods that are block format + */ + function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) + { + settype($allowed, 'array'); + settype($smarty_args, 'boolean'); + $this->_reg_objects[$object] = + array(&$object_impl, $allowed, $smarty_args, $block_methods); + } + + /** + * Unregisters object + * + * @param string $object name of template object + */ + function unregister_object($object) + { + unset($this->_reg_objects[$object]); + } + + + /** + * Registers block function to be used in templates + * + * @param string $block name of template block + * @param string $block_impl PHP function to register + */ + function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null) { $this->_plugins['block'][$block] = - array($block_impl, null, null, false); + array($block_impl, null, null, false, $cacheable, $cache_attrs); } -/*======================================================================*\ - Function: unregister_block - Purpose: Unregisters block function -\*======================================================================*/ + /** + * Unregisters block function + * + * @param string $block name of template function + */ function unregister_block($block) { unset($this->_plugins['block'][$block]); } -/*======================================================================*\ - Function: register_compiler_function - Purpose: Registers compiler function -\*======================================================================*/ - function register_compiler_function($function, $function_impl) + /** + * Registers compiler function + * + * @param string $function name of template function + * @param string $function_impl name of PHP function to register + */ + function register_compiler_function($function, $function_impl, $cacheable=true) { $this->_plugins['compiler'][$function] = - array($function_impl, null, null, false); + array($function_impl, null, null, false, $cacheable); } -/*======================================================================*\ - Function: unregister_compiler_function - Purpose: Unregisters compiler function -\*======================================================================*/ + /** + * Unregisters compiler function + * + * @param string $function name of template function + */ function unregister_compiler_function($function) { unset($this->_plugins['compiler'][$function]); } -/*======================================================================*\ - Function: register_modifier - Purpose: Registers modifier to be used in templates -\*======================================================================*/ + /** + * Registers modifier to be used in templates + * + * @param string $modifier name of template modifier + * @param string $modifier_impl name of PHP function to register + */ function register_modifier($modifier, $modifier_impl) { $this->_plugins['modifier'][$modifier] = array($modifier_impl, null, null, false); } -/*======================================================================*\ - Function: unregister_modifier - Purpose: Unregisters modifier -\*======================================================================*/ + /** + * Unregisters modifier + * + * @param string $modifier name of template modifier + */ function unregister_modifier($modifier) { unset($this->_plugins['modifier'][$modifier]); } -/*======================================================================*\ - Function: register_resource - Purpose: Registers a resource to fetch a template -\*======================================================================*/ + /** + * Registers a resource to fetch a template + * + * @param string $type name of resource + * @param array $functions array of functions to handle resource + */ function register_resource($type, $functions) { - $this->_plugins['resource'][$type] = - array((array)$functions, false); + if (count($functions)==4) { + $this->_plugins['resource'][$type] = + array($functions, false); + + } elseif (count($functions)==5) { + $this->_plugins['resource'][$type] = + array(array(array(&$functions[0], $functions[1]) + ,array(&$functions[0], $functions[2]) + ,array(&$functions[0], $functions[3]) + ,array(&$functions[0], $functions[4])) + ,false); + + } else { + $this->trigger_error("malformed function-list for '$type' in register_resource"); + + } } -/*======================================================================*\ - Function: unregister_resource - Purpose: Unregisters a resource -\*======================================================================*/ + /** + * Unregisters a resource + * + * @param string $type name of resource + */ function unregister_resource($type) { unset($this->_plugins['resource'][$type]); } -/*======================================================================*\ - Function: register_prefilter - Purpose: Registers a prefilter function to apply - to a template before compiling -\*======================================================================*/ + /** + * Registers a prefilter function to apply + * to a template before compiling + * + * @param string $function name of PHP function to register + */ function register_prefilter($function) { - $this->_plugins['prefilter'][$function] + $_name = (is_array($function)) ? $function[1] : $function; + $this->_plugins['prefilter'][$_name] = array($function, null, null, false); } -/*======================================================================*\ - Function: unregister_prefilter - Purpose: Unregisters a prefilter function -\*======================================================================*/ + /** + * Unregisters a prefilter function + * + * @param string $function name of PHP function + */ function unregister_prefilter($function) { unset($this->_plugins['prefilter'][$function]); } -/*======================================================================*\ - Function: register_postfilter - Purpose: Registers a postfilter function to apply - to a compiled template after compilation -\*======================================================================*/ + /** + * Registers a postfilter function to apply + * to a compiled template after compilation + * + * @param string $function name of PHP function to register + */ function register_postfilter($function) { - $this->_plugins['postfilter'][$function] + $_name = (is_array($function)) ? $function[1] : $function; + $this->_plugins['postfilter'][$_name] = array($function, null, null, false); } -/*======================================================================*\ - Function: unregister_postfilter - Purpose: Unregisters a postfilter function -\*======================================================================*/ + /** + * Unregisters a postfilter function + * + * @param string $function name of PHP function + */ function unregister_postfilter($function) { unset($this->_plugins['postfilter'][$function]); } -/*======================================================================*\ - Function: register_outputfilter - Purpose: Registers an output filter function to apply - to a template output -\*======================================================================*/ + /** + * Registers an output filter function to apply + * to a template output + * + * @param string $function name of PHP function + */ function register_outputfilter($function) { - $this->_plugins['outputfilter'][$function] + $_name = (is_array($function)) ? $function[1] : $function; + $this->_plugins['outputfilter'][$_name] = array($function, null, null, false); } -/*======================================================================*\ - Function: unregister_outputfilter - Purpose: Unregisters an outputfilter function -\*======================================================================*/ + /** + * Unregisters an outputfilter function + * + * @param string $function name of PHP function + */ function unregister_outputfilter($function) { unset($this->_plugins['outputfilter'][$function]); } -/*======================================================================*\ - Function: load_filter() - Purpose: load a filter of specified type and name -\*======================================================================*/ + /** + * load a filter of specified type and name + * + * @param string $type filter type + * @param string $name filter name + */ function load_filter($type, $name) { switch ($type) { case 'output': - $this->_load_plugins(array(array($type . 'filter', $name, null, null, false))); + $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false))); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php'); + smarty_core_load_plugins($_params, $this); break; case 'pre': @@ -481,52 +921,61 @@ } } -/*======================================================================*\ - Function: clear_cache() - Purpose: clear cached content for the given template and cache id -\*======================================================================*/ + /** + * clear cached content for the given template and cache id + * + * @param string $tpl_file name of template file + * @param string $cache_id name of cache_id + * @param string $compile_id name of compile_id + * @param string $exp_time expiration time + * @return boolean + */ function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) { - + if (!isset($compile_id)) $compile_id = $this->compile_id; - if (isset($cache_id)) - $auto_id = (isset($compile_id)) ? $cache_id . '|' . $compile_id : $cache_id; - elseif(isset($compile_id)) - $auto_id = $compile_id; - else - $auto_id = null; + if (!isset($tpl_file)) + $compile_id = null; + + $_auto_id = $this->_get_auto_id($cache_id, $compile_id); if (!empty($this->cache_handler_func)) { - $funcname = $this->cache_handler_func; - return $funcname('clear', $this, $dummy, $tpl_file, $cache_id, $compile_id); + return call_user_func_array($this->cache_handler_func, + array('clear', &$this, &$dummy, $tpl_file, $cache_id, $compile_id, $exp_time)); } else { - return $this->_rm_auto($this->cache_dir, $tpl_file, $auto_id, $exp_time); + $_params = array('auto_base' => $this->cache_dir, + 'auto_source' => $tpl_file, + 'auto_id' => $_auto_id, + 'exp_time' => $exp_time); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rm_auto.php'); + return smarty_core_rm_auto($_params, $this); } - + } -/*======================================================================*\ - Function: clear_all_cache() - Purpose: clear the entire contents of cache (all templates) -\*======================================================================*/ + /** + * clear the entire contents of cache (all templates) + * + * @param string $exp_time expire time + * @return boolean results of {@link smarty_core_rm_auto()} + */ function clear_all_cache($exp_time = null) { - if (!empty($this->cache_handler_func)) { - $funcname = $this->cache_handler_func; - return $funcname('clear', $this, $dummy); - } else { - return $this->_rm_auto($this->cache_dir,null,null,$exp_time); - } + return $this->clear_cache(null, null, null, $exp_time); } -/*======================================================================*\ - Function: is_cached() - Purpose: test to see if valid cache exists for this template -\*======================================================================*/ + /** + * test to see if valid cache exists for this template + * + * @param string $tpl_file name of template file + * @param string $cache_id + * @param string $compile_id + * @return string|false results of {@link _read_cache_file()} + */ function is_cached($tpl_file, $cache_id = null, $compile_id = null) { if (!$this->caching) @@ -535,182 +984,313 @@ if (!isset($compile_id)) $compile_id = $this->compile_id; - return $this->_read_cache_file($tpl_file, $cache_id, $compile_id, $results); + $_params = array( + 'tpl_file' => $tpl_file, + 'cache_id' => $cache_id, + 'compile_id' => $compile_id + ); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.read_cache_file.php'); + return smarty_core_read_cache_file($_params, $this); } -/*======================================================================*\ - Function: clear_all_assign() - Purpose: clear all the assigned template variables. -\*======================================================================*/ + /** + * clear all the assigned template variables. + * + */ function clear_all_assign() { $this->_tpl_vars = array(); } -/*======================================================================*\ - Function: clear_compiled_tpl() - Purpose: clears compiled version of specified template resource, - or all compiled template files if one is not specified. - This function is for advanced use only, not normally needed. -\*======================================================================*/ + /** + * clears compiled version of specified template resource, + * or all compiled template files if one is not specified. + * This function is for advanced use only, not normally needed. + * + * @param string $tpl_file + * @param string $compile_id + * @param string $exp_time + * @return boolean results of {@link smarty_core_rm_auto()} + */ function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) { - if (!isset($compile_id)) + if (!isset($compile_id)) { $compile_id = $this->compile_id; - return $this->_rm_auto($this->compile_dir, $tpl_file, $compile_id, $exp_time); + } + $_params = array('auto_base' => $this->compile_dir, + 'auto_source' => $tpl_file, + 'auto_id' => $compile_id, + 'exp_time' => $exp_time, + 'extensions' => array('.inc', '.php')); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rm_auto.php'); + return smarty_core_rm_auto($_params, $this); } - /*======================================================================*\ - Function: template_exists() - Purpose: Checks whether requested template exists. -\*======================================================================*/ + /** + * Checks whether requested template exists. + * + * @param string $tpl_file + * @return boolean + */ function template_exists($tpl_file) { - return $this->_fetch_template_info($tpl_file, $source, $timestamp, true, true); + $_params = array('resource_name' => $tpl_file, 'quiet'=>true, 'get_source'=>false); + return $this->_fetch_resource_info($_params); } -/*======================================================================*\ - Function: get_template_vars - Purpose: Returns an array containing template variables -\*======================================================================*/ - function &get_template_vars() + /** + * Returns an array containing template variables + * + * @param string $name + * @param string $type + * @return array + */ + function &get_template_vars($name=null) { - return $this->_tpl_vars; + if(!isset($name)) { + return $this->_tpl_vars; + } + if(isset($this->_tpl_vars[$name])) { + return $this->_tpl_vars[$name]; + } } + /** + * Returns an array containing config variables + * + * @param string $name + * @param string $type + * @return array + */ + function &get_config_vars($name=null) + { + if(!isset($name) && is_array($this->_config[0])) { + return $this->_config[0]['vars']; + } else if(isset($this->_config[0]['vars'][$name])) { + return $this->_config[0]['vars'][$name]; + } + } -/*======================================================================*\ - Function: trigger_error - Purpose: trigger Smarty error -\*======================================================================*/ + /** + * trigger Smarty error + * + * @param string $error_msg + * @param integer $error_type + */ function trigger_error($error_msg, $error_type = E_USER_WARNING) { trigger_error("Smarty error: $error_msg", $error_type); } -/*======================================================================*\ - Function: display() - Purpose: executes & displays the template results -\*======================================================================*/ - function display($tpl_file, $cache_id = null, $compile_id = null) - { - $this->fetch($tpl_file, $cache_id, $compile_id, true); - } - -/*======================================================================*\ - Function: fetch() - Purpose: executes & returns or displays the template results -\*======================================================================*/ - function fetch($_smarty_tpl_file, $_smarty_cache_id = null, $_smarty_compile_id = null, $_smarty_display = false) - { - $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(error_reporting() & ~E_NOTICE); - - if (!$this->debugging && $this->debugging_ctrl == 'URL' - && strstr($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'], $this->_smarty_debug_id)) { - $this->debugging = true; + /** + * executes & displays the template results + * + * @param string $resource_name + * @param string $cache_id + * @param string $compile_id + */ + function display($resource_name, $cache_id = null, $compile_id = null) + { + $this->fetch($resource_name, $cache_id, $compile_id, true); + } + + /** + * executes & returns or displays the template results + * + * @param string $resource_name + * @param string $cache_id + * @param string $compile_id + * @param boolean $display + */ + function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false) + { + static $_cache_info = array(); + + $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting) + ? $this->error_reporting : error_reporting() & ~E_NOTICE); + + if (!$this->debugging && $this->debugging_ctrl == 'URL') { + $_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']; + if (@strstr($_query_string, $this->_smarty_debug_id)) { + if (@strstr($_query_string, $this->_smarty_debug_id . '=on')) { + // enable debugging for this browser session + @setcookie('SMARTY_DEBUG', true); + $this->debugging = true; + } elseif (@strstr($_query_string, $this->_smarty_debug_id . '=off')) { + // disable debugging for this browser session + @setcookie('SMARTY_DEBUG', false); + $this->debugging = false; + } else { + // enable debugging for this page + $this->debugging = true; + } + } else { + $_cookie_var = $this->request_use_auto_globals ? $_COOKIE['SMARTY_DEBUG'] : $GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']; + $this->debugging = $_cookie_var ? true : false; + } } if ($this->debugging) { // capture time for debugging info - $debug_start_time = $this->_get_microtime(); + $_params = array(); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + $_debug_start_time = smarty_core_get_microtime($_params, $this); $this->_smarty_debug_info[] = array('type' => 'template', - 'filename' => $_smarty_tpl_file, + 'filename' => $resource_name, 'depth' => 0); - $included_tpls_idx = count($this->_smarty_debug_info) - 1; + $_included_tpls_idx = count($this->_smarty_debug_info) - 1; } - if (!isset($_smarty_compile_id)) - $_smarty_compile_id = $this->compile_id; - - $this->_compile_id = $_smarty_compile_id; + if (!isset($compile_id)) { + $compile_id = $this->compile_id; + } + $this->_compile_id = $compile_id; $this->_inclusion_depth = 0; if ($this->caching) { - if ($this->_read_cache_file($_smarty_tpl_file, $_smarty_cache_id, $_smarty_compile_id, $_smarty_results)) { + // save old cache_info, initialize cache_info + array_push($_cache_info, $this->_cache_info); + $this->_cache_info = array(); + $_params = array( + 'tpl_file' => $resource_name, + 'cache_id' => $cache_id, + 'compile_id' => $compile_id, + 'results' => null + ); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.read_cache_file.php'); + if (smarty_core_read_cache_file($_params, $this)) { + $_smarty_results = $_params['results']; if (@count($this->_cache_info['insert_tags'])) { - $this->_load_plugins($this->_cache_info['insert_tags']); - $_smarty_results = $this->_process_cached_inserts($_smarty_results); + $_params = array('plugins' => $this->_cache_info['insert_tags']); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php'); + smarty_core_load_plugins($_params, $this); + $_params = array('results' => $_smarty_results); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.process_cached_inserts.php'); + $_smarty_results = smarty_core_process_cached_inserts($_params, $this); + } + if (@count($this->_cache_info['cache_serials'])) { + $_params = array('results' => $_smarty_results); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.process_compiled_include.php'); + $_smarty_results = smarty_core_process_compiled_include($_params, $this); } - if ($_smarty_display) { + + + if ($display) { if ($this->debugging) { // capture time for debugging info - $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time; - - $_smarty_results .= $this->_generate_debug_output(); + $_params = array(); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time; + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.display_debug_console.php'); + $_smarty_results .= smarty_core_display_debug_console($_params, $this); } if ($this->cache_modified_check) { - $last_modified_date = substr($GLOBALS['HTTP_SERVER_VARS']['HTTP_IF_MODIFIED_SINCE'], 0, strpos($GLOBALS['HTTP_SERVER_VARS']['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3); - $gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT'; + $_server_vars = ($this->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; + $_last_modified_date = @substr($_server_vars['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3); + $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT'; if (@count($this->_cache_info['insert_tags']) == 0 - && $gmt_mtime == $last_modified_date) { - header("HTTP/1.1 304 Not Modified"); + && !$this->_cache_serials + && $_gmt_mtime == $_last_modified_date) { + if (php_sapi_name()=='cgi') + header("Status: 304 Not Modified"); + else + header("HTTP/1.1 304 Not Modified"); + } else { - header("Last-Modified: ".$gmt_mtime); - echo $_smarty_results; + header("Last-Modified: ".$_gmt_mtime); + echo $_smarty_results; } } else { - echo $_smarty_results; - } + echo $_smarty_results; + } error_reporting($_smarty_old_error_level); - return true; + // restore initial cache_info + $this->_cache_info = array_pop($_cache_info); + return true; } else { error_reporting($_smarty_old_error_level); + // restore initial cache_info + $this->_cache_info = array_pop($_cache_info); return $_smarty_results; } } else { - $this->_cache_info = array(); - $this->_cache_info['template'][] = $_smarty_tpl_file; + $this->_cache_info['template'][$resource_name] = true; + if ($this->cache_modified_check && $display) { + header("Last-Modified: ".gmdate('D, d M Y H:i:s', time()).' GMT'); + } } } - extract($this->_tpl_vars); - - /* Initialize config array. */ - $this->_config = array(array('vars' => array(), - 'files' => array())); - - if (count($this->autoload_filters)) - $this->_autoload_filters(); + // load filters that are marked as autoload + if (count($this->autoload_filters)) { + foreach ($this->autoload_filters as $_filter_type => $_filters) { + foreach ($_filters as $_filter) { + $this->load_filter($_filter_type, $_filter); + } + } + } - $_smarty_compile_path = $this->_get_compile_path($_smarty_tpl_file); + $_smarty_compile_path = $this->_get_compile_path($resource_name); // if we just need to display the results, don't perform output // buffering - for speed - if ($_smarty_display && !$this->caching && count($this->_plugins['outputfilter']) == 0) { - if ($this->_process_template($_smarty_tpl_file, $_smarty_compile_path)) + $_cache_including = $this->_cache_including; + $this->_cache_including = false; + if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) { + if ($this->_is_compiled($resource_name, $_smarty_compile_path) + || $this->_compile_resource($resource_name, $_smarty_compile_path)) { include($_smarty_compile_path); } } else { ob_start(); - if ($this->_process_template($_smarty_tpl_file, $_smarty_compile_path)) + if ($this->_is_compiled($resource_name, $_smarty_compile_path) + || $this->_compile_resource($resource_name, $_smarty_compile_path)) { include($_smarty_compile_path); } $_smarty_results = ob_get_contents(); ob_end_clean(); - foreach ((array)$this->_plugins['outputfilter'] as $output_filter) { - $_smarty_results = $output_filter[0]($_smarty_results, $this); + foreach ((array)$this->_plugins['outputfilter'] as $_output_filter) { + $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this)); } } if ($this->caching) { - $this->_write_cache_file($_smarty_tpl_file, $_smarty_cache_id, $_smarty_compile_id, $_smarty_results); - $_smarty_results = $this->_process_cached_inserts($_smarty_results); + $_params = array('tpl_file' => $resource_name, + 'cache_id' => $cache_id, + 'compile_id' => $compile_id, + 'results' => $_smarty_results); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_cache_file.php'); + smarty_core_write_cache_file($_params, $this); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.process_cached_inserts.php'); + $_smarty_results = smarty_core_process_cached_inserts($_params, $this); + + if ($this->_cache_serials) { + // strip nocache-tags from output + $_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s' + ,'' + ,$_smarty_results); + } + // restore initial cache_info + $this->_cache_info = array_pop($_cache_info); } + $this->_cache_including = $_cache_including; - if ($_smarty_display) { + if ($display) { if (isset($_smarty_results)) { echo $_smarty_results; } if ($this->debugging) { // capture time for debugging info - $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = ($this->_get_microtime() - $debug_start_time); - - echo $this->_generate_debug_output(); + $_params = array(); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.display_debug_console.php'); + echo smarty_core_display_debug_console($_params, $this); } error_reporting($_smarty_old_error_level); return; @@ -720,369 +1300,152 @@ } } - -/*======================================================================*\ - Function: _assign_smarty_interface - Purpose: assign $smarty interface variable -\*======================================================================*/ - function _assign_smarty_interface() - { - if ($this->_smarty_vars !== null) - return; - - $globals_map = array('g' => 'HTTP_GET_VARS', - 'p' => 'HTTP_POST_VARS', - 'c' => 'HTTP_COOKIE_VARS', - 's' => 'HTTP_SERVER_VARS', - 'e' => 'HTTP_ENV_VARS'); - - $smarty = array('request' => array()); - - foreach (preg_split('!!', strtolower($this->request_vars_order)) as $c) { - if (isset($globals_map[$c])) { - $smarty['request'] = array_merge($smarty['request'], $GLOBALS[$globals_map[$c]]); - } - } - $smarty['request'] = @array_merge($smarty['request'], $GLOBALS['HTTP_SESSION_VARS']); - - $this->_smarty_vars = $smarty; - } - - -/*======================================================================*\ - Function: _generate_debug_output() - Purpose: generate debug output -\*======================================================================*/ - -function _generate_debug_output() { - // we must force compile the debug template in case the environment - // changed between separate applications. - $_ldelim_orig = $this->left_delimiter; - $_rdelim_orig = $this->right_delimiter; - - $this->left_delimiter = '{'; - $this->right_delimiter = '}'; - - $_force_compile_orig = $this->force_compile; - $this->force_compile = true; - $_compile_id_orig = $this->_compile_id; - $this->_compile_id = null; - - $compile_path = $this->_get_compile_path($this->debug_tpl); - if ($this->_process_template($this->debug_tpl, $compile_path)) - { - ob_start(); - include($compile_path); - $results = ob_get_contents(); - ob_end_clean(); - } - $this->force_compile = $_force_compile_orig; - $this->_compile_id = $_compile_id_orig; - - $this->left_delimiter = $_ldelim_orig; - $this->right_delimiter = $_rdelim_orig; - - return $results; -} - -/*======================================================================*\ - Function: _is_trusted() - Purpose: determines if a resource is trusted or not -\*======================================================================*/ - function _is_trusted($resource_type, $resource_name) - { - $_smarty_trusted = false; - if ($resource_type == 'file') { - if (!empty($this->trusted_dir)) { - // see if template file is within a trusted directory. If so, - // disable security during the execution of the template. - - if (!empty($this->trusted_dir)) { - foreach ((array)$this->trusted_dir as $curr_dir) { - if (!empty($curr_dir) && is_readable ($curr_dir)) { - if (substr(realpath($resource_name),0, strlen(realpath($curr_dir))) == realpath($curr_dir)) { - $_smarty_trusted = true; - break; - } - } - } - } - } - } else { - // resource is not on local file system - $resource_func = $this->_plugins['resource'][$resource_type][0][3]; - $_smarty_trusted = $resource_func($resource_name, $this); + /** + * load configuration values + * + * @param string $file + * @param string $section + * @param string $scope + */ + function config_load($file, $section = null, $scope = 'global') + { + require_once($this->_get_plugin_filepath('function', 'config_load')); + smarty_function_config_load(array('file' => $file, 'section' => $section, 'scope' => $scope), $this); + } + + /** + * return a reference to a registered object + * + * @param string $name + * @return object + */ + function &get_registered_object($name) { + if (!isset($this->_reg_objects[$name])) + $this->_trigger_fatal_error("'$name' is not a registered object"); + + if (!is_object($this->_reg_objects[$name][0])) + $this->_trigger_fatal_error("registered '$name' is not an object"); + + return $this->_reg_objects[$name][0]; + } + + /** + * clear configuration values + * + * @param string $var + */ + function clear_config($var = null) + { + if(!isset($var)) { + // clear all values + $this->_config = array(array('vars' => array(), + 'files' => array())); + } else { + unset($this->_config[0]['vars'][$var]); } - - return $_smarty_trusted; } -/*======================================================================*\ - Function: _is_secure() - Purpose: determines if a resource is secure or not. -\*======================================================================*/ - function _is_secure($resource_type, $resource_name) + /** + * get filepath of requested plugin + * + * @param string $type + * @param string $name + * @return string|false + */ + function _get_plugin_filepath($type, $name) { - if (!$this->security || $this->security_settings['INCLUDE_ANY']) { - return true; - } - - $_smarty_secure = false; - if ($resource_type == 'file') { - if (!empty($this->secure_dir)) { - foreach ((array)$this->secure_dir as $curr_dir) { - if ( !empty($curr_dir) && is_readable ($curr_dir)) { - if (substr(realpath($resource_name),0, strlen(realpath($curr_dir))) == realpath($curr_dir)) { - $_smarty_secure = true; - break; - } - } - } - } - } else { - // resource is not on local file system - $resource_func = $this->_plugins['resource'][$resource_type][0][2]; - $_smarty_secure = $resource_func($resource_name, $_smarty_secure, $this); - } - - return $_smarty_secure; - } - - -/*======================================================================*\ - Function: _get_php_resource - Purpose: Retrieves PHP script resource -\*======================================================================*/ - function _get_php_resource($resource, &$resource_type, &$php_resource) - { - $this->_parse_file_path($this->trusted_dir, $resource, $resource_type, $resource_name); - - /* - * Find out if the resource exists. - */ - - if ($resource_type == 'file') { - $readable = false; - if(@is_file($resource_name)) { - $readable = true; - } else { - // test for file in include_path - if($this->_get_include_path($resource_name,$_include_path)) { - $readable = true; - } - } - } else if ($resource_type != 'file') { - $readable = true; - $resource_func = $this->_plugins['resource'][$resource_type][0][0]; - $readable = $resource_func($resource_name, $template_source, $this); - } - - /* - * Set the error function, depending on which class calls us. - */ - if (method_exists($this, '_syntax_error')) { - $error_func = '_syntax_error'; - } else { - $error_func = 'trigger_error'; - } - - if ($readable) { - if ($this->security) { - if (!$this->_is_trusted($resource_type, $resource_name)) { - $this->$error_func("(secure mode) '$resource_type:$resource_name' is not trusted"); - return false; - } - } - } else { - $this->$error_func("'$resource_type: $resource_name' is not readable"); - return false; - } - - if ($resource_type == 'file') { - $php_resource = $resource_name; - } else { - $php_resource = $template_source; - } - - return true; + $_params = array('type' => $type, 'name' => $name); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.assemble_plugin_filepath.php'); + return smarty_core_assemble_plugin_filepath($_params, $this); } - -/*======================================================================*\ - Function: _process_template() - Purpose: -\*======================================================================*/ - function _process_template($tpl_file, $compile_path) + /** + * test if resource needs compiling + * + * @param string $resource_name + * @param string $compile_path + * @return boolean + */ + function _is_compiled($resource_name, $compile_path) { - // test if template needs to be compiled if (!$this->force_compile && file_exists($compile_path)) { if (!$this->compile_check) { - // no need to check if the template needs recompiled + // no need to check compiled file return true; } else { - // get template source and timestamp - if (!$this->_fetch_template_info($tpl_file, $template_source, - $template_timestamp)) { + // get file source and timestamp + $_params = array('resource_name' => $resource_name, 'get_source'=>false); + if (!$this->_fetch_resource_info($_params)) { return false; } - if ($template_timestamp <= filemtime($compile_path)) { + if ($_params['resource_timestamp'] <= filemtime($compile_path)) { // template not expired, no recompile return true; } else { // compile template - $this->_compile_template($tpl_file, $template_source, $template_compiled); - $this->_write_compiled_template($compile_path, $template_compiled, $template_timestamp); - return true; + return false; } } } else { // compiled template does not exist, or forced compile - if (!$this->_fetch_template_info($tpl_file, $template_source, - $template_timestamp)) { - return false; - } - $this->_compile_template($tpl_file, $template_source, $template_compiled); - $this->_write_compiled_template($compile_path, $template_compiled, $template_timestamp); - return true; + return false; } } -/*======================================================================*\ - Function: _get_compile_path - Purpose: Get the compile path for this template file -\*======================================================================*/ - function _get_compile_path($tpl_file) - { - return $this->_get_auto_filename($this->compile_dir, $tpl_file, - $this->_compile_id); - } - -/*======================================================================*\ - Function: _write_compiled_template - Purpose: -\*======================================================================*/ - function _write_compiled_template($compile_path, $template_compiled, $template_timestamp) - { - // we save everything into $compile_dir - $this->_write_file($compile_path, $template_compiled, true); - touch($compile_path, $template_timestamp); - return true; - } - -/*======================================================================*\ - Function: _parse_file_path - Purpose: parse out the type and name from the template resource -\*======================================================================*/ - function _parse_file_path($file_base_path, $file_path, &$resource_type, &$resource_name) + /** + * compile the template + * + * @param string $resource_name + * @param string $compile_path + * @return boolean + */ + function _compile_resource($resource_name, $compile_path) { - // split tpl_path by the first colon - $_file_path_parts = explode(':', $file_path, 2); - if (count($_file_path_parts) == 1) { - // no resource type, treat as type "file" - $resource_type = 'file'; - $resource_name = $_file_path_parts[0]; - } else { - $resource_type = $_file_path_parts[0]; - $resource_name = $_file_path_parts[1]; - if ($resource_type != 'file') { - $this->_load_resource_plugin($resource_type); - } + $_params = array('resource_name' => $resource_name); + if (!$this->_fetch_resource_info($_params)) { + return false; } - if ($resource_type == 'file') { - if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $resource_name)) { - // relative pathname to $file_base_path - // use the first directory where the file is found - foreach ((array)$file_base_path as $_curr_path) { - $_fullpath = $_curr_path . DIR_SEP . $resource_name; - if (@is_file($_fullpath)) { - $resource_name = $_fullpath; - return true; - } - // didn't find the file, try include_path - if($this->_get_include_path($_fullpath, $_include_path)) { - $resource_name = $_include_path; - return true; - } - } - return false; + $_source_content = $_params['source_content']; + $_resource_timestamp = $_params['resource_timestamp']; + $_cache_include = substr($compile_path, 0, -4).'.inc'; + + if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) { + // if a _cache_serial was set, we also have to write an include-file: + if ($this->_cache_include_info) { + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_include.php'); + smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content)), $this); } - } - // resource type != file - return true; - } - - -/*======================================================================*\ - Function: _fetch_template_info() - Purpose: fetch the template info. Gets timestamp, and source - if get_source is true -\*======================================================================*/ - function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source = true, $quiet = false) - { - $_return = false; - if ($this->_parse_file_path($this->template_dir, $tpl_path, $resource_type, $resource_name)) { - switch ($resource_type) { - case 'file': - if ($get_source) { - $template_source = $this->_read_file($resource_name); - } - $template_timestamp = filemtime($resource_name); - $_return = true; - break; + $_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content, 'resource_timestamp' => $_resource_timestamp); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_resource.php'); + smarty_core_write_compiled_resource($_params, $this); - default: - // call resource functions to fetch the template source and timestamp - if ($get_source) { - $resource_func = $this->_plugins['resource'][$resource_type][0][0]; - $_source_return = $resource_func($resource_name, $template_source, $this); - } else { - $_source_return = true; - } - $resource_func = $this->_plugins['resource'][$resource_type][0][1]; - $_timestamp_return = $resource_func($resource_name, $template_timestamp, $this); - $_return = $_source_return && $_timestamp_return; - break; - } - } - - if (!$_return) { - // see if we can get a template with the default template handler - if (!empty($this->default_template_handler_func)) { - if (!function_exists($this->default_template_handler_func)) { - $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist."); - $_return = false; - } - $funcname = $this->default_template_handler_func; - $_return = $funcname($resource_type, $resource_name, $template_source, $template_timestamp, $this); - } - } - - if (!$_return) { - if (!$quiet) { - $this->trigger_error("unable to read template resource: \"$tpl_path\""); - } - } else if ($_return && $this->security && !$this->_is_secure($resource_type, $resource_name)) { - if (!$quiet) - $this->trigger_error("(secure mode) accessing \"$tpl_path\" is not allowed"); - $template_source = null; - $template_timestamp = null; + return true; + } else { return false; } - return $_return; } - -/*======================================================================*\ - Function: _compile_template() - Purpose: called to compile the templates -\*======================================================================*/ - function _compile_template($tpl_file, $template_source, &$template_compiled) + /** + * compile the given source + * + * @param string $resource_name + * @param string $source_content + * @param string $compiled_content + * @return boolean + */ + function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null) { - require_once SMARTY_DIR.$this->compiler_class . '.class.php'; + if (file_exists(SMARTY_DIR . $this->compiler_file)) { + require_once(SMARTY_DIR . $this->compiler_file); + } else { + // use include_path + require_once($this->compiler_file); + } + $smarty_compiler = new $this->compiler_class; @@ -1100,288 +1463,227 @@ $smarty_compiler->secure_dir = $this->secure_dir; $smarty_compiler->security_settings = $this->security_settings; $smarty_compiler->trusted_dir = $this->trusted_dir; + $smarty_compiler->use_sub_dirs = $this->use_sub_dirs; + $smarty_compiler->_reg_objects = &$this->_reg_objects; $smarty_compiler->_plugins = &$this->_plugins; $smarty_compiler->_tpl_vars = &$this->_tpl_vars; $smarty_compiler->default_modifiers = $this->default_modifiers; + $smarty_compiler->compile_id = $this->_compile_id; + $smarty_compiler->_config = $this->_config; + $smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals; - if ($smarty_compiler->_compile_file($tpl_file, $template_source, $template_compiled)) - return true; - else { - $this->trigger_error($smarty_compiler->_error_msg); - return false; - } - } - -/*======================================================================*\ - Function: _smarty_include() - Purpose: called for included templates -\*======================================================================*/ - function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars) - { - if ($this->debugging) { - $debug_start_time = $this->_get_microtime(); - $this->_smarty_debug_info[] = array('type' => 'template', - 'filename' => $_smarty_include_tpl_file, - 'depth' => ++$this->_inclusion_depth); - $included_tpls_idx = count($this->_smarty_debug_info) - 1; - } + $smarty_compiler->_cache_serial = null; + $smarty_compiler->_cache_include = $cache_include_path; - $this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars); - extract($this->_tpl_vars); - array_unshift($this->_config, $this->_config[0]); - $_smarty_compile_path = $this->_get_compile_path($_smarty_include_tpl_file); + $_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content); - if ($this->_process_template($_smarty_include_tpl_file, $_smarty_compile_path)) { - include($_smarty_compile_path); - } + if ($smarty_compiler->_cache_serial) { + $this->_cache_include_info = array( + 'cache_serial'=>$smarty_compiler->_cache_serial + ,'plugins_code'=>$smarty_compiler->_plugins_code + ,'include_file_path' => $cache_include_path); - array_shift($this->_config); - $this->_inclusion_depth--; + } else { + $this->_cache_include_info = null; - if ($this->debugging) { - // capture time for debugging info - $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time; } - if ($this->caching) { - $this->_cache_info['template'][] = $_smarty_include_tpl_file; - } + return $_results; } -/*======================================================================*\ - Function: _smarty_include_php() - Purpose: called for included templates -\*======================================================================*/ - function _smarty_include_php($_smarty_include_php_file, $_smarty_assign, $_smarty_once) + /** + * Get the compile path for this resource + * + * @param string $resource_name + * @return string results of {@link _get_auto_filename()} + */ + function _get_compile_path($resource_name) { - $this->_get_php_resource($_smarty_include_php_file, $_smarty_resource_type, - $_smarty_php_resource); - - if (!empty($_smarty_assign)) { - ob_start(); - if ($_smarty_resource_type == 'file') { - if($_smarty_once) { - include_once($_smarty_php_resource); - } else { - include($_smarty_php_resource); - } - } else { - eval($_smarty_php_resource); - } - $this->assign($_smarty_assign, ob_get_contents()); - ob_end_clean(); - } else { - if ($_smarty_resource_type == 'file') { - if($_smarty_once) { - include_once($_smarty_php_resource); - } else { - include($_smarty_php_resource); - } - } else { - eval($_smarty_php_resource); - } - } + return $this->_get_auto_filename($this->compile_dir, $resource_name, + $this->_compile_id) . '.php'; } -/*======================================================================*\ - Function: _config_load - Purpose: load configuration values -\*======================================================================*/ - function _config_load($file, $section, $scope) - { - if(@is_dir($this->config_dir)) { - $_config_dir = $this->config_dir; - } else { - // config_dir not found, try include_path - $this->_get_include_path($this->config_dir,$_config_dir); - } - - if ($this->_conf_obj === null) { - /* Prepare the configuration object. */ - if (!class_exists('Config_File')) - require_once SMARTY_DIR.'Config_File.class.php'; - $this->_conf_obj = new Config_File($_config_dir); - $this->_conf_obj->read_hidden = false; - } else { - $this->_conf_obj->set_path($_config_dir); - } + /** + * fetch the template info. Gets timestamp, and source + * if get_source is true + * + * sets $source_content to the source of the template, and + * $resource_timestamp to its time stamp + * @param string $resource_name + * @param string $source_content + * @param integer $resource_timestamp + * @param boolean $get_source + * @param boolean $quiet + * @return boolean + */ - if ($this->debugging) { - $debug_start_time = $this->_get_microtime(); - } - - if ($this->caching) { - $this->_cache_info['config'][] = $file; - } - - if (!isset($this->_config[0]['files'][$file])) { - $this->_config[0]['vars'] = array_merge($this->_config[0]['vars'], $this->_conf_obj->get($file)); - $this->_config[0]['files'][$file] = true; - } - if ($scope == 'parent') { - if (count($this->_config) > 0 && !isset($this->_config[1]['files'][$file])) { - $this->_config[1]['vars'] = array_merge($this->_config[1]['vars'], $this->_conf_obj->get($file)); - $this->_config[1]['files'][$file] = true; - } - } else if ($scope == 'global') - for ($i = 1, $for_max = count($this->_config); $i < $for_max; $i++) { - if (!isset($this->_config[$i]['files'][$file])) { - $this->_config[$i]['vars'] = array_merge($this->_config[$i]['vars'], $this->_conf_obj->get($file)); - $this->_config[$i]['files'][$file] = true; - } - } + function _fetch_resource_info(&$params) + { + if(!isset($params['get_source'])) { $params['get_source'] = true; } + if(!isset($params['quiet'])) { $params['quiet'] = false; } - if (!empty($section)) { - $this->_config[0]['vars'] = array_merge($this->_config[0]['vars'], $this->_conf_obj->get($file, $section)); - if ($scope == 'parent') { - if (count($this->_config) > 0) - $this->_config[1]['vars'] = array_merge($this->_config[1]['vars'], $this->_conf_obj->get($file, $section)); - } else if ($scope == 'global') - for ($i = 1, $for_max = count($this->_config); $i < $for_max; $i++) - $this->_config[$i]['vars'] = array_merge($this->_config[$i]['vars'], $this->_conf_obj->get($file, $section)); - } + $_return = false; + $_params = array('resource_name' => $params['resource_name']) ; + if (isset($params['resource_base_path'])) + $_params['resource_base_path'] = $params['resource_base_path']; + else + $_params['resource_base_path'] = $this->template_dir; - if ($this->debugging) { - $debug_start_time = $this->_get_microtime(); - $this->_smarty_debug_info[] = array('type' => 'config', - 'filename' => $file.' ['.$section.'] '.$scope, - 'depth' => $this->_inclusion_depth, - 'exec_time' => $this->_get_microtime() - $debug_start_time); - } - } + if ($this->_parse_resource_name($_params)) { + $_resource_type = $_params['resource_type']; + $_resource_name = $_params['resource_name']; + switch ($_resource_type) { + case 'file': + if ($params['get_source']) { + $params['source_content'] = $this->_read_file($_resource_name); + } + $params['resource_timestamp'] = filemtime($_resource_name); + $_return = is_file($_resource_name); + break; + default: + // call resource functions to fetch the template source and timestamp + if ($params['get_source']) { + $_source_return = isset($this->_plugins['resource'][$_resource_type]) && + call_user_func_array($this->_plugins['resource'][$_resource_type][0][0], + array($_resource_name, &$params['source_content'], &$this)); + } else { + $_source_return = true; + } -/*======================================================================*\ - Function: _process_cached_inserts - Purpose: Replace cached inserts with the actual results -\*======================================================================*/ - function _process_cached_inserts($results) - { - preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis', - $results, $match); - list($cached_inserts, $insert_args) = $match; + $_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) && + call_user_func_array($this->_plugins['resource'][$_resource_type][0][1], + array($_resource_name, &$params['resource_timestamp'], &$this)); - for ($i = 0, $for_max = count($cached_inserts); $i < $for_max; $i++) { - if ($this->debugging) { - $debug_start_time = $this->_get_microtime(); + $_return = $_source_return && $_timestamp_return; + break; } + } - $args = unserialize($insert_args[$i]); - - $name = $args['name']; - unset($args['name']); - - if (isset($args['script'])) { - if (!$this->_get_php_resource($this->_dequote($args['script']), $resource_type, $php_resource)) { - return false; - } - - if ($resource_type == 'file') { - include_once($php_resource); + if (!$_return) { + // see if we can get a template with the default template handler + if (!empty($this->default_template_handler_func)) { + if (!is_callable($this->default_template_handler_func)) { + $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist."); } else { - eval($php_resource); + $_return = call_user_func_array( + $this->default_template_handler_func, + array($_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this)); } - unset($args['script']); } + } - $function_name = $this->_plugins['insert'][$name][0]; - $replace = $function_name($args, $this); - - $results = str_replace($cached_inserts[$i], $replace, $results); - if ($this->debugging) { - $this->_smarty_debug_info[] = array('type' => 'insert', - 'filename' => 'insert_'.$name, - 'depth' => $this->_inclusion_depth, - 'exec_time' => $this->_get_microtime() - $debug_start_time); + if (!$_return) { + if (!$params['quiet']) { + $this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"'); + } + } else if ($_return && $this->security) { + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_secure.php'); + if (!smarty_core_is_secure($_params, $this)) { + if (!$params['quiet']) + $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed'); + $params['source_content'] = null; + $params['resource_timestamp'] = null; + return false; } } - - return $results; + return $_return; } -/*======================================================================*\ - Function: _run_insert_handler - Purpose: Handle insert tags -\*======================================================================*/ -function _run_insert_handler($args) -{ - if ($this->debugging) { - $debug_start_time = $this->_get_microtime(); - } + /** + * parse out the type and name from the resource + * + * @param string $resource_base_path + * @param string $resource_name + * @param string $resource_type + * @param string $resource_name + * @return boolean + */ - if ($this->caching) { - $arg_string = serialize($args); - $name = $args['name']; - if (!isset($this->_cache_info['insert_tags'][$name])) { - $this->_cache_info['insert_tags'][$name] = array('insert', - $name, - $this->_plugins['insert'][$name][1], - $this->_plugins['insert'][$name][2], - !empty($args['script']) ? true : false); - } - return $this->_smarty_md5."{insert_cache $arg_string}".$this->_smarty_md5; - } else { - if (isset($args['script'])) { - if (!$this->_get_php_resource($this->_dequote($args['script']), $resource_type, $php_resource)) { - return false; - } + function _parse_resource_name(&$params) + { - if ($resource_type == 'file') { - include_once($php_resource); + // split tpl_path by the first colon + $_resource_name_parts = explode(':', $params['resource_name'], 2); + + if (count($_resource_name_parts) == 1) { + // no resource type given + $params['resource_type'] = $this->default_resource_type; + $params['resource_name'] = $_resource_name_parts[0]; + } else { + if(strlen($_resource_name_parts[0]) == 1) { + // 1 char is not resource type, but part of filepath + $params['resource_type'] = $this->default_resource_type; + $params['resource_name'] = $params['resource_name']; } else { - eval($php_resource); + $params['resource_type'] = $_resource_name_parts[0]; + $params['resource_name'] = $_resource_name_parts[1]; } - unset($args['script']); } - $function_name = $this->_plugins['insert'][$args['name']][0]; - $content = $function_name($args, $this); - if ($this->debugging) { - $this->_smarty_debug_info[] = array('type' => 'insert', - 'filename' => 'insert_'.$args['name'], - 'depth' => $this->_inclusion_depth, - 'exec_time' => $this->_get_microtime() - $debug_start_time); + if ($params['resource_type'] == 'file') { + if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $params['resource_name'])) { + // relative pathname to $params['resource_base_path'] + // use the first directory where the file is found + foreach ((array)$params['resource_base_path'] as $_curr_path) { + $_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name']; + if (file_exists($_fullpath) && is_file($_fullpath)) { + $params['resource_name'] = $_fullpath; + return true; + } + // didn't find the file, try include_path + $_params = array('file_path' => $_fullpath); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php'); + if(smarty_core_get_include_path($_params, $this)) { + $params['resource_name'] = $_params['new_file_path']; + return true; + } + } + return false; + } else { + /* absolute path */ + return file_exists($params['resource_name']); + } + } elseif (empty($this->_plugins['resource'][$params['resource_type']])) { + $_params = array('type' => $params['resource_type']); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_resource_plugin.php'); + smarty_core_load_resource_plugin($_params, $this); } - if (!empty($args["assign"])) { - $this->assign($args["assign"], $content); - } else { - return $content; - } + return true; } -} -/*======================================================================*\ - Function: _run_mod_handler - Purpose: Handle modifiers -\*======================================================================*/ + /** + * Handle modifiers + * + * @param string|null $modifier_name + * @param array|null $map_array + * @return string result of modifiers + */ function _run_mod_handler() { - $args = func_get_args(); - list($modifier_name, $map_array) = array_splice($args, 0, 2); - list($func_name, $tpl_file, $tpl_line) = - $this->_plugins['modifier'][$modifier_name]; - $var = $args[0]; - - if ($map_array && is_array($var)) { - foreach ($var as $key => $val) { - $args[0] = $val; - $var[$key] = call_user_func_array($func_name, $args); - } - return $var; - } else { - return call_user_func_array($func_name, $args); - } - } - - -/*======================================================================*\ - Function: _dequote - Purpose: Remove starting and ending quotes from the string -\*======================================================================*/ + $_args = func_get_args(); + list($_modifier_name, $_map_array) = array_splice($_args, 0, 2); + list($_func_name, $_tpl_file, $_tpl_line) = + $this->_plugins['modifier'][$_modifier_name]; + + $_var = $_args[0]; + foreach ($_var as $_key => $_val) { + $_args[0] = $_val; + $_var[$_key] = call_user_func_array($_func_name, $_args); + } + return $_var; + } + + /** + * Remove starting and ending quotes from the string + * + * @param string $string + * @return string + */ function _dequote($string) { if (($string{0} == "'" || $string{0} == '"') && @@ -1392,661 +1694,246 @@ } -/*======================================================================*\ - Function: _read_file() - Purpose: read in a file from line $start for $lines. - read the entire file if $start and $lines are null. -\*======================================================================*/ - function _read_file($filename, $start=null, $lines=null) + /** + * read in a file from line $start for $lines. + * read the entire file if $start and $lines are null. + * + * @param string $filename + * @param integer $start + * @param integer $lines + * @return string + */ + function _read_file($filename) { - if (!($fd = @fopen($filename, 'r'))) { - return false; - } - flock($fd, LOCK_SH); - if ($start == null && $lines == null) { - // read the entire file - $contents = fread($fd, filesize($filename)); + if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) { + $contents = ($size = filesize($filename)) ? fread($fd, $size) : ''; + fclose($fd); + return $contents; } else { - if ( $start > 1 ) { - // skip the first lines before $start - for ($loop=1; $loop < $start; $loop++) { - fgets($fd, 65536); - } - } - if ( $lines == null ) { - // read the rest of the file - while (!feof($fd)) { - $contents .= fgets($fd, 65536); - } - } else { - // read up to $lines lines - for ($loop=0; $loop < $lines; $loop++) { - $contents .= fgets($fd, 65536); - if (feof($fd)) { - break; - } - } - } + return false; } - fclose($fd); - return $contents; } -/*======================================================================*\ - Function: _write_file() - Purpose: write out a file -\*======================================================================*/ - function _write_file($filename, $contents, $create_dirs = false) + /** + * get a concrete filename for automagically created content + * + * @param string $auto_base + * @param string $auto_source + * @param string $auto_id + * @return string + * @staticvar string|null + * @staticvar string|null + */ + function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null) { - if ($create_dirs) - $this->_create_dir_structure(dirname($filename)); + $_compile_dir_sep = $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; - if (!($fd = @fopen($filename, 'w'))) { - $this->trigger_error("problem writing '$filename.'"); - return false; - } - - // flock doesn't seem to work on several windows platforms (98, NT4, NT5, ?), - // so we'll not use it at all in windows. - - if ( strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' || (flock($fd, LOCK_EX)) ) { - fwrite( $fd, $contents ); - fclose($fd); - chmod($filename, 0644); + if(@is_dir($auto_base)) { + $_return = $auto_base . DIRECTORY_SEPARATOR; + } else { + // auto_base not found, try include_path + $_params = array('file_path' => $auto_base); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php'); + smarty_core_get_include_path($_params, $this); + $_return = isset($_params['new_file_path']) ? $_params['new_file_path'] . DIRECTORY_SEPARATOR : null; + } + + if(isset($auto_id)) { + // make auto_id safe for directory names + $auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id))); + // split into separate directories + $_return .= $auto_id . $_compile_dir_sep; + } + + if(isset($auto_source)) { + // make source name safe for filename + $_filename = urlencode(basename($auto_source)); + $_crc32 = sprintf("%08X", crc32($auto_source)); + // prepend %% to avoid name conflicts with + // with $params['auto_id'] names + $_crc32 = substr($_crc32, 0, 2) . $_compile_dir_sep . + substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32; + $_return .= '%%' . $_crc32 . '%%' . $_filename; } - return true; + return $_return; } -/*======================================================================*\ - Function: _get_auto_filename - Purpose: get a concrete filename for automagically created content -\*======================================================================*/ - function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null) - { - static $_dir_sep = null; - static $_dir_sep_enc = null; - - if(!isset($_dir_sep)) { - $_dir_sep_enc = urlencode(DIR_SEP); - if($this->use_sub_dirs) { - $_dir_sep = DIR_SEP; - } else { - $_dir_sep = '^'; - } - } - - if(@is_dir($auto_base)) { - $res = $auto_base . DIR_SEP; - } else { - // auto_base not found, try include_path - $this->_get_include_path($auto_base,$_include_path); - $res = $_include_path . DIR_SEP; - } - - if(isset($auto_id)) { - // make auto_id safe for directory names - $auto_id = str_replace('%7C','|',(urlencode($auto_id))); - // split into separate directories - $auto_id = str_replace('|', $_dir_sep, $auto_id); - $res .= $auto_id . $_dir_sep; - } - - if(isset($auto_source)) { - // make source name safe for filename - if($this->use_sub_dirs) { - $_filename = urlencode(basename($auto_source)); - $_crc32 = crc32($auto_source) . $_dir_sep; - // prepend %% to avoid name conflicts with - // with $auto_id names - $_crc32 = '%%' . substr($_crc32,0,3) . $_dir_sep . '%%' . $_crc32; - $res .= $_crc32 . $_filename . '.php'; - } else { - $res .= str_replace($_dir_sep_enc,'^',urlencode($auto_source)); - } - } - - return $res; - } - -/*======================================================================*\ - Function: _rm_auto - Purpose: delete an automagically created file by name and id -\*======================================================================*/ - function _rm_auto($auto_base, $auto_source = null, $auto_id = null, $exp_time = null) - { - if (!@is_dir($auto_base)) - return false; - - if(!isset($auto_id) && !isset($auto_source)) { - $res = $this->_rmdir($auto_base, 0, $exp_time); - } else { - $tname = $this->_get_auto_filename($auto_base, $auto_source, $auto_id); - - if(isset($auto_source)) { - $res = $this->_unlink($tname); - } elseif ($this->use_sub_dirs) { - $res = $this->_rmdir($tname, 1, $exp_time); - } else { - // remove matching file names - $handle = opendir($auto_base); - while ($filename = readdir($handle)) { - if($filename == '.' || $filename == '..') { - continue; - } elseif (substr($auto_base . DIR_SEP . $filename,0,strlen($tname)) == $tname) { - $this->_unlink($auto_base . DIR_SEP . $filename, $exp_time); - } - } - } - } - - return $res; - } - -/*======================================================================*\ - Function: _rmdir - Purpose: delete a dir recursively (level=0 -> keep root) - WARNING: no security whatsoever!! -\*======================================================================*/ - function _rmdir($dirname, $level = 1, $exp_time = null) - { - - if($handle = @opendir($dirname)) { - - while ($entry = readdir($handle)) { - if ($entry != '.' && $entry != '..') { - if (@is_dir($dirname . DIR_SEP . $entry)) { - $this->_rmdir($dirname . DIR_SEP . $entry, $level + 1, $exp_time); - } - else { - $this->_unlink($dirname . DIR_SEP . $entry, $exp_time); - } - } - } - - closedir($handle); - - if ($level) - @rmdir($dirname); - - return true; - - } else { - return false; - } - } - -/*======================================================================*\ - Function: _unlink - Purpose: unlink a file, possibly using expiration time -\*======================================================================*/ + /** + * unlink a file, possibly using expiration time + * + * @param string $resource + * @param integer $exp_time + */ function _unlink($resource, $exp_time = null) { - if(isset($exp_time)) { - if(time() - filemtime($resource) >= $exp_time) { - @unlink($resource); - } - } else { - @unlink($resource); - } - } - -/*======================================================================*\ - Function: _create_dir_structure - Purpose: create full directory structure -\*======================================================================*/ - function _create_dir_structure($dir) - { - if (!@file_exists($dir)) { - $_dir_parts = preg_split('!\\'.DIR_SEP.'+!', $dir, -1, PREG_SPLIT_NO_EMPTY); - $_new_dir = ($dir{0} == DIR_SEP) ? DIR_SEP : ''; - - // do not attempt to test or make directories outside of open_basedir - $_open_basedir_ini = ini_get('open_basedir'); - if(!empty($_open_basedir_ini)) { - $_use_open_basedir = true; - $_open_basedir_sep = (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') ? ';' : ':'; - $_open_basedirs = explode($_open_basedir_sep, $_open_basedir_ini); - } else { - $_use_open_basedir = false; - } - - foreach ($_dir_parts as $_dir_part) { - $_new_dir .= $_dir_part; - - if ($_use_open_basedir) { - $_make_new_dir = false; - foreach ($_open_basedirs as $_open_basedir) { - if (substr($_new_dir.'/', 0, strlen($_open_basedir)) == $_open_basedir) { - $_make_new_dir = true; - break; - } - } - } else { - $_make_new_dir = true; - } - - if ($_make_new_dir && !@file_exists($_new_dir) && !@mkdir($_new_dir, 0771)) { - $this->trigger_error("problem creating directory \"$dir\""); - return false; - } - $_new_dir .= DIR_SEP; - } + if(isset($exp_time)) { + if(time() - @filemtime($resource) >= $exp_time) { + return @unlink($resource); + } + } else { + return @unlink($resource); } } -/*======================================================================*\ - Function: _write_cache_file - Purpose: Prepend the cache information to the cache file - and write it -\*======================================================================*/ - function _write_cache_file($tpl_file, $cache_id, $compile_id, $results) + /** + * returns an auto_id for auto-file-functions + * + * @param string $cache_id + * @param string $compile_id + * @return string|null + */ + function _get_auto_id($cache_id=null, $compile_id=null) { + if (isset($cache_id)) + return (isset($compile_id)) ? $cache_id . '|' . $compile_id : $cache_id; + elseif(isset($compile_id)) + return $compile_id; + else + return null; + } + + /** + * trigger Smarty plugin error + * + * @param string $error_msg + * @param string $tpl_file + * @param integer $tpl_line + * @param string $file + * @param integer $line + * @param integer $error_type + */ + function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null, + $file = null, $line = null, $error_type = E_USER_ERROR) { - // put timestamp in cache header - $this->_cache_info['timestamp'] = time(); - if ($this->cache_lifetime > -1){ - // expiration set - $this->_cache_info['expires'] = $this->_cache_info['timestamp'] + $this->cache_lifetime; + if(isset($file) && isset($line)) { + $info = ' ('.basename($file).", line $line)"; } else { - // cache will never expire - $this->_cache_info['expires'] = -1; + $info = ''; } - - // prepend the cache header info into cache file - $results = serialize($this->_cache_info)."\n".$results; - - if (!empty($this->cache_handler_func)) { - // use cache_handler function - $funcname = $this->cache_handler_func; - return $funcname('write', $this, $results, $tpl_file, $cache_id, $compile_id); + if (isset($tpl_line) && isset($tpl_file)) { + $this->trigger_error('[in ' . $tpl_file . ' line ' . $tpl_line . "]: $error_msg$info", $error_type); } else { - // use local cache file - if (isset($cache_id)) - $auto_id = (isset($compile_id)) ? $cache_id . '|' . $compile_id : $cache_id; - elseif(isset($compile_id)) - $auto_id = $compile_id; - else - $auto_id = null; - - $cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $auto_id); - $this->_write_file($cache_file, $results, true); - return true; + $this->trigger_error($error_msg . $info, $error_type); } } -/*======================================================================*\ - Function: _read_cache_file - Purpose: read a cache file, determine if it needs to be - regenerated or not -\*======================================================================*/ - function _read_cache_file($tpl_file, $cache_id, $compile_id, &$results) - { - static $content_cache = array(); - if ($this->force_compile) { - // force compile enabled, always regenerate - return false; - } + /** + * callback function for preg_replace, to call a non-cacheable block + * @return string + */ + function _process_compiled_include_callback($match) { + $_func = '_smarty_tplfunc_'.$match[2].'_'.$match[3]; + ob_start(); + $_func($this); + $_ret = ob_get_contents(); + ob_end_clean(); + return $_ret; + } - if (isset($content_cache["$tpl_file,$cache_id,$compile_id"])) { - list($results, $this->_cache_info) = $content_cache["$tpl_file,$cache_id,$compile_id"]; - return true; - } - if (!empty($this->cache_handler_func)) { - // use cache_handler function - $funcname = $this->cache_handler_func; - $funcname('read', $this, $results, $tpl_file, $cache_id, $compile_id); - } else { - // use local cache file - if (isset($cache_id)) - $auto_id = (isset($compile_id)) ? $cache_id . '|' . $compile_id : $cache_id; - elseif(isset($compile_id)) - $auto_id = $compile_id; - else - $auto_id = null; + /** + * called for included templates + * + * @param string $_smarty_include_tpl_file + * @param string $_smarty_include_vars + */ - $cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $auto_id); - $results = $this->_read_file($cache_file); - } + // $_smarty_include_tpl_file, $_smarty_include_vars - if (empty($results)) { - // nothing to parse (error?), regenerate cache - return false; + function _smarty_include($params) + { + if ($this->debugging) { + $_params = array(); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + $debug_start_time = smarty_core_get_microtime($_params, $this); + $this->_smarty_debug_info[] = array('type' => 'template', + 'filename' => $params['smarty_include_tpl_file'], + 'depth' => ++$this->_inclusion_depth); + $included_tpls_idx = count($this->_smarty_debug_info) - 1; } - $cache_split = explode("\n", $results, 2); - $cache_header = $cache_split[0]; - - $this->_cache_info = unserialize($cache_header); + $this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']); - if ($this->caching == 2 && isset ($this->_cache_info['expires'])){ - // caching by expiration time - if ($this->_cache_info['expires'] > -1 && (time() > $this->_cache_info['expires'])) { - // cache expired, regenerate - return false; - } - } else { - // caching by lifetime - if ($this->cache_lifetime > -1 && (time() - $this->_cache_info['timestamp'] > $this->cache_lifetime)) { - // cache expired, regenerate - return false; - } - } + // config vars are treated as local, so push a copy of the + // current ones onto the front of the stack + array_unshift($this->_config, $this->_config[0]); - if ($this->compile_check) { - foreach ($this->_cache_info['template'] as $template_dep) { - $this->_fetch_template_info($template_dep, $template_source, $template_timestamp, false); - if ($this->_cache_info['timestamp'] < $template_timestamp) { - // template file has changed, regenerate cache - return false; - } - } + $_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']); - if (isset($this->_cache_info['config'])) { - foreach ($this->_cache_info['config'] as $config_dep) { - if ($this->_cache_info['timestamp'] < filemtime($this->config_dir.DIR_SEP.$config_dep)) { - // config file has changed, regenerate cache - return false; - } - } - } - } - $results = $cache_split[1]; - $content_cache["$tpl_file,$cache_id,$compile_id"] = array($results, $this->_cache_info); - - return true; - } - -/*======================================================================*\ - Function: _get_plugin_filepath - Purpose: get filepath of requested plugin -\*======================================================================*/ - function _get_plugin_filepath($type, $name) - { - $_plugin_filename = "$type.$name.php"; - - foreach ((array)$this->plugins_dir as $_plugin_dir) { - - $_plugin_filepath = $_plugin_dir . DIR_SEP . $_plugin_filename; - - // see if path is relative - if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) { - $_relative_paths[] = $_plugin_dir; - // relative path, see if it is in the SMARTY_DIR - if (@is_readable(SMARTY_DIR . $_plugin_filepath)) { - return SMARTY_DIR . $_plugin_filepath; - } - } - // try relative to cwd (or absolute) - if (@is_readable($_plugin_filepath)) { - return $_plugin_filepath; - } + if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path) + || $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path)) + { + include($_smarty_compile_path); } - // still not found, try PHP include_path - if(isset($_relative_paths)) { - foreach ((array)$_relative_paths as $_plugin_dir) { - - $_plugin_filepath = $_plugin_dir . DIR_SEP . $_plugin_filename; - - if ($this->_get_include_path($_plugin_filepath, $_include_filepath)) { - return $_include_filepath; - } - } - } - - - return false; - } - -/*======================================================================*\ - Function: _load_plugins - Purpose: Load requested plugins -\*======================================================================*/ - function _load_plugins($plugins) - { - - foreach ($plugins as $plugin_info) { - list($type, $name, $tpl_file, $tpl_line, $delayed_loading) = $plugin_info; - $plugin = &$this->_plugins[$type][$name]; - - /* - * We do not load plugin more than once for each instance of Smarty. - * The following code checks for that. The plugin can also be - * registered dynamically at runtime, in which case template file - * and line number will be unknown, so we fill them in. - * - * The final element of the info array is a flag that indicates - * whether the dynamically registered plugin function has been - * checked for existence yet or not. - */ - if (isset($plugin)) { - if (!$plugin[3]) { - if (!function_exists($plugin[0])) { - $this->_trigger_plugin_error("$type '$name' is not implemented", $tpl_file, $tpl_line); - } else { - $plugin[1] = $tpl_file; - $plugin[2] = $tpl_line; - $plugin[3] = true; - } - } - continue; - } else if ($type == 'insert') { - /* - * For backwards compatibility, we check for insert functions in - * the symbol table before trying to load them as a plugin. - */ - $plugin_func = 'insert_' . $name; - if (function_exists($plugin_func)) { - $plugin = array($plugin_func, $tpl_file, $tpl_line, true); - continue; - } - } - - $plugin_file = $this->_get_plugin_filepath($type, $name); + // pop the local vars off the front of the stack + array_shift($this->_config); - if ($found = ($plugin_file != false)) { - $message = "could not load plugin file '$type.$name.php'\n"; - } + $this->_inclusion_depth--; - /* - * If plugin file is found, it -must- provide the properly named - * plugin function. In case it doesn't, simply output the error and - * do not fall back on any other method. - */ - if ($found) { - include_once $plugin_file; - - $plugin_func = 'smarty_' . $type . '_' . $name; - if (!function_exists($plugin_func)) { - $this->_trigger_plugin_error("plugin function $plugin_func() not found in $plugin_file", $tpl_file, $tpl_line); - continue; - } - } - /* - * In case of insert plugins, their code may be loaded later via - * 'script' attribute. - */ - else if ($type == 'insert' && $delayed_loading) { - $plugin_func = 'smarty_' . $type . '_' . $name; - $found = true; - } - - /* - * Plugin specific processing and error checking. - */ - if (!$found) { - if ($type == 'modifier') { - /* - * In case modifier falls back on using PHP functions - * directly, we only allow those specified in the security - * context. - */ - if ($this->security && !in_array($name, $this->security_settings['MODIFIER_FUNCS'])) { - $message = "(secure mode) modifier '$name' is not allowed"; - } else { - if (!function_exists($name)) { - $message = "modifier '$name' is not implemented"; - } else { - $plugin_func = $name; - $found = true; - } - } - } else if ($type == 'function') { - /* - * This is a catch-all situation. - */ - $message = "unknown tag - '$name'"; - } - } + if ($this->debugging) { + // capture time for debugging info + $_params = array(); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time; + } - if ($found) { - $this->_plugins[$type][$name] = array($plugin_func, $tpl_file, $tpl_line, true); - } else { - // output error - $this->_trigger_plugin_error($message, $tpl_file, $tpl_line); - } + if ($this->caching) { + $this->_cache_info['template'][$params['smarty_include_tpl_file']] = true; } } -/*======================================================================*\ - Function: _load_resource_plugin - Purpose: -\*======================================================================*/ - function _load_resource_plugin($type) - { - /* - * Resource plugins are not quite like the other ones, so they are - * handled differently. The first element of plugin info is the array of - * functions provided by the plugin, the second one indicates whether - * all of them exist or not. - */ - - $plugin = &$this->_plugins['resource'][$type]; - if (isset($plugin)) { - if (!$plugin[1] && count($plugin[0])) { - $plugin[1] = true; - foreach ($plugin[0] as $plugin_func) { - if (!function_exists($plugin_func)) { - $plugin[1] = false; - break; - } - } - } - if (!$plugin[1]) { - $this->_trigger_plugin_error("resource '$type' is not implemented"); - } - - return; - } + /** + * get or set an array of cached attributes for function that is + * not cacheable + * @return array + */ + function &_smarty_cache_attrs($cache_serial, $count) { + $_cache_attrs =& $this->_cache_info['cache_attrs'][$cache_serial][$count]; - $plugin_file = $this->_get_plugin_filepath('resource', $type); - $found = ($plugin_file != false); + if ($this->_cache_including) { + /* return next set of cache_attrs */ + $_return =& current($_cache_attrs); + next($_cache_attrs); + return $_return; - if ($found) { /* - * If the plugin file is found, it -must- provide the properly named - * plugin functions. - */ - include_once $plugin_file; - - /* - * Locate functions that we require the plugin to provide. - */ - $resource_ops = array('source', 'timestamp', 'secure', 'trusted'); - $resource_funcs = array(); - foreach ($resource_ops as $op) { - $plugin_func = 'smarty_resource_' . $type . '_' . $op; - if (!function_exists($plugin_func)) { - $this->_trigger_plugin_error("plugin function $plugin_func() not found in $plugin_file"); - return; - } else { - $resource_funcs[] = $plugin_func; - } - } + } else { + /* add a reference to a new set of cache_attrs */ + $_cache_attrs[] = array(); + return $_cache_attrs[count($_cache_attrs)-1]; - $this->_plugins['resource'][$type] = array($resource_funcs, true); } - } -/*======================================================================*\ - Function: _autoload_filters() - Purpose: automatically load a set of filters -\*======================================================================*/ - function _autoload_filters() - { - foreach ($this->autoload_filters as $filter_type => $filters) { - foreach ($filters as $filter) { - $this->load_filter($filter_type, $filter); - } - } } -/*======================================================================*\ - Function: quote_replace - Purpose: Quote subpattern references -\*======================================================================*/ - function quote_replace($string) + + /** + * wrapper for include() retaining $this + * @return mixed + */ + function _include($filename, $once=false, $params=null) { - return preg_replace('![\\$]\d!', '\\\\\\0', $string); + if ($once) { + return include_once($filename); + } else { + return include($filename); + } } -/*======================================================================*\ - Function: _trigger_plugin_error - Purpose: trigger Smarty plugin error -\*======================================================================*/ - function _trigger_plugin_error($error_msg, $tpl_file = null, $tpl_line = null, $error_type = E_USER_ERROR) + /** + * wrapper for eval() retaining $this + * @return mixed + */ + function _eval($code, $params=null) { - if (isset($tpl_line) && isset($tpl_file)) { - trigger_error("Smarty plugin error: [in " . $tpl_file . " line " . - $tpl_line . "]: $error_msg", $error_type); - } else { - trigger_error("Smarty plugin error: $error_msg", $error_type); - } + return eval($code); } + /**#@-*/ -/*======================================================================*\ - Function: _get_microtime - Purpose: Get seconds and microseconds -\*======================================================================*/ - function _get_microtime() - { - $mtime = microtime(); - $mtime = explode(" ", $mtime); - $mtime = (double)($mtime[1]) + (double)($mtime[0]); - return ($mtime); - } - -/*======================================================================*\ - Function: _get_include_path - Purpose: Get path to file from include_path -\*======================================================================*/ - function _get_include_path($file_path,&$new_file_path) - { - static $_path_array = null; - - if(!isset($_path_array)) { - $_ini_include_path = ini_get('include_path'); - - if(strstr($_ini_include_path,';')) { - // windows pathnames - $_path_array = explode(';',$_ini_include_path); - } else { - $_path_array = explode(':',$_ini_include_path); - } - } - foreach ($_path_array as $_include_path) { - if (@file_exists($_include_path . DIR_SEP . $file_path)) { - $new_file_path = $_include_path . DIR_SEP . $file_path; - return true; - } - } - return false; - } - } /* vim: set expandtab: */