uwetews
2018-08-19 02:35:46 +02:00
parent b5e5085391
commit 799b5cb342
51 changed files with 2869 additions and 3418 deletions

View File

@@ -1,4 +1,11 @@
===== 3.1.33-dev-4 ===== ===== 3.1.33-dev-6 =====
19.08.2018
- fix PSR-2 coding standards and PHPDoc blocks https://github.com/smarty-php/smarty/pull/452
https://github.com/smarty-php/smarty/pull/475
https://github.com/smarty-php/smarty/pull/473
- bugfix PHP5.2 compatibility https://github.com/smarty-php/smarty/pull/472
===== 3.1.33-dev-4 =====
17.05.2018 17.05.2018
- bugfix strip-block produces different output in Smarty v3.1.32 https://github.com/smarty-php/smarty/issues/436 - bugfix strip-block produces different output in Smarty v3.1.32 https://github.com/smarty-php/smarty/issues/436
- bugfix Smarty::compileAllTemplates ignores `$extension` parameter https://github.com/smarty-php/smarty/issues/437 - bugfix Smarty::compileAllTemplates ignores `$extension` parameter https://github.com/smarty-php/smarty/issues/437

View File

@@ -124,7 +124,7 @@ class Smarty_Internal_Configfilelexer
* @param string $data template source * @param string $data template source
* @param Smarty_Internal_Config_File_Compiler $compiler * @param Smarty_Internal_Config_File_Compiler $compiler
*/ */
function __construct($data, Smarty_Internal_Config_File_Compiler $compiler) public function __construct($data, Smarty_Internal_Config_File_Compiler $compiler)
{ {
$this->data = $data . "\n"; //now all lines are \n-terminated $this->data = $data . "\n"; //now all lines are \n-terminated
$this->dataLength = strlen($data); $this->dataLength = strlen($data);

View File

@@ -89,7 +89,7 @@ class Smarty_Internal_Configfileparser
* @param Smarty_Internal_Configfilelexer $lex * @param Smarty_Internal_Configfilelexer $lex
* @param Smarty_Internal_Config_File_Compiler $compiler * @param Smarty_Internal_Config_File_Compiler $compiler
*/ */
function __construct(Smarty_Internal_Configfilelexer $lex, Smarty_Internal_Config_File_Compiler $compiler) public function __construct(Smarty_Internal_Configfilelexer $lex, Smarty_Internal_Config_File_Compiler $compiler)
{ {
$this->lex = $lex; $this->lex = $lex;
$this->smarty = $compiler->smarty; $this->smarty = $compiler->smarty;

View File

@@ -215,7 +215,7 @@ class Smarty_Internal_Templatelexer
* @param string $source template source * @param string $source template source
* @param Smarty_Internal_TemplateCompilerBase $compiler * @param Smarty_Internal_TemplateCompilerBase $compiler
*/ */
function __construct($source, Smarty_Internal_TemplateCompilerBase $compiler) public function __construct($source, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$this->data = $source; $this->data = $source;
$this->dataLength = strlen($this->data); $this->dataLength = strlen($this->data);

View File

@@ -147,7 +147,7 @@ class Smarty_Internal_Templateparser
* @param Smarty_Internal_Templatelexer $lex * @param Smarty_Internal_Templatelexer $lex
* @param Smarty_Internal_TemplateCompilerBase $compiler * @param Smarty_Internal_TemplateCompilerBase $compiler
*/ */
function __construct(Smarty_Internal_Templatelexer $lex, Smarty_Internal_TemplateCompilerBase $compiler) public function __construct(Smarty_Internal_Templatelexer $lex, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$this->lex = $lex; $this->lex = $lex;
$this->compiler = $compiler; $this->compiler = $compiler;

View File

@@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.33-dev-5'; const SMARTY_VERSION = '3.1.33-dev-6';
/** /**
* define variable scopes * define variable scopes
*/ */
@@ -166,133 +166,157 @@ class Smarty extends Smarty_Internal_TemplateBase
const PLUGIN_COMPILER = 'compiler'; const PLUGIN_COMPILER = 'compiler';
const PLUGIN_MODIFIER = 'modifier'; const PLUGIN_MODIFIER = 'modifier';
const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler'; const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler';
/** /**
* assigned global tpl vars * assigned global tpl vars
*/ */
public static $global_tpl_vars = array(); public static $global_tpl_vars = array();
/** /**
* Flag denoting if Multibyte String functions are available * Flag denoting if Multibyte String functions are available
*/ */
public static $_MBSTRING = SMARTY_MBSTRING; public static $_MBSTRING = SMARTY_MBSTRING;
/** /**
* The character set to adhere to (e.g. "UTF-8") * The character set to adhere to (e.g. "UTF-8")
*/ */
public static $_CHARSET = SMARTY_RESOURCE_CHAR_SET; public static $_CHARSET = SMARTY_RESOURCE_CHAR_SET;
/** /**
* The date format to be used internally * The date format to be used internally
* (accepts date() and strftime()) * (accepts date() and strftime())
*/ */
public static $_DATE_FORMAT = SMARTY_RESOURCE_DATE_FORMAT; public static $_DATE_FORMAT = SMARTY_RESOURCE_DATE_FORMAT;
/** /**
* Flag denoting if PCRE should run in UTF-8 mode * Flag denoting if PCRE should run in UTF-8 mode
*/ */
public static $_UTF8_MODIFIER = 'u'; public static $_UTF8_MODIFIER = 'u';
/** /**
* Flag denoting if operating system is windows * Flag denoting if operating system is windows
*/ */
public static $_IS_WINDOWS = false; public static $_IS_WINDOWS = false;
/** /**
* auto literal on delimiters with whitespace * auto literal on delimiters with whitespace
* *
* @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 file path in include_path * look up relative file path in include_path
* *
* @var boolean * @var boolean
*/ */
public $use_include_path = false; public $use_include_path = false;
/** /**
* flag if template_dir is normalized * flag if template_dir is normalized
* *
* @var bool * @var bool
*/ */
public $_templateDirNormalized = false; public $_templateDirNormalized = false;
/** /**
* 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;
/** /**
* flag if config_dir is normalized * flag if config_dir is normalized
* *
* @var bool * @var bool
*/ */
public $_configDirNormalized = false; public $_configDirNormalized = false;
/** /**
* 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;
/** /**
* flag if template_dir is normalized * flag if template_dir is normalized
* *
* @var bool * @var bool
*/ */
public $_compileDirNormalized = false; public $_compileDirNormalized = false;
/** /**
* flag if plugins_dir is normalized * flag if plugins_dir is normalized
* *
* @var bool * @var bool
*/ */
public $_pluginsDirNormalized = false; public $_pluginsDirNormalized = false;
/** /**
* flag if template_dir is normalized * flag if template_dir is normalized
* *
* @var bool * @var bool
*/ */
public $_cacheDirNormalized = false; public $_cacheDirNormalized = false;
/** /**
* force template compiling? * force template compiling?
* *
* @var boolean * @var boolean
*/ */
public $force_compile = false; public $force_compile = false;
/**
* 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;
/** /**
* merge compiled includes * merge compiled includes
* *
* @var boolean * @var boolean
*/ */
public $merge_compiled_includes = false; public $merge_compiled_includes = false;
/* /*
* flag for behaviour when extends: resource and {extends} tag are used simultaneous * flag for behaviour when extends: resource and {extends} tag are used simultaneous
* if false disable execution of {extends} in templates called by extends resource. * if false disable execution of {extends} in templates called by extends resource.
@@ -301,30 +325,35 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var boolean * @var boolean
*/ */
public $extends_recursion = true; public $extends_recursion = true;
/** /**
* force cache file creation * force cache file creation
* *
* @var boolean * @var boolean
*/ */
public $force_cache = false; public $force_cache = false;
/** /**
* 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 = "}";
/** /**
* array of strings which shall be treated as literal by compiler * array of strings which shall be treated as literal by compiler
* *
* @var array string * @var array string
*/ */
public $literals = array(); public $literals = array();
/** /**
* class name * class name
* This should be instance of Smarty_Security. * This should be instance of Smarty_Security.
@@ -333,24 +362,28 @@ class Smarty extends Smarty_Internal_TemplateBase
* @see Smarty_Security * @see Smarty_Security
*/ */
public $security_class = 'Smarty_Security'; public $security_class = 'Smarty_Security';
/** /**
* implementation of security class * implementation of security class
* *
* @var Smarty_Security * @var Smarty_Security
*/ */
public $security_policy = null; public $security_policy = null;
/** /**
* controls handling of PHP-blocks * controls handling of PHP-blocks
* *
* @var integer * @var integer
*/ */
public $php_handling = self::PHP_PASSTHRU; public $php_handling = self::PHP_PASSTHRU;
/** /**
* controls if the php template file resource is allowed * controls if the php template file resource is allowed
* *
* @var bool * @var bool
*/ */
public $allow_php_templates = false; public $allow_php_templates = false;
/** /**
* debug mode * debug mode
* Setting this to true enables the debug-console. * Setting this to true enables the debug-console.
@@ -358,6 +391,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var boolean * @var boolean
*/ */
public $debugging = false; public $debugging = false;
/** /**
* This determines if debugging is enable-able from the browser. * This determines if debugging is enable-able from the browser.
* <ul> * <ul>
@@ -368,6 +402,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @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'.
@@ -376,54 +411,63 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var string * @var string
*/ */
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;
/** /**
* 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;
/** /**
* locking concurrent compiles * locking concurrent compiles
* *
* @var boolean * @var boolean
*/ */
public $compile_locking = true; public $compile_locking = true;
/** /**
* Controls whether cache resources should use locking mechanism * Controls whether cache resources should use 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;
/** /**
* 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.
@@ -431,6 +475,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @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.
@@ -438,144 +483,168 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var string * @var string
*/ */
public $caching_type = 'file'; public $caching_type = 'file';
/** /**
* config type * config type
* *
* @var string * @var string
*/ */
public $default_config_type = 'file'; public $default_config_type = 'file';
/** /**
* 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();
/** /**
* 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();
/** /**
* registered cache resources * registered cache resources
* *
* @var array * @var array
*/ */
public $registered_cache_resources = array(); public $registered_cache_resources = 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;
/** /**
* start time for execution time calculation * start time for execution time calculation
* *
* @var int * @var int
*/ */
public $start_time = 0; public $start_time = 0;
/** /**
* 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;
/** /**
* This object type (Smarty = 1, template = 2, data = 4) * This object type (Smarty = 1, template = 2, data = 4)
* *
* @var int * @var int
*/ */
public $_objType = 1; public $_objType = 1;
/** /**
* Debug object * Debug object
* *
* @var Smarty_Internal_Debug * @var Smarty_Internal_Debug
*/ */
public $_debug = null; public $_debug = null;
/** /**
* template directory * template directory
* *
* @var array * @var array
*/ */
protected $template_dir = array('./templates/'); protected $template_dir = array('./templates/');
/** /**
* flags for normalized template directory entries * flags for normalized template directory entries
* *
* @var array * @var array
*/ */
protected $_processedTemplateDir = array(); protected $_processedTemplateDir = array();
/** /**
* config directory * config directory
* *
* @var array * @var array
*/ */
protected $config_dir = array('./configs/'); protected $config_dir = array('./configs/');
/** /**
* flags for normalized template directory entries * flags for normalized template directory entries
* *
* @var array * @var array
*/ */
protected $_processedConfigDir = array(); protected $_processedConfigDir = array();
/** /**
* compile directory * compile directory
* *
* @var string * @var string
*/ */
protected $compile_dir = './templates_c/'; protected $compile_dir = './templates_c/';
/** /**
* plugins directory * plugins directory
* *
* @var array * @var array
*/ */
protected $plugins_dir = array(); protected $plugins_dir = array();
/** /**
* cache directory * cache directory
* *
* @var string * @var string
*/ */
protected $cache_dir = './cache/'; protected $cache_dir = './cache/';
/** /**
* removed properties * removed properties
* *
@@ -584,6 +653,7 @@ class Smarty extends Smarty_Internal_TemplateBase
protected $obsoleteProperties = array('resource_caching', 'template_resource_caching', 'direct_access_security', protected $obsoleteProperties = array('resource_caching', 'template_resource_caching', 'direct_access_security',
'_dir_perms', '_file_perms', 'plugin_search_order', '_dir_perms', '_file_perms', 'plugin_search_order',
'inheritance_merge_compiled_includes', 'resource_cache_mode',); 'inheritance_merge_compiled_includes', 'resource_cache_mode',);
/** /**
* List of private properties which will call getter/setter on a direct access * List of private properties which will call getter/setter on a direct access
* *
@@ -657,7 +727,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @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
*/ */
public function enableSecurity($security_class = null) public function enableSecurity($security_class = null)
{ {
@@ -946,7 +1016,7 @@ class Smarty extends Smarty_Internal_TemplateBase
Smarty_Internal_Template::$isCacheTplObj[ $_templateId ]; Smarty_Internal_Template::$isCacheTplObj[ $_templateId ];
$tpl->inheritance = null; $tpl->inheritance = null;
$tpl->tpl_vars = $tpl->config_vars = array(); $tpl->tpl_vars = $tpl->config_vars = array();
} else if (!$do_clone && isset(Smarty_Internal_Template::$tplObjCache[ $_templateId ])) { } elseif (!$do_clone && isset(Smarty_Internal_Template::$tplObjCache[ $_templateId ])) {
$tpl = clone Smarty_Internal_Template::$tplObjCache[ $_templateId ]; $tpl = clone Smarty_Internal_Template::$tplObjCache[ $_templateId ];
$tpl->inheritance = null; $tpl->inheritance = null;
$tpl->tpl_vars = $tpl->config_vars = array(); $tpl->tpl_vars = $tpl->config_vars = array();
@@ -984,8 +1054,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
* @throws \SmartyException
*/ */
public function loadPlugin($plugin_name, $check = true) public function loadPlugin($plugin_name, $check = true)
{ {
@@ -1005,13 +1075,14 @@ class Smarty extends Smarty_Internal_TemplateBase
* @throws \SmartyException * @throws \SmartyException
*/ */
public function _getTemplateId($template_name, public function _getTemplateId($template_name,
$cache_id = null, $cache_id = null,
$compile_id = null, $compile_id = null,
$caching = null, $caching = null,
Smarty_Internal_Template $template = null Smarty_Internal_Template $template = null
) { )
{
$template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" : $template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
$template_name; $template_name;
$cache_id = $cache_id === null ? $this->cache_id : $cache_id; $cache_id = $cache_id === null ? $this->cache_id : $cache_id;
$compile_id = $compile_id === null ? $this->compile_id : $compile_id; $compile_id = $compile_id === null ? $this->compile_id : $compile_id;
$caching = (int)($caching === null ? $this->caching : $caching); $caching = (int)($caching === null ? $this->caching : $caching);
@@ -1044,8 +1115,6 @@ class Smarty extends Smarty_Internal_TemplateBase
public function _realpath($path, $realpath = null) public function _realpath($path, $realpath = null)
{ {
$nds = array('/' => '\\', '\\' => '/'); $nds = array('/' => '\\', '\\' => '/');
// normalize DIRECTORY_SEPARATOR
//$path = str_replace(array($nds[DIRECTORY_SEPARATOR], DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, $path);
preg_match( preg_match(
'%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u', '%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u',
$path, $path,
@@ -1059,12 +1128,17 @@ class Smarty extends Smarty_Internal_TemplateBase
$path = getcwd() . DIRECTORY_SEPARATOR . $path; $path = getcwd() . DIRECTORY_SEPARATOR . $path;
} }
} }
// normalize DIRECTORY_SEPARATOR
$path = str_replace($nds[DIRECTORY_SEPARATOR], DIRECTORY_SEPARATOR, $path);
do { do {
$path = preg_replace( $path = preg_replace(
array('#[\\\\/]{2}#', '#[\\\\/][.][\\\\/]#', '#[\\\\/]([^\\\\/.]+)[\\\\/][.][.][\\\\/]#'), array('#[\\\\/]{2}#', '#[\\\\/][.][\\\\/]#', '#[\\\\/]([^\\\\/.]+)[\\\\/][.][.][\\\\/]#'),
DIRECTORY_SEPARATOR, $path, -1, $count DIRECTORY_SEPARATOR,
$path,
-1,
$count
); );
} while($count > 0); } while ($count > 0);
return $realpath !== false ? $parts[ 'root' ] . $path : str_ireplace(getcwd(), '.', $parts[ 'root' ] . $path); return $realpath !== false ? $parts[ 'root' ] . $path : str_ireplace(getcwd(), '.', $parts[ 'root' ] . $path);
} }
@@ -1261,22 +1335,19 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param string $name property name * @param string $name property name
* *
* @return mixed * @return mixed
* @throws \SmartyException
*/ */
public function __get($name) public function __get($name)
{ {
if (isset($this->accessMap[ $name ])) { if (isset($this->accessMap[ $name ])) {
$method = 'get' . $this->accessMap[ $name ]; $method = 'get' . $this->accessMap[ $name ];
return $this->{$method}(); return $this->{$method}();
} else {if (isset($this->_cache[ $name ])) { } elseif (isset($this->_cache[ $name ])) {
return $this->_cache[ $name ]; return $this->_cache[ $name ];
} else {if (in_array($name, $this->obsoleteProperties)) { } elseif (in_array($name, $this->obsoleteProperties)) {
return null; return null;
} else { } else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
} }
}
}
return null; return null;
} }
@@ -1288,22 +1359,18 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param string $name property name * @param string $name property name
* @param mixed $value parameter passed to setter * @param mixed $value parameter passed to setter
* *
* @throws \SmartyException
*/ */
public function __set($name, $value) public function __set($name, $value)
{ {
if (isset($this->accessMap[ $name ])) { if (isset($this->accessMap[ $name ])) {
$method = 'set' . $this->accessMap[ $name ]; $method = 'set' . $this->accessMap[ $name ];
$this->{$method}($value); $this->{$method}($value);
} else {if (in_array($name, $this->obsoleteProperties)) { } elseif (in_array($name, $this->obsoleteProperties)) {
return; return;
} elseif (is_object($value) && method_exists($value, $name)) {
$this->$name = $value;
} else { } else {
if (is_object($value) && method_exists($value, $name)) { trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
$this->$name = $value;
} else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
}
}
} }
} }

View File

@@ -127,7 +127,7 @@
{foreach $assigned_vars as $vars} {foreach $assigned_vars as $vars}
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}"> <tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
<td><h3><font color=blue>${$vars@key}</font></h3> <td><h3><font color=blue>${$vars@key}</font></h3>
{if isset($vars['nocache'])}<b>Nocache</b></br>{/if} {if isset($vars['nocache'])}<b>Nocache</b><br>{/if}
{if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if} {if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if}
</td> </td>
<td><h3>Value</h3>{$vars['value']|debug_print_var:10:80 nofilter}</td> <td><h3>Value</h3>{$vars['value']|debug_print_var:10:80 nofilter}</td>

View File

@@ -20,7 +20,7 @@
* - indent_char - string (" ") * - indent_char - string (" ")
* - wrap_boundary - boolean (true) * - wrap_boundary - boolean (true)
* *
* @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat} * @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat}
* (Smarty online manual) * (Smarty online manual)
* *
* @param array $params parameters * @param array $params parameters
@@ -40,10 +40,9 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
$template->_checkPlugins( $template->_checkPlugins(
array(array('function' => 'smarty_modifier_mb_wordwrap', array(array('function' => 'smarty_modifier_mb_wordwrap',
'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php')) 'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php'))
); );
} }
$style = null; $style = null;
$indent = 0; $indent = 0;
$indent_first = 0; $indent_first = 0;
@@ -52,37 +51,31 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
$wrap_char = "\n"; $wrap_char = "\n";
$wrap_cut = false; $wrap_cut = false;
$assign = null; $assign = null;
foreach ($params as $_key => $_val) { foreach ($params as $_key => $_val) {
switch ($_key) { switch ($_key) {
case 'style': case 'style':
case 'indent_char': case 'indent_char':
case 'wrap_char': case 'wrap_char':
case 'assign': case 'assign':
$$_key = (string) $_val; $$_key = (string)$_val;
break; break;
case 'indent':
case 'indent': case 'indent_first':
case 'indent_first': case 'wrap':
case 'wrap': $$_key = (int)$_val;
$$_key = (int) $_val; break;
break; case 'wrap_cut':
$$_key = (bool)$_val;
case 'wrap_cut': break;
$$_key = (bool) $_val; default:
break; trigger_error("textformat: unknown attribute '{$_key}'");
default:
trigger_error("textformat: unknown attribute '{$_key}'");
} }
} }
if ($style === 'email') { if ($style === 'email') {
$wrap = 72; $wrap = 72;
} }
// split into paragraphs // split into paragraphs
$_paragraphs = preg_split('![\r\n]{2}!', $content); $_paragraphs = preg_split('![\r\n]{2}!', $content);
foreach ($_paragraphs as &$_paragraph) { foreach ($_paragraphs as &$_paragraph) {
if (!$_paragraph) { if (!$_paragraph) {
continue; continue;
@@ -91,9 +84,10 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
$_paragraph = $_paragraph =
preg_replace( preg_replace(
array('!\s+!' . Smarty::$_UTF8_MODIFIER, array('!\s+!' . Smarty::$_UTF8_MODIFIER,
'!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER),
array(' ', array(' ',
''), $_paragraph ''),
$_paragraph
); );
// indent first line // indent first line
if ($indent_first > 0) { if ($indent_first > 0) {
@@ -111,7 +105,6 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
} }
} }
$_output = implode($wrap_char . $wrap_char, $_paragraphs); $_output = implode($wrap_char . $wrap_char, $_paragraphs);
if ($assign) { if ($assign) {
$template->assign($assign, $_output); $template->assign($assign, $_output);
} else { } else {

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {fetch} plugin * Smarty {fetch} plugin
* Type: function * Type: function
@@ -26,20 +25,16 @@ function smarty_function_fetch($params, $template)
{ {
if (empty($params[ 'file' ])) { if (empty($params[ 'file' ])) {
trigger_error('[plugin] fetch parameter \'file\' cannot be empty', E_USER_NOTICE); trigger_error('[plugin] fetch parameter \'file\' cannot be empty', E_USER_NOTICE);
return; return;
} }
// strip file protocol // strip file protocol
if (stripos($params[ 'file' ], 'file://') === 0) { if (stripos($params[ 'file' ], 'file://') === 0) {
$params[ 'file' ] = substr($params[ 'file' ], 7); $params[ 'file' ] = substr($params[ 'file' ], 7);
} }
$protocol = strpos($params[ 'file' ], '://'); $protocol = strpos($params[ 'file' ], '://');
if ($protocol !== false) { if ($protocol !== false) {
$protocol = strtolower(substr($params[ 'file' ], 0, $protocol)); $protocol = strtolower(substr($params[ 'file' ], 0, $protocol));
} }
if (isset($template->smarty->security_policy)) { if (isset($template->smarty->security_policy)) {
if ($protocol) { if ($protocol) {
// remote resource (or php stream, …) // remote resource (or php stream, …)
@@ -53,7 +48,6 @@ function smarty_function_fetch($params, $template)
} }
} }
} }
$content = ''; $content = '';
if ($protocol === 'http') { if ($protocol === 'http') {
// http fetch // http fetch
@@ -81,73 +75,69 @@ function smarty_function_fetch($params, $template)
// loop through parameters, setup headers // loop through parameters, setup headers
foreach ($params as $param_key => $param_value) { foreach ($params as $param_key => $param_value) {
switch ($param_key) { switch ($param_key) {
case 'file': case 'file':
case 'assign': case 'assign':
case 'assign_headers': case 'assign_headers':
break; break;
case 'user': case 'user':
if (!empty($param_value)) { if (!empty($param_value)) {
$user = $param_value; $user = $param_value;
}
break;
case 'pass':
if (!empty($param_value)) {
$pass = $param_value;
}
break;
case 'accept':
if (!empty($param_value)) {
$accept = $param_value;
}
break;
case 'header':
if (!empty($param_value)) {
if (!preg_match('![\w\d-]+: .+!', $param_value)) {
trigger_error("[plugin] invalid header format '{$param_value}'", E_USER_NOTICE);
return;
} else {
$extra_headers[] = $param_value;
} }
} break;
break; case 'pass':
case 'proxy_host': if (!empty($param_value)) {
if (!empty($param_value)) { $pass = $param_value;
$proxy_host = $param_value; }
} break;
break; case 'accept':
case 'proxy_port': if (!empty($param_value)) {
if (!preg_match('!\D!', $param_value)) { $accept = $param_value;
$proxy_port = (int) $param_value; }
} else { break;
trigger_error("[plugin] invalid value for attribute '{$param_key }'", E_USER_NOTICE); case 'header':
if (!empty($param_value)) {
if (!preg_match('![\w\d-]+: .+!', $param_value)) {
trigger_error("[plugin] invalid header format '{$param_value}'", E_USER_NOTICE);
return;
} else {
$extra_headers[] = $param_value;
}
}
break;
case 'proxy_host':
if (!empty($param_value)) {
$proxy_host = $param_value;
}
break;
case 'proxy_port':
if (!preg_match('!\D!', $param_value)) {
$proxy_port = (int)$param_value;
} else {
trigger_error("[plugin] invalid value for attribute '{$param_key }'", E_USER_NOTICE);
return;
}
break;
case 'agent':
if (!empty($param_value)) {
$agent = $param_value;
}
break;
case 'referer':
if (!empty($param_value)) {
$referer = $param_value;
}
break;
case 'timeout':
if (!preg_match('!\D!', $param_value)) {
$timeout = (int)$param_value;
} else {
trigger_error("[plugin] invalid value for attribute '{$param_key}'", E_USER_NOTICE);
return;
}
break;
default:
trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE);
return; return;
}
break;
case 'agent':
if (!empty($param_value)) {
$agent = $param_value;
}
break;
case 'referer':
if (!empty($param_value)) {
$referer = $param_value;
}
break;
case 'timeout':
if (!preg_match('!\D!', $param_value)) {
$timeout = (int) $param_value;
} else {
trigger_error("[plugin] invalid value for attribute '{$param_key}'", E_USER_NOTICE);
return;
}
break;
default:
trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE);
return;
} }
} }
if (!empty($proxy_host) && !empty($proxy_port)) { if (!empty($proxy_host) && !empty($proxy_port)) {
@@ -156,10 +146,8 @@ function smarty_function_fetch($params, $template)
} else { } else {
$fp = fsockopen($server_name, $port, $errno, $errstr, $timeout); $fp = fsockopen($server_name, $port, $errno, $errstr, $timeout);
} }
if (!$fp) { if (!$fp) {
trigger_error("[plugin] unable to fetch: $errstr ($errno)", E_USER_NOTICE); trigger_error("[plugin] unable to fetch: $errstr ($errno)", E_USER_NOTICE);
return; return;
} else { } else {
if ($_is_proxy) { if ($_is_proxy) {
@@ -187,23 +175,19 @@ function smarty_function_fetch($params, $template)
if (!empty($user) && !empty($pass)) { if (!empty($user) && !empty($pass)) {
fputs($fp, 'Authorization: BASIC ' . base64_encode("$user:$pass") . "\r\n"); fputs($fp, 'Authorization: BASIC ' . base64_encode("$user:$pass") . "\r\n");
} }
fputs($fp, "\r\n"); fputs($fp, "\r\n");
while (!feof($fp)) { while (!feof($fp)) {
$content .= fgets($fp, 4096); $content .= fgets($fp, 4096);
} }
fclose($fp); fclose($fp);
$csplit = preg_split("!\r\n\r\n!", $content, 2); $csplit = preg_split("!\r\n\r\n!", $content, 2);
$content = $csplit[ 1 ]; $content = $csplit[ 1 ];
if (!empty($params[ 'assign_headers' ])) { if (!empty($params[ 'assign_headers' ])) {
$template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ])); $template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ]));
} }
} }
} else { } else {
trigger_error("[plugin fetch] unable to parse URL, check syntax", E_USER_NOTICE); trigger_error("[plugin fetch] unable to parse URL, check syntax", E_USER_NOTICE);
return; return;
} }
} else { } else {
@@ -212,7 +196,6 @@ function smarty_function_fetch($params, $template)
throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'"); throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'");
} }
} }
if (!empty($params[ 'assign' ])) { if (!empty($params[ 'assign' ])) {
$template->assign($params[ 'assign' ], $content); $template->assign($params[ 'assign' ], $content);
} else { } else {

View File

@@ -39,16 +39,15 @@
* @param Smarty_Internal_Template $template template object * @param Smarty_Internal_Template $template template object
* *
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
* @throws \SmartyException * @throws \SmartyException
*/ */
function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template) function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template)
{ {
$template->_checkPlugins( $template->_checkPlugins(
array(array('function' => 'smarty_function_escape_special_chars', array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')) 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
); );
$name = 'checkbox'; $name = 'checkbox';
$values = null; $values = null;
$options = null; $options = null;
@@ -58,119 +57,112 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
$labels = true; $labels = true;
$label_ids = false; $label_ids = false;
$output = null; $output = null;
$extra = ''; $extra = '';
foreach ($params as $_key => $_val) { foreach ($params as $_key => $_val) {
switch ($_key) { switch ($_key) {
case 'name': case 'name':
case 'separator': case 'separator':
$$_key = (string) $_val; $$_key = (string)$_val;
break;
case 'escape':
case 'labels':
case 'label_ids':
$$_key = (bool) $_val;
break;
case 'options':
$$_key = (array) $_val;
break;
case 'values':
case 'output':
$$_key = array_values((array) $_val);
break;
case 'checked':
case 'selected':
if (is_array($_val)) {
$selected = array();
foreach ($_val as $_sel) {
if (is_object($_sel)) {
if (method_exists($_sel, '__toString')) {
$_sel = smarty_function_escape_special_chars((string) $_sel->__toString());
} else {
trigger_error(
'html_checkboxes: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method', E_USER_NOTICE
);
continue;
}
} else {
$_sel = smarty_function_escape_special_chars((string) $_sel);
}
$selected[ $_sel ] = true;
}
} elseif (is_object($_val)) {
if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
} else {
trigger_error(
'html_checkboxes: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method', E_USER_NOTICE
);
}
} else {
$selected = smarty_function_escape_special_chars((string) $_val);
}
break;
case 'checkboxes':
trigger_error(
'html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead',
E_USER_WARNING
);
$options = (array) $_val;
break;
case 'assign':
break;
case 'strict':
break;
case 'disabled':
case 'readonly':
if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
trigger_error(
"html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute",
E_USER_NOTICE
);
}
if ($_val === true || $_val === $_key) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
}
break; break;
} case 'escape':
case 'labels':
case 'label_ids':
$$_key = (bool)$_val;
break;
case 'options':
$$_key = (array)$_val;
break;
case 'values':
case 'output':
$$_key = array_values((array)$_val);
break;
case 'checked':
case 'selected':
if (is_array($_val)) {
$selected = array();
foreach ($_val as $_sel) {
if (is_object($_sel)) {
if (method_exists($_sel, '__toString')) {
$_sel = smarty_function_escape_special_chars((string)$_sel->__toString());
} else {
trigger_error(
'html_checkboxes: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method',
E_USER_NOTICE
);
continue;
}
} else {
$_sel = smarty_function_escape_special_chars((string)$_sel);
}
$selected[ $_sel ] = true;
}
} elseif (is_object($_val)) {
if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string)$_val->__toString());
} else {
trigger_error(
'html_checkboxes: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method',
E_USER_NOTICE
);
}
} else {
$selected = smarty_function_escape_special_chars((string)$_val);
}
break;
case 'checkboxes':
trigger_error(
'html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead',
E_USER_WARNING
);
$options = (array)$_val;
break;
case 'assign':
break;
case 'strict':
break;
case 'disabled':
case 'readonly':
if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
trigger_error(
"html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute",
E_USER_NOTICE
);
}
if ($_val === true || $_val === $_key) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
}
break;
}
// omit break; to fall through! // omit break; to fall through!
default:
default: if (!is_array($_val)) {
if (!is_array($_val)) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; } else {
} else { trigger_error("html_checkboxes: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
trigger_error("html_checkboxes: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); }
} break;
break;
} }
} }
if (!isset($options) && !isset($values)) { if (!isset($options) && !isset($values)) {
return ''; return '';
} /* raise error here? */ } /* raise error here? */
$_html_result = array(); $_html_result = array();
if (isset($options)) { if (isset($options)) {
foreach ($options as $_key => $_val) { foreach ($options as $_key => $_val) {
$_html_result[] = $_html_result[] =
smarty_function_html_checkboxes_output( smarty_function_html_checkboxes_output(
$name, $_key, $_val, $selected, $extra, $separator, $labels, $name,
$label_ids, $escape $_key,
$_val,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape
); );
} }
} else { } else {
@@ -178,18 +170,25 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
$_val = isset($output[ $_i ]) ? $output[ $_i ] : ''; $_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
$_html_result[] = $_html_result[] =
smarty_function_html_checkboxes_output( smarty_function_html_checkboxes_output(
$name, $_key, $_val, $selected, $extra, $separator, $labels, $name,
$label_ids, $escape $_key,
$_val,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape
); );
} }
} }
if (!empty($params[ 'assign' ])) { if (!empty($params[ 'assign' ])) {
$template->assign($params[ 'assign' ], $_html_result); $template->assign($params[ 'assign' ], $_html_result);
} else { } else {
return implode("\n", $_html_result); return implode("\n", $_html_result);
} }
} }
/** /**
* @param $name * @param $name
* @param $value * @param $value
@@ -199,50 +198,56 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
* @param $separator * @param $separator
* @param $labels * @param $labels
* @param $label_ids * @param $label_ids
* @param bool $escape * @param bool $escape
* *
* @return string * @return string
*/ */
function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, function smarty_function_html_checkboxes_output($name,
$label_ids, $escape = true $value,
) { $output,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape = true
)
{
$_output = ''; $_output = '';
if (is_object($value)) { if (is_object($value)) {
if (method_exists($value, '__toString')) { if (method_exists($value, '__toString')) {
$value = (string) $value->__toString(); $value = (string)$value->__toString();
} else { } else {
trigger_error( trigger_error(
'html_options: value is an object of class \'' . get_class($value) . 'html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method', E_USER_NOTICE '\' without __toString() method',
E_USER_NOTICE
); );
return ''; return '';
} }
} else { } else {
$value = (string) $value; $value = (string)$value;
} }
if (is_object($output)) { if (is_object($output)) {
if (method_exists($output, '__toString')) { if (method_exists($output, '__toString')) {
$output = (string) $output->__toString(); $output = (string)$output->__toString();
} else { } else {
trigger_error( trigger_error(
'html_options: output is an object of class \'' . get_class($output) . 'html_options: output is an object of class \'' . get_class($output) .
'\' without __toString() method', E_USER_NOTICE '\' without __toString() method',
E_USER_NOTICE
); );
return ''; return '';
} }
} else { } else {
$output = (string) $output; $output = (string)$output;
} }
if ($labels) { if ($labels) {
if ($label_ids) { if ($label_ids) {
$_id = smarty_function_escape_special_chars( $_id = smarty_function_escape_special_chars(
preg_replace( preg_replace(
'![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', '![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER,
'_',
$name . '_' . $value $name . '_' . $value
) )
); );
@@ -251,19 +256,15 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
$_output .= '<label>'; $_output .= '<label>';
} }
} }
$name = smarty_function_escape_special_chars($name); $name = smarty_function_escape_special_chars($name);
$value = smarty_function_escape_special_chars($value); $value = smarty_function_escape_special_chars($value);
if ($escape) { if ($escape) {
$output = smarty_function_escape_special_chars($output); $output = smarty_function_escape_special_chars($output);
} }
$_output .= '<input type="checkbox" name="' . $name . '[]" value="' . $value . '"'; $_output .= '<input type="checkbox" name="' . $name . '[]" value="' . $value . '"';
if ($labels && $label_ids) { if ($labels && $label_ids) {
$_output .= ' id="' . $_id . '"'; $_output .= ' id="' . $_id . '"';
} }
if (is_array($selected)) { if (is_array($selected)) {
if (isset($selected[ $value ])) { if (isset($selected[ $value ])) {
$_output .= ' checked="checked"'; $_output .= ' checked="checked"';
@@ -271,13 +272,10 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
} elseif ($value === $selected) { } elseif ($value === $selected) {
$_output .= ' checked="checked"'; $_output .= ' checked="checked"';
} }
$_output .= $extra . ' />' . $output; $_output .= $extra . ' />' . $output;
if ($labels) { if ($labels) {
$_output .= '</label>'; $_output .= '</label>';
} }
$_output .= $separator; $_output .= $separator;
return $_output; return $_output;
} }

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_image} function plugin * Smarty {html_image} function plugin
* Type: function * Type: function
@@ -33,15 +32,14 @@
* *
* @throws SmartyException * @throws SmartyException
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
*/ */
function smarty_function_html_image($params, Smarty_Internal_Template $template) function smarty_function_html_image($params, Smarty_Internal_Template $template)
{ {
$template->_checkPlugins( $template->_checkPlugins(
array(array('function' => 'smarty_function_escape_special_chars', array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')) 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
); );
$alt = ''; $alt = '';
$file = ''; $file = '';
$height = ''; $height = '';
@@ -53,61 +51,54 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template)
$basedir = isset($_SERVER[ 'DOCUMENT_ROOT' ]) ? $_SERVER[ 'DOCUMENT_ROOT' ] : ''; $basedir = isset($_SERVER[ 'DOCUMENT_ROOT' ]) ? $_SERVER[ 'DOCUMENT_ROOT' ] : '';
foreach ($params as $_key => $_val) { foreach ($params as $_key => $_val) {
switch ($_key) { switch ($_key) {
case 'file': case 'file':
case 'height': case 'height':
case 'width': case 'width':
case 'dpi': case 'dpi':
case 'path_prefix': case 'path_prefix':
case 'basedir': case 'basedir':
$$_key = $_val; $$_key = $_val;
break; break;
case 'alt':
case 'alt': if (!is_array($_val)) {
if (!is_array($_val)) { $$_key = smarty_function_escape_special_chars($_val);
$$_key = smarty_function_escape_special_chars($_val); } else {
} else { throw new SmartyException("html_image: extra attribute '{$_key}' cannot be an array",
throw new SmartyException("html_image: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); E_USER_NOTICE);
} }
break; break;
case 'link':
case 'link': case 'href':
case 'href': $prefix = '<a href="' . $_val . '">';
$prefix = '<a href="' . $_val . '">'; $suffix = '</a>';
$suffix = '</a>'; break;
break; default:
if (!is_array($_val)) {
default: $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
if (!is_array($_val)) { } else {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; throw new SmartyException("html_image: extra attribute '{$_key}' cannot be an array",
} else { E_USER_NOTICE);
throw new SmartyException("html_image: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); }
} break;
break;
} }
} }
if (empty($file)) { if (empty($file)) {
trigger_error('html_image: missing \'file\' parameter', E_USER_NOTICE); trigger_error('html_image: missing \'file\' parameter', E_USER_NOTICE);
return; return;
} }
if ($file[ 0 ] === '/') { if ($file[ 0 ] === '/') {
$_image_path = $basedir . $file; $_image_path = $basedir . $file;
} else { } else {
$_image_path = $file; $_image_path = $file;
} }
// strip file protocol // strip file protocol
if (stripos($params[ 'file' ], 'file://') === 0) { if (stripos($params[ 'file' ], 'file://') === 0) {
$params[ 'file' ] = substr($params[ 'file' ], 7); $params[ 'file' ] = substr($params[ 'file' ], 7);
} }
$protocol = strpos($params[ 'file' ], '://'); $protocol = strpos($params[ 'file' ], '://');
if ($protocol !== false) { if ($protocol !== false) {
$protocol = strtolower(substr($params[ 'file' ], 0, $protocol)); $protocol = strtolower(substr($params[ 'file' ], 0, $protocol));
} }
if (isset($template->smarty->security_policy)) { if (isset($template->smarty->security_policy)) {
if ($protocol) { if ($protocol) {
// remote resource (or php stream, …) // remote resource (or php stream, …)
@@ -121,25 +112,20 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template)
} }
} }
} }
if (!isset($params[ 'width' ]) || !isset($params[ 'height' ])) { if (!isset($params[ 'width' ]) || !isset($params[ 'height' ])) {
// FIXME: (rodneyrehm) getimagesize() loads the complete file off a remote resource, use custom [jpg,png,gif]header reader! // FIXME: (rodneyrehm) getimagesize() loads the complete file off a remote resource, use custom [jpg,png,gif]header reader!
if (!$_image_data = @getimagesize($_image_path)) { if (!$_image_data = @getimagesize($_image_path)) {
if (!file_exists($_image_path)) { if (!file_exists($_image_path)) {
trigger_error("html_image: unable to find '{$_image_path}'", E_USER_NOTICE); trigger_error("html_image: unable to find '{$_image_path}'", E_USER_NOTICE);
return; return;
} elseif (!is_readable($_image_path)) { } elseif (!is_readable($_image_path)) {
trigger_error("html_image: unable to read '{$_image_path}'", E_USER_NOTICE); trigger_error("html_image: unable to read '{$_image_path}'", E_USER_NOTICE);
return; return;
} else { } else {
trigger_error("html_image: '{$_image_path}' is not a valid image file", E_USER_NOTICE); trigger_error("html_image: '{$_image_path}' is not a valid image file", E_USER_NOTICE);
return; return;
} }
} }
if (!isset($params[ 'width' ])) { if (!isset($params[ 'width' ])) {
$width = $_image_data[ 0 ]; $width = $_image_data[ 0 ];
} }
@@ -147,7 +133,6 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template)
$height = $_image_data[ 1 ]; $height = $_image_data[ 1 ];
} }
} }
if (isset($params[ 'dpi' ])) { if (isset($params[ 'dpi' ])) {
if (strstr($_SERVER[ 'HTTP_USER_AGENT' ], 'Mac')) { if (strstr($_SERVER[ 'HTTP_USER_AGENT' ], 'Mac')) {
// FIXME: (rodneyrehm) wrong dpi assumption // FIXME: (rodneyrehm) wrong dpi assumption
@@ -160,7 +145,6 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template)
$width = round($width * $_resize); $width = round($width * $_resize);
$height = round($height * $_resize); $height = round($height * $_resize);
} }
return $prefix . '<img src="' . $path_prefix . $file . '" alt="' . $alt . '" width="' . $width . '" height="' . return $prefix . '<img src="' . $path_prefix . $file . '" alt="' . $alt . '" width="' . $width . '" height="' .
$height . '"' . $extra . ' />' . $suffix; $height . '"' . $extra . ' />' . $suffix;
} }

View File

@@ -26,7 +26,7 @@
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de> * @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de>
* *
* @param array $params parameters * @param array $params parameters
* *
* @param \Smarty_Internal_Template $template * @param \Smarty_Internal_Template $template
* *
@@ -38,9 +38,8 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
{ {
$template->_checkPlugins( $template->_checkPlugins(
array(array('function' => 'smarty_function_escape_special_chars', array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')) 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
); );
$name = null; $name = null;
$values = null; $values = null;
$options = null; $options = null;
@@ -48,99 +47,87 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
$output = null; $output = null;
$id = null; $id = null;
$class = null; $class = null;
$extra = ''; $extra = '';
foreach ($params as $_key => $_val) { foreach ($params as $_key => $_val) {
switch ($_key) { switch ($_key) {
case 'name': case 'name':
case 'class': case 'class':
case 'id': case 'id':
$$_key = (string) $_val; $$_key = (string)$_val;
break;
case 'options':
$options = (array) $_val;
break;
case 'values':
case 'output':
$$_key = array_values((array) $_val);
break;
case 'selected':
if (is_array($_val)) {
$selected = array();
foreach ($_val as $_sel) {
if (is_object($_sel)) {
if (method_exists($_sel, '__toString')) {
$_sel = smarty_function_escape_special_chars((string) $_sel->__toString());
} else {
trigger_error(
'html_options: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method', E_USER_NOTICE
);
continue;
}
} else {
$_sel = smarty_function_escape_special_chars((string) $_sel);
}
$selected[ $_sel ] = true;
}
} elseif (is_object($_val)) {
if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
} else {
trigger_error(
'html_options: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method', E_USER_NOTICE
);
}
} else {
$selected = smarty_function_escape_special_chars((string) $_val);
}
break;
case 'strict':
break;
case 'disabled':
case 'readonly':
if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
trigger_error(
"html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute",
E_USER_NOTICE
);
}
if ($_val === true || $_val === $_key) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
}
break; break;
} case 'options':
$options = (array)$_val;
break;
case 'values':
case 'output':
$$_key = array_values((array)$_val);
break;
case 'selected':
if (is_array($_val)) {
$selected = array();
foreach ($_val as $_sel) {
if (is_object($_sel)) {
if (method_exists($_sel, '__toString')) {
$_sel = smarty_function_escape_special_chars((string)$_sel->__toString());
} else {
trigger_error(
'html_options: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method',
E_USER_NOTICE
);
continue;
}
} else {
$_sel = smarty_function_escape_special_chars((string)$_sel);
}
$selected[ $_sel ] = true;
}
} elseif (is_object($_val)) {
if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string)$_val->__toString());
} else {
trigger_error(
'html_options: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method',
E_USER_NOTICE
);
}
} else {
$selected = smarty_function_escape_special_chars((string)$_val);
}
break;
case 'strict':
break;
case 'disabled':
case 'readonly':
if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
trigger_error(
"html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute",
E_USER_NOTICE
);
}
if ($_val === true || $_val === $_key) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
}
break;
}
// omit break; to fall through! // omit break; to fall through!
default:
default: if (!is_array($_val)) {
if (!is_array($_val)) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; } else {
} else { trigger_error("html_options: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
trigger_error("html_options: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); }
} break;
break;
} }
} }
if (!isset($options) && !isset($values)) { if (!isset($options) && !isset($values)) {
/* raise error here? */ /* raise error here? */
return ''; return '';
} }
$_html_result = ''; $_html_result = '';
$_idx = 0; $_idx = 0;
if (isset($options)) { if (isset($options)) {
foreach ($options as $_key => $_val) { foreach ($options as $_key => $_val) {
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx); $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx);
@@ -151,7 +138,6 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx); $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx);
} }
} }
if (!empty($name)) { if (!empty($name)) {
$_html_class = !empty($class) ? ' class="' . $class . '"' : ''; $_html_class = !empty($class) ? ' class="' . $class . '"' : '';
$_html_id = !empty($id) ? ' id="' . $id . '"' : ''; $_html_id = !empty($id) ? ' id="' . $id . '"' : '';
@@ -159,9 +145,9 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
'<select name="' . $name . '"' . $_html_class . $_html_id . $extra . '>' . "\n" . $_html_result . '<select name="' . $name . '"' . $_html_class . $_html_id . $extra . '>' . "\n" . $_html_result .
'</select>' . "\n"; '</select>' . "\n";
} }
return $_html_result; return $_html_result;
} }
/** /**
* @param $key * @param $key
* @param $value * @param $value
@@ -188,32 +174,36 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
$_html_id = !empty($id) ? ' id="' . $id . '-' . $idx . '"' : ''; $_html_id = !empty($id) ? ' id="' . $id . '-' . $idx . '"' : '';
if (is_object($value)) { if (is_object($value)) {
if (method_exists($value, '__toString')) { if (method_exists($value, '__toString')) {
$value = smarty_function_escape_special_chars((string) $value->__toString()); $value = smarty_function_escape_special_chars((string)$value->__toString());
} else { } else {
trigger_error( trigger_error(
'html_options: value is an object of class \'' . get_class($value) . 'html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method', E_USER_NOTICE '\' without __toString() method',
E_USER_NOTICE
); );
return ''; return '';
} }
} else { } else {
$value = smarty_function_escape_special_chars((string) $value); $value = smarty_function_escape_special_chars((string)$value);
} }
$_html_result .= $_html_class . $_html_id . '>' . $value . '</option>' . "\n"; $_html_result .= $_html_class . $_html_id . '>' . $value . '</option>' . "\n";
$idx ++; $idx++;
} else { } else {
$_idx = 0; $_idx = 0;
$_html_result = $_html_result =
smarty_function_html_options_optgroup( smarty_function_html_options_optgroup(
$key, $value, $selected, !empty($id) ? ($id . '-' . $idx) : null, $key,
$class, $_idx $value,
$selected,
!empty($id) ? ($id . '-' . $idx) : null,
$class,
$_idx
); );
$idx ++; $idx++;
} }
return $_html_result; return $_html_result;
} }
/** /**
* @param $key * @param $key
* @param $values * @param $values
@@ -231,6 +221,5 @@ function smarty_function_html_options_optgroup($key, $values, $selected, $id, $c
$optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, $idx); $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, $idx);
} }
$optgroup_html .= "</optgroup>\n"; $optgroup_html .= "</optgroup>\n";
return $optgroup_html; return $optgroup_html;
} }

View File

@@ -39,16 +39,15 @@
* @param Smarty_Internal_Template $template template object * @param Smarty_Internal_Template $template template object
* *
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
* @throws \SmartyException * @throws \SmartyException
*/ */
function smarty_function_html_radios($params, Smarty_Internal_Template $template) function smarty_function_html_radios($params, Smarty_Internal_Template $template)
{ {
$template->_checkPlugins( $template->_checkPlugins(
array(array('function' => 'smarty_function_escape_special_chars', array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')) 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
); );
$name = 'radio'; $name = 'radio';
$values = null; $values = null;
$options = null; $options = null;
@@ -59,103 +58,95 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
$label_ids = false; $label_ids = false;
$output = null; $output = null;
$extra = ''; $extra = '';
foreach ($params as $_key => $_val) { foreach ($params as $_key => $_val) {
switch ($_key) { switch ($_key) {
case 'name': case 'name':
case 'separator': case 'separator':
$$_key = (string) $_val; $$_key = (string)$_val;
break;
case 'checked':
case 'selected':
if (is_array($_val)) {
trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING);
} elseif (is_object($_val)) {
if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
} else {
trigger_error(
'html_radios: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method', E_USER_NOTICE
);
}
} else {
$selected = (string) $_val;
}
break;
case 'escape':
case 'labels':
case 'label_ids':
$$_key = (bool) $_val;
break;
case 'options':
$$_key = (array) $_val;
break;
case 'values':
case 'output':
$$_key = array_values((array) $_val);
break;
case 'radios':
trigger_error(
'html_radios: the use of the "radios" attribute is deprecated, use "options" instead',
E_USER_WARNING
);
$options = (array) $_val;
break;
case 'assign':
break;
case 'strict':
break;
case 'disabled':
case 'readonly':
if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
trigger_error(
"html_options: {$_key} attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
E_USER_NOTICE
);
}
if ($_val === true || $_val === $_key) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
}
break; break;
} case 'checked':
case 'selected':
if (is_array($_val)) {
trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING);
} elseif (is_object($_val)) {
if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string)$_val->__toString());
} else {
trigger_error(
'html_radios: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method',
E_USER_NOTICE
);
}
} else {
$selected = (string)$_val;
}
break;
case 'escape':
case 'labels':
case 'label_ids':
$$_key = (bool)$_val;
break;
case 'options':
$$_key = (array)$_val;
break;
case 'values':
case 'output':
$$_key = array_values((array)$_val);
break;
case 'radios':
trigger_error(
'html_radios: the use of the "radios" attribute is deprecated, use "options" instead',
E_USER_WARNING
);
$options = (array)$_val;
break;
case 'assign':
break;
case 'strict':
break;
case 'disabled':
case 'readonly':
if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
trigger_error(
"html_options: {$_key} attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
E_USER_NOTICE
);
}
if ($_val === true || $_val === $_key) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
}
break;
}
// omit break; to fall through! // omit break; to fall through!
default:
default: if (!is_array($_val)) {
if (!is_array($_val)) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; } else {
} else { trigger_error("html_radios: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
trigger_error("html_radios: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); }
} break;
break;
} }
} }
if (!isset($options) && !isset($values)) { if (!isset($options) && !isset($values)) {
/* raise error here? */ /* raise error here? */
return ''; return '';
} }
$_html_result = array(); $_html_result = array();
if (isset($options)) { if (isset($options)) {
foreach ($options as $_key => $_val) { foreach ($options as $_key => $_val) {
$_html_result[] = $_html_result[] =
smarty_function_html_radios_output( smarty_function_html_radios_output(
$name, $_key, $_val, $selected, $extra, $separator, $labels, $name,
$label_ids, $escape $_key,
$_val,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape
); );
} }
} else { } else {
@@ -163,18 +154,25 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
$_val = isset($output[ $_i ]) ? $output[ $_i ] : ''; $_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
$_html_result[] = $_html_result[] =
smarty_function_html_radios_output( smarty_function_html_radios_output(
$name, $_key, $_val, $selected, $extra, $separator, $labels, $name,
$label_ids, $escape $_key,
$_val,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape
); );
} }
} }
if (!empty($params[ 'assign' ])) { if (!empty($params[ 'assign' ])) {
$template->assign($params[ 'assign' ], $_html_result); $template->assign($params[ 'assign' ], $_html_result);
} else { } else {
return implode("\n", $_html_result); return implode("\n", $_html_result);
} }
} }
/** /**
* @param $name * @param $name
* @param $value * @param $value
@@ -188,46 +186,52 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
* *
* @return string * @return string
*/ */
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, function smarty_function_html_radios_output($name,
$escape $value,
) { $output,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape
)
{
$_output = ''; $_output = '';
if (is_object($value)) { if (is_object($value)) {
if (method_exists($value, '__toString')) { if (method_exists($value, '__toString')) {
$value = (string) $value->__toString(); $value = (string)$value->__toString();
} else { } else {
trigger_error( trigger_error(
'html_options: value is an object of class \'' . get_class($value) . 'html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method', E_USER_NOTICE '\' without __toString() method',
E_USER_NOTICE
); );
return ''; return '';
} }
} else { } else {
$value = (string) $value; $value = (string)$value;
} }
if (is_object($output)) { if (is_object($output)) {
if (method_exists($output, '__toString')) { if (method_exists($output, '__toString')) {
$output = (string) $output->__toString(); $output = (string)$output->__toString();
} else { } else {
trigger_error( trigger_error(
'html_options: output is an object of class \'' . get_class($output) . 'html_options: output is an object of class \'' . get_class($output) .
'\' without __toString() method', E_USER_NOTICE '\' without __toString() method',
E_USER_NOTICE
); );
return ''; return '';
} }
} else { } else {
$output = (string) $output; $output = (string)$output;
} }
if ($labels) { if ($labels) {
if ($label_ids) { if ($label_ids) {
$_id = smarty_function_escape_special_chars( $_id = smarty_function_escape_special_chars(
preg_replace( preg_replace(
'![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', '![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER,
'_',
$name . '_' . $value $name . '_' . $value
) )
); );
@@ -236,29 +240,22 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
$_output .= '<label>'; $_output .= '<label>';
} }
} }
$name = smarty_function_escape_special_chars($name); $name = smarty_function_escape_special_chars($name);
$value = smarty_function_escape_special_chars($value); $value = smarty_function_escape_special_chars($value);
if ($escape) { if ($escape) {
$output = smarty_function_escape_special_chars($output); $output = smarty_function_escape_special_chars($output);
} }
$_output .= '<input type="radio" name="' . $name . '" value="' . $value . '"'; $_output .= '<input type="radio" name="' . $name . '" value="' . $value . '"';
if ($labels && $label_ids) { if ($labels && $label_ids) {
$_output .= ' id="' . $_id . '"'; $_output .= ' id="' . $_id . '"';
} }
if ($value === $selected) { if ($value === $selected) {
$_output .= ' checked="checked"'; $_output .= ' checked="checked"';
} }
$_output .= $extra . ' />' . $output; $_output .= $extra . ' />' . $output;
if ($labels) { if ($labels) {
$_output .= '</label>'; $_output .= '</label>';
} }
$_output .= $separator; $_output .= $separator;
return $_output; return $_output;
} }

View File

@@ -35,7 +35,7 @@
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Rodney Rehm * @author Rodney Rehm
* *
* @param array $params parameters * @param array $params parameters
* *
* @param \Smarty_Internal_Template $template * @param \Smarty_Internal_Template $template
* *
@@ -46,7 +46,7 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
{ {
$template->_checkPlugins( $template->_checkPlugins(
array(array('function' => 'smarty_function_escape_special_chars', array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')) 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
); );
// generate timestamps used for month names only // generate timestamps used for month names only
static $_month_timestamps = null; static $_month_timestamps = null;
@@ -54,11 +54,10 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
if ($_month_timestamps === null) { if ($_month_timestamps === null) {
$_current_year = date('Y'); $_current_year = date('Y');
$_month_timestamps = array(); $_month_timestamps = array();
for ($i = 1; $i <= 12; $i ++) { for ($i = 1; $i <= 12; $i++) {
$_month_timestamps[ $i ] = mktime(0, 0, 0, $i, 1, 2000); $_month_timestamps[ $i ] = mktime(0, 0, 0, $i, 1, 2000);
} }
} }
/* Default values. */ /* Default values. */
$prefix = 'Date_'; $prefix = 'Date_';
$start_year = null; $start_year = null;
@@ -107,74 +106,68 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$day_id = null; $day_id = null;
$month_id = null; $month_id = null;
$year_id = null; $year_id = null;
foreach ($params as $_key => $_value) { foreach ($params as $_key => $_value) {
switch ($_key) { switch ($_key) {
case 'time': case 'time':
if (!is_array($_value) && $_value !== null) { if (!is_array($_value) && $_value !== null) {
$template->_checkPlugins( $template->_checkPlugins(
array(array('function' => 'smarty_make_timestamp', array(array('function' => 'smarty_make_timestamp',
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php')) 'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'))
); );
$time = smarty_make_timestamp($_value); $time = smarty_make_timestamp($_value);
} }
break; break;
case 'month_names':
case 'month_names': if (is_array($_value) && count($_value) === 12) {
if (is_array($_value) && count($_value) === 12) { $$_key = $_value;
$$_key = $_value; } else {
} else { trigger_error('html_select_date: month_names must be an array of 12 strings', E_USER_NOTICE);
trigger_error('html_select_date: month_names must be an array of 12 strings', E_USER_NOTICE); }
} break;
break; case 'prefix':
case 'field_array':
case 'prefix': case 'start_year':
case 'field_array': case 'end_year':
case 'start_year': case 'day_format':
case 'end_year': case 'day_value_format':
case 'day_format': case 'month_format':
case 'day_value_format': case 'month_value_format':
case 'month_format': case 'day_size':
case 'month_value_format': case 'month_size':
case 'day_size': case 'year_size':
case 'month_size': case 'all_extra':
case 'year_size': case 'day_extra':
case 'all_extra': case 'month_extra':
case 'day_extra': case 'year_extra':
case 'month_extra': case 'field_order':
case 'year_extra': case 'field_separator':
case 'field_order': case 'option_separator':
case 'field_separator': case 'all_empty':
case 'option_separator': case 'month_empty':
case 'all_empty': case 'day_empty':
case 'month_empty': case 'year_empty':
case 'day_empty': case 'all_id':
case 'year_empty': case 'month_id':
case 'all_id': case 'day_id':
case 'month_id': case 'year_id':
case 'day_id': $$_key = (string)$_value;
case 'year_id': break;
$$_key = (string) $_value; case 'display_days':
break; case 'display_months':
case 'display_years':
case 'display_days': case 'year_as_text':
case 'display_months': case 'reverse_years':
case 'display_years': $$_key = (bool)$_value;
case 'year_as_text': break;
case 'reverse_years': default:
$$_key = (bool) $_value; if (!is_array($_value)) {
break; $extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"';
} else {
default: trigger_error("html_select_date: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
if (!is_array($_value)) { }
$extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"'; break;
} else {
trigger_error("html_select_date: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
} }
} }
// Note: date() is faster than strftime() // Note: date() is faster than strftime()
// Note: explode(date()) is faster than date() date() date() // Note: explode(date()) is faster than date() date() date()
if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) { if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
@@ -210,7 +203,6 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
} else { } else {
list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d', $time)); list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d', $time));
} }
// make syntax "+N" or "-N" work with $start_year and $end_year // make syntax "+N" or "-N" work with $start_year and $end_year
// Note preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match) is slower than trim+substr // Note preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match) is slower than trim+substr
foreach (array('start', foreach (array('start',
@@ -218,23 +210,21 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$key .= '_year'; $key .= '_year';
$t = $$key; $t = $$key;
if ($t === null) { if ($t === null) {
$$key = (int) $_current_year; $$key = (int)$_current_year;
} elseif ($t[ 0 ] === '+') { } elseif ($t[ 0 ] === '+') {
$$key = (int) ($_current_year + (int) trim(substr($t, 1))); $$key = (int)($_current_year + (int)trim(substr($t, 1)));
} elseif ($t[ 0 ] === '-') { } elseif ($t[ 0 ] === '-') {
$$key = (int) ($_current_year - (int) trim(substr($t, 1))); $$key = (int)($_current_year - (int)trim(substr($t, 1)));
} else { } else {
$$key = (int) $$key; $$key = (int)$$key;
} }
} }
// flip for ascending or descending // flip for ascending or descending
if (($start_year > $end_year && !$reverse_years) || ($start_year < $end_year && $reverse_years)) { if (($start_year > $end_year && !$reverse_years) || ($start_year < $end_year && $reverse_years)) {
$t = $end_year; $t = $end_year;
$end_year = $start_year; $end_year = $start_year;
$start_year = $t; $start_year = $t;
} }
// generate year <select> or <input> // generate year <select> or <input>
if ($display_years) { if ($display_years) {
$_extra = ''; $_extra = '';
@@ -245,7 +235,6 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
if ($year_extra) { if ($year_extra) {
$_extra .= ' ' . $year_extra; $_extra .= ' ' . $year_extra;
} }
if ($year_as_text) { if ($year_as_text) {
$_html_years = $_html_years =
'<input type="text" name="' . $_name . '" value="' . $_year . '" size="4" maxlength="4"' . $_extra . '<input type="text" name="' . $_name . '" value="' . $_year . '" size="4" maxlength="4"' . $_extra .
@@ -254,32 +243,28 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$_html_years = '<select name="' . $_name . '"'; $_html_years = '<select name="' . $_name . '"';
if ($year_id !== null || $all_id !== null) { if ($year_id !== null || $all_id !== null) {
$_html_years .= ' id="' . smarty_function_escape_special_chars( $_html_years .= ' id="' . smarty_function_escape_special_chars(
$year_id !== null ? $year_id !== null ?
($year_id ? $year_id : $_name) : ($year_id ? $year_id : $_name) :
($all_id ? ($all_id . $_name) : ($all_id ? ($all_id . $_name) :
$_name) $_name)
) . '"'; ) . '"';
} }
if ($year_size) { if ($year_size) {
$_html_years .= ' size="' . $year_size . '"'; $_html_years .= ' size="' . $year_size . '"';
} }
$_html_years .= $_extra . $extra_attrs . '>' . $option_separator; $_html_years .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($year_empty) || isset($all_empty)) { if (isset($year_empty) || isset($all_empty)) {
$_html_years .= '<option value="">' . (isset($year_empty) ? $year_empty : $all_empty) . '</option>' . $_html_years .= '<option value="">' . (isset($year_empty) ? $year_empty : $all_empty) . '</option>' .
$option_separator; $option_separator;
} }
$op = $start_year > $end_year ? -1 : 1;
$op = $start_year > $end_year ? - 1 : 1;
for ($i = $start_year; $op > 0 ? $i <= $end_year : $i >= $end_year; $i += $op) { for ($i = $start_year; $op > 0 ? $i <= $end_year : $i >= $end_year; $i += $op) {
$_html_years .= '<option value="' . $i . '"' . ($_year == $i ? ' selected="selected"' : '') . '>' . $i . $_html_years .= '<option value="' . $i . '"' . ($_year == $i ? ' selected="selected"' : '') . '>' . $i .
'</option>' . $option_separator; '</option>' . $option_separator;
} }
$_html_years .= '</select>'; $_html_years .= '</select>';
} }
} }
// generate month <select> or <input> // generate month <select> or <input>
if ($display_months) { if ($display_months) {
$_extra = ''; $_extra = '';
@@ -290,27 +275,24 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
if ($month_extra) { if ($month_extra) {
$_extra .= ' ' . $month_extra; $_extra .= ' ' . $month_extra;
} }
$_html_months = '<select name="' . $_name . '"'; $_html_months = '<select name="' . $_name . '"';
if ($month_id !== null || $all_id !== null) { if ($month_id !== null || $all_id !== null) {
$_html_months .= ' id="' . smarty_function_escape_special_chars( $_html_months .= ' id="' . smarty_function_escape_special_chars(
$month_id !== null ? $month_id !== null ?
($month_id ? $month_id : $_name) : ($month_id ? $month_id : $_name) :
($all_id ? ($all_id . $_name) : ($all_id ? ($all_id . $_name) :
$_name) $_name)
) . '"'; ) . '"';
} }
if ($month_size) { if ($month_size) {
$_html_months .= ' size="' . $month_size . '"'; $_html_months .= ' size="' . $month_size . '"';
} }
$_html_months .= $_extra . $extra_attrs . '>' . $option_separator; $_html_months .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($month_empty) || isset($all_empty)) { if (isset($month_empty) || isset($all_empty)) {
$_html_months .= '<option value="">' . (isset($month_empty) ? $month_empty : $all_empty) . '</option>' . $_html_months .= '<option value="">' . (isset($month_empty) ? $month_empty : $all_empty) . '</option>' .
$option_separator; $option_separator;
} }
for ($i = 1; $i <= 12; $i++) {
for ($i = 1; $i <= 12; $i ++) {
$_val = sprintf('%02d', $i); $_val = sprintf('%02d', $i);
$_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[ $i ]) : $_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[ $i ]) :
($month_format === '%m' ? $_val : strftime($month_format, $_month_timestamps[ $i ])); ($month_format === '%m' ? $_val : strftime($month_format, $_month_timestamps[ $i ]));
@@ -318,10 +300,8 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$_html_months .= '<option value="' . $_value . '"' . ($_val == $_month ? ' selected="selected"' : '') . $_html_months .= '<option value="' . $_value . '"' . ($_val == $_month ? ' selected="selected"' : '') .
'>' . $_text . '</option>' . $option_separator; '>' . $_text . '</option>' . $option_separator;
} }
$_html_months .= '</select>'; $_html_months .= '</select>';
} }
// generate day <select> or <input> // generate day <select> or <input>
if ($display_days) { if ($display_days) {
$_extra = ''; $_extra = '';
@@ -332,71 +312,63 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
if ($day_extra) { if ($day_extra) {
$_extra .= ' ' . $day_extra; $_extra .= ' ' . $day_extra;
} }
$_html_days = '<select name="' . $_name . '"'; $_html_days = '<select name="' . $_name . '"';
if ($day_id !== null || $all_id !== null) { if ($day_id !== null || $all_id !== null) {
$_html_days .= ' id="' . $_html_days .= ' id="' .
smarty_function_escape_special_chars( smarty_function_escape_special_chars(
$day_id !== null ? ($day_id ? $day_id : $_name) : $day_id !== null ? ($day_id ? $day_id : $_name) :
($all_id ? ($all_id . $_name) : $_name) ($all_id ? ($all_id . $_name) : $_name)
) . '"'; ) . '"';
} }
if ($day_size) { if ($day_size) {
$_html_days .= ' size="' . $day_size . '"'; $_html_days .= ' size="' . $day_size . '"';
} }
$_html_days .= $_extra . $extra_attrs . '>' . $option_separator; $_html_days .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($day_empty) || isset($all_empty)) { if (isset($day_empty) || isset($all_empty)) {
$_html_days .= '<option value="">' . (isset($day_empty) ? $day_empty : $all_empty) . '</option>' . $_html_days .= '<option value="">' . (isset($day_empty) ? $day_empty : $all_empty) . '</option>' .
$option_separator; $option_separator;
} }
for ($i = 1; $i <= 31; $i++) {
for ($i = 1; $i <= 31; $i ++) {
$_val = sprintf('%02d', $i); $_val = sprintf('%02d', $i);
$_text = $day_format === '%02d' ? $_val : sprintf($day_format, $i); $_text = $day_format === '%02d' ? $_val : sprintf($day_format, $i);
$_value = $day_value_format === '%02d' ? $_val : sprintf($day_value_format, $i); $_value = $day_value_format === '%02d' ? $_val : sprintf($day_value_format, $i);
$_html_days .= '<option value="' . $_value . '"' . ($_val == $_day ? ' selected="selected"' : '') . '>' . $_html_days .= '<option value="' . $_value . '"' . ($_val == $_day ? ' selected="selected"' : '') . '>' .
$_text . '</option>' . $option_separator; $_text . '</option>' . $option_separator;
} }
$_html_days .= '</select>'; $_html_days .= '</select>';
} }
// order the fields for output // order the fields for output
$_html = ''; $_html = '';
for ($i = 0; $i <= 2; $i ++) { for ($i = 0; $i <= 2; $i++) {
switch ($field_order[ $i ]) { switch ($field_order[ $i ]) {
case 'Y': case 'Y':
case 'y': case 'y':
if (isset($_html_years)) { if (isset($_html_years)) {
if ($_html) { if ($_html) {
$_html .= $field_separator; $_html .= $field_separator;
}
$_html .= $_html_years;
} }
$_html .= $_html_years; break;
} case 'm':
break; case 'M':
if (isset($_html_months)) {
case 'm': if ($_html) {
case 'M': $_html .= $field_separator;
if (isset($_html_months)) { }
if ($_html) { $_html .= $_html_months;
$_html .= $field_separator;
} }
$_html .= $_html_months; break;
} case 'd':
break; case 'D':
if (isset($_html_days)) {
case 'd': if ($_html) {
case 'D': $_html .= $field_separator;
if (isset($_html_days)) { }
if ($_html) { $_html .= $_html_days;
$_html .= $field_separator;
} }
$_html .= $_html_days; break;
}
break;
} }
} }
return $_html; return $_html;
} }

View File

@@ -16,7 +16,7 @@
* @author Roberto Berto <roberto@berto.net> * @author Roberto Berto <roberto@berto.net>
* @author Monte Ohrt <monte AT ohrt DOT com> * @author Monte Ohrt <monte AT ohrt DOT com>
* *
* @param array $params parameters * @param array $params parameters
* *
* @param \Smarty_Internal_Template $template * @param \Smarty_Internal_Template $template
* *
@@ -28,127 +28,108 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
{ {
$template->_checkPlugins( $template->_checkPlugins(
array(array('function' => 'smarty_function_escape_special_chars', array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')) 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
); );
$prefix = 'Time_'; $prefix = 'Time_';
$field_array = null; $field_array = null;
$field_separator = "\n"; $field_separator = "\n";
$option_separator = "\n"; $option_separator = "\n";
$time = null; $time = null;
$display_hours = true; $display_hours = true;
$display_minutes = true; $display_minutes = true;
$display_seconds = true; $display_seconds = true;
$display_meridian = true; $display_meridian = true;
$hour_format = '%02d'; $hour_format = '%02d';
$hour_value_format = '%02d'; $hour_value_format = '%02d';
$minute_format = '%02d'; $minute_format = '%02d';
$minute_value_format = '%02d'; $minute_value_format = '%02d';
$second_format = '%02d'; $second_format = '%02d';
$second_value_format = '%02d'; $second_value_format = '%02d';
$hour_size = null; $hour_size = null;
$minute_size = null; $minute_size = null;
$second_size = null; $second_size = null;
$meridian_size = null; $meridian_size = null;
$all_empty = null; $all_empty = null;
$hour_empty = null; $hour_empty = null;
$minute_empty = null; $minute_empty = null;
$second_empty = null; $second_empty = null;
$meridian_empty = null; $meridian_empty = null;
$all_id = null; $all_id = null;
$hour_id = null; $hour_id = null;
$minute_id = null; $minute_id = null;
$second_id = null; $second_id = null;
$meridian_id = null; $meridian_id = null;
$use_24_hours = true; $use_24_hours = true;
$minute_interval = 1; $minute_interval = 1;
$second_interval = 1; $second_interval = 1;
$extra_attrs = ''; $extra_attrs = '';
$all_extra = null; $all_extra = null;
$hour_extra = null; $hour_extra = null;
$minute_extra = null; $minute_extra = null;
$second_extra = null; $second_extra = null;
$meridian_extra = null; $meridian_extra = null;
foreach ($params as $_key => $_value) { foreach ($params as $_key => $_value) {
switch ($_key) { switch ($_key) {
case 'time': case 'time':
if (!is_array($_value) && $_value !== null) { if (!is_array($_value) && $_value !== null) {
$template->_checkPlugins( $template->_checkPlugins(
array(array('function' => 'smarty_make_timestamp', array(array('function' => 'smarty_make_timestamp',
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php')) 'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'))
); );
$time = smarty_make_timestamp($_value); $time = smarty_make_timestamp($_value);
} }
break; break;
case 'prefix':
case 'prefix': case 'field_array':
case 'field_array': case 'field_separator':
case 'option_separator':
case 'field_separator': case 'all_extra':
case 'option_separator': case 'hour_extra':
case 'minute_extra':
case 'all_extra': case 'second_extra':
case 'hour_extra': case 'meridian_extra':
case 'minute_extra': case 'all_empty':
case 'second_extra': case 'hour_empty':
case 'meridian_extra': case 'minute_empty':
case 'second_empty':
case 'all_empty': case 'meridian_empty':
case 'hour_empty': case 'all_id':
case 'minute_empty': case 'hour_id':
case 'second_empty': case 'minute_id':
case 'meridian_empty': case 'second_id':
case 'meridian_id':
case 'all_id': case 'hour_format':
case 'hour_id': case 'hour_value_format':
case 'minute_id': case 'minute_format':
case 'second_id': case 'minute_value_format':
case 'meridian_id': case 'second_format':
case 'second_value_format':
case 'hour_format': $$_key = (string)$_value;
case 'hour_value_format': break;
case 'minute_format': case 'display_hours':
case 'minute_value_format': case 'display_minutes':
case 'second_format': case 'display_seconds':
case 'second_value_format': case 'display_meridian':
$$_key = (string) $_value; case 'use_24_hours':
break; $$_key = (bool)$_value;
break;
case 'display_hours': case 'minute_interval':
case 'display_minutes': case 'second_interval':
case 'display_seconds': case 'hour_size':
case 'display_meridian': case 'minute_size':
case 'use_24_hours': case 'second_size':
$$_key = (bool) $_value; case 'meridian_size':
break; $$_key = (int)$_value;
break;
case 'minute_interval': default:
case 'second_interval': if (!is_array($_value)) {
$extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"';
case 'hour_size': } else {
case 'minute_size': trigger_error("html_select_date: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
case 'second_size': }
case 'meridian_size': break;
$$_key = (int) $_value;
break;
default:
if (!is_array($_value)) {
$extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"';
} else {
trigger_error("html_select_date: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
} }
} }
if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) { if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
if (isset($params[ 'time' ][ $prefix . 'Hour' ])) { if (isset($params[ 'time' ][ $prefix . 'Hour' ])) {
// $_REQUEST[$field_array] given // $_REQUEST[$field_array] given
@@ -191,7 +172,6 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
} else { } else {
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time)); list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
} }
// generate hour <select> // generate hour <select>
if ($display_hours) { if ($display_hours) {
$_html_hours = ''; $_html_hours = '';
@@ -203,44 +183,37 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
if ($hour_extra) { if ($hour_extra) {
$_extra .= ' ' . $hour_extra; $_extra .= ' ' . $hour_extra;
} }
$_html_hours = '<select name="' . $_name . '"'; $_html_hours = '<select name="' . $_name . '"';
if ($hour_id !== null || $all_id !== null) { if ($hour_id !== null || $all_id !== null) {
$_html_hours .= ' id="' . $_html_hours .= ' id="' .
smarty_function_escape_special_chars( smarty_function_escape_special_chars(
$hour_id !== null ? ($hour_id ? $hour_id : $_name) : $hour_id !== null ? ($hour_id ? $hour_id : $_name) :
($all_id ? ($all_id . $_name) : $_name) ($all_id ? ($all_id . $_name) : $_name)
) . '"'; ) . '"';
} }
if ($hour_size) { if ($hour_size) {
$_html_hours .= ' size="' . $hour_size . '"'; $_html_hours .= ' size="' . $hour_size . '"';
} }
$_html_hours .= $_extra . $extra_attrs . '>' . $option_separator; $_html_hours .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($hour_empty) || isset($all_empty)) { if (isset($hour_empty) || isset($all_empty)) {
$_html_hours .= '<option value="">' . (isset($hour_empty) ? $hour_empty : $all_empty) . '</option>' . $_html_hours .= '<option value="">' . (isset($hour_empty) ? $hour_empty : $all_empty) . '</option>' .
$option_separator; $option_separator;
} }
$start = $use_24_hours ? 0 : 1; $start = $use_24_hours ? 0 : 1;
$end = $use_24_hours ? 23 : 12; $end = $use_24_hours ? 23 : 12;
for ($i = $start; $i <= $end; $i ++) { for ($i = $start; $i <= $end; $i++) {
$_val = sprintf('%02d', $i); $_val = sprintf('%02d', $i);
$_text = $hour_format === '%02d' ? $_val : sprintf($hour_format, $i); $_text = $hour_format === '%02d' ? $_val : sprintf($hour_format, $i);
$_value = $hour_value_format === '%02d' ? $_val : sprintf($hour_value_format, $i); $_value = $hour_value_format === '%02d' ? $_val : sprintf($hour_value_format, $i);
if (!$use_24_hours) { if (!$use_24_hours) {
$_hour12 = $_hour == 0 ? 12 : ($_hour <= 12 ? $_hour : $_hour - 12); $_hour12 = $_hour == 0 ? 12 : ($_hour <= 12 ? $_hour : $_hour - 12);
} }
$selected = $_hour !== null ? ($use_24_hours ? $_hour == $_val : $_hour12 == $_val) : null; $selected = $_hour !== null ? ($use_24_hours ? $_hour == $_val : $_hour12 == $_val) : null;
$_html_hours .= '<option value="' . $_value . '"' . ($selected ? ' selected="selected"' : '') . '>' . $_html_hours .= '<option value="' . $_value . '"' . ($selected ? ' selected="selected"' : '') . '>' .
$_text . '</option>' . $option_separator; $_text . '</option>' . $option_separator;
} }
$_html_hours .= '</select>'; $_html_hours .= '</select>';
} }
// generate minute <select> // generate minute <select>
if ($display_minutes) { if ($display_minutes) {
$_html_minutes = ''; $_html_minutes = '';
@@ -252,26 +225,23 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
if ($minute_extra) { if ($minute_extra) {
$_extra .= ' ' . $minute_extra; $_extra .= ' ' . $minute_extra;
} }
$_html_minutes = '<select name="' . $_name . '"'; $_html_minutes = '<select name="' . $_name . '"';
if ($minute_id !== null || $all_id !== null) { if ($minute_id !== null || $all_id !== null) {
$_html_minutes .= ' id="' . smarty_function_escape_special_chars( $_html_minutes .= ' id="' . smarty_function_escape_special_chars(
$minute_id !== null ? $minute_id !== null ?
($minute_id ? $minute_id : $_name) : ($minute_id ? $minute_id : $_name) :
($all_id ? ($all_id . $_name) : ($all_id ? ($all_id . $_name) :
$_name) $_name)
) . '"'; ) . '"';
} }
if ($minute_size) { if ($minute_size) {
$_html_minutes .= ' size="' . $minute_size . '"'; $_html_minutes .= ' size="' . $minute_size . '"';
} }
$_html_minutes .= $_extra . $extra_attrs . '>' . $option_separator; $_html_minutes .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($minute_empty) || isset($all_empty)) { if (isset($minute_empty) || isset($all_empty)) {
$_html_minutes .= '<option value="">' . (isset($minute_empty) ? $minute_empty : $all_empty) . '</option>' . $_html_minutes .= '<option value="">' . (isset($minute_empty) ? $minute_empty : $all_empty) . '</option>' .
$option_separator; $option_separator;
} }
$selected = $_minute !== null ? ($_minute - $_minute % $minute_interval) : null; $selected = $_minute !== null ? ($_minute - $_minute % $minute_interval) : null;
for ($i = 0; $i <= 59; $i += $minute_interval) { for ($i = 0; $i <= 59; $i += $minute_interval) {
$_val = sprintf('%02d', $i); $_val = sprintf('%02d', $i);
@@ -280,10 +250,8 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
$_html_minutes .= '<option value="' . $_value . '"' . ($selected === $i ? ' selected="selected"' : '') . $_html_minutes .= '<option value="' . $_value . '"' . ($selected === $i ? ' selected="selected"' : '') .
'>' . $_text . '</option>' . $option_separator; '>' . $_text . '</option>' . $option_separator;
} }
$_html_minutes .= '</select>'; $_html_minutes .= '</select>';
} }
// generate second <select> // generate second <select>
if ($display_seconds) { if ($display_seconds) {
$_html_seconds = ''; $_html_seconds = '';
@@ -295,26 +263,23 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
if ($second_extra) { if ($second_extra) {
$_extra .= ' ' . $second_extra; $_extra .= ' ' . $second_extra;
} }
$_html_seconds = '<select name="' . $_name . '"'; $_html_seconds = '<select name="' . $_name . '"';
if ($second_id !== null || $all_id !== null) { if ($second_id !== null || $all_id !== null) {
$_html_seconds .= ' id="' . smarty_function_escape_special_chars( $_html_seconds .= ' id="' . smarty_function_escape_special_chars(
$second_id !== null ? $second_id !== null ?
($second_id ? $second_id : $_name) : ($second_id ? $second_id : $_name) :
($all_id ? ($all_id . $_name) : ($all_id ? ($all_id . $_name) :
$_name) $_name)
) . '"'; ) . '"';
} }
if ($second_size) { if ($second_size) {
$_html_seconds .= ' size="' . $second_size . '"'; $_html_seconds .= ' size="' . $second_size . '"';
} }
$_html_seconds .= $_extra . $extra_attrs . '>' . $option_separator; $_html_seconds .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($second_empty) || isset($all_empty)) { if (isset($second_empty) || isset($all_empty)) {
$_html_seconds .= '<option value="">' . (isset($second_empty) ? $second_empty : $all_empty) . '</option>' . $_html_seconds .= '<option value="">' . (isset($second_empty) ? $second_empty : $all_empty) . '</option>' .
$option_separator; $option_separator;
} }
$selected = $_second !== null ? ($_second - $_second % $second_interval) : null; $selected = $_second !== null ? ($_second - $_second % $second_interval) : null;
for ($i = 0; $i <= 59; $i += $second_interval) { for ($i = 0; $i <= 59; $i += $second_interval) {
$_val = sprintf('%02d', $i); $_val = sprintf('%02d', $i);
@@ -323,10 +288,8 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
$_html_seconds .= '<option value="' . $_value . '"' . ($selected === $i ? ' selected="selected"' : '') . $_html_seconds .= '<option value="' . $_value . '"' . ($selected === $i ? ' selected="selected"' : '') .
'>' . $_text . '</option>' . $option_separator; '>' . $_text . '</option>' . $option_separator;
} }
$_html_seconds .= '</select>'; $_html_seconds .= '</select>';
} }
// generate meridian <select> // generate meridian <select>
if ($display_meridian && !$use_24_hours) { if ($display_meridian && !$use_24_hours) {
$_html_meridian = ''; $_html_meridian = '';
@@ -338,33 +301,29 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
if ($meridian_extra) { if ($meridian_extra) {
$_extra .= ' ' . $meridian_extra; $_extra .= ' ' . $meridian_extra;
} }
$_html_meridian = '<select name="' . $_name . '"'; $_html_meridian = '<select name="' . $_name . '"';
if ($meridian_id !== null || $all_id !== null) { if ($meridian_id !== null || $all_id !== null) {
$_html_meridian .= ' id="' . smarty_function_escape_special_chars( $_html_meridian .= ' id="' . smarty_function_escape_special_chars(
$meridian_id !== null ? $meridian_id !== null ?
($meridian_id ? $meridian_id : ($meridian_id ? $meridian_id :
$_name) : $_name) :
($all_id ? ($all_id . $_name) : ($all_id ? ($all_id . $_name) :
$_name) $_name)
) . '"'; ) . '"';
} }
if ($meridian_size) { if ($meridian_size) {
$_html_meridian .= ' size="' . $meridian_size . '"'; $_html_meridian .= ' size="' . $meridian_size . '"';
} }
$_html_meridian .= $_extra . $extra_attrs . '>' . $option_separator; $_html_meridian .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($meridian_empty) || isset($all_empty)) { if (isset($meridian_empty) || isset($all_empty)) {
$_html_meridian .= '<option value="">' . (isset($meridian_empty) ? $meridian_empty : $all_empty) . $_html_meridian .= '<option value="">' . (isset($meridian_empty) ? $meridian_empty : $all_empty) .
'</option>' . $option_separator; '</option>' . $option_separator;
} }
$_html_meridian .= '<option value="am"' . ($_hour > 0 && $_hour < 12 ? ' selected="selected"' : '') . $_html_meridian .= '<option value="am"' . ($_hour > 0 && $_hour < 12 ? ' selected="selected"' : '') .
'>AM</option>' . $option_separator . '<option value="pm"' . '>AM</option>' . $option_separator . '<option value="pm"' .
($_hour < 12 ? '' : ' selected="selected"') . '>PM</option>' . $option_separator . ($_hour < 12 ? '' : ' selected="selected"') . '>PM</option>' . $option_separator .
'</select>'; '</select>';
} }
$_html = ''; $_html = '';
foreach (array('_html_hours', foreach (array('_html_hours',
'_html_minutes', '_html_minutes',
@@ -377,6 +336,5 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
$_html .= $$k; $_html .= $$k;
} }
} }
return $_html; return $_html;
} }

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_table} function plugin * Smarty {html_table} function plugin
* Type: function * Type: function
@@ -60,54 +59,46 @@ function smarty_function_html_table($params)
$inner = 'cols'; $inner = 'cols';
$caption = ''; $caption = '';
$loop = null; $loop = null;
if (!isset($params[ 'loop' ])) { if (!isset($params[ 'loop' ])) {
trigger_error("html_table: missing 'loop' parameter", E_USER_WARNING); trigger_error("html_table: missing 'loop' parameter", E_USER_WARNING);
return; return;
} }
foreach ($params as $_key => $_value) { foreach ($params as $_key => $_value) {
switch ($_key) { switch ($_key) {
case 'loop': case 'loop':
$$_key = (array) $_value; $$_key = (array)$_value;
break; break;
case 'cols':
case 'cols': if (is_array($_value) && !empty($_value)) {
if (is_array($_value) && !empty($_value)) { $cols = $_value;
$cols = $_value; $cols_count = count($_value);
$cols_count = count($_value); } elseif (!is_numeric($_value) && is_string($_value) && !empty($_value)) {
} elseif (!is_numeric($_value) && is_string($_value) && !empty($_value)) { $cols = explode(',', $_value);
$cols = explode(',', $_value); $cols_count = count($cols);
$cols_count = count($cols); } elseif (!empty($_value)) {
} elseif (!empty($_value)) { $cols_count = (int)$_value;
$cols_count = (int) $_value; } else {
} else { $cols_count = $cols;
$cols_count = $cols; }
} break;
break; case 'rows':
$$_key = (int)$_value;
case 'rows': break;
$$_key = (int) $_value; case 'table_attr':
break; case 'trailpad':
case 'hdir':
case 'table_attr': case 'vdir':
case 'trailpad': case 'inner':
case 'hdir': case 'caption':
case 'vdir': $$_key = (string)$_value;
case 'inner': break;
case 'caption': case 'tr_attr':
$$_key = (string) $_value; case 'td_attr':
break; case 'th_attr':
$$_key = $_value;
case 'tr_attr': break;
case 'td_attr':
case 'th_attr':
$$_key = $_value;
break;
} }
} }
$loop_count = count($loop); $loop_count = count($loop);
if (empty($params[ 'rows' ])) { if (empty($params[ 'rows' ])) {
/* no rows specified */ /* no rows specified */
@@ -118,37 +109,30 @@ function smarty_function_html_table($params)
$cols_count = ceil($loop_count / $rows); $cols_count = ceil($loop_count / $rows);
} }
} }
$output = "<table $table_attr>\n"; $output = "<table $table_attr>\n";
if (!empty($caption)) { if (!empty($caption)) {
$output .= '<caption>' . $caption . "</caption>\n"; $output .= '<caption>' . $caption . "</caption>\n";
} }
if (is_array($cols)) { if (is_array($cols)) {
$cols = ($hdir === 'right') ? $cols : array_reverse($cols); $cols = ($hdir === 'right') ? $cols : array_reverse($cols);
$output .= "<thead><tr>\n"; $output .= "<thead><tr>\n";
for ($r = 0; $r < $cols_count; $r++) {
for ($r = 0; $r < $cols_count; $r ++) {
$output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>'; $output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>';
$output .= $cols[ $r ]; $output .= $cols[ $r ];
$output .= "</th>\n"; $output .= "</th>\n";
} }
$output .= "</tr></thead>\n"; $output .= "</tr></thead>\n";
} }
$output .= "<tbody>\n"; $output .= "<tbody>\n";
for ($r = 0; $r < $rows; $r ++) { for ($r = 0; $r < $rows; $r++) {
$output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n"; $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
$rx = ($vdir === 'down') ? $r * $cols_count : ($rows - 1 - $r) * $cols_count; $rx = ($vdir === 'down') ? $r * $cols_count : ($rows - 1 - $r) * $cols_count;
for ($c = 0; $c < $cols_count; $c++) {
for ($c = 0; $c < $cols_count; $c ++) {
$x = ($hdir === 'right') ? $rx + $c : $rx + $cols_count - 1 - $c; $x = ($hdir === 'right') ? $rx + $c : $rx + $cols_count - 1 - $c;
if ($inner !== 'cols') { if ($inner !== 'cols') {
/* shuffle x to loop over rows*/ /* shuffle x to loop over rows*/
$x = floor($x / $cols_count) + ($x % $cols_count) * $rows; $x = floor($x / $cols_count) + ($x % $cols_count) * $rows;
} }
if ($x < $loop_count) { if ($x < $loop_count) {
$output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[ $x ] . "</td>\n"; $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[ $x ] . "</td>\n";
} else { } else {
@@ -159,9 +143,9 @@ function smarty_function_html_table($params)
} }
$output .= "</tbody>\n"; $output .= "</tbody>\n";
$output .= "</table>\n"; $output .= "</table>\n";
return $output; return $output;
} }
/** /**
* @param $name * @param $name
* @param $var * @param $var
@@ -176,6 +160,5 @@ function smarty_function_html_table_cycle($name, $var, $no)
} else { } else {
$ret = $var[ $no % count($var) ]; $ret = $var[ $no % count($var) ];
} }
return ($ret) ? ' ' . $ret : ''; return ($ret) ? ' ' . $ret : '';
} }

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {mailto} function plugin * Smarty {mailto} function plugin
* Type: function * Type: function
@@ -52,15 +51,12 @@ function smarty_function_mailto($params)
static $_allowed_encoding = static $_allowed_encoding =
array('javascript' => true, 'javascript_charcode' => true, 'hex' => true, 'none' => true); array('javascript' => true, 'javascript_charcode' => true, 'hex' => true, 'none' => true);
$extra = ''; $extra = '';
if (empty($params[ 'address' ])) { if (empty($params[ 'address' ])) {
trigger_error("mailto: missing 'address' parameter", E_USER_WARNING); trigger_error("mailto: missing 'address' parameter", E_USER_WARNING);
return; return;
} else { } else {
$address = $params[ 'address' ]; $address = $params[ 'address' ];
} }
$text = $address; $text = $address;
// netscape and mozilla do not decode %40 (@) in BCC field (bug?) // netscape and mozilla do not decode %40 (@) in BCC field (bug?)
// so, don't encode it. // so, don't encode it.
@@ -69,70 +65,58 @@ function smarty_function_mailto($params)
$mail_parms = array(); $mail_parms = array();
foreach ($params as $var => $value) { foreach ($params as $var => $value) {
switch ($var) { switch ($var) {
case 'cc': case 'cc':
case 'bcc': case 'bcc':
case 'followupto': case 'followupto':
if (!empty($value)) { if (!empty($value)) {
$mail_parms[] = $var . '=' . str_replace($search, $replace, rawurlencode($value)); $mail_parms[] = $var . '=' . str_replace($search, $replace, rawurlencode($value));
} }
break; break;
case 'subject':
case 'subject': case 'newsgroups':
case 'newsgroups': $mail_parms[] = $var . '=' . rawurlencode($value);
$mail_parms[] = $var . '=' . rawurlencode($value); break;
break; case 'extra':
case 'text':
case 'extra': $$var = $value;
case 'text': default:
$$var = $value;
default:
} }
} }
if ($mail_parms) { if ($mail_parms) {
$address .= '?' . join('&', $mail_parms); $address .= '?' . join('&', $mail_parms);
} }
$encode = (empty($params[ 'encode' ])) ? 'none' : $params[ 'encode' ]; $encode = (empty($params[ 'encode' ])) ? 'none' : $params[ 'encode' ];
if (!isset($_allowed_encoding[ $encode ])) { if (!isset($_allowed_encoding[ $encode ])) {
trigger_error( trigger_error(
"mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex", "mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex",
E_USER_WARNING E_USER_WARNING
); );
return; return;
} }
// FIXME: (rodneyrehm) document.write() excues me what? 1998 has passed! // FIXME: (rodneyrehm) document.write() excues me what? 1998 has passed!
if ($encode === 'javascript') { if ($encode === 'javascript') {
$string = 'document.write(\'<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>\');'; $string = 'document.write(\'<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>\');';
$js_encode = ''; $js_encode = '';
for ($x = 0, $_length = strlen($string); $x < $_length; $x ++) { for ($x = 0, $_length = strlen($string); $x < $_length; $x++) {
$js_encode .= '%' . bin2hex($string[ $x ]); $js_encode .= '%' . bin2hex($string[ $x ]);
} }
return '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>'; return '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>';
} elseif ($encode === 'javascript_charcode') { } elseif ($encode === 'javascript_charcode') {
$string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>'; $string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
for ($x = 0, $y = strlen($string); $x < $y; $x++) {
for ($x = 0, $y = strlen($string); $x < $y; $x ++) {
$ord[] = ord($string[ $x ]); $ord[] = ord($string[ $x ]);
} }
$_ret = "<script type=\"text/javascript\" language=\"javascript\">\n" . "{document.write(String.fromCharCode(" . $_ret = "<script type=\"text/javascript\" language=\"javascript\">\n" . "{document.write(String.fromCharCode(" .
implode(',', $ord) . "))" . "}\n" . "</script>\n"; implode(',', $ord) . "))" . "}\n" . "</script>\n";
return $_ret; return $_ret;
} elseif ($encode === 'hex') { } elseif ($encode === 'hex') {
preg_match('!^(.*)(\?.*)$!', $address, $match); preg_match('!^(.*)(\?.*)$!', $address, $match);
if (!empty($match[ 2 ])) { if (!empty($match[ 2 ])) {
trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.", E_USER_WARNING); trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.", E_USER_WARNING);
return; return;
} }
$address_encode = ''; $address_encode = '';
for ($x = 0, $_length = strlen($address); $x < $_length; $x ++) { for ($x = 0, $_length = strlen($address); $x < $_length; $x++) {
if (preg_match('!\w!' . Smarty::$_UTF8_MODIFIER, $address[ $x ])) { if (preg_match('!\w!' . Smarty::$_UTF8_MODIFIER, $address[ $x ])) {
$address_encode .= '%' . bin2hex($address[ $x ]); $address_encode .= '%' . bin2hex($address[ $x ]);
} else { } else {
@@ -140,12 +124,10 @@ function smarty_function_mailto($params)
} }
} }
$text_encode = ''; $text_encode = '';
for ($x = 0, $_length = strlen($text); $x < $_length; $x ++) { for ($x = 0, $_length = strlen($text); $x < $_length; $x++) {
$text_encode .= '&#x' . bin2hex($text[ $x ]) . ';'; $text_encode .= '&#x' . bin2hex($text[ $x ]) . ';';
} }
$mailto = "&#109;&#97;&#105;&#108;&#116;&#111;&#58;"; $mailto = "&#109;&#97;&#105;&#108;&#116;&#111;&#58;";
return '<a href="' . $mailto . $address_encode . '" ' . $extra . '>' . $text_encode . '</a>'; return '<a href="' . $mailto . $address_encode . '" ' . $extra . '>' . $text_encode . '</a>';
} else { } else {
// no encoding // no encoding

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage Debug * @subpackage Debug
*/ */
/** /**
* Smarty debug_print_var modifier plugin * Smarty debug_print_var modifier plugin
* Type: modifier * Type: modifier
@@ -26,87 +25,79 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
{ {
$_replace = array("\n" => '\n', "\r" => '\r', "\t" => '\t'); $_replace = array("\n" => '\n', "\r" => '\r', "\t" => '\t');
switch (gettype($var)) { switch (gettype($var)) {
case 'array' : case 'array' :
$results = '<b>Array (' . count($var) . ')</b>'; $results = '<b>Array (' . count($var) . ')</b>';
if ($depth === $max) { if ($depth === $max) {
break;
}
foreach ($var as $curr_key => $curr_val) {
$results .= '<br>' . str_repeat('&nbsp;', $depth * 2) . '<b>' . strtr($curr_key, $_replace) .
'</b> =&gt; ' .
smarty_modifier_debug_print_var($curr_val, $max, $length, ++$depth, $objects);
$depth--;
}
break; break;
} case 'object' :
foreach ($var as $curr_key => $curr_val) { $object_vars = get_object_vars($var);
$results .= '<br>' . str_repeat('&nbsp;', $depth * 2) . '<b>' . strtr($curr_key, $_replace) . $results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
'</b> =&gt; ' . if (in_array($var, $objects)) {
smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects); $results .= ' called recursive';
$depth --; break;
} }
break; if ($depth === $max) {
break;
case 'object' : }
$object_vars = get_object_vars($var); $objects[] = $var;
$results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>'; foreach ($object_vars as $curr_key => $curr_val) {
if (in_array($var, $objects)) { $results .= '<br>' . str_repeat('&nbsp;', $depth * 2) . '<b> -&gt;' . strtr($curr_key, $_replace) .
$results .= ' called recursive'; '</b> = ' . smarty_modifier_debug_print_var($curr_val, $max, $length, ++$depth, $objects);
$depth--;
}
break; break;
} case 'boolean' :
if ($depth === $max) { case 'NULL' :
case 'resource' :
if (true === $var) {
$results = 'true';
} elseif (false === $var) {
$results = 'false';
} elseif (null === $var) {
$results = 'null';
} else {
$results = htmlspecialchars((string)$var);
}
$results = '<i>' . $results . '</i>';
break; break;
} case 'integer' :
$objects[] = $var; case 'float' :
foreach ($object_vars as $curr_key => $curr_val) { $results = htmlspecialchars((string)$var);
$results .= '<br>' . str_repeat('&nbsp;', $depth * 2) . '<b> -&gt;' . strtr($curr_key, $_replace) . break;
'</b> = ' . smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects); case 'string' :
$depth --; $results = strtr($var, $_replace);
} if (Smarty::$_MBSTRING) {
break; if (mb_strlen($var, Smarty::$_CHARSET) > $length) {
$results = mb_substr($var, 0, $length - 3, Smarty::$_CHARSET) . '...';
case 'boolean' : }
case 'NULL' : } else {
case 'resource' : if (isset($var[ $length ])) {
if (true === $var) { $results = substr($var, 0, $length - 3) . '...';
$results = 'true'; }
} elseif (false === $var) {
$results = 'false';
} elseif (null === $var) {
$results = 'null';
} else {
$results = htmlspecialchars((string) $var);
}
$results = '<i>' . $results . '</i>';
break;
case 'integer' :
case 'float' :
$results = htmlspecialchars((string) $var);
break;
case 'string' :
$results = strtr($var, $_replace);
if (Smarty::$_MBSTRING) {
if (mb_strlen($var, Smarty::$_CHARSET) > $length) {
$results = mb_substr($var, 0, $length - 3, Smarty::$_CHARSET) . '...';
} }
} else { $results = htmlspecialchars('"' . $results . '"', ENT_QUOTES, Smarty::$_CHARSET);
if (isset($var[ $length ])) { break;
$results = substr($var, 0, $length - 3) . '...'; case 'unknown type' :
default :
$results = strtr((string)$var, $_replace);
if (Smarty::$_MBSTRING) {
if (mb_strlen($results, Smarty::$_CHARSET) > $length) {
$results = mb_substr($results, 0, $length - 3, Smarty::$_CHARSET) . '...';
}
} else {
if (strlen($results) > $length) {
$results = substr($results, 0, $length - 3) . '...';
}
} }
} $results = htmlspecialchars($results, ENT_QUOTES, Smarty::$_CHARSET);
$results = htmlspecialchars('"' . $results . '"', ENT_QUOTES, Smarty::$_CHARSET);
break;
case 'unknown type' :
default :
$results = strtr((string) $var, $_replace);
if (Smarty::$_MBSTRING) {
if (mb_strlen($results, Smarty::$_CHARSET) > $length) {
$results = mb_substr($results, 0, $length - 3, Smarty::$_CHARSET) . '...';
}
} else {
if (strlen($results) > $length) {
$results = substr($results, 0, $length - 3) . '...';
}
}
$results = htmlspecialchars($results, ENT_QUOTES, Smarty::$_CHARSET);
} }
return $results; return $results;
} }

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifier * @subpackage PluginsModifier
*/ */
/** /**
* Smarty escape modifier plugin * Smarty escape modifier plugin
* Type: modifier * Type: modifier
@@ -30,218 +29,203 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
if ($_double_encode === null) { if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
} }
if (!$char_set) { if (!$char_set) {
$char_set = Smarty::$_CHARSET; $char_set = Smarty::$_CHARSET;
} }
switch ($esc_type) { switch ($esc_type) {
case 'html': case 'html':
if ($_double_encode) {
// php >=5.3.2 - go native
return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
} else {
if ($double_encode) {
// php <5.2.3 - only handle double encoding
return htmlspecialchars($string, ENT_QUOTES, $char_set);
} else {
// php <5.2.3 - prevent double encoding
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
$string = str_replace(
array('%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'), array('&',
';'), $string
);
return $string;
}
}
case 'htmlall':
if (Smarty::$_MBSTRING) {
// mb_convert_encoding ignores htmlspecialchars()
if ($_double_encode) { if ($_double_encode) {
// php >=5.3.2 - go native // php >=5.3.2 - go native
$string = htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode); return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
} else { } else {
if ($double_encode) { if ($double_encode) {
// php <5.2.3 - only handle double encoding // php <5.2.3 - only handle double encoding
$string = htmlspecialchars($string, ENT_QUOTES, $char_set); return htmlspecialchars($string, ENT_QUOTES, $char_set);
} else { } else {
// php <5.2.3 - prevent double encoding // php <5.2.3 - prevent double encoding
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string, ENT_QUOTES, $char_set); $string = htmlspecialchars($string, ENT_QUOTES, $char_set);
$string = $string = str_replace(
str_replace( array('%%%SMARTY_START%%%',
array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'),
'%%%SMARTY_END%%%'), array('&', array('&',
';'), $string ';'),
); $string
);
return $string; return $string;
} }
} }
case 'htmlall':
// htmlentities() won't convert everything, so use mb_convert_encoding if (Smarty::$_MBSTRING) {
return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set); // mb_convert_encoding ignores htmlspecialchars()
} if ($_double_encode) {
// php >=5.3.2 - go native
// no MBString fallback $string = htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
if ($_double_encode) {
return htmlentities($string, ENT_QUOTES, $char_set, $double_encode);
} else {
if ($double_encode) {
return htmlentities($string, ENT_QUOTES, $char_set);
} else {
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlentities($string, ENT_QUOTES, $char_set);
$string = str_replace(
array('%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'), array('&',
';'), $string
);
return $string;
}
}
case 'url':
return rawurlencode($string);
case 'urlpathinfo':
return str_replace('%2F', '/', rawurlencode($string));
case 'quotes':
// escape unescaped single quotes
return preg_replace("%(?<!\\\\)'%", "\\'", $string);
case 'hex':
// escape every byte into hex
// Note that the UTF-8 encoded character ä will be represented as %c3%a4
$return = '';
$_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) {
$return .= '%' . bin2hex($string[ $x ]);
}
return $return;
case 'hexentity':
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
}
$is_loaded_1 = true;
}
$return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
$return .= '&#x' . strtoupper(dechex($unicode)) . ';';
}
return $return;
}
// no MBString fallback
$_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) {
$return .= '&#x' . bin2hex($string[ $x ]) . ';';
}
return $return;
case 'decentity':
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
}
$is_loaded_1 = true;
}
$return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
$return .= '&#' . $unicode . ';';
}
return $return;
}
// no MBString fallback
$_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) {
$return .= '&#' . ord($string[ $x ]) . ';';
}
return $return;
case 'javascript':
// escape quotes and backslashes, newlines, etc.
return strtr(
$string, array('\\' => '\\\\',
"'" => "\\'",
'"' => '\\"',
"\r" => '\\r',
"\n" => '\\n',
'</' => '<\/')
);
case 'mail':
if (Smarty::$_MBSTRING) {
if (!$is_loaded_2) {
if (!is_callable('smarty_mb_str_replace')) {
include_once SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php';
}
$is_loaded_2 = true;
}
return smarty_mb_str_replace(
array('@',
'.'), array(' [AT] ',
' [DOT] '), $string
);
}
// no MBString fallback
return str_replace(
array('@',
'.'), array(' [AT] ',
' [DOT] '), $string
);
case 'nonstd':
// escape non-standard chars, such as ms document quotes
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
}
$is_loaded_1 = true;
}
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
if ($unicode >= 126) {
$return .= '&#' . $unicode . ';';
} else { } else {
$return .= chr($unicode); if ($double_encode) {
// php <5.2.3 - only handle double encoding
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
} else {
// php <5.2.3 - prevent double encoding
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
$string =
str_replace(
array('%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'),
array('&',
';'),
$string
);
return $string;
}
}
// htmlentities() won't convert everything, so use mb_convert_encoding
return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set);
}
// no MBString fallback
if ($_double_encode) {
return htmlentities($string, ENT_QUOTES, $char_set, $double_encode);
} else {
if ($double_encode) {
return htmlentities($string, ENT_QUOTES, $char_set);
} else {
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlentities($string, ENT_QUOTES, $char_set);
$string = str_replace(
array('%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'),
array('&',
';'),
$string
);
return $string;
} }
} }
case 'url':
return $return; return rawurlencode($string);
} case 'urlpathinfo':
return str_replace('%2F', '/', rawurlencode($string));
$_length = strlen($string); case 'quotes':
for ($_i = 0; $_i < $_length; $_i ++) { // escape unescaped single quotes
$_ord = ord(substr($string, $_i, 1)); return preg_replace("%(?<!\\\\)'%", "\\'", $string);
// non-standard char, escape it case 'hex':
if ($_ord >= 126) { // escape every byte into hex
$return .= '&#' . $_ord . ';'; // Note that the UTF-8 encoded character ä will be represented as %c3%a4
} else { $return = '';
$return .= substr($string, $_i, 1); $_length = strlen($string);
for ($x = 0; $x < $_length; $x++) {
$return .= '%' . bin2hex($string[ $x ]);
} }
} return $return;
case 'hexentity':
return $return; $return = '';
if (Smarty::$_MBSTRING) {
default: if (!$is_loaded_1) {
return $string; if (!is_callable('smarty_mb_to_unicode')) {
include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
}
$is_loaded_1 = true;
}
$return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
$return .= '&#x' . strtoupper(dechex($unicode)) . ';';
}
return $return;
}
// no MBString fallback
$_length = strlen($string);
for ($x = 0; $x < $_length; $x++) {
$return .= '&#x' . bin2hex($string[ $x ]) . ';';
}
return $return;
case 'decentity':
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
}
$is_loaded_1 = true;
}
$return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
$return .= '&#' . $unicode . ';';
}
return $return;
}
// no MBString fallback
$_length = strlen($string);
for ($x = 0; $x < $_length; $x++) {
$return .= '&#' . ord($string[ $x ]) . ';';
}
return $return;
case 'javascript':
// escape quotes and backslashes, newlines, etc.
return strtr(
$string,
array('\\' => '\\\\',
"'" => "\\'",
'"' => '\\"',
"\r" => '\\r',
"\n" => '\\n',
'</' => '<\/')
);
case 'mail':
if (Smarty::$_MBSTRING) {
if (!$is_loaded_2) {
if (!is_callable('smarty_mb_str_replace')) {
include_once SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php';
}
$is_loaded_2 = true;
}
return smarty_mb_str_replace(
array('@',
'.'),
array(' [AT] ',
' [DOT] '),
$string
);
}
// no MBString fallback
return str_replace(
array('@',
'.'),
array(' [AT] ',
' [DOT] '),
$string
);
case 'nonstd':
// escape non-standard chars, such as ms document quotes
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
}
$is_loaded_1 = true;
}
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
if ($unicode >= 126) {
$return .= '&#' . $unicode . ';';
} else {
$return .= chr($unicode);
}
}
return $return;
}
$_length = strlen($string);
for ($_i = 0; $_i < $_length; $_i++) {
$_ord = ord(substr($string, $_i, 1));
// non-standard char, escape it
if ($_ord >= 126) {
$return .= '&#' . $_ord . ';';
} else {
$return .= substr($string, $_i, 1);
}
}
return $return;
default:
return $string;
} }
} }

View File

@@ -62,7 +62,7 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa
} }
$length = $token_length; $length = $token_length;
} }
} else if ($token === "\n") { } elseif ($token === "\n") {
// hard break must reset counters // hard break must reset counters
$length = 0; $length = 0;
} }

View File

@@ -14,7 +14,7 @@
* @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual) * @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
* @author Rodney Rehm * @author Rodney Rehm
* *
* @param array $params parameters * @param array $params parameters
* @param Smarty_Internal_TemplateCompilerBase $compiler * @param Smarty_Internal_TemplateCompilerBase $compiler
* *
* @return string with compiled code * @return string with compiled code
@@ -26,80 +26,71 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
static $is_loaded = false; static $is_loaded = false;
$compiler->template->_checkPlugins( $compiler->template->_checkPlugins(
array(array('function' => 'smarty_literal_compiler_param', array(array('function' => 'smarty_literal_compiler_param',
'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php')) 'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'))
); );
if ($_double_encode === null) { if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
} }
try { try {
$esc_type = smarty_literal_compiler_param($params, 1, 'html'); $esc_type = smarty_literal_compiler_param($params, 1, 'html');
$char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET); $char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET);
$double_encode = smarty_literal_compiler_param($params, 3, true); $double_encode = smarty_literal_compiler_param($params, 3, true);
if (!$char_set) { if (!$char_set) {
$char_set = Smarty::$_CHARSET; $char_set = Smarty::$_CHARSET;
} }
switch ($esc_type) { switch ($esc_type) {
case 'html': case 'html':
if ($_double_encode) {
return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
var_export($double_encode, true) . ')';
} elseif ($double_encode) {
return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
} else {
// fall back to modifier.escape.php
}
case 'htmlall':
if (Smarty::$_MBSTRING) {
if ($_double_encode) { if ($_double_encode) {
// php >=5.2.3 - go native return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($double_encode, true) . ')';
var_export($char_set, true) . ', ' . var_export($double_encode, true) .
'), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
} elseif ($double_encode) { } elseif ($double_encode) {
// php <5.2.3 - only handle double encoding return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' .
var_export($char_set, true) . '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
} else { } else {
// fall back to modifier.escape.php // fall back to modifier.escape.php
} }
} case 'htmlall':
if (Smarty::$_MBSTRING) {
// no MBString fallback if ($_double_encode) {
if ($_double_encode) { // php >=5.2.3 - go native
// php >=5.2.3 - go native return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' .
return 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' . var_export($char_set, true) . ', ' . var_export($double_encode, true) .
var_export($double_encode, true) . ')'; '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
} elseif ($double_encode) { } elseif ($double_encode) {
// php <5.2.3 - only handle double encoding // php <5.2.3 - only handle double encoding
return 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')'; return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' .
} else { var_export($char_set, true) . '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
// fall back to modifier.escape.php } else {
} // fall back to modifier.escape.php
}
case 'url': }
return 'rawurlencode(' . $params[ 0 ] . ')'; // no MBString fallback
if ($_double_encode) {
case 'urlpathinfo': // php >=5.2.3 - go native
return 'str_replace("%2F", "/", rawurlencode(' . $params[ 0 ] . '))'; return 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
var_export($double_encode, true) . ')';
case 'quotes': } elseif ($double_encode) {
// escape unescaped single quotes // php <5.2.3 - only handle double encoding
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[ 0 ] . ')'; return 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
} else {
case 'javascript': // fall back to modifier.escape.php
// escape quotes and backslashes, newlines, etc. }
return 'strtr(' . $params[ 0 ] . case 'url':
return 'rawurlencode(' . $params[ 0 ] . ')';
case 'urlpathinfo':
return 'str_replace("%2F", "/", rawurlencode(' . $params[ 0 ] . '))';
case 'quotes':
// escape unescaped single quotes
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[ 0 ] . ')';
case 'javascript':
// escape quotes and backslashes, newlines, etc.
return 'strtr(' .
$params[ 0 ] .
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))'; ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))';
} }
} }
catch (SmartyException $e) { catch (SmartyException $e) {
// pass through to regular plugin fallback // pass through to regular plugin fallback
} }
// could not optimize |escape call, so fallback to regular plugin // could not optimize |escape call, so fallback to regular plugin
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) { if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
$compiler->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] = $compiler->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] =
@@ -112,6 +103,5 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
$compiler->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] = $compiler->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] =
'smarty_modifier_escape'; 'smarty_modifier_escape';
} }
return 'smarty_modifier_escape(' . join(', ', $params) . ')'; return 'smarty_modifier_escape(' . join(', ', $params) . ')';
} }

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty unescape modifier plugin * Smarty unescape modifier plugin
* Type: modifier * Type: modifier
@@ -28,23 +27,18 @@ function smarty_modifiercompiler_unescape($params)
} else { } else {
$params[ 2 ] = "'{$params[ 2 ]}'"; $params[ 2 ] = "'{$params[ 2 ]}'";
} }
switch (trim($params[ 1 ], '"\'')) { switch (trim($params[ 1 ], '"\'')) {
case 'entity': case 'entity':
case 'htmlall': case 'htmlall':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 2 ] . ', \'HTML-ENTITIES\')'; return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 2 ] . ', \'HTML-ENTITIES\')';
} }
return 'html_entity_decode(' . $params[ 0 ] . ', ENT_NOQUOTES, ' . $params[ 2 ] . ')';
return 'html_entity_decode(' . $params[ 0 ] . ', ENT_NOQUOTES, ' . $params[ 2 ] . ')'; case 'html':
return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)';
case 'html': case 'url':
return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)'; return 'rawurldecode(' . $params[ 0 ] . ')';
default:
case 'url': return $params[ 0 ];
return 'rawurldecode(' . $params[ 0 ] . ')';
default:
return $params[ 0 ];
} }
} }

View File

@@ -28,7 +28,7 @@ if (!function_exists('smarty_mb_str_replace')) {
$string = smarty_mb_str_replace($search, $replace, $string, $c); $string = smarty_mb_str_replace($search, $replace, $string, $c);
$count += $c; $count += $c;
} }
} else if (is_array($search)) { } elseif (is_array($search)) {
if (!is_array($replace)) { if (!is_array($replace)) {
foreach ($search as &$string) { foreach ($search as &$string) {
$subject = smarty_mb_str_replace($string, $replace, $subject, $c); $subject = smarty_mb_str_replace($string, $replace, $subject, $c);

View File

@@ -25,12 +25,12 @@ abstract class Smarty_CacheResource
/** /**
* populate Cached Object with meta data from Resource * populate Cached Object with meta data from Resource
* *
* @param Smarty_Template_Cached $cached cached object * @param \Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object * @param Smarty_Internal_Template $_template template object
* *
* @return void * @return void
*/ */
abstract public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template); abstract public function populate(\Smarty_Template_Cached $cached, Smarty_Internal_Template $_template);
/** /**
* populate Cached Object with timestamp and exists from Resource * populate Cached Object with timestamp and exists from Resource

View File

@@ -123,7 +123,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
&& (!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api'))) < 1 && (!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api'))) < 1
) { ) {
opcache_invalidate($_template->cached->filepath, true); opcache_invalidate($_template->cached->filepath, true);
} else if (function_exists('apc_compile_file')) { } elseif (function_exists('apc_compile_file')) {
apc_compile_file($_template->cached->filepath); apc_compile_file($_template->cached->filepath);
} }
$cached = $_template->cached; $cached = $_template->cached;

View File

@@ -66,7 +66,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
++$compiler->_cache[ 'blockNesting' ]; ++$compiler->_cache[ 'blockNesting' ];
$_className = 'Block_' . preg_replace('![^\w]+!', '_', uniqid(rand(), true)); $_className = 'Block_' . preg_replace('![^\w]+!', '_', uniqid(mt_rand(), true));
$compiler->_cache[ 'blockName' ][ $compiler->_cache[ 'blockNesting' ] ] = $_attr[ 'name' ]; $compiler->_cache[ 'blockName' ][ $compiler->_cache[ 'blockNesting' ] ] = $_attr[ 'name' ];
$compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ] = $_className; $compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ] = $_className;
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ] = array(); $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ] = array();

View File

@@ -40,7 +40,6 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null) public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
{ {

View File

@@ -1,5 +1,4 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Modifier * Smarty Internal Plugin Compile Modifier
* Compiles code for modifier execution * Compiles code for modifier execution
@@ -47,110 +46,113 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
} }
foreach ($modifier_types as $type) { foreach ($modifier_types as $type) {
switch ($type) { switch ($type) {
case 1: case 1:
// registered modifier // registered modifier
if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) { if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) {
if (is_callable($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ])) { if (is_callable($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ])) {
$output =
sprintf(
'call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))',
Smarty::PLUGIN_MODIFIER,
var_export($modifier, true),
$params
);
$compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
}
break;
case 2:
// registered modifier compiler
if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ])) {
$output = $output =
sprintf( call_user_func(
'call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))', $compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ],
Smarty::PLUGIN_MODIFIER, var_export($modifier, true), $params $single_modifier,
$compiler->smarty
); );
$compiler->known_modifier_type[ $modifier ] = $type; $compiler->known_modifier_type[ $modifier ] = $type;
break 2; break 2;
} }
} break;
break; case 3:
case 2: // modifiercompiler plugin
// registered modifier compiler if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ])) { // check if modifier allowed
$output = if (!is_object($compiler->smarty->security_policy)
call_user_func( || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
$compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ], ) {
$single_modifier, $compiler->smarty $plugin = 'smarty_modifiercompiler_' . $modifier;
); $output = $plugin($single_modifier, $compiler);
$compiler->known_modifier_type[ $modifier ] = $type; }
break 2; $compiler->known_modifier_type[ $modifier ] = $type;
} break 2;
break;
case 3:
// modifiercompiler plugin
if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
$plugin = 'smarty_modifiercompiler_' . $modifier;
$output = $plugin($single_modifier, $compiler);
} }
$compiler->known_modifier_type[ $modifier ] = $type; break;
break 2; case 4:
} // modifier plugin
break; if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
case 4: // check if modifier allowed
// modifier plugin if (!is_object($compiler->smarty->security_policy)
if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) { || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
// check if modifier allowed ) {
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
$output = "{$function}({$params})";
}
$compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
break;
case 5:
// PHP function
if (is_callable($modifier)) {
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
) {
$output = "{$modifier}({$params})";
}
$compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
break;
case 6:
// default plugin handler
if (isset($compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])
|| (is_callable($compiler->smarty->default_plugin_handler_func)
&& $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))
) {
$function = $compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ];
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
if (!is_array($function)) {
$output = "{$function}({$params})"; $output = "{$function}({$params})";
} else { }
if (is_object($function[ 0 ])) { $compiler->known_modifier_type[ $modifier ] = $type;
$output = $function[ 0 ] . '->'. $function[ 1 ] . '(' . $params . ')'; break 2;
}
break;
case 5:
// PHP function
if (is_callable($modifier)) {
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
) {
$output = "{$modifier}({$params})";
}
$compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
break;
case 6:
// default plugin handler
if (isset($compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])
|| (is_callable($compiler->smarty->default_plugin_handler_func)
&& $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))
) {
$function = $compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ];
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
if (!is_array($function)) {
$output = "{$function}({$params})";
} else { } else {
$output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')'; if (is_object($function[ 0 ])) {
$output = $function[ 0 ] . '->' . $function[ 1 ] . '(' . $params . ')';
} else {
$output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')';
}
} }
} }
if (isset($compiler->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
||
isset($compiler->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
) {
// was a plugin
$compiler->known_modifier_type[ $modifier ] = 4;
} else {
$compiler->known_modifier_type[ $modifier ] = $type;
}
break 2;
} }
if (isset($compiler->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
|| isset($compiler->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
) {
// was a plugin
$compiler->known_modifier_type[ $modifier ] = 4;
} else {
$compiler->known_modifier_type[ $modifier ] = $type;
}
break 2;
}
} }
} }
if (!isset($compiler->known_modifier_type[ $modifier ])) { if (!isset($compiler->known_modifier_type[ $modifier ])) {
$compiler->trigger_template_error("unknown modifier '{$modifier}'", null, true); $compiler->trigger_template_error("unknown modifier '{$modifier}'", null, true);
} }
} }
return $output; return $output;
} }
} }

View File

@@ -21,7 +21,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param $parameter * @param $parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \SmartyCompilerException
@@ -33,86 +33,82 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
if ($variable === false) { if ($variable === false) {
$compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true); $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true);
} }
if (!isset($compiler->smarty->security_policy) if (!isset($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler) || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)
) { ) {
switch ($variable) { switch ($variable) {
case 'foreach': case 'foreach':
case 'section': case 'section':
if (!isset(Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ])) { if (!isset(Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ])) {
$class = 'Smarty_Internal_Compile_' . ucfirst($variable); $class = 'Smarty_Internal_Compile_' . ucfirst($variable);
Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ] = new $class; Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ] = new $class;
} }
return Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ]->compileSpecialVariable(array(), $compiler, $_index); return Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ]->compileSpecialVariable(array(),
case 'capture': $compiler,
if (class_exists('Smarty_Internal_Compile_Capture')) { $_index);
return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index); case 'capture':
} if (class_exists('Smarty_Internal_Compile_Capture')) {
return ''; return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);
case 'now': }
return 'time()'; return '';
case 'cookies': case 'now':
if (isset($compiler->smarty->security_policy) return 'time()';
&& !$compiler->smarty->security_policy->allow_super_globals case 'cookies':
) { if (isset($compiler->smarty->security_policy)
$compiler->trigger_template_error("(secure mode) super globals not permitted"); && !$compiler->smarty->security_policy->allow_super_globals
) {
$compiler->trigger_template_error("(secure mode) super globals not permitted");
break;
}
$compiled_ref = '$_COOKIE';
break; break;
} case 'get':
$compiled_ref = '$_COOKIE'; case 'post':
break; case 'env':
case 'get': case 'server':
case 'post': case 'session':
case 'env': case 'request':
case 'server': if (isset($compiler->smarty->security_policy)
case 'session': && !$compiler->smarty->security_policy->allow_super_globals
case 'request': ) {
if (isset($compiler->smarty->security_policy) $compiler->trigger_template_error("(secure mode) super globals not permitted");
&& !$compiler->smarty->security_policy->allow_super_globals break;
) { }
$compiler->trigger_template_error("(secure mode) super globals not permitted"); $compiled_ref = '$_' . strtoupper($variable);
break; break;
} case 'template':
$compiled_ref = '$_' . strtoupper($variable); return 'basename($_smarty_tpl->source->filepath)';
break; case 'template_object':
return '$_smarty_tpl';
case 'template': case 'current_dir':
return 'basename($_smarty_tpl->source->filepath)'; return 'dirname($_smarty_tpl->source->filepath)';
case 'version':
case 'template_object': return "Smarty::SMARTY_VERSION";
return '$_smarty_tpl'; case 'const':
if (isset($compiler->smarty->security_policy)
case 'current_dir': && !$compiler->smarty->security_policy->allow_constants
return 'dirname($_smarty_tpl->source->filepath)'; ) {
$compiler->trigger_template_error("(secure mode) constants not permitted");
case 'version': break;
return "Smarty::SMARTY_VERSION"; }
if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) {
case 'const': return "@constant('{$_index[1]}')";
if (isset($compiler->smarty->security_policy) } else {
&& !$compiler->smarty->security_policy->allow_constants return "@constant({$_index[1]})";
) { }
$compiler->trigger_template_error("(secure mode) constants not permitted"); case 'config':
if (isset($_index[ 2 ])) {
return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
} else {
return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])";
}
case 'ldelim':
return "\$_smarty_tpl->smarty->left_delimiter";
case 'rdelim':
return "\$_smarty_tpl->smarty->right_delimiter";
default:
$compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], "'") . ' is not defined');
break; break;
}
if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) {
return "@constant('{$_index[1]}')";
} else {
return "@constant({$_index[1]})";
}
case 'config':
if (isset($_index[ 2 ])) {
return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
} else {
return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])";
}
case 'ldelim':
return "\$_smarty_tpl->smarty->left_delimiter";
case 'rdelim':
return "\$_smarty_tpl->smarty->right_delimiter";
default:
$compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], "'") . ' is not defined');
break;
} }
if (isset($_index[ 1 ])) { if (isset($_index[ 1 ])) {
array_shift($_index); array_shift($_index);

View File

@@ -88,7 +88,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$compiler->loopNesting ++; $compiler->loopNesting++;
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$attributes = array('name' => $compiler->getId($_attr[ 'name' ])); $attributes = array('name' => $compiler->getId($_attr[ 'name' ]));
@@ -98,20 +98,18 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true); $compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true);
} }
} }
$local = "\$__section_{$attributes['name']}_" . $this->counter ++ . '_'; $local = "\$__section_{$attributes['name']}_" . $this->counter++ . '_';
$sectionVar = "\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']"; $sectionVar = "\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']";
$this->openTag($compiler, 'section', array('section', $compiler->nocache, $local, $sectionVar)); $this->openTag($compiler, 'section', array('section', $compiler->nocache, $local, $sectionVar));
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$initLocal = array(); $initLocal = array();
$initNamedProperty = array(); $initNamedProperty = array();
$initFor = array(); $initFor = array();
$incFor = array(); $incFor = array();
$cmpFor = array(); $cmpFor = array();
$propValue = array('index' => "{$sectionVar}->value['index']", 'show' => 'true', 'step' => 1, $propValue = array('index' => "{$sectionVar}->value['index']", 'show' => 'true', 'step' => 1,
'iteration' => "{$local}iteration", 'iteration' => "{$local}iteration",
); );
$propType = array('index' => 2, 'iteration' => 2, 'show' => 0, 'step' => 0,); $propType = array('index' => 2, 'iteration' => 2, 'show' => 0, 'step' => 0,);
// search for used tag attributes // search for used tag attributes
@@ -132,50 +130,49 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$output = "<?php\n"; $output = "<?php\n";
foreach ($_attr as $attr_name => $attr_value) { foreach ($_attr as $attr_name => $attr_value) {
switch ($attr_name) { switch ($attr_name) {
case 'loop': case 'loop':
if (is_numeric($attr_value)) { if (is_numeric($attr_value)) {
$v = (int) $attr_value; $v = (int)$attr_value;
$t = 0; $t = 0;
} else { } else {
$v = "(is_array(@\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop))"; $v = "(is_array(@\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop))";
$t = 1; $t = 1;
} }
if ($t === 1) { if ($t === 1) {
$initLocal[ 'loop' ] = $v; $initLocal[ 'loop' ] = $v;
$v = "{$local}loop"; $v = "{$local}loop";
} }
break; break;
case 'show': case 'show':
if (is_bool($attr_value)) { if (is_bool($attr_value)) {
$v = $attr_value ? 'true' : 'false'; $v = $attr_value ? 'true' : 'false';
$t = 0; $t = 0;
} else { } else {
$v = "(bool) $attr_value"; $v = "(bool) $attr_value";
$t = 3;
}
break;
case 'step':
if (is_numeric($attr_value)) {
$v = (int)$attr_value;
$v = ($v === 0) ? 1 : $v;
$t = 0;
break;
}
$initLocal[ 'step' ] = "((int)@$attr_value) === 0 ? 1 : (int)@$attr_value";
$v = "{$local}step";
$t = 2;
break;
case 'max':
case 'start':
if (is_numeric($attr_value)) {
$v = (int)$attr_value;
$t = 0;
break;
}
$v = "(int)@$attr_value";
$t = 3; $t = 3;
}
break;
case 'step':
if (is_numeric($attr_value)) {
$v = (int) $attr_value;
$v = ($v === 0) ? 1 : $v;
$t = 0;
break; break;
}
$initLocal[ 'step' ] = "((int)@$attr_value) === 0 ? 1 : (int)@$attr_value";
$v = "{$local}step";
$t = 2;
break;
case 'max':
case 'start':
if (is_numeric($attr_value)) {
$v = (int) $attr_value;
$t = 0;
break;
}
$v = "(int)@$attr_value";
$t = 3;
break;
} }
if ($t === 3 && $compiler->getId($attr_value)) { if ($t === 3 && $compiler->getId($attr_value)) {
$t = 1; $t = 1;
@@ -183,7 +180,6 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$propValue[ $attr_name ] = $v; $propValue[ $attr_name ] = $v;
$propType[ $attr_name ] = $t; $propType[ $attr_name ] = $t;
} }
if (isset($namedAttr[ 'step' ])) { if (isset($namedAttr[ 'step' ])) {
$initNamedProperty[ 'step' ] = $propValue[ 'step' ]; $initNamedProperty[ 'step' ] = $propValue[ 'step' ];
} }
@@ -192,19 +188,17 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
} }
$incFor[ 'iteration' ] = "{$propValue['iteration']}++"; $incFor[ 'iteration' ] = "{$propValue['iteration']}++";
$initFor[ 'iteration' ] = "{$propValue['iteration']} = 1"; $initFor[ 'iteration' ] = "{$propValue['iteration']} = 1";
if ($propType[ 'step' ] === 0) { if ($propType[ 'step' ] === 0) {
if ($propValue[ 'step' ] === 1) { if ($propValue[ 'step' ] === 1) {
$incFor[ 'index' ] = "{$sectionVar}->value['index']++"; $incFor[ 'index' ] = "{$sectionVar}->value['index']++";
} elseif ($propValue[ 'step' ] > 1) { } elseif ($propValue[ 'step' ] > 1) {
$incFor[ 'index' ] = "{$sectionVar}->value['index'] += {$propValue['step']}"; $incFor[ 'index' ] = "{$sectionVar}->value['index'] += {$propValue['step']}";
} else { } else {
$incFor[ 'index' ] = "{$sectionVar}->value['index'] -= " . - $propValue[ 'step' ]; $incFor[ 'index' ] = "{$sectionVar}->value['index'] -= " . -$propValue[ 'step' ];
} }
} else { } else {
$incFor[ 'index' ] = "{$sectionVar}->value['index'] += {$propValue['step']}"; $incFor[ 'index' ] = "{$sectionVar}->value['index'] += {$propValue['step']}";
} }
if (!isset($propValue[ 'max' ])) { if (!isset($propValue[ 'max' ])) {
$propValue[ 'max' ] = $propValue[ 'loop' ]; $propValue[ 'max' ] = $propValue[ 'loop' ];
$propType[ 'max' ] = $propType[ 'loop' ]; $propType[ 'max' ] = $propType[ 'loop' ];
@@ -217,7 +211,6 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$propType[ 'max' ] = $propType[ 'loop' ]; $propType[ 'max' ] = $propType[ 'loop' ];
} }
} }
if (!isset($propValue[ 'start' ])) { if (!isset($propValue[ 'start' ])) {
$start_code = $start_code =
array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue[ 'loop' ], 5 => ' - 1'); array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue[ 'loop' ], 5 => ' - 1');
@@ -239,8 +232,8 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$propValue[ 'start' ] = join('', $start_code); $propValue[ 'start' ] = join('', $start_code);
} else { } else {
$start_code = $start_code =
array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ", 4 => '0', array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ", 4 => '0',
5 => ' : ', 6 => '-1', 7 => ', ', 8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')', 5 => ' : ', 6 => '-1', 7 => ', ', 8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')',
11 => ' : ', 12 => 'min(', 13 => $propValue[ 'start' ], 14 => ', ', 11 => ' : ', 12 => 'min(', 13 => $propValue[ 'start' ], 14 => ', ',
15 => "{$propValue['step']} > 0 ? ", 16 => $propValue[ 'loop' ], 17 => ' : ', 15 => "{$propValue['step']} > 0 ? ", 16 => $propValue[ 'loop' ], 17 => ' : ',
18 => $propType[ 'loop' ] === 0 ? $propValue[ 'loop' ] - 1 : "{$propValue['loop']} - 1", 18 => $propType[ 'loop' ] === 0 ? $propValue[ 'loop' ] - 1 : "{$propValue['loop']} - 1",
@@ -260,25 +253,25 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$propType[ 'start' ] = $propType[ 'step' ] + $propType[ 'loop' ]; $propType[ 'start' ] = $propType[ 'step' ] + $propType[ 'loop' ];
$start_code[ 1 ] = ''; $start_code[ 1 ] = '';
if ($propValue[ 'start' ] < 0) { if ($propValue[ 'start' ] < 0) {
for ($i = 11; $i <= 19; $i ++) { for ($i = 11; $i <= 19; $i++) {
$start_code[ $i ] = ''; $start_code[ $i ] = '';
} }
if ($propType[ 'start' ] === 0) { if ($propType[ 'start' ] === 0) {
$start_code = array(max( $start_code = array(max(
$propValue[ 'step' ] > 0 ? 0 : - 1, $propValue[ 'step' ] > 0 ? 0 : -1,
$propValue[ 'start' ] + $propValue[ 'loop' ] $propValue[ 'start' ] + $propValue[ 'loop' ]
)); ));
} }
} else { } else {
for ($i = 1; $i <= 11; $i ++) { for ($i = 1; $i <= 11; $i++) {
$start_code[ $i ] = ''; $start_code[ $i ] = '';
} }
if ($propType[ 'start' ] === 0) { if ($propType[ 'start' ] === 0) {
$start_code = $start_code =
array(min( array(min(
$propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1, $propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1,
$propValue[ 'start' ] $propValue[ 'start' ]
)); ));
} }
} }
} }
@@ -288,9 +281,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$initLocal[ 'start' ] = $propValue[ 'start' ]; $initLocal[ 'start' ] = $propValue[ 'start' ];
$propValue[ 'start' ] = "{$local}start"; $propValue[ 'start' ] = "{$local}start";
} }
$initFor[ 'index' ] = "{$sectionVar}->value['index'] = {$propValue['start']}"; $initFor[ 'index' ] = "{$sectionVar}->value['index'] = {$propValue['start']}";
if (!isset($_attr[ 'start' ]) && !isset($_attr[ 'step' ]) && !isset($_attr[ 'max' ])) { if (!isset($_attr[ 'start' ]) && !isset($_attr[ 'step' ]) && !isset($_attr[ 'max' ])) {
$propValue[ 'total' ] = $propValue[ 'loop' ]; $propValue[ 'total' ] = $propValue[ 'loop' ];
$propType[ 'total' ] = $propType[ 'loop' ]; $propType[ 'total' ] = $propType[ 'loop' ];
@@ -302,13 +293,14 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
min( min(
ceil( ceil(
($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] - $propValue[ 'start' ] : ($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] - $propValue[ 'start' ] :
(int) $propValue[ 'start' ] + 1) / abs($propValue[ 'step' ]) (int)$propValue[ 'start' ] + 1) / abs($propValue[ 'step' ])
), $propValue[ 'max' ] ),
$propValue[ 'max' ]
); );
} else { } else {
$total_code = array(1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ", $total_code = array(1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ",
5 => $propValue[ 'loop' ], 6 => ' - ', 7 => $propValue[ 'start' ], 8 => ' : ', 5 => $propValue[ 'loop' ], 6 => ' - ', 7 => $propValue[ 'start' ], 8 => ' : ',
9 => $propValue[ 'start' ], 10 => '+ 1', 11 => ')', 12 => '/ ', 13 => 'abs(', 9 => $propValue[ 'start' ], 10 => '+ 1', 11 => ')', 12 => '/ ', 13 => 'abs(',
14 => $propValue[ 'step' ], 15 => ')', 16 => ')', 17 => ", {$propValue['max']})",); 14 => $propValue[ 'step' ], 15 => ')', 16 => ')', 17 => ", {$propValue['max']})",);
if (!isset($propValue[ 'max' ])) { if (!isset($propValue[ 'max' ])) {
$total_code[ 1 ] = $total_code[ 17 ] = ''; $total_code[ 1 ] = $total_code[ 17 ] = '';
@@ -318,15 +310,15 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$total_code[ 6 ] = $total_code[ 7 ] = ''; $total_code[ 6 ] = $total_code[ 7 ] = '';
} }
if ($propType[ 'start' ] === 0) { if ($propType[ 'start' ] === 0) {
$total_code[ 9 ] = (int) $propValue[ 'start' ] + 1; $total_code[ 9 ] = (int)$propValue[ 'start' ] + 1;
$total_code[ 10 ] = ''; $total_code[ 10 ] = '';
} }
if ($propType[ 'step' ] === 0) { if ($propType[ 'step' ] === 0) {
$total_code[ 13 ] = $total_code[ 15 ] = ''; $total_code[ 13 ] = $total_code[ 15 ] = '';
if ($propValue[ 'step' ] === 1 || $propValue[ 'step' ] === - 1) { if ($propValue[ 'step' ] === 1 || $propValue[ 'step' ] === -1) {
$total_code[ 2 ] = $total_code[ 12 ] = $total_code[ 14 ] = $total_code[ 16 ] = ''; $total_code[ 2 ] = $total_code[ 12 ] = $total_code[ 14 ] = $total_code[ 16 ] = '';
} elseif ($propValue[ 'step' ] < 0) { } elseif ($propValue[ 'step' ] < 0) {
$total_code[ 14 ] = - $propValue[ 'step' ]; $total_code[ 14 ] = -$propValue[ 'step' ];
} }
$total_code[ 4 ] = ''; $total_code[ 4 ] = '';
if ($propValue[ 'step' ] > 0) { if ($propValue[ 'step' ] > 0) {
@@ -338,7 +330,6 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$propValue[ 'total' ] = join('', $total_code); $propValue[ 'total' ] = join('', $total_code);
} }
} }
if (isset($namedAttr[ 'loop' ])) { if (isset($namedAttr[ 'loop' ])) {
$initNamedProperty[ 'loop' ] = "'loop' => {$propValue['loop']}"; $initNamedProperty[ 'loop' ] = "'loop' => {$propValue['loop']}";
} }
@@ -351,13 +342,10 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$initLocal[ 'total' ] = $propValue[ 'total' ]; $initLocal[ 'total' ] = $propValue[ 'total' ];
$propValue[ 'total' ] = "{$local}total"; $propValue[ 'total' ] = "{$local}total";
} }
$cmpFor[ 'iteration' ] = "{$propValue['iteration']} <= {$propValue['total']}"; $cmpFor[ 'iteration' ] = "{$propValue['iteration']} <= {$propValue['total']}";
foreach ($initLocal as $key => $code) { foreach ($initLocal as $key => $code) {
$output .= "{$local}{$key} = {$code};\n"; $output .= "{$local}{$key} = {$code};\n";
} }
$_vars = 'array(' . join(', ', $initNamedProperty) . ')'; $_vars = 'array(' . join(', ', $initNamedProperty) . ')';
$output .= "{$sectionVar} = new Smarty_Variable({$_vars});\n"; $output .= "{$sectionVar} = new Smarty_Variable({$_vars});\n";
$cond_code = "{$propValue['total']} !== 0"; $cond_code = "{$propValue['total']} !== 0";
@@ -396,7 +384,6 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} === {$propValue['total']});\n"; $output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} === {$propValue['total']});\n";
} }
$output .= '?>'; $output .= '?>';
return $output; return $output;
} }
} }
@@ -421,10 +408,8 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
list($openTag, $nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section')); list($openTag, $nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section'));
$this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache, $local, $sectionVar)); $this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache, $local, $sectionVar));
return "<?php }} else {\n ?>"; return "<?php }} else {\n ?>";
} }
} }
@@ -447,15 +432,13 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$compiler->loopNesting --; $compiler->loopNesting--;
// must endblock be nocache? // must endblock be nocache?
if ($compiler->nocache) { if ($compiler->nocache) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
list($openTag, $compiler->nocache, $local, $sectionVar) = list($openTag, $compiler->nocache, $local, $sectionVar) =
$this->closeTag($compiler, array('section', 'sectionelse')); $this->closeTag($compiler, array('section', 'sectionelse'));
$output = "<?php\n"; $output = "<?php\n";
if ($openTag === 'sectionelse') { if ($openTag === 'sectionelse') {
$output .= "}\n"; $output .= "}\n";
@@ -463,7 +446,6 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
$output .= "}\n}\n"; $output .= "}\n}\n";
} }
$output .= '?>'; $output .= '?>';
return $output; return $output;
} }
} }

View File

@@ -130,10 +130,10 @@ class Smarty_Internal_Configfilelexer
/** /**
* constructor * constructor
* *
* @param string $data template source * @param string $data template source
* @param Smarty_Internal_Config_File_Compiler $compiler * @param Smarty_Internal_Config_File_Compiler $compiler
*/ */
function __construct($data, Smarty_Internal_Config_File_Compiler $compiler) public function __construct($data, Smarty_Internal_Config_File_Compiler $compiler)
{ {
$this->data = $data . "\n"; //now all lines are \n-terminated $this->data = $data . "\n"; //now all lines are \n-terminated
$this->dataLength = strlen($data); $this->dataLength = strlen($data);
@@ -166,47 +166,35 @@ class Smarty_Internal_Configfilelexer
public function yypushstate($state) public function yypushstate($state)
{ {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%sState push %s\n",
"%sState push %s\n", $this->yyTracePrompt,
$this->yyTracePrompt, isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state
);
} }
array_push($this->_yy_stack, $this->_yy_state); array_push($this->_yy_stack, $this->_yy_state);
$this->_yy_state = $state; $this->_yy_state = $state;
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%snew State %s\n",
"%snew State %s\n", $this->yyTracePrompt,
$this->yyTracePrompt, isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state
);
} }
} }
public function yypopstate() public function yypopstate()
{ {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%sState pop %s\n",
"%sState pop %s\n", $this->yyTracePrompt,
$this->yyTracePrompt, isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state
);
} }
$this->_yy_state = array_pop($this->_yy_stack); $this->_yy_state = array_pop($this->_yy_stack);
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%snew State %s\n",
"%snew State %s\n", $this->yyTracePrompt,
$this->yyTracePrompt, isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state
);
} }
} }
@@ -214,13 +202,10 @@ class Smarty_Internal_Configfilelexer
{ {
$this->_yy_state = $state; $this->_yy_state = $state;
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%sState set %s\n",
"%sState set %s\n", $this->yyTracePrompt,
$this->yyTracePrompt, isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state
);
} }
} }
@@ -244,14 +229,10 @@ class Smarty_Internal_Configfilelexer
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception( throw new Exception('Error: lexing failed because a rule matched' .
'Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data,
' an empty string. Input "' . substr( $this->counter,
$this->data, 5) . '... state START');
$this->counter,
5
) . '... state START'
);
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -262,11 +243,11 @@ class Smarty_Internal_Configfilelexer
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
// accept this token // accept this token
return true; return true;
} else if ($r === true) { } elseif ($r === true) {
// we have changed state // we have changed state
// process this token in the new state // process this token in the new state
return $this->yylex(); return $this->yylex();
} else if ($r === false) { } elseif ($r === false) {
$this->counter += strlen($this->value); $this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
@@ -276,10 +257,8 @@ class Smarty_Internal_Configfilelexer
continue; continue;
} }
} else { } else {
throw new Exception( throw new Exception('Unexpected input at line' . $this->line .
'Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
': ' . $this->data[ $this->counter ]
);
} }
break; break;
} while (true); } while (true);
@@ -348,14 +327,10 @@ class Smarty_Internal_Configfilelexer
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception( throw new Exception('Error: lexing failed because a rule matched' .
'Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data,
' an empty string. Input "' . substr( $this->counter,
$this->data, 5) . '... state VALUE');
$this->counter,
5
) . '... state VALUE'
);
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -366,11 +341,11 @@ class Smarty_Internal_Configfilelexer
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
// accept this token // accept this token
return true; return true;
} else if ($r === true) { } elseif ($r === true) {
// we have changed state // we have changed state
// process this token in the new state // process this token in the new state
return $this->yylex(); return $this->yylex();
} else if ($r === false) { } elseif ($r === false) {
$this->counter += strlen($this->value); $this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
@@ -380,10 +355,8 @@ class Smarty_Internal_Configfilelexer
continue; continue;
} }
} else { } else {
throw new Exception( throw new Exception('Unexpected input at line' . $this->line .
'Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
': ' . $this->data[ $this->counter ]
);
} }
break; break;
} while (true); } while (true);
@@ -426,9 +399,8 @@ class Smarty_Internal_Configfilelexer
function yy_r2_7() function yy_r2_7()
{ {
if (!$this->configBooleanize if (!$this->configBooleanize ||
|| !in_array(strtolower($this->value), array('true', 'false', 'on', 'off', 'yes', 'no')) !in_array(strtolower($this->value), array('true', 'false', 'on', 'off', 'yes', 'no'))) {
) {
$this->yypopstate(); $this->yypopstate();
$this->yypushstate(self::NAKED_STRING_VALUE); $this->yypushstate(self::NAKED_STRING_VALUE);
return true; //reprocess in new state return true; //reprocess in new state
@@ -470,14 +442,10 @@ class Smarty_Internal_Configfilelexer
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception( throw new Exception('Error: lexing failed because a rule matched' .
'Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data,
' an empty string. Input "' . substr( $this->counter,
$this->data, 5) . '... state NAKED_STRING_VALUE');
$this->counter,
5
) . '... state NAKED_STRING_VALUE'
);
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -488,11 +456,11 @@ class Smarty_Internal_Configfilelexer
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
// accept this token // accept this token
return true; return true;
} else if ($r === true) { } elseif ($r === true) {
// we have changed state // we have changed state
// process this token in the new state // process this token in the new state
return $this->yylex(); return $this->yylex();
} else if ($r === false) { } elseif ($r === false) {
$this->counter += strlen($this->value); $this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
@@ -502,10 +470,8 @@ class Smarty_Internal_Configfilelexer
continue; continue;
} }
} else { } else {
throw new Exception( throw new Exception('Unexpected input at line' . $this->line .
'Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
': ' . $this->data[ $this->counter ]
);
} }
break; break;
} while (true); } while (true);
@@ -536,14 +502,10 @@ class Smarty_Internal_Configfilelexer
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception( throw new Exception('Error: lexing failed because a rule matched' .
'Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data,
' an empty string. Input "' . substr( $this->counter,
$this->data, 5) . '... state COMMENT');
$this->counter,
5
) . '... state COMMENT'
);
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -554,11 +516,11 @@ class Smarty_Internal_Configfilelexer
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
// accept this token // accept this token
return true; return true;
} else if ($r === true) { } elseif ($r === true) {
// we have changed state // we have changed state
// process this token in the new state // process this token in the new state
return $this->yylex(); return $this->yylex();
} else if ($r === false) { } elseif ($r === false) {
$this->counter += strlen($this->value); $this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
@@ -568,10 +530,8 @@ class Smarty_Internal_Configfilelexer
continue; continue;
} }
} else { } else {
throw new Exception( throw new Exception('Unexpected input at line' . $this->line .
'Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
': ' . $this->data[ $this->counter ]
);
} }
break; break;
} while (true); } while (true);
@@ -612,14 +572,10 @@ class Smarty_Internal_Configfilelexer
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception( throw new Exception('Error: lexing failed because a rule matched' .
'Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data,
' an empty string. Input "' . substr( $this->counter,
$this->data, 5) . '... state SECTION');
$this->counter,
5
) . '... state SECTION'
);
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -630,11 +586,11 @@ class Smarty_Internal_Configfilelexer
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
// accept this token // accept this token
return true; return true;
} else if ($r === true) { } elseif ($r === true) {
// we have changed state // we have changed state
// process this token in the new state // process this token in the new state
return $this->yylex(); return $this->yylex();
} else if ($r === false) { } elseif ($r === false) {
$this->counter += strlen($this->value); $this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
@@ -644,10 +600,8 @@ class Smarty_Internal_Configfilelexer
continue; continue;
} }
} else { } else {
throw new Exception( throw new Exception('Unexpected input at line' . $this->line .
'Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
': ' . $this->data[ $this->counter ]
);
} }
break; break;
} while (true); } while (true);
@@ -683,14 +637,10 @@ class Smarty_Internal_Configfilelexer
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception( throw new Exception('Error: lexing failed because a rule matched' .
'Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data,
' an empty string. Input "' . substr( $this->counter,
$this->data, 5) . '... state TRIPPLE');
$this->counter,
5
) . '... state TRIPPLE'
);
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -701,11 +651,11 @@ class Smarty_Internal_Configfilelexer
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
// accept this token // accept this token
return true; return true;
} else if ($r === true) { } elseif ($r === true) {
// we have changed state // we have changed state
// process this token in the new state // process this token in the new state
return $this->yylex(); return $this->yylex();
} else if ($r === false) { } elseif ($r === false) {
$this->counter += strlen($this->value); $this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
@@ -715,10 +665,8 @@ class Smarty_Internal_Configfilelexer
continue; continue;
} }
} else { } else {
throw new Exception( throw new Exception('Unexpected input at line' . $this->line .
'Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
': ' . $this->data[ $this->counter ]
);
} }
break; break;
} while (true); } while (true);

View File

@@ -48,7 +48,7 @@ class Smarty_Internal_Configfileparser
const YY_SZ_ACTTAB = 38; const YY_SZ_ACTTAB = 38;
const YY_SHIFT_USE_DFLT = -8; const YY_SHIFT_USE_DFLT = -8;
const YY_SHIFT_MAX = 19; const YY_SHIFT_MAX = 19;
const YY_REDUCE_USE_DFLT = -21; const YY_REDUCE_USE_DFLT = -17;
const YY_REDUCE_MAX = 10; const YY_REDUCE_MAX = 10;
const YYNOCODE = 29; const YYNOCODE = 29;
const YYSTACKDEPTH = 100; const YYSTACKDEPTH = 100;
@@ -58,24 +58,24 @@ class Smarty_Internal_Configfileparser
const YYERRSYMDT = 'yy0'; const YYERRSYMDT = 'yy0';
const YYFALLBACK = 0; const YYFALLBACK = 0;
static public $yy_action = array( static public $yy_action = array(
29, 30, 34, 33, 24, 13, 19, 25, 35, 21, 32, 31, 30, 29, 35, 13, 19, 3, 24, 26,
59, 8, 3, 1, 20, 12, 14, 31, 20, 12, 59, 9, 14, 1, 16, 25, 11, 28, 25, 11,
15, 17, 23, 18, 27, 26, 4, 5, 6, 32, 17, 27, 34, 20, 18, 15, 23, 5, 6, 22,
2, 11, 28, 22, 16, 9, 7, 10, 10, 8, 4, 12, 2, 33, 7, 21,
); );
static public $yy_lookahead = array( static public $yy_lookahead = array(
7, 8, 9, 10, 11, 12, 5, 27, 15, 16, 7, 8, 9, 10, 11, 12, 5, 23, 15, 16,
20, 21, 23, 23, 17, 18, 13, 14, 17, 18, 20, 21, 2, 23, 4, 17, 18, 14, 17, 18,
15, 2, 17, 4, 25, 26, 6, 3, 3, 14, 13, 14, 25, 26, 15, 2, 17, 3, 3, 17,
23, 1, 24, 17, 2, 25, 22, 25, 25, 25, 6, 1, 23, 27, 22, 24,
); );
static public $yy_shift_ofst = array( static public $yy_shift_ofst = array(
-8, 1, 1, 1, -7, -3, -3, 30, -8, -8, -8, 1, 1, 1, -7, -2, -2, 32, -8, -8,
-8, 19, 5, 3, 15, 16, 24, 25, 32, 20, -8, 9, 10, 7, 25, 24, 23, 3, 12, 26,
); );
static public $yy_reduce_ofst = array( static public $yy_reduce_ofst = array(
-10, -1, -1, -1, -20, 10, 12, 8, 14, 7, -10, -3, -3, -3, 8, 6, 5, 13, 11, 14,
-11, -16,
); );
static public $yyExpectedTokens = array( static public $yyExpectedTokens = array(
array(), array(),
@@ -89,14 +89,14 @@ class Smarty_Internal_Configfileparser
array(), array(),
array(), array(),
array(), array(),
array(2, 4,),
array(15, 17,), array(15, 17,),
array(2, 4,),
array(13, 14,), array(13, 14,),
array(14,),
array(17,),
array(3,), array(3,),
array(3,), array(3,),
array(2,), array(2,),
array(14,),
array(17,),
array(6,), array(6,),
array(), array(),
array(), array(),
@@ -116,10 +116,10 @@ class Smarty_Internal_Configfileparser
array(), array(),
); );
static public $yy_default = array( static public $yy_default = array(
44, 37, 41, 40, 58, 58, 58, 36, 39, 44, 44, 37, 41, 40, 58, 58, 58, 36, 44, 39,
44, 58, 58, 58, 58, 58, 58, 58, 58, 58, 44, 58, 58, 58, 58, 58, 58, 58, 58, 58,
55, 54, 57, 56, 50, 45, 43, 42, 38, 46, 43, 38, 57, 56, 53, 55, 54, 52, 51, 49,
47, 52, 51, 49, 48, 53, 48, 47, 46, 45, 42, 50,
); );
public static $yyFallback = array(); public static $yyFallback = array();
public static $yyRuleName = array( public static $yyRuleName = array(
@@ -275,7 +275,7 @@ class Smarty_Internal_Configfileparser
* @param Smarty_Internal_Configfilelexer $lex * @param Smarty_Internal_Configfilelexer $lex
* @param Smarty_Internal_Config_File_Compiler $compiler * @param Smarty_Internal_Config_File_Compiler $compiler
*/ */
function __construct(Smarty_Internal_Configfilelexer $lex, Smarty_Internal_Config_File_Compiler $compiler) public function __construct(Smarty_Internal_Configfilelexer $lex, Smarty_Internal_Config_File_Compiler $compiler)
{ {
$this->lex = $lex; $this->lex = $lex;
$this->smarty = $compiler->smarty; $this->smarty = $compiler->smarty;
@@ -287,8 +287,8 @@ class Smarty_Internal_Configfileparser
public static function yy_destructor($yymajor, $yypminor) public static function yy_destructor($yymajor, $yypminor)
{ {
switch ($yymajor) { switch ($yymajor) {
default: default:
break; /* If no destructor action specified: do nothing */ break; /* If no destructor action specified: do nothing */
} }
} }
@@ -343,7 +343,7 @@ class Smarty_Internal_Configfileparser
{ {
if (!$TraceFILE) { if (!$TraceFILE) {
$zTracePrompt = 0; $zTracePrompt = 0;
} else if (!$zTracePrompt) { } elseif (!$zTracePrompt) {
$TraceFILE = 0; $TraceFILE = 0;
} }
$this->yyTraceFILE = $TraceFILE; $this->yyTraceFILE = $TraceFILE;
@@ -375,11 +375,9 @@ class Smarty_Internal_Configfileparser
} }
$yytos = array_pop($this->yystack); $yytos = array_pop($this->yystack);
if ($this->yyTraceFILE && $this->yyidx >= 0) { if ($this->yyTraceFILE && $this->yyidx >= 0) {
fwrite( fwrite($this->yyTraceFILE,
$this->yyTraceFILE, $this->yyTracePrompt . 'Popping ' . $this->yyTokenName[ $yytos->major ] .
$this->yyTracePrompt . 'Popping ' . $this->yyTokenName[ $yytos->major ] . "\n");
"\n"
);
} }
$yymajor = $yytos->major; $yymajor = $yytos->major;
self::yy_destructor($yymajor, $yytos->minor); self::yy_destructor($yymajor, $yytos->minor);
@@ -431,8 +429,7 @@ class Smarty_Internal_Configfileparser
$this->yyidx -= self::$yyRuleInfo[ $yyruleno ][ 1 ]; $this->yyidx -= self::$yyRuleInfo[ $yyruleno ][ 1 ];
$nextstate = $this->yy_find_reduce_action( $nextstate = $this->yy_find_reduce_action(
$this->yystack[ $this->yyidx ]->stateno, $this->yystack[ $this->yyidx ]->stateno,
self::$yyRuleInfo[ $yyruleno ][ 0 ] self::$yyRuleInfo[ $yyruleno ][ 0 ]);
);
if (isset(self::$yyExpectedTokens[ $nextstate ])) { if (isset(self::$yyExpectedTokens[ $nextstate ])) {
$expected = array_merge($expected, self::$yyExpectedTokens[ $nextstate ]); $expected = array_merge($expected, self::$yyExpectedTokens[ $nextstate ]);
if (isset($res4[ $nextstate ][ $token ])) { if (isset($res4[ $nextstate ][ $token ])) {
@@ -442,8 +439,8 @@ class Smarty_Internal_Configfileparser
return array_unique($expected); return array_unique($expected);
} }
} else { } else {
if ($res4[ $nextstate ][ $token ] = in_array($token, self::$yyExpectedTokens[ $nextstate ], true) if ($res4[ $nextstate ][ $token ] =
) { in_array($token, self::$yyExpectedTokens[ $nextstate ], true)) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
return array_unique($expected); return array_unique($expected);
@@ -458,14 +455,14 @@ class Smarty_Internal_Configfileparser
$x->major = self::$yyRuleInfo[ $yyruleno ][ 0 ]; $x->major = self::$yyRuleInfo[ $yyruleno ][ 0 ];
$this->yystack[ $this->yyidx ] = $x; $this->yystack[ $this->yyidx ] = $x;
continue 2; continue 2;
} else if ($nextstate === self::YYNSTATE + self::YYNRULE + 1) { } elseif ($nextstate === self::YYNSTATE + self::YYNRULE + 1) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
// the last token was just ignored, we can't accept // the last token was just ignored, we can't accept
// by ignoring input, this is in essence ignoring a // by ignoring input, this is in essence ignoring a
// syntax error! // syntax error!
return array_unique($expected); return array_unique($expected);
} else if ($nextstate === self::YY_NO_ACTION) { } elseif ($nextstate === self::YY_NO_ACTION) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
// input accepted, but not shifted (I guess) // input accepted, but not shifted (I guess)
@@ -518,8 +515,7 @@ class Smarty_Internal_Configfileparser
$this->yyidx -= self::$yyRuleInfo[ $yyruleno ][ 1 ]; $this->yyidx -= self::$yyRuleInfo[ $yyruleno ][ 1 ];
$nextstate = $this->yy_find_reduce_action( $nextstate = $this->yy_find_reduce_action(
$this->yystack[ $this->yyidx ]->stateno, $this->yystack[ $this->yyidx ]->stateno,
self::$yyRuleInfo[ $yyruleno ][ 0 ] self::$yyRuleInfo[ $yyruleno ][ 0 ]);
);
if (isset($res2[ $nextstate ][ $token ])) { if (isset($res2[ $nextstate ][ $token ])) {
if ($res2[ $nextstate ][ $token ]) { if ($res2[ $nextstate ][ $token ]) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
@@ -527,13 +523,9 @@ class Smarty_Internal_Configfileparser
return true; return true;
} }
} else { } else {
if ($res2[ $nextstate ][ $token ] = (isset(self::$yyExpectedTokens[ $nextstate ]) if ($res2[ $nextstate ][ $token ] =
&& in_array( (isset(self::$yyExpectedTokens[ $nextstate ]) &&
$token, in_array($token, self::$yyExpectedTokens[ $nextstate ], true))) {
self::$yyExpectedTokens[ $nextstate ],
true
))
) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
return true; return true;
@@ -547,7 +539,7 @@ class Smarty_Internal_Configfileparser
$x->major = self::$yyRuleInfo[ $yyruleno ][ 0 ]; $x->major = self::$yyRuleInfo[ $yyruleno ][ 0 ];
$this->yystack[ $this->yyidx ] = $x; $this->yystack[ $this->yyidx ] = $x;
continue 2; continue 2;
} else if ($nextstate === self::YYNSTATE + self::YYNRULE + 1) { } elseif ($nextstate === self::YYNSTATE + self::YYNRULE + 1) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
if (!$token) { if (!$token) {
@@ -558,7 +550,7 @@ class Smarty_Internal_Configfileparser
// by ignoring input, this is in essence ignoring a // by ignoring input, this is in essence ignoring a
// syntax error! // syntax error!
return false; return false;
} else if ($nextstate === self::YY_NO_ACTION) { } elseif ($nextstate === self::YY_NO_ACTION) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
// input accepted, but not shifted (I guess) // input accepted, but not shifted (I guess)
@@ -591,19 +583,15 @@ class Smarty_Internal_Configfileparser
return self::YY_NO_ACTION; return self::YY_NO_ACTION;
} }
$i += $iLookAhead; $i += $iLookAhead;
if ($i < 0 || $i >= self::YY_SZ_ACTTAB if ($i < 0 || $i >= self::YY_SZ_ACTTAB ||
|| self::$yy_lookahead[ $i ] != $iLookAhead self::$yy_lookahead[ $i ] != $iLookAhead) {
) {
if (count(self::$yyFallback) && $iLookAhead < count(self::$yyFallback) if (count(self::$yyFallback) && $iLookAhead < count(self::$yyFallback)
&& ($iFallback = self::$yyFallback[ $iLookAhead ]) != 0 && ($iFallback = self::$yyFallback[ $iLookAhead ]) != 0) {
) {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fwrite( fwrite($this->yyTraceFILE,
$this->yyTraceFILE, $this->yyTracePrompt . 'FALLBACK ' .
$this->yyTracePrompt . 'FALLBACK ' .
$this->yyTokenName[ $iLookAhead ] . ' => ' . $this->yyTokenName[ $iLookAhead ] . ' => ' .
$this->yyTokenName[ $iFallback ] . "\n" $this->yyTokenName[ $iFallback ] . "\n");
);
} }
return $this->yy_find_shift_action($iFallback); return $this->yy_find_shift_action($iFallback);
} }
@@ -627,9 +615,8 @@ class Smarty_Internal_Configfileparser
return self::YY_NO_ACTION; return self::YY_NO_ACTION;
} }
$i += $iLookAhead; $i += $iLookAhead;
if ($i < 0 || $i >= self::YY_SZ_ACTTAB if ($i < 0 || $i >= self::YY_SZ_ACTTAB ||
|| self::$yy_lookahead[ $i ] != $iLookAhead self::$yy_lookahead[ $i ] != $iLookAhead) {
) {
return self::$yy_default[ $stateno ]; return self::$yy_default[ $stateno ];
} else { } else {
return self::$yy_action[ $i ]; return self::$yy_action[ $i ];
@@ -658,19 +645,15 @@ class Smarty_Internal_Configfileparser
$yytos->minor = $yypMinor; $yytos->minor = $yypMinor;
$this->yystack[] = $yytos; $this->yystack[] = $yytos;
if ($this->yyTraceFILE && $this->yyidx > 0) { if ($this->yyTraceFILE && $this->yyidx > 0) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%sShift %d\n",
"%sShift %d\n", $this->yyTracePrompt,
$this->yyTracePrompt, $yyNewState);
$yyNewState
);
fprintf($this->yyTraceFILE, "%sStack:", $this->yyTracePrompt); fprintf($this->yyTraceFILE, "%sStack:", $this->yyTracePrompt);
for ($i = 1; $i <= $this->yyidx; $i++) { for ($i = 1; $i <= $this->yyidx; $i++) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, " %s",
" %s", $this->yyTokenName[ $this->yystack[ $i ]->major ]);
$this->yyTokenName[ $this->yystack[ $i ]->major ]
);
} }
fwrite($this->yyTraceFILE, "\n"); fwrite($this->yyTraceFILE, "\n");
} }
@@ -697,10 +680,8 @@ class Smarty_Internal_Configfileparser
function yy_r5() function yy_r5()
{ {
if ($this->configReadHidden) { if ($this->configReadHidden) {
$this->add_section_vars( $this->add_section_vars($this->yystack[ $this->yyidx + -3 ]->minor,
$this->yystack[ $this->yyidx + -3 ]->minor, $this->yystack[ $this->yyidx + 0 ]->minor);
$this->yystack[ $this->yyidx + 0 ]->minor
);
} }
$this->_retvalue = null; $this->_retvalue = null;
} }
@@ -727,8 +708,9 @@ class Smarty_Internal_Configfileparser
// line 277 "../smarty/lexer/smarty_internal_configfileparser.y" // line 277 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r9() function yy_r9()
{ {
$this->_retvalue = array('key' => $this->yystack[ $this->yyidx + -2 ]->minor, $this->_retvalue =
'value' => $this->yystack[ $this->yyidx + 0 ]->minor); array('key' => $this->yystack[ $this->yyidx + -2 ]->minor,
'value' => $this->yystack[ $this->yyidx + 0 ]->minor);
} }
// line 281 "../smarty/lexer/smarty_internal_configfileparser.y" // line 281 "../smarty/lexer/smarty_internal_configfileparser.y"
@@ -783,15 +765,12 @@ class Smarty_Internal_Configfileparser
public function yy_reduce($yyruleno) public function yy_reduce($yyruleno)
{ {
if ($this->yyTraceFILE && $yyruleno >= 0 if ($this->yyTraceFILE && $yyruleno >= 0
&& $yyruleno < count(self::$yyRuleName) && $yyruleno < count(self::$yyRuleName)) {
) { fprintf($this->yyTraceFILE,
fprintf( "%sReduce (%d) [%s].\n",
$this->yyTraceFILE, $this->yyTracePrompt,
"%sReduce (%d) [%s].\n", $yyruleno,
$this->yyTracePrompt, self::$yyRuleName[ $yyruleno ]);
$yyruleno,
self::$yyRuleName[ $yyruleno ]
);
} }
$this->_retvalue = $yy_lefthand_side = null; $this->_retvalue = $yy_lefthand_side = null;
if (isset(self::$yyReduceMap[ $yyruleno ])) { if (isset(self::$yyReduceMap[ $yyruleno ])) {
@@ -819,7 +798,7 @@ class Smarty_Internal_Configfileparser
} else { } else {
$this->yy_shift($yyact, $yygoto, $yy_lefthand_side); $this->yy_shift($yyact, $yygoto, $yy_lefthand_side);
} }
} else if ($yyact === self::YYNSTATE + self::YYNRULE + 1) { } elseif ($yyact === self::YYNSTATE + self::YYNRULE + 1) {
$this->yy_accept(); $this->yy_accept();
} }
} }
@@ -872,18 +851,15 @@ class Smarty_Internal_Configfileparser
} }
$yyendofinput = ($yymajor == 0); $yyendofinput = ($yymajor == 0);
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%sInput %s\n",
"%sInput %s\n", $this->yyTracePrompt,
$this->yyTracePrompt, $this->yyTokenName[ $yymajor ]);
$this->yyTokenName[ $yymajor ]
);
} }
do { do {
$yyact = $this->yy_find_shift_action($yymajor); $yyact = $this->yy_find_shift_action($yymajor);
if ($yymajor < self::YYERRORSYMBOL if ($yymajor < self::YYERRORSYMBOL &&
&& !$this->yy_is_expected_token($yymajor) !$this->yy_is_expected_token($yymajor)) {
) {
// force a syntax error // force a syntax error
$yyact = self::YY_ERROR_ACTION; $yyact = self::YY_ERROR_ACTION;
} }
@@ -895,15 +871,13 @@ class Smarty_Internal_Configfileparser
} else { } else {
$yymajor = self::YYNOCODE; $yymajor = self::YYNOCODE;
} }
} else if ($yyact < self::YYNSTATE + self::YYNRULE) { } elseif ($yyact < self::YYNSTATE + self::YYNRULE) {
$this->yy_reduce($yyact - self::YYNSTATE); $this->yy_reduce($yyact - self::YYNSTATE);
} else if ($yyact === self::YY_ERROR_ACTION) { } elseif ($yyact === self::YY_ERROR_ACTION) {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%sSyntax Error!\n",
"%sSyntax Error!\n", $this->yyTracePrompt);
$this->yyTracePrompt
);
} }
if (self::YYERRORSYMBOL) { if (self::YYERRORSYMBOL) {
if ($this->yyerrcnt < 0) { if ($this->yyerrcnt < 0) {
@@ -912,12 +886,10 @@ class Smarty_Internal_Configfileparser
$yymx = $this->yystack[ $this->yyidx ]->major; $yymx = $this->yystack[ $this->yyidx ]->major;
if ($yymx === self::YYERRORSYMBOL || $yyerrorhit) { if ($yymx === self::YYERRORSYMBOL || $yyerrorhit) {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%sDiscard input token %s\n",
"%sDiscard input token %s\n", $this->yyTracePrompt,
$this->yyTracePrompt, $this->yyTokenName[ $yymajor ]);
$this->yyTokenName[ $yymajor ]
);
} }
$this->yy_destructor($yymajor, $yytokenvalue); $this->yy_destructor($yymajor, $yytokenvalue);
$yymajor = self::YYNOCODE; $yymajor = self::YYNOCODE;
@@ -932,7 +904,7 @@ class Smarty_Internal_Configfileparser
$this->yy_destructor($yymajor, $yytokenvalue); $this->yy_destructor($yymajor, $yytokenvalue);
$this->yy_parse_failed(); $this->yy_parse_failed();
$yymajor = self::YYNOCODE; $yymajor = self::YYNOCODE;
} else if ($yymx !== self::YYERRORSYMBOL) { } elseif ($yymx !== self::YYERRORSYMBOL) {
$u2 = 0; $u2 = 0;
$this->yy_shift($yyact, self::YYERRORSYMBOL, $u2); $this->yy_shift($yyact, self::YYERRORSYMBOL, $u2);
} }

View File

@@ -104,10 +104,10 @@ abstract class Smarty_Internal_Data
if ($tpl_var !== '') { if ($tpl_var !== '') {
if ($this->_objType === 2) { if ($this->_objType === 2) {
/** /**
*
* *
* @var Smarty_Internal_Template $this *
*/ * @var Smarty_Internal_Template $this
*/
$this->_assignInScope($tpl_var, $value, $nocache); $this->_assignInScope($tpl_var, $value, $nocache);
} else { } else {
$this->tpl_vars[ $tpl_var ] = new Smarty_Variable($value, $nocache); $this->tpl_vars[ $tpl_var ] = new Smarty_Variable($value, $nocache);
@@ -168,7 +168,7 @@ abstract class Smarty_Internal_Data
* assigns values to template variables by reference * assigns values to template variables by reference
* *
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name
* @param $value * @param $value
* @param boolean $nocache if true any output of this variable will be not cached * @param boolean $nocache if true any output of this variable will be not cached
* *
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
@@ -206,9 +206,12 @@ abstract class Smarty_Internal_Data
* @return Smarty_Variable|Smarty_Undefined_Variable the object of the variable * @return Smarty_Variable|Smarty_Undefined_Variable the object of the variable
* @deprecated since 3.1.28 please use Smarty_Internal_Data::getTemplateVars() instead. * @deprecated since 3.1.28 please use Smarty_Internal_Data::getTemplateVars() instead.
*/ */
public function getVariable($variable = null, Smarty_Internal_Data $_ptr = null, $searchParents = true, public function getVariable($variable = null,
$error_enable = true Smarty_Internal_Data $_ptr = null,
) { $searchParents = true,
$error_enable = true
)
{
return $this->ext->getTemplateVars->_getVariable($this, $variable, $_ptr, $searchParents, $error_enable); return $this->ext->getTemplateVars->_getVariable($this, $variable, $_ptr, $searchParents, $error_enable);
} }
@@ -281,7 +284,6 @@ abstract class Smarty_Internal_Data
* @param array $args argument array * @param array $args argument array
* *
* @return mixed * @return mixed
* @throws SmartyException
*/ */
public function __call($name, $args) public function __call($name, $args)
{ {

View File

@@ -211,7 +211,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
// copy the working dirs from application // copy the working dirs from application
$debObj->setCompileDir($smarty->getCompileDir()); $debObj->setCompileDir($smarty->getCompileDir());
// init properties by hand as user may have edited the original Smarty class // init properties by hand as user may have edited the original Smarty class
$debObj->setPluginsDir(is_dir(__DIR__ . '/../plugins') ? __DIR__ . '/../plugins' : $smarty->getPluginsDir()); $debObj->setPluginsDir(is_dir(dirname(__FILE__) . '/../plugins') ? dirname(__FILE__) . '/../plugins' : $smarty->getPluginsDir());
$debObj->force_compile = false; $debObj->force_compile = false;
$debObj->compile_check = Smarty::COMPILECHECK_ON; $debObj->compile_check = Smarty::COMPILECHECK_ON;
$debObj->left_delimiter = '{'; $debObj->left_delimiter = '{';
@@ -220,7 +220,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$debObj->debugging = false; $debObj->debugging = false;
$debObj->debugging_ctrl = 'NONE'; $debObj->debugging_ctrl = 'NONE';
$debObj->error_reporting = E_ALL & ~E_NOTICE; $debObj->error_reporting = E_ALL & ~E_NOTICE;
$debObj->debug_tpl = isset($smarty->debug_tpl) ? $smarty->debug_tpl : 'file:' . __DIR__ . '/../debug.tpl'; $debObj->debug_tpl = isset($smarty->debug_tpl) ? $smarty->debug_tpl : 'file:' . dirname(__FILE__) . '/../debug.tpl';
$debObj->registered_plugins = array(); $debObj->registered_plugins = array();
$debObj->registered_resources = array(); $debObj->registered_resources = array();
$debObj->registered_filters = array(); $debObj->registered_filters = array();

View File

@@ -24,7 +24,6 @@ class Smarty_Internal_ErrorHandler
/** /**
* Enable error handler to mute expected messages * Enable error handler to mute expected messages
* *
* @return boolean
*/ */
public static function muteExpectedErrors() public static function muteExpectedErrors()
{ {

View File

@@ -61,7 +61,6 @@ class Smarty_Internal_Extension_Handler
* @param array $args argument array * @param array $args argument array
* *
* @return mixed * @return mixed
* @throws SmartyException
*/ */
public function _callExternalMethod(Smarty_Internal_Data $data, $name, $args) public function _callExternalMethod(Smarty_Internal_Data $data, $name, $args)
{ {
@@ -106,7 +105,7 @@ class Smarty_Internal_Extension_Handler
if ($property !== false) { if ($property !== false) {
if (property_exists($data, $property)) { if (property_exists($data, $property)) {
$propertyType = $this->resolvedProperties[ $match[0] ][ $objType ] = 1; $propertyType = $this->resolvedProperties[ $match[0] ][ $objType ] = 1;
} else if (property_exists($smarty, $property)) { } elseif (property_exists($smarty, $property)) {
$propertyType = $this->resolvedProperties[ $match[0] ][ $objType ] = 2; $propertyType = $this->resolvedProperties[ $match[0] ][ $objType ] = 2;
} else { } else {
$this->resolvedProperties['property'][ $basename ] = $property = false; $this->resolvedProperties['property'][ $basename ] = $property = false;
@@ -120,7 +119,7 @@ class Smarty_Internal_Extension_Handler
$obj = $propertyType === 1 ? $data : $smarty; $obj = $propertyType === 1 ? $data : $smarty;
if ($match[2] === 'get') { if ($match[2] === 'get') {
return $obj->$property; return $obj->$property;
} else if ($match[2] === 'set') { } elseif ($match[2] === 'set') {
return $obj->$property = $args[0]; return $obj->$property = $args[0];
} }
} }
@@ -156,7 +155,6 @@ class Smarty_Internal_Extension_Handler
* @param string $property_name property name * @param string $property_name property name
* *
* @return mixed|Smarty_Template_Cached * @return mixed|Smarty_Template_Cached
* @throws SmartyException
*/ */
public function __get($property_name) public function __get($property_name)
{ {
@@ -178,7 +176,6 @@ class Smarty_Internal_Extension_Handler
* @param string $property_name property name * @param string $property_name property name
* @param mixed $value value * @param mixed $value value
* *
* @throws SmartyException
*/ */
public function __set($property_name, $value) public function __set($property_name, $value)
{ {
@@ -192,7 +189,6 @@ class Smarty_Internal_Extension_Handler
* @param array $args argument array * @param array $args argument array
* *
* @return mixed * @return mixed
* @throws SmartyException
*/ */
public function __call($name, $args) public function __call($name, $args)
{ {

View File

@@ -119,7 +119,7 @@ class Smarty_Internal_Method_ClearCompiledTemplate
&& (!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api')) < 1) && (!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api')) < 1)
) { ) {
opcache_invalidate($_filepath, true); opcache_invalidate($_filepath, true);
} else if (function_exists('apc_delete_file')) { } elseif (function_exists('apc_delete_file')) {
apc_delete_file($_filepath); apc_delete_file($_filepath);
} }
} }

View File

@@ -52,7 +52,6 @@ class Smarty_Internal_Method_ConfigLoad
* @param int $scope scope into which config variables * @param int $scope scope into which config variables
* shall be loaded * shall be loaded
* *
* @return \Smarty|\Smarty_Internal_Data|\Smarty_Internal_Template
* @throws \Exception * @throws \Exception
*/ */
public function _loadConfigFile(Smarty_Internal_Data $data, $config_file, $sections = null, $scope = 0) public function _loadConfigFile(Smarty_Internal_Data $data, $config_file, $sections = null, $scope = 0)

View File

@@ -29,7 +29,7 @@ class Smarty_Internal_Method_CreateData
* variables * variables
* @param string $name optional data block name * @param string $name optional data block name
* *
* @returns Smarty_Data data object * @return \Smarty_Data data object
*/ */
public function createData(Smarty_Internal_TemplateBase $obj, Smarty_Internal_Data $parent = null, $name = null) public function createData(Smarty_Internal_TemplateBase $obj, Smarty_Internal_Data $parent = null, $name = null)
{ {

View File

@@ -26,7 +26,6 @@ class Smarty_Internal_Resource_Stream extends Smarty_Resource_Recompiled
* @param Smarty_Internal_Template $_template template object * @param Smarty_Internal_Template $_template template object
* *
* @return void * @return void
* @throws \SmartyException
*/ */
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{ {
@@ -46,7 +45,6 @@ class Smarty_Internal_Resource_Stream extends Smarty_Resource_Recompiled
* @param Smarty_Template_Source $source source object * @param Smarty_Template_Source $source source object
* *
* @return string template source * @return string template source
* @throws SmartyException if source cannot be loaded
*/ */
public function getContent(Smarty_Template_Source $source) public function getContent(Smarty_Template_Source $source)
{ {

View File

@@ -26,43 +26,41 @@ class Smarty_Internal_Runtime_CacheModify
@substr($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ], 0, strpos($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ], 'GMT') + 3); @substr($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ], 0, strpos($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ], 'GMT') + 3);
if ($_isCached && $cached->timestamp <= strtotime($_last_modified_date)) { if ($_isCached && $cached->timestamp <= strtotime($_last_modified_date)) {
switch (PHP_SAPI) { switch (PHP_SAPI) {
case 'cgi': // php-cgi < 5.3 case 'cgi': // php-cgi < 5.3
case 'cgi-fcgi': // php-cgi >= 5.3 case 'cgi-fcgi': // php-cgi >= 5.3
case 'fpm-fcgi': // php-fpm >= 5.3.3 case 'fpm-fcgi': // php-fpm >= 5.3.3
header('Status: 304 Not Modified'); header('Status: 304 Not Modified');
break; break;
case 'cli':
case 'cli': if (/* ^phpunit */
if (/* ^phpunit */
!empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */ !empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */
) { ) {
$_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] = '304 Not Modified'; $_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] = '304 Not Modified';
} }
break; break;
default:
default: if (/* ^phpunit */
if (/* ^phpunit */
!empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */ !empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */
) { ) {
$_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] = '304 Not Modified'; $_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] = '304 Not Modified';
} else { } else {
header($_SERVER[ 'SERVER_PROTOCOL' ] . ' 304 Not Modified'); header($_SERVER[ 'SERVER_PROTOCOL' ] . ' 304 Not Modified');
} }
break; break;
} }
} else { } else {
switch (PHP_SAPI) { switch (PHP_SAPI) {
case 'cli': case 'cli':
if (/* ^phpunit */ if (/* ^phpunit */
!empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */ !empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */
) { ) {
$_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] = $_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] =
'Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT'; 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT';
} }
break; break;
default: default:
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT');
break; break;
} }
echo $content; echo $content;
} }

View File

@@ -126,7 +126,7 @@ class Smarty_Internal_Runtime_CacheResourceFile
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1) && (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
) { ) {
opcache_invalidate($_filepath, true); opcache_invalidate($_filepath, true);
} else if (function_exists('apc_delete_file')) { } elseif (function_exists('apc_delete_file')) {
apc_delete_file($_filepath); apc_delete_file($_filepath);
} }
} }

View File

@@ -26,6 +26,29 @@
*/ */
class Smarty_Internal_Template extends Smarty_Internal_TemplateBase class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
{ {
/**
* Template object cache
*
* @var Smarty_Internal_Template[]
*/
public static $tplObjCache = array();
/**
* Template object cache for Smarty::isCached() === true
*
* @var Smarty_Internal_Template[]
*/
public static $isCacheTplObj = array();
/**
* Sub template Info Cache
* - index name
* - value use count
*
* @var int[]
*/
public static $subTplInfo = array();
/** /**
* This object type (Smarty = 1, template = 2, data = 4) * This object type (Smarty = 1, template = 2, data = 4)
* *
@@ -103,29 +126,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
*/ */
public $endRenderCallbacks = array(); public $endRenderCallbacks = array();
/**
* Template object cache
*
* @var Smarty_Internal_Template[]
*/
public static $tplObjCache = array();
/**
* Template object cache for Smarty::isCached() === true
*
* @var Smarty_Internal_Template[]
*/
public static $isCacheTplObj = array();
/**
* Sub template Info Cache
* - index name
* - value use count
*
* @var int[]
*/
public static $subTplInfo = array();
/** /**
* Create template data object * Create template data object
* Some of the global Smarty settings copied to template scope * Some of the global Smarty settings copied to template scope
@@ -133,20 +133,28 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
* *
* @param string $template_resource template resource string * @param string $template_resource template resource string
* @param Smarty $smarty Smarty instance * @param Smarty $smarty Smarty instance
* @param null|\Smarty_Internal_Template|\Smarty|\Smarty_Internal_Data $_parent back pointer to parent object * @param null|\Smarty_Internal_Template|\Smarty|\Smarty_Internal_Data $_parent back pointer to parent
* with variables or null * object with variables or
* null
* @param mixed $_cache_id cache id or null * @param mixed $_cache_id cache id or null
* @param mixed $_compile_id compile id or null * @param mixed $_compile_id compile id or null
* @param bool|int|null $_caching use caching? * @param bool|int|null $_caching use caching?
* @param int|null $_cache_lifetime cache life-time in seconds * @param int|null $_cache_lifetime cache life-time in
* seconds
* @param bool $_isConfig * @param bool $_isConfig
* *
* @throws \SmartyException * @throws \SmartyException
*/ */
public function __construct($template_resource, Smarty $smarty, Smarty_Internal_Data $_parent = null, public function __construct($template_resource,
$_cache_id = null, $_compile_id = null, $_caching = null, $_cache_lifetime = null, Smarty $smarty,
$_isConfig = false Smarty_Internal_Data $_parent = null,
) { $_cache_id = null,
$_compile_id = null,
$_caching = null,
$_cache_lifetime = null,
$_isConfig = false
)
{
$this->smarty = $smarty; $this->smarty = $smarty;
// Smarty parameter // Smarty parameter
$this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id; $this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
@@ -195,7 +203,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
} }
// read from cache or render // read from cache or render
if ($this->caching === Smarty::CACHING_LIFETIME_CURRENT || $this->caching === Smarty::CACHING_LIFETIME_SAVED) { if ($this->caching === Smarty::CACHING_LIFETIME_CURRENT || $this->caching === Smarty::CACHING_LIFETIME_SAVED) {
if (!isset($this->cached) || $this->cached->cache_id !== $this->cache_id if (!isset($this->cached) || $this->cached->cache_id !== $this->cache_id
|| $this->cached->compile_id !== $this->compile_id || $this->cached->compile_id !== $this->compile_id
) { ) {
$this->loadCached(true); $this->loadCached(true);
@@ -207,18 +215,18 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
} }
$this->compiled->render($this); $this->compiled->render($this);
} }
// display or fetch // display or fetch
if ($display) { if ($display) {
if ($this->caching && $this->smarty->cache_modified_check) { if ($this->caching && $this->smarty->cache_modified_check) {
$this->smarty->ext->_cacheModify->cacheModifiedCheck( $this->smarty->ext->_cacheModify->cacheModifiedCheck(
$this->cached, $this, $this->cached,
$this,
isset($content) ? $content : ob_get_clean() isset($content) ? $content : ob_get_clean()
); );
} else { } else {
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
&& !$no_output_filter && (isset($this->smarty->autoload_filters[ 'output' ]) && !$no_output_filter && (isset($this->smarty->autoload_filters[ 'output' ])
|| isset($this->smarty->registered_filters[ 'output' ])) || isset($this->smarty->registered_filters[ 'output' ]))
) { ) {
echo $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this); echo $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this);
} else { } else {
@@ -238,10 +246,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$this->smarty->_debug->display_debug($this, true); $this->smarty->_debug->display_debug($this, true);
} }
} }
if (!$no_output_filter if (!$no_output_filter
&& (!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) && (!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
&& (isset($this->smarty->autoload_filters[ 'output' ]) && (isset($this->smarty->autoload_filters[ 'output' ])
|| isset($this->smarty->registered_filters[ 'output' ])) || isset($this->smarty->registered_filters[ 'output' ]))
) { ) {
return $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this); return $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this);
} }
@@ -267,9 +275,18 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \SmartyException
*/ */
public function _subTemplateRender($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $scope, public function _subTemplateRender($template,
$forceTplCache, $uid = null, $content_func = null $cache_id,
) { $compile_id,
$caching,
$cache_lifetime,
$data,
$scope,
$forceTplCache,
$uid = null,
$content_func = null
)
{
$tpl = clone $this; $tpl = clone $this;
$tpl->parent = $this; $tpl->parent = $this;
$smarty = &$this->smarty; $smarty = &$this->smarty;
@@ -326,14 +343,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$tpl->scope = $scope; $tpl->scope = $scope;
if (!isset(self::$tplObjCache[ $tpl->templateId ]) && !$tpl->source->handler->recompiled) { if (!isset(self::$tplObjCache[ $tpl->templateId ]) && !$tpl->source->handler->recompiled) {
// check if template object should be cached // check if template object should be cached
if ($forceTplCache || (isset(self::$subTplInfo[ $tpl->template_resource ]) if ($forceTplCache || (isset(self::$subTplInfo[ $tpl->template_resource ])
&& self::$subTplInfo[ $tpl->template_resource ] > 1) && self::$subTplInfo[ $tpl->template_resource ] > 1)
|| ($tpl->_isSubTpl() && isset(self::$tplObjCache[ $tpl->parent->templateId ])) || ($tpl->_isSubTpl() && isset(self::$tplObjCache[ $tpl->parent->templateId ]))
) { ) {
self::$tplObjCache[ $tpl->templateId ] = $tpl; self::$tplObjCache[ $tpl->templateId ] = $tpl;
} }
} }
if (!empty($data)) { if (!empty($data)) {
// set up variable values // set up variable values
foreach ($data as $_key => $_val) { foreach ($data as $_key => $_val) {
@@ -428,16 +444,16 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
* *
* @throws \SmartyException * @throws \SmartyException
*/ */
public function _checkPlugins($plugins) public function _checkPlugins($plugins)
{ {
static $checked = array(); static $checked = array();
foreach($plugins as $plugin) { foreach ($plugins as $plugin) {
$name = join('::', (array)$plugin[ 'function' ]); $name = join('::', (array)$plugin[ 'function' ]);
if (!isset($checked[$name])) { if (!isset($checked[ $name ])) {
if (!is_callable($plugin['function'])) { if (!is_callable($plugin[ 'function' ])) {
if (is_file($plugin['file'])) { if (is_file($plugin[ 'file' ])) {
include_once $plugin['file']; include_once $plugin[ 'file' ];
if (is_callable($plugin['function'])) { if (is_callable($plugin[ 'function' ])) {
$checked[ $name ] = true; $checked[ $name ] = true;
} }
} }
@@ -479,7 +495,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
return false; return false;
} }
$is_valid = true; $is_valid = true;
if (!empty($properties[ 'file_dependency' ]) if (!empty($properties[ 'file_dependency' ])
&& ((!$cache && $tpl->compile_check) || $tpl->compile_check === Smarty::COMPILECHECK_ON) && ((!$cache && $tpl->compile_check) || $tpl->compile_check === Smarty::COMPILECHECK_ON)
) { ) {
// check file dependencies at compiled code // check file dependencies at compiled code
@@ -510,7 +526,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
} }
if ($cache) { if ($cache) {
// CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
if ($tpl->caching === Smarty::CACHING_LIFETIME_SAVED && $properties[ 'cache_lifetime' ] >= 0 if ($tpl->caching === Smarty::CACHING_LIFETIME_SAVED && $properties[ 'cache_lifetime' ] >= 0
&& (time() > ($tpl->cached->timestamp + $properties[ 'cache_lifetime' ])) && (time() > ($tpl->cached->timestamp + $properties[ 'cache_lifetime' ]))
) { ) {
$is_valid = false; $is_valid = false;
@@ -653,32 +669,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
return parent::__call($name, $args); return parent::__call($name, $args);
} }
/**
* set Smarty property in template context
*
* @param string $property_name property name
* @param mixed $value value
*
* @throws SmartyException
*/
public function __set($property_name, $value)
{
switch ($property_name) {
case 'compiled':
case 'cached':
case 'compiler':
$this->$property_name = $value;
return;
default:
// Smarty property ?
if (property_exists($this->smarty, $property_name)) {
$this->smarty->$property_name = $value;
return;
}
}
throw new SmartyException("invalid template property '$property_name'.");
}
/** /**
* get Smarty property in template context * get Smarty property in template context
* *
@@ -690,26 +680,50 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
public function __get($property_name) public function __get($property_name)
{ {
switch ($property_name) { switch ($property_name) {
case 'compiled': case 'compiled':
$this->loadCompiled(); $this->loadCompiled();
return $this->compiled; return $this->compiled;
case 'cached':
case 'cached': $this->loadCached();
$this->loadCached(); return $this->cached;
return $this->cached; case 'compiler':
$this->loadCompiler();
case 'compiler': return $this->compiler;
$this->loadCompiler(); default:
return $this->compiler; // Smarty property ?
default: if (property_exists($this->smarty, $property_name)) {
// Smarty property ? return $this->smarty->$property_name;
if (property_exists($this->smarty, $property_name)) { }
return $this->smarty->$property_name;
}
} }
throw new SmartyException("template property '$property_name' does not exist."); throw new SmartyException("template property '$property_name' does not exist.");
} }
/**
* set Smarty property in template context
*
* @param string $property_name property name
* @param mixed $value value
*
* @throws SmartyException
*/
public function __set($property_name, $value)
{
switch ($property_name) {
case 'compiled':
case 'cached':
case 'compiler':
$this->$property_name = $value;
return;
default:
// Smarty property ?
if (property_exists($this->smarty, $property_name)) {
$this->smarty->$property_name = $value;
return;
}
}
throw new SmartyException("invalid template property '$property_name'.");
}
/** /**
* Template data object destructor * Template data object destructor
*/ */

View File

@@ -271,7 +271,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @param mixed $cache_attr caching attributes if any * @param mixed $cache_attr caching attributes if any
* *
* @return \Smarty|\Smarty_Internal_Template * @return \Smarty|\Smarty_Internal_Template
* @throws SmartyException when the plugin tag is invalid * @throws \SmartyException
*/ */
public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null) public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null)
{ {
@@ -288,7 +288,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @param string $name filter name * @param string $name filter name
* *
* @return bool * @return bool
* @throws SmartyException if filter could not be loaded * @throws \SmartyException
*/ */
public function loadFilter($type, $name) public function loadFilter($type, $name)
{ {
@@ -301,9 +301,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @api Smarty::registerFilter() * @api Smarty::registerFilter()
* @link http://www.smarty.net/docs/en/api.register.filter.tpl * @link http://www.smarty.net/docs/en/api.register.filter.tpl
* *
* @param string $type filter type * @param string $type filter type
* @param callback $callback * @param callback $callback
* @param string|null $name optional filter name * @param string|null $name optional filter name
* *
* @return \Smarty|\Smarty_Internal_Template * @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException * @throws \SmartyException

View File

@@ -328,7 +328,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
array('.', array('.',
','), ','),
'_', '_',
uniqid(rand(), true) uniqid(mt_rand(), true)
); );
} }
@@ -586,7 +586,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$isset_par = str_replace("')->value", "',null,true,false)->value", $par); $isset_par = str_replace("')->value", "',null,true,false)->value", $par);
} }
return $name . '(' . $isset_par . ')'; return $name . '(' . $isset_par . ')';
} else if (in_array( } elseif (in_array(
$func_name, $func_name,
array('empty', array('empty',
'reset', 'reset',
@@ -717,7 +717,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @param string $tag tag name * @param string $tag tag name
* *
* @return bool|\Smarty_Internal_CompileBase tag compiler object or false if not found * @return bool|\Smarty_Internal_CompileBase tag compiler object or false if not found
* @throws \SmartyCompilerException
*/ */
public function getTagCompiler($tag) public function getTagCompiler($tag)
{ {
@@ -754,7 +753,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) { if (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
$function = $function =
$this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ]; $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
} else if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) { } elseif (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
$this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] = $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] =
$this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ]; $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ];
$function = $function =
@@ -764,7 +763,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) { if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
$function = $function =
$this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ]; $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
} else if (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) { } elseif (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
$this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] = $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] =
$this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ]; $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ];
$function = $function =
@@ -982,7 +981,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$_scopeName = trim($_attr[ 'scope' ], '\'"'); $_scopeName = trim($_attr[ 'scope' ], '\'"');
if (is_numeric($_scopeName) && in_array($_scopeName, $validScopes)) { if (is_numeric($_scopeName) && in_array($_scopeName, $validScopes)) {
$_scope = $_scopeName; $_scope = $_scopeName;
} else if (is_string($_scopeName)) { } elseif (is_string($_scopeName)) {
$_scopeName = trim($_scopeName, '\'"'); $_scopeName = trim($_scopeName, '\'"');
$_scope = isset($validScopes[ $_scopeName ]) ? $validScopes[ $_scopeName ] : false; $_scope = isset($validScopes[ $_scopeName ]) ? $validScopes[ $_scopeName ] : false;
} else { } else {
@@ -1028,7 +1027,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
if ($tagline === true) { if ($tagline === true) {
// get line number of Tag // get line number of Tag
$line = $lex->taglineno; $line = $lex->taglineno;
} else if (!isset($line)) { } elseif (!isset($line)) {
// get template source line which has error // get template source line which has error
$line = $lex->line; $line = $lex->line;
} else { } else {
@@ -1463,7 +1462,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|| in_array($method, $this->smarty->registered_objects[ $tag ][ 1 ])) || in_array($method, $this->smarty->registered_objects[ $tag ][ 1 ]))
) { ) {
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method); return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method);
} else if (in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ])) { } elseif (in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ])) {
return $this->callTagCompiler( return $this->callTagCompiler(
'private_object_block_function', 'private_object_block_function',
$args, $args,

View File

@@ -13,14 +13,15 @@
* This is the template file lexer. * This is the template file lexer.
* It is generated from the smarty_internal_templatelexer.plex file * It is generated from the smarty_internal_templatelexer.plex file
* *
*
* @author Uwe Tews <uwe.tews@googlemail.com> * @author Uwe Tews <uwe.tews@googlemail.com>
*/ */
class Smarty_Internal_Templatelexer class Smarty_Internal_Templatelexer
{ {
const TEXT = 1; const TEXT = 1;
const TAG = 2; const TAG = 2;
const TAGBODY = 3; const TAGBODY = 3;
const LITERAL = 4; const LITERAL = 4;
const DOUBLEQUOTEDSTRING = 5; const DOUBLEQUOTEDSTRING = 5;
/** /**
* Source * Source
@@ -191,16 +192,16 @@ class Smarty_Internal_Templatelexer
* @var null * @var null
*/ */
private $yy_global_pattern5 = null; private $yy_global_pattern5 = null;
private $_yy_state = 1; private $_yy_state = 1;
private $_yy_stack = array(); private $_yy_stack = array();
/** /**
* constructor * constructor
* *
* @param string $source template source * @param string $source template source
* @param Smarty_Internal_TemplateCompilerBase $compiler * @param Smarty_Internal_TemplateCompilerBase $compiler
*/ */
function __construct($source, Smarty_Internal_TemplateCompilerBase $compiler) public function __construct($source, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$this->data = $source; $this->data = $source;
$this->dataLength = strlen($this->data); $this->dataLength = strlen($this->data);
@@ -218,6 +219,7 @@ class Smarty_Internal_Templatelexer
/** /**
* open lexer/parser trace file * open lexer/parser trace file
*
*/ */
public function PrintTrace() public function PrintTrace()
{ {
@@ -237,11 +239,11 @@ class Smarty_Internal_Templatelexer
return $this->compiler->replaceDelimiter($preg); return $this->compiler->replaceDelimiter($preg);
} }
/** /**
* check if current value is an autoliteral left delimiter * check if current value is an autoliteral left delimiter
* *
* @return bool * @return bool
*/ */
public function isAutoLiteral() public function isAutoLiteral()
{ {
return $this->smarty->getAutoLiteral() && isset($this->value[ $this->compiler->getLdelLength() ]) ? return $this->smarty->getAutoLiteral() && isset($this->value[ $this->compiler->getLdelLength() ]) ?
@@ -256,47 +258,35 @@ class Smarty_Internal_Templatelexer
public function yypushstate($state) public function yypushstate($state)
{ {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%sState push %s\n",
"%sState push %s\n", $this->yyTracePrompt,
$this->yyTracePrompt, isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state
);
} }
array_push($this->_yy_stack, $this->_yy_state); array_push($this->_yy_stack, $this->_yy_state);
$this->_yy_state = $state; $this->_yy_state = $state;
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%snew State %s\n",
"%snew State %s\n", $this->yyTracePrompt,
$this->yyTracePrompt, isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state
);
} }
} }
public function yypopstate() public function yypopstate()
{ {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%sState pop %s\n",
"%sState pop %s\n", $this->yyTracePrompt,
$this->yyTracePrompt, isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state
);
} }
$this->_yy_state = array_pop($this->_yy_stack); $this->_yy_state = array_pop($this->_yy_stack);
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%snew State %s\n",
"%snew State %s\n", $this->yyTracePrompt,
$this->yyTracePrompt, isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state
);
} }
} }
@@ -304,13 +294,10 @@ class Smarty_Internal_Templatelexer
{ {
$this->_yy_state = $state; $this->_yy_state = $state;
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf( fprintf($this->yyTraceFILE,
$this->yyTraceFILE, "%sState set %s\n",
"%sState set %s\n", $this->yyTracePrompt,
$this->yyTracePrompt, isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state
);
} }
} }
@@ -334,14 +321,10 @@ class Smarty_Internal_Templatelexer
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception( throw new Exception('Error: lexing failed because a rule matched' .
'Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data,
' an empty string. Input "' . substr( $this->counter,
$this->data, 5) . '... state TEXT');
$this->counter,
5
) . '... state TEXT'
);
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -352,11 +335,11 @@ class Smarty_Internal_Templatelexer
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
// accept this token // accept this token
return true; return true;
} else if ($r === true) { } elseif ($r === true) {
// we have changed state // we have changed state
// process this token in the new state // process this token in the new state
return $this->yylex(); return $this->yylex();
} else if ($r === false) { } elseif ($r === false) {
$this->counter += strlen($this->value); $this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
@@ -366,10 +349,8 @@ class Smarty_Internal_Templatelexer
continue; continue;
} }
} else { } else {
throw new Exception( throw new Exception('Unexpected input at line' . $this->line .
'Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
': ' . $this->data[ $this->counter ]
);
} }
break; break;
} while (true); } while (true);
@@ -382,13 +363,11 @@ class Smarty_Internal_Templatelexer
function yy_r1_2() function yy_r1_2()
{ {
preg_match( preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/",
"/[*]{$this->compiler->getRdelPreg()}[\n]?/", $this->data,
$this->data, $match,
$match, PREG_OFFSET_CAPTURE,
PREG_OFFSET_CAPTURE, $this->counter);
$this->counter
);
if (isset($match[ 0 ][ 1 ])) { if (isset($match[ 0 ][ 1 ])) {
$to = $match[ 0 ][ 1 ] + strlen($match[ 0 ][ 0 ]); $to = $match[ 0 ][ 1 ] + strlen($match[ 0 ][ 0 ]);
} else { } else {
@@ -456,14 +435,10 @@ class Smarty_Internal_Templatelexer
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception( throw new Exception('Error: lexing failed because a rule matched' .
'Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data,
' an empty string. Input "' . substr( $this->counter,
$this->data, 5) . '... state TAG');
$this->counter,
5
) . '... state TAG'
);
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -474,11 +449,11 @@ class Smarty_Internal_Templatelexer
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
// accept this token // accept this token
return true; return true;
} else if ($r === true) { } elseif ($r === true) {
// we have changed state // we have changed state
// process this token in the new state // process this token in the new state
return $this->yylex(); return $this->yylex();
} else if ($r === false) { } elseif ($r === false) {
$this->counter += strlen($this->value); $this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
@@ -488,10 +463,8 @@ class Smarty_Internal_Templatelexer
continue; continue;
} }
} else { } else {
throw new Exception( throw new Exception('Unexpected input at line' . $this->line .
'Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
': ' . $this->data[ $this->counter ]
);
} }
break; break;
} while (true); } while (true);
@@ -601,14 +574,10 @@ class Smarty_Internal_Templatelexer
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception( throw new Exception('Error: lexing failed because a rule matched' .
'Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data,
' an empty string. Input "' . substr( $this->counter,
$this->data, 5) . '... state TAGBODY');
$this->counter,
5
) . '... state TAGBODY'
);
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -619,11 +588,11 @@ class Smarty_Internal_Templatelexer
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
// accept this token // accept this token
return true; return true;
} else if ($r === true) { } elseif ($r === true) {
// we have changed state // we have changed state
// process this token in the new state // process this token in the new state
return $this->yylex(); return $this->yylex();
} else if ($r === false) { } elseif ($r === false) {
$this->counter += strlen($this->value); $this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
@@ -633,10 +602,8 @@ class Smarty_Internal_Templatelexer
continue; continue;
} }
} else { } else {
throw new Exception( throw new Exception('Unexpected input at line' . $this->line .
'Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
': ' . $this->data[ $this->counter ]
);
} }
break; break;
} while (true); } while (true);
@@ -794,8 +761,8 @@ class Smarty_Internal_Templatelexer
function yy_r3_43() function yy_r3_43()
{ {
// resolve conflicts with shorttag and right_delimiter starting with '=' // resolve conflicts with shorttag and right_delimiter starting with '='
if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->compiler->getRdelLength()) === $this->smarty->getRightDelimiter() if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->compiler->getRdelLength()) ===
) { $this->smarty->getRightDelimiter()) {
preg_match('/\s+/', $this->value, $match); preg_match('/\s+/', $this->value, $match);
$this->value = $match[ 0 ]; $this->value = $match[ 0 ];
$this->token = Smarty_Internal_Templateparser::TP_SPACE; $this->token = Smarty_Internal_Templateparser::TP_SPACE;
@@ -895,14 +862,10 @@ class Smarty_Internal_Templatelexer
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception( throw new Exception('Error: lexing failed because a rule matched' .
'Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data,
' an empty string. Input "' . substr( $this->counter,
$this->data, 5) . '... state LITERAL');
$this->counter,
5
) . '... state LITERAL'
);
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -913,11 +876,11 @@ class Smarty_Internal_Templatelexer
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
// accept this token // accept this token
return true; return true;
} else if ($r === true) { } elseif ($r === true) {
// we have changed state // we have changed state
// process this token in the new state // process this token in the new state
return $this->yylex(); return $this->yylex();
} else if ($r === false) { } elseif ($r === false) {
$this->counter += strlen($this->value); $this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
@@ -927,10 +890,8 @@ class Smarty_Internal_Templatelexer
continue; continue;
} }
} else { } else {
throw new Exception( throw new Exception('Unexpected input at line' . $this->line .
'Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
': ' . $this->data[ $this->counter ]
);
} }
break; break;
} while (true); } while (true);
@@ -978,14 +939,10 @@ class Smarty_Internal_Templatelexer
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception( throw new Exception('Error: lexing failed because a rule matched' .
'Error: lexing failed because a rule matched' . ' an empty string. Input "' . substr($this->data,
' an empty string. Input "' . substr( $this->counter,
$this->data, 5) . '... state DOUBLEQUOTEDSTRING');
$this->counter,
5
) . '... state DOUBLEQUOTEDSTRING'
);
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -996,11 +953,11 @@ class Smarty_Internal_Templatelexer
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
// accept this token // accept this token
return true; return true;
} else if ($r === true) { } elseif ($r === true) {
// we have changed state // we have changed state
// process this token in the new state // process this token in the new state
return $this->yylex(); return $this->yylex();
} else if ($r === false) { } elseif ($r === false) {
$this->counter += strlen($this->value); $this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n"); $this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
@@ -1010,10 +967,8 @@ class Smarty_Internal_Templatelexer
continue; continue;
} }
} else { } else {
throw new Exception( throw new Exception('Unexpected input at line' . $this->line .
'Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
': ' . $this->data[ $this->counter ]
);
} }
break; break;
} while (true); } while (true);
@@ -1083,4 +1038,4 @@ class Smarty_Internal_Templatelexer
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -82,7 +82,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'template_dir' ] = $message; $errors[ 'template_dir' ] = $message;
} }
} else if (!is_readable($template_dir)) { } elseif (!is_readable($template_dir)) {
$status = false; $status = false;
$message = "FAILED: $template_dir is not readable"; $message = "FAILED: $template_dir is not readable";
if ($errors === null) { if ($errors === null) {
@@ -110,7 +110,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'compile_dir' ] = $message; $errors[ 'compile_dir' ] = $message;
} }
} else if (!is_dir($_compile_dir)) { } elseif (!is_dir($_compile_dir)) {
$status = false; $status = false;
$message = "FAILED: {$_compile_dir} is not a directory"; $message = "FAILED: {$_compile_dir} is not a directory";
if ($errors === null) { if ($errors === null) {
@@ -118,7 +118,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'compile_dir' ] = $message; $errors[ 'compile_dir' ] = $message;
} }
} else if (!is_readable($_compile_dir)) { } elseif (!is_readable($_compile_dir)) {
$status = false; $status = false;
$message = "FAILED: {$_compile_dir} is not readable"; $message = "FAILED: {$_compile_dir} is not readable";
if ($errors === null) { if ($errors === null) {
@@ -126,7 +126,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'compile_dir' ] = $message; $errors[ 'compile_dir' ] = $message;
} }
} else if (!is_writable($_compile_dir)) { } elseif (!is_writable($_compile_dir)) {
$status = false; $status = false;
$message = "FAILED: {$_compile_dir} is not writable"; $message = "FAILED: {$_compile_dir} is not writable";
if ($errors === null) { if ($errors === null) {
@@ -192,7 +192,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'plugins_dir' ] = $message; $errors[ 'plugins_dir' ] = $message;
} }
} else if (!is_readable($plugin_dir)) { } elseif (!is_readable($plugin_dir)) {
$status = false; $status = false;
$message = "FAILED: $plugin_dir is not readable"; $message = "FAILED: $plugin_dir is not readable";
if ($errors === null) { if ($errors === null) {
@@ -200,7 +200,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'plugins_dir' ] = $message; $errors[ 'plugins_dir' ] = $message;
} }
} else if ($_core_plugins_dir && $_core_plugins_dir == realpath($plugin_dir)) { } elseif ($_core_plugins_dir && $_core_plugins_dir == realpath($plugin_dir)) {
$_core_plugins_available = true; $_core_plugins_available = true;
if ($errors === null) { if ($errors === null) {
echo "$plugin_dir is OK.\n"; echo "$plugin_dir is OK.\n";
@@ -216,7 +216,7 @@ class Smarty_Internal_TestInstall
$message = "WARNING: Smarty's own libs/plugins is not available"; $message = "WARNING: Smarty's own libs/plugins is not available";
if ($errors === null) { if ($errors === null) {
echo $message . ".\n"; echo $message . ".\n";
} else if (!isset($errors[ 'plugins_dir' ])) { } elseif (!isset($errors[ 'plugins_dir' ])) {
$errors[ 'plugins_dir' ] = $message; $errors[ 'plugins_dir' ] = $message;
} }
} }
@@ -234,7 +234,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'cache_dir' ] = $message; $errors[ 'cache_dir' ] = $message;
} }
} else if (!is_dir($_cache_dir)) { } elseif (!is_dir($_cache_dir)) {
$status = false; $status = false;
$message = "FAILED: {$_cache_dir} is not a directory"; $message = "FAILED: {$_cache_dir} is not a directory";
if ($errors === null) { if ($errors === null) {
@@ -242,7 +242,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'cache_dir' ] = $message; $errors[ 'cache_dir' ] = $message;
} }
} else if (!is_readable($_cache_dir)) { } elseif (!is_readable($_cache_dir)) {
$status = false; $status = false;
$message = "FAILED: {$_cache_dir} is not readable"; $message = "FAILED: {$_cache_dir} is not readable";
if ($errors === null) { if ($errors === null) {
@@ -250,7 +250,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'cache_dir' ] = $message; $errors[ 'cache_dir' ] = $message;
} }
} else if (!is_writable($_cache_dir)) { } elseif (!is_writable($_cache_dir)) {
$status = false; $status = false;
$message = "FAILED: {$_cache_dir} is not writable"; $message = "FAILED: {$_cache_dir} is not writable";
if ($errors === null) { if ($errors === null) {
@@ -312,7 +312,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'config_dir' ] = $message; $errors[ 'config_dir' ] = $message;
} }
} else if (!is_readable($config_dir)) { } elseif (!is_readable($config_dir)) {
$status = false; $status = false;
$message = "FAILED: $config_dir is not readable"; $message = "FAILED: $config_dir is not readable";
if ($errors === null) { if ($errors === null) {
@@ -502,7 +502,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'sysplugins' ] = $message; $errors[ 'sysplugins' ] = $message;
} }
} else if ($errors === null) { } elseif ($errors === null) {
echo "... OK\n"; echo "... OK\n";
} }
} else { } else {
@@ -586,7 +586,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'plugins' ] = $message; $errors[ 'plugins' ] = $message;
} }
} else if ($errors === null) { } elseif ($errors === null) {
echo "... OK\n"; echo "... OK\n";
} }
} else { } else {

View File

@@ -264,10 +264,9 @@ class Smarty_Security
* Check if PHP function is trusted. * Check if PHP function is trusted.
* *
* @param string $function_name * @param string $function_name
* @param object $compiler compiler object * @param object $compiler compiler object
* *
* @return boolean true if function is trusted * @return boolean true if function is trusted
* @throws SmartyCompilerException if php function is not trusted
*/ */
public function isTrustedPhpFunction($function_name, $compiler) public function isTrustedPhpFunction($function_name, $compiler)
{ {
@@ -286,10 +285,9 @@ class Smarty_Security
* Check if static class is trusted. * Check if static class is trusted.
* *
* @param string $class_name * @param string $class_name
* @param object $compiler compiler object * @param object $compiler compiler object
* *
* @return boolean true if class is trusted * @return boolean true if class is trusted
* @throws SmartyCompilerException if static class is not trusted
*/ */
public function isTrustedStaticClass($class_name, $compiler) public function isTrustedStaticClass($class_name, $compiler)
{ {
@@ -309,10 +307,9 @@ class Smarty_Security
* *
* @param string $class_name * @param string $class_name
* @param string $params * @param string $params
* @param object $compiler compiler object * @param object $compiler compiler object
* *
* @return boolean true if class method is trusted * @return boolean true if class method is trusted
* @throws SmartyCompilerException if static class method is not trusted
*/ */
public function isTrustedStaticClassAccess($class_name, $params, $compiler) public function isTrustedStaticClassAccess($class_name, $params, $compiler)
{ {
@@ -347,10 +344,9 @@ class Smarty_Security
* Check if PHP modifier is trusted. * Check if PHP modifier is trusted.
* *
* @param string $modifier_name * @param string $modifier_name
* @param object $compiler compiler object * @param object $compiler compiler object
* *
* @return boolean true if modifier is trusted * @return boolean true if modifier is trusted
* @throws SmartyCompilerException if modifier is not trusted
*/ */
public function isTrustedPhpModifier($modifier_name, $compiler) public function isTrustedPhpModifier($modifier_name, $compiler)
{ {
@@ -372,7 +368,6 @@ class Smarty_Security
* @param object $compiler compiler object * @param object $compiler compiler object
* *
* @return boolean true if tag is trusted * @return boolean true if tag is trusted
* @throws SmartyCompilerException if modifier is not trusted
*/ */
public function isTrustedTag($tag_name, $compiler) public function isTrustedTag($tag_name, $compiler)
{ {
@@ -410,7 +405,6 @@ class Smarty_Security
* @param object $compiler compiler object * @param object $compiler compiler object
* *
* @return boolean true if tag is trusted * @return boolean true if tag is trusted
* @throws SmartyCompilerException if modifier is not trusted
*/ */
public function isTrustedSpecialSmartyVar($var_name, $compiler) public function isTrustedSpecialSmartyVar($var_name, $compiler)
{ {
@@ -430,10 +424,9 @@ class Smarty_Security
* Check if modifier plugin is trusted. * Check if modifier plugin is trusted.
* *
* @param string $modifier_name * @param string $modifier_name
* @param object $compiler compiler object * @param object $compiler compiler object
* *
* @return boolean true if tag is trusted * @return boolean true if tag is trusted
* @throws SmartyCompilerException if modifier is not trusted
*/ */
public function isTrustedModifier($modifier_name, $compiler) public function isTrustedModifier($modifier_name, $compiler)
{ {

View File

@@ -134,7 +134,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
$smarty = &$_smarty_tpl->smarty; $smarty = &$_smarty_tpl->smarty;
if ($source->handler->recompiled) { if ($source->handler->recompiled) {
$source->handler->process($_smarty_tpl); $source->handler->process($_smarty_tpl);
} else if (!$source->handler->uncompiled) { } elseif (!$source->handler->uncompiled) {
if (!$this->exists || $smarty->force_compile if (!$this->exists || $smarty->force_compile
|| ($_smarty_tpl->compile_check && $source->getTimeStamp() > $this->getTimeStamp()) || ($_smarty_tpl->compile_check && $source->getTimeStamp() > $this->getTimeStamp())
) { ) {
@@ -246,7 +246,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1) && (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
) { ) {
opcache_invalidate($this->filepath, true); opcache_invalidate($this->filepath, true);
} else if (function_exists('apc_compile_file')) { } elseif (function_exists('apc_compile_file')) {
apc_compile_file($this->filepath); apc_compile_file($this->filepath);
} }
if (defined('HHVM_VERSION')) { if (defined('HHVM_VERSION')) {

View File

@@ -6,7 +6,7 @@
* Time: 23:58 * Time: 23:58
*/ */
$sysplugins = array(); $sysplugins = array();
$iterator = new DirectoryIterator(__DIR__ . '/../libs/sysplugins'); $iterator = new DirectoryIterator(dirname(__FILE__) . '/../libs/sysplugins');
foreach ($iterator as $file) { foreach ($iterator as $file) {
if (!$file->isDot() && 'php' == $file->getExtension()) { if (!$file->isDot() && 'php' == $file->getExtension()) {
$filename = $file->getBasename(); $filename = $file->getBasename();
@@ -14,17 +14,17 @@ foreach ($iterator as $file) {
} }
} }
$plugins = array(); $plugins = array();
$iterator = new DirectoryIterator(__DIR__ . '/../libs/plugins'); $iterator = new DirectoryIterator(dirname(__FILE__) . '/../libs/plugins');
foreach ($iterator as $file) { foreach ($iterator as $file) {
if (!$file->isDot() && 'php' == $file->getExtension()) { if (!$file->isDot() && 'php' == $file->getExtension()) {
$filename = $file->getBasename(); $filename = $file->getBasename();
$plugins[ $filename ] = true; $plugins[ $filename ] = true;
} }
} }
$code = file_get_contents(__DIR__ . '/../libs/sysplugins/smarty_internal_testinstall.php'); $code = file_get_contents(dirname(__FILE__) . '/../libs/sysplugins/smarty_internal_testinstall.php');
$expectedPlugins = '$expectedPlugins = ' . var_export($plugins, true); $expectedPlugins = '$expectedPlugins = ' . var_export($plugins, true);
$code = preg_replace('#\$expectedPlugins =[^;]+#', $expectedPlugins, $code); $code = preg_replace('#\$expectedPlugins =[^;]+#', $expectedPlugins, $code);
$expectedSysplugins = '$expectedSysplugins = ' . var_export($sysplugins, true); $expectedSysplugins = '$expectedSysplugins = ' . var_export($sysplugins, true);
$code = preg_replace('#\$expectedSysplugins =[^;]+#', $expectedSysplugins, $code); $code = preg_replace('#\$expectedSysplugins =[^;]+#', $expectedSysplugins, $code);
file_put_contents(__DIR__ . '/../libs/sysplugins/smarty_internal_testinstall.php', $code); file_put_contents(dirname(__FILE__) . '/../libs/sysplugins/smarty_internal_testinstall.php', $code);