+++ /dev/null
-<?php\r
-\r
-/**\r
- * Project: Smarty: the PHP compiling template engine\r
- * File: Smarty.class.php\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Lesser General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2.1 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Lesser General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * For questions, help, comments, discussion, etc., please join the\r
- * Smarty mailing list. Send a blank e-mail to\r
- * smarty-general-subscribe@lists.php.net\r
- *\r
- * You may contact the authors of Smarty by e-mail at:\r
- * monte@ispi.net\r
- * andrei@php.net\r
- *\r
- * Or, write to:\r
- * Monte Ohrt\r
- * Director of Technology, ispi\r
- * 237 S. 70th suite 220\r
- * Lincoln, NE 68510\r
- *\r
- * The latest version of Smarty can be obtained from:\r
- * http://smarty.php.net/\r
- *\r
- * @link http://smarty.php.net/\r
- * @copyright 2001-2003 ispi of Lincoln, Inc.\r
- * @author Monte Ohrt <monte@ispi.net>\r
- * @author Andrei Zmievski <andrei@php.net>\r
- * @package Smarty\r
- * @version 2.6.0\r
- */\r
-\r
-/* $Id: Smarty.class.php,v 1.1 2005/10/17 18:37:39 jeichorn Exp $ */\r
-\r
-/**\r
- * DIR_SEP isn't used anymore, but third party apps might\r
- */\r
-if(!defined('DIR_SEP')) {\r
- define('DIR_SEP', DIRECTORY_SEPARATOR);\r
-}\r
-\r
-/**\r
- * set SMARTY_DIR to absolute path to Smarty library files.\r
- * if not defined, include_path will be used. Sets SMARTY_DIR only if user\r
- * application has not already defined it.\r
- */\r
-\r
-if (!defined('SMARTY_DIR')) {\r
- define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);\r
-}\r
-\r
-define('SMARTY_PHP_PASSTHRU', 0);\r
-define('SMARTY_PHP_QUOTE', 1);\r
-define('SMARTY_PHP_REMOVE', 2);\r
-define('SMARTY_PHP_ALLOW', 3);\r
-\r
-/**\r
- * @package Smarty\r
- */\r
-class Smarty\r
-{\r
- /**#@+\r
- * Smarty Configuration Section\r
- */\r
-\r
- /**\r
- * The name of the directory where templates are located.\r
- *\r
- * @var string\r
- */\r
- var $template_dir = 'templates';\r
-\r
- /**\r
- * The directory where compiled templates are located.\r
- *\r
- * @var string\r
- */\r
- var $compile_dir = 'templates_c';\r
-\r
- /**\r
- * The directory where config files are located.\r
- *\r
- * @var string\r
- */\r
- var $config_dir = 'configs';\r
-\r
- /**\r
- * An array of directories searched for plugins.\r
- *\r
- * @var array\r
- */\r
- var $plugins_dir = array('plugins');\r
-\r
- /**\r
- * If debugging is enabled, a debug console window will display\r
- * when the page loads (make sure your browser allows unrequested\r
- * popup windows)\r
- *\r
- * @var boolean\r
- */\r
- var $debugging = false;\r
-\r
- /**\r
- * This is the path to the debug console template. If not set,\r
- * the default one will be used.\r
- *\r
- * @var string\r
- */\r
- var $debug_tpl = '';\r
-\r
- /**\r
- * This determines if debugging is enable-able from the browser.\r
- * <ul>\r
- * <li>NONE => no debugging control allowed</li>\r
- * <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li>\r
- * </ul>\r
- * @link http://www.foo.dom/index.php?SMARTY_DEBUG\r
- * @var string\r
- */\r
- var $debugging_ctrl = 'NONE';\r
-\r
- /**\r
- * This tells Smarty whether to check for recompiling or not. Recompiling\r
- * does not need to happen unless a template or config file is changed.\r
- * Typically you enable this during development, and disable for\r
- * production.\r
- *\r
- * @var boolean\r
- */\r
- var $compile_check = true;\r
-\r
- /**\r
- * This forces templates to compile every time. Useful for development\r
- * or debugging.\r
- *\r
- * @var boolean\r
- */\r
- var $force_compile = false;\r
-\r
- /**\r
- * This enables template caching.\r
- * <ul>\r
- * <li>0 = no caching</li>\r
- * <li>1 = use class cache_lifetime value</li>\r
- * <li>2 = use cache_lifetime in cache file</li>\r
- * </ul>\r
- * @var integer\r
- */\r
- var $caching = 0;\r
-\r
- /**\r
- * The name of the directory for cache files.\r
- *\r
- * @var string\r
- */\r
- var $cache_dir = 'cache';\r
-\r
- /**\r
- * This is the number of seconds cached content will persist.\r
- * <ul>\r
- * <li>0 = always regenerate cache</li>\r
- * <li>-1 = never expires</li>\r
- * </ul>\r
- *\r
- * @var integer\r
- */\r
- var $cache_lifetime = 3600;\r
-\r
- /**\r
- * Only used when $caching is enabled. If true, then If-Modified-Since headers\r
- * are respected with cached content, and appropriate HTTP headers are sent.\r
- * This way repeated hits to a cached page do not send the entire page to the\r
- * client every time.\r
- *\r
- * @var boolean\r
- */\r
- var $cache_modified_check = false;\r
-\r
- /**\r
- * This determines how Smarty handles "<?php ... ?>" tags in templates.\r
- * possible values:\r
- * <ul>\r
- * <li>SMARTY_PHP_PASSTHRU -> print tags as plain text</li>\r
- * <li>SMARTY_PHP_QUOTE -> escape tags as entities</li>\r
- * <li>SMARTY_PHP_REMOVE -> remove php tags</li>\r
- * <li>SMARTY_PHP_ALLOW -> execute php tags</li>\r
- * </ul>\r
- *\r
- * @var integer\r
- */\r
- var $php_handling = SMARTY_PHP_PASSTHRU;\r
-\r
- /**\r
- * This enables template security. When enabled, many things are restricted\r
- * in the templates that normally would go unchecked. This is useful when\r
- * untrusted parties are editing templates and you want a reasonable level\r
- * of security. (no direct execution of PHP in templates for example)\r
- *\r
- * @var boolean\r
- */\r
- var $security = false;\r
-\r
- /**\r
- * This is the list of template directories that are considered secure. This\r
- * is used only if {@link $security} is enabled. One directory per array\r
- * element. {@link $template_dir} is in this list implicitly.\r
- *\r
- * @var array\r
- */\r
- var $secure_dir = array();\r
-\r
- /**\r
- * These are the security settings for Smarty. They are used only when\r
- * {@link $security} is enabled.\r
- *\r
- * @var array\r
- */\r
- var $security_settings = array(\r
- 'PHP_HANDLING' => false,\r
- 'IF_FUNCS' => array('array', 'list',\r
- 'isset', 'empty',\r
- 'count', 'sizeof',\r
- 'in_array', 'is_array',\r
- 'true','false'),\r
- 'INCLUDE_ANY' => false,\r
- 'PHP_TAGS' => false,\r
- 'MODIFIER_FUNCS' => array('count'),\r
- 'ALLOW_CONSTANTS' => false\r
- );\r
-\r
- /**\r
- * This is an array of directories where trusted php scripts reside.\r
- * {@link $security} is disabled during their inclusion/execution.\r
- *\r
- * @var array\r
- */\r
- var $trusted_dir = array();\r
-\r
- /**\r
- * The left delimiter used for the template tags.\r
- *\r
- * @var string\r
- */\r
- var $left_delimiter = '{';\r
-\r
- /**\r
- * The right delimiter used for the template tags.\r
- *\r
- * @var string\r
- */\r
- var $right_delimiter = '}';\r
-\r
- /**\r
- * The order in which request variables are registered, similar to\r
- * variables_order in php.ini E = Environment, G = GET, P = POST,\r
- * C = Cookies, S = Server\r
- *\r
- * @var string\r
- */\r
- var $request_vars_order = "EGPCS";\r
-\r
- /**\r
- * Indicates wether $HTTP_*_VARS[] (request_use_auto_globals=false)\r
- * are uses as request-vars or $_*[]-vars. note: if\r
- * request_use_auto_globals is true, then $request_vars_order has\r
- * no effect, but the php-ini-value "gpc_order"\r
- *\r
- * @var boolean\r
- */\r
- var $request_use_auto_globals = false;\r
-\r
- /**\r
- * Set this if you want different sets of compiled files for the same\r
- * templates. This is useful for things like different languages.\r
- * Instead of creating separate sets of templates per language, you\r
- * set different compile_ids like 'en' and 'de'.\r
- *\r
- * @var string\r
- */\r
- var $compile_id = null;\r
-\r
- /**\r
- * This tells Smarty whether or not to use sub dirs in the cache/ and\r
- * templates_c/ directories. sub directories better organized, but\r
- * may not work well with PHP safe mode enabled.\r
- *\r
- * @var boolean\r
- *\r
- */\r
- var $use_sub_dirs = true;\r
-\r
- /**\r
- * This is a list of the modifiers to apply to all template variables.\r
- * Put each modifier in a separate array element in the order you want\r
- * them applied. example: <code>array('escape:"htmlall"');</code>\r
- *\r
- * @var array\r
- */\r
- var $default_modifiers = array();\r
-\r
- /**\r
- * This is the resource type to be used when not specified\r
- * at the beginning of the resource path. examples:\r
- * $smarty->display('file:index.tpl');\r
- * $smarty->display('db:index.tpl');\r
- * $smarty->display('index.tpl'); // will use default resource type\r
- * {include file="file:index.tpl"}\r
- * {include file="db:index.tpl"}\r
- * {include file="index.tpl"} {* will use default resource type *}\r
- *\r
- * @var array\r
- */\r
- var $default_resource_type = 'file';\r
-\r
- /**\r
- * The function used for cache file handling. If not set, built-in caching is used.\r
- *\r
- * @var null|string function name\r
- */\r
- var $cache_handler_func = null;\r
-\r
- /**\r
- * These are the variables from the globals array that are\r
- * assigned to all templates automatically. This isn't really\r
- * necessary any more, you can use the $smarty var to access them\r
- * directly.\r
- *\r
- * @var array\r
- */\r
- var $global_assign = array('HTTP_SERVER_VARS' => array('SCRIPT_NAME'));\r
-\r
- /**\r
- * The value of "undefined". Leave it alone :-)\r
- *\r
- * @var null\r
- */\r
- var $undefined = null;\r
-\r
- /**\r
- * This indicates which filters are automatically loaded into Smarty.\r
- *\r
- * @var array array of filter names\r
- */\r
- var $autoload_filters = array();\r
-\r
- /**#@+\r
- * @var boolean\r
- */\r
- /**\r
- * This tells if config file vars of the same name overwrite each other or not.\r
- * if disabled, same name variables are accumulated in an array.\r
- */\r
- var $config_overwrite = true;\r
-\r
- /**\r
- * This tells whether or not to automatically booleanize config file variables.\r
- * If enabled, then the strings "on", "true", and "yes" are treated as boolean\r
- * true, and "off", "false" and "no" are treated as boolean false.\r
- */\r
- var $config_booleanize = true;\r
-\r
- /**\r
- * This tells whether hidden sections [.foobar] are readable from the\r
- * tempalates or not. Normally you would never allow this since that is\r
- * the point behind hidden sections: the application can access them, but\r
- * the templates cannot.\r
- */\r
- var $config_read_hidden = false;\r
-\r
- /**\r
- * This tells whether or not automatically fix newlines in config files.\r
- * It basically converts \r (mac) or \r\n (dos) to \n\r
- */\r
- var $config_fix_newlines = true;\r
- /**#@-*/\r
-\r
- /**\r
- * If a template cannot be found, this PHP function will be executed.\r
- * Useful for creating templates on-the-fly or other special action.\r
- *\r
- * @var string function name\r
- */\r
- var $default_template_handler_func = '';\r
-\r
- /**\r
- * The file that contains the compiler class. This can a full\r
- * pathname, or relative to the php_include path.\r
- *\r
- * @var string\r
- */\r
- var $compiler_file = 'Smarty_Compiler.class.php';\r
-\r
- /**\r
- * The class used for compiling templates.\r
- *\r
- * @var string\r
- */\r
- var $compiler_class = 'Smarty_Compiler';\r
-\r
- /**\r
- * The class used to load config vars.\r
- *\r
- * @var string\r
- */\r
- var $config_class = 'Config_File';\r
-\r
-/**#@+\r
- * END Smarty Configuration Section\r
- * There should be no need to touch anything below this line.\r
- * @access private\r
- */\r
- /**\r
- * error messages. true/false\r
- *\r
- * @var boolean\r
- */\r
- var $_error_msg = false;\r
-\r
- /**\r
- * where assigned template vars are kept\r
- *\r
- * @var array\r
- */\r
- var $_tpl_vars = array();\r
-\r
- /**\r
- * stores run-time $smarty.* vars\r
- *\r
- * @var null|array\r
- */\r
- var $_smarty_vars = null;\r
-\r
- /**\r
- * keeps track of sections\r
- *\r
- * @var array\r
- */\r
- var $_sections = array();\r
-\r
- /**\r
- * keeps track of foreach blocks\r
- *\r
- * @var array\r
- */\r
- var $_foreach = array();\r
-\r
- /**\r
- * keeps track of tag hierarchy\r
- *\r
- * @var array\r
- */\r
- var $_tag_stack = array();\r
-\r
- /**\r
- * configuration object\r
- *\r
- * @var Config_file\r
- */\r
- var $_conf_obj = null;\r
-\r
- /**\r
- * loaded configuration settings\r
- *\r
- * @var array\r
- */\r
- var $_config = array(array('vars' => array(), 'files' => array()));\r
-\r
- /**\r
- * md5 checksum of the string 'Smarty'\r
- *\r
- * @var string\r
- */\r
- var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f';\r
-\r
- /**\r
- * Smarty version number\r
- *\r
- * @var string\r
- */\r
- var $_version = '2.6.0';\r
-\r
- /**\r
- * current template inclusion depth\r
- *\r
- * @var integer\r
- */\r
- var $_inclusion_depth = 0;\r
-\r
- /**\r
- * for different compiled templates\r
- *\r
- * @var string\r
- */\r
- var $_compile_id = null;\r
-\r
- /**\r
- * text in URL to enable debug mode\r
- *\r
- * @var string\r
- */\r
- var $_smarty_debug_id = 'SMARTY_DEBUG';\r
-\r
- /**\r
- * debugging information for debug console\r
- *\r
- * @var array\r
- */\r
- var $_smarty_debug_info = array();\r
-\r
- /**\r
- * info that makes up a cache file\r
- *\r
- * @var array\r
- */\r
- var $_cache_info = array();\r
-\r
- /**\r
- * default file permissions\r
- *\r
- * @var integer\r
- */\r
- var $_file_perms = 0644;\r
-\r
- /**\r
- * default dir permissions\r
- *\r
- * @var integer\r
- */\r
- var $_dir_perms = 0771;\r
-\r
- /**\r
- * registered objects\r
- *\r
- * @var array\r
- */\r
- var $_reg_objects = array();\r
-\r
- /**\r
- * table keeping track of plugins\r
- *\r
- * @var array\r
- */\r
- var $_plugins = array(\r
- 'modifier' => array(),\r
- 'function' => array(),\r
- 'block' => array(),\r
- 'compiler' => array(),\r
- 'prefilter' => array(),\r
- 'postfilter' => array(),\r
- 'outputfilter' => array(),\r
- 'resource' => array(),\r
- 'insert' => array());\r
-\r
-\r
- /**\r
- * cache serials\r
- *\r
- * @var array\r
- */\r
- var $_cache_serials = array();\r
-\r
- /**\r
- * name of optional cache include file\r
- *\r
- * @var string\r
- */\r
- var $_cache_include = null;\r
-\r
- /**\r
- * indicate if the current code is used in a compiled\r
- * include\r
- *\r
- * @var string\r
- */\r
- var $_cache_including = false;\r
-\r
- /**#@-*/\r
- /**\r
- * The class constructor.\r
- *\r
- * @uses $global_assign uses {@link assign()} to assign each corresponding\r
- * value from $GLOBALS to the template vars\r
- */\r
- function Smarty()\r
- {\r
- foreach ($this->global_assign as $key => $var_name) {\r
- if (is_array($var_name)) {\r
- foreach ($var_name as $var) {\r
- if (isset($GLOBALS[$key][$var])) {\r
- $this->assign($var, $GLOBALS[$key][$var]);\r
- } else {\r
- $this->assign($var, $this->undefined);\r
- }\r
- }\r
- } else {\r
- if (isset($GLOBALS[$var_name])) {\r
- $this->assign($var_name, $GLOBALS[$var_name]);\r
- } else {\r
- $this->assign($var_name, $this->undefined);\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * assigns values to template variables\r
- *\r
- * @param array|string $tpl_var the template variable name(s)\r
- * @param mixed $value the value to assign\r
- */\r
- function assign($tpl_var, $value = null)\r
- {\r
- if (is_array($tpl_var)){\r
- foreach ($tpl_var as $key => $val) {\r
- if ($key != '') {\r
- $this->_tpl_vars[$key] = $val;\r
- }\r
- }\r
- } else {\r
- if ($tpl_var != '')\r
- $this->_tpl_vars[$tpl_var] = $value;\r
- }\r
- }\r
-\r
- /**\r
- * assigns values to template variables by reference\r
- *\r
- * @param string $tpl_var the template variable name\r
- * @param mixed $value the referenced value to assign\r
- */\r
- function assign_by_ref($tpl_var, &$value)\r
- {\r
- if ($tpl_var != '')\r
- $this->_tpl_vars[$tpl_var] = &$value;\r
- }\r
-\r
- /**\r
- * appends values to template variables\r
- *\r
- * @param array|string $tpl_var the template variable name(s)\r
- * @param mixed $value the value to append\r
- */\r
- function append($tpl_var, $value=null, $merge=false)\r
- {\r
- if (is_array($tpl_var)) {\r
- // $tpl_var is an array, ignore $value\r
- foreach ($tpl_var as $_key => $_val) {\r
- if ($_key != '') {\r
- if(!@is_array($this->_tpl_vars[$_key])) {\r
- settype($this->_tpl_vars[$_key],'array');\r
- }\r
- if($merge && is_array($_val)) {\r
- foreach($_val as $_mkey => $_mval) {\r
- $this->_tpl_vars[$_key][$_mkey] = $_mval;\r
- }\r
- } else {\r
- $this->_tpl_vars[$_key][] = $_val;\r
- }\r
- }\r
- }\r
- } else {\r
- if ($tpl_var != '' && isset($value)) {\r
- if(!@is_array($this->_tpl_vars[$tpl_var])) {\r
- settype($this->_tpl_vars[$tpl_var],'array');\r
- }\r
- if($merge && is_array($value)) {\r
- foreach($value as $_mkey => $_mval) {\r
- $this->_tpl_vars[$tpl_var][$_mkey] = $_mval;\r
- }\r
- } else {\r
- $this->_tpl_vars[$tpl_var][] = $value;\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * appends values to template variables by reference\r
- *\r
- * @param string $tpl_var the template variable name\r
- * @param mixed $value the referenced value to append\r
- */\r
- function append_by_ref($tpl_var, &$value, $merge=false)\r
- {\r
- if ($tpl_var != '' && isset($value)) {\r
- if(!@is_array($this->_tpl_vars[$tpl_var])) {\r
- settype($this->_tpl_vars[$tpl_var],'array');\r
- }\r
- if ($merge && is_array($value)) {\r
- foreach($value as $_key => $_val) {\r
- $this->_tpl_vars[$tpl_var][$_key] = &$value[$_key];\r
- }\r
- } else {\r
- $this->_tpl_vars[$tpl_var][] = &$value;\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * clear the given assigned template variable.\r
- *\r
- * @param string $tpl_var the template variable to clear\r
- */\r
- function clear_assign($tpl_var)\r
- {\r
- if (is_array($tpl_var))\r
- foreach ($tpl_var as $curr_var)\r
- unset($this->_tpl_vars[$curr_var]);\r
- else\r
- unset($this->_tpl_vars[$tpl_var]);\r
- }\r
-\r
-\r
- /**\r
- * Registers custom function to be used in templates\r
- *\r
- * @param string $function the name of the template function\r
- * @param string $function_impl the name of the PHP function to register\r
- */\r
- function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null)\r
- {\r
- $this->_plugins['function'][$function] =\r
- array($function_impl, null, null, false, $cacheable, $cache_attrs);\r
-\r
- }\r
-\r
- /**\r
- * Unregisters custom function\r
- *\r
- * @param string $function name of template function\r
- */\r
- function unregister_function($function)\r
- {\r
- unset($this->_plugins['function'][$function]);\r
- }\r
-\r
- /**\r
- * Registers object to be used in templates\r
- *\r
- * @param string $object name of template object\r
- * @param object &$object_impl the referenced PHP object to register\r
- * @param null|array $allowed list of allowed methods (empty = all)\r
- * @param boolean $smarty_args smarty argument format, else traditional\r
- * @param null|array $block_functs list of methods that are block format\r
- */\r
- function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())\r
- {\r
- settype($allowed, 'array');\r
- settype($smarty_args, 'boolean');\r
- $this->_reg_objects[$object] =\r
- array(&$object_impl, $allowed, $smarty_args, $block_methods);\r
- }\r
-\r
- /**\r
- * Unregisters object\r
- *\r
- * @param string $object name of template object\r
- */\r
- function unregister_object($object)\r
- {\r
- unset($this->_reg_objects[$object]);\r
- }\r
-\r
-\r
- /**\r
- * Registers block function to be used in templates\r
- *\r
- * @param string $block name of template block\r
- * @param string $block_impl PHP function to register\r
- */\r
- function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)\r
- {\r
- $this->_plugins['block'][$block] =\r
- array($block_impl, null, null, false, $cacheable, $cache_attrs);\r
- }\r
-\r
- /**\r
- * Unregisters block function\r
- *\r
- * @param string $block name of template function\r
- */\r
- function unregister_block($block)\r
- {\r
- unset($this->_plugins['block'][$block]);\r
- }\r
-\r
- /**\r
- * Registers compiler function\r
- *\r
- * @param string $function name of template function\r
- * @param string $function_impl name of PHP function to register\r
- */\r
- function register_compiler_function($function, $function_impl, $cacheable=true)\r
- {\r
- $this->_plugins['compiler'][$function] =\r
- array($function_impl, null, null, false, $cacheable);\r
- }\r
-\r
- /**\r
- * Unregisters compiler function\r
- *\r
- * @param string $function name of template function\r
- */\r
- function unregister_compiler_function($function)\r
- {\r
- unset($this->_plugins['compiler'][$function]);\r
- }\r
-\r
- /**\r
- * Registers modifier to be used in templates\r
- *\r
- * @param string $modifier name of template modifier\r
- * @param string $modifier_impl name of PHP function to register\r
- */\r
- function register_modifier($modifier, $modifier_impl)\r
- {\r
- $this->_plugins['modifier'][$modifier] =\r
- array($modifier_impl, null, null, false);\r
- }\r
-\r
- /**\r
- * Unregisters modifier\r
- *\r
- * @param string $modifier name of template modifier\r
- */\r
- function unregister_modifier($modifier)\r
- {\r
- unset($this->_plugins['modifier'][$modifier]);\r
- }\r
-\r
- /**\r
- * Registers a resource to fetch a template\r
- *\r
- * @param string $type name of resource\r
- * @param array $functions array of functions to handle resource\r
- */\r
- function register_resource($type, $functions)\r
- {\r
- if (count($functions)==4) {\r
- $this->_plugins['resource'][$type] =\r
- array($functions, false);\r
-\r
- } elseif (count($functions)==5) {\r
- $this->_plugins['resource'][$type] =\r
- array(array(array(&$functions[0], $functions[1])\r
- ,array(&$functions[0], $functions[2])\r
- ,array(&$functions[0], $functions[3])\r
- ,array(&$functions[0], $functions[4]))\r
- ,false);\r
-\r
- } else {\r
- $this->trigger_error("malformed function-list for '$type' in register_resource");\r
-\r
- }\r
- }\r
-\r
- /**\r
- * Unregisters a resource\r
- *\r
- * @param string $type name of resource\r
- */\r
- function unregister_resource($type)\r
- {\r
- unset($this->_plugins['resource'][$type]);\r
- }\r
-\r
- /**\r
- * Registers a prefilter function to apply\r
- * to a template before compiling\r
- *\r
- * @param string $function name of PHP function to register\r
- */\r
- function register_prefilter($function)\r
- {\r
- $_name = (is_array($function)) ? $function[1] : $function;\r
- $this->_plugins['prefilter'][$_name]\r
- = array($function, null, null, false);\r
- }\r
-\r
- /**\r
- * Unregisters a prefilter function\r
- *\r
- * @param string $function name of PHP function\r
- */\r
- function unregister_prefilter($function)\r
- {\r
- unset($this->_plugins['prefilter'][$function]);\r
- }\r
-\r
- /**\r
- * Registers a postfilter function to apply\r
- * to a compiled template after compilation\r
- *\r
- * @param string $function name of PHP function to register\r
- */\r
- function register_postfilter($function)\r
- {\r
- $_name = (is_array($function)) ? $function[1] : $function;\r
- $this->_plugins['postfilter'][$_name]\r
- = array($function, null, null, false);\r
- }\r
-\r
- /**\r
- * Unregisters a postfilter function\r
- *\r
- * @param string $function name of PHP function\r
- */\r
- function unregister_postfilter($function)\r
- {\r
- unset($this->_plugins['postfilter'][$function]);\r
- }\r
-\r
- /**\r
- * Registers an output filter function to apply\r
- * to a template output\r
- *\r
- * @param string $function name of PHP function\r
- */\r
- function register_outputfilter($function)\r
- {\r
- $_name = (is_array($function)) ? $function[1] : $function;\r
- $this->_plugins['outputfilter'][$_name]\r
- = array($function, null, null, false);\r
- }\r
-\r
- /**\r
- * Unregisters an outputfilter function\r
- *\r
- * @param string $function name of PHP function\r
- */\r
- function unregister_outputfilter($function)\r
- {\r
- unset($this->_plugins['outputfilter'][$function]);\r
- }\r
-\r
- /**\r
- * load a filter of specified type and name\r
- *\r
- * @param string $type filter type\r
- * @param string $name filter name\r
- */\r
- function load_filter($type, $name)\r
- {\r
- switch ($type) {\r
- case 'output':\r
- $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false)));\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php');\r
- smarty_core_load_plugins($_params, $this);\r
- break;\r
-\r
- case 'pre':\r
- case 'post':\r
- if (!isset($this->_plugins[$type . 'filter'][$name]))\r
- $this->_plugins[$type . 'filter'][$name] = false;\r
- break;\r
- }\r
- }\r
-\r
- /**\r
- * clear cached content for the given template and cache id\r
- *\r
- * @param string $tpl_file name of template file\r
- * @param string $cache_id name of cache_id\r
- * @param string $compile_id name of compile_id\r
- * @param string $exp_time expiration time\r
- * @return boolean\r
- */\r
- function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)\r
- {\r
-\r
- if (!isset($compile_id))\r
- $compile_id = $this->compile_id;\r
-\r
- if (!isset($tpl_file))\r
- $compile_id = null;\r
-\r
- $_auto_id = $this->_get_auto_id($cache_id, $compile_id);\r
-\r
- if (!empty($this->cache_handler_func)) {\r
- return call_user_func_array($this->cache_handler_func,\r
- array('clear', &$this, &$dummy, $tpl_file, $cache_id, $compile_id, $exp_time));\r
- } else {\r
- $_params = array('auto_base' => $this->cache_dir,\r
- 'auto_source' => $tpl_file,\r
- 'auto_id' => $_auto_id,\r
- 'exp_time' => $exp_time);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rm_auto.php');\r
- return smarty_core_rm_auto($_params, $this);\r
- }\r
-\r
- }\r
-\r
-\r
- /**\r
- * clear the entire contents of cache (all templates)\r
- *\r
- * @param string $exp_time expire time\r
- * @return boolean results of {@link smarty_core_rm_auto()}\r
- */\r
- function clear_all_cache($exp_time = null)\r
- {\r
- if (!empty($this->cache_handler_func)) {\r
- $dummy = null;\r
- call_user_func_array($this->cache_handler_func,\r
- array('clear', &$this, &$dummy, null, null, null, $exp_time));\r
- } else {\r
- $_params = array('auto_base' => $this->cache_dir,\r
- 'auto_source' => null,\r
- 'auto_id' => null,\r
- 'exp_time' => $exp_time);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rm_auto.php');\r
- return smarty_core_rm_auto($_params, $this);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * test to see if valid cache exists for this template\r
- *\r
- * @param string $tpl_file name of template file\r
- * @param string $cache_id\r
- * @param string $compile_id\r
- * @return string|false results of {@link _read_cache_file()}\r
- */\r
- function is_cached($tpl_file, $cache_id = null, $compile_id = null)\r
- {\r
- if (!$this->caching)\r
- return false;\r
-\r
- if (!isset($compile_id))\r
- $compile_id = $this->compile_id;\r
-\r
- $_params = array(\r
- 'tpl_file' => $tpl_file,\r
- 'cache_id' => $cache_id,\r
- 'compile_id' => $compile_id\r
- );\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.read_cache_file.php');\r
- return smarty_core_read_cache_file($_params, $this);\r
- }\r
-\r
-\r
- /**\r
- * clear all the assigned template variables.\r
- *\r
- */\r
- function clear_all_assign()\r
- {\r
- $this->_tpl_vars = array();\r
- }\r
-\r
- /**\r
- * clears compiled version of specified template resource,\r
- * or all compiled template files if one is not specified.\r
- * This function is for advanced use only, not normally needed.\r
- *\r
- * @param string $tpl_file\r
- * @param string $compile_id\r
- * @param string $exp_time\r
- * @return boolean results of {@link smarty_core_rm_auto()}\r
- */\r
- function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)\r
- {\r
- if (!isset($compile_id)) {\r
- $compile_id = $this->compile_id;\r
- }\r
- $_params = array('auto_base' => $this->compile_dir,\r
- 'auto_source' => $tpl_file,\r
- 'auto_id' => $compile_id,\r
- 'exp_time' => $exp_time,\r
- 'extensions' => array('.inc', '.php'));\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rm_auto.php');\r
- return smarty_core_rm_auto($_params, $this);\r
- }\r
-\r
- /**\r
- * Checks whether requested template exists.\r
- *\r
- * @param string $tpl_file\r
- * @return boolean\r
- */\r
- function template_exists($tpl_file)\r
- {\r
- $_params = array('resource_name' => $tpl_file, 'quiet'=>true, 'get_source'=>false);\r
- return $this->_fetch_resource_info($_params);\r
- }\r
-\r
- /**\r
- * Returns an array containing template variables\r
- *\r
- * @param string $name\r
- * @param string $type\r
- * @return array\r
- */\r
- function &get_template_vars($name=null)\r
- {\r
- if(!isset($name)) {\r
- return $this->_tpl_vars;\r
- }\r
- if(isset($this->_tpl_vars[$name])) {\r
- return $this->_tpl_vars[$name];\r
- }\r
- }\r
-\r
- /**\r
- * Returns an array containing config variables\r
- *\r
- * @param string $name\r
- * @param string $type\r
- * @return array\r
- */\r
- function &get_config_vars($name=null)\r
- {\r
- if(!isset($name) && is_array($this->_config[0])) {\r
- return $this->_config[0]['vars'];\r
- } else if(isset($this->_config[0]['vars'][$name])) {\r
- return $this->_config[0]['vars'][$name];\r
- }\r
- }\r
-\r
- /**\r
- * trigger Smarty error\r
- *\r
- * @param string $error_msg\r
- * @param integer $error_type\r
- */\r
- function trigger_error($error_msg, $error_type = E_USER_WARNING)\r
- {\r
- trigger_error("Smarty error: $error_msg", $error_type);\r
- }\r
-\r
-\r
- /**\r
- * executes & displays the template results\r
- *\r
- * @param string $resource_name\r
- * @param string $cache_id\r
- * @param string $compile_id\r
- */\r
- function display($resource_name, $cache_id = null, $compile_id = null)\r
- {\r
- $this->fetch($resource_name, $cache_id, $compile_id, true);\r
- }\r
-\r
- /**\r
- * executes & returns or displays the template results\r
- *\r
- * @param string $resource_name\r
- * @param string $cache_id\r
- * @param string $compile_id\r
- * @param boolean $display\r
- */\r
- function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)\r
- {\r
- static $_cache_info = array();\r
-\r
- $_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(error_reporting() & ~E_NOTICE);\r
-\r
- if (!$this->debugging && $this->debugging_ctrl == 'URL'\r
- && @strstr($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'], $this->_smarty_debug_id)) {\r
- // enable debugging from URL\r
- $this->debugging = true;\r
- }\r
-\r
- if ($this->debugging) {\r
- // capture time for debugging info\r
- $_params = array();\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');\r
- $_debug_start_time = smarty_core_get_microtime($_params, $this);\r
- $this->_smarty_debug_info[] = array('type' => 'template',\r
- 'filename' => $resource_name,\r
- 'depth' => 0);\r
- $_included_tpls_idx = count($this->_smarty_debug_info) - 1;\r
- }\r
-\r
- if (!isset($compile_id)) {\r
- $compile_id = $this->compile_id;\r
- }\r
-\r
- $this->_compile_id = $compile_id;\r
- $this->_inclusion_depth = 0;\r
-\r
- if ($this->caching) {\r
- // save old cache_info, initialize cache_info\r
- array_push($_cache_info, $this->_cache_info);\r
- $this->_cache_info = array();\r
- $_params = array(\r
- 'tpl_file' => $resource_name,\r
- 'cache_id' => $cache_id,\r
- 'compile_id' => $compile_id,\r
- 'results' => null\r
- );\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.read_cache_file.php');\r
- if (smarty_core_read_cache_file($_params, $this)) {\r
- $_smarty_results = $_params['results'];\r
- if (@count($this->_cache_info['insert_tags'])) {\r
- $_params = array('plugins' => $this->_cache_info['insert_tags']);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php');\r
- smarty_core_load_plugins($_params, $this);\r
- $_params = array('results' => $_smarty_results);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.process_cached_inserts.php');\r
- $_smarty_results = smarty_core_process_cached_inserts($_params, $this);\r
- }\r
- if (@count($this->_cache_info['cache_serials'])) {\r
- $_params = array('results' => $_smarty_results);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.process_compiled_include.php');\r
- $_smarty_results = smarty_core_process_compiled_include($_params, $this);\r
- }\r
-\r
-\r
- if ($display) {\r
- if ($this->debugging)\r
- {\r
- // capture time for debugging info\r
- $_params = array();\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');\r
- $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time;\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.display_debug_console.php');\r
- $_smarty_results .= smarty_core_display_debug_console($_params, $this);\r
- }\r
- if ($this->cache_modified_check) {\r
- $_last_modified_date = @substr($GLOBALS['HTTP_SERVER_VARS']['HTTP_IF_MODIFIED_SINCE'], 0, strpos($GLOBALS['HTTP_SERVER_VARS']['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);\r
- $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';\r
- if (@count($this->_cache_info['insert_tags']) == 0\r
- && !$this->_cache_serials\r
- && $_gmt_mtime == $_last_modified_date) {\r
- if (php_sapi_name()=='cgi')\r
- header("Status: 304 Not Modified");\r
- else\r
- header("HTTP/1.1 304 Not Modified");\r
-\r
- } else {\r
- header("Last-Modified: ".$_gmt_mtime);\r
- echo $_smarty_results;\r
- }\r
- } else {\r
- echo $_smarty_results;\r
- }\r
- error_reporting($_smarty_old_error_level);\r
- // restore initial cache_info\r
- $this->_cache_info = array_pop($_cache_info);\r
- return true;\r
- } else {\r
- error_reporting($_smarty_old_error_level);\r
- // restore initial cache_info\r
- $this->_cache_info = array_pop($_cache_info);\r
- return $_smarty_results;\r
- }\r
- } else {\r
- $this->_cache_info['template'][$resource_name] = true;\r
- if ($this->cache_modified_check) {\r
- header("Last-Modified: ".gmdate('D, d M Y H:i:s', time()).' GMT');\r
- }\r
- }\r
- }\r
-\r
- // load filters that are marked as autoload\r
- if (count($this->autoload_filters)) {\r
- foreach ($this->autoload_filters as $_filter_type => $_filters) {\r
- foreach ($_filters as $_filter) {\r
- $this->load_filter($_filter_type, $_filter);\r
- }\r
- }\r
- }\r
-\r
- $_smarty_compile_path = $this->_get_compile_path($resource_name);\r
-\r
- // if we just need to display the results, don't perform output\r
- // buffering - for speed\r
- $_cache_including = $this->_cache_including;\r
- $this->_cache_including = false;\r
- if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {\r
- if ($this->_is_compiled($resource_name, $_smarty_compile_path)\r
- || $this->_compile_resource($resource_name, $_smarty_compile_path))\r
- {\r
- include($_smarty_compile_path);\r
- }\r
- } else {\r
- ob_start();\r
- if ($this->_is_compiled($resource_name, $_smarty_compile_path)\r
- || $this->_compile_resource($resource_name, $_smarty_compile_path))\r
- {\r
- include($_smarty_compile_path);\r
- }\r
- $_smarty_results = ob_get_contents();\r
- ob_end_clean();\r
-\r
- foreach ((array)$this->_plugins['outputfilter'] as $_output_filter) {\r
- $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this));\r
- }\r
- }\r
-\r
- if ($this->caching) {\r
- $_params = array('tpl_file' => $resource_name,\r
- 'cache_id' => $cache_id,\r
- 'compile_id' => $compile_id,\r
- 'results' => $_smarty_results);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_cache_file.php');\r
- smarty_core_write_cache_file($_params, $this);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.process_cached_inserts.php');\r
- $_smarty_results = smarty_core_process_cached_inserts($_params, $this);\r
-\r
- if ($this->_cache_serials) {\r
- // strip nocache-tags from output\r
- $_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s'\r
- ,''\r
- ,$_smarty_results);\r
- }\r
- // restore initial cache_info\r
- $this->_cache_info = array_pop($_cache_info);\r
- }\r
- $this->_cache_including = $_cache_including;\r
-\r
- if ($display) {\r
- if (isset($_smarty_results)) { echo $_smarty_results; }\r
- if ($this->debugging) {\r
- // capture time for debugging info\r
- $_params = array();\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');\r
- $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.display_debug_console.php');\r
- echo smarty_core_display_debug_console($_params, $this);\r
- }\r
- error_reporting($_smarty_old_error_level);\r
- return;\r
- } else {\r
- error_reporting($_smarty_old_error_level);\r
- if (isset($_smarty_results)) { return $_smarty_results; }\r
- }\r
- }\r
-\r
- /**\r
- * load configuration values\r
- *\r
- * @param string $file\r
- * @param string $section\r
- * @param string $scope\r
- */\r
- function config_load($file, $section = null, $scope = 'global')\r
- {\r
- require_once($this->_get_plugin_filepath('function', 'config_load'));\r
- smarty_function_config_load(array('file' => $file, 'section' => $section, 'scope' => $scope), $this);\r
- }\r
-\r
- /**\r
- * return a reference to a registered object\r
- *\r
- * @param string $name\r
- * @return object\r
- */\r
- function &get_registered_object($name) {\r
- if (!isset($this->_reg_objects[$name]))\r
- $this->_trigger_fatal_error("'$name' is not a registered object");\r
-\r
- if (!is_object($this->_reg_objects[$name][0]))\r
- $this->_trigger_fatal_error("registered '$name' is not an object");\r
-\r
- return $this->_reg_objects[$name][0];\r
- }\r
-\r
- /**\r
- * clear configuration values\r
- *\r
- * @param string $var\r
- */\r
- function clear_config($var = null)\r
- {\r
- if(!isset($var)) {\r
- // clear all values\r
- $this->_config = array(array('vars' => array(),\r
- 'files' => array()));\r
- } else {\r
- unset($this->_config[0]['vars'][$var]);\r
- }\r
- }\r
-\r
- /**\r
- * get filepath of requested plugin\r
- *\r
- * @param string $type\r
- * @param string $name\r
- * @return string|false\r
- */\r
- function _get_plugin_filepath($type, $name)\r
- {\r
- $_params = array('type' => $type, 'name' => $name);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.assemble_plugin_filepath.php');\r
- return smarty_core_assemble_plugin_filepath($_params, $this);\r
- }\r
-\r
- /**\r
- * test if resource needs compiling\r
- *\r
- * @param string $resource_name\r
- * @param string $compile_path\r
- * @return boolean\r
- */\r
- function _is_compiled($resource_name, $compile_path)\r
- {\r
- if (!$this->force_compile && file_exists($compile_path)) {\r
- if (!$this->compile_check) {\r
- // no need to check compiled file\r
- return true;\r
- } else {\r
- // get file source and timestamp\r
- $_params = array('resource_name' => $resource_name, 'get_source'=>false);\r
- if (!$this->_fetch_resource_info($_params, $this)) {\r
- return false;\r
- }\r
- if ($_params['resource_timestamp'] <= filemtime($compile_path)) {\r
- // template not expired, no recompile\r
- return true;\r
- } else {\r
- // compile template\r
- return false;\r
- }\r
- }\r
- } else {\r
- // compiled template does not exist, or forced compile\r
- return false;\r
- }\r
- }\r
-\r
- /**\r
- * compile the template\r
- *\r
- * @param string $resource_name\r
- * @param string $compile_path\r
- * @return boolean\r
- */\r
- function _compile_resource($resource_name, $compile_path)\r
- {\r
-\r
- $_params = array('resource_name' => $resource_name);\r
- if (!$this->_fetch_resource_info($_params)) {\r
- return false;\r
- }\r
-\r
- $_source_content = $_params['source_content'];\r
- $_resource_timestamp = $_params['resource_timestamp'];\r
- $_cache_include = substr($compile_path, 0, -4).'.inc';\r
-\r
- if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) {\r
- // if a _cache_serial was set, we also have to write an include-file:\r
- if ($this->_cache_include_info) {\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_include.php');\r
- smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content)), $this);\r
- }\r
-\r
- $_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content, 'resource_timestamp' => $_resource_timestamp);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_resource.php');\r
- smarty_core_write_compiled_resource($_params, $this);\r
-\r
- return true;\r
- } else {\r
- $this->trigger_error($smarty_compiler->_error_msg);\r
- return false;\r
- }\r
-\r
- }\r
-\r
- /**\r
- * compile the given source\r
- *\r
- * @param string $resource_name\r
- * @param string $source_content\r
- * @param string $compiled_content\r
- * @return boolean\r
- */\r
- function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null)\r
- {\r
- if (file_exists(SMARTY_DIR . $this->compiler_file)) {\r
- require_once(SMARTY_DIR . $this->compiler_file);\r
- } else {\r
- // use include_path\r
- require_once($this->compiler_file);\r
- }\r
-\r
-\r
- $smarty_compiler = new $this->compiler_class;\r
-\r
- $smarty_compiler->template_dir = $this->template_dir;\r
- $smarty_compiler->compile_dir = $this->compile_dir;\r
- $smarty_compiler->plugins_dir = $this->plugins_dir;\r
- $smarty_compiler->config_dir = $this->config_dir;\r
- $smarty_compiler->force_compile = $this->force_compile;\r
- $smarty_compiler->caching = $this->caching;\r
- $smarty_compiler->php_handling = $this->php_handling;\r
- $smarty_compiler->left_delimiter = $this->left_delimiter;\r
- $smarty_compiler->right_delimiter = $this->right_delimiter;\r
- $smarty_compiler->_version = $this->_version;\r
- $smarty_compiler->security = $this->security;\r
- $smarty_compiler->secure_dir = $this->secure_dir;\r
- $smarty_compiler->security_settings = $this->security_settings;\r
- $smarty_compiler->trusted_dir = $this->trusted_dir;\r
- $smarty_compiler->_reg_objects = &$this->_reg_objects;\r
- $smarty_compiler->_plugins = &$this->_plugins;\r
- $smarty_compiler->_tpl_vars = &$this->_tpl_vars;\r
- $smarty_compiler->default_modifiers = $this->default_modifiers;\r
- $smarty_compiler->compile_id = $this->_compile_id;\r
- $smarty_compiler->_config = $this->_config;\r
- $smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals;\r
-\r
- $smarty_compiler->_cache_serial = null;\r
- $smarty_compiler->_cache_include = $cache_include_path;\r
-\r
-\r
- $_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content);\r
-\r
- if ($smarty_compiler->_cache_serial) {\r
- $this->_cache_include_info = array(\r
- 'cache_serial'=>$smarty_compiler->_cache_serial\r
- ,'plugins_code'=>$smarty_compiler->_plugins_code\r
- ,'include_file_path' => $cache_include_path);\r
-\r
- } else {\r
- $this->_cache_include_info = null;\r
-\r
- }\r
-\r
- return $_results;\r
- }\r
-\r
- /**\r
- * Get the compile path for this resource\r
- *\r
- * @param string $resource_name\r
- * @return string results of {@link _get_auto_filename()}\r
- */\r
- function _get_compile_path($resource_name)\r
- {\r
- return $this->_get_auto_filename($this->compile_dir, $resource_name,\r
- $this->_compile_id) . '.php';\r
- }\r
-\r
- /**\r
- * fetch the template info. Gets timestamp, and source\r
- * if get_source is true\r
- *\r
- * sets $source_content to the source of the template, and\r
- * $resource_timestamp to its time stamp\r
- * @param string $resource_name\r
- * @param string $source_content\r
- * @param integer $resource_timestamp\r
- * @param boolean $get_source\r
- * @param boolean $quiet\r
- * @return boolean\r
- */\r
-\r
- function _fetch_resource_info(&$params)\r
- {\r
- if(!isset($params['get_source'])) { $params['get_source'] = true; }\r
- if(!isset($params['quiet'])) { $params['quiet'] = false; }\r
-\r
- $_return = false;\r
- $_params = array('resource_name' => $params['resource_name']) ;\r
- if (isset($params['resource_base_path']))\r
- $_params['resource_base_path'] = $params['resource_base_path'];\r
-\r
- if ($this->_parse_resource_name($_params)) {\r
- $_resource_type = $_params['resource_type'];\r
- $_resource_name = $_params['resource_name'];\r
- switch ($_resource_type) {\r
- case 'file':\r
- if ($params['get_source']) {\r
- $params['source_content'] = $this->_read_file($_resource_name);\r
- }\r
- $params['resource_timestamp'] = filemtime($_resource_name);\r
- $_return = is_file($_resource_name);\r
- break;\r
-\r
- default:\r
- // call resource functions to fetch the template source and timestamp\r
- if ($params['get_source']) {\r
- $_source_return = isset($this->_plugins['resource'][$_resource_type]) &&\r
- call_user_func_array($this->_plugins['resource'][$_resource_type][0][0],\r
- array($_resource_name, &$params['source_content'], &$this));\r
- } else {\r
- $_source_return = true;\r
- }\r
-\r
- $_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) &&\r
- call_user_func_array($this->_plugins['resource'][$_resource_type][0][1],\r
- array($_resource_name, &$params['resource_timestamp'], &$this));\r
-\r
- $_return = $_source_return && $_timestamp_return;\r
- break;\r
- }\r
- }\r
-\r
- if (!$_return) {\r
- // see if we can get a template with the default template handler\r
- if (!empty($this->default_template_handler_func)) {\r
- if (!is_callable($this->default_template_handler_func)) {\r
- $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist.");\r
- } else {\r
- $_return = call_user_func_array(\r
- $this->default_template_handler_func,\r
- array($_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this));\r
- }\r
- }\r
- }\r
-\r
- if (!$_return) {\r
- if (!$params['quiet']) {\r
- $this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"');\r
- }\r
- } else if ($_return && $this->security) {\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_secure.php');\r
- if (!smarty_core_is_secure($_params, $this)) {\r
- if (!$params['quiet'])\r
- $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed');\r
- $params['source_content'] = null;\r
- $params['resource_timestamp'] = null;\r
- return false;\r
- }\r
- }\r
- return $_return;\r
- }\r
-\r
-\r
- /**\r
- * parse out the type and name from the resource\r
- *\r
- * @param string $resource_base_path\r
- * @param string $resource_name\r
- * @param string $resource_type\r
- * @param string $resource_name\r
- * @return boolean\r
- */\r
-\r
- function _parse_resource_name(&$params)\r
- {\r
-\r
- // split tpl_path by the first colon\r
- $_resource_name_parts = explode(':', $params['resource_name'], 2);\r
-\r
- if (count($_resource_name_parts) == 1) {\r
- // no resource type given\r
- $params['resource_type'] = $this->default_resource_type;\r
- $params['resource_name'] = $_resource_name_parts[0];\r
- } else {\r
- if(strlen($_resource_name_parts[0]) == 1) {\r
- // 1 char is not resource type, but part of filepath\r
- $params['resource_type'] = $this->default_resource_type;\r
- $params['resource_name'] = $params['resource_name'];\r
- } else {\r
- $params['resource_type'] = $_resource_name_parts[0];\r
- $params['resource_name'] = $_resource_name_parts[1];\r
- }\r
- }\r
-\r
- if ($params['resource_type'] == 'file') {\r
- if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $params['resource_name'])) {\r
- // relative pathname to $params['resource_base_path']\r
- // use the first directory where the file is found\r
- if (isset($params['resource_base_path'])) {\r
- $_resource_base_path = (array)$params['resource_base_path'];\r
- } else {\r
- $_resource_base_path = (array)$this->template_dir;\r
- $_resource_base_path[] = '.';\r
- }\r
- foreach ($_resource_base_path as $_curr_path) {\r
- $_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name'];\r
- if (file_exists($_fullpath) && is_file($_fullpath)) {\r
- $params['resource_name'] = $_fullpath;\r
- return true;\r
- }\r
- // didn't find the file, try include_path\r
- $_params = array('file_path' => $_fullpath);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php');\r
- if(smarty_core_get_include_path($_params, $this)) {\r
- $params['resource_name'] = $_params['new_file_path'];\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
- } elseif (empty($this->_plugins['resource'][$params['resource_type']])) {\r
- $_params = array('type' => $params['resource_type']);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_resource_plugin.php');\r
- smarty_core_load_resource_plugin($_params, $this);\r
- }\r
-\r
- return true;\r
- }\r
-\r
-\r
- /**\r
- * Handle modifiers\r
- *\r
- * @param string|null $modifier_name\r
- * @param array|null $map_array\r
- * @return string result of modifiers\r
- */\r
- function _run_mod_handler()\r
- {\r
- $_args = func_get_args();\r
- list($_modifier_name, $_map_array) = array_splice($_args, 0, 2);\r
- list($_func_name, $_tpl_file, $_tpl_line) =\r
- $this->_plugins['modifier'][$_modifier_name];\r
-\r
- $_var = $_args[0];\r
- foreach ($_var as $_key => $_val) {\r
- $_args[0] = $_val;\r
- $_var[$_key] = call_user_func_array($_func_name, $_args);\r
- }\r
- return $_var;\r
- }\r
-\r
- /**\r
- * Remove starting and ending quotes from the string\r
- *\r
- * @param string $string\r
- * @return string\r
- */\r
- function _dequote($string)\r
- {\r
- if (($string{0} == "'" || $string{0} == '"') &&\r
- $string{strlen($string)-1} == $string{0})\r
- return substr($string, 1, -1);\r
- else\r
- return $string;\r
- }\r
-\r
-\r
- /**\r
- * read in a file from line $start for $lines.\r
- * read the entire file if $start and $lines are null.\r
- *\r
- * @param string $filename\r
- * @param integer $start\r
- * @param integer $lines\r
- * @return string\r
- */\r
- function _read_file($filename, $start=null, $lines=null)\r
- {\r
- if (!($fd = @fopen($filename, 'r'))) {\r
- return false;\r
- }\r
- flock($fd, LOCK_SH);\r
- if ($start == null && $lines == null) {\r
- // read the entire file\r
- $contents = fread($fd, filesize($filename));\r
- } else {\r
- if ( $start > 1 ) {\r
- // skip the first lines before $start\r
- for ($loop=1; $loop < $start; $loop++) {\r
- fgets($fd, 65536);\r
- }\r
- }\r
- if ( $lines == null ) {\r
- // read the rest of the file\r
- while (!feof($fd)) {\r
- $contents .= fgets($fd, 65536);\r
- }\r
- } else {\r
- // read up to $lines lines\r
- for ($loop=0; $loop < $lines; $loop++) {\r
- $contents .= fgets($fd, 65536);\r
- if (feof($fd)) {\r
- break;\r
- }\r
- }\r
- }\r
- }\r
- fclose($fd);\r
- return $contents;\r
- }\r
-\r
- /**\r
- * get a concrete filename for automagically created content\r
- *\r
- * @param string $auto_base\r
- * @param string $auto_source\r
- * @param string $auto_id\r
- * @return string\r
- * @staticvar string|null\r
- * @staticvar string|null\r
- */\r
- function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null)\r
- {\r
- $_compile_dir_sep = $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';\r
-\r
- if(@is_dir($auto_base)) {\r
- $_return = $auto_base . DIRECTORY_SEPARATOR;\r
- } else {\r
- // auto_base not found, try include_path\r
- $_params = array('file_path' => $auto_base);\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php');\r
- smarty_core_get_include_path($_params, $this);\r
- $_return = isset($_params['new_file_path']) ? $_params['new_file_path'] . DIRECTORY_SEPARATOR : null;\r
- }\r
-\r
- if(isset($auto_id)) {\r
- // make auto_id safe for directory names\r
- $auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id)));\r
- // split into separate directories\r
- $_return .= $auto_id . $_compile_dir_sep;\r
- }\r
-\r
- if(isset($auto_source)) {\r
- // make source name safe for filename\r
- $_filename = urlencode(basename($auto_source));\r
- $_crc32 = crc32($auto_source) . $_compile_dir_sep;\r
- // prepend %% to avoid name conflicts with\r
- // with $params['auto_id'] names\r
- $_crc32 = '%%' . substr($_crc32,0,3) . $_compile_dir_sep . '%%' . $_crc32;\r
- $_return .= $_crc32 . $_filename;\r
- }\r
-\r
- return $_return;\r
- }\r
-\r
- /**\r
- * unlink a file, possibly using expiration time\r
- *\r
- * @param string $resource\r
- * @param integer $exp_time\r
- */\r
- function _unlink($resource, $exp_time = null)\r
- {\r
- if(isset($exp_time)) {\r
- if(time() - @filemtime($resource) >= $exp_time) {\r
- return @unlink($resource);\r
- }\r
- } else {\r
- return @unlink($resource);\r
- }\r
- }\r
-\r
- /**\r
- * returns an auto_id for auto-file-functions\r
- *\r
- * @param string $cache_id\r
- * @param string $compile_id\r
- * @return string|null\r
- */\r
- function _get_auto_id($cache_id=null, $compile_id=null) {\r
- if (isset($cache_id))\r
- return (isset($compile_id)) ? $cache_id . '|' . $compile_id : $cache_id;\r
- elseif(isset($compile_id))\r
- return $compile_id;\r
- else\r
- return null;\r
- }\r
-\r
- /**\r
- * trigger Smarty plugin error\r
- *\r
- * @param string $error_msg\r
- * @param string $tpl_file\r
- * @param integer $tpl_line\r
- * @param string $file\r
- * @param integer $line\r
- * @param integer $error_type\r
- */\r
- function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null,\r
- $file = null, $line = null, $error_type = E_USER_ERROR)\r
- {\r
- if(isset($file) && isset($line)) {\r
- $info = ' ('.basename($file).", line $line)";\r
- } else {\r
- $info = null;\r
- }\r
- if (isset($tpl_line) && isset($tpl_file)) {\r
- trigger_error("Smarty error: [in " . $tpl_file . " line " .\r
- $tpl_line . "]: $error_msg$info", $error_type);\r
- } else {\r
- trigger_error("Smarty error: $error_msg$info", $error_type);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * callback function for preg_replace, to call a non-cacheable block\r
- * @return string\r
- */\r
- function _process_compiled_include_callback($match) {\r
- $_func = '_smarty_tplfunc_'.$match[2].'_'.$match[3];\r
- ob_start();\r
- $_func($this);\r
- $_ret = ob_get_contents();\r
- ob_end_clean();\r
- return $_ret;\r
- }\r
-\r
-\r
- /**\r
- * called for included templates\r
- *\r
- * @param string $_smarty_include_tpl_file\r
- * @param string $_smarty_include_vars\r
- */\r
-\r
- // $_smarty_include_tpl_file, $_smarty_include_vars\r
-\r
- function _smarty_include($params)\r
- {\r
- if ($this->debugging) {\r
- $_params = array();\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');\r
- $debug_start_time = smarty_core_get_microtime($_params, $this);\r
- $this->_smarty_debug_info[] = array('type' => 'template',\r
- 'filename' => $params['smarty_include_tpl_file'],\r
- 'depth' => ++$this->_inclusion_depth);\r
- $included_tpls_idx = count($this->_smarty_debug_info) - 1;\r
- }\r
-\r
- $this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']);\r
-\r
- // config vars are treated as local, so push a copy of the\r
- // current ones onto the front of the stack\r
- array_unshift($this->_config, $this->_config[0]);\r
-\r
- $_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']);\r
-\r
-\r
- if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path)\r
- || $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path))\r
- {\r
- include($_smarty_compile_path);\r
- }\r
-\r
- // pop the local vars off the front of the stack\r
- array_shift($this->_config);\r
-\r
- $this->_inclusion_depth--;\r
-\r
- if ($this->debugging) {\r
- // capture time for debugging info\r
- $_params = array();\r
- require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');\r
- $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time;\r
- }\r
-\r
- if ($this->caching) {\r
- $this->_cache_info['template'][$params['smarty_include_tpl_file']] = true;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * get or set an array of cached attributes for function that is\r
- * not cacheable\r
- * @return array\r
- */\r
- function &_smarty_cache_attrs($cache_serial, $count) {\r
- $_cache_attrs =& $this->_cache_info['cache_attrs'][$cache_serial][$count];\r
-\r
- if ($this->_cache_including) {\r
- /* return next set of cache_attrs */\r
- $_return =& current($_cache_attrs);\r
- next($_cache_attrs);\r
- return $_return;\r
-\r
- } else {\r
- /* add a reference to a new set of cache_attrs */\r
- $_cache_attrs[] = array();\r
- return $_cache_attrs[count($_cache_attrs)-1];\r
-\r
- }\r
-\r
- }\r
-\r
-\r
- /**\r
- * wrapper for include() retaining $this\r
- * @return mixed\r
- */\r
- function _include($filename, $once=false, $params=null)\r
- {\r
- if ($once) {\r
- return include_once($filename);\r
- } else {\r
- return include($filename);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * wrapper for eval() retaining $this\r
- * @return mixed\r
- */\r
- function _eval($code, $params=null)\r
- {\r
- return eval($code);\r
- }\r
- /**#@-*/\r
-\r
-}\r
-\r
-/* vim: set expandtab: */\r
-\r
-?>\r