update Smarty to v3.1.33 - "This release does cover security issue CVE-2018-16831, other bug fixes (see changelog.txt) and adds a new feature of the {capture} tag (see NEW_FEATURES.txt)."

postfixadmin_3.2
David Goodwin 5 years ago
parent 7697bee2af
commit 5731742fd6

@ -54,8 +54,8 @@ class Smarty_Autoloader
if (!defined('SMARTY_SPL_AUTOLOAD')) { if (!defined('SMARTY_SPL_AUTOLOAD')) {
define('SMARTY_SPL_AUTOLOAD', 0); define('SMARTY_SPL_AUTOLOAD', 0);
} }
if (SMARTY_SPL_AUTOLOAD && if (SMARTY_SPL_AUTOLOAD
set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
) { ) {
$registeredAutoLoadFunctions = spl_autoload_functions(); $registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) { if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {

@ -27,7 +27,7 @@
* @author Uwe Tews <uwe dot tews at gmail dot com> * @author Uwe Tews <uwe dot tews at gmail dot com>
* @author Rodney Rehm * @author Rodney Rehm
* @package Smarty * @package Smarty
* @version 3.1.32 * @version 3.1.33
*/ */
/** /**
* set SMARTY_DIR to absolute path to Smarty library files. * set SMARTY_DIR to absolute path to Smarty library files.
@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.32'; const SMARTY_VERSION = '3.1.33';
/** /**
* 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,160 +483,189 @@ 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
* *
* @var string[] * @var string[]
*/ */
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
* *
* @var string[] * @var string[]
*/ */
protected $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir', protected $accessMap = array(
'template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir',
'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir', 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir',
'cache_dir' => 'CacheDir',); 'cache_dir' => 'CacheDir',
);
/** /**
* Initialize new Smarty object * Initialize new Smarty object
@ -657,7 +731,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)
{ {
@ -835,7 +909,7 @@ class Smarty extends Smarty_Internal_TemplateBase
$this->plugins_dir = (array)$this->plugins_dir; $this->plugins_dir = (array)$this->plugins_dir;
} }
foreach ($this->plugins_dir as $k => $v) { foreach ($this->plugins_dir as $k => $v) {
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . DIRECTORY_SEPARATOR, true); $this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, '/\\') . DIRECTORY_SEPARATOR, true);
} }
$this->_cache[ 'plugin_files' ] = array(); $this->_cache[ 'plugin_files' ] = array();
$this->_pluginsDirNormalized = true; $this->_pluginsDirNormalized = true;
@ -984,8 +1058,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)
{ {
@ -1004,12 +1078,13 @@ class Smarty extends Smarty_Internal_TemplateBase
* @return string * @return string
* @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;
@ -1036,30 +1111,19 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param string $path file path * @param string $path file path
* @param bool $realpath if true - convert to absolute * @param bool $realpath if true - convert to absolute
* false - convert to relative * false - convert to relative
* null - keep as it is but remove /./ /../ * null - keep as it is but
* remove /./ /../
* *
* @return string * @return string
*/ */
public function _realpath($path, $realpath = null) public function _realpath($path, $realpath = null)
{ {
static $nds = null;
static $sepDotsep = null;
static $sepDot = null;
static $sepSep =null;
if (!isset($nds)) {
$nds = array('/' => '\\', '\\' => '/'); $nds = array('/' => '\\', '\\' => '/');
$sepDotsep = DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR; preg_match(
$sepDot = DIRECTORY_SEPARATOR . '.'; '%^(?<root>(?:[[:alpha:]]:[\\\\/]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u',
$sepSep = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
}
// normalize DIRECTORY_SEPARATOR
$path = str_replace(array($nds[DIRECTORY_SEPARATOR], $sepDotsep), DIRECTORY_SEPARATOR, $path);
if (strpos($path,$sepDot) === false && (($realpath === false && $path[0] === '.') || $realpath === null) && $path[0] !== '\\') {
return $path;
}
preg_match('%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u',
$path, $path,
$parts); $parts
);
$path = $parts[ 'path' ]; $path = $parts[ 'path' ];
if ($parts[ 'root' ] === '\\') { if ($parts[ 'root' ] === '\\') {
$parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ]; $parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ];
@ -1068,24 +1132,18 @@ class Smarty extends Smarty_Internal_TemplateBase
$path = getcwd() . DIRECTORY_SEPARATOR . $path; $path = getcwd() . DIRECTORY_SEPARATOR . $path;
} }
} }
// remove noop 'DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR' and 'DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR' patterns // normalize DIRECTORY_SEPARATOR
$path = str_replace(array($sepDotsep,$sepSep), DIRECTORY_SEPARATOR, $path); $path = str_replace($nds[ DIRECTORY_SEPARATOR ], DIRECTORY_SEPARATOR, $path);
// resolve '..DIRECTORY_SEPARATOR' pattern, smallest first $parts[ 'root' ] = str_replace($nds[ DIRECTORY_SEPARATOR ], DIRECTORY_SEPARATOR, $parts[ 'root' ]);
if (strpos($path, '..' . DIRECTORY_SEPARATOR) !== false && do {
preg_match_all('#[\\\\/]([.][.][\\\\/])+#u', $path, $match) $path = preg_replace(
) { array('#[\\\\/]{2}#', '#[\\\\/][.][\\\\/]#', '#[\\\\/]([^\\\\/.]+)[\\\\/][.][.][\\\\/]#'),
$counts = array();
foreach ($match[ 0 ] as $m) {
$counts[] = (int)((strlen($m) - 1) / 3);
}
sort($counts);
foreach ($counts as $count) {
$path = preg_replace('#([\\\\/]+[^\\\\/]+){' . $count .
'}[\\\\/]+([.][.][\\\\/]+){' . $count . '}#u',
DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR,
$path); $path,
} -1,
} $count
);
} 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);
} }
@ -1282,7 +1340,6 @@ 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)
{ {
@ -1307,7 +1364,6 @@ 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)
{ {
@ -1316,14 +1372,12 @@ class Smarty extends Smarty_Internal_TemplateBase
$this->{$method}($value); $this->{$method}($value);
} elseif (in_array($name, $this->obsoleteProperties)) { } elseif (in_array($name, $this->obsoleteProperties)) {
return; return;
} else { } elseif (is_object($value) && method_exists($value, $name)) {
if (is_object($value) && method_exists($value, $name)) {
$this->$name = $value; $this->$name = $value;
} else { } else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
} }
} }
}
/** /**
* Normalize and set directory string * Normalize and set directory string
@ -1345,7 +1399,6 @@ class Smarty extends Smarty_Internal_TemplateBase
* Normalize template_dir or config_dir * Normalize template_dir or config_dir
* *
* @param bool $isConfig true for config_dir * @param bool $isConfig true for config_dir
*
*/ */
private function _normalizeTemplateConfig($isConfig) private function _normalizeTemplateConfig($isConfig)
{ {

@ -28,7 +28,7 @@
/** /**
* @ignore * @ignore
*/ */
require_once(dirname(__FILE__) . '/Smarty.class.php'); require_once dirname(__FILE__) . '/Smarty.class.php';
/** /**
* Smarty Backward Compatibility Wrapper Class * Smarty Backward Compatibility Wrapper Class
@ -53,7 +53,6 @@ class SmartyBC extends Smarty
/** /**
* Initialize new SmartyBC object * Initialize new SmartyBC object
*
*/ */
public function __construct() public function __construct()
{ {
@ -130,9 +129,13 @@ class SmartyBC extends Smarty
* @throws SmartyException * @throws SmartyException
* @internal param array $block_functs list of methods that are block format * @internal param array $block_functs list of methods that are block format
*/ */
public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, public function register_object(
$block_methods = array()) $object,
{ $object_impl,
$allowed = array(),
$smarty_args = true,
$block_methods = array()
) {
settype($allowed, 'array'); settype($allowed, 'array');
settype($smarty_args, 'boolean'); settype($smarty_args, 'boolean');
$this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods); $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);

@ -1,5 +1,5 @@
<?php <?php
/* /**
* This file is part of the Smarty package. * This file is part of the Smarty package.
* *
* (c) Sebastian Bergmann <sebastian@phpunit.de> * (c) Sebastian Bergmann <sebastian@phpunit.de>
@ -7,11 +7,10 @@
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
/**
/*
* Load and register Smarty Autoloader * Load and register Smarty Autoloader
*/ */
if (!class_exists('Smarty_Autoloader')) { if (!class_exists('Smarty_Autoloader')) {
require dirname(__FILE__) . '/Autoloader.php'; include dirname(__FILE__) . '/Autoloader.php';
} }
Smarty_Autoloader::register(true); Smarty_Autoloader::register(true);

@ -113,10 +113,10 @@
<div> <div>
{foreach $template_data as $template} {foreach $template_data as $template}
<font color=brown>{$template.name}</font> <font color=brown>{$template.name}</font>
<br>&nbsp;&nbsp;<span class="exectime"> <br />&nbsp;&nbsp;<span class="exectime">
(compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"}) (compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"})
</span> </span>
<br> <br />
{/foreach} {/foreach}
</div> </div>
{/if} {/if}
@ -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>

@ -20,7 +20,6 @@
* - 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)
* *
@ -39,10 +38,15 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
return; return;
} }
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
$template->_checkPlugins(array(array('function' => 'smarty_modifier_mb_wordwrap', $template->_checkPlugins(
'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php'))); array(
array(
'function' => 'smarty_modifier_mb_wordwrap',
'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php'
)
)
);
} }
$style = null; $style = null;
$indent = 0; $indent = 0;
$indent_first = 0; $indent_first = 0;
@ -51,7 +55,6 @@ 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':
@ -60,38 +63,40 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
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': case 'wrap_cut':
$$_key = (bool)$_val; $$_key = (bool)$_val;
break; break;
default: default:
trigger_error("textformat: unknown attribute '{$_key}'"); 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;
} }
// convert mult. spaces & special chars to single space // convert mult. spaces & special chars to single space
$_paragraph = $_paragraph =
preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, preg_replace(
'!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), array(
array(' ', '!\s+!' . Smarty::$_UTF8_MODIFIER,
''), $_paragraph); '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER
),
array(
' ',
''
),
$_paragraph
);
// indent first line // indent first line
if ($indent_first > 0) { if ($indent_first > 0) {
$_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph; $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;
@ -108,7 +113,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 {

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {counter} function plugin * Smarty {counter} function plugin
* Type: function * Type: function
@ -24,50 +23,40 @@
function smarty_function_counter($params, $template) function smarty_function_counter($params, $template)
{ {
static $counters = array(); static $counters = array();
$name = (isset($params[ 'name' ])) ? $params[ 'name' ] : 'default'; $name = (isset($params[ 'name' ])) ? $params[ 'name' ] : 'default';
if (!isset($counters[ $name ])) { if (!isset($counters[ $name ])) {
$counters[ $name ] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1); $counters[ $name ] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1);
} }
$counter =& $counters[ $name ]; $counter =& $counters[ $name ];
if (isset($params[ 'start' ])) { if (isset($params[ 'start' ])) {
$counter[ 'start' ] = $counter[ 'count' ] = (int)$params[ 'start' ]; $counter[ 'start' ] = $counter[ 'count' ] = (int)$params[ 'start' ];
} }
if (!empty($params[ 'assign' ])) { if (!empty($params[ 'assign' ])) {
$counter[ 'assign' ] = $params[ 'assign' ]; $counter[ 'assign' ] = $params[ 'assign' ];
} }
if (isset($counter[ 'assign' ])) { if (isset($counter[ 'assign' ])) {
$template->assign($counter[ 'assign' ], $counter[ 'count' ]); $template->assign($counter[ 'assign' ], $counter[ 'count' ]);
} }
if (isset($params[ 'print' ])) { if (isset($params[ 'print' ])) {
$print = (bool)$params[ 'print' ]; $print = (bool)$params[ 'print' ];
} else { } else {
$print = empty($counter[ 'assign' ]); $print = empty($counter[ 'assign' ]);
} }
if ($print) { if ($print) {
$retval = $counter[ 'count' ]; $retval = $counter[ 'count' ];
} else { } else {
$retval = null; $retval = null;
} }
if (isset($params[ 'skip' ])) { if (isset($params[ 'skip' ])) {
$counter[ 'skip' ] = $params[ 'skip' ]; $counter[ 'skip' ] = $params[ 'skip' ];
} }
if (isset($params[ 'direction' ])) { if (isset($params[ 'direction' ])) {
$counter[ 'direction' ] = $params[ 'direction' ]; $counter[ 'direction' ] = $params[ 'direction' ];
} }
if ($counter[ 'direction' ] === 'down') { if ($counter[ 'direction' ] === 'down') {
$counter[ 'count' ] -= $counter[ 'skip' ]; $counter[ 'count' ] -= $counter[ 'skip' ];
} else { } else {
$counter[ 'count' ] += $counter[ 'skip' ]; $counter[ 'count' ] += $counter[ 'skip' ];
} }
return $retval; return $retval;
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {cycle} function plugin * Smarty {cycle} function plugin
* Type: function * Type: function
@ -29,7 +28,6 @@
* {cycle name=row values="one,two,three" reset=true} * {cycle name=row values="one,two,three" reset=true}
* {cycle name=row} * {cycle name=row}
* *
*
* @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle} * @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle}
* (Smarty online manual) * (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
@ -43,20 +41,16 @@
* *
* @return string|null * @return string|null
*/ */
function smarty_function_cycle($params, $template) function smarty_function_cycle($params, $template)
{ {
static $cycle_vars; static $cycle_vars;
$name = (empty($params[ 'name' ])) ? 'default' : $params[ 'name' ]; $name = (empty($params[ 'name' ])) ? 'default' : $params[ 'name' ];
$print = (isset($params[ 'print' ])) ? (bool)$params[ 'print' ] : true; $print = (isset($params[ 'print' ])) ? (bool)$params[ 'print' ] : true;
$advance = (isset($params[ 'advance' ])) ? (bool)$params[ 'advance' ] : true; $advance = (isset($params[ 'advance' ])) ? (bool)$params[ 'advance' ] : true;
$reset = (isset($params[ 'reset' ])) ? (bool)$params[ 'reset' ] : false; $reset = (isset($params[ 'reset' ])) ? (bool)$params[ 'reset' ] : false;
if (!isset($params[ 'values' ])) { if (!isset($params[ 'values' ])) {
if (!isset($cycle_vars[ $name ][ 'values' ])) { if (!isset($cycle_vars[ $name ][ 'values' ])) {
trigger_error('cycle: missing \'values\' parameter'); trigger_error('cycle: missing \'values\' parameter');
return; return;
} }
} else { } else {
@ -65,34 +59,28 @@ function smarty_function_cycle($params, $template)
} }
$cycle_vars[ $name ][ 'values' ] = $params[ 'values' ]; $cycle_vars[ $name ][ 'values' ] = $params[ 'values' ];
} }
if (isset($params[ 'delimiter' ])) { if (isset($params[ 'delimiter' ])) {
$cycle_vars[ $name ][ 'delimiter' ] = $params[ 'delimiter' ]; $cycle_vars[ $name ][ 'delimiter' ] = $params[ 'delimiter' ];
} elseif (!isset($cycle_vars[ $name ][ 'delimiter' ])) { } elseif (!isset($cycle_vars[ $name ][ 'delimiter' ])) {
$cycle_vars[ $name ][ 'delimiter' ] = ','; $cycle_vars[ $name ][ 'delimiter' ] = ',';
} }
if (is_array($cycle_vars[ $name ][ 'values' ])) { if (is_array($cycle_vars[ $name ][ 'values' ])) {
$cycle_array = $cycle_vars[ $name ][ 'values' ]; $cycle_array = $cycle_vars[ $name ][ 'values' ];
} else { } else {
$cycle_array = explode($cycle_vars[ $name ][ 'delimiter' ], $cycle_vars[ $name ][ 'values' ]); $cycle_array = explode($cycle_vars[ $name ][ 'delimiter' ], $cycle_vars[ $name ][ 'values' ]);
} }
if (!isset($cycle_vars[ $name ][ 'index' ]) || $reset) { if (!isset($cycle_vars[ $name ][ 'index' ]) || $reset) {
$cycle_vars[ $name ][ 'index' ] = 0; $cycle_vars[ $name ][ 'index' ] = 0;
} }
if (isset($params[ 'assign' ])) { if (isset($params[ 'assign' ])) {
$print = false; $print = false;
$template->assign($params[ 'assign' ], $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]); $template->assign($params[ 'assign' ], $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]);
} }
if ($print) { if ($print) {
$retval = $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]; $retval = $cycle_array[ $cycle_vars[ $name ][ 'index' ] ];
} else { } else {
$retval = null; $retval = null;
} }
if ($advance) { if ($advance) {
if ($cycle_vars[ $name ][ 'index' ] >= count($cycle_array) - 1) { if ($cycle_vars[ $name ][ 'index' ] >= count($cycle_array) - 1) {
$cycle_vars[ $name ][ 'index' ] = 0; $cycle_vars[ $name ][ 'index' ] = 0;
@ -100,6 +88,5 @@ function smarty_function_cycle($params, $template)
$cycle_vars[ $name ][ 'index' ]++; $cycle_vars[ $name ][ 'index' ]++;
} }
} }
return $retval; return $retval;
} }

@ -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
@ -104,7 +98,6 @@ function smarty_function_fetch($params, $template)
if (!empty($param_value)) { if (!empty($param_value)) {
if (!preg_match('![\w\d-]+: .+!', $param_value)) { if (!preg_match('![\w\d-]+: .+!', $param_value)) {
trigger_error("[plugin] invalid header format '{$param_value}'", E_USER_NOTICE); trigger_error("[plugin] invalid header format '{$param_value}'", E_USER_NOTICE);
return; return;
} else { } else {
$extra_headers[] = $param_value; $extra_headers[] = $param_value;
@ -121,7 +114,6 @@ function smarty_function_fetch($params, $template)
$proxy_port = (int)$param_value; $proxy_port = (int)$param_value;
} else { } else {
trigger_error("[plugin] invalid value for attribute '{$param_key }'", E_USER_NOTICE); trigger_error("[plugin] invalid value for attribute '{$param_key }'", E_USER_NOTICE);
return; return;
} }
break; break;
@ -140,13 +132,11 @@ function smarty_function_fetch($params, $template)
$timeout = (int)$param_value; $timeout = (int)$param_value;
} else { } else {
trigger_error("[plugin] invalid value for attribute '{$param_key}'", E_USER_NOTICE); trigger_error("[plugin] invalid value for attribute '{$param_key}'", E_USER_NOTICE);
return; return;
} }
break; break;
default: default:
trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE); trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE);
return; return;
} }
} }
@ -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 {

@ -29,7 +29,6 @@
* - assign (optional) - assign the output as an array to this variable * - assign (optional) - assign the output as an array to this variable
* - escape (optional) - escape the content (not value), defaults to true * - escape (optional) - escape the content (not value), defaults to true
* *
*
* @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} * @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
* (Smarty online manual) * (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com> * @author Christopher Kvarme <christopher.kvarme@flashjab.com>
@ -45,9 +44,14 @@
*/ */
function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template) function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template)
{ {
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', $template->_checkPlugins(
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); array(
array(
'function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
)
)
);
$name = 'checkbox'; $name = 'checkbox';
$values = null; $values = null;
$options = null; $options = null;
@ -57,31 +61,25 @@ 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; break;
case 'escape': case 'escape':
case 'labels': case 'labels':
case 'label_ids': case 'label_ids':
$$_key = (bool)$_val; $$_key = (bool)$_val;
break; break;
case 'options': case 'options':
$$_key = (array)$_val; $$_key = (array)$_val;
break; break;
case 'values': case 'values':
case 'output': case 'output':
$$_key = array_values((array)$_val); $$_key = array_values((array)$_val);
break; break;
case 'checked': case 'checked':
case 'selected': case 'selected':
if (is_array($_val)) { if (is_array($_val)) {
@ -91,8 +89,11 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
if (method_exists($_sel, '__toString')) { if (method_exists($_sel, '__toString')) {
$_sel = smarty_function_escape_special_chars((string)$_sel->__toString()); $_sel = smarty_function_escape_special_chars((string)$_sel->__toString());
} else { } else {
trigger_error('html_checkboxes: selected attribute contains an object of class \'' . trigger_error(
get_class($_sel) . '\' without __toString() method', E_USER_NOTICE); 'html_checkboxes: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method',
E_USER_NOTICE
);
continue; continue;
} }
} else { } else {
@ -104,42 +105,43 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
if (method_exists($_val, '__toString')) { if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string)$_val->__toString()); $selected = smarty_function_escape_special_chars((string)$_val->__toString());
} else { } else {
trigger_error('html_checkboxes: selected attribute is an object of class \'' . get_class($_val) . trigger_error(
'\' without __toString() method', E_USER_NOTICE); 'html_checkboxes: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method',
E_USER_NOTICE
);
} }
} else { } else {
$selected = smarty_function_escape_special_chars((string)$_val); $selected = smarty_function_escape_special_chars((string)$_val);
} }
break; break;
case 'checkboxes': case 'checkboxes':
trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', trigger_error(
E_USER_WARNING); 'html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead',
E_USER_WARNING
);
$options = (array)$_val; $options = (array)$_val;
break; break;
case 'assign': case 'assign':
break; break;
case 'strict': case 'strict':
break; break;
case 'disabled': case 'disabled':
case 'readonly': case 'readonly':
if (!empty($params[ 'strict' ])) { if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) { 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", trigger_error(
E_USER_NOTICE); "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) { if ($_val === true || $_val === $_key) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
} }
break; break;
} }
// omit break; to fall through! // omit break; to fall through!
// no break
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) . '"';
@ -149,34 +151,49 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
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($name, $_key, $_val, $selected, $extra, $separator, $labels, smarty_function_html_checkboxes_output(
$label_ids, $escape); $name,
$_key,
$_val,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape
);
} }
} else { } else {
foreach ($values as $_i => $_key) { foreach ($values as $_i => $_key) {
$_val = isset($output[ $_i ]) ? $output[ $_i ] : ''; $_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
$_html_result[] = $_html_result[] =
smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, smarty_function_html_checkboxes_output(
$label_ids, $escape); $name,
$_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
@ -190,59 +207,69 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
* *
* @return string * @return string
*/ */
function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, function smarty_function_html_checkboxes_output(
$label_ids, $escape = true) $name,
{ $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('html_options: value is an object of class \'' . get_class($value) . trigger_error(
'\' without __toString() method', E_USER_NOTICE); 'html_options: value is an object of class \'' . get_class($value) .
'\' 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('html_options: output is an object of class \'' . get_class($output) . trigger_error(
'\' without __toString() method', E_USER_NOTICE); 'html_options: output is an object of class \'' . get_class($output) .
'\' 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(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', $_id = smarty_function_escape_special_chars(
$name . '_' . $value)); preg_replace(
'![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER,
'_',
$name . '_' . $value
)
);
$_output .= '<label for="' . $_id . '">'; $_output .= '<label for="' . $_id . '">';
} else { } else {
$_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"';
@ -250,13 +277,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;
} }

@ -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
@ -22,7 +21,6 @@
* - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT * - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT
* - path_prefix - prefix for path output (optional, default empty) * - path_prefix - prefix for path output (optional, default empty)
* *
*
* @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image} * @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image}
* (Smarty online manual) * (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
@ -38,9 +36,14 @@
*/ */
function smarty_function_html_image($params, Smarty_Internal_Template $template) function smarty_function_html_image($params, Smarty_Internal_Template $template)
{ {
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', $template->_checkPlugins(
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); array(
array(
'function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
)
)
);
$alt = ''; $alt = '';
$file = ''; $file = '';
$height = ''; $height = '';
@ -60,53 +63,50 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template)
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", E_USER_NOTICE); throw new SmartyException(
"html_image: extra attribute '{$_key}' cannot be an array",
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: 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 {
throw new SmartyException ("html_image: extra attribute '{$_key}' cannot be an array", 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, …)
@ -120,25 +120,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 ];
} }
@ -146,7 +141,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
@ -159,7 +153,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;
} }

@ -21,7 +21,6 @@
* - id (optional) - string default not set * - id (optional) - string default not set
* - class (optional) - string default not set * - class (optional) - string default not set
* *
*
* @link http://www.smarty.net/manual/en/language.function.html.options.php {html_image} * @link http://www.smarty.net/manual/en/language.function.html.options.php {html_image}
* (Smarty online manual) * (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
@ -37,9 +36,14 @@
*/ */
function smarty_function_html_options($params, Smarty_Internal_Template $template) function smarty_function_html_options($params, Smarty_Internal_Template $template)
{ {
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', $template->_checkPlugins(
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); array(
array(
'function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
)
)
);
$name = null; $name = null;
$values = null; $values = null;
$options = null; $options = null;
@ -47,9 +51,7 @@ 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':
@ -57,16 +59,13 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
case 'id': case 'id':
$$_key = (string)$_val; $$_key = (string)$_val;
break; break;
case 'options': case 'options':
$options = (array)$_val; $options = (array)$_val;
break; break;
case 'values': case 'values':
case 'output': case 'output':
$$_key = array_values((array)$_val); $$_key = array_values((array)$_val);
break; break;
case 'selected': case 'selected':
if (is_array($_val)) { if (is_array($_val)) {
$selected = array(); $selected = array();
@ -75,8 +74,11 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
if (method_exists($_sel, '__toString')) { if (method_exists($_sel, '__toString')) {
$_sel = smarty_function_escape_special_chars((string)$_sel->__toString()); $_sel = smarty_function_escape_special_chars((string)$_sel->__toString());
} else { } else {
trigger_error('html_options: selected attribute contains an object of class \'' . trigger_error(
get_class($_sel) . '\' without __toString() method', E_USER_NOTICE); 'html_options: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method',
E_USER_NOTICE
);
continue; continue;
} }
} else { } else {
@ -88,33 +90,34 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
if (method_exists($_val, '__toString')) { if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string)$_val->__toString()); $selected = smarty_function_escape_special_chars((string)$_val->__toString());
} else { } else {
trigger_error('html_options: selected attribute is an object of class \'' . get_class($_val) . trigger_error(
'\' without __toString() method', E_USER_NOTICE); 'html_options: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method',
E_USER_NOTICE
);
} }
} else { } else {
$selected = smarty_function_escape_special_chars((string)$_val); $selected = smarty_function_escape_special_chars((string)$_val);
} }
break; break;
case 'strict': case 'strict':
break; break;
case 'disabled': case 'disabled':
case 'readonly': case 'readonly':
if (!empty($params[ 'strict' ])) { if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) { 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", trigger_error(
E_USER_NOTICE); "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) { if ($_val === true || $_val === $_key) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
} }
break; break;
} }
// omit break; to fall through! // omit break; to fall through!
// no break
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) . '"';
@ -124,16 +127,12 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
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);
@ -144,7 +143,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 . '"' : '';
@ -152,9 +150,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
@ -183,9 +181,11 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
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('html_options: value is an object of class \'' . get_class($value) . trigger_error(
'\' without __toString() method', E_USER_NOTICE); 'html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method',
E_USER_NOTICE
);
return ''; return '';
} }
} else { } else {
@ -196,13 +196,19 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
} else { } else {
$_idx = 0; $_idx = 0;
$_html_result = $_html_result =
smarty_function_html_options_optgroup($key, $value, $selected, !empty($id) ? ($id . '-' . $idx) : null, smarty_function_html_options_optgroup(
$class, $_idx); $key,
$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
@ -220,6 +226,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;
} }

@ -29,7 +29,6 @@
* {html_radios values=$ids name='box' separator='<br>' output=$names} * {html_radios values=$ids name='box' separator='<br>' output=$names}
* {html_radios values=$ids checked=$checked separator='<br>' output=$names} * {html_radios values=$ids checked=$checked separator='<br>' output=$names}
* *
*
* @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios} * @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios}
* (Smarty online manual) * (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com> * @author Christopher Kvarme <christopher.kvarme@flashjab.com>
@ -45,9 +44,14 @@
*/ */
function smarty_function_html_radios($params, Smarty_Internal_Template $template) function smarty_function_html_radios($params, Smarty_Internal_Template $template)
{ {
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', $template->_checkPlugins(
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); array(
array(
'function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
)
)
);
$name = 'radio'; $name = 'radio';
$values = null; $values = null;
$options = null; $options = null;
@ -58,14 +62,12 @@ 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; break;
case 'checked': case 'checked':
case 'selected': case 'selected':
if (is_array($_val)) { if (is_array($_val)) {
@ -74,57 +76,55 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
if (method_exists($_val, '__toString')) { if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string)$_val->__toString()); $selected = smarty_function_escape_special_chars((string)$_val->__toString());
} else { } else {
trigger_error('html_radios: selected attribute is an object of class \'' . get_class($_val) . trigger_error(
'\' without __toString() method', E_USER_NOTICE); 'html_radios: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method',
E_USER_NOTICE
);
} }
} else { } else {
$selected = (string)$_val; $selected = (string)$_val;
} }
break; break;
case 'escape': case 'escape':
case 'labels': case 'labels':
case 'label_ids': case 'label_ids':
$$_key = (bool)$_val; $$_key = (bool)$_val;
break; break;
case 'options': case 'options':
$$_key = (array)$_val; $$_key = (array)$_val;
break; break;
case 'values': case 'values':
case 'output': case 'output':
$$_key = array_values((array)$_val); $$_key = array_values((array)$_val);
break; break;
case 'radios': case 'radios':
trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', trigger_error(
E_USER_WARNING); 'html_radios: the use of the "radios" attribute is deprecated, use "options" instead',
E_USER_WARNING
);
$options = (array)$_val; $options = (array)$_val;
break; break;
case 'assign': case 'assign':
break; break;
case 'strict': case 'strict':
break; break;
case 'disabled': case 'disabled':
case 'readonly': case 'readonly':
if (!empty($params[ 'strict' ])) { if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) { 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", trigger_error(
E_USER_NOTICE); "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) { if ($_val === true || $_val === $_key) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
} }
break; break;
} }
// omit break; to fall through! // omit break; to fall through!
// no break
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) . '"';
@ -134,36 +134,50 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
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($name, $_key, $_val, $selected, $extra, $separator, $labels, smarty_function_html_radios_output(
$label_ids, $escape); $name,
$_key,
$_val,
$selected,
$extra,
$separator,
$labels,
$label_ids,
$escape
);
} }
} else { } else {
foreach ($values as $_i => $_key) { foreach ($values as $_i => $_key) {
$_val = isset($output[ $_i ]) ? $output[ $_i ] : ''; $_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
$_html_result[] = $_html_result[] =
smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, smarty_function_html_radios_output(
$label_ids, $escape); $name,
$_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
@ -177,69 +191,76 @@ 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(
$escape) $name,
{ $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('html_options: value is an object of class \'' . get_class($value) . trigger_error(
'\' without __toString() method', E_USER_NOTICE); 'html_options: value is an object of class \'' . get_class($value) .
'\' 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('html_options: output is an object of class \'' . get_class($output) . trigger_error(
'\' without __toString() method', E_USER_NOTICE); 'html_options: output is an object of class \'' . get_class($output) .
'\' 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(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', $_id = smarty_function_escape_special_chars(
$name . '_' . $value)); preg_replace(
'![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER,
'_',
$name . '_' . $value
)
);
$_output .= '<label for="' . $_id . '">'; $_output .= '<label for="' . $_id . '">';
} else { } else {
$_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;
} }

@ -28,7 +28,6 @@
* - 2.0 complete rewrite for performance, * - 2.0 complete rewrite for performance,
* added attributes month_names, *_id * added attributes month_names, *_id
* *
*
* @link http://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date} * @link http://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date}
* (Smarty online manual) * (Smarty online manual)
* @version 2.0 * @version 2.0
@ -45,8 +44,14 @@
*/ */
function smarty_function_html_select_date($params, Smarty_Internal_Template $template) function smarty_function_html_select_date($params, Smarty_Internal_Template $template)
{ {
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', $template->_checkPlugins(
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); array(
array(
'function' => 'smarty_function_escape_special_chars',
'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;
static $_current_year = null; static $_current_year = null;
@ -57,7 +62,6 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$_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;
@ -106,17 +110,21 @@ 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(array(array('function' => 'smarty_make_timestamp', $template->_checkPlugins(
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'))); array(
array(
'function' => 'smarty_make_timestamp',
'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;
@ -124,7 +132,6 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
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 'prefix':
case 'field_array': case 'field_array':
case 'start_year': case 'start_year':
@ -153,7 +160,6 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
case 'year_id': case 'year_id':
$$_key = (string)$_value; $$_key = (string)$_value;
break; break;
case 'display_days': case 'display_days':
case 'display_months': case 'display_months':
case 'display_years': case 'display_years':
@ -161,7 +167,6 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
case 'reverse_years': case 'reverse_years':
$$_key = (bool)$_value; $$_key = (bool)$_value;
break; break;
default: default:
if (!is_array($_value)) { if (!is_array($_value)) {
$extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"'; $extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"';
@ -171,15 +176,16 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
break; 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' ])) {
if (isset($params[ 'time' ][ $prefix . 'Year' ])) { if (isset($params[ 'time' ][ $prefix . 'Year' ])) {
// $_REQUEST[$field_array] given // $_REQUEST[$field_array] given
foreach (array('Y' => 'Year', foreach (array(
'Y' => 'Year',
'm' => 'Month', 'm' => 'Month',
'd' => 'Day') as $_elementKey => $_elementName) { 'd' => 'Day'
) as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName); $_variableName = '_' . strtolower($_elementName);
$$_variableName = $$_variableName =
isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] : isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
@ -187,9 +193,11 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
} }
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Year' ])) { } elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Year' ])) {
// $_REQUEST given // $_REQUEST given
foreach (array('Y' => 'Year', foreach (array(
'Y' => 'Year',
'm' => 'Month', 'm' => 'Month',
'd' => 'Day') as $_elementKey => $_elementName) { 'd' => 'Day'
) as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName); $_variableName = '_' . strtolower($_elementName);
$$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ? $$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
$params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey); $params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
@ -207,11 +215,12 @@ 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(
'end') as $key) { 'start',
'end'
) as $key) {
$key .= '_year'; $key .= '_year';
$t = $$key; $t = $$key;
if ($t === null) { if ($t === null) {
@ -224,14 +233,12 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$$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 = '';
@ -242,7 +249,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 .
@ -250,31 +256,29 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
} else { } else {
$_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($year_id !== null ? $_html_years .= ' id="' . smarty_function_escape_special_chars(
$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 = '';
@ -285,24 +289,23 @@ 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($month_id !== null ? $_html_months .= ' id="' . smarty_function_escape_special_chars(
$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 ]) :
@ -311,10 +314,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 = '';
@ -325,23 +326,22 @@ 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($day_id !== null ? ($day_id ? $day_id : $_name) : smarty_function_escape_special_chars(
($all_id ? ($all_id . $_name) : $_name)) . '"'; $day_id !== null ? ($day_id ? $day_id : $_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);
@ -349,10 +349,8 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$_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++) {
@ -366,7 +364,6 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$_html .= $_html_years; $_html .= $_html_years;
} }
break; break;
case 'm': case 'm':
case 'M': case 'M':
if (isset($_html_months)) { if (isset($_html_months)) {
@ -376,7 +373,6 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$_html .= $_html_months; $_html .= $_html_months;
} }
break; break;
case 'd': case 'd':
case 'D': case 'D':
if (isset($_html_days)) { if (isset($_html_days)) {
@ -388,6 +384,5 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
break; break;
} }
} }
return $_html; return $_html;
} }

@ -26,88 +26,86 @@
*/ */
function smarty_function_html_select_time($params, Smarty_Internal_Template $template) function smarty_function_html_select_time($params, Smarty_Internal_Template $template)
{ {
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', $template->_checkPlugins(
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); array(
array(
'function' => 'smarty_function_escape_special_chars',
'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(array(array('function' => 'smarty_make_timestamp', $template->_checkPlugins(
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'))); array(
array(
'function' => 'smarty_make_timestamp',
'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 'field_separator':
case 'option_separator': case 'option_separator':
case 'all_extra': case 'all_extra':
case 'hour_extra': case 'hour_extra':
case 'minute_extra': case 'minute_extra':
case 'second_extra': case 'second_extra':
case 'meridian_extra': case 'meridian_extra':
case 'all_empty': case 'all_empty':
case 'hour_empty': case 'hour_empty':
case 'minute_empty': case 'minute_empty':
case 'second_empty': case 'second_empty':
case 'meridian_empty': case 'meridian_empty':
case 'all_id': case 'all_id':
case 'hour_id': case 'hour_id':
case 'minute_id': case 'minute_id':
case 'second_id': case 'second_id':
case 'meridian_id': case 'meridian_id':
case 'hour_format': case 'hour_format':
case 'hour_value_format': case 'hour_value_format':
case 'minute_format': case 'minute_format':
@ -116,7 +114,6 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
case 'second_value_format': case 'second_value_format':
$$_key = (string)$_value; $$_key = (string)$_value;
break; break;
case 'display_hours': case 'display_hours':
case 'display_minutes': case 'display_minutes':
case 'display_seconds': case 'display_seconds':
@ -124,17 +121,14 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
case 'use_24_hours': case 'use_24_hours':
$$_key = (bool)$_value; $$_key = (bool)$_value;
break; break;
case 'minute_interval': case 'minute_interval':
case 'second_interval': case 'second_interval':
case 'hour_size': case 'hour_size':
case 'minute_size': case 'minute_size':
case 'second_size': case 'second_size':
case 'meridian_size': case 'meridian_size':
$$_key = (int)$_value; $$_key = (int)$_value;
break; break;
default: default:
if (!is_array($_value)) { if (!is_array($_value)) {
$extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"'; $extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"';
@ -144,13 +138,14 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
break; 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
foreach (array('H' => 'Hour', foreach (array(
'H' => 'Hour',
'i' => 'Minute', 'i' => 'Minute',
's' => 'Second') as $_elementKey => $_elementName) { 's' => 'Second'
) as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName); $_variableName = '_' . strtolower($_elementName);
$$_variableName = $$_variableName =
isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] : isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
@ -163,9 +158,11 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time)); list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Hour' ])) { } elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Hour' ])) {
// $_REQUEST given // $_REQUEST given
foreach (array('H' => 'Hour', foreach (array(
'H' => 'Hour',
'i' => 'Minute', 'i' => 'Minute',
's' => 'Second') as $_elementKey => $_elementName) { 's' => 'Second'
) as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName); $_variableName = '_' . strtolower($_elementName);
$$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ? $$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
$params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey); $params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
@ -187,7 +184,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 = '';
@ -199,42 +195,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($hour_id !== null ? ($hour_id ? $hour_id : $_name) : smarty_function_escape_special_chars(
($all_id ? ($all_id . $_name) : $_name)) . '"'; $hour_id !== null ? ($hour_id ? $hour_id : $_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 = '';
@ -246,24 +237,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($minute_id !== null ? $_html_minutes .= ' id="' . smarty_function_escape_special_chars(
$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);
@ -272,10 +262,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 = '';
@ -287,24 +275,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($second_id !== null ? $_html_seconds .= ' id="' . smarty_function_escape_special_chars(
$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);
@ -313,10 +300,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 = '';
@ -328,36 +313,36 @@ 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($meridian_id !== null ? $_html_meridian .= ' id="' . smarty_function_escape_special_chars(
$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',
'_html_seconds', '_html_seconds',
'_html_meridian') as $k) { '_html_meridian'
) as $k) {
if (isset($$k)) { if (isset($$k)) {
if ($_html) { if ($_html) {
$_html .= $field_separator; $_html .= $field_separator;
@ -365,6 +350,5 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
$_html .= $$k; $_html .= $$k;
} }
} }
return $_html; return $_html;
} }

@ -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
@ -35,7 +34,6 @@
* {table loop=$data cols=4 tr_attr='"bgcolor=red"'} * {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
* {table loop=$data cols="first,second,third" tr_attr=$colors} * {table loop=$data cols="first,second,third" tr_attr=$colors}
* *
*
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Messju Mohr <messju at lammfellpuschen dot de> * @author credit to Messju Mohr <messju at lammfellpuschen dot de>
* @author credit to boots <boots dot smarty at yahoo dot com> * @author credit to boots <boots dot smarty at yahoo dot com>
@ -61,19 +59,15 @@ 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;
@ -87,11 +81,9 @@ function smarty_function_html_table($params)
$cols_count = $cols; $cols_count = $cols;
} }
break; break;
case 'rows': case 'rows':
$$_key = (int)$_value; $$_key = (int)$_value;
break; break;
case 'table_attr': case 'table_attr':
case 'trailpad': case 'trailpad':
case 'hdir': case 'hdir':
@ -100,7 +92,6 @@ function smarty_function_html_table($params)
case 'caption': case 'caption':
$$_key = (string)$_value; $$_key = (string)$_value;
break; break;
case 'tr_attr': case 'tr_attr':
case 'td_attr': case 'td_attr':
case 'th_attr': case 'th_attr':
@ -108,7 +99,6 @@ function smarty_function_html_table($params)
break; break;
} }
} }
$loop_count = count($loop); $loop_count = count($loop);
if (empty($params[ 'rows' ])) { if (empty($params[ 'rows' ])) {
/* no rows specified */ /* no rows specified */
@ -119,17 +109,13 @@ 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 ];
@ -137,19 +123,16 @@ function smarty_function_html_table($params)
} }
$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 {
@ -160,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
@ -177,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 : '';
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {mailto} function plugin * Smarty {mailto} function plugin
* Type: function * Type: function
@ -37,7 +36,6 @@
* {mailto address="me@domain.com" cc="you@domain.com,they@domain.com"} * {mailto address="me@domain.com" cc="you@domain.com,they@domain.com"}
* {mailto address="me@domain.com" extra='class="mailto"'} * {mailto address="me@domain.com" extra='class="mailto"'}
* *
*
* @link http://www.smarty.net/manual/en/language.function.mailto.php {mailto} * @link http://www.smarty.net/manual/en/language.function.mailto.php {mailto}
* (Smarty online manual) * (Smarty online manual)
* @version 1.2 * @version 1.2
@ -53,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.
@ -77,57 +72,48 @@ function smarty_function_mailto($params)
$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 'extra':
case 'text': case 'text':
$$var = $value; $$var = $value;
// no break
default: 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("mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex", trigger_error(
E_USER_WARNING); "mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex",
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 = '';
@ -142,9 +128,7 @@ function smarty_function_mailto($params)
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

@ -6,7 +6,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {math} function plugin * Smarty {math} function plugin
* Type: function * Type: function
@ -25,66 +24,71 @@
function smarty_function_math($params, $template) function smarty_function_math($params, $template)
{ {
static $_allowed_funcs = static $_allowed_funcs =
array('int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true, array(
'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true, 'rand' => true, 'int' => true,
'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true); 'abs' => true,
'ceil' => true,
'cos' => true,
'exp' => true,
'floor' => true,
'log' => true,
'log10' => true,
'max' => true,
'min' => true,
'pi' => true,
'pow' => true,
'rand' => true,
'round' => true,
'sin' => true,
'sqrt' => true,
'srand' => true,
'tan' => true
);
// be sure equation parameter is present // be sure equation parameter is present
if (empty($params[ 'equation' ])) { if (empty($params[ 'equation' ])) {
trigger_error("math: missing equation parameter", E_USER_WARNING); trigger_error("math: missing equation parameter", E_USER_WARNING);
return; return;
} }
$equation = $params[ 'equation' ]; $equation = $params[ 'equation' ];
// make sure parenthesis are balanced // make sure parenthesis are balanced
if (substr_count($equation, '(') !== substr_count($equation, ')')) { if (substr_count($equation, '(') !== substr_count($equation, ')')) {
trigger_error("math: unbalanced parenthesis", E_USER_WARNING); trigger_error("math: unbalanced parenthesis", E_USER_WARNING);
return; return;
} }
// disallow backticks // disallow backticks
if (strpos($equation, '`') !== false) { if (strpos($equation, '`') !== false) {
trigger_error("math: backtick character not allowed in equation", E_USER_WARNING); trigger_error("math: backtick character not allowed in equation", E_USER_WARNING);
return; return;
} }
// also disallow dollar signs // also disallow dollar signs
if (strpos($equation, '$') !== false) { if (strpos($equation, '$') !== false) {
trigger_error("math: dollar signs not allowed in equation", E_USER_WARNING); trigger_error("math: dollar signs not allowed in equation", E_USER_WARNING);
return; return;
} }
foreach ($params as $key => $val) { foreach ($params as $key => $val) {
if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') { if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') {
// make sure value is not empty // make sure value is not empty
if (strlen($val) === 0) { if (strlen($val) === 0) {
trigger_error("math: parameter '{$key}' is empty", E_USER_WARNING); trigger_error("math: parameter '{$key}' is empty", E_USER_WARNING);
return; return;
} }
if (!is_numeric($val)) { if (!is_numeric($val)) {
trigger_error("math: parameter '{$key}' is not numeric", E_USER_WARNING); trigger_error("math: parameter '{$key}' is not numeric", E_USER_WARNING);
return; return;
} }
} }
} }
// match all vars in equation, make sure all are passed // match all vars in equation, make sure all are passed
preg_match_all('!(?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)!', $equation, $match); preg_match_all('!(?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)!', $equation, $match);
foreach ($match[ 1 ] as $curr_var) { foreach ($match[ 1 ] as $curr_var) {
if ($curr_var && !isset($params[ $curr_var ]) && !isset($_allowed_funcs[ $curr_var ])) { if ($curr_var && !isset($params[ $curr_var ]) && !isset($_allowed_funcs[ $curr_var ])) {
trigger_error("math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'", E_USER_WARNING); trigger_error(
"math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'",
E_USER_WARNING
);
return; return;
} }
} }
foreach ($params as $key => $val) { foreach ($params as $key => $val) {
if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') { if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') {
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation); $equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
@ -92,7 +96,6 @@ function smarty_function_math($params, $template)
} }
$smarty_math_result = null; $smarty_math_result = null;
eval("\$smarty_math_result = " . $equation . ";"); eval("\$smarty_math_result = " . $equation . ";");
if (empty($params[ 'format' ])) { if (empty($params[ 'format' ])) {
if (empty($params[ 'assign' ])) { if (empty($params[ 'assign' ])) {
return $smarty_math_result; return $smarty_math_result;

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifier * @subpackage PluginsModifier
*/ */
/** /**
* Smarty capitalize modifier plugin * Smarty capitalize modifier plugin
* Type: modifier * Type: modifier
@ -29,50 +28,75 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
$upper_string = mb_convert_case($string, MB_CASE_TITLE, Smarty::$_CHARSET); $upper_string = mb_convert_case($string, MB_CASE_TITLE, Smarty::$_CHARSET);
} else { } else {
// uppercase word breaks // uppercase word breaks
$upper_string = preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, $upper_string = preg_replace_callback(
'smarty_mod_cap_mbconvert_cb', $string); "!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER,
'smarty_mod_cap_mbconvert_cb',
$string
);
} }
// check uc_digits case // check uc_digits case
if (!$uc_digits) { if (!$uc_digits) {
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, if (preg_match_all(
PREG_OFFSET_CAPTURE)) { "!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER,
$string,
$matches,
PREG_OFFSET_CAPTURE
)
) {
foreach ($matches[ 1 ] as $match) { foreach ($matches[ 1 ] as $match) {
$upper_string = $upper_string =
substr_replace($upper_string, mb_strtolower($match[ 0 ], Smarty::$_CHARSET), $match[ 1 ], substr_replace(
strlen($match[ 0 ])); $upper_string,
mb_strtolower($match[ 0 ], Smarty::$_CHARSET),
$match[ 1 ],
strlen($match[ 0 ])
);
} }
} }
} }
$upper_string = $upper_string =
preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert2_cb', preg_replace_callback(
$upper_string); "!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER,
'smarty_mod_cap_mbconvert2_cb',
$upper_string
);
return $upper_string; return $upper_string;
} }
// lowercase first // lowercase first
if ($lc_rest) { if ($lc_rest) {
$string = strtolower($string); $string = strtolower($string);
} }
// uppercase (including hyphenated words) // uppercase (including hyphenated words)
$upper_string = $upper_string =
preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst_cb', preg_replace_callback(
$string); "!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER,
'smarty_mod_cap_ucfirst_cb',
$string
);
// check uc_digits case // check uc_digits case
if (!$uc_digits) { if (!$uc_digits) {
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, if (preg_match_all(
PREG_OFFSET_CAPTURE)) { "!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER,
$string,
$matches,
PREG_OFFSET_CAPTURE
)
) {
foreach ($matches[ 1 ] as $match) { foreach ($matches[ 1 ] as $match) {
$upper_string = $upper_string =
substr_replace($upper_string, strtolower($match[ 0 ]), $match[ 1 ], strlen($match[ 0 ])); substr_replace($upper_string, strtolower($match[ 0 ]), $match[ 1 ], strlen($match[ 0 ]));
} }
} }
} }
$upper_string = preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst2_cb', $upper_string = preg_replace_callback(
$upper_string); "!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER,
'smarty_mod_cap_ucfirst2_cb',
$upper_string
);
return $upper_string; return $upper_string;
} }
/* /**
* *
* Bug: create_function() use exhausts memory when used in long loops * Bug: create_function() use exhausts memory when used in long loops
* Fix: use declared functions for callbacks instead of using create_function() * Fix: use declared functions for callbacks instead of using create_function()
@ -89,6 +113,7 @@ function smarty_mod_cap_mbconvert_cb($matches)
{ {
return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 2 ]), MB_CASE_UPPER, Smarty::$_CHARSET); return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 2 ]), MB_CASE_UPPER, Smarty::$_CHARSET);
} }
/** /**
* @param $matches * @param $matches
* *
@ -98,6 +123,7 @@ function smarty_mod_cap_mbconvert2_cb($matches)
{ {
return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 3 ]), MB_CASE_UPPER, Smarty::$_CHARSET); return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 3 ]), MB_CASE_UPPER, Smarty::$_CHARSET);
} }
/** /**
* @param $matches * @param $matches
* *
@ -107,6 +133,7 @@ function smarty_mod_cap_ucfirst_cb($matches)
{ {
return stripslashes($matches[ 1 ]) . ucfirst(stripslashes($matches[ 2 ])); return stripslashes($matches[ 1 ]) . ucfirst(stripslashes($matches[ 2 ]));
} }
/** /**
* @param $matches * @param $matches
* *

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifier * @subpackage PluginsModifier
*/ */
/** /**
* Smarty date_format modifier plugin * Smarty date_format modifier plugin
* Type: modifier * Type: modifier
@ -38,7 +37,7 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
static $is_loaded = false; static $is_loaded = false;
if (!$is_loaded) { if (!$is_loaded) {
if (!is_callable('smarty_make_timestamp')) { if (!is_callable('smarty_make_timestamp')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); include_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
} }
$is_loaded = true; $is_loaded = true;
} }
@ -51,20 +50,24 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
} }
if ($formatter === 'strftime' || ($formatter === 'auto' && strpos($format, '%') !== false)) { if ($formatter === 'strftime' || ($formatter === 'auto' && strpos($format, '%') !== false)) {
if (Smarty::$_IS_WINDOWS) { if (Smarty::$_IS_WINDOWS) {
$_win_from = array('%D', $_win_from = array(
'%D',
'%h', '%h',
'%n', '%n',
'%r', '%r',
'%R', '%R',
'%t', '%t',
'%T'); '%T'
$_win_to = array('%m/%d/%y', );
$_win_to = array(
'%m/%d/%y',
'%b', '%b',
"\n", "\n",
'%I:%M:%S %p', '%I:%M:%S %p',
'%H:%M', '%H:%M',
"\t", "\t",
'%H:%M:%S'); '%H:%M:%S'
);
if (strpos($format, '%e') !== false) { if (strpos($format, '%e') !== false) {
$_win_from[] = '%e'; $_win_from[] = '%e';
$_win_to[] = sprintf('%\' 2d', date('j', $timestamp)); $_win_to[] = sprintf('%\' 2d', date('j', $timestamp));
@ -75,7 +78,6 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
} }
$format = str_replace($_win_from, $_win_to, $format); $format = str_replace($_win_from, $_win_to, $format);
} }
return strftime($format, $timestamp); return strftime($format, $timestamp);
} else { } else {
return date($format, $timestamp); return date($format, $timestamp);

@ -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
@ -38,7 +37,6 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$depth--; $depth--;
} }
break; break;
case 'object': case 'object':
$object_vars = get_object_vars($var); $object_vars = get_object_vars($var);
$results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>'; $results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
@ -56,7 +54,6 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$depth--; $depth--;
} }
break; break;
case 'boolean': case 'boolean':
case 'NULL': case 'NULL':
case 'resource': case 'resource':
@ -71,12 +68,10 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
} }
$results = '<i>' . $results . '</i>'; $results = '<i>' . $results . '</i>';
break; break;
case 'integer': case 'integer':
case 'float': case 'float':
$results = htmlspecialchars((string)$var); $results = htmlspecialchars((string)$var);
break; break;
case 'string': case 'string':
$results = strtr($var, $_replace); $results = strtr($var, $_replace);
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
@ -88,10 +83,8 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$results = substr($var, 0, $length - 3) . '...'; $results = substr($var, 0, $length - 3) . '...';
} }
} }
$results = htmlspecialchars('"' . $results . '"', ENT_QUOTES, Smarty::$_CHARSET); $results = htmlspecialchars('"' . $results . '"', ENT_QUOTES, Smarty::$_CHARSET);
break; break;
case 'unknown type': case 'unknown type':
default: default:
$results = strtr((string)$var, $_replace); $results = strtr((string)$var, $_replace);
@ -104,9 +97,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$results = substr($results, 0, $length - 3) . '...'; $results = substr($results, 0, $length - 3) . '...';
} }
} }
$results = htmlspecialchars($results, ENT_QUOTES, Smarty::$_CHARSET); $results = htmlspecialchars($results, ENT_QUOTES, Smarty::$_CHARSET);
} }
return $results; return $results;
} }

@ -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,11 +29,9 @@ 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) { if ($_double_encode) {
@ -48,14 +45,21 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// 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 = str_replace(array('%%%SMARTY_START%%%', $string = str_replace(
'%%%SMARTY_END%%%'), array('&', array(
';'), $string); '%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'
),
array(
'&',
';'
),
$string
);
return $string; return $string;
} }
} }
// no break
case 'htmlall': case 'htmlall':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
// mb_convert_encoding ignores htmlspecialchars() // mb_convert_encoding ignores htmlspecialchars()
@ -71,18 +75,23 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
$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(array('%%%SMARTY_START%%%', str_replace(
'%%%SMARTY_END%%%'), array('&', array(
';'), $string); '%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'
),
array(
'&',
';'
),
$string
);
return $string; return $string;
} }
} }
// htmlentities() won't convert everything, so use mb_convert_encoding // htmlentities() won't convert everything, so use mb_convert_encoding
return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set); return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set);
} }
// no MBString fallback // no MBString fallback
if ($_double_encode) { if ($_double_encode) {
return htmlentities($string, ENT_QUOTES, $char_set, $double_encode); return htmlentities($string, ENT_QUOTES, $char_set, $double_encode);
@ -92,24 +101,28 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
} else { } else {
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlentities($string, ENT_QUOTES, $char_set); $string = htmlentities($string, ENT_QUOTES, $char_set);
$string = str_replace(array('%%%SMARTY_START%%%', $string = str_replace(
'%%%SMARTY_END%%%'), array('&', array(
';'), $string); '%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'
),
array(
'&',
';'
),
$string
);
return $string; return $string;
} }
} }
// no break
case 'url': case 'url':
return rawurlencode($string); return rawurlencode($string);
case 'urlpathinfo': case 'urlpathinfo':
return str_replace('%2F', '/', rawurlencode($string)); return str_replace('%2F', '/', rawurlencode($string));
case 'quotes': case 'quotes':
// escape unescaped single quotes // escape unescaped single quotes
return preg_replace("%(?<!\\\\)'%", "\\'", $string); return preg_replace("%(?<!\\\\)'%", "\\'", $string);
case 'hex': case 'hex':
// escape every byte into hex // escape every byte into hex
// Note that the UTF-8 encoded character ä will be represented as %c3%a4 // Note that the UTF-8 encoded character ä will be represented as %c3%a4
@ -118,15 +131,13 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
for ($x = 0; $x < $_length; $x++) { for ($x = 0; $x < $_length; $x++) {
$return .= '%' . bin2hex($string[ $x ]); $return .= '%' . bin2hex($string[ $x ]);
} }
return $return; return $return;
case 'hexentity': case 'hexentity':
$return = ''; $return = '';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) { if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) { if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
} }
$is_loaded_1 = true; $is_loaded_1 = true;
} }
@ -134,7 +145,6 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
$return .= '&#x' . strtoupper(dechex($unicode)) . ';'; $return .= '&#x' . strtoupper(dechex($unicode)) . ';';
} }
return $return; return $return;
} }
// no MBString fallback // no MBString fallback
@ -142,15 +152,13 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
for ($x = 0; $x < $_length; $x++) { for ($x = 0; $x < $_length; $x++) {
$return .= '&#x' . bin2hex($string[ $x ]) . ';'; $return .= '&#x' . bin2hex($string[ $x ]) . ';';
} }
return $return; return $return;
case 'decentity': case 'decentity':
$return = ''; $return = '';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) { if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) { if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
} }
$is_loaded_1 = true; $is_loaded_1 = true;
} }
@ -158,7 +166,6 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
$return .= '&#' . $unicode . ';'; $return .= '&#' . $unicode . ';';
} }
return $return; return $return;
} }
// no MBString fallback // no MBString fallback
@ -166,42 +173,59 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
for ($x = 0; $x < $_length; $x++) { for ($x = 0; $x < $_length; $x++) {
$return .= '&#' . ord($string[ $x ]) . ';'; $return .= '&#' . ord($string[ $x ]) . ';';
} }
return $return; return $return;
case 'javascript': case 'javascript':
// escape quotes and backslashes, newlines, etc. // escape quotes and backslashes, newlines, etc.
return strtr($string, array('\\' => '\\\\', return strtr(
$string,
array(
'\\' => '\\\\',
"'" => "\\'", "'" => "\\'",
'"' => '\\"', '"' => '\\"',
"\r" => '\\r', "\r" => '\\r',
"\n" => '\\n', "\n" => '\\n',
'</' => '<\/')); '</' => '<\/'
)
);
case 'mail': case 'mail':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!$is_loaded_2) { if (!$is_loaded_2) {
if (!is_callable('smarty_mb_str_replace')) { if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); include_once SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php';
} }
$is_loaded_2 = true; $is_loaded_2 = true;
} }
return smarty_mb_str_replace(array('@', return smarty_mb_str_replace(
'.'), array(' [AT] ', array(
' [DOT] '), $string); '@',
'.'
),
array(
' [AT] ',
' [DOT] '
),
$string
);
} }
// no MBString fallback // no MBString fallback
return str_replace(array('@', return str_replace(
'.'), array(' [AT] ', array(
' [DOT] '), $string); '@',
'.'
),
array(
' [AT] ',
' [DOT] '
),
$string
);
case 'nonstd': case 'nonstd':
// escape non-standard chars, such as ms document quotes // escape non-standard chars, such as ms document quotes
$return = ''; $return = '';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) { if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) { if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
} }
$is_loaded_1 = true; $is_loaded_1 = true;
} }
@ -212,10 +236,8 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
$return .= chr($unicode); $return .= chr($unicode);
} }
} }
return $return; return $return;
} }
$_length = strlen($string); $_length = strlen($string);
for ($_i = 0; $_i < $_length; $_i++) { for ($_i = 0; $_i < $_length; $_i++) {
$_ord = ord(substr($string, $_i, 1)); $_ord = ord(substr($string, $_i, 1));
@ -226,9 +248,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
$return .= substr($string, $_i, 1); $return .= substr($string, $_i, 1);
} }
} }
return $return; return $return;
default: default:
return $string; return $string;
} }

@ -11,7 +11,6 @@
* Name: mb_wordwrap * Name: mb_wordwrap
* Purpose: Wrap a string to a given number of characters * Purpose: Wrap a string to a given number of characters
* *
* @link http://php.net/manual/en/function.wordwrap.php for similarity * @link http://php.net/manual/en/function.wordwrap.php for similarity
* *
* @param string $str the string to wrap * @param string $str the string to wrap
@ -30,30 +29,28 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa
$t = ''; $t = '';
$_previous = false; $_previous = false;
$_space = false; $_space = false;
foreach ($tokens as $_token) { foreach ($tokens as $_token) {
$token_length = mb_strlen($_token, Smarty::$_CHARSET); $token_length = mb_strlen($_token, Smarty::$_CHARSET);
$_tokens = array($_token); $_tokens = array($_token);
if ($token_length > $width) { if ($token_length > $width) {
if ($cut) { if ($cut) {
$_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_tokens = preg_split(
'!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER,
$_token, $_token,
-1, -1,
PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE); PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE
);
} }
} }
foreach ($_tokens as $token) { foreach ($_tokens as $token) {
$_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token); $_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token);
$token_length = mb_strlen($token, Smarty::$_CHARSET); $token_length = mb_strlen($token, Smarty::$_CHARSET);
$length += $token_length; $length += $token_length;
if ($length > $width) { if ($length > $width) {
// remove space before inserted break // remove space before inserted break
if ($_previous) { if ($_previous) {
$t = mb_substr($t, 0, -1, Smarty::$_CHARSET); $t = mb_substr($t, 0, -1, Smarty::$_CHARSET);
} }
if (!$_space) { if (!$_space) {
// add the break before the token // add the break before the token
if (!empty($t)) { if (!empty($t)) {
@ -70,6 +67,5 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa
$t .= $token; $t .= $token;
} }
} }
return $t; return $t;
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifier * @subpackage PluginsModifier
*/ */
/** /**
* Smarty regex_replace modifier plugin * Smarty regex_replace modifier plugin
* Type: modifier * Type: modifier
@ -32,7 +31,6 @@ function smarty_modifier_regex_replace($string, $search, $replace, $limit = - 1)
} else { } else {
$search = _smarty_regex_replace_check($search); $search = _smarty_regex_replace_check($search);
} }
return preg_replace($search, $replace, $string, $limit); return preg_replace($search, $replace, $string, $limit);
} }
@ -53,6 +51,5 @@ function _smarty_regex_replace_check($search)
if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[ 1 ], 'e') !== false)) { if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[ 1 ], 'e') !== false)) {
$search = substr($search, 0, -strlen($match[ 1 ])) . preg_replace('![e\s]+!', '', $match[ 1 ]); $search = substr($search, 0, -strlen($match[ 1 ])) . preg_replace('![e\s]+!', '', $match[ 1 ]);
} }
return $search; return $search;
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifier * @subpackage PluginsModifier
*/ */
/** /**
* Smarty replace modifier plugin * Smarty replace modifier plugin
* Type: modifier * Type: modifier
@ -28,12 +27,11 @@ function smarty_modifier_replace($string, $search, $replace)
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!$is_loaded) { if (!$is_loaded) {
if (!is_callable('smarty_mb_str_replace')) { if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); include_once SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php';
} }
$is_loaded = true; $is_loaded = true;
} }
return smarty_mb_str_replace($search, $replace, $string); return smarty_mb_str_replace($search, $replace, $string);
} }
return str_replace($search, $replace, $string); return str_replace($search, $replace, $string);
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifier * @subpackage PluginsModifier
*/ */
/** /**
* Smarty spacify modifier plugin * Smarty spacify modifier plugin
* Type: modifier * Type: modifier

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifier * @subpackage PluginsModifier
*/ */
/** /**
* Smarty truncate modifier plugin * Smarty truncate modifier plugin
* Type: modifier * Type: modifier
@ -30,25 +29,24 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if ($length === 0) { if ($length === 0) {
return ''; return '';
} }
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (mb_strlen($string, Smarty::$_CHARSET) > $length) { if (mb_strlen($string, Smarty::$_CHARSET) > $length) {
$length -= min($length, mb_strlen($etc, Smarty::$_CHARSET)); $length -= min($length, mb_strlen($etc, Smarty::$_CHARSET));
if (!$break_words && !$middle) { if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '', $string = preg_replace(
mb_substr($string, 0, $length + 1, Smarty::$_CHARSET)); '/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER,
'',
mb_substr($string, 0, $length + 1, Smarty::$_CHARSET)
);
} }
if (!$middle) { if (!$middle) {
return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc; return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
} }
return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc .
mb_substr($string, -$length / 2, $length, Smarty::$_CHARSET); mb_substr($string, -$length / 2, $length, Smarty::$_CHARSET);
} }
return $string; return $string;
} }
// no MBString fallback // no MBString fallback
if (isset($string[ $length ])) { if (isset($string[ $length ])) {
$length -= min($length, strlen($etc)); $length -= min($length, strlen($etc));
@ -58,9 +56,7 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if (!$middle) { if (!$middle) {
return substr($string, 0, $length) . $etc; return substr($string, 0, $length) . $etc;
} }
return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2); return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2);
} }
return $string; return $string;
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty cat modifier plugin * Smarty cat modifier plugin
* Type: modifier * Type: modifier

@ -5,14 +5,14 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty count_characters modifier plugin * Smarty count_characters modifier plugin
* Type: modifier * Type: modifier
* Name: count_characters * Name: count_characters
* Purpose: count the number of characters in a text * Purpose: count the number of characters in a text
* *
* @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual) * @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online
* manual)
* @author Uwe Tews * @author Uwe Tews
* *
* @param array $params parameters * @param array $params parameters

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty count_paragraphs modifier plugin * Smarty count_paragraphs modifier plugin
* Type: modifier * Type: modifier

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty count_sentences modifier plugin * Smarty count_sentences modifier plugin
* Type: modifier * Type: modifier

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty count_words modifier plugin * Smarty count_words modifier plugin
* Type: modifier * Type: modifier

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty default modifier plugin * Smarty default modifier plugin
* Type: modifier * Type: modifier
@ -25,11 +24,9 @@ function smarty_modifiercompiler_default($params)
if (!isset($params[ 1 ])) { if (!isset($params[ 1 ])) {
$params[ 1 ] = "''"; $params[ 1 ] = "''";
} }
array_shift($params); array_shift($params);
foreach ($params as $param) { foreach ($params as $param) {
$output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)'; $output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)';
} }
return $output; return $output;
} }

@ -24,21 +24,24 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
{ {
static $_double_encode = null; static $_double_encode = null;
static $is_loaded = false; static $is_loaded = false;
$compiler->template->_checkPlugins(array(array('function' => 'smarty_literal_compiler_param', $compiler->template->_checkPlugins(
'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'))); array(
array(
'function' => 'smarty_literal_compiler_param',
'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) { if ($_double_encode) {
@ -49,7 +52,7 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
} else { } else {
// fall back to modifier.escape.php // fall back to modifier.escape.php
} }
// no break
case 'htmlall': case 'htmlall':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if ($_double_encode) { if ($_double_encode) {
@ -65,7 +68,6 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
// fall back to modifier.escape.php // fall back to modifier.escape.php
} }
} }
// no MBString fallback // no MBString fallback
if ($_double_encode) { if ($_double_encode) {
// php >=5.2.3 - go native // php >=5.2.3 - go native
@ -77,27 +79,23 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
} else { } else {
// fall back to modifier.escape.php // fall back to modifier.escape.php
} }
// no break
case 'url': case 'url':
return 'rawurlencode(' . $params[ 0 ] . ')'; return 'rawurlencode(' . $params[ 0 ] . ')';
case 'urlpathinfo': case 'urlpathinfo':
return 'str_replace("%2F", "/", rawurlencode(' . $params[ 0 ] . '))'; return 'str_replace("%2F", "/", rawurlencode(' . $params[ 0 ] . '))';
case 'quotes': case 'quotes':
// escape unescaped single quotes // escape unescaped single quotes
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[ 0 ] . ')'; return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[ 0 ] . ')';
case 'javascript': case 'javascript':
// escape quotes and backslashes, newlines, etc. // escape quotes and backslashes, newlines, etc.
return 'strtr(' . $params[ 0 ] . 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' ] =
@ -110,6 +108,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) . ')';
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty from_charset modifier plugin * Smarty from_charset modifier plugin
* Type: modifier * Type: modifier
@ -24,10 +23,8 @@ function smarty_modifiercompiler_from_charset($params)
// FIXME: (rodneyrehm) shouldn't this throw an error? // FIXME: (rodneyrehm) shouldn't this throw an error?
return $params[ 0 ]; return $params[ 0 ];
} }
if (!isset($params[ 1 ])) { if (!isset($params[ 1 ])) {
$params[ 1 ] = '"ISO-8859-1"'; $params[ 1 ] = '"ISO-8859-1"';
} }
return 'mb_convert_encoding(' . $params[ 0 ] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[ 1 ] . ')'; return 'mb_convert_encoding(' . $params[ 0 ] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[ 1 ] . ')';
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty indent modifier plugin * Smarty indent modifier plugin
* Type: modifier * Type: modifier
@ -19,7 +18,6 @@
* *
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_indent($params) function smarty_modifiercompiler_indent($params)
{ {
if (!isset($params[ 1 ])) { if (!isset($params[ 1 ])) {
@ -28,6 +26,5 @@ function smarty_modifiercompiler_indent($params)
if (!isset($params[ 2 ])) { if (!isset($params[ 2 ])) {
$params[ 2 ] = "' '"; $params[ 2 ] = "' '";
} }
return 'preg_replace(\'!^!m\',str_repeat(' . $params[ 2 ] . ',' . $params[ 1 ] . '),' . $params[ 0 ] . ')'; return 'preg_replace(\'!^!m\',str_repeat(' . $params[ 2 ] . ',' . $params[ 1 ] . '),' . $params[ 0 ] . ')';
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty lower modifier plugin * Smarty lower modifier plugin
* Type: modifier * Type: modifier
@ -20,7 +19,6 @@
* *
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_lower($params) function smarty_modifiercompiler_lower($params)
{ {
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty noprint modifier plugin * Smarty noprint modifier plugin
* Type: modifier * Type: modifier

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty string_format modifier plugin * Smarty string_format modifier plugin
* Type: modifier * Type: modifier

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty strip modifier plugin * Smarty strip modifier plugin
* Type: modifier * Type: modifier
@ -22,12 +21,10 @@
* *
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_strip($params) function smarty_modifiercompiler_strip($params)
{ {
if (!isset($params[ 1 ])) { if (!isset($params[ 1 ])) {
$params[ 1 ] = "' '"; $params[ 1 ] = "' '";
} }
return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})"; return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})";
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty strip_tags modifier plugin * Smarty strip_tags modifier plugin
* Type: modifier * Type: modifier

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty to_charset modifier plugin * Smarty to_charset modifier plugin
* Type: modifier * Type: modifier
@ -24,10 +23,8 @@ function smarty_modifiercompiler_to_charset($params)
// FIXME: (rodneyrehm) shouldn't this throw an error? // FIXME: (rodneyrehm) shouldn't this throw an error?
return $params[ 0 ]; return $params[ 0 ];
} }
if (!isset($params[ 1 ])) { if (!isset($params[ 1 ])) {
$params[ 1 ] = '"ISO-8859-1"'; $params[ 1 ] = '"ISO-8859-1"';
} }
return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 1 ] . ', "' . addslashes(Smarty::$_CHARSET) . '")'; return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 1 ] . ', "' . addslashes(Smarty::$_CHARSET) . '")';
} }

@ -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,22 +27,17 @@ 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': case 'html':
return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)'; return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)';
case 'url': case 'url':
return 'rawurldecode(' . $params[ 0 ] . ')'; return 'rawurldecode(' . $params[ 0 ] . ')';
default: default:
return $params[ 0 ]; return $params[ 0 ];
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty upper modifier plugin * Smarty upper modifier plugin
* Type: modifier * Type: modifier

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFilter * @subpackage PluginsFilter
*/ */
/** /**
* Smarty trimwhitespace outputfilter plugin * Smarty trimwhitespace outputfilter plugin
* Trim unnecessary whitespace from HTML markup. * Trim unnecessary whitespace from HTML markup.
@ -22,43 +21,46 @@ function smarty_outputfilter_trimwhitespace($source)
$store = array(); $store = array();
$_store = 0; $_store = 0;
$_offset = 0; $_offset = 0;
// Unify Line-Breaks to \n // Unify Line-Breaks to \n
$source = preg_replace('/\015\012|\015|\012/', "\n", $source); $source = preg_replace('/\015\012|\015|\012/', "\n", $source);
// capture Internet Explorer and KnockoutJS Conditional Comments // capture Internet Explorer and KnockoutJS Conditional Comments
if (preg_match_all('#<!--((\[[^\]]+\]>.*?<!\[[^\]]+\])|(\s*/?ko\s+.+))-->#is', $source, $matches, if (preg_match_all(
PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { '#<!--((\[[^\]]+\]>.*?<!\[[^\]]+\])|(\s*/?ko\s+.+))-->#is',
$source,
$matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
)
) {
foreach ($matches as $match) { foreach ($matches as $match) {
$store[] = $match[ 0 ][ 0 ]; $store[] = $match[ 0 ][ 0 ];
$_length = strlen($match[ 0 ][ 0 ]); $_length = strlen($match[ 0 ][ 0 ]);
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
$source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length); $source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
$_offset += $_length - strlen($replace); $_offset += $_length - strlen($replace);
$_store++; $_store++;
} }
} }
// Strip all HTML-Comments // Strip all HTML-Comments
// yes, even the ones in <script> - see http://stackoverflow.com/a/808850/515124 // yes, even the ones in <script> - see http://stackoverflow.com/a/808850/515124
$source = preg_replace('#<!--.*?-->#ms', '', $source); $source = preg_replace('#<!--.*?-->#ms', '', $source);
// capture html elements not to be messed with // capture html elements not to be messed with
$_offset = 0; $_offset = 0;
if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is', if (preg_match_all(
$source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { '#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is',
$source,
$matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
)
) {
foreach ($matches as $match) { foreach ($matches as $match) {
$store[] = $match[ 0 ][ 0 ]; $store[] = $match[ 0 ][ 0 ];
$_length = strlen($match[ 0 ][ 0 ]); $_length = strlen($match[ 0 ][ 0 ]);
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
$source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length); $source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
$_offset += $_length - strlen($replace); $_offset += $_length - strlen($replace);
$_store++; $_store++;
} }
} }
$expressions = array(// replace multiple spaces between tags by a single space $expressions = array(// replace multiple spaces between tags by a single space
// can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements // can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements
'#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2', '#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
@ -66,24 +68,22 @@ function smarty_outputfilter_trimwhitespace($source)
'#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',
// note: for some very weird reason trim() seems to remove spaces inside attributes. // note: for some very weird reason trim() seems to remove spaces inside attributes.
// maybe a \0 byte or something is interfering? // maybe a \0 byte or something is interfering?
'#^\s+<#Ss' => '<', '#>\s+$#Ss' => '>',); '#^\s+<#Ss' => '<',
'#>\s+$#Ss' => '>',
);
$source = preg_replace(array_keys($expressions), array_values($expressions), $source); $source = preg_replace(array_keys($expressions), array_values($expressions), $source);
// note: for some very weird reason trim() seems to remove spaces inside attributes. // note: for some very weird reason trim() seems to remove spaces inside attributes.
// maybe a \0 byte or something is interfering? // maybe a \0 byte or something is interfering?
// $source = trim( $source ); // $source = trim( $source );
$_offset = 0; $_offset = 0;
if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) { foreach ($matches as $match) {
$_length = strlen($match[ 0 ][ 0 ]); $_length = strlen($match[ 0 ][ 0 ]);
$replace = $store[ $match[ 1 ][ 0 ] ]; $replace = $store[ $match[ 1 ][ 0 ] ];
$source = substr_replace($source, $replace, $match[ 0 ][ 1 ] + $_offset, $_length); $source = substr_replace($source, $replace, $match[ 0 ][ 1 ] + $_offset, $_length);
$_offset += strlen($replace) - $_length; $_offset += strlen($replace) - $_length;
$_store++; $_store++;
} }
} }
return $source; return $source;
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsShared * @subpackage PluginsShared
*/ */
/** /**
* escape_special_chars common function * escape_special_chars common function
* Function: smarty_function_escape_special_chars * Function: smarty_function_escape_special_chars
@ -29,6 +28,5 @@ function smarty_function_escape_special_chars($string)
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
} }
} }
return $string; return $string;
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsShared * @subpackage PluginsShared
*/ */
/** /**
* evaluate compiler parameter * evaluate compiler parameter
* *
@ -25,12 +24,12 @@ function smarty_literal_compiler_param($params, $index, $default = null)
} }
// test if param is a literal // test if param is a literal
if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[ $index ])) { if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[ $index ])) {
throw new SmartyException('$param[' . $index . throw new SmartyException(
'] is not a literal and is thus not evaluatable at compile time'); '$param[' . $index .
'] is not a literal and is thus not evaluatable at compile time'
);
} }
$t = null; $t = null;
eval("\$t = " . $params[ $index ] . ";"); eval("\$t = " . $params[ $index ] . ";");
return $t; return $t;
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsShared * @subpackage PluginsShared
*/ */
/** /**
* Function: smarty_make_timestamp * Function: smarty_make_timestamp
* Purpose: used by other smarty functions to make a timestamp from a string. * Purpose: used by other smarty functions to make a timestamp from a string.
@ -21,14 +20,20 @@ function smarty_make_timestamp($string)
if (empty($string)) { if (empty($string)) {
// use "now": // use "now":
return time(); return time();
} elseif ($string instanceof DateTime || } elseif ($string instanceof DateTime
(interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface) || (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)
) { ) {
return (int)$string->format('U'); // PHP 5.2 BC return (int)$string->format('U'); // PHP 5.2 BC
} elseif (strlen($string) === 14 && ctype_digit($string)) { } elseif (strlen($string) === 14 && ctype_digit($string)) {
// it is mysql timestamp format of YYYYMMDDHHMMSS? // it is mysql timestamp format of YYYYMMDDHHMMSS?
return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), substr($string, 4, 2), return mktime(
substr($string, 6, 2), substr($string, 0, 4)); substr($string, 8, 2),
substr($string, 10, 2),
substr($string, 12, 2),
substr($string, 4, 2),
substr($string, 6, 2),
substr($string, 0, 4)
);
} elseif (is_numeric($string)) { } elseif (is_numeric($string)) {
// it is a numeric string, we handle it as timestamp // it is a numeric string, we handle it as timestamp
return (int)$string; return (int)$string;
@ -39,7 +44,6 @@ function smarty_make_timestamp($string)
// strtotime() was not able to parse $string, use "now": // strtotime() was not able to parse $string, use "now":
return time(); return time();
} }
return $time; return $time;
} }
} }

@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsShared * @subpackage PluginsShared
*/ */
/** /**
* convert characters to their decimal unicode equivalents * convert characters to their decimal unicode equivalents
* *
@ -24,7 +23,6 @@ function smarty_mb_to_unicode($string, $encoding = null)
} else { } else {
$expanded = mb_convert_encoding($string, 'UTF-32BE'); $expanded = mb_convert_encoding($string, 'UTF-32BE');
} }
return unpack('N*', $expanded); return unpack('N*', $expanded);
} }
@ -49,6 +47,5 @@ function smarty_mb_from_unicode($unicode, $encoding = null)
$character = pack('N*', $utf32be); $character = pack('N*', $utf32be);
$t .= mb_convert_encoding($character, $encoding, 'UTF-32BE'); $t .= mb_convert_encoding($character, $encoding, 'UTF-32BE');
} }
return $t; return $t;
} }

@ -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
@ -50,8 +50,11 @@ abstract class Smarty_CacheResource
* *
* @return boolean true or false if the cached content does not exist * @return boolean true or false if the cached content does not exist
*/ */
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, abstract public function process(
$update = false); Smarty_Internal_Template $_template,
Smarty_Template_Cached $cached = null,
$update = false
);
/** /**
* Write the rendered template output to cache * Write the rendered template output to cache
@ -70,7 +73,7 @@ abstract class Smarty_CacheResource
* *
* @return string content * @return string content
*/ */
abstract function readCachedContent(Smarty_Internal_Template $_template); abstract public function readCachedContent(Smarty_Internal_Template $_template);
/** /**
* Return cached content * Return cached content
@ -87,7 +90,6 @@ abstract class Smarty_CacheResource
$unifunc($_template); $unifunc($_template);
return ob_get_clean(); return ob_get_clean();
} }
return null; return null;
} }
@ -133,7 +135,6 @@ abstract class Smarty_CacheResource
} }
sleep(1); sleep(1);
} }
return $hadLock; return $hadLock;
} }
@ -193,12 +194,10 @@ abstract class Smarty_CacheResource
if (!isset($type)) { if (!isset($type)) {
$type = $smarty->caching_type; $type = $smarty->caching_type;
} }
// try smarty's cache // try smarty's cache
if (isset($smarty->_cache[ 'cacheresource_handlers' ][ $type ])) { if (isset($smarty->_cache[ 'cacheresource_handlers' ][ $type ])) {
return $smarty->_cache[ 'cacheresource_handlers' ][ $type ]; return $smarty->_cache[ 'cacheresource_handlers' ][ $type ];
} }
// try registered resource // try registered resource
if (isset($smarty->registered_cache_resources[ $type ])) { if (isset($smarty->registered_cache_resources[ $type ])) {
// do not cache these instances as they may vary from instance to instance // do not cache these instances as they may vary from instance to instance

@ -106,12 +106,17 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
if ($mtime !== null) { if ($mtime !== null) {
$cached->timestamp = $mtime; $cached->timestamp = $mtime;
$cached->exists = !!$cached->timestamp; $cached->exists = !!$cached->timestamp;
return; return;
} }
$timestamp = null; $timestamp = null;
$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $cached->content, $this->fetch(
$timestamp); $cached->filepath,
$cached->source->name,
$cached->cache_id,
$cached->compile_id,
$cached->content,
$timestamp
);
$cached->timestamp = isset($timestamp) ? $timestamp : false; $cached->timestamp = isset($timestamp) ? $timestamp : false;
$cached->exists = !!$cached->timestamp; $cached->exists = !!$cached->timestamp;
} }
@ -125,24 +130,31 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
* *
* @return boolean true or false if the cached content does not exist * @return boolean true or false if the cached content does not exist
*/ */
public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Template_Cached $cached = null, public function process(
$update = false) Smarty_Internal_Template $_smarty_tpl,
{ Smarty_Template_Cached $cached = null,
$update = false
) {
if (!$cached) { if (!$cached) {
$cached = $_smarty_tpl->cached; $cached = $_smarty_tpl->cached;
} }
$content = $cached->content ? $cached->content : null; $content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null; $timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) { if ($content === null || !$timestamp) {
$this->fetch($_smarty_tpl->cached->filepath, $_smarty_tpl->source->name, $_smarty_tpl->cache_id, $this->fetch(
$_smarty_tpl->compile_id, $content, $timestamp); $_smarty_tpl->cached->filepath,
$_smarty_tpl->source->name,
$_smarty_tpl->cache_id,
$_smarty_tpl->compile_id,
$content,
$timestamp
);
} }
if (isset($content)) { if (isset($content)) {
eval('?>' . $content); eval('?>' . $content);
$cached->content = null; $cached->content = null;
return true; return true;
} }
return false; return false;
} }
@ -156,8 +168,14 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/ */
public function writeCachedContent(Smarty_Internal_Template $_template, $content) public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{ {
return $this->save($_template->cached->filepath, $_template->source->name, $_template->cache_id, return $this->save(
$_template->compile_id, $_template->cache_lifetime, $content); $_template->cached->filepath,
$_template->source->name,
$_template->cache_id,
$_template->compile_id,
$_template->cache_lifetime,
$content
);
} }
/** /**
@ -173,8 +191,14 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
$timestamp = null; $timestamp = null;
if ($content === null) { if ($content === null) {
$timestamp = null; $timestamp = null;
$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $this->fetch(
$_template->compile_id, $content, $timestamp); $_template->cached->filepath,
$_template->source->name,
$_template->cache_id,
$_template->compile_id,
$content,
$timestamp
);
} }
if (isset($content)) { if (isset($content)) {
return $content; return $content;
@ -210,7 +234,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{ {
$cache_name = null; $cache_name = null;
if (isset($resource_name)) { if (isset($resource_name)) {
$source = Smarty_Template_Source::load(null, $smarty, $resource_name); $source = Smarty_Template_Source::load(null, $smarty, $resource_name);
if ($source->exists) { if ($source->exists) {
@ -219,7 +242,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
return 0; return 0;
} }
} }
return $this->delete($cache_name, $cache_id, $compile_id, $exp_time); return $this->delete($cache_name, $cache_id, $compile_id, $exp_time);
} }
@ -235,7 +257,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
{ {
$id = $cached->lock_id; $id = $cached->lock_id;
$name = $cached->source->name . '.lock'; $name = $cached->source->name . '.lock';
$mtime = $this->fetchTimestamp($id, $name, $cached->cache_id, $cached->compile_id); $mtime = $this->fetchTimestamp($id, $name, $cached->cache_id, $cached->compile_id);
if ($mtime === null) { if ($mtime === null) {
$this->fetch($id, $name, $cached->cache_id, $cached->compile_id, $content, $mtime); $this->fetch($id, $name, $cached->cache_id, $cached->compile_id, $content, $mtime);

@ -56,7 +56,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
{ {
$cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' . $cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' .
$this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id); $this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
$this->populateTimestamp($cached); $this->populateTimestamp($cached);
} }
@ -69,8 +68,15 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*/ */
public function populateTimestamp(Smarty_Template_Cached $cached) public function populateTimestamp(Smarty_Template_Cached $cached)
{ {
if (!$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content, if (!$this->fetch(
$timestamp, $cached->source->uid) $cached->filepath,
$cached->source->name,
$cached->cache_id,
$cached->compile_id,
$content,
$timestamp,
$cached->source->uid
)
) { ) {
return; return;
} }
@ -88,27 +94,34 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* *
* @return boolean true or false if the cached content does not exist * @return boolean true or false if the cached content does not exist
*/ */
public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Template_Cached $cached = null, public function process(
$update = false) Smarty_Internal_Template $_smarty_tpl,
{ Smarty_Template_Cached $cached = null,
$update = false
) {
if (!$cached) { if (!$cached) {
$cached = $_smarty_tpl->cached; $cached = $_smarty_tpl->cached;
} }
$content = $cached->content ? $cached->content : null; $content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null; $timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) { if ($content === null || !$timestamp) {
if (!$this->fetch($_smarty_tpl->cached->filepath, $_smarty_tpl->source->name, $_smarty_tpl->cache_id, if (!$this->fetch(
$_smarty_tpl->compile_id, $content, $timestamp, $_smarty_tpl->source->uid) $_smarty_tpl->cached->filepath,
$_smarty_tpl->source->name,
$_smarty_tpl->cache_id,
$_smarty_tpl->compile_id,
$content,
$timestamp,
$_smarty_tpl->source->uid
)
) { ) {
return false; return false;
} }
} }
if (isset($content)) { if (isset($content)) {
eval('?>' . $content); eval('?>' . $content);
return true; return true;
} }
return false; return false;
} }
@ -123,7 +136,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
public function writeCachedContent(Smarty_Internal_Template $_template, $content) public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{ {
$this->addMetaTimestamp($content); $this->addMetaTimestamp($content);
return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime); return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime);
} }
@ -139,8 +151,15 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$content = $_template->cached->content ? $_template->cached->content : null; $content = $_template->cached->content ? $_template->cached->content : null;
$timestamp = null; $timestamp = null;
if ($content === null) { if ($content === null) {
if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, if (!$this->fetch(
$_template->compile_id, $content, $timestamp, $_template->source->uid) $_template->cached->filepath,
$_template->source->name,
$_template->cache_id,
$_template->compile_id,
$content,
$timestamp,
$_template->source->uid
)
) { ) {
return false; return false;
} }
@ -204,7 +223,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* *
* @return string filepath of cache file * @return string filepath of cache file
* @throws \SmartyException * @throws \SmartyException
*
*/ */
protected function getTemplateUid(Smarty $smarty, $resource_name) protected function getTemplateUid(Smarty $smarty, $resource_name)
{ {
@ -246,13 +264,18 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* *
* @return boolean success * @return boolean success
*/ */
protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null, protected function fetch(
&$timestamp = null, $resource_uid = null) $cid,
{ $resource_name = null,
$cache_id = null,
$compile_id = null,
&$content = null,
&$timestamp = null,
$resource_uid = null
) {
$t = $this->read(array($cid)); $t = $this->read(array($cid));
$content = !empty($t[ $cid ]) ? $t[ $cid ] : null; $content = !empty($t[ $cid ]) ? $t[ $cid ] : null;
$timestamp = null; $timestamp = null;
if ($content && ($timestamp = $this->getMetaTimestamp($content))) { if ($content && ($timestamp = $this->getMetaTimestamp($content))) {
$invalidated = $invalidated =
$this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id, $resource_uid); $this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id, $resource_uid);
@ -261,7 +284,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$content = null; $content = null;
} }
} }
return !!$content; return !!$content;
} }
@ -306,9 +328,13 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* *
* @return void * @return void
*/ */
protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null, protected function invalidate(
$resource_uid = null) $cid = null,
{ $resource_name = null,
$cache_id = null,
$compile_id = null,
$resource_uid = null
) {
$now = microtime(true); $now = microtime(true);
$key = null; $key = null;
// invalidate everything // invalidate everything
@ -347,9 +373,13 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* *
* @return float the microtime the CacheID was invalidated * @return float the microtime the CacheID was invalidated
*/ */
protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null, protected function getLatestInvalidationTimestamp(
$resource_uid = null) $cid,
{ $resource_name = null,
$cache_id = null,
$compile_id = null,
$resource_uid = null
) {
// abort if there is no CacheID // abort if there is no CacheID
if (false && !$cid) { if (false && !$cid) {
return 0; return 0;
@ -358,14 +388,12 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
if (!($_cid = $this->listInvalidationKeys($cid, $resource_name, $cache_id, $compile_id, $resource_uid))) { if (!($_cid = $this->listInvalidationKeys($cid, $resource_name, $cache_id, $compile_id, $resource_uid))) {
return 0; return 0;
} }
// there are no InValidationKeys // there are no InValidationKeys
if (!($values = $this->read($_cid))) { if (!($values = $this->read($_cid))) {
return 0; return 0;
} }
// make sure we're dealing with floats // make sure we're dealing with floats
$values = array_map('floatval', $values); $values = array_map('floatval', $values);
return max($values); return max($values);
} }
@ -382,9 +410,13 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* @return array list of InvalidationKeys * @return array list of InvalidationKeys
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey * @uses $invalidationKeyPrefix to prepend to each InvalidationKey
*/ */
protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null, protected function listInvalidationKeys(
$resource_uid = null) $cid,
{ $resource_name = null,
$cache_id = null,
$compile_id = null,
$resource_uid = null
) {
$t = array('IVK#ALL'); $t = array('IVK#ALL');
$_name = $_compile = '#'; $_name = $_compile = '#';
if ($resource_name) { if ($resource_name) {
@ -418,7 +450,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
// skip past delimiter position // skip past delimiter position
$i++; $i++;
} }
return $t; return $t;
} }
@ -434,7 +465,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
{ {
$key = 'LOCK#' . $cached->filepath; $key = 'LOCK#' . $cached->filepath;
$data = $this->read(array($key)); $data = $this->read(array($key));
return $data && time() - $data[ $key ] < $smarty->locking_timeout; return $data && time() - $data[ $key ] < $smarty->locking_timeout;
} }

@ -22,7 +22,7 @@ class Smarty_Data extends Smarty_Internal_Data
* *
* @var int * @var int
*/ */
static $count = 0; public static $count = 0;
/** /**
* Data block name * Data block name

@ -7,6 +7,7 @@
* @author Uwe Tews * @author Uwe Tews
* @author Rodney Rehm * @author Rodney Rehm
*/ */
/** /**
* This class does contain all necessary methods for the HTML cache on file system * This class does contain all necessary methods for the HTML cache on file system
* Implements the file system as resource for the HTML cache Version ussing nocache inserts. * Implements the file system as resource for the HTML cache Version ussing nocache inserts.
@ -32,11 +33,17 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
$_filepath = sha1($source->uid . $smarty->_joined_template_dir); $_filepath = sha1($source->uid . $smarty->_joined_template_dir);
$cached->filepath = $smarty->getCacheDir(); $cached->filepath = $smarty->getCacheDir();
if (isset($_template->cache_id)) { if (isset($_template->cache_id)) {
$cached->filepath .= preg_replace(array('![^\w|]+!', $cached->filepath .= preg_replace(
'![|]+!'), array(
array('_', '![^\w|]+!',
$_compile_dir_sep), '![|]+!'
$_template->cache_id) . $_compile_dir_sep; ),
array(
'_',
$_compile_dir_sep
),
$_template->cache_id
) . $_compile_dir_sep;
} }
if (isset($_template->compile_id)) { if (isset($_template->compile_id)) {
$cached->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) . $_compile_dir_sep; $cached->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) . $_compile_dir_sep;
@ -87,10 +94,11 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
* *
* @return boolean true or false if the cached content does not exist * @return boolean true or false if the cached content does not exist
*/ */
public function process(Smarty_Internal_Template $_smarty_tpl, public function process(
Smarty_Internal_Template $_smarty_tpl,
Smarty_Template_Cached $cached = null, Smarty_Template_Cached $cached = null,
$update = false) $update = false
{ ) {
$_smarty_tpl->cached->valid = false; $_smarty_tpl->cached->valid = false;
if ($update && defined('HHVM_VERSION')) { if ($update && defined('HHVM_VERSION')) {
eval('?>' . file_get_contents($_smarty_tpl->cached->filepath)); eval('?>' . file_get_contents($_smarty_tpl->cached->filepath));
@ -111,12 +119,14 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*/ */
public function writeCachedContent(Smarty_Internal_Template $_template, $content) public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{ {
if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, if ($_template->smarty->ext->_writeFile->writeFile(
$_template->cached->filepath,
$content, $content,
$_template->smarty) === true $_template->smarty
) === true
) { ) {
if (function_exists('opcache_invalidate') && if (function_exists('opcache_invalidate')
(!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);
} elseif (function_exists('apc_compile_file')) { } elseif (function_exists('apc_compile_file')) {

@ -29,9 +29,11 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
* *
* @var array * @var array
*/ */
public $valid_scopes = array('local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT, public $valid_scopes = array(
'local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
'root' => Smarty::SCOPE_ROOT, 'global' => Smarty::SCOPE_GLOBAL, 'root' => Smarty::SCOPE_ROOT, 'global' => Smarty::SCOPE_GLOBAL,
'tpl_root' => Smarty::SCOPE_TPL_ROOT, 'smarty' => Smarty::SCOPE_SMARTY); 'tpl_root' => Smarty::SCOPE_TPL_ROOT, 'smarty' => Smarty::SCOPE_SMARTY
);
/** /**
* Compiles code for the {assign} tag * Compiles code for the {assign} tag

@ -1,5 +1,5 @@
<?php <?php
/* /**
* This file is part of Smarty. * This file is part of Smarty.
* *
* (c) 2015 Uwe Tews * (c) 2015 Uwe Tews
@ -22,6 +22,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $required_attributes = array('name'); public $required_attributes = array('name');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@ -29,6 +30,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $shorttag_order = array('name'); public $shorttag_order = array('name');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@ -36,6 +38,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $option_flags = array('hide', 'nocache'); public $option_flags = array('hide', 'nocache');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@ -50,7 +53,6 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @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 array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
*
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
@ -67,16 +69,20 @@ 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();
$compiler->_cache[ 'blockParams' ][ 1 ][ 'subBlocks' ][ trim($_attr[ 'name' ], '"\'') ][] = $_className; $compiler->_cache[ 'blockParams' ][ 1 ][ 'subBlocks' ][ trim($_attr[ 'name' ], '"\'') ][] = $_className;
$this->openTag($compiler, $this->openTag(
$compiler,
'block', 'block',
array($_attr, $compiler->nocache, $compiler->parser->current_buffer, array(
$_attr, $compiler->nocache, $compiler->parser->current_buffer,
$compiler->template->compiled->has_nocache_code, $compiler->template->compiled->has_nocache_code,
$compiler->template->caching)); $compiler->template->caching
)
);
$compiler->saveRequiredPlugins(true); $compiler->saveRequiredPlugins(true);
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
@ -84,9 +90,9 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
$compiler->suppressNocacheProcessing = true; $compiler->suppressNocacheProcessing = true;
} }
} }
/** /**
* Smarty Internal Plugin Compile BlockClose Class * Smarty Internal Plugin Compile BlockClose Class
*
*/ */
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_Inheritance class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_Inheritance
{ {
@ -118,7 +124,6 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$_functionCode = $compiler->parser->current_buffer; $_functionCode = $compiler->parser->current_buffer;
// setup buffer for template function code // setup buffer for template function code
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$output = "<?php\n"; $output = "<?php\n";
$output .= "/* {block {$_name}} */\n"; $output .= "/* {block {$_name}} */\n";
$output .= "class {$_className} extends Smarty_Internal_Block\n"; $output .= "class {$_className} extends Smarty_Internal_Block\n";
@ -136,9 +141,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$output .= "ob_start();\n"; $output .= "ob_start();\n";
} }
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser, $compiler->parser->current_buffer->append_subtree(
new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->parser,
$output)); new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php\n"; $output = "<?php\n";
if (isset($_assign)) { if (isset($_assign)) {
@ -148,9 +157,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$output .= "}\n"; $output .= "}\n";
$output .= "/* {/block {$_name}} */\n\n"; $output .= "/* {/block {$_name}} */\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser, $compiler->parser->current_buffer->append_subtree(
new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->parser,
$output)); new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); $compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
// restore old status // restore old status

@ -1,5 +1,5 @@
<?php <?php
/* /**
* This file is part of Smarty. * This file is part of Smarty.
* *
* (c) 2015 Uwe Tews * (c) 2015 Uwe Tews

@ -1,5 +1,5 @@
<?php <?php
/* /**
* This file is part of Smarty. * This file is part of Smarty.
* *
* (c) 2015 Uwe Tews * (c) 2015 Uwe Tews

@ -78,11 +78,9 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr[ 'nocache' ] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
if (isset($_attr[ 'levels' ])) { if (isset($_attr[ 'levels' ])) {
if (!is_numeric($_attr[ 'levels' ])) { if (!is_numeric($_attr[ 'levels' ])) {
$compiler->trigger_template_error('level attribute must be a numeric constant', null, true); $compiler->trigger_template_error('level attribute must be a numeric constant', null, true);

@ -40,16 +40,14 @@ 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,
$tag = trim($parameter[ 0 ], '"\''); Smarty_Internal_TemplateCompilerBase $compiler,
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : null; $parameter = null
if (!$name) { ) {
//$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true); return '$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl' .
} (isset($parameter[ 1 ]) ? ", {$parameter[ 1 ]})" : ')');
return '$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl'.(isset($name)?", '{$name}')":')');
} }
/** /**
@ -65,16 +63,13 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args, $parameter, 'capture'); $_attr = $this->getAttributes($compiler, $args, $parameter, 'capture');
$buffer = isset($_attr[ 'name' ]) ? $_attr[ 'name' ] : "'default'"; $buffer = isset($_attr[ 'name' ]) ? $_attr[ 'name' ] : "'default'";
$assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : 'null'; $assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : 'null';
$append = isset($_attr[ 'append' ]) ? $_attr[ 'append' ] : 'null'; $append = isset($_attr[ 'append' ]) ? $_attr[ 'append' ] : 'null';
$compiler->_cache[ 'capture_stack' ][] = array($compiler->nocache); $compiler->_cache[ 'capture_stack' ][] = array($compiler->nocache);
// 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;
$_output = "<?php \$_smarty_tpl->smarty->ext->_capture->open(\$_smarty_tpl, $buffer, $assign, $append);?>"; $_output = "<?php \$_smarty_tpl->smarty->ext->_capture->open(\$_smarty_tpl, $buffer, $assign, $append);?>";
return $_output; return $_output;
} }
} }
@ -104,9 +99,7 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
if ($compiler->nocache) { if ($compiler->nocache) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
list($compiler->nocache) = array_pop($compiler->_cache[ 'capture_stack' ]); list($compiler->nocache) = array_pop($compiler->_cache[ 'capture_stack' ]);
return "<?php \$_smarty_tpl->smarty->ext->_capture->close(\$_smarty_tpl);?>"; return "<?php \$_smarty_tpl->smarty->ext->_capture->close(\$_smarty_tpl);?>";
} }
} }

@ -1,5 +1,5 @@
<?php <?php
/* /**
* This file is part of Smarty. * This file is part of Smarty.
* *
* (c) 2015 Uwe Tews * (c) 2015 Uwe Tews
@ -53,8 +53,10 @@ class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$tag = isset($parameter[ 0 ]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'"; $tag = isset($parameter[ 0 ]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'";
if (!isset($compiler->_cache[ 'blockNesting' ])) { if (!isset($compiler->_cache[ 'blockNesting' ])) {
$compiler->trigger_template_error("{$tag} used outside {block} tags ", $compiler->trigger_template_error(
$compiler->parser->lex->taglineno); "{$tag} used outside {block} tags ",
$compiler->parser->lex->taglineno
);
} }
$compiler->has_code = true; $compiler->has_code = true;
$compiler->suppressNocacheProcessing = true; $compiler->suppressNocacheProcessing = true;

@ -53,9 +53,11 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
* *
* @var array * @var array
*/ */
public $valid_scopes = array('local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT, public $valid_scopes = array(
'local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
'root' => Smarty::SCOPE_ROOT, 'tpl_root' => Smarty::SCOPE_TPL_ROOT, 'root' => Smarty::SCOPE_ROOT, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
'smarty' => Smarty::SCOPE_SMARTY, 'global' => Smarty::SCOPE_SMARTY); 'smarty' => Smarty::SCOPE_SMARTY, 'global' => Smarty::SCOPE_SMARTY
);
/** /**
* Compiles code for the {config_load} tag * Compiles code for the {config_load} tag
@ -70,11 +72,9 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr[ 'nocache' ] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
// save possible attributes // save possible attributes
$conf_file = $_attr[ 'file' ]; $conf_file = $_attr[ 'file' ];
if (isset($_attr[ 'section' ])) { if (isset($_attr[ 'section' ])) {
@ -88,11 +88,9 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
} else { } else {
$_scope = $compiler->convertScope($_attr, $this->valid_scopes); $_scope = $compiler->convertScope($_attr, $this->valid_scopes);
} }
// create config object // create config object
$_output = $_output =
"<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n"; "<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n";
return $_output; return $_output;
} }
} }

@ -29,10 +29,8 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
// compile always as nocache // compile always as nocache
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
// display debug template // display debug template
$_output = $_output =
"<?php \$_smarty_debug = new Smarty_Internal_Debug;\n \$_smarty_debug->display_debug(\$_smarty_tpl);\n"; "<?php \$_smarty_debug = new Smarty_Internal_Debug;\n \$_smarty_debug->display_debug(\$_smarty_tpl);\n";

@ -56,16 +56,15 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
// output will be stored in a smarty variable instead of being displayed // output will be stored in a smarty variable instead of being displayed
$_assign = $_attr[ 'assign' ]; $_assign = $_attr[ 'assign' ];
} }
// create template object // create template object
$_output = "\$_template = new {$compiler->smarty->template_class}('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->smarty, \$_smarty_tpl);"; $_output =
"\$_template = new {$compiler->smarty->template_class}('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->smarty, \$_smarty_tpl);";
//was there an assign attribute? //was there an assign attribute?
if (isset($_assign)) { if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());"; $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
} else { } else {
$_output .= 'echo $_template->fetch();'; $_output .= 'echo $_template->fetch();';
} }
return "<?php $_output ?>"; return "<?php $_output ?>";
} }
} }

@ -1,5 +1,4 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile extend * Smarty Internal Plugin Compile extend
* Compiles the {extends} tag * Compiles the {extends} tag
@ -108,11 +107,13 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
$inlineUids = $match[ 1 ]; $inlineUids = $match[ 1 ];
} }
} }
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
'<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl' . '<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl' .
(isset($template) ? (isset($template) ?
", {$template}{$inlineUids}" : ", {$template}{$inlineUids}" :
'') . ");\n?>"); '') . ");\n?>"
);
} }
/** /**
@ -126,10 +127,16 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
*/ */
private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $template) private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $template)
{ {
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag(
$compiler->compileTag('include', $compiler->parser,
array($template, $compiler->compileTag(
array('scope' => 'parent')))); 'include',
array(
$template,
array('scope' => 'parent')
)
)
);
} }
/** /**

@ -45,7 +45,6 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
$this->mapCache = array(); $this->mapCache = array();
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$output = "<?php\n"; $output = "<?php\n";
if ($parameter === 1) { if ($parameter === 1) {
foreach ($_attr[ 'start' ] as $_statement) { foreach ($_attr[ 'start' ] as $_statement) {
@ -93,7 +92,6 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
$output .= "\$_smarty_tpl->tpl_vars[$var]->last = \$_smarty_tpl->tpl_vars[$var]->iteration === \$_smarty_tpl->tpl_vars[$var]->total;"; $output .= "\$_smarty_tpl->tpl_vars[$var]->last = \$_smarty_tpl->tpl_vars[$var]->iteration === \$_smarty_tpl->tpl_vars[$var]->total;";
} }
$output .= '?>'; $output .= '?>';
$this->openTag($compiler, 'for', array('for', $compiler->nocache)); $this->openTag($compiler, 'for', array('for', $compiler->nocache));
// 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;
@ -123,10 +121,8 @@ class Smarty_Internal_Compile_Forelse 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) = $this->closeTag($compiler, array('for')); list($openTag, $nocache) = $this->closeTag($compiler, array('for'));
$this->openTag($compiler, 'forelse', array('forelse', $nocache)); $this->openTag($compiler, 'forelse', array('forelse', $nocache));
return "<?php }} else { ?>"; return "<?php }} else { ?>";
} }
} }
@ -157,9 +153,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
if ($compiler->nocache) { if ($compiler->nocache) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse')); list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse'));
$output = "<?php }\n"; $output = "<?php }\n";
if ($openTag !== 'forelse') { if ($openTag !== 'forelse') {
$output .= "}\n"; $output .= "}\n";

@ -119,12 +119,14 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
if ($fromName) { if ($fromName) {
foreach (array('item', 'key') as $a) { foreach (array('item', 'key') as $a) {
if (isset($attributes[ $a ]) && $attributes[ $a ] === $fromName) { if (isset($attributes[ $a ]) && $attributes[ $a ] === $fromName) {
$compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'", $compiler->trigger_template_error(
null, true); "'{$a}' and 'from' may not have same variable name '{$fromName}'",
null,
true
);
} }
} }
} }
$itemVar = "\$_smarty_tpl->tpl_vars['{$item}']"; $itemVar = "\$_smarty_tpl->tpl_vars['{$item}']";
$local = '$__foreach_' . $attributes[ 'item' ] . '_' . $this->counter++ . '_'; $local = '$__foreach_' . $attributes[ 'item' ] . '_' . $this->counter++ . '_';
// search for used tag attributes // search for used tag attributes
@ -187,8 +189,11 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
} }
$needTotal = isset($itemAttr[ 'total' ]); $needTotal = isset($itemAttr[ 'total' ]);
// Register tag // Register tag
$this->openTag($compiler, 'foreach', $this->openTag(
array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2)); $compiler,
'foreach',
array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2)
);
// 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;
// generate output code // generate output code
@ -249,7 +254,6 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
$output .= "{$local}saved = {$itemVar};\n"; $output .= "{$local}saved = {$itemVar};\n";
} }
$output .= '?>'; $output .= '?>';
return $output; return $output;
} }
@ -286,7 +290,6 @@ class Smarty_Internal_Compile_Foreachelse 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, $itemVar, $restore) = $this->closeTag($compiler, array('foreach')); list($openTag, $nocache, $local, $itemVar, $restore) = $this->closeTag($compiler, array('foreach'));
$this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $itemVar, 0)); $this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $itemVar, 0));
$output = "<?php\n"; $output = "<?php\n";
@ -322,11 +325,10 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
if ($compiler->nocache) { if ($compiler->nocache) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
list(
list($openTag, $compiler->nocache, $local, $itemVar, $restore) = $openTag, $compiler->nocache, $local, $itemVar, $restore
$this->closeTag($compiler, array('foreach', 'foreachelse')); ) = $this->closeTag($compiler, array('foreach', 'foreachelse'));
$output = "<?php\n"; $output = "<?php\n";
if ($restore === 2) { if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n"; $output .= "{$itemVar} = {$local}saved;\n";
} }

@ -16,7 +16,6 @@
*/ */
class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
{ {
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@ -54,15 +53,16 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr[ 'nocache' ] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
unset($_attr[ 'nocache' ]); unset($_attr[ 'nocache' ]);
$_name = trim($_attr[ 'name' ], '\'"'); $_name = trim($_attr[ 'name' ], '\'"');
$compiler->parent_compiler->tpl_function[ $_name ] = array(); $compiler->parent_compiler->tpl_function[ $_name ] = array();
$save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code, $save = array(
$compiler->template->caching); $_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
$compiler->template->caching
);
$this->openTag($compiler, 'function', $save); $this->openTag($compiler, 'function', $save);
// Init temporary context // Init temporary context
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
@ -80,7 +80,6 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
*/ */
class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
{ {
/** /**
* Compiler object * Compiler object
* *
@ -125,7 +124,6 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$_functionCode = $compiler->parser->current_buffer; $_functionCode = $compiler->parser->current_buffer;
// setup buffer for template function code // setup buffer for template function code
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}"; $_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}";
$_funcNameCaching = $_funcName . '_nocache'; $_funcNameCaching = $_funcName . '_nocache';
if ($compiler->template->compiled->has_nocache_code) { if ($compiler->template->compiled->has_nocache_code) {
@ -143,9 +141,13 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php "; $output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->saveTemplateVariables(\\\$_smarty_tpl, '{$_name}');\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value, \\\$_smarty_tpl->isRenderingCache);\n}\n?>"; $output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->saveTemplateVariables(\\\$_smarty_tpl, '{$_name}');\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value, \\\$_smarty_tpl->isRenderingCache);\n}\n?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";?>"; $output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";?>";
$compiler->parser->current_buffer->append_subtree($compiler->parser, $compiler->parser->current_buffer->append_subtree(
new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->parser,
$output)); new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php "; $output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n"; $output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n";
@ -154,13 +156,21 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "}\n}\n"; $output .= "}\n}\n";
$output .= "/*/ {$_funcName}_nocache */\n\n"; $output .= "/*/ {$_funcName}_nocache */\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser, $compiler->parser->current_buffer->append_subtree(
new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->parser,
$output)); new Smarty_Internal_ParseTree_Tag(
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->parser,
preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", $output
)
);
$_functionCode = new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
preg_replace_callback(
"/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
array($this, 'removeNocache'), array($this, 'removeNocache'),
$_functionCode->to_smarty_php($compiler->parser))); $_functionCode->to_smarty_php($compiler->parser)
)
);
} }
$compiler->parent_compiler->tpl_function[ $_name ][ 'call_name' ] = $_funcName; $compiler->parent_compiler->tpl_function[ $_name ][ 'call_name' ] = $_funcName;
$output = "<?php\n"; $output = "<?php\n";
@ -169,18 +179,27 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\n"; $output .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
$output .= $_paramsCode; $output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\n}\n"; $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\n}\n";
$output .= $compiler->compileCheckPlugins(array_merge($compiler->required_plugins[ 'compiled' ], $compiler->required_plugins[ 'nocache' ])); $output .= $compiler->compileCheckPlugins(array_merge($compiler->required_plugins[ 'compiled' ],
$compiler->required_plugins[ 'nocache' ]));
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser, $compiler->parser->current_buffer->append_subtree(
new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->parser,
$output)); new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php\n}}\n"; $output = "<?php\n}}\n";
$output .= "/*/ {$_funcName} */\n\n"; $output .= "/*/ {$_funcName} */\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser, $compiler->parser->current_buffer->append_subtree(
new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->parser,
$output)); new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); $compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
// restore old buffer // restore old buffer
$compiler->parser->current_buffer = $saved_data[ 1 ]; $compiler->parser->current_buffer = $saved_data[ 1 ];
@ -198,11 +217,14 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
* *
* @return string * @return string
*/ */
function removeNocache($match) public function removeNocache($match)
{ {
$code = $code =
preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", preg_replace(
'', $match[ 0 ]); "/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
'',
$match[ 0 ]
);
$code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code); $code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code);
return $code; return $code;
} }

@ -33,11 +33,9 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$this->openTag($compiler, 'if', array(1, $compiler->nocache)); $this->openTag($compiler, 'if', array(1, $compiler->nocache));
// must whole block be nocache ? // must whole block be nocache ?
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
if (!isset($parameter[ 'if condition' ])) { if (!isset($parameter[ 'if condition' ])) {
$compiler->trigger_template_error('missing if condition', null, true); $compiler->trigger_template_error('missing if condition', null, true);
} }
if (is_array($parameter[ 'if condition' ])) { if (is_array($parameter[ 'if condition' ])) {
if (is_array($parameter[ 'if condition' ][ 'var' ])) { if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ]; $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
@ -55,8 +53,11 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$assignCompiler = new Smarty_Internal_Compile_Assign(); $assignCompiler = new Smarty_Internal_Compile_Assign();
if (is_array($parameter[ 'if condition' ][ 'var' ])) { if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ]; $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
$_output .= $assignCompiler->compile($assignAttr, $compiler, $_output .= $assignCompiler->compile(
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])); $assignAttr,
$compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
);
} else { } else {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ]; $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
$_output .= $assignCompiler->compile($assignAttr, $compiler, array()); $_output .= $assignCompiler->compile($assignAttr, $compiler, array());
@ -89,7 +90,6 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
{ {
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif')); list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
$this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache)); $this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache));
return '<?php } else { ?>'; return '<?php } else { ?>';
} }
} }
@ -116,13 +116,10 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif')); list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
if (!isset($parameter[ 'if condition' ])) { if (!isset($parameter[ 'if condition' ])) {
$compiler->trigger_template_error('missing elseif condition', null, true); $compiler->trigger_template_error('missing elseif condition', null, true);
} }
$assignCode = ''; $assignCode = '';
$var = ''; $var = '';
if (is_array($parameter[ 'if condition' ])) { if (is_array($parameter[ 'if condition' ])) {
@ -143,8 +140,11 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
$assignAttr[][ 'value' ] = $prefixVar; $assignAttr[][ 'value' ] = $prefixVar;
if (is_array($parameter[ 'if condition' ][ 'var' ])) { if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ]; $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
$assignCode .= $assignCompiler->compile($assignAttr, $compiler, $assignCode .= $assignCompiler->compile(
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])); $assignAttr,
$compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
);
} else { } else {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ]; $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
$assignCode .= $assignCompiler->compile($assignAttr, $compiler, array()); $assignCode .= $assignCompiler->compile($assignAttr, $compiler, array());
@ -152,7 +152,6 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
} else { } else {
$condition_by_assign = false; $condition_by_assign = false;
} }
$prefixCode = $compiler->getPrefixCode(); $prefixCode = $compiler->getPrefixCode();
if (empty($prefixCode)) { if (empty($prefixCode)) {
if ($condition_by_assign) { if ($condition_by_assign) {
@ -203,7 +202,6 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
for ($i = 0; $i < $nesting; $i++) { for ($i = 0; $i < $nesting; $i++) {
$tmp .= '}'; $tmp .= '}';
} }
return "<?php {$tmp}?>"; return "<?php {$tmp}?>";
} }
} }

@ -7,6 +7,7 @@
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Include Class * Smarty Internal Plugin Compile Include Class
* *
@ -19,6 +20,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* caching mode to create nocache code but no cache file * caching mode to create nocache code but no cache file
*/ */
const CACHING_NOCACHE_CODE = 9999; const CACHING_NOCACHE_CODE = 9999;
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@ -26,6 +28,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $required_attributes = array('file'); public $required_attributes = array('file');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@ -33,6 +36,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $shorttag_order = array('file'); public $shorttag_order = array('file');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@ -40,6 +44,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $option_flags = array('nocache', 'inline', 'caching'); public $option_flags = array('nocache', 'inline', 'caching');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@ -47,14 +52,17 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $optional_attributes = array('_any'); public $optional_attributes = array('_any');
/** /**
* Valid scope names * Valid scope names
* *
* @var array * @var array
*/ */
public $valid_scopes = array('parent' => Smarty::SCOPE_PARENT, 'root' => Smarty::SCOPE_ROOT, public $valid_scopes = array(
'parent' => Smarty::SCOPE_PARENT, 'root' => Smarty::SCOPE_ROOT,
'global' => Smarty::SCOPE_GLOBAL, 'tpl_root' => Smarty::SCOPE_TPL_ROOT, 'global' => Smarty::SCOPE_GLOBAL, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
'smarty' => Smarty::SCOPE_SMARTY); 'smarty' => Smarty::SCOPE_SMARTY
);
/** /**
* Compiles code for the {include} tag * Compiles code for the {include} tag
@ -193,9 +201,14 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching')); $t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
$compiler->smarty->allow_ambiguous_resources = true; $compiler->smarty->allow_ambiguous_resources = true;
/* @var Smarty_Internal_Template $tpl */ /* @var Smarty_Internal_Template $tpl */
$tpl = new $compiler->smarty->template_class (trim($fullResourceName, '"\''), $compiler->smarty, $tpl = new $compiler->smarty->template_class(
$compiler->template, $compiler->template->cache_id, $c_id, trim($fullResourceName, '"\''),
$_caching); $compiler->smarty,
$compiler->template,
$compiler->template->cache_id,
$c_id,
$_caching
);
$uid = $tpl->source->type . $tpl->source->uid; $uid = $tpl->source->type . $tpl->source->uid;
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ])) { if (!isset($compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ])) {
$has_compiled_template = $this->compileInlineTemplate($compiler, $tpl, $t_hash); $has_compiled_template = $this->compileInlineTemplate($compiler, $tpl, $t_hash);
@ -275,10 +288,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \SmartyException
*/ */
public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler, public function compileInlineTemplate(
Smarty_Internal_SmartyTemplateCompiler $compiler,
Smarty_Internal_Template $tpl, Smarty_Internal_Template $tpl,
$t_hash) $t_hash
{ ) {
$uid = $tpl->source->type . $tpl->source->uid; $uid = $tpl->source->type . $tpl->source->uid;
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) { if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
$compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'uid' ] = $tpl->source->uid; $compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'uid' ] = $tpl->source->uid;
@ -317,9 +331,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if ($tpl->compiled->has_nocache_code) { if ($tpl->compiled->has_nocache_code) {
// replace nocache_hash // replace nocache_hash
$compiled_code = $compiled_code =
str_replace("{$tpl->compiled->nocache_hash}", str_replace(
"{$tpl->compiled->nocache_hash}",
$compiler->template->compiled->nocache_hash, $compiler->template->compiled->nocache_hash,
$compiled_code); $compiled_code
);
$compiler->template->compiled->has_nocache_code = true; $compiler->template->compiled->has_nocache_code = true;
} }
$compiler->parent_compiler->mergedSubTemplatesCode[ $tpl->compiled->unifunc ] = $compiled_code; $compiler->parent_compiler->mergedSubTemplatesCode[ $tpl->compiled->unifunc ] = $compiled_code;

@ -7,6 +7,7 @@
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Insert Class * Smarty Internal Plugin Compile Insert Class
* *
@ -56,7 +57,10 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
} }
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
/** @var Smarty_Internal_Template $_smarty_tpl /**
*
*
* @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code * used in evaluated code
*/ */
$_smarty_tpl = $compiler->template; $_smarty_tpl = $compiler->template;

@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $required_attributes = array('name'); public $required_attributes = array('name');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $shorttag_order = array('name'); public $shorttag_order = array('name');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@ -104,11 +106,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
} }
// code for script file loading // code for script file loading
$_output .= "require_once '{$_filepath}' ;"; $_output .= "require_once '{$_filepath}' ;";
require_once $_filepath; include_once $_filepath;
if (!is_callable($_function)) { if (!is_callable($_function)) {
$compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", $compiler->trigger_template_error(
" {insert} function '{$_function}' is not callable in script file '{$_script}'",
null, null,
true); true
);
} }
} else { } else {
$_filepath = 'null'; $_filepath = 'null';
@ -117,9 +121,11 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
if (!is_callable($_function)) { if (!is_callable($_function)) {
// try plugin // try plugin
if (!$_function = $compiler->getPlugin($_name, 'insert')) { if (!$_function = $compiler->getPlugin($_name, 'insert')) {
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", $compiler->trigger_template_error(
"{insert} no function or plugin found for '{$_name}'",
null, null,
true); true
);
} }
} }
} }

@ -40,7 +40,6 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
$compiler->nocache = true; $compiler->nocache = true;
// this tag does not return compiled code // this tag does not return compiled code
$compiler->has_code = false; $compiler->has_code = false;
return true; return true;
} }
} }
@ -69,7 +68,6 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase
list($compiler->nocache) = $this->closeTag($compiler, array('nocache')); list($compiler->nocache) = $this->closeTag($compiler, array('nocache'));
// this tag does not return compiled code // this tag does not return compiled code
$compiler->has_code = false; $compiler->has_code = false;
return true; return true;
} }
} }

@ -1,5 +1,5 @@
<?php <?php
/* /**
* This file is part of Smarty. * This file is part of Smarty.
* *
* (c) 2015 Uwe Tews * (c) 2015 Uwe Tews
@ -15,7 +15,6 @@
*/ */
class Smarty_Internal_Compile_Parent extends Smarty_Internal_Compile_Child class Smarty_Internal_Compile_Parent extends Smarty_Internal_Compile_Child
{ {
/** /**
* Tag name * Tag name
* *

@ -54,7 +54,6 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
unset($_attr[ 'nocache' ]); unset($_attr[ 'nocache' ]);
list($callback, $_paramsArray, $callable) = $this->setup($compiler, $_attr, $tag, $function); list($callback, $_paramsArray, $callable) = $this->setup($compiler, $_attr, $tag, $function);
$_params = 'array(' . implode(',', $_paramsArray) . ')'; $_params = 'array(' . implode(',', $_paramsArray) . ')';
// compile code // compile code
$output = "<?php "; $output = "<?php ";
if (is_array($callback)) { if (is_array($callback)) {
@ -84,11 +83,17 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
$mod_content2 = "\$_block_content{$this->nesting}"; $mod_content2 = "\$_block_content{$this->nesting}";
$mod_content = "\$_block_content{$this->nesting} = ob_get_clean();\n"; $mod_content = "\$_block_content{$this->nesting} = ob_get_clean();\n";
$mod_pre = "ob_start();\n"; $mod_pre = "ob_start();\n";
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), $mod_post = 'echo ' . $compiler->compileTag(
array('modifierlist' => $parameter[ 'modifier_list' ], 'private_modifier',
'value' => 'ob_get_clean()')) . ";\n"; array(),
array(
'modifierlist' => $parameter[ 'modifier_list' ],
'value' => 'ob_get_clean()'
)
) . ";\n";
} }
$output = "<?php {$mod_content}\$_block_repeat=false;\n{$mod_pre}echo {$callback}({$_params}, {$mod_content2}, \$_smarty_tpl, \$_block_repeat);\n{$mod_post}}\n"; $output =
"<?php {$mod_content}\$_block_repeat=false;\n{$mod_pre}echo {$callback}({$_params}, {$mod_content2}, \$_smarty_tpl, \$_block_repeat);\n{$mod_post}}\n";
$output .= 'array_pop($_smarty_tpl->smarty->_cache[\'_tag_stack\']);?>'; $output .= 'array_pop($_smarty_tpl->smarty->_cache[\'_tag_stack\']);?>';
} }
return $output; return $output;

@ -16,28 +16,6 @@
*/ */
class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_CompileBase class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_CompileBase
{ {
/**
* Preg search pattern
*
* @var string
*/
private $propertyPreg = '';
/**
* Offsets in preg match result
*
* @var array
*/
private $resultOffsets = array();
/**
* Start offset
*
* @var int
*/
private $startOffset = 0;
/** /**
* Name of this tag * Name of this tag
* *
@ -71,6 +49,27 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*/ */
public $matchResults = array(); public $matchResults = array();
/**
* Preg search pattern
*
* @var string
*/
private $propertyPreg = '';
/**
* Offsets in preg match result
*
* @var array
*/
private $resultOffsets = array();
/**
* Start offset
*
* @var int
*/
private $startOffset = 0;
/** /**
* Scan sources for used tag attributes * Scan sources for used tag attributes
* *
@ -82,10 +81,10 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
public function scanForProperties($attributes, Smarty_Internal_TemplateCompilerBase $compiler) public function scanForProperties($attributes, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$this->propertyPreg = '~('; $this->propertyPreg = '~(';
$this->startOffset = 0; $this->startOffset = 1;
$this->resultOffsets = array(); $this->resultOffsets = array();
$this->matchResults = array('named' => array(), 'item' => array()); $this->matchResults = array('named' => array(), 'item' => array());
if ($this->isNamed) { if (isset($attributes[ 'name' ])) {
$this->buildPropertyPreg(true, $attributes); $this->buildPropertyPreg(true, $attributes);
} }
if (isset($this->itemProperties)) { if (isset($this->itemProperties)) {
@ -112,19 +111,19 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
public function buildPropertyPreg($named, $attributes) public function buildPropertyPreg($named, $attributes)
{ {
if ($named) { if ($named) {
$this->resultOffsets[ 'named' ] = $this->startOffset + 4; $this->resultOffsets[ 'named' ] = $this->startOffset = $this->startOffset + 3;
$this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" . ($this->tagName === 'section' ? "|[\[]\s*" : '') $this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" .
. "){$attributes['name']}[.]("; ($this->tagName === 'section' ? "|[\[]\s*" : '') .
"){$attributes['name']}[.](";
$properties = $this->nameProperties; $properties = $this->nameProperties;
} else { } else {
$this->resultOffsets[ 'item' ] = $this->startOffset + 3; $this->resultOffsets[ 'item' ] = $this->startOffset = $this->startOffset + 2;
$this->propertyPreg .= "([\$]{$attributes['item']}[@]("; $this->propertyPreg .= "([\$]{$attributes['item']}[@](";
$properties = $this->itemProperties; $properties = $this->itemProperties;
} }
$this->startOffset += count($properties) + 2;
$propName = reset($properties); $propName = reset($properties);
while ($propName) { while ($propName) {
$this->propertyPreg .= "({$propName})"; $this->propertyPreg .= "{$propName}";
$propName = next($properties); $propName = next($properties);
if ($propName) { if ($propName) {
$this->propertyPreg .= '|'; $this->propertyPreg .= '|';
@ -140,11 +139,11 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*/ */
public function matchProperty($source) public function matchProperty($source)
{ {
preg_match_all($this->propertyPreg, $source, $match, PREG_SET_ORDER); preg_match_all($this->propertyPreg, $source, $match);
foreach ($this->resultOffsets as $key => $offset) { foreach ($this->resultOffsets as $key => $offset) {
foreach ($match as $m) { foreach ($match[ $offset ] as $m) {
if (isset($m[ $offset ]) && !empty($m[ $offset ])) { if (!empty($m)) {
$this->matchResults[ $key ][ strtolower($m[ $offset ]) ] = true; $this->matchResults[ $key ][ strtolower($m) ] = true;
} }
} }
} }
@ -181,8 +180,11 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
if ((isset($nextCompiler->smarty->autoload_filters[ 'pre' ]) || if ((isset($nextCompiler->smarty->autoload_filters[ 'pre' ]) ||
isset($nextCompiler->smarty->registered_filters[ 'pre' ])) isset($nextCompiler->smarty->registered_filters[ 'pre' ]))
) { ) {
$_content = $nextCompiler->smarty->ext->_filterHandler->runFilter('pre', $_content, $_content = $nextCompiler->smarty->ext->_filterHandler->runFilter(
$nextCompiler->template); 'pre',
$_content,
$nextCompiler->template
);
} }
$this->matchProperty($_content); $this->matchProperty($_content);
} }

@ -49,7 +49,6 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
unset($_attr[ 'nocache' ]); unset($_attr[ 'nocache' ]);
// convert attributes into parameter array string // convert attributes into parameter array string
$_paramsArray = array(); $_paramsArray = array();
@ -64,9 +63,14 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
// compile code // compile code
$output = "{$function}({$_params},\$_smarty_tpl)"; $output = "{$function}({$_params},\$_smarty_tpl)";
if (!empty($parameter[ 'modifierlist' ])) { if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(), $output = $compiler->compileTag(
array('modifierlist' => $parameter[ 'modifierlist' ], 'private_modifier',
'value' => $output)); array(),
array(
'modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output
)
);
} }
$output = "<?php echo {$output};?>\n"; $output = "<?php echo {$output};?>\n";
return $output; return $output;

@ -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
@ -52,8 +51,12 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
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 = $output =
sprintf('call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))', sprintf(
Smarty::PLUGIN_MODIFIER, var_export($modifier, true), $params); '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; $compiler->known_modifier_type[ $modifier ] = $type;
break 2; break 2;
} }
@ -63,8 +66,11 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// registered modifier compiler // registered modifier compiler
if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ])) { if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ])) {
$output = $output =
call_user_func($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ], call_user_func(
$single_modifier, $compiler->smarty); $compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ],
$single_modifier,
$compiler->smarty
);
$compiler->known_modifier_type[ $modifier ] = $type; $compiler->known_modifier_type[ $modifier ] = $type;
break 2; break 2;
} }
@ -73,8 +79,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// modifiercompiler plugin // modifiercompiler plugin
if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) { if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || if (!is_object($compiler->smarty->security_policy)
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) { ) {
$plugin = 'smarty_modifiercompiler_' . $modifier; $plugin = 'smarty_modifiercompiler_' . $modifier;
$output = $plugin($single_modifier, $compiler); $output = $plugin($single_modifier, $compiler);
@ -87,8 +93,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// modifier plugin // modifier plugin
if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) { if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || if (!is_object($compiler->smarty->security_policy)
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) { ) {
$output = "{$function}({$params})"; $output = "{$function}({$params})";
} }
@ -100,8 +106,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// PHP function // PHP function
if (is_callable($modifier)) { if (is_callable($modifier)) {
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || if (!is_object($compiler->smarty->security_policy)
$compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
) { ) {
$output = "{$modifier}({$params})"; $output = "{$modifier}({$params})";
} }
@ -111,14 +117,14 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
break; break;
case 6: case 6:
// default plugin handler // default plugin handler
if (isset($compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ]) || if (isset($compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])
(is_callable($compiler->smarty->default_plugin_handler_func) && || (is_callable($compiler->smarty->default_plugin_handler_func)
$compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER)) && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))
) { ) {
$function = $compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ]; $function = $compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ];
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || if (!is_object($compiler->smarty->security_policy)
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) { ) {
if (!is_array($function)) { if (!is_array($function)) {
$output = "{$function}({$params})"; $output = "{$function}({$params})";
@ -130,7 +136,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
} }
} }
} }
if (isset($compiler->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) || if (isset($compiler->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
||
isset($compiler->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) isset($compiler->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
) { ) {
// was a plugin // was a plugin
@ -146,7 +153,6 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
$compiler->trigger_template_error("unknown modifier '{$modifier}'", null, true); $compiler->trigger_template_error("unknown modifier '{$modifier}'", null, true);
} }
} }
return $output; return $output;
} }
} }

@ -70,8 +70,11 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
$output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}"; $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
} }
if (!empty($parameter[ 'modifierlist' ])) { if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(), $output = $compiler->compileTag(
array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output)); 'private_modifier',
array(),
array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output)
);
} }
if (empty($_assign)) { if (empty($_assign)) {
return "<?php echo {$output};?>\n"; return "<?php echo {$output};?>\n";

@ -16,7 +16,6 @@
*/ */
class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
{ {
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@ -43,10 +42,16 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
if ($_attr[ 'type' ] === 'xml') { if ($_attr[ 'type' ] === 'xml') {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
$output = addcslashes($_attr[ 'code' ], "'\\"); $output = addcslashes($_attr[ 'code' ], "'\\");
$compiler->parser->current_buffer->append_subtree($compiler->parser, $compiler->parser->current_buffer->append_subtree(
new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->parser,
$compiler->processNocacheCode("<?php echo '{$output}';?>", new Smarty_Internal_ParseTree_Tag(
true))); $compiler->parser,
$compiler->processNocacheCode(
"<?php echo '{$output}';?>",
true
)
)
);
return ''; return '';
} }
if ($_attr[ 'type' ] !== 'tag') { if ($_attr[ 'type' ] !== 'tag') {
@ -54,23 +59,37 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
return ''; return '';
} elseif ($compiler->php_handling === Smarty::PHP_QUOTE) { } elseif ($compiler->php_handling === Smarty::PHP_QUOTE) {
$output = $output =
preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i', preg_replace_callback(
array($this, 'quote'), $_attr[ 'code' ]); '#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i',
$compiler->parser->current_buffer->append_subtree($compiler->parser, array($this, 'quote'),
new Smarty_Internal_ParseTree_Text($output)); $_attr[ 'code' ]
);
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Text($output)
);
return ''; return '';
} elseif ($compiler->php_handling === Smarty::PHP_PASSTHRU || $_attr[ 'type' ] === 'unmatched') { } elseif ($compiler->php_handling === Smarty::PHP_PASSTHRU || $_attr[ 'type' ] === 'unmatched') {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
$output = addcslashes($_attr[ 'code' ], "'\\"); $output = addcslashes($_attr[ 'code' ], "'\\");
$compiler->parser->current_buffer->append_subtree($compiler->parser, $compiler->parser->current_buffer->append_subtree(
new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->parser,
$compiler->processNocacheCode("<?php echo '{$output}';?>", new Smarty_Internal_ParseTree_Tag(
true))); $compiler->parser,
$compiler->processNocacheCode(
"<?php echo '{$output}';?>",
true
)
)
);
return ''; return '';
} elseif ($compiler->php_handling === Smarty::PHP_ALLOW) { } elseif ($compiler->php_handling === Smarty::PHP_ALLOW) {
if (!($compiler->smarty instanceof SmartyBC)) { if (!($compiler->smarty instanceof SmartyBC)) {
$compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', $compiler->trigger_template_error(
null, true); '$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it',
null,
true
);
} }
$compiler->has_code = true; $compiler->has_code = true;
return $_attr[ 'code' ]; return $_attr[ 'code' ];
@ -80,8 +99,11 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
} else { } else {
$compiler->has_code = true; $compiler->has_code = true;
if (!($compiler->smarty instanceof SmartyBC)) { if (!($compiler->smarty instanceof SmartyBC)) {
$compiler->trigger_template_error('{php}{/php} tags not allowed. Use SmartyBC to enable them', null, $compiler->trigger_template_error(
true); '{php}{/php} tags not allowed. Use SmartyBC to enable them',
null,
true
);
} }
$ldel = preg_quote($compiler->smarty->left_delimiter, '#'); $ldel = preg_quote($compiler->smarty->left_delimiter, '#');
$rdel = preg_quote($compiler->smarty->right_delimiter, '#'); $rdel = preg_quote($compiler->smarty->right_delimiter, '#');
@ -93,8 +115,11 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
$compiler->trigger_template_error("illegal value of option flag '{$match[2]}'", null, true); $compiler->trigger_template_error("illegal value of option flag '{$match[2]}'", null, true);
} }
} }
return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), return preg_replace(
array('<?php ', '?>'), $_attr[ 'code' ]); array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"),
array('<?php ', '?>'),
$_attr[ 'code' ]
);
} }
} }
@ -148,8 +173,10 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
if ($lex->phpType === 'unmatched') { if ($lex->phpType === 'unmatched') {
return; return;
} }
if (($lex->phpType === 'php' || $lex->phpType === 'asp') && if (($lex->phpType === 'php' || $lex->phpType === 'asp')
($lex->compiler->php_handling === Smarty::PHP_PASSTHRU || $lex->compiler->php_handling === Smarty::PHP_QUOTE) &&
($lex->compiler->php_handling === Smarty::PHP_PASSTHRU ||
$lex->compiler->php_handling === Smarty::PHP_QUOTE)
) { ) {
return; return;
} }
@ -161,8 +188,14 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
$lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'"); $lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'");
} }
while ($body) { while ($body) {
if (preg_match('~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~', if (preg_match(
$lex->data, $match, PREG_OFFSET_CAPTURE, $start)) { '~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~',
$lex->data,
$match,
PREG_OFFSET_CAPTURE,
$start
)
) {
$value = $match[ 0 ][ 0 ]; $value = $match[ 0 ][ 0 ];
$from = $pos = $match[ 0 ][ 1 ]; $from = $pos = $match[ 0 ][ 1 ];
if ($pos > $close) { if ($pos > $close) {
@ -178,8 +211,14 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
} }
} }
while ($close > $pos && $close < $start) { while ($close > $pos && $close < $start) {
if (preg_match('~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE, if (preg_match(
$from)) { '~' . preg_quote($closeTag, '~') . '~i',
$lex->data,
$match,
PREG_OFFSET_CAPTURE,
$from
)
) {
$close = $match[ 0 ][ 1 ]; $close = $match[ 0 ][ 1 ];
$from = $close + strlen($match[ 0 ][ 0 ]); $from = $close + strlen($match[ 0 ][ 0 ]);
} else { } else {

@ -49,9 +49,14 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
$output = $parameter[ 'value' ]; $output = $parameter[ 'value' ];
// tag modifier // tag modifier
if (!empty($parameter[ 'modifierlist' ])) { if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(), $output = $compiler->compileTag(
array('modifierlist' => $parameter[ 'modifierlist' ], 'private_modifier',
'value' => $output)); array(),
array(
'modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output
)
);
} }
if (isset($_attr[ 'assign' ])) { if (isset($_attr[ 'assign' ])) {
// assign output to variable // assign output to variable
@ -64,8 +69,11 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
if (empty($compiler->default_modifier_list)) { if (empty($compiler->default_modifier_list)) {
$modifierlist = array(); $modifierlist = array();
foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) { foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) {
preg_match_all('/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/', preg_match_all(
$single_default_modifier, $mod_array); '/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/',
$single_default_modifier,
$mod_array
);
for ($i = 0, $count = count($mod_array[ 0 ]); $i < $count; $i++) { for ($i = 0, $count = count($mod_array[ 0 ]); $i < $count; $i++) {
if ($mod_array[ 0 ][ $i ] !== ':') { if ($mod_array[ 0 ][ $i ] !== ':') {
$modifierlist[ $key ][] = $mod_array[ 0 ][ $i ]; $modifierlist[ $key ][] = $mod_array[ 0 ][ $i ];
@ -74,9 +82,14 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
} }
$compiler->default_modifier_list = $modifierlist; $compiler->default_modifier_list = $modifierlist;
} }
$output = $compiler->compileTag('private_modifier', array(), $output = $compiler->compileTag(
array('modifierlist' => $compiler->default_modifier_list, 'private_modifier',
'value' => $output)); array(),
array(
'modifierlist' => $compiler->default_modifier_list,
'value' => $output
)
);
} }
// autoescape html // autoescape html
if ($compiler->template->smarty->escape_html) { if ($compiler->template->smarty->escape_html) {
@ -98,8 +111,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
} }
// auto loaded filters // auto loaded filters
if (isset($compiler->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ])) { if (isset($compiler->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ])) {
foreach ((array) $compiler->template->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ] as $name) foreach ((array)$compiler->template->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ] as $name) {
{
$result = $this->compile_variable_filter($compiler, $name, $output); $result = $this->compile_variable_filter($compiler, $name, $output);
if ($result !== false) { if ($result !== false) {
$output = $result; $output = $result;
@ -110,19 +122,21 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
} }
} }
foreach ($compiler->variable_filters as $filter) { foreach ($compiler->variable_filters as $filter) {
if (count($filter) === 1 && if (count($filter) === 1
($result = $this->compile_variable_filter($compiler, $filter[ 0 ], $output)) !== false && ($result = $this->compile_variable_filter($compiler, $filter[ 0 ], $output)) !== false
) { ) {
$output = $result; $output = $result;
} else { } else {
$output = $compiler->compileTag('private_modifier', array(), $output = $compiler->compileTag(
array('modifierlist' => array($filter), 'value' => $output)); 'private_modifier',
array(),
array('modifierlist' => array($filter), 'value' => $output)
);
} }
} }
} }
$output = "<?php echo {$output};?>\n"; $output = "<?php echo {$output};?>\n";
} }
return $output; return $output;
} }

@ -76,9 +76,14 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
} }
} }
if (!empty($parameter[ 'modifierlist' ])) { if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(), $output = $compiler->compileTag(
array('modifierlist' => $parameter[ 'modifierlist' ], 'private_modifier',
'value' => $output)); array(),
array(
'modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output
)
);
} }
$output = "<?php echo {$output};?>\n"; $output = "<?php echo {$output};?>\n";
return $output; return $output;

@ -33,8 +33,8 @@ 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':
@ -43,7 +43,11 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
$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(),
$compiler,
$_index
);
case 'capture': case 'capture':
if (class_exists('Smarty_Internal_Compile_Capture')) { if (class_exists('Smarty_Internal_Compile_Capture')) {
return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index); return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);
@ -52,8 +56,8 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
case 'now': case 'now':
return 'time()'; return 'time()';
case 'cookies': case 'cookies':
if (isset($compiler->smarty->security_policy) && if (isset($compiler->smarty->security_policy)
!$compiler->smarty->security_policy->allow_super_globals && !$compiler->smarty->security_policy->allow_super_globals
) { ) {
$compiler->trigger_template_error("(secure mode) super globals not permitted"); $compiler->trigger_template_error("(secure mode) super globals not permitted");
break; break;
@ -66,30 +70,25 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
case 'server': case 'server':
case 'session': case 'session':
case 'request': case 'request':
if (isset($compiler->smarty->security_policy) && if (isset($compiler->smarty->security_policy)
!$compiler->smarty->security_policy->allow_super_globals && !$compiler->smarty->security_policy->allow_super_globals
) { ) {
$compiler->trigger_template_error("(secure mode) super globals not permitted"); $compiler->trigger_template_error("(secure mode) super globals not permitted");
break; break;
} }
$compiled_ref = '$_' . strtoupper($variable); $compiled_ref = '$_' . strtoupper($variable);
break; break;
case 'template': case 'template':
return 'basename($_smarty_tpl->source->filepath)'; return 'basename($_smarty_tpl->source->filepath)';
case 'template_object': case 'template_object':
return '$_smarty_tpl'; return '$_smarty_tpl';
case 'current_dir': case 'current_dir':
return 'dirname($_smarty_tpl->source->filepath)'; return 'dirname($_smarty_tpl->source->filepath)';
case 'version': case 'version':
return "Smarty::SMARTY_VERSION"; return "Smarty::SMARTY_VERSION";
case 'const': case 'const':
if (isset($compiler->smarty->security_policy) && if (isset($compiler->smarty->security_policy)
!$compiler->smarty->security_policy->allow_constants && !$compiler->smarty->security_policy->allow_constants
) { ) {
$compiler->trigger_template_error("(secure mode) constants not permitted"); $compiler->trigger_template_error("(secure mode) constants not permitted");
break; break;
@ -99,13 +98,14 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
} else { } else {
return "@constant({$_index[1]})"; return "@constant({$_index[1]})";
} }
// no break
case 'config': case 'config':
if (isset($_index[ 2 ])) { if (isset($_index[ 2 ])) {
return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)"; return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
} else { } else {
return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])"; return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])";
} }
// no break
case 'ldelim': case 'ldelim':
return "\$_smarty_tpl->smarty->left_delimiter"; return "\$_smarty_tpl->smarty->left_delimiter";
case 'rdelim': case 'rdelim':

@ -59,8 +59,10 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
* *
* @var array * @var array
*/ */
public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum', 'index_prev', public $nameProperties = array(
'index_next', 'loop'); 'first', 'last', 'index', 'iteration', 'show', 'total', 'rownum', 'index_prev',
'index_next', 'loop'
);
/** /**
* {section} tag has no item properties * {section} tag has no item properties
@ -103,15 +105,14 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$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
@ -165,7 +166,6 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$v = "{$local}step"; $v = "{$local}step";
$t = 2; $t = 2;
break; break;
case 'max': case 'max':
case 'start': case 'start':
if (is_numeric($attr_value)) { if (is_numeric($attr_value)) {
@ -183,7 +183,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,7 +191,6 @@ 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']++";
@ -204,7 +202,6 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
} 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 +214,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,12 +235,14 @@ 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",
19 => ')'); 19 => ')'
);
if ($propType[ 'step' ] === 0) { if ($propType[ 'step' ] === 0) {
$start_code[ 3 ] = $start_code[ 5 ] = $start_code[ 15 ] = $start_code[ 17 ] = ''; $start_code[ 3 ] = $start_code[ 5 ] = $start_code[ 15 ] = $start_code[ 17 ] = '';
if ($propValue[ 'step' ] > 0) { if ($propValue[ 'step' ] > 0) {
@ -264,8 +262,12 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$start_code[ $i ] = ''; $start_code[ $i ] = '';
} }
if ($propType[ 'start' ] === 0) { if ($propType[ 'start' ] === 0) {
$start_code = array(max($propValue[ 'step' ] > 0 ? 0 : - 1, $start_code = array(
$propValue[ 'start' ] + $propValue[ 'loop' ])); max(
$propValue[ 'step' ] > 0 ? 0 : -1,
$propValue[ 'start' ] + $propValue[ 'loop' ]
)
);
} }
} else { } else {
for ($i = 1; $i <= 11; $i++) { for ($i = 1; $i <= 11; $i++) {
@ -273,8 +275,12 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
} }
if ($propType[ 'start' ] === 0) { if ($propType[ 'start' ] === 0) {
$start_code = $start_code =
array(min($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1, array(
$propValue[ 'start' ])); min(
$propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1,
$propValue[ 'start' ]
)
);
} }
} }
} }
@ -284,9 +290,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' ];
@ -295,13 +299,20 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$propType[ 'start' ] + $propType[ 'loop' ] + $propType[ 'step' ] + $propType[ 'max' ]; $propType[ 'start' ] + $propType[ 'loop' ] + $propType[ 'step' ] + $propType[ 'max' ];
if ($propType[ 'total' ] === 0) { if ($propType[ 'total' ] === 0) {
$propValue[ 'total' ] = $propValue[ 'total' ] =
min(ceil(($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] - $propValue[ 'start' ] : min(
(int) $propValue[ 'start' ] + 1) / abs($propValue[ 'step' ])), $propValue[ 'max' ]); ceil(
($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] - $propValue[ 'start' ] :
(int)$propValue[ 'start' ] + 1) / abs($propValue[ 'step' ])
),
$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 ] = '';
} }
@ -330,7 +341,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']}";
} }
@ -343,13 +353,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";
@ -388,7 +395,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;
} }
} }
@ -413,10 +419,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 ?>";
} }
} }
@ -444,10 +448,8 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
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";
@ -455,7 +457,6 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
$output .= "}\n}\n"; $output .= "}\n}\n";
} }
$output .= '?>'; $output .= '?>';
return $output; return $output;
} }
} }

@ -31,7 +31,6 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase
$compiler->variable_filters = $parameter[ 'modifier_list' ]; $compiler->variable_filters = $parameter[ 'modifier_list' ];
// this tag does not return compiled code // this tag does not return compiled code
$compiler->has_code = false; $compiler->has_code = false;
return true; return true;
} }
} }
@ -64,7 +63,6 @@ class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase
} }
// this tag does not return compiled code // this tag does not return compiled code
$compiler->has_code = false; $compiler->has_code = false;
return true; return true;
} }
} }

@ -22,7 +22,7 @@ class Smarty_Internal_Compile_Shared_Inheritance extends Smarty_Internal_Compile
* @param \Smarty_Internal_TemplateCompilerBase $compiler * @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param bool|false $initChildSequence if true force child template * @param bool|false $initChildSequence if true force child template
*/ */
static function postCompile(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false) public static function postCompile(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
{ {
$compiler->prefixCompiledCode .= "<?php \$_smarty_tpl->_loadInheritance();\n\$_smarty_tpl->inheritance->init(\$_smarty_tpl, " . $compiler->prefixCompiledCode .= "<?php \$_smarty_tpl->_loadInheritance();\n\$_smarty_tpl->inheritance->init(\$_smarty_tpl, " .
var_export($initChildSequence, true) . ");\n?>\n"; var_export($initChildSequence, true) . ");\n?>\n";
@ -37,11 +37,12 @@ class Smarty_Internal_Compile_Shared_Inheritance extends Smarty_Internal_Compile
public function registerInit(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false) public function registerInit(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
{ {
if ($initChildSequence || !isset($compiler->_cache[ 'inheritanceInit' ])) { if ($initChildSequence || !isset($compiler->_cache[ 'inheritanceInit' ])) {
$compiler->registerPostCompileCallback(array('Smarty_Internal_Compile_Shared_Inheritance', 'postCompile'), $compiler->registerPostCompileCallback(
array('Smarty_Internal_Compile_Shared_Inheritance', 'postCompile'),
array($initChildSequence), array($initChildSequence),
'inheritanceInit', 'inheritanceInit',
$initChildSequence); $initChildSequence
);
$compiler->_cache[ 'inheritanceInit' ] = true; $compiler->_cache[ 'inheritanceInit' ] = true;
} }
} }

@ -32,11 +32,9 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$this->openTag($compiler, 'while', $compiler->nocache); $this->openTag($compiler, 'while', $compiler->nocache);
if (!array_key_exists('if condition', $parameter)) { if (!array_key_exists('if condition', $parameter)) {
$compiler->trigger_template_error('missing while condition', null, true); $compiler->trigger_template_error('missing while condition', null, true);
} }
// 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;
if (is_array($parameter[ 'if condition' ])) { if (is_array($parameter[ 'if condition' ])) {
@ -56,14 +54,16 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
if (is_array($parameter[ 'if condition' ][ 'var' ])) { if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ]; $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
$_output = "<?php while ({$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]}) {?>"; $_output = "<?php while ({$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]}) {?>";
$_output .= $assignCompiler->compile($assignAttr, $compiler, $_output .= $assignCompiler->compile(
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])); $assignAttr,
$compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
);
} else { } else {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ]; $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
$_output = "<?php while ({$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]}) {?>"; $_output = "<?php while ({$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]}) {?>";
$_output .= $assignCompiler->compile($assignAttr, $compiler, array()); $_output .= $assignCompiler->compile($assignAttr, $compiler, array());
} }
return $_output; return $_output;
} else { } else {
return "<?php\n while ({$parameter['if condition']}) {?>"; return "<?php\n while ({$parameter['if condition']}) {?>";

@ -103,8 +103,12 @@ abstract class Smarty_Internal_CompileBase
if (isset($this->optionMap[ $v ])) { if (isset($this->optionMap[ $v ])) {
$_indexed_attr[ $k ] = $this->optionMap[ $v ]; $_indexed_attr[ $k ] = $this->optionMap[ $v ];
} else { } else {
$compiler->trigger_template_error("illegal value '" . var_export($v, true) . $compiler->trigger_template_error(
"' for option flag '{$k}'", null, true); "illegal value '" . var_export($v, true) .
"' for option flag '{$k}'",
null,
true
);
} }
} }
// must be named attribute // must be named attribute
@ -124,8 +128,14 @@ abstract class Smarty_Internal_CompileBase
if ($this->optional_attributes !== array('_any')) { if ($this->optional_attributes !== array('_any')) {
if (!isset($this->mapCache[ 'all' ])) { if (!isset($this->mapCache[ 'all' ])) {
$this->mapCache[ 'all' ] = $this->mapCache[ 'all' ] =
array_fill_keys(array_merge($this->required_attributes, $this->optional_attributes, array_fill_keys(
$this->option_flags), true); array_merge(
$this->required_attributes,
$this->optional_attributes,
$this->option_flags
),
true
);
} }
foreach ($_indexed_attr as $key => $dummy) { foreach ($_indexed_attr as $key => $dummy) {
if (!isset($this->mapCache[ 'all' ][ $key ]) && $key !== 0) { if (!isset($this->mapCache[ 'all' ][ $key ]) && $key !== 0) {
@ -184,12 +194,10 @@ abstract class Smarty_Internal_CompileBase
} }
// wrong nesting of tags // wrong nesting of tags
$compiler->trigger_template_error("unclosed '{$compiler->smarty->left_delimiter}{$_openTag}{$compiler->smarty->right_delimiter}' tag"); $compiler->trigger_template_error("unclosed '{$compiler->smarty->left_delimiter}{$_openTag}{$compiler->smarty->right_delimiter}' tag");
return; return;
} }
// wrong nesting of tags // wrong nesting of tags
$compiler->trigger_template_error('unexpected closing tag', null, true); $compiler->trigger_template_error('unexpected closing tag', null, true);
return; return;
} }
} }

@ -103,9 +103,11 @@ class Smarty_Internal_Config_File_Compiler
{ {
$this->template = $template; $this->template = $template;
$this->template->compiled->file_dependency[ $this->template->source->uid ] = $this->template->compiled->file_dependency[ $this->template->source->uid ] =
array($this->template->source->filepath, array(
$this->template->source->filepath,
$this->template->source->getTimeStamp(), $this->template->source->getTimeStamp(),
$this->template->source->type); $this->template->source->type
);
if ($this->smarty->debugging) { if ($this->smarty->debugging) {
if (!isset($this->smarty->_debug)) { if (!isset($this->smarty->_debug)) {
$this->smarty->_debug = new Smarty_Internal_Debug(); $this->smarty->_debug = new Smarty_Internal_Debug();
@ -114,12 +116,19 @@ class Smarty_Internal_Config_File_Compiler
} }
// init the lexer/parser to compile the config file // init the lexer/parser to compile the config file
/* @var Smarty_Internal_ConfigFileLexer $this ->lex */ /* @var Smarty_Internal_ConfigFileLexer $this ->lex */
$this->lex = new $this->lexer_class(str_replace(array("\r\n", $this->lex = new $this->lexer_class(
"\r"), "\n", $template->source->getContent()) . "\n", str_replace(
$this); array(
"\r\n",
"\r"
),
"\n",
$template->source->getContent()
) . "\n",
$this
);
/* @var Smarty_Internal_ConfigFileParser $this ->parser */ /* @var Smarty_Internal_ConfigFileParser $this ->parser */
$this->parser = new $this->parser_class($this->lex, $this); $this->parser = new $this->parser_class($this->lex, $this);
if (function_exists('mb_internal_encoding') if (function_exists('mb_internal_encoding')
&& function_exists('ini_get') && function_exists('ini_get')
&& ((int)ini_get('mbstring.func_overload')) & 2 && ((int)ini_get('mbstring.func_overload')) & 2
@ -141,7 +150,6 @@ class Smarty_Internal_Config_File_Compiler
} }
// finish parsing process // finish parsing process
$this->parser->doParse(0, 0); $this->parser->doParse(0, 0);
if ($mbEncoding) { if ($mbEncoding) {
mb_internal_encoding($mbEncoding); mb_internal_encoding($mbEncoding);
} }
@ -153,7 +161,6 @@ class Smarty_Internal_Config_File_Compiler
"<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") .
"\n"; "\n";
$template_header .= " compiled from '{$this->template->source->filepath}' */ ?>\n"; $template_header .= " compiled from '{$this->template->source->filepath}' */ ?>\n";
$code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' . $code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
var_export($this->config_data, true) . '); ?>'; var_export($this->config_data, true) . '); ?>';
return $template_header . $this->template->smarty->ext->_codeFrame->create($this->template, $code); return $template_header . $this->template->smarty->ext->_codeFrame->create($this->template, $code);

@ -27,73 +27,86 @@ class Smarty_Internal_Configfilelexer
const COMMENT = 4; const COMMENT = 4;
const SECTION = 5; const SECTION = 5;
const TRIPPLE = 6; const TRIPPLE = 6;
/** /**
* Source * Source
* *
* @var string * @var string
*/ */
public $data; public $data;
/** /**
* Source length * Source length
* *
* @var int * @var int
*/ */
public $dataLength = null; public $dataLength = null;
/** /**
* byte counter * byte counter
* *
* @var int * @var int
*/ */
public $counter; public $counter;
/** /**
* token number * token number
* *
* @var int * @var int
*/ */
public $token; public $token;
/** /**
* token value * token value
* *
* @var string * @var string
*/ */
public $value; public $value;
/** /**
* current line * current line
* *
* @var int * @var int
*/ */
public $line; public $line;
/** /**
* state number * state number
* *
* @var int * @var int
*/ */
public $state = 1; public $state = 1;
/** /**
* Smarty object * Smarty object
* *
* @var Smarty * @var Smarty
*/ */
public $smarty = null; public $smarty = null;
/** /**
* trace file * trace file
* *
* @var resource * @var resource
*/ */
public $yyTraceFILE; public $yyTraceFILE;
/** /**
* trace prompt * trace prompt
* *
* @var string * @var string
*/ */
public $yyTracePrompt; public $yyTracePrompt;
/** /**
* state names * state names
* *
* @var array * @var array
*/ */
public $state_name = array(1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION', public $state_name = array(
6 => 'TRIPPLE'); 1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION', 6 => 'TRIPPLE'
);
/** /**
* token names * token names
* *
@ -101,30 +114,40 @@ class Smarty_Internal_Configfilelexer
*/ */
public $smarty_token_names = array( // Text for parser error messages public $smarty_token_names = array( // Text for parser error messages
); );
/** /**
* compiler object * compiler object
* *
* @var Smarty_Internal_Config_File_Compiler * @var Smarty_Internal_Config_File_Compiler
*/ */
private $compiler = null; private $compiler = null;
/** /**
* copy of config_booleanize * copy of config_booleanize
* *
* @var bool * @var bool
*/ */
private $configBooleanize = false; private $configBooleanize = false;
/** /**
* storage for assembled token patterns * storage for assembled token patterns
* *
* @var string * @var string
*/ */
private $yy_global_pattern1 = null; private $yy_global_pattern1 = null;
private $yy_global_pattern2 = null; private $yy_global_pattern2 = null;
private $yy_global_pattern3 = null; private $yy_global_pattern3 = null;
private $yy_global_pattern4 = null; private $yy_global_pattern4 = null;
private $yy_global_pattern5 = null; private $yy_global_pattern5 = null;
private $yy_global_pattern6 = null; private $yy_global_pattern6 = null;
private $_yy_state = 1; private $_yy_state = 1;
private $_yy_stack = array(); private $_yy_stack = array();
/** /**
@ -133,7 +156,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);
@ -166,39 +189,43 @@ class Smarty_Internal_Configfilelexer
public function yypushstate($state) public function yypushstate($state)
{ {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, fprintf(
$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 ] : isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $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($this->yyTraceFILE, fprintf(
$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 ] : isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state
$this->_yy_state); );
} }
} }
public function yypopstate() public function yypopstate()
{ {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, fprintf(
$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 ] : isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $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($this->yyTraceFILE, fprintf(
$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 ] : isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state
$this->_yy_state); );
} }
} }
@ -206,11 +233,12 @@ class Smarty_Internal_Configfilelexer
{ {
$this->_yy_state = $state; $this->_yy_state = $state;
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, fprintf(
$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 ] : isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state
$this->_yy_state); );
} }
} }
@ -235,9 +263,11 @@ class Smarty_Internal_Configfilelexer
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data, ' an empty string. Input "' . substr(
$this->data,
$this->counter, $this->counter,
5) . '... state START'); 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
@ -269,45 +299,45 @@ class Smarty_Internal_Configfilelexer
} while (true); } while (true);
} }
function yy_r1_1() public function yy_r1_1()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART; $this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART;
$this->yypushstate(self::COMMENT); $this->yypushstate(self::COMMENT);
} }
function yy_r1_2() public function yy_r1_2()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_OPENB; $this->token = Smarty_Internal_Configfileparser::TPC_OPENB;
$this->yypushstate(self::SECTION); $this->yypushstate(self::SECTION);
} }
function yy_r1_3() public function yy_r1_3()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB; $this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB;
} }
function yy_r1_4() public function yy_r1_4()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_EQUAL; $this->token = Smarty_Internal_Configfileparser::TPC_EQUAL;
$this->yypushstate(self::VALUE); $this->yypushstate(self::VALUE);
} // end function } // end function
function yy_r1_5() public function yy_r1_5()
{ {
return false; return false;
} }
function yy_r1_6() public function yy_r1_6()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE; $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
} }
function yy_r1_7() public function yy_r1_7()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_ID; $this->token = Smarty_Internal_Configfileparser::TPC_ID;
} }
function yy_r1_8() public function yy_r1_8()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_OTHER; $this->token = Smarty_Internal_Configfileparser::TPC_OTHER;
} }
@ -333,9 +363,11 @@ class Smarty_Internal_Configfilelexer
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data, ' an empty string. Input "' . substr(
$this->data,
$this->counter, $this->counter,
5) . '... state VALUE'); 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
@ -367,42 +399,42 @@ class Smarty_Internal_Configfilelexer
} while (true); } while (true);
} }
function yy_r2_1() public function yy_r2_1()
{ {
return false; return false;
} }
function yy_r2_2() public function yy_r2_2()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_FLOAT; $this->token = Smarty_Internal_Configfileparser::TPC_FLOAT;
$this->yypopstate(); $this->yypopstate();
} }
function yy_r2_3() public function yy_r2_3()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_INT; $this->token = Smarty_Internal_Configfileparser::TPC_INT;
$this->yypopstate(); $this->yypopstate();
} }
function yy_r2_4() public function yy_r2_4()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES; $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES;
$this->yypushstate(self::TRIPPLE); $this->yypushstate(self::TRIPPLE);
} }
function yy_r2_5() public function yy_r2_5()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING; $this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING;
$this->yypopstate(); $this->yypopstate();
} }
function yy_r2_6() public function yy_r2_6()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING; $this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING;
$this->yypopstate(); $this->yypopstate();
} // end function } // end function
function yy_r2_7() public 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'))) {
@ -415,13 +447,13 @@ class Smarty_Internal_Configfilelexer
} }
} }
function yy_r2_8() public function yy_r2_8()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING; $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->yypopstate(); $this->yypopstate();
} }
function yy_r2_9() public function yy_r2_9()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING; $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->value = ''; $this->value = '';
@ -448,9 +480,11 @@ class Smarty_Internal_Configfilelexer
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data, ' an empty string. Input "' . substr(
$this->data,
$this->counter, $this->counter,
5) . '... state NAKED_STRING_VALUE'); 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
@ -482,7 +516,7 @@ class Smarty_Internal_Configfilelexer
} while (true); } while (true);
} }
function yy_r3_1() public function yy_r3_1()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING; $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->yypopstate(); $this->yypopstate();
@ -508,9 +542,11 @@ class Smarty_Internal_Configfilelexer
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data, ' an empty string. Input "' . substr(
$this->data,
$this->counter, $this->counter,
5) . '... state COMMENT'); 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
@ -542,17 +578,17 @@ class Smarty_Internal_Configfilelexer
} while (true); } while (true);
} }
function yy_r4_1() public function yy_r4_1()
{ {
return false; return false;
} }
function yy_r4_2() public function yy_r4_2()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING; $this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
} // end function } // end function
function yy_r4_3() public function yy_r4_3()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE; $this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
$this->yypopstate(); $this->yypopstate();
@ -578,9 +614,11 @@ class Smarty_Internal_Configfilelexer
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data, ' an empty string. Input "' . substr(
$this->data,
$this->counter, $this->counter,
5) . '... state SECTION'); 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
@ -612,12 +650,12 @@ class Smarty_Internal_Configfilelexer
} while (true); } while (true);
} }
function yy_r5_1() public function yy_r5_1()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_DOT; $this->token = Smarty_Internal_Configfileparser::TPC_DOT;
} }
function yy_r5_2() public function yy_r5_2()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_SECTION; $this->token = Smarty_Internal_Configfileparser::TPC_SECTION;
$this->yypopstate(); $this->yypopstate();
@ -643,9 +681,11 @@ class Smarty_Internal_Configfilelexer
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data, ' an empty string. Input "' . substr(
$this->data,
$this->counter, $this->counter,
5) . '... state TRIPPLE'); 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
@ -677,21 +717,21 @@ class Smarty_Internal_Configfilelexer
} while (true); } while (true);
} }
function yy_r6_1() public function yy_r6_1()
{ {
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES_END; $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES_END;
$this->yypopstate(); $this->yypopstate();
$this->yypushstate(self::START); $this->yypushstate(self::START);
} }
function yy_r6_2() public function yy_r6_2()
{ {
$to = strlen($this->data); $to = strlen($this->data);
preg_match("/\"\"\"[ \t\r]*[\n#;]/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); preg_match("/\"\"\"[ \t\r]*[\n#;]/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter);
if (isset($match[ 0 ][ 1 ])) { if (isset($match[ 0 ][ 1 ])) {
$to = $match[ 0 ][ 1 ]; $to = $match[ 0 ][ 1 ];
} else { } else {
$this->compiler->trigger_template_error('missing or misspelled literal closing tag'); $this->compiler->trigger_config_file_error('missing or misspelled literal closing tag');
} }
$this->value = substr($this->data, $this->counter, $to - $this->counter); $this->value = substr($this->data, $this->counter, $to - $this->counter);
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT; $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT;

@ -9,7 +9,7 @@ class TPC_yyStackEntry
** is the value of the token */ ** is the value of the token */
} }
#line 12 "../smarty/lexer/smarty_internal_configfileparser.y" // line 12 "../smarty/lexer/smarty_internal_configfileparser.y"
/** /**
* Smarty Internal Plugin Configfileparse * Smarty Internal Plugin Configfileparse
@ -23,7 +23,7 @@ class TPC_yyStackEntry
*/ */
class Smarty_Internal_Configfileparser class Smarty_Internal_Configfileparser
{ {
#line 25 "../smarty/lexer/smarty_internal_configfileparser.y" // line 25 "../smarty/lexer/smarty_internal_configfileparser.y"
const TPC_OPENB = 1; const TPC_OPENB = 1;
const TPC_SECTION = 2; const TPC_SECTION = 2;
const TPC_CLOSEB = 3; const TPC_CLOSEB = 3;
@ -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;
@ -57,27 +57,32 @@ class Smarty_Internal_Configfileparser
const YYERRORSYMBOL = 19; const YYERRORSYMBOL = 19;
const YYERRSYMDT = 'yy0'; const YYERRSYMDT = 'yy0';
const YYFALLBACK = 0; const YYFALLBACK = 0;
static public $yy_action = array(
29, 30, 34, 33, 24, 13, 19, 25, 35, 21, public static $yy_action = array(
59, 8, 3, 1, 20, 12, 14, 31, 20, 12, 32, 31, 30, 29, 35, 13, 19, 3, 24, 26,
15, 17, 23, 18, 27, 26, 4, 5, 6, 32, 59, 9, 14, 1, 16, 25, 11, 28, 25, 11,
2, 11, 28, 22, 16, 9, 7, 10, 17, 27, 34, 20, 18, 15, 23, 5, 6, 22,
10, 8, 4, 12, 2, 33, 7, 21,
); );
static public $yy_lookahead = array(
7, 8, 9, 10, 11, 12, 5, 27, 15, 16, public static $yy_lookahead = array(
20, 21, 23, 23, 17, 18, 13, 14, 17, 18, 7, 8, 9, 10, 11, 12, 5, 23, 15, 16,
15, 2, 17, 4, 25, 26, 6, 3, 3, 14, 20, 21, 2, 23, 4, 17, 18, 14, 17, 18,
23, 1, 24, 17, 2, 25, 22, 25, 13, 14, 25, 26, 15, 2, 17, 3, 3, 17,
25, 25, 6, 1, 23, 27, 22, 24,
); );
static public $yy_shift_ofst = array(
-8, 1, 1, 1, -7, -3, -3, 30, -8, -8, public static $yy_shift_ofst = array(
-8, 19, 5, 3, 15, 16, 24, 25, 32, 20, -8, 1, 1, 1, -7, -2, -2, 32, -8, -8,
-8, 9, 10, 7, 25, 24, 23, 3, 12, 26,
); );
static public $yy_reduce_ofst = array(
-10, -1, -1, -1, -20, 10, 12, 8, 14, 7, public static $yy_reduce_ofst = array(
-11, -10, -3, -3, -3, 8, 6, 5, 13, 11, 14,
-16,
); );
static public $yyExpectedTokens = array(
public static $yyExpectedTokens = array(
array(), array(),
array(5, 17, 18,), array(5, 17, 18,),
array(5, 17, 18,), array(5, 17, 18,),
@ -89,14 +94,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(),
@ -115,13 +120,16 @@ class Smarty_Internal_Configfileparser
array(), array(),
array(), array(),
); );
static public $yy_default = array(
44, 37, 41, 40, 58, 58, 58, 36, 39, 44, public static $yy_default = array(
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(
'start ::= global_vars sections', 'start ::= global_vars sections',
'global_vars ::= var_list', 'global_vars ::= var_list',
@ -146,6 +154,7 @@ class Smarty_Internal_Configfileparser
'newline ::= COMMENTSTART NEWLINE', 'newline ::= COMMENTSTART NEWLINE',
'newline ::= COMMENTSTART NAKED_STRING NEWLINE', 'newline ::= COMMENTSTART NAKED_STRING NEWLINE',
); );
public static $yyRuleInfo = array( public static $yyRuleInfo = array(
array(0 => 20, 1 => 2), array(0 => 20, 1 => 2),
array(0 => 21, 1 => 1), array(0 => 21, 1 => 1),
@ -170,6 +179,7 @@ class Smarty_Internal_Configfileparser
array(0 => 25, 1 => 2), array(0 => 25, 1 => 2),
array(0 => 25, 1 => 3), array(0 => 25, 1 => 3),
); );
public static $yyReduceMap = array( public static $yyReduceMap = array(
0 => 0, 0 => 0,
2 => 0, 2 => 0,
@ -194,46 +204,60 @@ class Smarty_Internal_Configfileparser
17 => 17, 17 => 17,
18 => 17, 18 => 17,
); );
/** /**
* helper map * helper map
* *
* @var array * @var array
*/ */
private static $escapes_single = array('\\' => '\\', private static $escapes_single = array(
'\'' => '\''); '\\' => '\\',
'\'' => '\''
);
/** /**
* result status * result status
* *
* @var bool * @var bool
*/ */
public $successful = true; public $successful = true;
/** /**
* return value * return value
* *
* @var mixed * @var mixed
*/ */
public $retvalue = 0; public $retvalue = 0;
/** /**
* @var * @var
*/ */
public $yymajor; public $yymajor;
/** /**
* compiler object * compiler object
* *
* @var Smarty_Internal_Config_File_Compiler * @var Smarty_Internal_Config_File_Compiler
*/ */
public $compiler = null; public $compiler = null;
/** /**
* smarty object * smarty object
* *
* @var Smarty * @var Smarty
*/ */
public $smarty = null; public $smarty = null;
public $yyTraceFILE; public $yyTraceFILE;
public $yyTracePrompt; public $yyTracePrompt;
public $yyidx; public $yyidx;
public $yyerrcnt; public $yyerrcnt;
public $yystack = array(); public $yystack = array();
public $yyTokenName = array( public $yyTokenName = array(
'$', 'OPENB', 'SECTION', 'CLOSEB', '$', 'OPENB', 'SECTION', 'CLOSEB',
'DOT', 'ID', 'EQUAL', 'FLOAT', 'DOT', 'ID', 'EQUAL', 'FLOAT',
@ -243,30 +267,35 @@ class Smarty_Internal_Configfileparser
'start', 'global_vars', 'sections', 'var_list', 'start', 'global_vars', 'sections', 'var_list',
'section', 'newline', 'var', 'value', 'section', 'newline', 'var', 'value',
); );
/** /**
* lexer object * lexer object
* *
* @var Smarty_Internal_Configfilelexer * @var Smarty_Internal_Configfilelexer
*/ */
private $lex; private $lex;
/** /**
* internal error flag * internal error flag
* *
* @var bool * @var bool
*/ */
private $internalError = false; private $internalError = false;
/** /**
* copy of config_overwrite property * copy of config_overwrite property
* *
* @var bool * @var bool
*/ */
private $configOverwrite = false; private $configOverwrite = false;
/** /**
* copy of config_read_hidden property * copy of config_read_hidden property
* *
* @var bool * @var bool
*/ */
private $configReadHidden = false; private $configReadHidden = false;
private $_retvalue; private $_retvalue;
/** /**
@ -275,7 +304,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;
@ -375,9 +404,11 @@ 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($this->yyTraceFILE, fwrite(
$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);
@ -387,7 +418,7 @@ class Smarty_Internal_Configfileparser
public function __destruct() public function __destruct()
{ {
while ($this->yystack !== Array()) { while ($this->yystack !== array()) {
$this->yy_pop_parser_stack(); $this->yy_pop_parser_stack();
} }
if (is_resource($this->yyTraceFILE)) { if (is_resource($this->yyTraceFILE)) {
@ -429,7 +460,8 @@ 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 ])) {
@ -515,7 +547,8 @@ 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;
@ -523,10 +556,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($token, (isset(self::$yyExpectedTokens[ $nextstate ]) &&
self::$yyExpectedTokens[ $nextstate ], in_array($token, self::$yyExpectedTokens[ $nextstate ], true))) {
true))) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
return true; return true;
@ -589,8 +621,7 @@ class Smarty_Internal_Configfileparser
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($this->yyTraceFILE, fwrite($this->yyTraceFILE, $this->yyTracePrompt . 'FALLBACK ' .
$this->yyTracePrompt . 'FALLBACK ' .
$this->yyTokenName[ $iLookAhead ] . ' => ' . $this->yyTokenName[ $iLookAhead ] . ' => ' .
$this->yyTokenName[ $iFallback ] . "\n"); $this->yyTokenName[ $iFallback ] . "\n");
} }
@ -635,7 +666,7 @@ class Smarty_Internal_Configfileparser
while ($this->yyidx >= 0) { while ($this->yyidx >= 0) {
$this->yy_pop_parser_stack(); $this->yy_pop_parser_stack();
} }
#line 239 "../smarty/lexer/smarty_internal_configfileparser.y" // line 239 "../smarty/lexer/smarty_internal_configfileparser.y"
$this->internalError = true; $this->internalError = true;
$this->compiler->trigger_config_file_error('Stack overflow in configfile parser'); $this->compiler->trigger_config_file_error('Stack overflow in configfile parser');
return; return;
@ -646,131 +677,142 @@ 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($this->yyTraceFILE, fprintf(
$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($this->yyTraceFILE, fprintf(
$this->yyTraceFILE,
" %s", " %s",
$this->yyTokenName[ $this->yystack[ $i ]->major ]); $this->yyTokenName[ $this->yystack[ $i ]->major ]
);
} }
fwrite($this->yyTraceFILE, "\n"); fwrite($this->yyTraceFILE, "\n");
} }
} }
function yy_r0() public function yy_r0()
{ {
$this->_retvalue = null; $this->_retvalue = null;
} }
function yy_r1() public function yy_r1()
{ {
$this->add_global_vars($this->yystack[ $this->yyidx + 0 ]->minor); $this->add_global_vars($this->yystack[ $this->yyidx + 0 ]->minor);
$this->_retvalue = null; $this->_retvalue = null;
} }
function yy_r4() public function yy_r4()
{ {
$this->add_section_vars($this->yystack[ $this->yyidx + -3 ]->minor, $this->yystack[ $this->yyidx + 0 ]->minor); $this->add_section_vars($this->yystack[ $this->yyidx + -3 ]->minor, $this->yystack[ $this->yyidx + 0 ]->minor);
$this->_retvalue = null; $this->_retvalue = null;
} }
#line 245 "../smarty/lexer/smarty_internal_configfileparser.y" // line 245 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r5() public function yy_r5()
{ {
if ($this->configReadHidden) { if ($this->configReadHidden) {
$this->add_section_vars($this->yystack[ $this->yyidx + -3 ]->minor, $this->add_section_vars(
$this->yystack[ $this->yyidx + 0 ]->minor); $this->yystack[ $this->yyidx + -3 ]->minor,
$this->yystack[ $this->yyidx + 0 ]->minor
);
} }
$this->_retvalue = null; $this->_retvalue = null;
} }
#line 250 "../smarty/lexer/smarty_internal_configfileparser.y" // line 250 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r6() public function yy_r6()
{ {
$this->_retvalue = $this->yystack[ $this->yyidx + -1 ]->minor; $this->_retvalue = $this->yystack[ $this->yyidx + -1 ]->minor;
} }
#line 264 "../smarty/lexer/smarty_internal_configfileparser.y" // line 264 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r7() public function yy_r7()
{ {
$this->_retvalue = $this->_retvalue =
array_merge($this->yystack[ $this->yyidx + -1 ]->minor, array($this->yystack[ $this->yyidx + 0 ]->minor)); array_merge($this->yystack[ $this->yyidx + -1 ]->minor, array($this->yystack[ $this->yyidx + 0 ]->minor));
} }
#line 269 "../smarty/lexer/smarty_internal_configfileparser.y" // line 269 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r8() public function yy_r8()
{ {
$this->_retvalue = array(); $this->_retvalue = array();
} }
#line 277 "../smarty/lexer/smarty_internal_configfileparser.y" // line 277 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r9() public 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"
function yy_r10() public function yy_r10()
{ {
$this->_retvalue = (float)$this->yystack[ $this->yyidx + 0 ]->minor; $this->_retvalue = (float)$this->yystack[ $this->yyidx + 0 ]->minor;
} }
#line 285 "../smarty/lexer/smarty_internal_configfileparser.y" // line 285 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r11() public function yy_r11()
{ {
$this->_retvalue = (int)$this->yystack[ $this->yyidx + 0 ]->minor; $this->_retvalue = (int)$this->yystack[ $this->yyidx + 0 ]->minor;
} }
#line 291 "../smarty/lexer/smarty_internal_configfileparser.y" // line 291 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r12() public function yy_r12()
{ {
$this->_retvalue = $this->parse_bool($this->yystack[ $this->yyidx + 0 ]->minor); $this->_retvalue = $this->parse_bool($this->yystack[ $this->yyidx + 0 ]->minor);
} }
#line 296 "../smarty/lexer/smarty_internal_configfileparser.y" // line 296 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r13() public function yy_r13()
{ {
$this->_retvalue = self::parse_single_quoted_string($this->yystack[ $this->yyidx + 0 ]->minor); $this->_retvalue = self::parse_single_quoted_string($this->yystack[ $this->yyidx + 0 ]->minor);
} }
#line 300 "../smarty/lexer/smarty_internal_configfileparser.y" // line 300 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r14() public function yy_r14()
{ {
$this->_retvalue = self::parse_double_quoted_string($this->yystack[ $this->yyidx + 0 ]->minor); $this->_retvalue = self::parse_double_quoted_string($this->yystack[ $this->yyidx + 0 ]->minor);
} }
#line 304 "../smarty/lexer/smarty_internal_configfileparser.y" // line 304 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r15() public function yy_r15()
{ {
$this->_retvalue = self::parse_tripple_double_quoted_string($this->yystack[ $this->yyidx + -1 ]->minor); $this->_retvalue = self::parse_tripple_double_quoted_string($this->yystack[ $this->yyidx + -1 ]->minor);
} }
#line 308 "../smarty/lexer/smarty_internal_configfileparser.y" // line 308 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r16() public function yy_r16()
{ {
$this->_retvalue = ''; $this->_retvalue = '';
} }
#line 312 "../smarty/lexer/smarty_internal_configfileparser.y" // line 312 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r17() public function yy_r17()
{ {
$this->_retvalue = $this->yystack[ $this->yyidx + 0 ]->minor; $this->_retvalue = $this->yystack[ $this->yyidx + 0 ]->minor;
} }
#line 316 "../smarty/lexer/smarty_internal_configfileparser.y" // line 316 "../smarty/lexer/smarty_internal_configfileparser.y"
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(
$this->yyTraceFILE,
"%sReduce (%d) [%s].\n", "%sReduce (%d) [%s].\n",
$this->yyTracePrompt, $this->yyTracePrompt,
$yyruleno, $yyruleno,
self::$yyRuleName[ $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 ])) {
@ -803,7 +845,7 @@ class Smarty_Internal_Configfileparser
} }
} }
#line 320 "../smarty/lexer/smarty_internal_configfileparser.y" // line 320 "../smarty/lexer/smarty_internal_configfileparser.y"
public function yy_parse_failed() public function yy_parse_failed()
{ {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
@ -814,10 +856,10 @@ class Smarty_Internal_Configfileparser
} }
} }
#line 324 "../smarty/lexer/smarty_internal_configfileparser.y" // line 324 "../smarty/lexer/smarty_internal_configfileparser.y"
public function yy_syntax_error($yymajor, $TOKEN) public function yy_syntax_error($yymajor, $TOKEN)
{ {
#line 232 "../smarty/lexer/smarty_internal_configfileparser.y" // line 232 "../smarty/lexer/smarty_internal_configfileparser.y"
$this->internalError = true; $this->internalError = true;
$this->yymajor = $yymajor; $this->yymajor = $yymajor;
$this->compiler->trigger_config_file_error(); $this->compiler->trigger_config_file_error();
@ -831,7 +873,7 @@ class Smarty_Internal_Configfileparser
while ($this->yyidx >= 0) { while ($this->yyidx >= 0) {
$this->yy_pop_parser_stack(); $this->yy_pop_parser_stack();
} }
#line 225 "../smarty/lexer/smarty_internal_configfileparser.y" // line 225 "../smarty/lexer/smarty_internal_configfileparser.y"
$this->successful = !$this->internalError; $this->successful = !$this->internalError;
$this->internalError = false; $this->internalError = false;
$this->retvalue = $this->_retvalue; $this->retvalue = $this->_retvalue;
@ -851,10 +893,12 @@ class Smarty_Internal_Configfileparser
} }
$yyendofinput = ($yymajor == 0); $yyendofinput = ($yymajor == 0);
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, fprintf(
$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);
@ -875,9 +919,11 @@ class Smarty_Internal_Configfileparser
$this->yy_reduce($yyact - self::YYNSTATE); $this->yy_reduce($yyact - self::YYNSTATE);
} elseif ($yyact === self::YY_ERROR_ACTION) { } elseif ($yyact === self::YY_ERROR_ACTION) {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, fprintf(
$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) {
@ -886,10 +932,12 @@ 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($this->yyTraceFILE, fprintf(
$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;
@ -996,4 +1044,3 @@ class Smarty_Internal_Configfileparser
} }
} }
} }

@ -103,7 +103,11 @@ abstract class Smarty_Internal_Data
} else { } else {
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);
@ -202,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(
$error_enable = true) $variable = null,
{ 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);
} }
@ -277,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)
{ {

@ -117,7 +117,6 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
if (isset($this->ignore_uid[ $template->source->uid ])) { if (isset($this->ignore_uid[ $template->source->uid ])) {
return; return;
} }
$key = $this->get_key($template); $key = $this->get_key($template);
} }
$this->template_data[ $this->index ][ $key ][ 'compile_time' ] += $this->template_data[ $this->index ][ $key ][ 'compile_time' ] +=
@ -211,7 +210,8 @@ 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,8 @@ 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();
@ -237,7 +238,6 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$_config_vars = $ptr->config_vars; $_config_vars = $ptr->config_vars;
ksort($_config_vars); ksort($_config_vars);
$debugging = $smarty->debugging; $debugging = $smarty->debugging;
$_template = new Smarty_Internal_Template($debObj->debug_tpl, $debObj); $_template = new Smarty_Internal_Template($debObj->debug_tpl, $debObj);
if ($obj->_isTplObj()) { if ($obj->_isTplObj()) {
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name); $_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
@ -306,7 +306,6 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$tpl_vars[ $key ][ 'scope' ] = 'Smarty object'; $tpl_vars[ $key ][ 'scope' ] = 'Smarty object';
} }
} }
if (isset($obj->parent)) { if (isset($obj->parent)) {
$parent = $this->get_debug_vars($obj->parent); $parent = $this->get_debug_vars($obj->parent);
foreach ($parent->tpl_vars as $name => $pvar) { foreach ($parent->tpl_vars as $name => $pvar) {
@ -315,7 +314,6 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
} }
} }
$tpl_vars = array_merge($parent->tpl_vars, $tpl_vars); $tpl_vars = array_merge($parent->tpl_vars, $tpl_vars);
foreach ($parent->config_vars as $name => $pvar) { foreach ($parent->config_vars as $name => $pvar) {
if (isset($config_vars[ $name ]) && $config_vars[ $name ][ 'value' ] === $pvar[ 'value' ]) { if (isset($config_vars[ $name ]) && $config_vars[ $name ][ 'value' ] === $pvar[ 'value' ]) {
$config_vars[ $name ][ 'scope' ] = $pvar[ 'scope' ]; $config_vars[ $name ][ 'scope' ] = $pvar[ 'scope' ];
@ -344,7 +342,6 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
} }
} }
} }
return (object)array('tpl_vars' => $tpl_vars, 'config_vars' => $config_vars); return (object)array('tpl_vars' => $tpl_vars, 'config_vars' => $config_vars);
} }
@ -376,7 +373,6 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$this->template_data[ $this->index ][ $key ][ 'render_time' ] = 0; $this->template_data[ $this->index ][ $key ][ 'render_time' ] = 0;
$this->template_data[ $this->index ][ $key ][ 'cache_time' ] = 0; $this->template_data[ $this->index ][ $key ][ 'cache_time' ] = 0;
$this->template_data[ $this->index ][ $key ][ 'total_time' ] = 0; $this->template_data[ $this->index ][ $key ][ 'total_time' ] = 0;
return $key; return $key;
} }
} }

@ -3,7 +3,6 @@
/** /**
* Smarty error handler * Smarty error handler
* *
*
* @package Smarty * @package Smarty
* @subpackage PluginsInternal * @subpackage PluginsInternal
* @author Uwe Tews * @author Uwe Tews
@ -17,6 +16,7 @@ class Smarty_Internal_ErrorHandler
* contains directories outside of SMARTY_DIR that are to be muted by muteExpectedErrors() * contains directories outside of SMARTY_DIR that are to be muted by muteExpectedErrors()
*/ */
public static $mutedDirectories = array(); public static $mutedDirectories = array();
/** /**
* error handler returned by set_error_handler() in self::muteExpectedErrors() * error handler returned by set_error_handler() in self::muteExpectedErrors()
*/ */
@ -25,7 +25,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()
{ {
@ -98,12 +97,14 @@ class Smarty_Internal_ErrorHandler
// or the error was within smarty but masked to be ignored // or the error was within smarty but masked to be ignored
if (!$_is_muted_directory || ($errno && $errno & error_reporting())) { if (!$_is_muted_directory || ($errno && $errno & error_reporting())) {
if (self::$previousErrorHandler) { if (self::$previousErrorHandler) {
return call_user_func(self::$previousErrorHandler, return call_user_func(
self::$previousErrorHandler,
$errno, $errno,
$errstr, $errstr,
$errfile, $errfile,
$errline, $errline,
$errcontext); $errcontext
);
} else { } else {
return false; return false;
} }

@ -5,7 +5,6 @@
* *
* Load extensions dynamically * Load extensions dynamically
* *
*
* @package Smarty * @package Smarty
* @subpackage PluginsInternal * @subpackage PluginsInternal
* @author Uwe Tews * @author Uwe Tews
@ -39,7 +38,6 @@
*/ */
class Smarty_Internal_Extension_Handler class Smarty_Internal_Extension_Handler
{ {
public $objType = null; public $objType = null;
/** /**
@ -48,9 +46,11 @@ class Smarty_Internal_Extension_Handler
* *
* @var array * @var array
*/ */
private $_property_info = array('AutoloadFilters' => 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0, private $_property_info = array(
'AutoloadFilters' => 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0,
'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0, 'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0,
'TemplateVars' => 0, 'Literals' => 'Literals',);# 'TemplateVars' => 0, 'Literals' => 'Literals',
);//
private $resolvedProperties = array(); private $resolvedProperties = array();
@ -62,7 +62,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)
{ {
@ -71,8 +70,9 @@ class Smarty_Internal_Extension_Handler
if (!isset($smarty->ext->$name)) { if (!isset($smarty->ext->$name)) {
if (preg_match('/^((set|get)|(.*?))([A-Z].*)$/', $name, $match)) { if (preg_match('/^((set|get)|(.*?))([A-Z].*)$/', $name, $match)) {
$basename = $this->upperCase($match[ 4 ]); $basename = $this->upperCase($match[ 4 ]);
if (!isset($smarty->ext->$basename) && isset($this->_property_info[ $basename ]) && if (!isset($smarty->ext->$basename) && isset($this->_property_info[ $basename ])
is_string($this->_property_info[ $basename ])) { && is_string($this->_property_info[ $basename ])
) {
$class = 'Smarty_Internal_Method_' . $this->_property_info[ $basename ]; $class = 'Smarty_Internal_Method_' . $this->_property_info[ $basename ];
if (class_exists($class)) { if (class_exists($class)) {
$classObj = new $class(); $classObj = new $class();
@ -90,13 +90,18 @@ class Smarty_Internal_Extension_Handler
if (!isset($this->resolvedProperties[ $match[ 0 ] ][ $objType ])) { if (!isset($this->resolvedProperties[ $match[ 0 ] ][ $objType ])) {
$property = isset($this->resolvedProperties[ 'property' ][ $basename ]) ? $property = isset($this->resolvedProperties[ 'property' ][ $basename ]) ?
$this->resolvedProperties[ 'property' ][ $basename ] : $this->resolvedProperties[ 'property' ][ $basename ] :
$property = $this->resolvedProperties['property'][ $basename ] = strtolower(join('_', $property = $this->resolvedProperties[ 'property' ][ $basename ] = strtolower(
preg_split('/([A-Z][^A-Z]*)/', join(
'_',
preg_split(
'/([A-Z][^A-Z]*)/',
$basename, $basename,
-1, -1,
PREG_SPLIT_NO_EMPTY | PREG_SPLIT_NO_EMPTY |
PREG_SPLIT_DELIM_CAPTURE))); PREG_SPLIT_DELIM_CAPTURE
)
)
);
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;
@ -150,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)
{ {
@ -172,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)
{ {
@ -186,11 +189,9 @@ 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)
{ {
return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), array($this)); return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), array($this));
} }
} }

@ -18,10 +18,11 @@ class Smarty_Internal_Method_AddAutoloadFilters extends Smarty_Internal_Method_S
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param array $filters filters to load automatically * @param array $filters filters to load automatically
* @param string $type "pre", "output", … specify the * @param string $type "pre", "output", … specify
* filter type to set. Defaults to * the filter type to set.
* none treating $filters' keys as * Defaults to none treating
* the appropriate types * $filters' keys as the
* appropriate types
* *
* @return \Smarty|\Smarty_Internal_Template * @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException * @throws \SmartyException

@ -52,8 +52,8 @@ class Smarty_Internal_Method_Append
$data->tpl_vars[ $tpl_var ] = clone $tpl_var_inst; $data->tpl_vars[ $tpl_var ] = clone $tpl_var_inst;
} }
} }
if (!(is_array($data->tpl_vars[ $tpl_var ]->value) || if (!(is_array($data->tpl_vars[ $tpl_var ]->value)
$data->tpl_vars[ $tpl_var ]->value instanceof ArrayAccess) || $data->tpl_vars[ $tpl_var ]->value instanceof ArrayAccess)
) { ) {
settype($data->tpl_vars[ $tpl_var ]->value, 'array'); settype($data->tpl_vars[ $tpl_var ]->value, 'array');
} }

@ -11,7 +11,6 @@
*/ */
class Smarty_Internal_Method_AppendByRef class Smarty_Internal_Method_AppendByRef
{ {
/** /**
* appends values to template variables by reference * appends values to template variables by reference
* *

@ -11,14 +11,14 @@
*/ */
class Smarty_Internal_Method_AssignByRef class Smarty_Internal_Method_AssignByRef
{ {
/** /**
* assigns values to template variables by reference * assigns values to template variables by reference
* *
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @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
*/ */

@ -24,7 +24,8 @@ class Smarty_Internal_Method_AssignGlobal
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $varName the global variable name * @param string $varName the global variable name
* @param mixed $value the value to assign * @param mixed $value the value to assign
* @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
*/ */

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save