diff --git a/change_log.txt b/change_log.txt
index 982a7e8e2..f82c9ee46 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -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
diff --git a/lexer/smarty_internal_configfilelexer.plex b/lexer/smarty_internal_configfilelexer.plex
index 67887a4a1..5e61f3389 100644
--- a/lexer/smarty_internal_configfilelexer.plex
+++ b/lexer/smarty_internal_configfilelexer.plex
@@ -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);
diff --git a/lexer/smarty_internal_configfileparser.y b/lexer/smarty_internal_configfileparser.y
index f5e707372..c981b58e9 100644
--- a/lexer/smarty_internal_configfileparser.y
+++ b/lexer/smarty_internal_configfileparser.y
@@ -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;
diff --git a/lexer/smarty_internal_templatelexer.plex b/lexer/smarty_internal_templatelexer.plex
index 52ee2d7bb..64a393109 100644
--- a/lexer/smarty_internal_templatelexer.plex
+++ b/lexer/smarty_internal_templatelexer.plex
@@ -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);
diff --git a/lexer/smarty_internal_templateparser.y b/lexer/smarty_internal_templateparser.y
index d53cdf2dc..8fcd5f34d 100644
--- a/lexer/smarty_internal_templateparser.y
+++ b/lexer/smarty_internal_templateparser.y
@@ -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;
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 1352d8154..a0e5fbd4f 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -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.
*
@@ -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 @@ public function templateExists($resource_name)
* @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 @@ public function createTemplate($template, $cache_id = null, $compile_id = null,
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 @@ public function createTemplate($template, $cache_id = null, $compile_id = null,
* @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 @@ public function loadPlugin($plugin_name, $check = true)
* @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 @@ public function _getTemplateId($template_name,
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(
'%^(?(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?(.*))$%u',
$path,
@@ -1059,12 +1128,17 @@ public function _realpath($path, $realpath = null)
$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 @@ public function _getSmartyObj()
* @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 @@ public function __get($name)
* @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);
}
}
diff --git a/libs/debug.tpl b/libs/debug.tpl
index 5526cbca8..966376fc1 100644
--- a/libs/debug.tpl
+++ b/libs/debug.tpl
@@ -127,7 +127,7 @@
{foreach $assigned_vars as $vars}
${$vars@key}
- {if isset($vars['nocache'])}Nocache{/if}
+ {if isset($vars['nocache'])}Nocache {/if}
{if isset($vars['scope'])}Origin: {$vars['scope']|debug_print_var nofilter}{/if}
|
Value{$vars['value']|debug_print_var:10:80 nofilter} |
diff --git a/libs/plugins/block.textformat.php b/libs/plugins/block.textformat.php
index 416d21eef..93ae076fd 100644
--- a/libs/plugins/block.textformat.php
+++ b/libs/plugins/block.textformat.php
@@ -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 {
diff --git a/libs/plugins/function.fetch.php b/libs/plugins/function.fetch.php
index dcec41466..768761b23 100644
--- a/libs/plugins/function.fetch.php
+++ b/libs/plugins/function.fetch.php
@@ -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);
-
+ 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;
+ }
+ }
+ 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 {
- $extra_headers[] = $param_value;
+ trigger_error("[plugin] invalid value for attribute '{$param_key}'", E_USER_NOTICE);
+ return;
}
- }
- 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;
+ 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 {
diff --git a/libs/plugins/function.html_checkboxes.php b/libs/plugins/function.html_checkboxes.php
index 54978ea24..9a1f9c898 100644
--- a/libs/plugins/function.html_checkboxes.php
+++ b/libs/plugins/function.html_checkboxes.php
@@ -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());
+ 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 {
- trigger_error(
- 'html_checkboxes: selected attribute contains an object of class \'' .
- get_class($_sel) . '\' without __toString() method', E_USER_NOTICE
- );
- continue;
+ $_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 {
- $_sel = smarty_function_escape_special_chars((string) $_sel);
+ trigger_error(
+ 'html_checkboxes: selected attribute is an object of class \'' . get_class($_val) .
+ '\' without __toString() method',
+ E_USER_NOTICE
+ );
}
- $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
- );
+ $selected = smarty_function_escape_special_chars((string)$_val);
}
- } 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
- );
+ 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;
}
-
- if ($_val === true || $_val === $_key) {
- $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
+ // 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;
- }
- // 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;
}
}
-
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 .= '';
}
-
$_output .= $separator;
-
return $_output;
}
diff --git a/libs/plugins/function.html_image.php b/libs/plugins/function.html_image.php
index 9455bfc1d..af29a82d2 100644
--- a/libs/plugins/function.html_image.php
+++ b/libs/plugins/function.html_image.php
@@ -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 = '';
- $suffix = '';
- 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 = '';
+ $suffix = '';
+ 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 . '' . $suffix;
}
diff --git a/libs/plugins/function.html_options.php b/libs/plugins/function.html_options.php
index aa4a42032..53e82a243 100644
--- a/libs/plugins/function.html_options.php
+++ b/libs/plugins/function.html_options.php
@@ -26,7 +26,7 @@
* @author Monte Ohrt
* @author Ralf Strehle (minor optimization)
*
- * @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());
+ 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 {
- trigger_error(
- 'html_options: selected attribute contains an object of class \'' .
- get_class($_sel) . '\' without __toString() method', E_USER_NOTICE
- );
- continue;
+ $_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 {
- $_sel = smarty_function_escape_special_chars((string) $_sel);
+ trigger_error(
+ 'html_options: selected attribute is an object of class \'' . get_class($_val) .
+ '\' without __toString() method',
+ E_USER_NOTICE
+ );
}
- $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
- );
+ $selected = smarty_function_escape_special_chars((string)$_val);
}
- } 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
- );
+ 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;
}
-
- if ($_val === true || $_val === $_key) {
- $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
+ // 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;
- }
- // 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;
}
}
-
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
'' . "\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 . '' . "\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 .= "\n";
-
return $optgroup_html;
}
diff --git a/libs/plugins/function.html_radios.php b/libs/plugins/function.html_radios.php
index 1b17d7e33..12c75bd6a 100644
--- a/libs/plugins/function.html_radios.php
+++ b/libs/plugins/function.html_radios.php
@@ -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());
+ 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 {
- trigger_error(
- 'html_radios: selected attribute is an object of class \'' . get_class($_val) .
- '\' without __toString() method', E_USER_NOTICE
- );
+ $selected = (string)$_val;
}
- } 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
- );
+ 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;
}
-
- if ($_val === true || $_val === $_key) {
- $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
+ // 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;
- }
- // 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;
}
}
-
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 .= '';
}
-
$_output .= $separator;
-
return $_output;
}
diff --git a/libs/plugins/function.html_select_date.php b/libs/plugins/function.html_select_date.php
index 52a394c62..87a9e8e67 100644
--- a/libs/plugins/function.html_select_date.php
+++ b/libs/plugins/function.html_select_date.php
@@ -35,7 +35,7 @@
* @author Monte Ohrt
* @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 ';
}
}
-
// generate month