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

View File

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

View File

@@ -124,7 +124,7 @@ class Smarty_Internal_Configfilelexer
* @param string $data template source
* @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->dataLength = strlen($data);

View File

@@ -89,7 +89,7 @@ class Smarty_Internal_Configfileparser
* @param Smarty_Internal_Configfilelexer $lex
* @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->smarty = $compiler->smarty;

View File

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

View File

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

View File

@@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.33-dev-5';
const SMARTY_VERSION = '3.1.33-dev-6';
/**
* define variable scopes
*/
@@ -166,133 +166,157 @@ class Smarty extends Smarty_Internal_TemplateBase
const PLUGIN_COMPILER = 'compiler';
const PLUGIN_MODIFIER = 'modifier';
const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler';
/**
* assigned global tpl vars
*/
public static $global_tpl_vars = array();
/**
* Flag denoting if Multibyte String functions are available
*/
public static $_MBSTRING = SMARTY_MBSTRING;
/**
* The character set to adhere to (e.g. "UTF-8")
*/
public static $_CHARSET = SMARTY_RESOURCE_CHAR_SET;
/**
* The date format to be used internally
* (accepts date() and strftime())
*/
public static $_DATE_FORMAT = SMARTY_RESOURCE_DATE_FORMAT;
/**
* Flag denoting if PCRE should run in UTF-8 mode
*/
public static $_UTF8_MODIFIER = 'u';
/**
* Flag denoting if operating system is windows
*/
public static $_IS_WINDOWS = false;
/**
* auto literal on delimiters with whitespace
*
* @var boolean
*/
public $auto_literal = true;
/**
* display error on not assigned variables
*
* @var boolean
*/
public $error_unassigned = false;
/**
* look up relative file path in include_path
*
* @var boolean
*/
public $use_include_path = false;
/**
* flag if template_dir is normalized
*
* @var bool
*/
public $_templateDirNormalized = false;
/**
* joined template directory string used in cache keys
*
* @var string
*/
public $_joined_template_dir = null;
/**
* flag if config_dir is normalized
*
* @var bool
*/
public $_configDirNormalized = false;
/**
* joined config directory string used in cache keys
*
* @var string
*/
public $_joined_config_dir = null;
/**
* default template handler
*
* @var callable
*/
public $default_template_handler_func = null;
/**
* default config handler
*
* @var callable
*/
public $default_config_handler_func = null;
/**
* default plugin handler
*
* @var callable
*/
public $default_plugin_handler_func = null;
/**
* flag if template_dir is normalized
*
* @var bool
*/
public $_compileDirNormalized = false;
/**
* flag if plugins_dir is normalized
*
* @var bool
*/
public $_pluginsDirNormalized = false;
/**
* flag if template_dir is normalized
*
* @var bool
*/
public $_cacheDirNormalized = false;
/**
* force template compiling?
*
* @var boolean
*/
public $force_compile = false;
/**
* use sub dirs for compiled/cached files?
*
* @var boolean
*/
/**
* use sub dirs for compiled/cached files?
*
* @var boolean
*/
public $use_sub_dirs = false;
/**
* allow ambiguous resources (that are made unique by the resource handler)
*
* @var boolean
*/
public $allow_ambiguous_resources = false;
/**
* merge compiled includes
*
* @var boolean
*/
public $merge_compiled_includes = false;
/*
* flag for behaviour when extends: resource and {extends} tag are used simultaneous
* if false disable execution of {extends} in templates called by extends resource.
@@ -301,30 +325,35 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var boolean
*/
public $extends_recursion = true;
/**
* force cache file creation
*
* @var boolean
*/
public $force_cache = false;
/**
* template left-delimiter
*
* @var string
*/
public $left_delimiter = "{";
/**
* template right-delimiter
*
* @var string
*/
public $right_delimiter = "}";
/**
* array of strings which shall be treated as literal by compiler
*
* @var array string
*/
public $literals = array();
/**
* class name
* This should be instance of Smarty_Security.
@@ -333,24 +362,28 @@ class Smarty extends Smarty_Internal_TemplateBase
* @see Smarty_Security
*/
public $security_class = 'Smarty_Security';
/**
* implementation of security class
*
* @var Smarty_Security
*/
public $security_policy = null;
/**
* controls handling of PHP-blocks
*
* @var integer
*/
public $php_handling = self::PHP_PASSTHRU;
/**
* controls if the php template file resource is allowed
*
* @var bool
*/
public $allow_php_templates = false;
/**
* debug mode
* Setting this to true enables the debug-console.
@@ -358,6 +391,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var boolean
*/
public $debugging = false;
/**
* This determines if debugging is enable-able from the browser.
* <ul>
@@ -368,6 +402,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var string
*/
public $debugging_ctrl = 'NONE';
/**
* Name of debugging URL-param.
* Only used when $debugging_ctrl is set to 'URL'.
@@ -376,54 +411,63 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var string
*/
public $smarty_debug_id = 'SMARTY_DEBUG';
/**
* Path of debug template.
*
* @var string
*/
public $debug_tpl = null;
/**
* When set, smarty uses this value as error_reporting-level.
*
* @var int
*/
public $error_reporting = null;
/**
* Controls whether variables with the same name overwrite each other.
*
* @var boolean
*/
public $config_overwrite = true;
/**
* Controls whether config values of on/true/yes and off/false/no get converted to boolean.
*
* @var boolean
*/
public $config_booleanize = true;
/**
* Controls whether hidden config sections/vars are read from the file.
*
* @var boolean
*/
public $config_read_hidden = false;
/**
* locking concurrent compiles
*
* @var boolean
*/
public $compile_locking = true;
/**
* Controls whether cache resources should use locking mechanism
*
* @var boolean
*/
public $cache_locking = false;
/**
* seconds to wait for acquiring a lock before ignoring the write lock
*
* @var float
*/
public $locking_timeout = 10;
/**
* resource type used if none given
* Must be an valid key of $registered_resources.
@@ -431,6 +475,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var string
*/
public $default_resource_type = 'file';
/**
* caching type
* Must be an element of $cache_resource_types.
@@ -438,144 +483,168 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var string
*/
public $caching_type = 'file';
/**
* config type
*
* @var string
*/
public $default_config_type = 'file';
/**
* check If-Modified-Since headers
*
* @var boolean
*/
public $cache_modified_check = false;
/**
* registered plugins
*
* @var array
*/
public $registered_plugins = array();
/**
* registered objects
*
* @var array
*/
public $registered_objects = array();
/**
* registered classes
*
* @var array
*/
public $registered_classes = array();
/**
* registered filters
*
* @var array
*/
public $registered_filters = array();
/**
* registered resources
*
* @var array
*/
public $registered_resources = array();
/**
* registered cache resources
*
* @var array
*/
public $registered_cache_resources = array();
/**
* autoload filter
*
* @var array
*/
public $autoload_filters = array();
/**
* default modifier
*
* @var array
*/
public $default_modifiers = array();
/**
* autoescape variable output
*
* @var boolean
*/
public $escape_html = false;
/**
* start time for execution time calculation
*
* @var int
*/
public $start_time = 0;
/**
* required by the compiler for BC
*
* @var string
*/
public $_current_file = null;
/**
* internal flag to enable parser debugging
*
* @var bool
*/
public $_parserdebug = false;
/**
* This object type (Smarty = 1, template = 2, data = 4)
*
* @var int
*/
public $_objType = 1;
/**
* Debug object
*
* @var Smarty_Internal_Debug
*/
public $_debug = null;
/**
* template directory
*
* @var array
*/
protected $template_dir = array('./templates/');
/**
* flags for normalized template directory entries
*
* @var array
*/
protected $_processedTemplateDir = array();
/**
* config directory
*
* @var array
*/
protected $config_dir = array('./configs/');
/**
* flags for normalized template directory entries
*
* @var array
*/
protected $_processedConfigDir = array();
/**
* compile directory
*
* @var string
*/
protected $compile_dir = './templates_c/';
/**
* plugins directory
*
* @var array
*/
protected $plugins_dir = array();
/**
* cache directory
*
* @var string
*/
protected $cache_dir = './cache/';
/**
* removed properties
*
@@ -584,6 +653,7 @@ class Smarty extends Smarty_Internal_TemplateBase
protected $obsoleteProperties = array('resource_caching', 'template_resource_caching', 'direct_access_security',
'_dir_perms', '_file_perms', 'plugin_search_order',
'inheritance_merge_compiled_includes', 'resource_cache_mode',);
/**
* List of private properties which will call getter/setter on a direct access
*
@@ -657,7 +727,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param string|Smarty_Security $security_class if a string is used, it must be class-name
*
* @return Smarty current Smarty instance for chaining
* @throws SmartyException when an invalid class name is provided
* @throws \SmartyException
*/
public function enableSecurity($security_class = null)
{
@@ -946,7 +1016,7 @@ class Smarty extends Smarty_Internal_TemplateBase
Smarty_Internal_Template::$isCacheTplObj[ $_templateId ];
$tpl->inheritance = null;
$tpl->tpl_vars = $tpl->config_vars = array();
} else if (!$do_clone && isset(Smarty_Internal_Template::$tplObjCache[ $_templateId ])) {
} elseif (!$do_clone && isset(Smarty_Internal_Template::$tplObjCache[ $_templateId ])) {
$tpl = clone Smarty_Internal_Template::$tplObjCache[ $_templateId ];
$tpl->inheritance = null;
$tpl->tpl_vars = $tpl->config_vars = array();
@@ -984,8 +1054,8 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param string $plugin_name class plugin name to load
* @param bool $check check if already loaded
*
* @throws SmartyException
* @return string |boolean filepath of loaded file or false
* @throws \SmartyException
*/
public function loadPlugin($plugin_name, $check = true)
{
@@ -1005,13 +1075,14 @@ class Smarty extends Smarty_Internal_TemplateBase
* @throws \SmartyException
*/
public function _getTemplateId($template_name,
$cache_id = null,
$compile_id = null,
$caching = null,
Smarty_Internal_Template $template = null
) {
$cache_id = null,
$compile_id = null,
$caching = null,
Smarty_Internal_Template $template = null
)
{
$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;
$compile_id = $compile_id === null ? $this->compile_id : $compile_id;
$caching = (int)($caching === null ? $this->caching : $caching);
@@ -1044,8 +1115,6 @@ class Smarty extends Smarty_Internal_TemplateBase
public function _realpath($path, $realpath = null)
{
$nds = array('/' => '\\', '\\' => '/');
// normalize DIRECTORY_SEPARATOR
//$path = str_replace(array($nds[DIRECTORY_SEPARATOR], DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, $path);
preg_match(
'%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u',
$path,
@@ -1059,12 +1128,17 @@ class Smarty extends Smarty_Internal_TemplateBase
$path = getcwd() . DIRECTORY_SEPARATOR . $path;
}
}
// normalize DIRECTORY_SEPARATOR
$path = str_replace($nds[DIRECTORY_SEPARATOR], DIRECTORY_SEPARATOR, $path);
do {
$path = preg_replace(
array('#[\\\\/]{2}#', '#[\\\\/][.][\\\\/]#', '#[\\\\/]([^\\\\/.]+)[\\\\/][.][.][\\\\/]#'),
DIRECTORY_SEPARATOR, $path, -1, $count
DIRECTORY_SEPARATOR,
$path,
-1,
$count
);
} while($count > 0);
} while ($count > 0);
return $realpath !== false ? $parts[ 'root' ] . $path : str_ireplace(getcwd(), '.', $parts[ 'root' ] . $path);
}
@@ -1261,22 +1335,19 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param string $name property name
*
* @return mixed
* @throws \SmartyException
*/
public function __get($name)
{
if (isset($this->accessMap[ $name ])) {
$method = 'get' . $this->accessMap[ $name ];
return $this->{$method}();
} else {if (isset($this->_cache[ $name ])) {
return $this->_cache[ $name ];
} else {if (in_array($name, $this->obsoleteProperties)) {
return null;
} elseif (isset($this->_cache[ $name ])) {
return $this->_cache[ $name ];
} elseif (in_array($name, $this->obsoleteProperties)) {
return null;
} else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
}
}
}
return null;
}
@@ -1288,22 +1359,18 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param string $name property name
* @param mixed $value parameter passed to setter
*
* @throws \SmartyException
*/
public function __set($name, $value)
{
if (isset($this->accessMap[ $name ])) {
$method = 'set' . $this->accessMap[ $name ];
$this->{$method}($value);
} else {if (in_array($name, $this->obsoleteProperties)) {
return;
} elseif (in_array($name, $this->obsoleteProperties)) {
return;
} elseif (is_object($value) && method_exists($value, $name)) {
$this->$name = $value;
} else {
if (is_object($value) && method_exists($value, $name)) {
$this->$name = $value;
} else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
}
}
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
}
}

View File

@@ -127,7 +127,7 @@
{foreach $assigned_vars as $vars}
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
<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}
</td>
<td><h3>Value</h3>{$vars['value']|debug_print_var:10:80 nofilter}</td>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -25,12 +25,12 @@ abstract class Smarty_CacheResource
/**
* populate Cached Object with meta data from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param \Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
*
* @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

View File

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

View File

@@ -66,7 +66,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
++$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[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ] = $_className;
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ] = array();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -211,7 +211,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
// copy the working dirs from application
$debObj->setCompileDir($smarty->getCompileDir());
// 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->compile_check = Smarty::COMPILECHECK_ON;
$debObj->left_delimiter = '{';
@@ -220,7 +220,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$debObj->debugging = false;
$debObj->debugging_ctrl = 'NONE';
$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_resources = array();
$debObj->registered_filters = array();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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