@ -2,22 +2,18 @@
/**
/**
* Project: Smarty: the PHP compiling template engine
* Project: Smarty: the PHP compiling template engine
* File: Smarty.class.php
* File: Smarty.class.php
* SVN: $Id: Smarty.class.php 4800 2013-12-15 15:19:01Z Uwe.Tews@googlemail.com $
* SVN: $Id: Smarty.class.php 4897 2014-10-14 22:29:58Z Uwe.Tews@googlemail.com $
*
* This library is free software; you can redistribute it and/or
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For questions, help, comments, discussion, etc., please join the
* For questions, help, comments, discussion, etc., please join the
* Smarty mailing list. Send a blank e-mail to
* Smarty mailing list. Send a blank e-mail to
* smarty-discussion-subscribe@googlegroups.com
* smarty-discussion-subscribe@googlegroups.com
@ -28,7 +24,7 @@
* @author Uwe Tews
* @author Uwe Tews
* @author Rodney Rehm
* @author Rodney Rehm
* @package Smarty
* @package Smarty
* @version 3.1-DEV
* @version 3.1.21
*/
*/
/**
/**
@ -102,6 +98,7 @@ include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_cacheresource_file.php';
/**
/**
* This is the main Smarty class
* This is the main Smarty class
*
* @package Smarty
* @package Smarty
*/
*/
class Smarty extends Smarty_Internal_TemplateBase
class Smarty extends Smarty_Internal_TemplateBase
@ -113,7 +110,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* smarty version
* smarty version
*/
*/
const SMARTY_VERSION = 'Smarty-3.1.16 ';
const SMARTY_VERSION = 'Smarty-3.1.21-dev ';
/**
/**
* define variable scopes
* define variable scopes
@ -206,111 +203,133 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* auto literal on delimiters with whitspace
* auto literal on delimiters with whitspace
*
* @var boolean
* @var boolean
*/
*/
public $auto_literal = true;
public $auto_literal = true;
/**
/**
* display error on not assigned variables
* display error on not assigned variables
*
* @var boolean
* @var boolean
*/
*/
public $error_unassigned = false;
public $error_unassigned = false;
/**
/**
* look up relative filepaths in include_path
* look up relative filepaths in include_path
*
* @var boolean
* @var boolean
*/
*/
public $use_include_path = false;
public $use_include_path = false;
/**
/**
* template directory
* template directory
*
* @var array
* @var array
*/
*/
private $template_dir = array();
private $template_dir = array();
/**
/**
* joined template directory string used in cache keys
* joined template directory string used in cache keys
*
* @var string
* @var string
*/
*/
public $joined_template_dir = null;
public $joined_template_dir = null;
/**
/**
* joined config directory string used in cache keys
* joined config directory string used in cache keys
*
* @var string
* @var string
*/
*/
public $joined_config_dir = null;
public $joined_config_dir = null;
/**
/**
* default template handler
* default template handler
*
* @var callable
* @var callable
*/
*/
public $default_template_handler_func = null;
public $default_template_handler_func = null;
/**
/**
* default config handler
* default config handler
*
* @var callable
* @var callable
*/
*/
public $default_config_handler_func = null;
public $default_config_handler_func = null;
/**
/**
* default plugin handler
* default plugin handler
*
* @var callable
* @var callable
*/
*/
public $default_plugin_handler_func = null;
public $default_plugin_handler_func = null;
/**
/**
* compile directory
* compile directory
*
* @var string
* @var string
*/
*/
private $compile_dir = null;
private $compile_dir = null;
/**
/**
* plugins directory
* plugins directory
*
* @var array
* @var array
*/
*/
private $plugins_dir = array();
private $plugins_dir = array();
/**
/**
* cache directory
* cache directory
*
* @var string
* @var string
*/
*/
private $cache_dir = null;
private $cache_dir = null;
/**
/**
* config directory
* config directory
*
* @var array
* @var array
*/
*/
private $config_dir = array();
private $config_dir = array();
/**
/**
* force template compiling?
* force template compiling?
*
* @var boolean
* @var boolean
*/
*/
public $force_compile = false;
public $force_compile = false;
/**
/**
* check template for modifications?
* check template for modifications?
*
* @var boolean
* @var boolean
*/
*/
public $compile_check = true;
public $compile_check = true;
/**
/**
* use sub dirs for compiled/cached files?
* use sub dirs for compiled/cached files?
*
* @var boolean
* @var boolean
*/
*/
public $use_sub_dirs = false;
public $use_sub_dirs = false;
/**
/**
* allow ambiguous resources (that are made unique by the resource handler)
* allow ambiguous resources (that are made unique by the resource handler)
*
* @var boolean
* @var boolean
*/
*/
public $allow_ambiguous_resources = false;
public $allow_ambiguous_resources = false;
/**
/**
* caching enabled
* caching enabled
*
* @var boolean
* @var boolean
*/
*/
public $caching = false;
public $caching = false;
/**
/**
* merge compiled includes
* merge compiled includes
*
* @var boolean
* @var boolean
*/
*/
public $merge_compiled_includes = false;
public $merge_compiled_includes = false;
/**
/**
* template inheritance merge compiled includes
* template inheritance merge compiled includes
*
* @var boolean
* @var boolean
*/
*/
public $inheritance_merge_compiled_includes = true;
public $inheritance_merge_compiled_includes = true;
/**
/**
* cache lifetime in seconds
* cache lifetime in seconds
*
* @var integer
* @var integer
*/
*/
public $cache_lifetime = 3600;
public $cache_lifetime = 3600;
/**
/**
* force cache file creation
* force cache file creation
*
* @var boolean
* @var boolean
*/
*/
public $force_cache = false;
public $force_cache = false;
@ -330,11 +349,13 @@ class Smarty extends Smarty_Internal_TemplateBase
public $compile_id = null;
public $compile_id = null;
/**
/**
* template left-delimiter
* template left-delimiter
*
* @var string
* @var string
*/
*/
public $left_delimiter = "{";
public $left_delimiter = "{";
/**
/**
* template right-delimiter
* template right-delimiter
*
* @var string
* @var string
*/
*/
public $right_delimiter = "}";
public $right_delimiter = "}";
@ -343,7 +364,6 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
*/
/**
/**
* class name
* class name
*
* This should be instance of Smarty_Security.
* This should be instance of Smarty_Security.
*
*
* @var string
* @var string
@ -370,7 +390,6 @@ class Smarty extends Smarty_Internal_TemplateBase
public $allow_php_templates = false;
public $allow_php_templates = false;
/**
/**
* Should compiled-templates be prevented from being called directly?
* Should compiled-templates be prevented from being called directly?
*
* {@internal
* {@internal
* Currently used by Smarty_Internal_Template only.
* Currently used by Smarty_Internal_Template only.
* }}
* }}
@ -381,7 +400,6 @@ class Smarty extends Smarty_Internal_TemplateBase
/**#@-*/
/**#@-*/
/**
/**
* debug mode
* debug mode
*
* Setting this to true enables the debug-console.
* Setting this to true enables the debug-console.
*
*
* @var boolean
* @var boolean
@ -393,12 +411,12 @@ class Smarty extends Smarty_Internal_TemplateBase
* < li > NONE => no debugging control allowed< / li >
* < li > NONE => no debugging control allowed< / li >
* < li > URL => enable debugging when SMARTY_DEBUG is found in the URL.< / li >
* < li > URL => enable debugging when SMARTY_DEBUG is found in the URL.< / li >
* < / ul >
* < / ul >
*
* @var string
* @var string
*/
*/
public $debugging_ctrl = 'NONE';
public $debugging_ctrl = 'NONE';
/**
/**
* Name of debugging URL-param.
* Name of debugging URL-param.
*
* Only used when $debugging_ctrl is set to 'URL'.
* Only used when $debugging_ctrl is set to 'URL'.
* The name of the URL-parameter that activates debugging.
* The name of the URL-parameter that activates debugging.
*
*
@ -407,16 +425,19 @@ class Smarty extends Smarty_Internal_TemplateBase
public $smarty_debug_id = 'SMARTY_DEBUG';
public $smarty_debug_id = 'SMARTY_DEBUG';
/**
/**
* Path of debug template.
* Path of debug template.
*
* @var string
* @var string
*/
*/
public $debug_tpl = null;
public $debug_tpl = null;
/**
/**
* When set, smarty uses this value as error_reporting-level.
* When set, smarty uses this value as error_reporting-level.
*
* @var int
* @var int
*/
*/
public $error_reporting = null;
public $error_reporting = null;
/**
/**
* Internal flag for getTags()
* Internal flag for getTags()
*
* @var boolean
* @var boolean
*/
*/
public $get_used_tags = false;
public $get_used_tags = false;
@ -427,16 +448,19 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* Controls whether variables with the same name overwrite each other.
* Controls whether variables with the same name overwrite each other.
*
* @var boolean
* @var boolean
*/
*/
public $config_overwrite = true;
public $config_overwrite = true;
/**
/**
* Controls whether config values of on/true/yes and off/false/no get converted to boolean.
* Controls whether config values of on/true/yes and off/false/no get converted to boolean.
*
* @var boolean
* @var boolean
*/
*/
public $config_booleanize = true;
public $config_booleanize = true;
/**
/**
* Controls whether hidden config sections/vars are read from the file.
* Controls whether hidden config sections/vars are read from the file.
*
* @var boolean
* @var boolean
*/
*/
public $config_read_hidden = false;
public $config_read_hidden = false;
@ -449,16 +473,19 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* locking concurrent compiles
* locking concurrent compiles
*
* @var boolean
* @var boolean
*/
*/
public $compile_locking = true;
public $compile_locking = true;
/**
/**
* Controls whether cache resources should emply locking mechanism
* Controls whether cache resources should emply locking mechanism
*
* @var boolean
* @var boolean
*/
*/
public $cache_locking = false;
public $cache_locking = false;
/**
/**
* seconds to wait for acquiring a lock before ignoring the write lock
* seconds to wait for acquiring a lock before ignoring the write lock
*
* @var float
* @var float
*/
*/
public $locking_timeout = 10;
public $locking_timeout = 10;
@ -467,19 +494,19 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* global template functions
* global template functions
*
* @var array
* @var array
*/
*/
public $template_functions = array();
public $template_functions = array();
/**
/**
* resource type used if none given
* resource type used if none given
*
* Must be an valid key of $registered_resources.
* Must be an valid key of $registered_resources.
*
* @var string
* @var string
*/
*/
public $default_resource_type = 'file';
public $default_resource_type = 'file';
/**
/**
* caching type
* caching type
*
* Must be an element of $cache_resource_types.
* Must be an element of $cache_resource_types.
*
*
* @var string
* @var string
@ -487,121 +514,145 @@ class Smarty extends Smarty_Internal_TemplateBase
public $caching_type = 'file';
public $caching_type = 'file';
/**
/**
* internal config properties
* internal config properties
*
* @var array
* @var array
*/
*/
public $properties = array();
public $properties = array();
/**
/**
* config type
* config type
*
* @var string
* @var string
*/
*/
public $default_config_type = 'file';
public $default_config_type = 'file';
/**
/**
* cached template objects
* cached template objects
*
* @var array
* @var array
*/
*/
public $template_objects = array();
public $template_objects = array();
/**
/**
* check If-Modified-Since headers
* check If-Modified-Since headers
*
* @var boolean
* @var boolean
*/
*/
public $cache_modified_check = false;
public $cache_modified_check = false;
/**
/**
* registered plugins
* registered plugins
*
* @var array
* @var array
*/
*/
public $registered_plugins = array();
public $registered_plugins = array();
/**
/**
* plugin search order
* plugin search order
*
* @var array
* @var array
*/
*/
public $plugin_search_order = array('function', 'block', 'compiler', 'class');
public $plugin_search_order = array('function', 'block', 'compiler', 'class');
/**
/**
* registered objects
* registered objects
*
* @var array
* @var array
*/
*/
public $registered_objects = array();
public $registered_objects = array();
/**
/**
* registered classes
* registered classes
*
* @var array
* @var array
*/
*/
public $registered_classes = array();
public $registered_classes = array();
/**
/**
* registered filters
* registered filters
*
* @var array
* @var array
*/
*/
public $registered_filters = array();
public $registered_filters = array();
/**
/**
* registered resources
* registered resources
*
* @var array
* @var array
*/
*/
public $registered_resources = array();
public $registered_resources = array();
/**
/**
* resource handler cache
* resource handler cache
*
* @var array
* @var array
*/
*/
public $_resource_handlers = array();
public $_resource_handlers = array();
/**
/**
* registered cache resources
* registered cache resources
*
* @var array
* @var array
*/
*/
public $registered_cache_resources = array();
public $registered_cache_resources = array();
/**
/**
* cache resource handler cache
* cache resource handler cache
*
* @var array
* @var array
*/
*/
public $_cacheresource_handlers = array();
public $_cacheresource_handlers = array();
/**
/**
* autoload filter
* autoload filter
*
* @var array
* @var array
*/
*/
public $autoload_filters = array();
public $autoload_filters = array();
/**
/**
* default modifier
* default modifier
*
* @var array
* @var array
*/
*/
public $default_modifiers = array();
public $default_modifiers = array();
/**
/**
* autoescape variable output
* autoescape variable output
*
* @var boolean
* @var boolean
*/
*/
public $escape_html = false;
public $escape_html = false;
/**
/**
* global internal smarty vars
* global internal smarty vars
*
* @var array
* @var array
*/
*/
public static $_smarty_vars = array();
public static $_smarty_vars = array();
/**
/**
* start time for execution time calculation
* start time for execution time calculation
*
* @var int
* @var int
*/
*/
public $start_time = 0;
public $start_time = 0;
/**
/**
* default file permissions
* default file permissions
*
* @var int
* @var int
*/
*/
public $_file_perms = 0644;
public $_file_perms = 0644;
/**
/**
* default dir permissions
* default dir permissions
*
* @var int
* @var int
*/
*/
public $_dir_perms = 0771;
public $_dir_perms = 0771;
/**
/**
* block tag hierarchy
* block tag hierarchy
*
* @var array
* @var array
*/
*/
public $_tag_stack = array();
public $_tag_stack = array();
/**
/**
* self pointer to Smarty object
* self pointer to Smarty object
*
* @var Smarty
* @var Smarty
*/
*/
public $smarty;
public $smarty;
/**
/**
* required by the compiler for BC
* required by the compiler for BC
*
* @var string
* @var string
*/
*/
public $_current_file = null;
public $_current_file = null;
/**
/**
* internal flag to enable parser debugging
* internal flag to enable parser debugging
*
* @var bool
* @var bool
*/
*/
public $_parserdebug = false;
public $_parserdebug = false;
@ -611,11 +662,19 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var array
* @var array
*/
*/
public $merged_templates_func = array();
public $merged_templates_func = array();
/**
* Cache of is_file results of loadPlugin()
*
* @var array
*/
public static $_is_file_cache= array();
/**#@-*/
/**#@-*/
/**
/**
* Initialize new Smarty object
* Initialize new Smarty object
*
*/
*/
public function __construct()
public function __construct()
{
{
@ -656,11 +715,11 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* < < magic > > Generic getter.
* < < magic > > Generic getter.
*
* Calls the appropriate getter function.
* Calls the appropriate getter function.
* Issues an E_USER_NOTICE if no valid getter is found.
* Issues an E_USER_NOTICE if no valid getter is found.
*
*
* @param string $name property name
* @param string $name property name
*
* @return mixed
* @return mixed
*/
*/
public function __get($name)
public function __get($name)
@ -682,7 +741,6 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* < < magic > > Generic setter.
* < < magic > > Generic setter.
*
* Calls the appropriate setter function.
* Calls the appropriate setter function.
* Issues an E_USER_NOTICE if no valid setter is found.
* Issues an E_USER_NOTICE if no valid setter is found.
*
*
@ -710,6 +768,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* Check if a template resource exists
* Check if a template resource exists
*
*
* @param string $resource_name template name
* @param string $resource_name template name
*
* @return boolean status
* @return boolean status
*/
*/
public function templateExists($resource_name)
public function templateExists($resource_name)
@ -727,8 +786,8 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* Returns a single or all global variables
* Returns a single or all global variables
*
*
* @param object $smarty
* @param string $varname variable name or null
* @param string $varname variable name or null
*
* @return string variable value or or array of variables
* @return string variable value or or array of variables
*/
*/
public function getGlobal($varname = null)
public function getGlobal($varname = null)
@ -754,6 +813,7 @@ class Smarty extends Smarty_Internal_TemplateBase
*
*
* @param integer $exp_time expiration time
* @param integer $exp_time expiration time
* @param string $type resource type
* @param string $type resource type
*
* @return integer number of cache files deleted
* @return integer number of cache files deleted
*/
*/
public function clearAllCache($exp_time = null, $type = null)
public function clearAllCache($exp_time = null, $type = null)
@ -773,6 +833,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param string $compile_id compile id
* @param string $compile_id compile id
* @param integer $exp_time expiration time
* @param integer $exp_time expiration time
* @param string $type resource type
* @param string $type resource type
*
* @return integer number of cache files deleted
* @return integer number of cache files deleted
*/
*/
public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
@ -788,6 +849,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* Loads security class and enables security
* Loads security class and enables security
*
*
* @param string|Smarty_Security $security_class if a string is used, it must be class-name
* @param string|Smarty_Security $security_class if a string is used, it must be class-name
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
* @throws SmartyException when an invalid class name is provided
* @throws SmartyException when an invalid class name is provided
*/
*/
@ -816,6 +878,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* Disable security
* Disable security
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
*/
public function disableSecurity()
public function disableSecurity()
@ -829,13 +892,14 @@ class Smarty extends Smarty_Internal_TemplateBase
* Set template directory
* Set template directory
*
*
* @param string|array $template_dir directory(s) of template sources
* @param string|array $template_dir directory(s) of template sources
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
*/
public function setTemplateDir($template_dir)
public function setTemplateDir($template_dir)
{
{
$this->template_dir = array();
$this->template_dir = array();
foreach ((array) $template_dir as $k => $v) {
foreach ((array) $template_dir as $k => $v) {
$this->template_dir[$k] = rtrim($v, '/\\') . DS;
$this->template_dir[$k] = preg_replace('#(\w+)(/|\\\\){1,}#', '$1$2', rtrim($v, '/\\') ) . DS;
}
}
$this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir);
$this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir);
@ -848,6 +912,7 @@ class Smarty extends Smarty_Internal_TemplateBase
*
*
* @param string|array $template_dir directory(s) of template sources
* @param string|array $template_dir directory(s) of template sources
* @param string $key of the array element to assign the template dir to
* @param string $key of the array element to assign the template dir to
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
* @throws SmartyException when the given template directory is not valid
* @throws SmartyException when the given template directory is not valid
*/
*/
@ -858,20 +923,24 @@ class Smarty extends Smarty_Internal_TemplateBase
if (is_array($template_dir)) {
if (is_array($template_dir)) {
foreach ($template_dir as $k => $v) {
foreach ($template_dir as $k => $v) {
$v = preg_replace('#(\w+)(/|\\\\){1,}#', '$1$2', rtrim($v, '/\\')) . DS;
if (is_int($k)) {
if (is_int($k)) {
// indexes are not merged but appended
// indexes are not merged but appended
$this->template_dir[] = rtrim( $v, '/\\') . DS ;
$this->template_dir[] = $v;
} else {
} else {
// string indexes are overridden
// string indexes are overridden
$this->template_dir[$k] = rtrim( $v, '/\\') . DS ;
$this->template_dir[$k] = $v;
}
}
}
}
} elseif ($key !== null) {
} else {
$v = preg_replace('#(\w+)(/|\\\\){1,}#', '$1$2', rtrim($template_dir, '/\\')) . DS;
if ($key !== null) {
// override directory at specified index
// override directory at specified index
$this->template_dir[$key] = rtrim($template_dir, '/\\') . DS;
$this->template_dir[$key] = $v ;
} else {
} else {
// append new directory
// append new directory
$this->template_dir[] = rtrim($template_dir, '/\\') . DS;
$this->template_dir[] = $v;
}
}
}
$this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir);
$this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir);
@ -881,7 +950,8 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* Get template directories
* Get template directories
*
*
* @param mixed index of directory to get, null to get all
* @param mixed $index index of directory to get, null to get all
*
* @return array|string list of template directories, or directory of $index
* @return array|string list of template directories, or directory of $index
*/
*/
public function getTemplateDir($index = null)
public function getTemplateDir($index = null)
@ -896,14 +966,15 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* Set config directory
* Set config directory
*
*
* @param string|array $template_dir directory(s) of configuration sources
* @param $config_dir
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
*/
public function setConfigDir($config_dir)
public function setConfigDir($config_dir)
{
{
$this->config_dir = array();
$this->config_dir = array();
foreach ((array) $config_dir as $k => $v) {
foreach ((array) $config_dir as $k => $v) {
$this->config_dir[$k] = rtrim($v, '/\\') . DS;
$this->config_dir[$k] = preg_replace('#(\w+)(/|\\\\){1,}#', '$1$2', rtrim($v, '/\\') ) . DS;
}
}
$this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir);
$this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir);
@ -915,7 +986,8 @@ class Smarty extends Smarty_Internal_TemplateBase
* Add config directory(s)
* Add config directory(s)
*
*
* @param string|array $config_dir directory(s) of config sources
* @param string|array $config_dir directory(s) of config sources
* @param string key of the array element to assign the config dir to
* @param mixed $key key of the array element to assign the config dir to
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
*/
public function addConfigDir($config_dir, $key = null)
public function addConfigDir($config_dir, $key = null)
@ -925,20 +997,24 @@ class Smarty extends Smarty_Internal_TemplateBase
if (is_array($config_dir)) {
if (is_array($config_dir)) {
foreach ($config_dir as $k => $v) {
foreach ($config_dir as $k => $v) {
$v = preg_replace('#(\w+)(/|\\\\){1,}#', '$1$2', rtrim($v, '/\\')) . DS;
if (is_int($k)) {
if (is_int($k)) {
// indexes are not merged but appended
// indexes are not merged but appended
$this->config_dir[] = rtrim( $v, '/\\') . DS ;
$this->config_dir[] = $v;
} else {
} else {
// string indexes are overridden
// string indexes are overridden
$this->config_dir[$k] = rtrim( $v, '/\\') . DS ;
$this->config_dir[$k] = $v;
}
}
}
}
} elseif ($key !== null) {
} else {
$v = preg_replace('#(\w+)(/|\\\\){1,}#', '$1$2', rtrim($config_dir, '/\\')) . DS;
if ($key !== null) {
// override directory at specified index
// override directory at specified index
$this->config_dir[$key] = rtrim($config_dir, '/\\') . DS;
$this->config_dir[$key] = rtrim($v , '/\\') . DS;
} else {
} else {
// append new directory
// append new directory
$this->config_dir[] = rtrim($config_dir, '/\\') . DS;
$this->config_dir[] = rtrim($v, '/\\') . DS;
}
}
}
$this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir);
$this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir);
@ -949,7 +1025,8 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* Get config directory
* Get config directory
*
*
* @param mixed index of directory to get, null to get all
* @param mixed $index index of directory to get, null to get all
*
* @return array|string configuration directory
* @return array|string configuration directory
*/
*/
public function getConfigDir($index = null)
public function getConfigDir($index = null)
@ -965,6 +1042,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* Set plugins directory
* Set plugins directory
*
*
* @param string|array $plugins_dir directory(s) of plugins
* @param string|array $plugins_dir directory(s) of plugins
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
*/
public function setPluginsDir($plugins_dir)
public function setPluginsDir($plugins_dir)
@ -980,8 +1058,8 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
/**
* Adds directory of plugin files
* Adds directory of plugin files
*
*
* @param object $smarty
* @param $plugins_dir
* @param string $ |array $ plugins folder
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
*/
public function addPluginsDir($plugins_dir)
public function addPluginsDir($plugins_dir)
@ -1023,6 +1101,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* Set compile directory
* Set compile directory
*
*
* @param string $compile_dir directory to store compiled templates in
* @param string $compile_dir directory to store compiled templates in
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
*/
public function setCompileDir($compile_dir)
public function setCompileDir($compile_dir)
@ -1049,6 +1128,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* Set cache directory
* Set cache directory
*
*
* @param string $cache_dir directory to store cached templates in
* @param string $cache_dir directory to store cached templates in
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
*/
public function setCacheDir($cache_dir)
public function setCacheDir($cache_dir)
@ -1075,6 +1155,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* Set default modifiers
* Set default modifiers
*
*
* @param array|string $modifiers modifier or list of modifiers to set
* @param array|string $modifiers modifier or list of modifiers to set
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
*/
public function setDefaultModifiers($modifiers)
public function setDefaultModifiers($modifiers)
@ -1088,6 +1169,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* Add default modifiers
* Add default modifiers
*
*
* @param array|string $modifiers modifier or list of modifiers to add
* @param array|string $modifiers modifier or list of modifiers to add
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
*/
public function addDefaultModifiers($modifiers)
public function addDefaultModifiers($modifiers)
@ -1111,12 +1193,12 @@ class Smarty extends Smarty_Internal_TemplateBase
return $this->default_modifiers;
return $this->default_modifiers;
}
}
/**
/**
* Set autoload filters
* Set autoload filters
*
*
* @param array $filters filters to load automatically
* @param array $filters filters to load automatically
* @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types
* @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
*/
public function setAutoloadFilters($filters, $type = null)
public function setAutoloadFilters($filters, $type = null)
@ -1135,6 +1217,7 @@ class Smarty extends Smarty_Internal_TemplateBase
*
*
* @param array $filters filters to load automatically
* @param array $filters filters to load automatically
* @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types
* @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
*/
*/
public function addAutoloadFilters($filters, $type = null)
public function addAutoloadFilters($filters, $type = null)
@ -1162,6 +1245,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* Get autoload filters
* Get autoload filters
*
*
* @param string $type type of filter to get autoloads for. Defaults to all autoload filters
* @param string $type type of filter to get autoloads for. Defaults to all autoload filters
*
* @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type was specified
* @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type was specified
*/
*/
public function getAutoloadFilters($type = null)
public function getAutoloadFilters($type = null)
@ -1187,6 +1271,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* set the debug template
* set the debug template
*
*
* @param string $tpl_name
* @param string $tpl_name
*
* @return Smarty current Smarty instance for chaining
* @return Smarty current Smarty instance for chaining
* @throws SmartyException if file is not readable
* @throws SmartyException if file is not readable
*/
*/
@ -1208,15 +1293,16 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param mixed $compile_id compile id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
* @param object $parent next higher level of Smarty variables
* @param boolean $do_clone flag is Smarty object shall be cloned
* @param boolean $do_clone flag is Smarty object shall be cloned
*
* @return object template object
* @return object template object
*/
*/
public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)
public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)
{
{
if (!empty($cache_id) & & (is_object($cache_id) || is_array($cache_id))) {
if ($cache_id !== null & & (is_object($cache_id) || is_array($cache_id))) {
$parent = $cache_id;
$parent = $cache_id;
$cache_id = null;
$cache_id = null;
}
}
if (!empty($parent) & & is_array($parent)) {
if ($parent !== null & & is_array($parent)) {
$data = $parent;
$data = $parent;
$parent = null;
$parent = null;
} else {
} else {
@ -1267,7 +1353,6 @@ class Smarty extends Smarty_Internal_TemplateBase
return $tpl;
return $tpl;
}
}
/**
/**
* Takes unknown classes and loads plugin files for them
* Takes unknown classes and loads plugin files for them
* class name format: Smarty_PluginType_PluginName
* class name format: Smarty_PluginType_PluginName
@ -1275,6 +1360,8 @@ class Smarty extends Smarty_Internal_TemplateBase
*
*
* @param string $plugin_name class plugin name to load
* @param string $plugin_name class plugin name to load
* @param bool $check check if already loaded
* @param bool $check check if already loaded
*
* @throws SmartyException
* @return string |boolean filepath of loaded file or false
* @return string |boolean filepath of loaded file or false
*/
*/
public function loadPlugin($plugin_name, $check = true)
public function loadPlugin($plugin_name, $check = true)
@ -1289,15 +1376,12 @@ class Smarty extends Smarty_Internal_TemplateBase
// count($_name_parts) < 3 = = = ! isset ( $ _name_parts [ 2 ] )
// count($_name_parts) < 3 = = = ! isset ( $ _name_parts [ 2 ] )
if (!isset($_name_parts[2]) || strtolower($_name_parts[0]) !== 'smarty') {
if (!isset($_name_parts[2]) || strtolower($_name_parts[0]) !== 'smarty') {
throw new SmartyException("plugin {$plugin_name} is not a valid name format");
throw new SmartyException("plugin {$plugin_name} is not a valid name format");
return false;
}
}
// if type is "internal", get plugin from sysplugins
// if type is "internal", get plugin from sysplugins
if (strtolower($_name_parts[1]) == 'internal') {
if (strtolower($_name_parts[1]) == 'internal') {
$file = SMARTY_SYSPLUGINS_DIR . strtolower($plugin_name) . '.php';
$file = SMARTY_SYSPLUGINS_DIR . strtolower($plugin_name) . '.php';
if (file_exists ($file)) {
if (isset(self::$_is_file_cache[$file]) ? self::$_is_file_cache[$file] : self::$_is_file_cache[$file] = is_file ($file)) {
require_once($file);
require_once($file);
return $file;
return $file;
} else {
} else {
return false;
return false;
@ -1315,9 +1399,8 @@ class Smarty extends Smarty_Internal_TemplateBase
$_plugin_dir . strtolower($_plugin_filename),
$_plugin_dir . strtolower($_plugin_filename),
);
);
foreach ($names as $file) {
foreach ($names as $file) {
if (file_exists ($file)) {
if (isset(self::$_is_file_cache[$file]) ? self::$_is_file_cache[$file] : self::$_is_file_cache[$file] = is_file ($file)) {
require_once($file);
require_once($file);
return $file;
return $file;
}
}
if ($this->use_include_path & & !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
if ($this->use_include_path & & !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
@ -1347,6 +1430,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param bool $force_compile force all to recompile
* @param bool $force_compile force all to recompile
* @param int $time_limit
* @param int $time_limit
* @param int $max_errors
* @param int $max_errors
*
* @return integer number of template files recompiled
* @return integer number of template files recompiled
*/
*/
public function compileAllTemplates($extension = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
public function compileAllTemplates($extension = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
@ -1361,6 +1445,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param bool $force_compile force all to recompile
* @param bool $force_compile force all to recompile
* @param int $time_limit
* @param int $time_limit
* @param int $max_errors
* @param int $max_errors
*
* @return integer number of template files recompiled
* @return integer number of template files recompiled
*/
*/
public function compileAllConfig($extension = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null)
public function compileAllConfig($extension = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null)
@ -1374,6 +1459,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param string $resource_name template name
* @param string $resource_name template name
* @param string $compile_id compile id
* @param string $compile_id compile id
* @param integer $exp_time expiration time
* @param integer $exp_time expiration time
*
* @return integer number of template files deleted
* @return integer number of template files deleted
*/
*/
public function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
public function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
@ -1381,11 +1467,11 @@ class Smarty extends Smarty_Internal_TemplateBase
return Smarty_Internal_Utility::clearCompiledTemplate($resource_name, $compile_id, $exp_time, $this);
return Smarty_Internal_Utility::clearCompiledTemplate($resource_name, $compile_id, $exp_time, $this);
}
}
/**
/**
* Return array of tag/attributes of all tags used by an template
* Return array of tag/attributes of all tags used by an template
*
*
* @param object $templae template object
* @param Smarty_Internal_Template $template
*
* @return array of tag/attributes
* @return array of tag/attributes
*/
*/
public function getTags(Smarty_Internal_Template $template)
public function getTags(Smarty_Internal_Template $template)
@ -1397,6 +1483,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* Run installation test
* Run installation test
*
*
* @param array $errors Array to write errors into, rather than outputting them
* @param array $errors Array to write errors into, rather than outputting them
*
* @return boolean true if setup is fine, false if something is wrong
* @return boolean true if setup is fine, false if something is wrong
*/
*/
public function testInstall(& $errors = null)
public function testInstall(& $errors = null)
@ -1408,7 +1495,13 @@ class Smarty extends Smarty_Internal_TemplateBase
* Error Handler to mute expected messages
* Error Handler to mute expected messages
*
*
* @link http://php.net/set_error_handler
* @link http://php.net/set_error_handler
*
* @param integer $errno Error level
* @param integer $errno Error level
* @param $errstr
* @param $errfile
* @param $errline
* @param $errcontext
*
* @return boolean
* @return boolean
*/
*/
public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
@ -1511,6 +1604,7 @@ if (Smarty::$_CHARSET !== 'UTF-8') {
/**
/**
* Smarty exception class
* Smarty exception class
*
* @package Smarty
* @package Smarty
*/
*/
class SmartyException extends Exception
class SmartyException extends Exception
@ -1525,6 +1619,7 @@ class SmartyException extends Exception
/**
/**
* Smarty compiler exception class
* Smarty compiler exception class
*
* @package Smarty
* @package Smarty
*/
*/
class SmartyCompilerException extends SmartyException
class SmartyCompilerException extends SmartyException
@ -1533,23 +1628,28 @@ class SmartyCompilerException extends SmartyException
{
{
return ' --> Smarty Compiler: ' . $this->message . ' < -- ' ;
return ' --> Smarty Compiler: ' . $this->message . ' < -- ' ;
}
}
/**
/**
* The line number of the template error
* The line number of the template error
*
* @type int|null
* @type int|null
*/
*/
public $line = null;
public $line = null;
/**
/**
* The template source snippet relating to the error
* The template source snippet relating to the error
*
* @type string|null
* @type string|null
*/
*/
public $source = null;
public $source = null;
/**
/**
* The raw text of the error message
* The raw text of the error message
*
* @type string|null
* @type string|null
*/
*/
public $desc = null;
public $desc = null;
/**
/**
* The resource identifier or template name
* The resource identifier or template name
*
* @type string|null
* @type string|null
*/
*/
public $template = null;
public $template = null;