From a1020815a23bf90985d74eab3548dd775694d1e1 Mon Sep 17 00:00:00 2001 From: mohrt Date: Fri, 21 Feb 2003 20:17:21 +0000 Subject: [PATCH] moved lib files under libs directory --- Config_File.class.php | 359 ----- Smarty.class.php | 2696 ------------------------------------- Smarty_Compiler.class.php | 1848 ------------------------- debug.tpl | 64 - 4 files changed, 4967 deletions(-) delete mode 100644 Config_File.class.php delete mode 100644 Smarty.class.php delete mode 100644 Smarty_Compiler.class.php delete mode 100644 debug.tpl diff --git a/Config_File.class.php b/Config_File.class.php deleted file mode 100644 index 2514efaa..00000000 --- a/Config_File.class.php +++ /dev/null @@ -1,359 +0,0 @@ - - * @access public - */ - -class Config_File { - /**#@+ - * Options - * @var boolean - */ - /** - * Controls whether variables with the same name overwrite each other. - */ - var $overwrite = true; - - /** - * Controls whether config values of on/true/yes and off/false/no get - * converted to boolean values automatically. - */ - var $booleanize = true; - - /** - * Controls whether hidden config sections/vars are read from the file. - */ - var $read_hidden = true; - - /** - * Controls whether or not to fix mac or dos formatted newlines. - * If set to true, \r or \r\n will be changed to \n. - */ - var $fix_newlines = true; - /**#@-*/ - - /** @access private */ - var $_config_path = ""; - var $_config_data = array(); - var $_separator = ""; - /**#@-*/ - - /** - * Constructs a new config file class. - * - * @param string $config_path (optional) path to the config files - */ - function Config_File($config_path = NULL) - { - if (substr(PHP_OS, 0, 3) == "WIN" || substr(PHP_OS, 0, 4) == "OS/2") - $this->_separator = "\\"; - else - $this->_separator = "/"; - - if (isset($config_path)) - $this->set_path($config_path); - } - - - /** - * Set the path where configuration files can be found. - * - * @param string $config_path path to the config files - */ - function set_path($config_path) - { - if (!empty($config_path)) { - if (!is_string($config_path) || !file_exists($config_path) || !is_dir($config_path)) { - $this->_trigger_error_msg("Bad config file path '$config_path'"); - return; - } - - $this->_config_path = $config_path . $this->_separator; - } - } - - - /** - * Retrieves config info based on the file, section, and variable name. - * - * @param string $file_name config file to get info for - * @param string $section_name (optional) section to get info for - * @param string $var_name (optional) variable to get info for - * @return string|array a value or array of values - */ - function &get($file_name, $section_name = NULL, $var_name = NULL) - { - if (empty($file_name)) { - $this->_trigger_error_msg('Empty config file name'); - return; - } else { - $file_name = $this->_config_path . $file_name; - if (!isset($this->_config_data[$file_name])) - $this->load_file($file_name, false); - } - - if (!empty($var_name)) { - if (empty($section_name)) { - return $this->_config_data[$file_name]["vars"][$var_name]; - } else { - if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name])) - return $this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name]; - else - return array(); - } - } else { - if (empty($section_name)) { - return (array)$this->_config_data[$file_name]["vars"]; - } else { - if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"])) - return (array)$this->_config_data[$file_name]["sections"][$section_name]["vars"]; - else - return array(); - } - } - } - - - /** - * Retrieves config info based on the key. - * - * @param $file_name string config key (filename/section/var) - * @return string|array same as get() - * @uses get() retrieves information from config file and returns it - */ - function &get_key($config_key) - { - list($file_name, $section_name, $var_name) = explode('/', $config_key, 3); - $result = &$this->get($file_name, $section_name, $var_name); - return $result; - } - - /** - * Get all loaded config file names. - * - * @return array an array of loaded config file names - */ - function get_file_names() - { - return array_keys($this->_config_data); - } - - - /** - * Get all section names from a loaded file. - * - * @param string $file_name config file to get section names from - * @return array an array of section names from the specified file - */ - function get_section_names($file_name) - { - $file_name = $this->_config_path . $file_name; - if (!isset($this->_config_data[$file_name])) { - $this->_trigger_error_msg("Unknown config file '$file_name'"); - return; - } - - return array_keys($this->_config_data[$file_name]["sections"]); - } - - - /** - * Get all global or section variable names. - * - * @param string $file_name config file to get info for - * @param string $section_name (optional) section to get info for - * @return array an array of variables names from the specified file/section - */ - function get_var_names($file_name, $section = NULL) - { - if (empty($file_name)) { - $this->_trigger_error_msg('Empty config file name'); - return; - } else if (!isset($this->_config_data[$file_name])) { - $this->_trigger_error_msg("Unknown config file '$file_name'"); - return; - } - - if (empty($section)) - return array_keys($this->_config_data[$file_name]["vars"]); - else - return array_keys($this->_config_data[$file_name]["sections"][$section]["vars"]); - } - - - /** - * Clear loaded config data for a certain file or all files. - * - * @param string $file_name file to clear config data for - */ - function clear($file_name = NULL) - { - if ($file_name === NULL) - $this->_config_data = array(); - else if (isset($this->_config_data[$file_name])) - $this->_config_data[$file_name] = array(); - } - - - /** - * Load a configuration file manually. - * - * @param string $file_name file name to load - * @param boolean $prepend_path whether current config path should be - * prepended to the filename - */ - function load_file($file_name, $prepend_path = true) - { - if ($prepend_path && $this->_config_path != "") - $config_file = $this->_config_path . $file_name; - else - $config_file = $file_name; - - ini_set('track_errors', true); - $fp = @fopen($config_file, "r"); - if (!is_resource($fp)) { - $this->_trigger_error_msg("Could not open config file '$config_file'"); - return false; - } - - $contents = fread($fp, filesize($config_file)); - fclose($fp); - - if($this->fix_newlines) { - // fix mac/dos formatted newlines - $contents = preg_replace('!\r\n?!',"\n",$contents); - } - - $config_data = array(); - - /* Get global variables first. */ - if (preg_match("/^(.*?)(\n\[|\Z)/s", $contents, $match)) - $config_data["vars"] = $this->_parse_config_block($match[1]); - - /* Get section variables. */ - $config_data["sections"] = array(); - preg_match_all("/^\[(.*?)\]/m", $contents, $match); - foreach ($match[1] as $section) { - if ($section{0} == '.' && !$this->read_hidden) - continue; - if (preg_match("/\[".preg_quote($section)."\](.*?)(\n\[|\Z)/s", $contents, $match)) - if ($section{0} == '.') - $section = substr($section, 1); - $config_data["sections"][$section]["vars"] = $this->_parse_config_block($match[1]); - } - - $this->_config_data[$config_file] = $config_data; - - return true; - } - - /**#@+ @access private */ - /** - * @var string $config_block - */ - function _parse_config_block($config_block) - { - $vars = array(); - - /* First we grab the multi-line values. */ - if (preg_match_all("/^([^=\n]+)=\s*\"{3}(.*?)\"{3}\s*$/ms", $config_block, $match, PREG_SET_ORDER)) { - for ($i = 0; $i < count($match); $i++) { - $this->_set_config_var($vars, trim($match[$i][1]), $match[$i][2], false); - } - $config_block = preg_replace("/^[^=\n]+=\s*\"{3}.*?\"{3}\s*$/ms", "", $config_block); - } - - - $config_lines = preg_split("/\n+/", $config_block); - - foreach ($config_lines as $line) { - if (preg_match("/^\s*(\.?\w+)\s*=(.*)/", $line, $match)) { - $var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', trim($match[2])); - $this->_set_config_var($vars, trim($match[1]), $var_value, $this->booleanize); - } - } - - return $vars; - } - - /** - * @param array &$container - * @param string $var_name - * @param mixed $var_value - * @param boolean $booleanize determines whether $var_value is converted to - * to true/false - */ - function _set_config_var(&$container, $var_name, $var_value, $booleanize) - { - if ($var_name{0} == '.') { - if (!$this->read_hidden) - return; - else - $var_name = substr($var_name, 1); - } - - if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) { - $this->_trigger_error_msg("Bad variable name '$var_name'"); - return; - } - - if ($booleanize) { - if (preg_match("/^(on|true|yes)$/i", $var_value)) - $var_value = true; - else if (preg_match("/^(off|false|no)$/i", $var_value)) - $var_value = false; - } - - if (!isset($container[$var_name]) || $this->overwrite) - $container[$var_name] = $var_value; - else { - settype($container[$var_name], 'array'); - $container[$var_name][] = $var_value; - } - } - - /** - * @uses trigger_error() creates a PHP warning/error - * @param string $error_msg - * @param integer $error_type one of - */ - function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING) - { - trigger_error("Config_File error: $error_msg", $error_type); - } - /**#@-*/ -} - -?> diff --git a/Smarty.class.php b/Smarty.class.php deleted file mode 100644 index dc15943b..00000000 --- a/Smarty.class.php +++ /dev/null @@ -1,2696 +0,0 @@ - - * @author Andrei Zmievski - * @package Smarty - * @version 2.4.2 - */ - -/** - * set SMARTY_DIR to absolute path to Smarty library files. - * if not defined, include_path will be used. - */ - -define('DIR_SEP', DIRECTORY_SEPARATOR); - -/** - * 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_PHP_PASSTHRU', 0); -define('SMARTY_PHP_QUOTE', 1); -define('SMARTY_PHP_REMOVE', 2); -define('SMARTY_PHP_ALLOW', 3); - -/** - * @package Smarty - */ -class Smarty -{ - /**#@+ - * 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; - - /** - * 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. - * - * @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. - * - * @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. - * - * - * @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: - * - * - * @var integer - */ - var $php_handling = SMARTY_PHP_PASSTHRU; - - /** - * 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', - 'true','false'), - 'INCLUDE_ANY' => false, - 'PHP_TAGS' => false, - 'MODIFIER_FUNCS' => array('count'), - 'ALLOW_CONSTANTS' => false - ); - - /** - * 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 = '}'; - - /** - * 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"; - - /** - * 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 = true; - - /** - * 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(); - - /** - * 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; - - /** - * These are the variables from the globals array that are - * assigned to all templates automatically. This isn't really - * necessary any more, you can use the $smarty var to access them - * directly. - * - * @var array - */ - var $global_assign = array('HTTP_SERVER_VARS' => array('SCRIPT_NAME')); - - /** - * The value of "undefined". Leave it alone :-) - * - * @var null - */ - var $undefined = 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 - */ - /** - * error messages. true/false - * - * @var boolean - */ - var $_error_msg = false; - - /** - * 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.4.2'; - - /** - * 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(), - 'compiler' => array(), - 'prefilter' => array(), - 'postfilter' => array(), - 'outputfilter' => array(), - 'resource' => array(), - 'insert' => array()); - - /**#@-*/ - /** - * The class constructor. - * - * @uses $global_assign uses {@link assign()} to assign each corresponding - * value from $GLOBALS to the template vars - */ - 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); - } - } - } - } - - - /** - * 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 != '') { - $this->_tpl_vars[$key] = $val; - } - } - } else { - if ($tpl_var != '') - $this->_tpl_vars[$tpl_var] = $value; - } - } - - /** - * 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 != '') - $this->_tpl_vars[$tpl_var] = &$value; - } - - /** - * 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)) { - // $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'); - } - if($merge && is_array($value)) { - foreach($value as $_mkey => $_mval) { - $this->_tpl_vars[$tpl_var][$_mkey] = $_mval; - } - } else { - $this->_tpl_vars[$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'); - } - 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; - } - } - } - - - /** - * 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)) - foreach ($tpl_var as $curr_var) - unset($this->_tpl_vars[$curr_var]); - else - unset($this->_tpl_vars[$tpl_var]); - } - - - /** - * 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) - { - $this->_plugins['function'][$function] = - array($function_impl, null, null, false); - } - - /** - * Unregisters custom function - * - * @param string $function name of template function - */ - function unregister_function($function) - { - unset($this->_plugins['function'][$function]); - } - - /** - * 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 - */ - function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true) - { - settype($allowed, 'array'); - settype($smarty_args, 'boolean'); - $this->_reg_objects[$object] = - array(&$object_impl, $allowed, $smarty_args); - } - - /** - * 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) - { - $this->_plugins['block'][$block] = - array($block_impl, null, null, false); - } - - /** - * Unregisters block function - * - * @param string $block name of template function - */ - function unregister_block($block) - { - unset($this->_plugins['block'][$block]); - } - - /** - * 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) - { - $this->_plugins['compiler'][$function] = - array($function_impl, null, null, false); - } - - /** - * Unregisters compiler function - * - * @param string $function name of template function - */ - function unregister_compiler_function($function) - { - unset($this->_plugins['compiler'][$function]); - } - - /** - * 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); - } - - /** - * Unregisters modifier - * - * @param string $modifier name of template modifier - */ - function unregister_modifier($modifier) - { - unset($this->_plugins['modifier'][$modifier]); - } - - /** - * 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); - } - - /** - * Unregisters a resource - * - * @param string $type name of resource - */ - function unregister_resource($type) - { - unset($this->_plugins['resource'][$type]); - } - - /** - * 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] - = array($function, null, null, false); - } - - /** - * Unregisters a prefilter function - * - * @param string $function name of PHP function - */ - function unregister_prefilter($function) - { - unset($this->_plugins['prefilter'][$function]); - } - - /** - * 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] - = array($function, null, null, false); - } - - /** - * Unregisters a postfilter function - * - * @param string $function name of PHP function - */ - function unregister_postfilter($function) - { - unset($this->_plugins['postfilter'][$function]); - } - - /** - * 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] - = array($function, null, null, false); - } - - /** - * Unregisters an outputfilter function - * - * @param string $function name of PHP function - */ - function unregister_outputfilter($function) - { - unset($this->_plugins['outputfilter'][$function]); - } - - /** - * 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))); - break; - - case 'pre': - case 'post': - if (!isset($this->_plugins[$type . 'filter'][$name])) - $this->_plugins[$type . 'filter'][$name] = false; - break; - } - } - - /** - * 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 - */ - 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)) ? $compile_id . '|' . $cache_id : $cache_id; - elseif(isset($compile_id)) - $auto_id = $compile_id; - else - $auto_id = null; - - if (!empty($this->cache_handler_func)) { - $funcname = $this->cache_handler_func; - return $funcname('clear', $this, $dummy, $tpl_file, $cache_id, $compile_id); - } else { - return $this->_rm_auto($this->cache_dir, $tpl_file, $auto_id, $exp_time); - } - - } - - - /** - * clear the entire contents of cache (all templates) - * - * @param string $exp_time expire time - */ - 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); - } - } - - - /** - * 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 - */ - function is_cached($tpl_file, $cache_id = null, $compile_id = null) - { - if (!$this->caching) - return false; - - if (!isset($compile_id)) - $compile_id = $this->compile_id; - - return $this->_read_cache_file($tpl_file, $cache_id, $compile_id, $results); - } - - - /** - * clear all the assigned template variables. - * - */ - function clear_all_assign() - { - $this->_tpl_vars = array(); - } - - /** - * 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 - */ - function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) - { - if (!isset($compile_id)) - $compile_id = $this->compile_id; - return $this->_rm_auto($this->compile_dir, $tpl_file, $compile_id, $exp_time); - } - - /** - * Checks whether requested template exists. - * - * @param string $tpl_file - */ - function template_exists($tpl_file) - { - return $this->_fetch_template_info($tpl_file, $source, $timestamp, true, true); - } - - /** - * Returns an array containing template variables - * - * @param string $name - * @param string $type - * @return mixed - */ - function &get_template_vars($name=null) - { - 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 mixed - */ - 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]; - } - } - - /** - * 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); - } - - - /** - * executes & displays the template results - * - * @param string $tpl_file - * @param string $cache_id - * @param string $compile_id - */ - function display($tpl_file, $cache_id = null, $compile_id = null) - { - $this->fetch($tpl_file, $cache_id, $compile_id, true); - } - - /** - * executes & returns or displays the template results - * - * @param string $_smarty_tpl_file - * @param string $_smarty_cache_id - * @param string $_smarty_compile_id - * @param boolean $_smarty_display - */ - 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->security && !in_array($this->template_dir, $this->secure_dir)) { - // add template_dir to secure_dir array - array_unshift($this->secure_dir, $this->template_dir); - } - - if (!$this->debugging && $this->debugging_ctrl == 'URL' - && strstr($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'], $this->_smarty_debug_id)) { - // enable debugging from URL - $this->debugging = true; - } - - if ($this->debugging) { - // capture time for debugging info - $debug_start_time = $this->_get_microtime(); - $this->_smarty_debug_info[] = array('type' => 'template', - 'filename' => $_smarty_tpl_file, - 'depth' => 0); - $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; - $this->_inclusion_depth = 0; - - if ($this->caching) { - if(!empty($this->_cache_info)) { - // nested call, init cache_info - $_cache_info = $this->_cache_info; - $this->_cache_info = array(); - } - if ($this->_read_cache_file($_smarty_tpl_file, $_smarty_cache_id, $_smarty_compile_id, $_smarty_results)) { - if (@count($this->_cache_info['insert_tags'])) { - $this->_load_plugins($this->_cache_info['insert_tags']); - $_smarty_results = $this->_process_cached_inserts($_smarty_results); - } - if ($_smarty_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(); - } - 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'; - if (@count($this->_cache_info['insert_tags']) == 0 - && $gmt_mtime == $last_modified_date) { - header("HTTP/1.1 304 Not Modified"); - } else { - header("Last-Modified: ".$gmt_mtime); - echo $_smarty_results; - } - } else { - echo $_smarty_results; - } - error_reporting($_smarty_old_error_level); - return true; - } else { - error_reporting($_smarty_old_error_level); - return $_smarty_results; - } - } else { - $this->_cache_info['template'][] = $_smarty_tpl_file; - if ($this->cache_modified_check) { - header("Last-Modified: ".gmdate('D, d M Y H:i:s', time()).' GMT'); - } - } - if(isset($_cache_info)) { - // restore cache_info - $this->_cache_info = $_cache_info; - } - } - - if (count($this->autoload_filters)) { - $this->_autoload_filters(); - } - - $_smarty_compile_path = $this->_get_compile_path($_smarty_tpl_file); - - // 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)) - { - include($_smarty_compile_path); - } - } else { - ob_start(); - if ($this->_process_template($_smarty_tpl_file, $_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); - } - } - - 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); - } - - if ($_smarty_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(); - } - error_reporting($_smarty_old_error_level); - return; - } else { - error_reporting($_smarty_old_error_level); - if (isset($_smarty_results)) { return $_smarty_results; } - } - } - - - /** - * 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; - } - - - /** - * generate debug output - * @return string debug.tpl template output - * @uses $debug_tpl debug template, used to display debugging output - */ - function _generate_debug_output() - { - // we must force compile the debug template in case the environment - // changed between separate applications. - - if(empty($this->debug_tpl)) { - // set path to debug template from SMARTY_DIR - $this->debug_tpl = 'file:'.SMARTY_DIR.'debug.tpl'; - if($this->security && is_file($this->debug_tpl)) { - $secure_dir[] = $this->debug_tpl; - } - } - - $_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; - } - - /** - * load configuration values - * - * @param string $file - * @param string $section - * @param string $scope - */ - function config_load($file, $section = null, $scope = 'global') - { - 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); - } - - $_file_path = str_replace('//', '/' ,$_config_dir . '/' . $file); - - // get path to compiled object file - if(isset($section)) { - $_compile_file = $this->_get_auto_filename($this->compile_dir, $section . ' ' . $file); - } else { - $_compile_file = $this->_get_auto_filename($this->compile_dir, $file); - } - - // need to compile config file? - if($this->force_compile || !file_exists($_compile_file) || - ($this->compile_check && - file_exists($_file_path) && - ( filemtime($_compile_file) != filemtime($_file_path) ))) { - $_compile_config = true; - } else { - include($_compile_file); - if(!empty($_config_vars)) { - $_compile_config = true; - } else { - $_compile_config = false; - } - } - - if($_compile_config) { - if(!is_object($this->_conf_obj)) { - require_once SMARTY_DIR . $this->config_class . '.class.php'; - $this->_conf_obj = new $this->config_class($_config_dir); - $this->_conf_obj->overwrite = $this->config_overwrite; - $this->_conf_obj->booleanize = $this->config_booleanize; - $this->_conf_obj->read_hidden = $this->config_read_hidden; - $this->_conf_obj->fix_newlines = $this->config_fix_newlines; - $this->_conf_obj->set_path = $_config_dir; - } - if($_config_vars = array_merge($this->_conf_obj->get($file), - $this->_conf_obj->get($file, $section))) { - if(function_exists('var_export')) { - $_compile_data = ''; - } else { - $_compile_data = ''; - } - $this->_write_file($_compile_file, $_compile_data, true); - touch($_compile_file,filemtime($_file_path)); - } - } - - if ($this->debugging) { - $debug_start_time = $this->_get_microtime(); - } - - if ($this->caching) { - $this->_cache_info['config'][] = $file; - } - - $this->_config[0]['vars'] = @array_merge($this->_config[0]['vars'], $_config_vars); - $this->_config[0]['files'][$file] = true; - - if ($scope == 'parent') { - $this->_config[1]['vars'] = @array_merge($this->_config[1]['vars'], $_config_vars); - $this->_config[1]['files'][$file] = true; - } 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'], $_config_vars); - $this->_config[$i]['files'][$file] = true; - } - } - - 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); - } - - } - - /** - * return a reference to a registered object - * - * @param string $name - */ - function &get_registered_object($name) { - if (!isset($this->_reg_objects[$object])) - $this->_trigger_fatal_error("'$object' is not a registered object"); - - if (!is_object($this->_reg_objects[$object][0])) - $this->_trigger_fatal_error("registered '$object' is not an object"); - - return $this->_reg_objects[$name][0]; - } - - /**#@+ - * @access private - */ - /** - * determines if a resource is trusted or not - * - * @param string $resource_type - * @param string $resource_name - */ - 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); - } - - return $_smarty_trusted; - } - - - /** - * determines if a resource is secure or not. - * - * @param string $resource_type - * @param string $resource_name - */ - function _is_secure($resource_type, $resource_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; - } - - - /** - * Retrieves PHP script resource - * - * sets $php_resource to the returned resource - * @param string $resource - * @param string $resource_type - * @param $php_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(file_exists($resource_name) && is_readable($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; - $template_source = null; - $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; - } - - - /** - * umm... process the template - * - * @param string $tpl_file - * @param string $compile_path - */ - function _process_template($tpl_file, $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 - return true; - } else { - // get template source and timestamp - if (!$this->_fetch_template_info($tpl_file, $template_source, - $template_timestamp)) { - return false; - } - if ($template_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; - } - } - } 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; - } - } - - /** - * Get the compile path for this template file - * - * @param string $tpl_file - */ - function _get_compile_path($tpl_file) - { - return $this->_get_auto_filename($this->compile_dir, $tpl_file, - $this->_compile_id); - } - - /** - * write the compiled template - * - * @param string $compile_path - * @param string $template_compiled - * @param integer $template_timestamp - * @return true - */ - 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; - } - - /** - * parse out the type and name from the template resource - * - * @param string $file_base_path - * @param string $file_path - * @param string $resource_type - * @param string $resource_name - */ - function _parse_file_path($file_base_path, $file_path, &$resource_type, &$resource_name) - { - // 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); - } - } - - 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 (file_exists($_fullpath) && 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; - } - } - - // resource type != file - return true; - } - - - /** - * fetch the template info. Gets timestamp, and source - * if get_source is true - * - * sets $template_source to the source of the template, and - * $template_timestamp to its time stamp - * @param string $tpl_path - * @param string $template_source - * @param integer $template_timestamp - * @param boolean $get_source - * @param boolean $quiet - */ - 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; - - 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."); - } else { - $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 false; - } - - return $_return; - } - - - /** - * called to compile the templates - * - * sets $template_compiled to the compiled template - * @param string $tpl_file - * @param string $template_source - * @param string $template_compiled - */ - function _compile_template($tpl_file, $template_source, &$template_compiled) - { - 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; - - $smarty_compiler->template_dir = $this->template_dir; - $smarty_compiler->compile_dir = $this->compile_dir; - $smarty_compiler->plugins_dir = $this->plugins_dir; - $smarty_compiler->config_dir = $this->config_dir; - $smarty_compiler->force_compile = $this->force_compile; - $smarty_compiler->caching = $this->caching; - $smarty_compiler->php_handling = $this->php_handling; - $smarty_compiler->left_delimiter = $this->left_delimiter; - $smarty_compiler->right_delimiter = $this->right_delimiter; - $smarty_compiler->_version = $this->_version; - $smarty_compiler->security = $this->security; - $smarty_compiler->secure_dir = $this->secure_dir; - $smarty_compiler->security_settings = $this->security_settings; - $smarty_compiler->trusted_dir = $this->trusted_dir; - $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; - - if ($smarty_compiler->_compile_file($tpl_file, $template_source, $template_compiled)) { - return true; - } else { - $this->trigger_error($smarty_compiler->_error_msg); - return false; - } - } - - /** - * called for included templates - * - * @param string $_smarty_include_tpl_file - * @param string $_smarty_include_vars - */ - 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; - } - - $this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars); - - // 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]); - - $_smarty_compile_path = $this->_get_compile_path($_smarty_include_tpl_file); - - if ($this->_process_template($_smarty_include_tpl_file, $_smarty_compile_path)) { - include($_smarty_compile_path); - } - - // pop the local vars off the front of the stack - array_shift($this->_config); - - $this->_inclusion_depth--; - - 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; - } - } - - /** - * called for included templates - * - * @param string $_smarty_include_php_file - * @param string $_smarty_assign variable to assign the included template's - * output into - * @param boolean $_smarty_once uses include_once if this is true - * @param array $_smarty_include_vars associative array of vars from - * {include file="blah" var=$var} - */ - function _smarty_include_php($_smarty_include_php_file, $_smarty_assign, $_smarty_once, $_smarty_include_vars) - { - $this->_get_php_resource($_smarty_include_php_file, $_smarty_resource_type, - $_smarty_php_resource); - - extract($_smarty_include_vars, EXTR_PREFIX_SAME, 'include_php_'); - - 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); - } - } - } - - - /** - * 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]); - } - } - - - /** - * Replace cached inserts with the actual results - * - * @param string $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; - - for ($i = 0, $for_max = count($cached_inserts); $i < $for_max; $i++) { - if ($this->debugging) { - $debug_start_time = $this->_get_microtime(); - } - - $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); - } else { - eval($php_resource); - } - 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); - } - } - - return $results; - } - - - /** - * Handle insert tags - * - * @param array $args - */ - function _run_insert_handler($args) - { - if ($this->debugging) { - $debug_start_time = $this->_get_microtime(); - } - - 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; - } - - if ($resource_type == 'file') { - include_once($php_resource); - } else { - eval($php_resource); - } - 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 (!empty($args["assign"])) { - $this->assign($args["assign"], $content); - } else { - return $content; - } - } - } - - - /** - * Handle 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); - } - } - - - /** - * Remove starting and ending quotes from the string - * - * @param string $string - */ - function _dequote($string) - { - if (($string{0} == "'" || $string{0} == '"') && - $string{strlen($string)-1} == $string{0}) - return substr($string, 1, -1); - else - return $string; - } - - - /** - * 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 - */ - function _read_file($filename, $start=null, $lines=null) - { - 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)); - } 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; - } - } - } - } - fclose($fd); - return $contents; - } - - /** - * write out a file to disk - * - * @param string $filename - * @param string $contents - * @param boolean $create_dirs - */ - function _write_file($filename, $contents, $create_dirs = false) - { - if ($create_dirs) - $this->_create_dir_structure(dirname($filename)); - - 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, $this->_file_perms); - } - - return true; - } - - /** - * get a concrete filename for automagically created content - * - * @param string $auto_base - * @param string $auto_source - * @param string $auto_id - */ - 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; - } - - /** - * delete an automagically created file by name and id - * - * @param string $auto_base - * @param string $auto_source - * @param string $auto_id - * @param integer $exp_time - */ - 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; - } - - /** - * delete a dir recursively (level=0 -> keep root) - * WARNING: no tests, it will try to remove what you tell it! - * - * @param string $dirname - * @param integer $level - * @param integer $exp_time - */ - function _rmdir($dirname, $level = 1, $exp_time = null) - { - - if($handle = @opendir($dirname)) { - - while (null != ($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; - } - } - - /** - * 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); - } - } - - /** - * create full directory structure - * - * @param string $dir - */ - 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, $this->_dir_perms)) { - $this->trigger_error("problem creating directory \"$dir\""); - return false; - } - $_new_dir .= DIR_SEP; - } - } - } - - /** - * Prepend the cache information to the cache file - * and write it - * - * @param string $tpl_file - * @param string $cache_id - * @param string $compile_id - * @param string $results - */ - function _write_cache_file($tpl_file, $cache_id, $compile_id, $results) - { - // 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; - } else { - // cache will never expire - $this->_cache_info['expires'] = -1; - } - - // 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); - } else { - // use local cache file - if (isset($cache_id)) - $auto_id = (isset($compile_id)) ? $compile_id . '|' . $cache_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; - } - } - - /** - * read a cache file, determine if it needs to be - * regenerated or not - * - * @param string $tpl_file - * @param string $cache_id - * @param string $compile_id - * @param string $results - */ - 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; - } - - 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)) ? $compile_id . '|' . $cache_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); - $results = $this->_read_file($cache_file); - } - - if (empty($results)) { - // nothing to parse (error?), regenerate cache - return false; - } - - $cache_split = explode("\n", $results, 2); - $cache_header = $cache_split[0]; - - $this->_cache_info = unserialize($cache_header); - - 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; - } - } - - 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; - } - } - - 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; - } - - /** - * get filepath of requested plugin - * - * @param string $type - * @param string $name - */ - 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; - } - } - - // 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; - } - - /** - * Load requested plugins - * - * @param array $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_fatal_error("[plugin] $type '$name' is not implemented", $tpl_file, $tpl_line, __FILE__, __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); - - if (! $found = ($plugin_file != false)) { - $message = "could not load plugin file '$type.$name.php'\n"; - } - - /* - * 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_fatal_error("[plugin] function $plugin_func() not found in $plugin_file", $tpl_file, $tpl_line, __FILE__, __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 ($found) { - $this->_plugins[$type][$name] = array($plugin_func, $tpl_file, $tpl_line, true); - } else { - // output error - $this->_trigger_fatal_error('[plugin] ' . $message, $tpl_file, $tpl_line, __FILE__, __LINE__); - } - } - } - - /** - * load a resource plugin - * - * @param string $type - */ - 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_fatal_error("[plugin] resource '$type' is not implemented", null, null, __FILE__, __LINE__); - } - - return; - } - - $plugin_file = $this->_get_plugin_filepath('resource', $type); - $found = ($plugin_file != false); - - 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_fatal_error("[plugin] function $plugin_func() not found in $plugin_file", null, null, __FILE__, __LINE__); - return; - } else { - $resource_funcs[] = $plugin_func; - } - } - - $this->_plugins['resource'][$type] = array($resource_funcs, true); - } - } - - /** - * 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); - } - } - } - - /** - * Quote subpattern references - * - * @param string $string - */ - function quote_replace($string) - { - return preg_replace('![\\$]\d!', '\\\\\\0', $string); - } - - - /** - * 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) - { - if(isset($file) && isset($line)) { - $info = ' ('.basename($file).", line $line)"; - } else { - $info = null; - } - if (isset($tpl_line) && isset($tpl_file)) { - trigger_error("Smarty error: [in " . $tpl_file . " line " . - $tpl_line . "]: $error_msg$info", $error_type); - } else { - trigger_error("Smarty error: $error_msg$info", $error_type); - } - } - - /** - * Get seconds and microseconds - * @return double - */ - function _get_microtime() - { - $mtime = microtime(); - $mtime = explode(" ", $mtime); - $mtime = (double)($mtime[1]) + (double)($mtime[0]); - return ($mtime); - } - - /** - * Get path to file from include_path - * - * @param string $file_path - * @param string $new_file_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: */ - -?> diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php deleted file mode 100644 index 87697428..00000000 --- a/Smarty_Compiler.class.php +++ /dev/null @@ -1,1848 +0,0 @@ - - * @author Andrei Zmievski - * @version 2.4.2 - * @copyright 2001,2002 ispi of Lincoln, Inc. - * @package Smarty - */ - -class Smarty_Compiler extends Smarty { - - // internal vars - /**#@+ - * @access private - */ - var $_sectionelse_stack = array(); // keeps track of whether section had 'else' part - var $_foreachelse_stack = array(); // keeps track of whether foreach had 'else' part - var $_literal_blocks = array(); // keeps literal template blocks - var $_php_blocks = array(); // keeps php code blocks - var $_current_file = null; // the current template being compiled - var $_current_line_no = 1; // line number for error messages - var $_capture_stack = array(); // keeps track of nested capture buffers - var $_plugin_info = array(); // keeps track of plugins to load - var $_init_smarty_vars = false; - var $_permitted_tokens = array('true','false','yes','no','on','off','null'); - var $_db_qstr_regexp = null; // regexps are setup in the constructor - var $_si_qstr_regexp = null; - var $_qstr_regexp = null; - var $_func_regexp = null; - var $_var_bracket_regexp = null; - var $_dvar_guts_regexp = null; - var $_dvar_regexp = null; - var $_cvar_regexp = null; - var $_svar_regexp = null; - var $_avar_regexp = null; - var $_mod_regexp = null; - var $_var_regexp = null; - var $_parenth_param_regexp = null; - var $_func_call_regexp = null; - var $_obj_ext_regexp = null; - var $_obj_start_regexp = null; - var $_obj_params_regexp = null; - var $_obj_call_regexp = null; - /**#@-*/ - /** - * The class constructor. - */ - function Smarty_Compiler() - { - // matches double quoted strings: - // "foobar" - // "foo\"bar" - $this->_db_qstr_regexp = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"'; - - // matches single quoted strings: - // 'foobar' - // 'foo\'bar' - $this->_si_qstr_regexp = '\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\''; - - // matches single or double quoted strings - $this->_qstr_regexp = '(?:' . $this->_db_qstr_regexp . '|' . $this->_si_qstr_regexp . ')'; - - // matches bracket portion of vars - // [0] - // [foo] - // [$bar] - $this->_var_bracket_regexp = '\[\$?[\w\.]+\]'; - - // matches $ vars (not objects): - // $foo - // $foo.bar - // $foo.bar.foobar - // $foo[0] - // $foo[$bar] - // $foo[5][blah] - // $foo[5].bar[$foobar][4] - $this->_dvar_guts_regexp = '\w+(?:' . $this->_var_bracket_regexp - . ')*(?:\.\$?\w+(?:' . $this->_var_bracket_regexp . ')*)*'; - $this->_dvar_regexp = '\$' . $this->_dvar_guts_regexp; - - // matches config vars: - // #foo# - // #foobar123_foo# - $this->_cvar_regexp = '\#\w+\#'; - - // matches section vars: - // %foo.bar% - $this->_svar_regexp = '\%\w+\.\w+\%'; - - // matches all valid variables (no quotes, no modifiers) - $this->_avar_regexp = '(?:' . $this->_dvar_regexp . '|' - . $this->_cvar_regexp . '|' . $this->_svar_regexp . ')'; - - // matches valid variable syntax: - // $foo - // $foo - // #foo# - // #foo# - // "text" - // "text" - $this->_var_regexp = '(?:' . $this->_avar_regexp . '|' . $this->_qstr_regexp . ')'; - - // matches valid object call (no objects allowed in parameters): - // $foo->bar - // $foo->bar() - // $foo->bar("text") - // $foo->bar($foo, $bar, "text") - // $foo->bar($foo, "foo") - // $foo->bar->foo() - // $foo->bar->foo->bar() - $this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')'; - $this->_obj_params_regexp = '\((?:\w+|' - . $this->_var_regexp . '(?:\s*,\s*(?:(?:\w+|' - . $this->_var_regexp . ')))*)?\)'; - $this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' . $this->_obj_ext_regexp . ')+)'; - $this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . ')?)'; - - // matches valid modifier syntax: - // |foo - // |@foo - // |foo:"bar" - // |foo:$bar - // |foo:"bar":$foobar - // |foo|bar - // |foo:$foo->bar - $this->_mod_regexp = '(?:\|@?\w+(?::(?>\w+|' - . $this->_obj_call_regexp . '|' . $this->_avar_regexp . '|' . $this->_qstr_regexp .'))*)'; - - // matches valid function name: - // foo123 - // _foo_bar - $this->_func_regexp = '[a-zA-Z_]\w*'; - - // matches valid registered object: - // foo->bar - $this->_reg_obj_regexp = '[a-zA-Z_]\w*->[a-zA-Z_]\w*'; - - // matches valid parameter values: - // true - // $foo - // $foo|bar - // #foo# - // #foo#|bar - // "text" - // "text"|bar - // $foo->bar - $this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|' - . $this->_var_regexp . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)'; - - // matches valid parenthesised function parameters: - // - // "text" - // $foo, $bar, "text" - // $foo|bar, "foo"|bar, $foo->bar($foo)|bar - $this->_parenth_param_regexp = '(?:\((?:\w+|' - . $this->_param_regexp . '(?:\s*,\s*(?:(?:\w+|' - . $this->_param_regexp . ')))*)?\))'; - - // matches valid function call: - // foo() - // foo_bar($foo) - // _foo_bar($foo,"bar") - // foo123($foo,$foo->bar(),"foo") - $this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:' - . $this->_parenth_param_regexp . '))'; - } - - /** - * compile a template file - * - * sets $template_compiled to the compiled source - * @param string $tpl_file - * @param string $template_source - * @param string $template_compiled - */ - function _compile_file($tpl_file, $template_source, &$template_compiled) - { - if ($this->security) { - // do not allow php syntax to be executed unless specified - if ($this->php_handling == SMARTY_PHP_ALLOW && - !$this->security_settings['PHP_HANDLING']) { - $this->php_handling = SMARTY_PHP_PASSTHRU; - } - } - - $this->_load_filters(); - - $this->_current_file = $tpl_file; - $this->_current_line_no = 1; - $ldq = preg_quote($this->left_delimiter, '!'); - $rdq = preg_quote($this->right_delimiter, '!'); - - // run template source through prefilter functions - if (count($this->_plugins['prefilter']) > 0) { - foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) { - if ($prefilter === false) continue; - if ($prefilter[3] || function_exists($prefilter[0])) { - $template_source = $prefilter[0]($template_source, $this); - $this->_plugins['prefilter'][$filter_name][3] = true; - } else { - $this->_trigger_fatal_error("[plugin] prefilter '$filter_name' is not implemented"); - } - } - } - - /* Annihilate the comments. */ - $template_source = preg_replace("!({$ldq})\*(.*?)\*({$rdq})!se", - "'\\1*'.str_repeat(\"\n\", substr_count('\\2', \"\n\")) .'*\\3'", - $template_source); - - /* Pull out the literal blocks. */ - preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_source, $match); - $this->_literal_blocks = $match[1]; - $template_source = preg_replace("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", - $this->quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $template_source); - - /* Pull out the php code blocks. */ - preg_match_all("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", $template_source, $match); - $this->_php_blocks = $match[1]; - $template_source = preg_replace("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", - $this->quote_replace($this->left_delimiter.'php'.$this->right_delimiter), $template_source); - - /* Gather all template tags. */ - preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_source, $match); - $template_tags = $match[1]; - /* Split content by template tags to obtain non-template content. */ - $text_blocks = preg_split("!{$ldq}.*?{$rdq}!s", $template_source); - - /* loop through text blocks */ - for ($curr_tb = 0, $for_max = count($text_blocks); $curr_tb < $for_max; $curr_tb++) { - /* match anything resembling php tags */ - if (preg_match_all('!(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?php[\"\']?)!is', $text_blocks[$curr_tb], $sp_match)) { - /* replace tags with placeholders to prevent recursive replacements */ - $sp_match[1] = array_unique($sp_match[1]); - usort($sp_match[1], '_smarty_sort_length'); - for ($curr_sp = 0, $for_max2 = count($sp_match[1]); $curr_sp < $for_max2; $curr_sp++) { - $text_blocks[$curr_tb] = str_replace($sp_match[1][$curr_sp],'%%%SMARTYSP'.$curr_sp.'%%%',$text_blocks[$curr_tb]); - } - /* process each one */ - for ($curr_sp = 0, $for_max2 = count($sp_match[0]); $curr_sp < $for_max2; $curr_sp++) { - if ($this->php_handling == SMARTY_PHP_PASSTHRU) { - /* echo php contents */ - $text_blocks[$curr_tb] = str_replace('%%%SMARTYSP'.$curr_sp.'%%%', ''."\n", $text_blocks[$curr_tb]); - } else if ($this->php_handling == SMARTY_PHP_QUOTE) { - /* quote php tags */ - $text_blocks[$curr_tb] = str_replace('%%%SMARTYSP'.$curr_sp.'%%%', htmlspecialchars($sp_match[1][$curr_sp]), $text_blocks[$curr_tb]); - } else if ($this->php_handling == SMARTY_PHP_REMOVE) { - /* remove php tags */ - $text_blocks[$curr_tb] = str_replace('%%%SMARTYSP'.$curr_sp.'%%%', '', $text_blocks[$curr_tb]); - } else { - /* SMARTY_PHP_ALLOW, but echo non php starting tags */ - $sp_match[1][$curr_sp] = preg_replace('%(<\?(?!php|=|$))%i', ''."\n", $sp_match[1][$curr_sp]); - $text_blocks[$curr_tb] = str_replace('%%%SMARTYSP'.$curr_sp.'%%%', $sp_match[1][$curr_sp], $text_blocks[$curr_tb]); - } - } - } - } - - /* Compile the template tags into PHP code. */ - $compiled_tags = array(); - for ($i = 0, $for_max = count($template_tags); $i < $for_max; $i++) { - $this->_current_line_no += substr_count($text_blocks[$i], "\n"); - $compiled_tags[] = $this->_compile_tag($template_tags[$i]); - $this->_current_line_no += substr_count($template_tags[$i], "\n"); - } - - $template_compiled = ''; - - /* Interleave the compiled contents and text blocks to get the final result. */ - for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) { - $template_compiled .= $text_blocks[$i].$compiled_tags[$i]; - } - $template_compiled .= $text_blocks[$i]; - - /* Reformat data between 'strip' and '/strip' tags, removing spaces, tabs and newlines. */ - if (preg_match_all("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s", $template_compiled, $match)) { - $strip_tags = $match[0]; - $strip_tags_modified = preg_replace("!{$ldq}/?strip{$rdq}|[\t ]+$|^[\t ]+!m", '', $strip_tags); - $strip_tags_modified = preg_replace('![\r\n]+!m', '', $strip_tags_modified); - for ($i = 0, $for_max = count($strip_tags); $i < $for_max; $i++) - $template_compiled = preg_replace("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s", - $this->quote_replace($strip_tags_modified[$i]), - $template_compiled, 1); - } - - // remove \n from the end of the file, if any - if ($template_compiled{strlen($template_compiled) - 1} == "\n" ) { - $template_compiled = substr($template_compiled, 0, -1); - } - - // run compiled template through postfilter functions - if (count($this->_plugins['postfilter']) > 0) { - foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) { - if ($postfilter === false) continue; - if ($postfilter[3] || function_exists($postfilter[0])) { - $template_compiled = $postfilter[0]($template_compiled, $this); - $this->_plugins['postfilter'][$filter_name][3] = true; - } else { - $this->_trigger_plugin_error("Smarty plugin error: postfilter '$filter_name' is not implemented"); - } - } - } - - // put header at the top of the compiled template - $template_header = "_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n"; - $template_header .= " compiled from ".$tpl_file." */ ?>\n"; - - /* Emit code to load needed plugins. */ - if (count($this->_plugin_info)) { - $plugins_code = '_load_plugins(array('; - foreach ($this->_plugin_info as $plugin_type => $plugins) { - foreach ($plugins as $plugin_name => $plugin_info) { - $plugins_code .= "\narray('$plugin_type', '$plugin_name', '$plugin_info[0]', $plugin_info[1], "; - $plugins_code .= $plugin_info[2] ? 'true),' : 'false),'; - } - } - $plugins_code .= ")); ?>"; - $template_header .= $plugins_code; - $this->_plugin_info = array(); - } - - if ($this->_init_smarty_vars) { - $template_header .= "_assign_smarty_interface(); ?>\n"; - $this->_init_smarty_vars = false; - } - - $template_compiled = $template_header . $template_compiled; - - return true; - } - - /** - * Compile a template tag - * - * @param string $template_tag - */ - function _compile_tag($template_tag) - { - - /* Matched comment. */ - if ($template_tag{0} == '*' && $template_tag{strlen($template_tag) - 1} == '*') - return ''; - - /* Split tag into two three parts: command, command modifiers and the arguments. */ - if(! preg_match('/^(?:(' . $this->_obj_call_regexp . '|' . $this->_var_regexp - . '|' . $this->_reg_obj_regexp . '|\/?' . $this->_func_regexp . ')(' . $this->_mod_regexp . '*)) - (?:\s+(.*))?$ - /xs', $template_tag, $match)) { - $this->_syntax_error("unrecognized tag: $template_tag", E_USER_ERROR, __FILE__, __LINE__); - } - - $tag_command = $match[1]; - $tag_modifier = isset($match[2]) ? $match[2] : null; - $tag_args = isset($match[3]) ? $match[3] : null; - - - /* If the tag name is a variable or object, we process it. */ - if (preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '$!', $tag_command)) { - $return = $this->_parse_var_props($tag_command . $tag_modifier, $this->_parse_attrs($tag_args)); - if(isset($_tag_attrs['assign'])) { - return "assign('" . $this->_dequote($_tag_attrs['assign']) . "', $return ); ?>\n"; - } else { - return "\n"; - } - } - - /* If the tag name is a registered object, we process it. */ - if (preg_match('!^' . $this->_reg_obj_regexp . '$!', $tag_command)) { - return $this->_compile_registered_object_tag($tag_command, $this->_parse_attrs($tag_args), $tag_modifier); - } - - switch ($tag_command) { - case 'include': - return $this->_compile_include_tag($tag_args); - - case 'include_php': - return $this->_compile_include_php_tag($tag_args); - - case 'if': - return $this->_compile_if_tag($tag_args); - - case 'else': - return ''; - - case 'elseif': - return $this->_compile_if_tag($tag_args, true); - - case '/if': - return ''; - - case 'capture': - return $this->_compile_capture_tag(true, $tag_args); - - case '/capture': - return $this->_compile_capture_tag(false); - - case 'ldelim': - return $this->left_delimiter; - - case 'rdelim': - return $this->right_delimiter; - - case 'section': - array_push($this->_sectionelse_stack, false); - return $this->_compile_section_start($tag_args); - - case 'sectionelse': - $this->_sectionelse_stack[count($this->_sectionelse_stack)-1] = true; - return ""; - - case '/section': - if (array_pop($this->_sectionelse_stack)) - return ""; - else - return ""; - - case 'foreach': - array_push($this->_foreachelse_stack, false); - return $this->_compile_foreach_start($tag_args); - break; - - case 'foreachelse': - $this->_foreachelse_stack[count($this->_foreachelse_stack)-1] = true; - return ""; - - case '/foreach': - if (array_pop($this->_foreachelse_stack)) - return ""; - else - return ""; - - case 'config_load': - return $this->_compile_config_load_tag($tag_args); - - case 'strip': - case '/strip': - return $this->left_delimiter.$tag_command.$this->right_delimiter; - - case 'literal': - list (,$literal_block) = each($this->_literal_blocks); - $this->_current_line_no += substr_count($literal_block, "\n"); - return "\n"; - - case 'php': - if ($this->security && !$this->security_settings['PHP_TAGS']) { - $this->_syntax_error("(secure mode) php tags not permitted", E_USER_WARNING, __FILE__, __LINE__); - return; - } - list (,$php_block) = each($this->_php_blocks); - $this->_current_line_no += substr_count($php_block, "\n"); - return ''; - - case 'insert': - return $this->_compile_insert_tag($tag_args); - - default: - if ($this->_compile_compiler_tag($tag_command, $tag_args, $output)) { - return $output; - } else if ($this->_compile_block_tag($tag_command, $tag_args, $tag_modifier, $output)) { - return $output; - } else { - return $this->_compile_custom_tag($tag_command, $tag_args, $tag_modifier); - } - } - } - - - /** - * compile the custom compiler tag - * - * sets $output to the compiled custom compiler tag - * @param string $tag_command - * @param string $tag_args - * @param string $output - */ - function _compile_compiler_tag($tag_command, $tag_args, &$output) - { - $found = false; - $have_function = true; - - /* - * First we check if the compiler function has already been registered - * or loaded from a plugin file. - */ - if (isset($this->_plugins['compiler'][$tag_command])) { - $found = true; - $plugin_func = $this->_plugins['compiler'][$tag_command][0]; - if (!function_exists($plugin_func)) { - $message = "compiler function '$tag_command' is not implemented"; - $have_function = false; - } - } - /* - * Otherwise we need to load plugin file and look for the function - * inside it. - */ - else if ($plugin_file = $this->_get_plugin_filepath('compiler', $tag_command)) { - $found = true; - - include_once $plugin_file; - - $plugin_func = 'smarty_compiler_' . $tag_command; - if (!function_exists($plugin_func)) { - $message = "plugin function $plugin_func() not found in $plugin_file\n"; - $have_function = false; - } else { - $this->_plugins['compiler'][$tag_command] = array($plugin_func, null, null); - } - } - - /* - * True return value means that we either found a plugin or a - * dynamically registered function. False means that we didn't and the - * compiler should now emit code to load custom function plugin for this - * tag. - */ - if ($found) { - if ($have_function) { - $output = ''; - } else { - $this->_syntax_error($message, E_USER_WARNING, __FILE__, __LINE__); - } - return true; - } else { - return false; - } - } - - - /** - * compile block function tag - * - * sets $output to compiled block function tag - * @param string $tag_command - * @param string $tag_args - * @param string $tag_modifier - * @param string $output - */ - function _compile_block_tag($tag_command, $tag_args, $tag_modifier, &$output) - { - if ($tag_command{0} == '/') { - $start_tag = false; - $tag_command = substr($tag_command, 1); - } else - $start_tag = true; - - $found = false; - $have_function = true; - - /* - * First we check if the block function has already been registered - * or loaded from a plugin file. - */ - if (isset($this->_plugins['block'][$tag_command])) { - $found = true; - $plugin_func = $this->_plugins['block'][$tag_command][0]; - if (!function_exists($plugin_func)) { - $message = "block function '$tag_command' is not implemented"; - $have_function = false; - } - } - /* - * Otherwise we need to load plugin file and look for the function - * inside it. - */ - else if ($plugin_file = $this->_get_plugin_filepath('block', $tag_command)) { - $found = true; - - include_once $plugin_file; - - $plugin_func = 'smarty_block_' . $tag_command; - if (!function_exists($plugin_func)) { - $message = "plugin function $plugin_func() not found in $plugin_file\n"; - $have_function = false; - } else { - $this->_plugins['block'][$tag_command] = array($plugin_func, null, null); - } - } - - if (!$found) { - return false; - } else if (!$have_function) { - $this->_syntax_error($message, E_USER_WARNING, __FILE__, __LINE__); - return true; - } - - /* - * Even though we've located the plugin function, compilation - * happens only once, so the plugin will still need to be loaded - * at runtime for future requests. - */ - $this->_add_plugin('block', $tag_command); - - if ($start_tag) { - $arg_list = array(); - $attrs = $this->_parse_attrs($tag_args); - foreach ($attrs as $arg_name => $arg_value) { - if (is_bool($arg_value)) - $arg_value = $arg_value ? 'true' : 'false'; - $arg_list[] = "'$arg_name' => $arg_value"; - } - - $output = "_tag_stack[] = array('$tag_command', array(".implode(',', (array)$arg_list).")); \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), null, \$this); ob_start(); ?>"; - } else { - $output = "_block_content = ob_get_contents(); ob_end_clean(); "; - $out_tag_text = "\$this->_plugins['block']['$tag_command'][0](\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$this->_block_content, \$this)"; - if($tag_modifier != '') { - $this->_parse_modifiers($out_tag_text, $tag_modifier); - } - $output .= 'echo ' . $out_tag_text . ';'; - $output .= " array_pop(\$this->_tag_stack); ?>"; - } - - return true; - } - - - /** - * compile custom function tag - * - * @param string $tag_command - * @param string $tag_args - * @param string $tag_modifier - */ - function _compile_custom_tag($tag_command, $tag_args, $tag_modifier) - { - $this->_add_plugin('function', $tag_command); - - $arg_list = array(); - $attrs = $this->_parse_attrs($tag_args); - - foreach ($attrs as $arg_name => $arg_value) { - if (is_bool($arg_value)) - $arg_value = $arg_value ? 'true' : 'false'; - if (is_null($arg_value)) - $arg_value = 'null'; - $arg_list[] = "'$arg_name' => $arg_value"; - } - - $return = "\$this->_plugins['function']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), \$this)"; - - if($tag_modifier != '') { - $this->_parse_modifiers($return, $tag_modifier); - } - - return '\n"; - } - - /** - * compile a registered object tag - * - * @param string $tag_command - * @param array $attrs - * @param string $tag_modifier - */ - function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier) - { - list($object, $obj_comp) = explode('->', $tag_command); - - $arg_list = array(); - if(count($attrs)) { - $_assign_var = false; - foreach ($attrs as $arg_name => $arg_value) { - if($arg_name == 'assign') { - $_assign_var = $arg_value; - unset($attrs['assign']); - continue; - } - if (is_bool($arg_value)) - $arg_value = $arg_value ? 'true' : 'false'; - $arg_list[] = "'$arg_name' => $arg_value"; - } - } - - if(!is_object($this->_reg_objects[$object][0])) { - $this->_trigger_fatal_error("registered '$object' is not an object"); - } elseif(!empty($this->_reg_objects[$object][1]) && !in_array($obj_comp, $this->_reg_objects[$object][1])) { - $this->_trigger_fatal_error("'$obj_comp' is not a registered component of object '$object'"); - } elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) { - // method - if($this->_reg_objects[$object][2]) { - // smarty object argument format - $return = "\$this->_reg_objects['$object'][0]->$obj_comp(array(".implode(',', (array)$arg_list)."), \$this)"; - } else { - // traditional argument format - $return = "\$this->_reg_objects['$object'][0]->$obj_comp(".implode(',', array_values($attrs)).")"; - } - } else { - // property - $return = "\$this->_reg_objects['$object'][0]->$obj_comp"; - } - - if($tag_modifier != '') { - $this->_parse_modifiers($return, $tag_modifier); - } - - if($_assign_var) { - return "assign('" . $this->_dequote($_assign_var) ."', $return); ?>\n"; - } else { - return '\n"; - } - } - - - - /** - * Compile {insert ...} tag - * - * @param string $tag_args - */ - function _compile_insert_tag($tag_args) - { - $attrs = $this->_parse_attrs($tag_args); - $name = $this->_dequote($attrs['name']); - - if (empty($name)) { - $this->_syntax_error("missing insert name", E_USER_ERROR, __FILE__, __LINE__); - } - - if (!empty($attrs['script'])) { - $delayed_loading = true; - } else { - $delayed_loading = false; - } - - foreach ($attrs as $arg_name => $arg_value) { - if (is_bool($arg_value)) - $arg_value = $arg_value ? 'true' : 'false'; - $arg_list[] = "'$arg_name' => $arg_value"; - } - - $this->_add_plugin('insert', $name, $delayed_loading); - - return "_run_insert_handler(array(".implode(', ', (array)$arg_list).")); ?>\n"; - } - - - /** - * Compile {config_load ...} tag - * - * @param string $tag_args - */ - function _compile_config_load_tag($tag_args) - { - $attrs = $this->_parse_attrs($tag_args); - - if (empty($attrs['file'])) { - $this->_syntax_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__); - } - - if (empty($attrs['section'])) { - $attrs['section'] = 'null'; - } - - if (isset($attrs['scope'])) { - $scope = @$this->_dequote($attrs['scope']); - if ($scope != 'local' && - $scope != 'parent' && - $scope != 'global') { - $this->_syntax_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__); - } - } else { - if (isset($attrs['global']) && $attrs['global']) - $scope = 'parent'; - else - $scope = 'local'; - } - - return 'config_load(' . $attrs['file'] . ', ' . $attrs['section'] . ", '$scope'); ?>"; - } - - - /** - * Compile {include ...} tag - * - * $param string $tag_args - */ - function _compile_include_tag($tag_args) - { - $attrs = $this->_parse_attrs($tag_args); - $arg_list = array(); - - if (empty($attrs['file'])) { - $this->_syntax_error("missing 'file' attribute in include tag", E_USER_ERROR, __FILE__, __LINE__); - } - - foreach ($attrs as $arg_name => $arg_value) { - if ($arg_name == 'file') { - $include_file = $arg_value; - continue; - } else if ($arg_name == 'assign') { - $assign_var = $arg_value; - continue; - } - if (is_bool($arg_value)) - $arg_value = $arg_value ? 'true' : 'false'; - $arg_list[] = "'$arg_name' => $arg_value"; - } - - $output = '_tpl_vars;\n" . - "\$this->_smarty_include(".$include_file.", array(".implode(',', (array)$arg_list)."));\n" . - "\$this->_tpl_vars = \$_smarty_tpl_vars;\n" . - "unset(\$_smarty_tpl_vars);\n"; - - if (isset($assign_var)) { - $output .= "\$this->assign(" . $assign_var . ", ob_get_contents()); ob_end_clean();\n"; - } - - $output .= ' ?>'; - - return $output; - - } - - /** - * Compile {include ...} tag - * - * @param string $tag_args - */ - function _compile_include_php_tag($tag_args) - { - $attrs = $this->_parse_attrs($tag_args); - - if (empty($attrs['file'])) { - $this->_syntax_error("missing 'file' attribute in include_php tag", E_USER_ERROR, __FILE__, __LINE__); - } - - $assign_var = $this->_dequote($attrs['assign']); - - $once_var = ( $attrs['once'] === false ) ? 'false' : 'true'; - - foreach($attrs as $arg_name => $arg_value) { - if($arg_name != 'file' AND $arg_name != 'once' AND $arg_name != 'assign') { - if(is_bool($arg_value)) - $arg_value = $arg_value ? 'true' : 'false'; - $arg_list[] = "'$arg_name' => $arg_value"; - } - } - - $output = - "_smarty_include_php($attrs[file], '$assign_var', $once_var, " . - "array(".implode(',', (array)$arg_list).")); ?>"; - - return $output; - } - - - /** - * Compile {section ...} tag - * - * @param string $tag_args - */ - function _compile_section_start($tag_args) - { - $attrs = $this->_parse_attrs($tag_args); - $arg_list = array(); - - $output = '_syntax_error("missing section name", E_USER_ERROR, __FILE__, __LINE__); - } - - $output .= "if (isset(\$this->_sections[$section_name])) unset(\$this->_sections[$section_name]);\n"; - $section_props = "\$this->_sections[$section_name]"; - - foreach ($attrs as $attr_name => $attr_value) { - switch ($attr_name) { - case 'loop': - $output .= "{$section_props}['loop'] = is_array($attr_value) ? count($attr_value) : max(0, (int)$attr_value);\n"; - break; - - case 'show': - if (is_bool($attr_value)) - $show_attr_value = $attr_value ? 'true' : 'false'; - else - $show_attr_value = "(bool)$attr_value"; - $output .= "{$section_props}['show'] = $show_attr_value;\n"; - break; - - case 'name': - $output .= "{$section_props}['$attr_name'] = $attr_value;\n"; - break; - - case 'max': - case 'start': - $output .= "{$section_props}['$attr_name'] = (int)$attr_value;\n"; - break; - - case 'step': - $output .= "{$section_props}['$attr_name'] = ((int)$attr_value) == 0 ? 1 : (int)$attr_value;\n"; - break; - - default: - $this->_syntax_error("unknown section attribute - '$attr_name'", E_USER_ERROR, __FILE__, __LINE__); - break; - } - } - - if (!isset($attrs['show'])) - $output .= "{$section_props}['show'] = true;\n"; - - if (!isset($attrs['loop'])) - $output .= "{$section_props}['loop'] = 1;\n"; - - if (!isset($attrs['max'])) - $output .= "{$section_props}['max'] = {$section_props}['loop'];\n"; - else - $output .= "if ({$section_props}['max'] < 0)\n" . - " {$section_props}['max'] = {$section_props}['loop'];\n"; - - if (!isset($attrs['step'])) - $output .= "{$section_props}['step'] = 1;\n"; - - if (!isset($attrs['start'])) - $output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n"; - else { - $output .= "if ({$section_props}['start'] < 0)\n" . - " {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" . - "else\n" . - " {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n"; - } - - $output .= "if ({$section_props}['show']) {\n"; - if (!isset($attrs['start']) && !isset($attrs['step']) && !isset($attrs['max'])) { - $output .= " {$section_props}['total'] = {$section_props}['loop'];\n"; - } else { - $output .= " {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n"; - } - $output .= " if ({$section_props}['total'] == 0)\n" . - " {$section_props}['show'] = false;\n" . - "} else\n" . - " {$section_props}['total'] = 0;\n"; - - $output .= "if ({$section_props}['show']):\n"; - $output .= " - for ({$section_props}['index'] = {$section_props}['start'], {$section_props}['iteration'] = 1; - {$section_props}['iteration'] <= {$section_props}['total']; - {$section_props}['index'] += {$section_props}['step'], {$section_props}['iteration']++):\n"; - $output .= "{$section_props}['rownum'] = {$section_props}['iteration'];\n"; - $output .= "{$section_props}['index_prev'] = {$section_props}['index'] - {$section_props}['step'];\n"; - $output .= "{$section_props}['index_next'] = {$section_props}['index'] + {$section_props}['step'];\n"; - $output .= "{$section_props}['first'] = ({$section_props}['iteration'] == 1);\n"; - $output .= "{$section_props}['last'] = ({$section_props}['iteration'] == {$section_props}['total']);\n"; - - $output .= "?>"; - - return $output; - } - - - /** - * Compile {foreach ...} tag. - * - * @param string $tag_args - */ - function _compile_foreach_start($tag_args) - { - $attrs = $this->_parse_attrs($tag_args); - $arg_list = array(); - - if (empty($attrs['from'])) { - $this->_syntax_error("missing 'from' attribute", E_USER_ERROR, __FILE__, __LINE__); - } - - if (empty($attrs['item'])) { - $this->_syntax_error("missing 'item' attribute", E_USER_ERROR, __FILE__, __LINE__); - } - - $from = $attrs['from']; - $item = $this->_dequote($attrs['item']); - if (isset($attrs['name'])) - $name = $attrs['name']; - - $output = '_foreach[$name])) unset(\$this->_foreach[$name]);\n"; - $foreach_props = "\$this->_foreach[$name]"; - } - - $key_part = ''; - - foreach ($attrs as $attr_name => $attr_value) { - switch ($attr_name) { - case 'key': - $key = $this->_dequote($attrs['key']); - $key_part = "\$this->_tpl_vars['$key'] => "; - break; - - case 'name': - $output .= "{$foreach_props}['$attr_name'] = $attr_value;\n"; - break; - } - } - - if (isset($name)) { - $output .= "{$foreach_props}['total'] = count((array)$from);\n"; - $output .= "{$foreach_props}['show'] = {$foreach_props}['total'] > 0;\n"; - $output .= "if ({$foreach_props}['show']):\n"; - $output .= "{$foreach_props}['iteration'] = 0;\n"; - $output .= " foreach ((array)$from as $key_part\$this->_tpl_vars['$item']):\n"; - $output .= " {$foreach_props}['iteration']++;\n"; - $output .= " {$foreach_props}['first'] = ({$foreach_props}['iteration'] == 1);\n"; - $output .= " {$foreach_props}['last'] = ({$foreach_props}['iteration'] == {$foreach_props}['total']);\n"; - } else { - $output .= "if (count((array)$from)):\n"; - $output .= " foreach ((array)$from as $key_part\$this->_tpl_vars['$item']):\n"; - } - $output .= '?>'; - - return $output; - } - - - /** - * Compile {capture} .. {/capture} tags - * - * @param boolean $start true if this is the {capture} tag - * @param string $tag_args - */ - function _compile_capture_tag($start, $tag_args = '') - { - $attrs = $this->_parse_attrs($tag_args); - - if ($start) { - if (isset($attrs['name'])) - $buffer = $attrs['name']; - else - $buffer = "'default'"; - - $output = ""; - $this->_capture_stack[] = $buffer; - } else { - $buffer = array_pop($this->_capture_stack); - $output = "_smarty_vars['capture'][$buffer] = ob_get_contents(); ob_end_clean(); ?>"; - } - - return $output; - } - - /** - * Compile {if ...} tag - * - * @param string $tag_args - * @param boolean $elseif if true, uses elseif instead of if - */ - function _compile_if_tag($tag_args, $elseif = false) - { - - /* Tokenize args for 'if' tag. */ - preg_match_all('/(?> - ' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*)? | # valid object call - ' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)? | # var or quoted string - \-?\d+(?:\.\d+)?|\.\d+|!==|<=>|===|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\*|\@ | # valid non-word token - \b\w+\b | # valid word token - \S+ # anything else - )/x', $tag_args, $match); - - $tokens = $match[0]; - - // make sure we have balanced parenthesis - $token_count = array_count_values($tokens); - if(isset($token_count['(']) && $token_count['('] != $token_count[')']) { - $this->_syntax_error("unbalanced parenthesis in if statement", E_USER_ERROR, __FILE__, __LINE__); - } - - $is_arg_stack = array(); - - for ($i = 0; $i < count($tokens); $i++) { - - $token = &$tokens[$i]; - - switch (strtolower($token)) { - case '!': - case '%': - case '!==': - case '==': - case '===': - case '>': - case '<': - case '!=': - case '<=': - case '>=': - case '&&': - case '||': - case '|': - case '^': - case '&': - case '~': - case ')': - case ',': - case '+': - case '-': - case '*': - case '/': - case '@': - break; - - case 'eq': - $token = '=='; - break; - - case 'ne': - case 'neq': - $token = '!='; - break; - - case 'lt': - $token = '<'; - break; - - case 'le': - case 'lte': - $token = '<='; - break; - - case 'gt': - $token = '>'; - break; - - case 'ge': - case 'gte': - $token = '>='; - break; - - case 'and': - $token = '&&'; - break; - - case 'or': - $token = '||'; - break; - - case 'not': - $token = '!'; - break; - - case 'mod': - $token = '%'; - break; - - case '(': - array_push($is_arg_stack, $i); - break; - - case 'is': - /* If last token was a ')', we operate on the parenthesized - expression. The start of the expression is on the stack. - Otherwise, we operate on the last encountered token. */ - if ($tokens[$i-1] == ')') - $is_arg_start = array_pop($is_arg_stack); - else - $is_arg_start = $i-1; - /* Construct the argument for 'is' expression, so it knows - what to operate on. */ - $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start)); - - /* Pass all tokens from next one until the end to the - 'is' expression parsing function. The function will - return modified tokens, where the first one is the result - of the 'is' expression and the rest are the tokens it - didn't touch. */ - $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1)); - - /* Replace the old tokens with the new ones. */ - array_splice($tokens, $is_arg_start, count($tokens), $new_tokens); - - /* Adjust argument start so that it won't change from the - current position for the next iteration. */ - $i = $is_arg_start; - break; - - default: - if(preg_match('!^' . $this->_func_regexp . '$!', $token) ) { - // function call - if($this->security && - !in_array($token, $this->security_settings['IF_FUNCS'])) { - $this->_syntax_error("(secure mode) '$token' not allowed in if statement", E_USER_ERROR, __FILE__, __LINE__); - } - } elseif(preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)$!', $token)) { - // object or variable - $token = $this->_parse_var_props($token); - } elseif(is_numeric($token)) { - // number, skip it - } else { - $this->_syntax_error("unidentified token '$token'", E_USER_ERROR, __FILE__, __LINE__); - } - break; - } - } - - if ($elseif) - return ''; - else - return ''; - } - - - /** - * Parse is expression - * - * @param string $is_arg - * @param array $tokens - */ - function _parse_is_expr($is_arg, $tokens) - { - $expr_end = 0; - $negate_expr = false; - - if (($first_token = array_shift($tokens)) == 'not') { - $negate_expr = true; - $expr_type = array_shift($tokens); - } else - $expr_type = $first_token; - - switch ($expr_type) { - case 'even': - if (@$tokens[$expr_end] == 'by') { - $expr_end++; - $expr_arg = $tokens[$expr_end++]; - $expr = "!(($is_arg / $expr_arg) % " . $this->_parse_var_props($expr_arg) . ")"; - } else - $expr = "!($is_arg % 2)"; - break; - - case 'odd': - if (@$tokens[$expr_end] == 'by') { - $expr_end++; - $expr_arg = $tokens[$expr_end++]; - $expr = "(($is_arg / $expr_arg) % ". $this->_parse_var_props($expr_arg) . ")"; - } else - $expr = "($is_arg % 2)"; - break; - - case 'div': - if (@$tokens[$expr_end] == 'by') { - $expr_end++; - $expr_arg = $tokens[$expr_end++]; - $expr = "!($is_arg % " . $this->_parse_var_props($expr_arg) . ")"; - } else { - $this->_syntax_error("expecting 'by' after 'div'", E_USER_ERROR, __FILE__, __LINE__); - } - break; - - default: - $this->_syntax_error("unknown 'is' expression - '$expr_type'", E_USER_ERROR, __FILE__, __LINE__); - break; - } - - if ($negate_expr) { - $expr = "!($expr)"; - } - - array_splice($tokens, 0, $expr_end, $expr); - - return $tokens; - } - - - /** - * Parse attribute string - * - * @param string $tag_args - * @param true $quote unused? - */ - function _parse_attrs($tag_args, $quote = true) - { - - /* Tokenize tag attributes. */ - preg_match_all('/(?:' . $this->_obj_call_regexp . '|' . $this->_qstr_regexp . ' | (?>[^"\'=\s]+) - )+ | - [=] - /x', $tag_args, $match); - $tokens = $match[0]; - - $attrs = array(); - /* Parse state: - 0 - expecting attribute name - 1 - expecting '=' - 2 - expecting attribute value (not '=') */ - $state = 0; - - foreach ($tokens as $token) { - switch ($state) { - case 0: - /* If the token is a valid identifier, we set attribute name - and go to state 1. */ - if (preg_match('!^\w+$!', $token)) { - $attr_name = $token; - $state = 1; - } else - $this->_syntax_error("invalid attribute name: '$token'", E_USER_ERROR, __FILE__, __LINE__); - break; - - case 1: - /* If the token is '=', then we go to state 2. */ - if ($token == '=') { - $state = 2; - } else - $this->_syntax_error("expecting '=' after attribute name '$last_token'", E_USER_ERROR, __FILE__, __LINE__); - break; - - case 2: - /* If token is not '=', we set the attribute value and go to - state 0. */ - if ($token != '=') { - /* We booleanize the token if it's a non-quoted possible - boolean value. */ - if (preg_match('!^(on|yes|true)$!', $token)) { - $token = 'true'; - } else if (preg_match('!^(off|no|false)$!', $token)) { - $token = 'false'; - } else if ($token == 'null') { - $token = 'null'; - } else if (!preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')?$!', $token)) { - /* treat as a string, double-quote it escaping quotes */ - $token = '"'.addslashes($token).'"'; - } - - $attrs[$attr_name] = $token; - $state = 0; - } else - $this->_syntax_error("'=' cannot be an attribute value", E_USER_ERROR, __FILE__, __LINE__); - break; - } - $last_token = $token; - } - - if($state != 0) { - if($state == 1) { - $this->_syntax_error("expecting '=' after attribute name '$last_token'", E_USER_ERROR, __FILE__, __LINE__); - } else { - $this->_syntax_error("missing attribute value", E_USER_ERROR, __FILE__, __LINE__); - } - } - - $this->_parse_vars_props($attrs); - - return $attrs; - } - - /** - * compile multiple variables and section properties tokens into - * PHP code - * - * @param array $tokens - */ - function _parse_vars_props(&$tokens) - { - foreach($tokens as $key => $val) { - $tokens[$key] = $this->_parse_var_props($val); - } - } - - /** - * compile single variable and section properties token into - * PHP code - * - * @param string $val - * @param string $tag_attrs - */ - function _parse_var_props($val, $tag_attrs = null) - { - - $val = trim($val); - - if(preg_match('!^(' . $this->_obj_call_regexp . '|' . $this->_dvar_regexp . ')(?:' . $this->_mod_regexp . '*)$!', $val)) { - // $ variable or object - return $this->_parse_var($val); - } - elseif(preg_match('!^' . $this->_db_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) { - // double quoted text - preg_match('!^(' . $this->_db_qstr_regexp . ')('. $this->_mod_regexp . '*)$!', $val, $match); - $return = $this->_expand_quoted_text($match[1]); - if($match[2] != '') { - $this->_parse_modifiers($return, $match[2]); - } - return $return; - } - elseif(preg_match('!^' . $this->_si_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) { - // single quoted text - preg_match('!^(' . $this->_si_qstr_regexp . ')('. $this->_mod_regexp . '*)$!', $val, $match); - if($match[2] != '') { - $this->_parse_modifiers($match[1], $match[2]); - return $match[1]; - } - } - elseif(preg_match('!^' . $this->_cvar_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) { - // config var - return $this->_parse_conf_var($val); - } - elseif(preg_match('!^' . $this->_svar_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) { - // section var - return $this->_parse_section_prop($val); - } - elseif(!in_array($val, $this->_permitted_tokens) && !is_numeric($val)) { - // literal string - return $this->_expand_quoted_text('"' . $val .'"'); - } - return $val; - } - - /** - * expand quoted text with embedded variables - * - * @param string $var_expr - */ - function _expand_quoted_text($var_expr) - { - // if contains unescaped $, expand it - if(preg_match_all('%(?_var_bracket_regexp . ')*)%', $var_expr, $match)) { - rsort($match[0]); - reset($match[0]); - foreach($match[0] as $var) { - $var_expr = str_replace ($var, '".' . $this->_parse_var($var) . '."', $var_expr); - } - return preg_replace('!\.""|""\.!', '', $var_expr); - } else { - return $var_expr; - } - } - - /** - * parse variable expression into PHP code - * - * @param string $var_expr - */ - function _parse_var($var_expr) - { - - preg_match('!(' . $this->_obj_call_regexp . '|' . $this->_var_regexp . ')(' . $this->_mod_regexp . '*)$!', $var_expr, $match); - - $var_ref = substr($match[1],1); - $modifiers = $match[2]; - - if(!empty($this->default_modifiers) && !preg_match('!(^|\|)smarty:nodefaults($|\|)!',$modifiers)) { - $_default_mod_string = implode('|',(array)$this->default_modifiers); - $modifiers = empty($modifiers) ? $_default_mod_string : $_default_mod_string . '|' . $modifiers; - } - - // get [foo] and .foo and ->foo and (...) pieces - preg_match_all('!(?:^\w+)|' . $this->_obj_params_regexp . '|(?:' . $this->_var_bracket_regexp . ')|->\w+|\.\$?\w+|\S+!', $var_ref, $match); - - $indexes = $match[0]; - $var_name = array_shift($indexes); - - /* Handle $smarty.* variable references as a special case. */ - if ($var_name == 'smarty') { - /* - * If the reference could be compiled, use the compiled output; - * otherwise, fall back on the $smarty variable generated at - * run-time. - */ - if (($smarty_ref = $this->_compile_smarty_ref($indexes)) !== null) { - $output = $smarty_ref; - } else { - $var_name = substr(array_shift($indexes), 1); - $output = "\$this->_smarty_vars['$var_name']"; - } - } else { - $output = "\$this->_tpl_vars['$var_name']"; - } - - foreach ($indexes as $index) { - if ($index{0} == '[') { - $index = substr($index, 1, -1); - if (is_numeric($index)) { - $output .= "[$index]"; - } elseif ($index{0} == '$') { - $output .= "[\$this->_tpl_vars['" . substr($index, 1) . "']]"; - } else { - $parts = explode('.', $index); - $section = $parts[0]; - $section_prop = isset($parts[1]) ? $parts[1] : 'index'; - $output .= "[\$this->_sections['$section']['$section_prop']]"; - } - } else if ($index{0} == '.') { - if ($index{1} == '$') - $output .= "[\$this->_tpl_vars['" . substr($index, 2) . "']]"; - else - $output .= "['" . substr($index, 1) . "']"; - } else if (substr($index,0,2) == '->') { - if(substr($index,2,2) == '__') { - $this->_syntax_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__); - } elseif($this->security && substr($index,2,1) == '_') { - $this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__); - } - $output .= $index; - } elseif ($index{0} == '(') { - $index = $this->_parse_parenth_args($index); - $output .= $index; - } else { - $output .= $index; - } - } - - // look for variables imbedded in quoted strings, replace them - if(preg_match('|(?_expand_quoted_text($match[0]), $output); - } - - $this->_parse_modifiers($output, $modifiers); - - return $output; - } - - /** - * parse arguments in function call parenthesis - * - * @param string $parenth_args - */ - function _parse_parenth_args($parenth_args) - { - preg_match_all('!' . $this->_param_regexp . '!',$parenth_args, $match); - $match = $match[0]; - rsort($match); - reset($match); - $orig_vals = $match; - $this->_parse_vars_props($match); - return str_replace($orig_vals, $match, $parenth_args); - } - - /** - * parse configuration variable expression into PHP code - * - * @param string $conf_var_expr - */ - function _parse_conf_var($conf_var_expr) - { - $parts = explode('|', $conf_var_expr, 2); - $var_ref = $parts[0]; - $modifiers = isset($parts[1]) ? $parts[1] : ''; - - $var_name = substr($var_ref, 1, -1); - - $output = "\$this->_config[0]['vars']['$var_name']"; - - $this->_parse_modifiers($output, $modifiers); - - return $output; - } - - - /** - * parse section property expression into PHP code - * - * @param string $section_prop_expr - */ - function _parse_section_prop($section_prop_expr) - { - $parts = explode('|', $section_prop_expr, 2); - $var_ref = $parts[0]; - $modifiers = isset($parts[1]) ? $parts[1] : ''; - - preg_match('!%(\w+)\.(\w+)%!', $var_ref, $match); - $section_name = $match[1]; - $prop_name = $match[2]; - - $output = "\$this->_sections['$section_name']['$prop_name']"; - - $this->_parse_modifiers($output, $modifiers); - - return $output; - } - - - /** - * parse modifier chain into PHP code - * - * sets $output to parsed modified chain - * @param string $output - * @param string $modifier_string - */ - function _parse_modifiers(&$output, $modifier_string) - { - preg_match_all('!\|(@?\w+)((?>:(?:'. $this->_qstr_regexp . '|[^|]+))*)!', '|' . $modifier_string, $match); - list(, $modifiers, $modifier_arg_strings) = $match; - - for ($i = 0, $for_max = count($modifiers); $i < $for_max; $i++) { - $modifier_name = $modifiers[$i]; - - if($modifier_name == 'smarty') { - // skip smarty modifier - continue; - } - - preg_match_all('!:(' . $this->_qstr_regexp . '|[^:]+)!', $modifier_arg_strings[$i], $match); - $modifier_args = $match[1]; - - if ($modifier_name{0} == '@') { - $map_array = 'false'; - $modifier_name = substr($modifier_name, 1); - } else { - $map_array = 'true'; - } - - $this->_add_plugin('modifier', $modifier_name); - - $this->_parse_vars_props($modifier_args); - - if (count($modifier_args) > 0) - $modifier_args = ', '.implode(', ', $modifier_args); - else - $modifier_args = ''; - - $output = "\$this->_run_mod_handler('$modifier_name', $map_array, $output$modifier_args)"; - } - } - - - /** - * add plugin - * - * @param string $type - * @param string $name - * @param boolean? $delayed_loading - */ - function _add_plugin($type, $name, $delayed_loading = null) - { - if (!isset($this->_plugin_info[$type])) { - $this->_plugin_info[$type] = array(); - } - if (!isset($this->_plugin_info[$type][$name])) { - $this->_plugin_info[$type][$name] = array($this->_current_file, - $this->_current_line_no, - $delayed_loading); - } - } - - - /** - * Compiles references of type $smarty.foo - * - * @param string $indexes - */ - function _compile_smarty_ref(&$indexes) - { - /* Extract the reference name. */ - $ref = substr($indexes[0], 1); - - switch ($ref) { - case 'now': - $compiled_ref = 'time()'; - if (count($indexes) > 1) { - $this->_syntax_error('$smarty' . implode('', $indexes) .' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__); - } - break; - - case 'foreach': - case 'section': - if ($indexes[1]{0} != '.') { - $this->_syntax_error('$smarty' . implode('', array_slice($indexes, 0, 2)) . ' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__); - } - $name = substr($indexes[1], 1); - array_shift($indexes); - if ($ref == 'foreach') - $compiled_ref = "\$this->_foreach['$name']"; - else - $compiled_ref = "\$this->_sections['$name']"; - break; - - case 'get': - array_shift($indexes); - $compiled_ref = "\$GLOBALS['HTTP_GET_VARS']"; - if ($name = substr($indexes[0], 1)) - $compiled_ref .= "['$name']"; - break; - - case 'post': - array_shift($indexes); - $name = substr($indexes[0], 1); - $compiled_ref = "\$GLOBALS['HTTP_POST_VARS']"; - if ($name = substr($indexes[0], 1)) - $compiled_ref .= "['$name']"; - break; - - case 'cookies': - array_shift($indexes); - $name = substr($indexes[0], 1); - $compiled_ref = "\$GLOBALS['HTTP_COOKIE_VARS']"; - if ($name = substr($indexes[0], 1)) - $compiled_ref .= "['$name']"; - break; - - case 'env': - array_shift($indexes); - $compiled_ref = "\$GLOBALS['HTTP_ENV_VARS']"; - if ($name = substr($indexes[0], 1)) - $compiled_ref .= "['$name']"; - break; - - case 'server': - array_shift($indexes); - $name = substr($indexes[0], 1); - $compiled_ref = "\$GLOBALS['HTTP_SERVER_VARS']"; - if ($name = substr($indexes[0], 1)) - $compiled_ref .= "['$name']"; - break; - - case 'session': - array_shift($indexes); - $name = substr($indexes[0], 1); - $compiled_ref = "\$GLOBALS['HTTP_SESSION_VARS']"; - if ($name = substr($indexes[0], 1)) - $compiled_ref .= "['$name']"; - break; - - /* - * These cases are handled either at run-time or elsewhere in the - * compiler. - */ - case 'request': - $this->_init_smarty_vars = true; - return null; - - case 'capture': - return null; - - case 'template': - $compiled_ref = "'$this->_current_file'"; - if (count($indexes) > 1) { - $this->_syntax_error('$smarty' . implode('', $indexes) .' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__); - } - break; - - case 'version': - $compiled_ref = "'$this->_version'"; - break; - - case 'const': - array_shift($indexes); - $compiled_ref = '(defined("' . substr($indexes[0],1) . '") ? ' . substr($indexes[0],1) . ' : null)'; - break; - - default: - $this->_syntax_error('$smarty.' . $ref . ' is an unknown reference', E_USER_ERROR, __FILE__, __LINE__); - break; - } - - array_shift($indexes); - return $compiled_ref; - } - - - /** - * load pre- and post-filters - */ - function _load_filters() - { - if (count($this->_plugins['prefilter']) > 0) { - foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) { - if ($prefilter === false) { - unset($this->_plugins['prefilter'][$filter_name]); - $this->_load_plugins(array(array('prefilter', $filter_name, null, null, false))); - } - } - } - if (count($this->_plugins['postfilter']) > 0) { - foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) { - if ($postfilter === false) { - unset($this->_plugins['postfilter'][$filter_name]); - $this->_load_plugins(array(array('postfilter', $filter_name, null, null, false))); - } - } - } - } - - - /** - * display Smarty syntax error - * - * @param string $error_msg - * @param integer $error_type - * @param string $file - * @param integer $line - */ - function _syntax_error($error_msg, $error_type = E_USER_ERROR, $file=null, $line=null) - { - if(isset($file) && isset($line)) { - $info = ' ('.basename($file).", line $line)"; - } else { - $info = null; - } - trigger_error('Smarty: [in ' . $this->_current_file . ' line ' . - $this->_current_line_no . "]: syntax error: $error_msg$info", $error_type); - } -} - -/** - * compare to values by their string length - * - * @access private - * @param string $a - * @param string $b - */ -function _smarty_sort_length($a, $b) -{ - if($a == $b) - return 0; - - if(strlen($a) == strlen($b)) - return ($a > $b) ? -1 : 1; - - return (strlen($a) > strlen($b)) ? -1 : 1; -} - - -/* vim: set et: */ - -?> diff --git a/debug.tpl b/debug.tpl deleted file mode 100644 index 3e939baa..00000000 --- a/debug.tpl +++ /dev/null @@ -1,64 +0,0 @@ -{* Smarty *} - -{* debug.tpl, last updated version 2.0.1 *} - -{assign_debug_info} - -{if isset($_smarty_debug_output) and $_smarty_debug_output eq "html"} - - - - {section name=templates loop=$_debug_tpls} - - {sectionelse} - - {/section} - - {section name=vars loop=$_debug_keys} - - {sectionelse} - - {/section} - - {section name=config_vars loop=$_debug_config_keys} - - {sectionelse} - - {/section} -
Smarty Debug Console
included templates & config files (load time in seconds):
{section name=indent loop=$_debug_tpls[templates].depth}   {/section}{$_debug_tpls[templates].filename}{if isset($_debug_tpls[templates].exec_time)} ({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}{/if}
no templates included
assigned template variables:
{ldelim}${$_debug_keys[vars]}{rdelim}{$_debug_vals[vars]|@debug_print_var}
no template variables assigned
assigned config file variables (outter template scope):
{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}{$_debug_config_vals[config_vars]|@debug_print_var}
no config vars assigned
- -{else} - -{/if}