Merge pull request #452 from dusta/Update-PSR-2

Update PSR-2
This commit is contained in:
uwetews
2018-08-12 03:20:33 +02:00
committed by GitHub
190 changed files with 3833 additions and 3119 deletions

View File

@@ -2,7 +2,9 @@
"name": "smarty/smarty",
"type": "library",
"description": "Smarty - the compiling PHP template engine",
"keywords": ["templating"],
"keywords": [
"templating"
],
"homepage": "http://www.smarty.net",
"license": "LGPL-3.0",
"authors": [
@@ -28,12 +30,13 @@
"php": ">=5.2"
},
"autoload": {
"files": ["libs/bootstrap.php"]
"files": [
"libs/bootstrap.php"
]
},
"extra": {
"branch-alias": {
"dev-master": "3.1.x-dev"
}
}
}
}

View File

@@ -17,11 +17,15 @@ $smarty->cache_lifetime = 120;
$smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true);
$smarty->assign("FirstName", array("John", "Mary", "James", "Henry"));
$smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case"));
$smarty->assign("Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"), array("I", "J", "K", "L"),
array("M", "N", "O", "P")));
$smarty->assign(
"Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"), array("I", "J", "K", "L"),
array("M", "N", "O", "P"))
);
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
$smarty->assign(
"contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234"))
);
$smarty->assign("option_values", array("NY", "NE", "KS", "IA", "OK", "TX"));
$smarty->assign("option_output", array("New York", "Nebraska", "Kansas", "Iowa", "Oklahoma", "Texas"));

View File

@@ -22,7 +22,7 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
/**
* Read values for a set of keys from cache
*
* @param array $keys list of keys to fetch
* @param array $keys list of keys to fetch
*
* @return array list of values with the given keys used as indexes
* @return boolean true on success, false on failure
@@ -41,8 +41,8 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
/**
* Save values for a set of keys to cache
*
* @param array $keys list of values to save
* @param int $expire expiration time
* @param array $keys list of values to save
* @param int $expire expiration time
*
* @return boolean true on success, false on failure
*/
@@ -58,7 +58,7 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
/**
* Remove values from cache
*
* @param array $keys list of keys to delete
* @param array $keys list of keys to delete
*
* @return boolean true on success, false on failure
*/

View File

@@ -32,7 +32,7 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
/**
* Read values for a set of keys from cache
*
* @param array $keys list of keys to fetch
* @param array $keys list of keys to fetch
*
* @return array list of values with the given keys used as indexes
* @return boolean true on success, false on failure
@@ -57,8 +57,8 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
/**
* Save values for a set of keys to cache
*
* @param array $keys list of values to save
* @param int $expire expiration time
* @param array $keys list of values to save
* @param int $expire expiration time
*
* @return boolean true on success, false on failure
*/
@@ -75,7 +75,7 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
/**
* Remove values from cache
*
* @param array $keys list of keys to delete
* @param array $keys list of keys to delete
*
* @return boolean true on success, false on failure
*/

View File

@@ -43,19 +43,21 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
}
$this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id');
$this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id');
$this->save = $this->db->prepare('REPLACE INTO output_cache (id, name, cache_id, compile_id, content)
VALUES (:id, :name, :cache_id, :compile_id, :content)');
$this->save = $this->db->prepare(
'REPLACE INTO output_cache (id, name, cache_id, compile_id, content)
VALUES (:id, :name, :cache_id, :compile_id, :content)'
);
}
/**
* fetch cached content and its modification time from data source
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $content cached content
* @param integer $mtime cache modification timestamp (epoch)
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $content cached content
* @param integer $mtime cache modification timestamp (epoch)
*
* @return void
*/
@@ -78,10 +80,10 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
*
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the complete cached content.
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
*
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
*/
@@ -97,19 +99,21 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
/**
* Save content to cache
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration time in seconds or null
* @param string $content content to cache
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration time in seconds or null
* @param string $content content to cache
*
* @return boolean success
*/
protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content)
{
$this->save->execute(array('id' => $id, 'name' => $name, 'cache_id' => $cache_id, 'compile_id' => $compile_id,
'content' => $content,));
$this->save->execute(
array('id' => $id, 'name' => $name, 'cache_id' => $cache_id, 'compile_id' => $compile_id,
'content' => $content,)
);
return !!$this->save->rowCount();
}
@@ -117,10 +121,10 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
/**
* Delete content from cache
*
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration or null
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration or null
*
* @return integer number of deleted caches
*/

View File

@@ -165,12 +165,12 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
/**
* fetch cached content and its modification time from data source
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string|null $cache_id cache id
* @param string|null $compile_id compile id
* @param string $content cached content
* @param integer $mtime cache modification timestamp (epoch)
* @param string $id unique cache content identifier
* @param string $name template name
* @param string|null $cache_id cache id
* @param string|null $compile_id compile id
* @param string $content cached content
* @param integer $mtime cache modification timestamp (epoch)
*
* @return void
* @access protected
@@ -197,10 +197,10 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
* {@internal implementing this method is optional.
* Only implement it if modification times can be accessed faster than loading the complete cached content.}}
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string|null $cache_id cache id
* @param string|null $compile_id compile id
* @param string $id unique cache content identifier
* @param string $name template name
* @param string|null $cache_id cache id
* @param string|null $compile_id compile id
*
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
* @access protected
@@ -269,10 +269,10 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
/**
* Delete content from cache
*
* @param string|null $name template name
* @param string|null $cache_id cache id
* @param string|null $compile_id compile id
* @param integer|null|-1 $exp_time seconds till expiration or null
* @param string|null $name template name
* @param string|null $cache_id cache id
* @param string|null $compile_id compile id
* @param integer|null|-1 $exp_time seconds till expiration or null
*
* @return integer number of deleted caches
* @access protected
@@ -324,4 +324,4 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
return (is_null($this->database)) ? "`{$this->table}`" : "`{$this->database}`.`{$this->table}`";
}
}

View File

@@ -40,4 +40,4 @@ class Smarty_CacheResource_Pdo_Gzip extends Smarty_CacheResource_Pdo
return gzinflate($content);
}
}

View File

@@ -13,8 +13,8 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/

View File

@@ -43,9 +43,9 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
/**
* Fetch a template and its modification time from database
*
* @param string $name template name
* @param string $source template source
* @param integer $mtime template modification timestamp (epoch)
* @param string $name template name
* @param string $source template source
* @param integer $mtime template modification timestamp (epoch)
*
* @return void
*/
@@ -68,7 +68,7 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
*
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source.
*
* @param string $name template name
* @param string $name template name
*
* @return integer timestamp (epoch) the template was modified
*/

View File

@@ -41,9 +41,9 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
/**
* Fetch a template and its modification time from database
*
* @param string $name template name
* @param string $source template source
* @param integer $mtime template modification timestamp (epoch)
* @param string $name template name
* @param string $source template source
* @param integer $mtime template modification timestamp (epoch)
*
* @return void
*/

View File

@@ -2,14 +2,14 @@
/**
* Smarty Autoloader
*
* @package Smarty
* @package Smarty
*/
/**
* Smarty Autoloader
*
* @package Smarty
* @author Uwe Tews
* @package Smarty
* @author Uwe Tews
* Usage:
* require_once '...path/Autoloader.php';
* Smarty_Autoloader::register();
@@ -20,7 +20,7 @@
*/
class Smarty_Autoloader
{
/**
/**
* Filepath to Smarty root
*
* @var string
@@ -54,8 +54,8 @@ class Smarty_Autoloader
if (!defined('SMARTY_SPL_AUTOLOAD')) {
define('SMARTY_SPL_AUTOLOAD', 0);
}
if (SMARTY_SPL_AUTOLOAD &&
set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
if (SMARTY_SPL_AUTOLOAD
&& set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
) {
$registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {

View File

@@ -276,10 +276,10 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
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)
@@ -618,7 +618,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Enable error handler to mute expected messages
*
* @return boolean
* @return boolean
* @deprecated
*/
public static function muteExpectedErrors()
@@ -639,7 +639,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Check if a template resource exists
*
* @param string $resource_name template name
* @param string $resource_name template name
*
* @return bool status
* @throws \SmartyException
@@ -654,7 +654,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Loads security class and enables security
*
* @param string|Smarty_Security $security_class if a string is used, it must be class-name
* @param string|Smarty_Security $security_class if a string is used, it must be class-name
*
* @return Smarty current Smarty instance for chaining
* @throws SmartyException when an invalid class name is provided
@@ -679,9 +679,9 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Add template directory(s)
*
* @param string|array $template_dir directory(s) of template sources
* @param string $key of the array element to assign the template dir to
* @param bool $isConfig true for config_dir
* @param string|array $template_dir directory(s) of template sources
* @param string $key of the array element to assign the template dir to
* @param bool $isConfig true for config_dir
*
* @return Smarty current Smarty instance for chaining
*/
@@ -747,8 +747,8 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Set template directory
*
* @param string|array $template_dir directory(s) of template sources
* @param bool $isConfig true for config_dir
* @param string|array $template_dir directory(s) of template sources
* @param bool $isConfig true for config_dir
*
* @return \Smarty current Smarty instance for chaining
*/
@@ -846,7 +846,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Set plugins directory
*
* @param string|array $plugins_dir directory(s) of plugins
* @param string|array $plugins_dir directory(s) of plugins
*
* @return Smarty current Smarty instance for chaining
*/
@@ -901,7 +901,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Set cache directory
*
* @param string $cache_dir directory to store cached templates in
* @param string $cache_dir directory to store cached templates in
*
* @return Smarty current Smarty instance for chaining
*/
@@ -915,11 +915,11 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* creates a template object
*
* @param string $template the resource handle of the template file
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
* @param boolean $do_clone flag is Smarty object shall be cloned
* @param string $template the resource handle of the template file
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
* @param boolean $do_clone flag is Smarty object shall be cloned
*
* @return \Smarty_Internal_Template template object
* @throws \SmartyException
@@ -981,8 +981,8 @@ class Smarty extends Smarty_Internal_TemplateBase
* class name format: Smarty_PluginType_PluginName
* plugin filename format: plugintype.pluginname.php
*
* @param string $plugin_name class plugin name to load
* @param bool $check check if already loaded
* @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
@@ -1005,11 +1005,11 @@ 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;
$cache_id = $cache_id === null ? $this->cache_id : $cache_id;
@@ -1033,10 +1033,11 @@ class Smarty extends Smarty_Internal_TemplateBase
* - remove /./ and /../
* - make it absolute if required
*
* @param string $path file path
* @param bool $realpath if true - convert to absolute
* false - convert to relative
* null - keep as it is but remove /./ /../
* @param string $path file path
* @param bool $realpath if true - convert to absolute
* false - convert to relative
* null - keep as it is but
* remove /./ /../
*
* @return string
*/
@@ -1045,9 +1046,11 @@ class Smarty extends Smarty_Internal_TemplateBase
$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,
$parts);
preg_match(
'%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u',
$path,
$parts
);
$path = $parts[ 'path' ];
if ($parts[ 'root' ] === '\\') {
$parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ];
@@ -1058,8 +1061,9 @@ class Smarty extends Smarty_Internal_TemplateBase
}
do {
$path = preg_replace(
array('#[\\\\/]{2}#', '#[\\\\/][.][\\\\/]#', '#[\\\\/]([^\\\\/.]+)[\\\\/][.][.][\\\\/]#'),
DIRECTORY_SEPARATOR, $path, -1, $count);
array('#[\\\\/]{2}#', '#[\\\\/][.][\\\\/]#', '#[\\\\/]([^\\\\/.]+)[\\\\/][.][.][\\\\/]#'),
DIRECTORY_SEPARATOR, $path, -1, $count
);
} while($count > 0);
return $realpath !== false ? $parts[ 'root' ] . $path : str_ireplace(getcwd(), '.', $parts[ 'root' ] . $path);
}
@@ -1254,7 +1258,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* Calls the appropriate getter function.
* Issues an E_USER_NOTICE if no valid getter is found.
*
* @param string $name property name
* @param string $name property name
*
* @return mixed
* @throws \SmartyException
@@ -1265,12 +1269,14 @@ class Smarty extends Smarty_Internal_TemplateBase
$method = 'get' . $this->accessMap[ $name ];
return $this->{$method}();
} else {if (isset($this->_cache[ $name ])) {
return $this->_cache[ $name ];
return $this->_cache[ $name ];
} else {if (in_array($name, $this->obsoleteProperties)) {
return null;
return null;
} else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
}}}
}
}
}
return null;
}
@@ -1290,14 +1296,15 @@ class Smarty extends Smarty_Internal_TemplateBase
$method = 'set' . $this->accessMap[ $name ];
$this->{$method}($value);
} else {if (in_array($name, $this->obsoleteProperties)) {
return;
return;
} else {
if (is_object($value) && method_exists($value, $name)) {
$this->$name = $value;
} else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
}
}}
}
}
}
/**
@@ -1320,7 +1327,6 @@ class Smarty extends Smarty_Internal_TemplateBase
* Normalize template_dir or config_dir
*
* @param bool $isConfig true for config_dir
*
*/
private function _normalizeTemplateConfig($isConfig)
{

View File

@@ -28,7 +28,7 @@
/**
* @ignore
*/
require_once(dirname(__FILE__) . '/Smarty.class.php');
require_once dirname(__FILE__) . '/Smarty.class.php';
/**
* Smarty Backward Compatibility Wrapper Class
@@ -53,7 +53,6 @@ class SmartyBC extends Smarty
/**
* Initialize new SmartyBC object
*
*/
public function __construct()
{
@@ -127,12 +126,12 @@ class SmartyBC extends Smarty
* @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_methods list of methods that are block format
*
* @throws SmartyException
* @throws SmartyException
* @internal param array $block_functs list of methods that are block format
*/
public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true,
$block_methods = array())
{
$block_methods = array()
) {
settype($allowed, 'array');
settype($smarty_args, 'boolean');
$this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
@@ -151,8 +150,8 @@ class SmartyBC extends Smarty
/**
* Registers block function to be used in templates
*
* @param string $block name of template block
* @param string $block_impl PHP function to register
* @param string $block name of template block
* @param string $block_impl PHP function to register
* @param bool $cacheable
* @param mixed $cache_attrs
*
@@ -326,10 +325,10 @@ class SmartyBC extends Smarty
/**
* clear cached content for the given template and cache id
*
* @param string $tpl_file name of template file
* @param string $cache_id name of cache_id
* @param string $compile_id name of compile_id
* @param string $exp_time expiration time
* @param string $tpl_file name of template file
* @param string $cache_id name of cache_id
* @param string $compile_id name of compile_id
* @param string $exp_time expiration time
*
* @return boolean
*/
@@ -341,7 +340,7 @@ class SmartyBC extends Smarty
/**
* clear the entire contents of cache (all templates)
*
* @param string $exp_time expire time
* @param string $exp_time expire time
*
* @return boolean
*/
@@ -353,9 +352,9 @@ class SmartyBC extends Smarty
/**
* test to see if valid cache exists for this template
*
* @param string $tpl_file name of template file
* @param string $cache_id
* @param string $compile_id
* @param string $tpl_file name of template file
* @param string $cache_id
* @param string $compile_id
*
* @return bool
* @throws \Exception
@@ -379,9 +378,9 @@ class SmartyBC extends Smarty
* or all compiled template files if one is not specified.
* This function is for advanced use only, not normally needed.
*
* @param string $tpl_file
* @param string $compile_id
* @param string $exp_time
* @param string $tpl_file
* @param string $compile_id
* @param string $exp_time
*
* @return boolean results of {@link smarty_core_rm_auto()}
*/
@@ -393,7 +392,7 @@ class SmartyBC extends Smarty
/**
* Checks whether requested template exists.
*
* @param string $tpl_file
* @param string $tpl_file
*
* @return bool
* @throws \SmartyException
@@ -406,7 +405,7 @@ class SmartyBC extends Smarty
/**
* Returns an array containing template variables
*
* @param string $name
* @param string $name
*
* @return array
*/
@@ -418,7 +417,7 @@ class SmartyBC extends Smarty
/**
* Returns an array containing config variables
*
* @param string $name
* @param string $name
*
* @return array
*/
@@ -442,7 +441,7 @@ class SmartyBC extends Smarty
/**
* return a reference to a registered object
*
* @param string $name
* @param string $name
*
* @return object
*/

View File

@@ -12,6 +12,6 @@
* Load and register Smarty Autoloader
*/
if (!class_exists('Smarty_Autoloader')) {
require dirname(__FILE__) . '/Autoloader.php';
include dirname(__FILE__) . '/Autoloader.php';
}
Smarty_Autoloader::register(true);

View File

@@ -20,8 +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
@@ -39,8 +38,10 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
return;
}
if (Smarty::$_MBSTRING) {
$template->_checkPlugins(array(array('function' => 'smarty_modifier_mb_wordwrap',
'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php')));
$template->_checkPlugins(
array(array('function' => 'smarty_modifier_mb_wordwrap',
'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php'))
);
}
$style = null;
@@ -54,25 +55,25 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'style':
case 'indent_char':
case 'wrap_char':
case 'assign':
$$_key = (string) $_val;
break;
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 'indent':
case 'indent_first':
case 'wrap':
$$_key = (int) $_val;
break;
case 'wrap_cut':
$$_key = (bool) $_val;
break;
case 'wrap_cut':
$$_key = (bool) $_val;
break;
default:
trigger_error("textformat: unknown attribute '{$_key}'");
default:
trigger_error("textformat: unknown attribute '{$_key}'");
}
}
@@ -88,10 +89,12 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
}
// convert mult. spaces & special chars to single space
$_paragraph =
preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER,
preg_replace(
array('!\s+!' . Smarty::$_UTF8_MODIFIER,
'!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER),
array(' ',
''), $_paragraph);
array(' ',
''), $_paragraph
);
// indent first line
if ($indent_first > 0) {
$_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;

View File

@@ -29,14 +29,13 @@
* {cycle name=row values="one,two,three" reset=true}
* {cycle name=row}
*
*
* @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle}
* @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Mark Priatel <mpriatel@rogers.com>
* @author credit to Gerard <gerard@interfold.com>
* @author credit to Jason Sweat <jsweat_php@yahoo.com>
* @version 1.3
* @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Mark Priatel <mpriatel@rogers.com>
* @author credit to Gerard <gerard@interfold.com>
* @author credit to Jason Sweat <jsweat_php@yahoo.com>
* @version 1.3
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object

View File

@@ -81,73 +81,73 @@ 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;
}
}
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);
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;
}
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;
$extra_headers[] = $param_value;
}
break;
default:
trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE);
}
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;
}
}
if (!empty($proxy_host) && !empty($proxy_port)) {

View File

@@ -29,24 +29,25 @@
* - assign (optional) - assign the output as an array to this variable
* - escape (optional) - escape the content (not value), defaults to true
*
*
* @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
* @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
* (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com>
* @author credits to Monte Ohrt <monte at ohrt dot com>
* @version 1.0
* @author Christopher Kvarme <christopher.kvarme@flashjab.com>
* @author credits to Monte Ohrt <monte at ohrt dot com>
* @version 1.0
*
* @param array $params parameters
* @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')));
$template->_checkPlugins(
array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
);
$name = 'checkbox';
$values = null;
@@ -62,91 +63,99 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'name':
case 'separator':
$$_key = (string) $_val;
break;
case 'name':
case 'separator':
$$_key = (string) $_val;
break;
case 'escape':
case 'labels':
case 'label_ids':
$$_key = (bool) $_val;
break;
case 'escape':
case 'labels':
case 'label_ids':
$$_key = (bool) $_val;
break;
case 'options':
$$_key = (array) $_val;
break;
case 'options':
$$_key = (array) $_val;
break;
case 'values':
case 'output':
$$_key = array_values((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;
}
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 {
$_sel = smarty_function_escape_special_chars((string) $_sel);
trigger_error(
'html_checkboxes: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method', E_USER_NOTICE
);
continue;
}
$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);
$_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 {
$selected = smarty_function_escape_special_chars((string) $_val);
trigger_error(
'html_checkboxes: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method', E_USER_NOTICE
);
}
break;
} 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 '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 'assign':
break;
case 'strict':
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;
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;
}
}
@@ -159,15 +168,19 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
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);
smarty_function_html_checkboxes_output(
$name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape
);
}
} else {
foreach ($values as $_i => $_key) {
$_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
$_html_result[] =
smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape);
smarty_function_html_checkboxes_output(
$name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape
);
}
}
@@ -186,21 +199,23 @@ 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)
{
$label_ids, $escape = true
) {
$_output = '';
if (is_object($value)) {
if (method_exists($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);
trigger_error(
'html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method', E_USER_NOTICE
);
return '';
}
@@ -212,8 +227,10 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
if (method_exists($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);
trigger_error(
'html_options: output is an object of class \'' . get_class($output) .
'\' without __toString() method', E_USER_NOTICE
);
return '';
}
@@ -223,8 +240,12 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
if ($labels) {
if ($label_ids) {
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_',
$name . '_' . $value));
$_id = smarty_function_escape_special_chars(
preg_replace(
'![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_',
$name . '_' . $value
)
);
$_output .= '<label for="' . $_id . '">';
} else {
$_output .= '<label>';

View File

@@ -22,7 +22,6 @@
* - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT
* - path_prefix - prefix for path output (optional, default empty)
*
*
* @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
@@ -34,12 +33,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')));
$template->_checkPlugins(
array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
);
$alt = '';
$file = '';
@@ -52,36 +53,36 @@ 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 '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 '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;
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;
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;
}
}

View File

@@ -21,24 +21,25 @@
* - id (optional) - string default not set
* - class (optional) - string default not set
*
*
* @link http://www.smarty.net/manual/en/language.function.html.options.php {html_image}
* @link http://www.smarty.net/manual/en/language.function.html.options.php {html_image}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de>
* @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
*
* @return string
* @uses smarty_function_escape_special_chars()
* @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/
function smarty_function_html_options($params, Smarty_Internal_Template $template)
{
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->_checkPlugins(
array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
);
$name = null;
$values = null;
@@ -52,76 +53,82 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'name':
case 'class':
case 'id':
$$_key = (string) $_val;
break;
case 'name':
case 'class':
case 'id':
$$_key = (string) $_val;
break;
case 'options':
$options = (array) $_val;
break;
case 'options':
$options = (array) $_val;
break;
case 'values':
case 'output':
$$_key = array_values((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;
}
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 {
$_sel = smarty_function_escape_special_chars((string) $_sel);
trigger_error(
'html_options: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method', E_USER_NOTICE
);
continue;
}
$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);
$_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 {
$selected = smarty_function_escape_special_chars((string) $_val);
trigger_error(
'html_options: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method', E_USER_NOTICE
);
}
break;
} else {
$selected = smarty_function_escape_special_chars((string) $_val);
}
break;
case 'strict':
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;
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;
}
}
@@ -183,8 +190,10 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
if (method_exists($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);
trigger_error(
'html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method', E_USER_NOTICE
);
return '';
}
@@ -196,8 +205,10 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
} else {
$_idx = 0;
$_html_result =
smarty_function_html_options_optgroup($key, $value, $selected, !empty($id) ? ($id . '-' . $idx) : null,
$class, $_idx);
smarty_function_html_options_optgroup(
$key, $value, $selected, !empty($id) ? ($id . '-' . $idx) : null,
$class, $_idx
);
$idx ++;
}

View File

@@ -29,7 +29,6 @@
* {html_radios values=$ids name='box' separator='<br>' output=$names}
* {html_radios values=$ids checked=$checked separator='<br>' output=$names}
*
*
* @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios}
* (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com>
@@ -40,13 +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')));
$template->_checkPlugins(
array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
);
$name = 'radio';
$values = null;
@@ -61,77 +62,83 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'name':
case 'separator':
$$_key = (string) $_val;
break;
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);
}
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 {
$selected = (string) $_val;
trigger_error(
'html_radios: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method', E_USER_NOTICE
);
}
break;
} else {
$selected = (string) $_val;
}
break;
case 'escape':
case 'labels':
case 'label_ids':
$$_key = (bool) $_val;
break;
case 'escape':
case 'labels':
case 'label_ids':
$$_key = (bool) $_val;
break;
case 'options':
$$_key = (array) $_val;
break;
case 'options':
$$_key = (array) $_val;
break;
case 'values':
case 'output':
$$_key = array_values((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 '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 'assign':
break;
case 'strict':
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;
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;
}
}
@@ -146,15 +153,19 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
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);
smarty_function_html_radios_output(
$name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape
);
}
} else {
foreach ($values as $_i => $_key) {
$_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
$_html_result[] =
smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape);
smarty_function_html_radios_output(
$name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape
);
}
}
@@ -178,16 +189,18 @@ 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)
{
$escape
) {
$_output = '';
if (is_object($value)) {
if (method_exists($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);
trigger_error(
'html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method', E_USER_NOTICE
);
return '';
}
@@ -199,8 +212,10 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
if (method_exists($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);
trigger_error(
'html_options: output is an object of class \'' . get_class($output) .
'\' without __toString() method', E_USER_NOTICE
);
return '';
}
@@ -210,8 +225,12 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
if ($labels) {
if ($label_ids) {
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_',
$name . '_' . $value));
$_id = smarty_function_escape_special_chars(
preg_replace(
'![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_',
$name . '_' . $value
)
);
$_output .= '<label for="' . $_id . '">';
} else {
$_output .= '<label>';

View File

@@ -28,15 +28,14 @@
* - 2.0 complete rewrite for performance,
* added attributes month_names, *_id
*
*
* @link http://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date}
* @link http://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date}
* (Smarty online manual)
* @version 2.0
* @author Andrei Zmievski
* @author Monte Ohrt <monte at ohrt dot com>
* @author Rodney Rehm
* @version 2.0
* @author Andrei Zmievski
* @author Monte Ohrt <monte at ohrt dot com>
* @author Rodney Rehm
*
* @param array $params parameters
* @param array $params parameters
*
* @param \Smarty_Internal_Template $template
*
@@ -45,8 +44,10 @@
*/
function smarty_function_html_select_date($params, Smarty_Internal_Template $template)
{
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->_checkPlugins(
array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
);
// generate timestamps used for month names only
static $_month_timestamps = null;
static $_current_year = null;
@@ -109,66 +110,68 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
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 '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 '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 '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;
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;
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;
}
}
@@ -250,10 +253,12 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
} else {
$_html_years = '<select name="' . $_name . '"';
if ($year_id !== null || $all_id !== null) {
$_html_years .= ' id="' . smarty_function_escape_special_chars($year_id !== null ?
$_html_years .= ' id="' . smarty_function_escape_special_chars(
$year_id !== null ?
($year_id ? $year_id : $_name) :
($all_id ? ($all_id . $_name) :
$_name)) . '"';
$_name)
) . '"';
}
if ($year_size) {
$_html_years .= ' size="' . $year_size . '"';
@@ -288,10 +293,12 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$_html_months = '<select name="' . $_name . '"';
if ($month_id !== null || $all_id !== null) {
$_html_months .= ' id="' . smarty_function_escape_special_chars($month_id !== null ?
$_html_months .= ' id="' . smarty_function_escape_special_chars(
$month_id !== null ?
($month_id ? $month_id : $_name) :
($all_id ? ($all_id . $_name) :
$_name)) . '"';
$_name)
) . '"';
}
if ($month_size) {
$_html_months .= ' size="' . $month_size . '"';
@@ -329,8 +336,10 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$_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 . '"';
@@ -357,35 +366,35 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
$_html = '';
for ($i = 0; $i <= 2; $i ++) {
switch ($field_order[ $i ]) {
case 'Y':
case 'y':
if (isset($_html_years)) {
if ($_html) {
$_html .= $field_separator;
}
$_html .= $_html_years;
case 'Y':
case 'y':
if (isset($_html_years)) {
if ($_html) {
$_html .= $field_separator;
}
break;
$_html .= $_html_years;
}
break;
case 'm':
case 'M':
if (isset($_html_months)) {
if ($_html) {
$_html .= $field_separator;
}
$_html .= $_html_months;
case 'm':
case 'M':
if (isset($_html_months)) {
if ($_html) {
$_html .= $field_separator;
}
break;
$_html .= $_html_months;
}
break;
case 'd':
case 'D':
if (isset($_html_days)) {
if ($_html) {
$_html .= $field_separator;
}
$_html .= $_html_days;
case 'd':
case 'D':
if (isset($_html_days)) {
if ($_html) {
$_html .= $field_separator;
}
break;
$_html .= $_html_days;
}
break;
}
}

View File

@@ -11,23 +11,25 @@
* Name: html_select_time
* Purpose: Prints the dropdowns for time selection
*
* @link http://www.smarty.net/manual/en/language.function.html.select.time.php {html_select_time}
* @link http://www.smarty.net/manual/en/language.function.html.select.time.php {html_select_time}
* (Smarty online manual)
* @author Roberto Berto <roberto@berto.net>
* @author Monte Ohrt <monte AT ohrt DOT com>
* @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
*
* @return string
* @uses smarty_make_timestamp()
* @uses smarty_make_timestamp()
* @throws \SmartyException
*/
function smarty_function_html_select_time($params, Smarty_Internal_Template $template)
{
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->_checkPlugins(
array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
);
$prefix = 'Time_';
$field_array = null;
$field_separator = "\n";
@@ -76,72 +78,74 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
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 '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 'prefix':
case 'field_array':
case 'field_separator':
case 'option_separator':
case 'field_separator':
case 'option_separator':
case 'all_extra':
case 'hour_extra':
case 'minute_extra':
case 'second_extra':
case 'meridian_extra':
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_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 '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 '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 '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 'minute_interval':
case 'second_interval':
case 'hour_size':
case 'minute_size':
case 'second_size':
case 'meridian_size':
$$_key = (int) $_value;
break;
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;
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;
}
}
@@ -203,8 +207,10 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
$_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)) . '"';
smarty_function_escape_special_chars(
$hour_id !== null ? ($hour_id ? $hour_id : $_name) :
($all_id ? ($all_id . $_name) : $_name)
) . '"';
}
if ($hour_size) {
$_html_hours .= ' size="' . $hour_size . '"';
@@ -249,10 +255,12 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
$_html_minutes = '<select name="' . $_name . '"';
if ($minute_id !== null || $all_id !== null) {
$_html_minutes .= ' id="' . smarty_function_escape_special_chars($minute_id !== null ?
$_html_minutes .= ' id="' . smarty_function_escape_special_chars(
$minute_id !== null ?
($minute_id ? $minute_id : $_name) :
($all_id ? ($all_id . $_name) :
$_name)) . '"';
$_name)
) . '"';
}
if ($minute_size) {
$_html_minutes .= ' size="' . $minute_size . '"';
@@ -290,10 +298,12 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
$_html_seconds = '<select name="' . $_name . '"';
if ($second_id !== null || $all_id !== null) {
$_html_seconds .= ' id="' . smarty_function_escape_special_chars($second_id !== null ?
$_html_seconds .= ' id="' . smarty_function_escape_special_chars(
$second_id !== null ?
($second_id ? $second_id : $_name) :
($all_id ? ($all_id . $_name) :
$_name)) . '"';
$_name)
) . '"';
}
if ($second_size) {
$_html_seconds .= ' size="' . $second_size . '"';
@@ -331,11 +341,13 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
$_html_meridian = '<select name="' . $_name . '"';
if ($meridian_id !== null || $all_id !== null) {
$_html_meridian .= ' id="' . smarty_function_escape_special_chars($meridian_id !== null ?
$_html_meridian .= ' id="' . smarty_function_escape_special_chars(
$meridian_id !== null ?
($meridian_id ? $meridian_id :
$_name) :
($all_id ? ($all_id . $_name) :
$_name)) . '"';
$_name)
) . '"';
}
if ($meridian_size) {
$_html_meridian .= ' size="' . $meridian_size . '"';

View File

@@ -35,12 +35,11 @@
* {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
* {table loop=$data cols="first,second,third" tr_attr=$colors}
*
*
* @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Messju Mohr <messju at lammfellpuschen dot de>
* @author credit to boots <boots dot smarty at yahoo dot com>
* @version 1.1
* @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table}
* @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Messju Mohr <messju at lammfellpuschen dot de>
* @author credit to boots <boots dot smarty at yahoo dot com>
* @version 1.1
* @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table}
* (Smarty online manual)
*
* @param array $params parameters
@@ -70,42 +69,42 @@ function smarty_function_html_table($params)
foreach ($params as $_key => $_value) {
switch ($_key) {
case 'loop':
$$_key = (array) $_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 '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 'rows':
$$_key = (int) $_value;
break;
case 'table_attr':
case 'trailpad':
case 'hdir':
case 'vdir':
case 'inner':
case 'caption':
$$_key = (string) $_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 'tr_attr':
case 'td_attr':
case 'th_attr':
$$_key = $_value;
break;
}
}

View File

@@ -37,12 +37,11 @@
* {mailto address="me@domain.com" cc="you@domain.com,they@domain.com"}
* {mailto address="me@domain.com" extra='class="mailto"'}
*
*
* @link http://www.smarty.net/manual/en/language.function.mailto.php {mailto}
* @link http://www.smarty.net/manual/en/language.function.mailto.php {mailto}
* (Smarty online manual)
* @version 1.2
* @author Monte Ohrt <monte at ohrt dot com>
* @author credits to Jason Sweat (added cc, bcc and subject functionality)
* @version 1.2
* @author Monte Ohrt <monte at ohrt dot com>
* @author credits to Jason Sweat (added cc, bcc and subject functionality)
*
* @param array $params parameters
*
@@ -70,24 +69,24 @@ 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 '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 'subject':
case 'newsgroups':
$mail_parms[] = $var . '=' . rawurlencode($value);
break;
case 'extra':
case 'text':
$$var = $value;
case 'extra':
case 'text':
$$var = $value;
default:
default:
}
}
@@ -97,8 +96,10 @@ function smarty_function_mailto($params)
$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);
trigger_error(
"mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex",
E_USER_WARNING
);
return;
}

View File

@@ -13,9 +13,9 @@
* Name: math
* Purpose: handle math computations in template
*
* @link http://www.smarty.net/manual/en/language.function.math.php {math}
* @link http://www.smarty.net/manual/en/language.function.math.php {math}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author Monte Ohrt <monte at ohrt dot com>
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object

View File

@@ -29,23 +29,32 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
$upper_string = mb_convert_case($string, MB_CASE_TITLE, Smarty::$_CHARSET);
} else {
// uppercase word breaks
$upper_string = preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER,
'smarty_mod_cap_mbconvert_cb', $string);
$upper_string = preg_replace_callback(
"!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER,
'smarty_mod_cap_mbconvert_cb', $string
);
}
// check uc_digits case
if (!$uc_digits) {
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches,
PREG_OFFSET_CAPTURE)) {
if (preg_match_all(
"!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches,
PREG_OFFSET_CAPTURE
)
) {
foreach ($matches[ 1 ] as $match) {
$upper_string =
substr_replace($upper_string, mb_strtolower($match[ 0 ], Smarty::$_CHARSET), $match[ 1 ],
strlen($match[ 0 ]));
substr_replace(
$upper_string, mb_strtolower($match[ 0 ], Smarty::$_CHARSET), $match[ 1 ],
strlen($match[ 0 ])
);
}
}
}
$upper_string =
preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert2_cb',
$upper_string);
preg_replace_callback(
"!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert2_cb',
$upper_string
);
return $upper_string;
}
@@ -55,20 +64,27 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
}
// uppercase (including hyphenated words)
$upper_string =
preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst_cb',
$string);
preg_replace_callback(
"!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst_cb',
$string
);
// check uc_digits case
if (!$uc_digits) {
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches,
PREG_OFFSET_CAPTURE)) {
if (preg_match_all(
"!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches,
PREG_OFFSET_CAPTURE
)
) {
foreach ($matches[ 1 ] as $match) {
$upper_string =
substr_replace($upper_string, strtolower($match[ 0 ]), $match[ 1 ], strlen($match[ 0 ]));
}
}
}
$upper_string = preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst2_cb',
$upper_string);
$upper_string = preg_replace_callback(
"!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst2_cb',
$upper_string
);
return $upper_string;
}

View File

@@ -38,7 +38,7 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
static $is_loaded = false;
if (!$is_loaded) {
if (!is_callable('smarty_make_timestamp')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
include_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
}
$is_loaded = true;
}

View File

@@ -26,86 +26,86 @@ 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) {
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 --;
}
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;
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 --;
}
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;
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>';
}
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;
case 'integer' :
case 'float' :
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);
break;
}
$results = '<i>' . $results . '</i>';
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) . '...';
}
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) . '...';
}
$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) . '...';
}
} else {
if (isset($var[ $length ])) {
$results = substr($var, 0, $length - 3) . '...';
}
}
$results = htmlspecialchars($results, ENT_QUOTES, Smarty::$_CHARSET);
$results = htmlspecialchars('"' . $results . '"', ENT_QUOTES, Smarty::$_CHARSET);
break;
case 'unknown type' :
default :
$results = strtr((string) $var, $_replace);
if (Smarty::$_MBSTRING) {
if (mb_strlen($results, Smarty::$_CHARSET) > $length) {
$results = mb_substr($results, 0, $length - 3, Smarty::$_CHARSET) . '...';
}
} else {
if (strlen($results) > $length) {
$results = substr($results, 0, $length - 3) . '...';
}
}
$results = htmlspecialchars($results, ENT_QUOTES, Smarty::$_CHARSET);
}
return $results;

View File

@@ -36,200 +36,212 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
}
switch ($esc_type) {
case 'html':
case 'html':
if ($_double_encode) {
// php >=5.3.2 - go native
return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
} else {
if ($double_encode) {
// php <5.2.3 - only handle double encoding
return htmlspecialchars($string, ENT_QUOTES, $char_set);
} else {
// php <5.2.3 - prevent double encoding
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
$string = str_replace(
array('%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'), array('&',
';'), $string
);
return $string;
}
}
case 'htmlall':
if (Smarty::$_MBSTRING) {
// mb_convert_encoding ignores htmlspecialchars()
if ($_double_encode) {
// php >=5.3.2 - go native
return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
$string = 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);
$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);
$string =
str_replace(
array('%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'), array('&',
';'), $string
);
return $string;
}
}
case 'htmlall':
if (Smarty::$_MBSTRING) {
// mb_convert_encoding ignores htmlspecialchars()
if ($_double_encode) {
// php >=5.3.2 - go native
$string = 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);
} 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);
// htmlentities() won't convert everything, so use mb_convert_encoding
return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set);
}
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);
// 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 {
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);
$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 $string;
}
}
case 'url':
return rawurlencode($string);
case 'url':
return rawurlencode($string);
case 'urlpathinfo':
return str_replace('%2F', '/', rawurlencode($string));
case 'urlpathinfo':
return str_replace('%2F', '/', rawurlencode($string));
case 'quotes':
// escape unescaped single quotes
return preg_replace("%(?<!\\\\)'%", "\\'", $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
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 = '';
$_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) {
$return .= '%' . bin2hex($string[ $x ]);
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 ]) . ';';
}
case 'hexentity':
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
require_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;
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;
}
// no MBString fallback
$_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) {
$return .= '&#x' . bin2hex($string[ $x ]) . ';';
$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 ]) . ';';
}
case 'decentity':
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
require_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;
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('\\' => '\\\\',
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')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
}
$is_loaded_2 = true;
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';
}
return smarty_mb_str_replace(array('@',
'.'), array(' [AT] ',
' [DOT] '), $string);
$is_loaded_2 = true;
}
// no MBString fallback
return str_replace(array('@',
return smarty_mb_str_replace(
array('@',
'.'), array(' [AT] ',
' [DOT] '), $string
);
}
// no MBString fallback
return str_replace(
array('@',
'.'), array(' [AT] ',
' [DOT] '), $string);
' [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')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
}
$is_loaded_1 = true;
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';
}
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
if ($unicode >= 126) {
$return .= '&#' . $unicode . ';';
} else {
$return .= chr($unicode);
}
}
return $return;
$is_loaded_1 = true;
}
$_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 . ';';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
if ($unicode >= 126) {
$return .= '&#' . $unicode . ';';
} else {
$return .= substr($string, $_i, 1);
$return .= chr($unicode);
}
}
return $return;
}
default:
return $string;
$_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

@@ -11,13 +11,12 @@
* Name: mb_wordwrap
* Purpose: Wrap a string to a given number of characters
*
* @link http://php.net/manual/en/function.wordwrap.php for similarity
* @link http://php.net/manual/en/function.wordwrap.php for similarity
*
* @param string $str the string to wrap
* @param int $width the width of the output
* @param string $break the character used to break the line
* @param boolean $cut ignored parameter, just for the sake of
* @param string $str the string to wrap
* @param int $width the width of the output
* @param string $break the character used to break the line
* @param boolean $cut ignored parameter, just for the sake of
*
* @return string wrapped string
* @author Rodney Rehm
@@ -36,10 +35,12 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa
$_tokens = array($_token);
if ($token_length > $width) {
if ($cut) {
$_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER,
$_token,
-1,
PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
$_tokens = preg_split(
'!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER,
$_token,
-1,
PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE
);
}
}

View File

@@ -12,9 +12,9 @@
* Name: regex_replace
* Purpose: regular expression search/replace
*
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
* regex_replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author Monte Ohrt <monte at ohrt dot com>
*
* @param string $string input string
* @param string|array $search regular expression(s) to search for

View File

@@ -28,7 +28,7 @@ function smarty_modifier_replace($string, $search, $replace)
if (Smarty::$_MBSTRING) {
if (!$is_loaded) {
if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
include_once SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php';
}
$is_loaded = true;
}

View File

@@ -35,8 +35,10 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if (mb_strlen($string, Smarty::$_CHARSET) > $length) {
$length -= min($length, mb_strlen($etc, Smarty::$_CHARSET));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '',
mb_substr($string, 0, $length + 1, Smarty::$_CHARSET));
$string = preg_replace(
'/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '',
mb_substr($string, 0, $length + 1, Smarty::$_CHARSET)
);
}
if (!$middle) {
return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;

View File

@@ -15,9 +15,9 @@
* Input: string to catenate
* Example: {$var|cat:"foo"}
*
* @link http://smarty.php.net/manual/en/language.modifier.cat.php cat
* @link http://smarty.php.net/manual/en/language.modifier.cat.php cat
* (Smarty online manual)
* @author Uwe Tews
* @author Uwe Tews
*
* @param array $params parameters
*

View File

@@ -12,9 +12,9 @@
* Name: count_paragraphs
* Purpose: count the number of paragraphs in a text
*
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_paragraphs (Smarty online manual)
* @author Uwe Tews
* @author Uwe Tews
*
* @param array $params parameters
*

View File

@@ -12,9 +12,9 @@
* Name: count_sentences
* Purpose: count the number of sentences in a text
*
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_sentences (Smarty online manual)
* @author Uwe Tews
* @author Uwe Tews
*
* @param array $params parameters
*

View File

@@ -14,8 +14,8 @@
* @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
* @author Rodney Rehm
*
* @param array $params parameters
* @param Smarty_Internal_TemplateCompilerBase $compiler
* @param array $params parameters
* @param Smarty_Internal_TemplateCompilerBase $compiler
*
* @return string with compiled code
* @throws \SmartyException
@@ -24,8 +24,10 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
{
static $_double_encode = null;
static $is_loaded = false;
$compiler->template->_checkPlugins(array(array('function' => 'smarty_literal_compiler_param',
'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php')));
$compiler->template->_checkPlugins(
array(array('function' => 'smarty_literal_compiler_param',
'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'))
);
if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
}
@@ -40,57 +42,57 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
}
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 'html':
if ($_double_encode) {
return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
var_export($double_encode, true) . ')';
} elseif ($double_encode) {
return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
} else {
// fall back to modifier.escape.php
}
case 'htmlall':
if (Smarty::$_MBSTRING) {
if ($_double_encode) {
// 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
case 'htmlall':
if (Smarty::$_MBSTRING) {
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) . ')';
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 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' .
var_export($char_set, true) . '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
} else {
// fall back to modifier.escape.php
}
}
case 'url':
return 'rawurlencode(' . $params[ 0 ] . ')';
// 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 'urlpathinfo':
return 'str_replace("%2F", "/", rawurlencode(' . $params[ 0 ] . '))';
case 'url':
return 'rawurlencode(' . $params[ 0 ] . ')';
case 'quotes':
// escape unescaped single quotes
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[ 0 ] . ')';
case 'urlpathinfo':
return 'str_replace("%2F", "/", rawurlencode(' . $params[ 0 ] . '))';
case 'javascript':
// escape quotes and backslashes, newlines, etc.
return 'strtr(' . $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", "</" => "<\/" ))';
}
}

View File

@@ -12,7 +12,7 @@
* Name: noprint
* Purpose: return an empty string
*
* @author Uwe Tews
* @author Uwe Tews
* @return string with compiled code
*/
function smarty_modifiercompiler_noprint()

View File

@@ -30,21 +30,21 @@ function smarty_modifiercompiler_unescape($params)
}
switch (trim($params[ 1 ], '"\'')) {
case 'entity':
case 'htmlall':
if (Smarty::$_MBSTRING) {
return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 2 ] . ', \'HTML-ENTITIES\')';
}
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 ] . ')';
return 'html_entity_decode(' . $params[ 0 ] . ', ENT_NOQUOTES, ' . $params[ 2 ] . ')';
case 'html':
return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)';
case 'html':
return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)';
case 'url':
return 'rawurldecode(' . $params[ 0 ] . ')';
case 'url':
return 'rawurldecode(' . $params[ 0 ] . ')';
default:
return $params[ 0 ];
default:
return $params[ 0 ];
}
}

View File

@@ -14,7 +14,7 @@
* @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual)
* @author Uwe Tews
*
* @param array $params parameters
* @param array $params parameters
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*
* @return string with compiled code
@@ -33,7 +33,7 @@ function smarty_modifiercompiler_wordwrap($params, Smarty_Internal_TemplateCompi
}
$function = 'wordwrap';
if (Smarty::$_MBSTRING) {
$function = $compiler->getPlugin('mb_wordwrap','modifier');
$function = $compiler->getPlugin('mb_wordwrap', 'modifier');
}
return $function . '(' . $params[ 0 ] . ',' . $params[ 1 ] . ',' . $params[ 2 ] . ',' . $params[ 3 ] . ')';
}

View File

@@ -10,12 +10,12 @@
* Smarty trimwhitespace outputfilter plugin
* Trim unnecessary whitespace from HTML markup.
*
* @author Rodney Rehm
* @author Rodney Rehm
*
* @param string $source input string
*
* @return string filtered output
* @todo substr_replace() is not overloaded by mbstring.func_overload - so this function might fail!
* @todo substr_replace() is not overloaded by mbstring.func_overload - so this function might fail!
*/
function smarty_outputfilter_trimwhitespace($source)
{
@@ -27,8 +27,11 @@ function smarty_outputfilter_trimwhitespace($source)
$source = preg_replace('/\015\012|\015|\012/', "\n", $source);
// capture Internet Explorer and KnockoutJS Conditional Comments
if (preg_match_all('#<!--((\[[^\]]+\]>.*?<!\[[^\]]+\])|(\s*/?ko\s+.+))-->#is', $source, $matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
if (preg_match_all(
'#<!--((\[[^\]]+\]>.*?<!\[[^\]]+\])|(\s*/?ko\s+.+))-->#is', $source, $matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
)
) {
foreach ($matches as $match) {
$store[] = $match[ 0 ][ 0 ];
$_length = strlen($match[ 0 ][ 0 ]);
@@ -46,8 +49,11 @@ function smarty_outputfilter_trimwhitespace($source)
// capture html elements not to be messed with
$_offset = 0;
if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is',
$source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
if (preg_match_all(
'#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is',
$source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER
)
) {
foreach ($matches as $match) {
$store[] = $match[ 0 ][ 0 ];
$_length = strlen($match[ 0 ][ 0 ]);

View File

@@ -12,9 +12,9 @@
* Purpose: used by other smarty functions to escape
* special chars except for already escaped ones
*
* @author Monte Ohrt <monte at ohrt dot com>
* @author Monte Ohrt <monte at ohrt dot com>
*
* @param string $string text that should by escaped
* @param string $string text that should by escaped
*
* @return string
*/

View File

@@ -25,8 +25,10 @@ function smarty_literal_compiler_param($params, $index, $default = null)
}
// test if param is a literal
if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[ $index ])) {
throw new SmartyException('$param[' . $index .
'] is not a literal and is thus not evaluatable at compile time');
throw new SmartyException(
'$param[' . $index .
'] is not a literal and is thus not evaluatable at compile time'
);
}
$t = null;

View File

@@ -10,7 +10,7 @@
* Function: smarty_make_timestamp
* Purpose: used by other smarty functions to make a timestamp from a string.
*
* @author Monte Ohrt <monte at ohrt dot com>
* @author Monte Ohrt <monte at ohrt dot com>
*
* @param DateTime|int|string $string date object, timestamp or string that can be converted using strtotime()
*
@@ -21,14 +21,16 @@ function smarty_make_timestamp($string)
if (empty($string)) {
// use "now":
return time();
} elseif ($string instanceof DateTime ||
(interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)
} elseif ($string instanceof DateTime
|| (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)
) {
return (int) $string->format('U'); // PHP 5.2 BC
} elseif (strlen($string) === 14 && ctype_digit($string)) {
// it is mysql timestamp format of YYYYMMDDHHMMSS?
return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), substr($string, 4, 2),
substr($string, 6, 2), substr($string, 0, 4));
return mktime(
substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), substr($string, 4, 2),
substr($string, 6, 2), substr($string, 0, 4)
);
} elseif (is_numeric($string)) {
// it is a numeric string, we handle it as timestamp
return (int) $string;

View File

@@ -9,10 +9,10 @@ if (!function_exists('smarty_mb_str_replace')) {
/**
* Multibyte string replace
*
* @param string|string[] $search the string to be searched
* @param string|string[] $replace the replacement string
* @param string $subject the source string
* @param int &$count number of matches found
* @param string|string[] $search the string to be searched
* @param string|string[] $replace the replacement string
* @param string $subject the source string
* @param int &$count number of matches found
*
* @return string replaced string
* @author Rodney Rehm

View File

@@ -9,7 +9,7 @@
/**
* convert characters to their decimal unicode equivalents
*
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
*
* @param string $string characters to calculate unicode of
* @param string $encoding encoding of $string, if null mb_internal_encoding() is used
@@ -31,7 +31,7 @@ function smarty_mb_to_unicode($string, $encoding = null)
/**
* convert unicodes to the character of given encoding
*
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
*
* @param integer|array $unicode single unicode or list of unicodes to convert
* @param string $encoding encoding of returned string, if null mb_internal_encoding() is used

View File

@@ -8,7 +8,7 @@
/**
* Smarty htmlspecialchars variablefilter plugin
*
* @param string $source input string
* @param string $source input string
* @param \Smarty_Internal_Template $template
*
* @return string filtered output

View File

@@ -51,7 +51,8 @@ abstract class Smarty_CacheResource
* @return boolean true or false if the cached content does not exist
*/
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null,
$update = false);
$update = false
);
/**
* Write the rendered template output to cache
@@ -66,7 +67,7 @@ abstract class Smarty_CacheResource
/**
* Read cached template from cache
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @return string content
*/

View File

@@ -18,12 +18,12 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* fetch cached content and its modification time from data source
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $content cached content
* @param integer $mtime cache modification timestamp (epoch)
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $content cached content
* @param integer $mtime cache modification timestamp (epoch)
*
* @return void
*/
@@ -34,10 +34,10 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
* {@internal implementing this method is optional.
* Only implement it if modification times can be accessed faster than loading the complete cached content.}}
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
*
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
*/
@@ -49,12 +49,12 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Save content to cache
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration or null
* @param string $content content to cache
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration or null
* @param string $content content to cache
*
* @return boolean success
*/
@@ -63,10 +63,10 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Delete content from cache
*
* @param string|null $name template name
* @param string|null $cache_id cache id
* @param string|null $compile_id compile id
* @param integer|null $exp_time seconds till expiration time in seconds or null
* @param string|null $name template name
* @param string|null $cache_id cache id
* @param string|null $compile_id compile id
* @param integer|null $exp_time seconds till expiration time in seconds or null
*
* @return integer number of deleted caches
*/
@@ -75,8 +75,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* populate Cached Object with meta data from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
@@ -110,8 +110,10 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
return;
}
$timestamp = null;
$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $cached->content,
$timestamp);
$this->fetch(
$cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $cached->content,
$timestamp
);
$cached->timestamp = isset($timestamp) ? $timestamp : false;
$cached->exists = !!$cached->timestamp;
}
@@ -120,22 +122,24 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
* Read the cached template and process the header
*
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Template_Cached $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Template_Cached $cached = null,
$update = false)
{
$update = false
) {
if (!$cached) {
$cached = $_smarty_tpl->cached;
}
$content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) {
$this->fetch($_smarty_tpl->cached->filepath, $_smarty_tpl->source->name, $_smarty_tpl->cache_id,
$_smarty_tpl->compile_id, $content, $timestamp);
$this->fetch(
$_smarty_tpl->cached->filepath, $_smarty_tpl->source->name, $_smarty_tpl->cache_id,
$_smarty_tpl->compile_id, $content, $timestamp
);
}
if (isset($content)) {
eval('?>' . $content);
@@ -149,21 +153,23 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
return $this->save($_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $_template->cache_lifetime, $content);
return $this->save(
$_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $_template->cache_lifetime, $content
);
}
/**
* Read cached template from cache
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @return string|boolean content
*/
@@ -173,8 +179,10 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
$timestamp = null;
if ($content === null) {
$timestamp = null;
$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $content, $timestamp);
$this->fetch(
$_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $content, $timestamp
);
}
if (isset($content)) {
return $content;
@@ -185,8 +193,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Empty cache
*
* @param Smarty $smarty Smarty object
* @param integer $exp_time expiration time (number of seconds, not timestamp)
* @param Smarty $smarty Smarty object
* @param integer $exp_time expiration time (number of seconds, not timestamp)
*
* @return integer number of cache files deleted
*/
@@ -198,11 +206,11 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Empty cache for a specific template
*
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time (number of seconds, not timestamp)
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time (number of seconds, not timestamp)
*
* @return int number of cache files deleted
* @throws \SmartyException
@@ -226,8 +234,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Check is cache is locked for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*
* @return boolean true or false if cache is locked
*/

View File

@@ -47,8 +47,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* populate Cached Object with meta data from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
@@ -63,14 +63,16 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Template_Cached $cached cached object
*
* @return void
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
{
if (!$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content,
$timestamp, $cached->source->uid)
if (!$this->fetch(
$cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content,
$timestamp, $cached->source->uid
)
) {
return;
}
@@ -83,22 +85,24 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* Read the cached template and process the header
*
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Template_Cached $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Template_Cached $cached = null,
$update = false)
{
$update = false
) {
if (!$cached) {
$cached = $_smarty_tpl->cached;
}
$content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) {
if (!$this->fetch($_smarty_tpl->cached->filepath, $_smarty_tpl->source->name, $_smarty_tpl->cache_id,
$_smarty_tpl->compile_id, $content, $timestamp, $_smarty_tpl->source->uid)
if (!$this->fetch(
$_smarty_tpl->cached->filepath, $_smarty_tpl->source->name, $_smarty_tpl->cache_id,
$_smarty_tpl->compile_id, $content, $timestamp, $_smarty_tpl->source->uid
)
) {
return false;
}
@@ -115,8 +119,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
@@ -130,7 +134,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Read cached template from cache
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @return string|false content
*/
@@ -139,8 +143,10 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$content = $_template->cached->content ? $_template->cached->content : null;
$timestamp = null;
if ($content === null) {
if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $content, $timestamp, $_template->source->uid)
if (!$this->fetch(
$_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $content, $timestamp, $_template->source->uid
)
) {
return false;
}
@@ -155,12 +161,12 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* Empty cache
* {@internal the $exp_time argument is ignored altogether }}
*
* @param Smarty $smarty Smarty object
* @param integer $exp_time expiration time [being ignored]
* @param Smarty $smarty Smarty object
* @param integer $exp_time expiration time [being ignored]
*
* @return integer number of cache files deleted [always -1]
* @uses purge() to clear the whole store
* @uses invalidate() to mark everything outdated if purge() is inapplicable
* @uses purge() to clear the whole store
* @uses invalidate() to mark everything outdated if purge() is inapplicable
*/
public function clearAll(Smarty $smarty, $exp_time = null)
{
@@ -174,17 +180,17 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* Empty cache for a specific template
* {@internal the $exp_time argument is ignored altogether}}
*
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time [being ignored]
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time [being ignored]
*
* @return int number of cache files deleted [always -1]
* @throws \SmartyException
* @uses buildCachedFilepath() to generate the CacheID
* @uses invalidate() to mark CacheIDs parent chain as outdated
* @uses delete() to remove CacheID from cache
* @uses buildCachedFilepath() to generate the CacheID
* @uses invalidate() to mark CacheIDs parent chain as outdated
* @uses delete() to remove CacheID from cache
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
@@ -199,12 +205,11 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Get template's unique ID
*
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
*
* @return string filepath of cache file
* @throws \SmartyException
*
*/
protected function getTemplateUid(Smarty $smarty, $resource_name)
{
@@ -220,7 +225,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Sanitize CacheID components
*
* @param string $string CacheID component to sanitize
* @param string $string CacheID component to sanitize
*
* @return string sanitized CacheID component
*/
@@ -236,19 +241,19 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Fetch and prepare a cache object.
*
* @param string $cid CacheID to fetch
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $content cached content
* @param integer &$timestamp cached timestamp (epoch)
* @param string $resource_uid resource's uid
* @param string $cid CacheID to fetch
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $content cached content
* @param integer &$timestamp cached timestamp (epoch)
* @param string $resource_uid resource's uid
*
* @return boolean success
*/
protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null,
&$timestamp = null, $resource_uid = null)
{
&$timestamp = null, $resource_uid = null
) {
$t = $this->read(array($cid));
$content = !empty($t[ $cid ]) ? $t[ $cid ] : null;
$timestamp = null;
@@ -281,7 +286,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Extract the timestamp the $content was cached
*
* @param string &$content the cached content
* @param string &$content the cached content
*
* @return float the microtime the content was cached
*/
@@ -298,17 +303,17 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Invalidate CacheID
*
* @param string $cid CacheID
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's uid
* @param string $cid CacheID
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's uid
*
* @return void
*/
protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null,
$resource_uid = null)
{
$resource_uid = null
) {
$now = microtime(true);
$key = null;
// invalidate everything
@@ -339,17 +344,17 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Determine the latest timestamp known to the invalidation chain
*
* @param string $cid CacheID to determine latest invalidation timestamp of
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's filepath
* @param string $cid CacheID to determine latest invalidation timestamp of
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's filepath
*
* @return float the microtime the CacheID was invalidated
*/
protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null,
$resource_uid = null)
{
$resource_uid = null
) {
// abort if there is no CacheID
if (false && !$cid) {
return 0;
@@ -373,18 +378,18 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* Translate a CacheID into the list of applicable InvalidationKeys.
* Splits 'some|chain|into|an|array' into array( '#clearAll#', 'some', 'some|chain', 'some|chain|into', ... )
*
* @param string $cid CacheID to translate
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's filepath
* @param string $cid CacheID to translate
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $resource_uid source's filepath
*
* @return array list of InvalidationKeys
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey
*/
protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null,
$resource_uid = null)
{
$resource_uid = null
) {
$t = array('IVK#ALL');
$_name = $_compile = '#';
if ($resource_name) {
@@ -425,8 +430,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Check is cache is locked for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*
* @return boolean true or false if cache is locked
*/
@@ -471,7 +476,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Read values for a set of keys from cache
*
* @param array $keys list of keys to fetch
* @param array $keys list of keys to fetch
*
* @return array list of values with the given keys used as indexes
*/
@@ -480,8 +485,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Save values for a set of keys to cache
*
* @param array $keys list of values to save
* @param int $expire expiration time
* @param array $keys list of values to save
* @param int $expire expiration time
*
* @return boolean true on success, false on failure
*/
@@ -490,7 +495,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Remove values from cache
*
* @param array $keys list of keys to delete
* @param array $keys list of keys to delete
*
* @return boolean true on success, false on failure
*/

View File

@@ -87,4 +87,4 @@ class Smarty_Internal_Block
public function callBlock(Smarty_Internal_Template $tpl)
{
}
}
}

View File

@@ -32,11 +32,13 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
$_filepath = sha1($source->uid . $smarty->_joined_template_dir);
$cached->filepath = $smarty->getCacheDir();
if (isset($_template->cache_id)) {
$cached->filepath .= preg_replace(array('![^\w|]+!',
$cached->filepath .= preg_replace(
array('![^\w|]+!',
'![|]+!'),
array('_',
array('_',
$_compile_dir_sep),
$_template->cache_id) . $_compile_dir_sep;
$_template->cache_id
) . $_compile_dir_sep;
}
if (isset($_template->compile_id)) {
$cached->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) . $_compile_dir_sep;
@@ -88,9 +90,9 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_smarty_tpl,
Smarty_Template_Cached $cached = null,
$update = false)
{
Smarty_Template_Cached $cached = null,
$update = false
) {
$_smarty_tpl->cached->valid = false;
if ($update && defined('HHVM_VERSION')) {
eval('?>' . file_get_contents($_smarty_tpl->cached->filepath));
@@ -111,12 +113,14 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath,
$content,
$_template->smarty) === true
if ($_template->smarty->ext->_writeFile->writeFile(
$_template->cached->filepath,
$content,
$_template->smarty
) === true
) {
if (function_exists('opcache_invalidate') &&
(!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api'))) < 1
if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api'))) < 1
) {
opcache_invalidate($_template->cached->filepath, true);
} else if (function_exists('apc_compile_file')) {
@@ -135,7 +139,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
/**
* Read cached template from cache
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @return string content
*/

View File

@@ -19,9 +19,9 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign
/**
* Compiles code for the {append} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException

View File

@@ -24,7 +24,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
*/
public $option_flags = array('nocache', 'noscope');
/**
/**
* Valid scope names
*
* @var array
@@ -36,9 +36,9 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
/**
* Compiles code for the {assign} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException

View File

@@ -47,10 +47,9 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
/**
* Compiles code for the {block} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
@@ -72,11 +71,13 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
$compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ] = $_className;
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ] = array();
$compiler->_cache[ 'blockParams' ][ 1 ][ 'subBlocks' ][ trim($_attr[ 'name' ], '"\'') ][] = $_className;
$this->openTag($compiler,
'block',
array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
$this->openTag(
$compiler,
'block',
array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
$compiler->template->compiled->has_nocache_code,
$compiler->template->caching));
$compiler->template->caching)
);
$compiler->saveRequiredPlugins(true);
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
@@ -86,16 +87,15 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
}
/**
* Smarty Internal Plugin Compile BlockClose Class
*
*/
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_Inheritance
{
/**
* Compiles code for the {/block} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return bool true
*/
@@ -124,7 +124,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$output .= "class {$_className} extends Smarty_Internal_Block\n";
$output .= "{\n";
foreach ($_block as $property => $value) {
$output .= "public \${$property} = " . var_export($value,true) .";\n";
$output .= "public \${$property} = " . var_export($value, true) .";\n";
}
$output .= "public function callBlock(Smarty_Internal_Template \$_smarty_tpl) {\n";
$output .= $compiler->compileRequiredPlugins();
@@ -136,9 +136,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$output .= "ob_start();\n";
}
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php\n";
if (isset($_assign)) {
@@ -148,9 +152,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$output .= "}\n";
$output .= "/* {/block {$_name}} */\n\n";
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
// restore old status

View File

@@ -21,4 +21,4 @@ class Smarty_Internal_Compile_Block_Child extends Smarty_Internal_Compile_Child
* @var string
*/
public $tag = 'block_child';
}
}

View File

@@ -28,4 +28,4 @@ class Smarty_Internal_Compile_Block_Parent extends Smarty_Internal_Compile_Child
* @var string
*/
public $blockType = 'Parent';
}
}

View File

@@ -33,16 +33,16 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
public $shorttag_order = array('levels');
/**
* Tag name may be overloaded by Smarty_Internal_Compile_Continue
*
* @var string
*/
* Tag name may be overloaded by Smarty_Internal_Compile_Continue
*
* @var string
*/
public $tag = 'break';
/**
* Compiles code for the {break} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@@ -67,7 +67,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
/**
* check attributes and return array of break and foreach levels
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return array

View File

@@ -43,8 +43,8 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
/**
* Compiles the calls of user defined tags defined by {function}
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/

View File

@@ -35,9 +35,9 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
/**
* Compiles code for the {$smarty.capture.xxx}
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase$compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
@@ -55,9 +55,9 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
/**
* Compiles code for the {capture} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param null $parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param null $parameter
*
* @return string compiled code
*/
@@ -90,9 +90,9 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/capture} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param null $parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param null $parameter
*
* @return string compiled code
*/

View File

@@ -40,9 +40,9 @@ class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
/**
* Compiles code for the {child} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
@@ -53,8 +53,10 @@ class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
$_attr = $this->getAttributes($compiler, $args);
$tag = isset($parameter[0]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'";
if (!isset($compiler->_cache[ 'blockNesting' ])) {
$compiler->trigger_template_error("{$tag} used outside {block} tags ",
$compiler->parser->lex->taglineno);
$compiler->trigger_template_error(
"{$tag} used outside {block} tags ",
$compiler->parser->lex->taglineno
);
}
$compiler->has_code = true;
$compiler->suppressNocacheProcessing = true;
@@ -74,4 +76,4 @@ class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
$output .="?>\n";
return $output;
}
}
}

View File

@@ -60,7 +60,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
/**
* Compiles code for the {config_load} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code

View File

@@ -17,9 +17,9 @@
class Smarty_Internal_Compile_Continue extends Smarty_Internal_Compile_Break
{
/**
* Tag name
*
* @var string
*/
* Tag name
*
* @var string
*/
public $tag = 'continue';
}

View File

@@ -20,8 +20,8 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
/**
* Compiles code for the {debug} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/

View File

@@ -43,8 +43,8 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
/**
* Compiles code for the {eval} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/

View File

@@ -108,28 +108,34 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
$inlineUids = $match[ 1 ];
}
}
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
'<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl' .
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
'<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl' .
(isset($template) ?
", {$template}{$inlineUids}" :
'') . ");\n?>");
'') . ");\n?>"
);
}
/**
* Add code for including subtemplate to end of template
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param string $template subtemplate name
* @param string $template subtemplate name
*
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $template)
{
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
$compiler->compileTag('include',
array($template,
array('scope' => 'parent'))));
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$compiler->compileTag(
'include',
array($template,
array('scope' => 'parent'))
)
);
}
/**

View File

@@ -26,9 +26,9 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
* The parser is generating different sets of attribute by which this compiler can
* determine which syntax is used.
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
@@ -113,9 +113,9 @@ class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase
/**
* Compiles code for the {forelse} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
@@ -142,9 +142,9 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/for} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/

View File

@@ -78,7 +78,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
/**
* Compiles code for the {foreach} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@@ -119,8 +119,10 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
if ($fromName) {
foreach (array('item', 'key') as $a) {
if (isset($attributes[ $a ]) && $attributes[ $a ] === $fromName) {
$compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'",
null, true);
$compiler->trigger_template_error(
"'{$a}' and 'from' may not have same variable name '{$fromName}'",
null, true
);
}
}
}
@@ -187,8 +189,10 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
}
$needTotal = isset($itemAttr[ 'total' ]);
// Register tag
$this->openTag($compiler, 'foreach',
array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2));
$this->openTag(
$compiler, 'foreach',
array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2)
);
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
// generate output code
@@ -277,7 +281,7 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
/**
* Compiles code for the {foreachelse} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@@ -309,12 +313,12 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/foreach} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$compiler->loopNesting --;

View File

@@ -44,7 +44,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
/**
* Compiles code for the {function} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool true
@@ -91,7 +91,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/function} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param object|\Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool true
@@ -143,9 +143,13 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->saveTemplateVariables(\\\$_smarty_tpl, '{$_name}');\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value, \\\$_smarty_tpl->isRenderingCache);\n}\n?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";?>";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n";
@@ -154,13 +158,21 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "}\n}\n";
$output .= "/*/ {$_funcName}_nocache */\n\n";
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser,
preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
array($this, 'removeNocache'),
$_functionCode->to_smarty_php($compiler->parser)));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$_functionCode = new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
preg_replace_callback(
"/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
array($this, 'removeNocache'),
$_functionCode->to_smarty_php($compiler->parser)
)
);
}
$compiler->parent_compiler->tpl_function[ $_name ][ 'call_name' ] = $_funcName;
$output = "<?php\n";
@@ -171,18 +183,26 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\n}\n";
$output .= $compiler->compileCheckPlugins(array_merge($compiler->required_plugins[ 'compiled' ], $compiler->required_plugins[ 'nocache' ]));
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php\n}}\n";
$output .= "/*/ {$_funcName} */\n\n";
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$output
)
);
$compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
// restore old buffer
// restore old buffer
$compiler->parser->current_buffer = $saved_data[ 1 ];
// restore old status
$compiler->restoreRequiredPlugins();
@@ -201,8 +221,10 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
function removeNocache($match)
{
$code =
preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
'', $match[ 0 ]);
preg_replace(
"/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
'', $match[ 0 ]
);
$code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code);
return $code;
}

View File

@@ -55,8 +55,10 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$assignCompiler = new Smarty_Internal_Compile_Assign();
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
$_output .= $assignCompiler->compile($assignAttr, $compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
$_output .= $assignCompiler->compile(
$assignAttr, $compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
);
} else {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
$_output .= $assignCompiler->compile($assignAttr, $compiler, array());
@@ -84,7 +86,7 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
@@ -143,8 +145,10 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
$assignAttr[][ 'value' ] = $prefixVar;
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
$assignCode .= $assignCompiler->compile($assignAttr, $compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
$assignCode .= $assignCompiler->compile(
$assignAttr, $compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
);
} else {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
$assignCode .= $assignCompiler->compile($assignAttr, $compiler, array());

View File

@@ -59,8 +59,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
/**
* Compiles code for the {include} tag
*
* @param array $args array with attributes from parser
* @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object
* @param array $args array with attributes from parser
* @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object
*
* @return string
* @throws \Exception
@@ -91,8 +91,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$compiled->includes[ $fullResourceName ]++;
$cache_tpl = true;
} else {
if ("{$compiler->template->source->type}:{$compiler->template->source->name}" ==
$fullResourceName
if ("{$compiler->template->source->type}:{$compiler->template->source->name}" == $fullResourceName
) {
// recursive call of current template
$compiled->includes[ $fullResourceName ] = 2;
@@ -193,9 +192,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
$compiler->smarty->allow_ambiguous_resources = true;
/* @var Smarty_Internal_Template $tpl */
$tpl = new $compiler->smarty->template_class (trim($fullResourceName, '"\''), $compiler->smarty,
$compiler->template, $compiler->template->cache_id, $c_id,
$_caching);
$tpl = new $compiler->smarty->template_class(
trim($fullResourceName, '"\''), $compiler->smarty,
$compiler->template, $compiler->template->cache_id, $c_id,
$_caching
);
$uid = $tpl->source->type . $tpl->source->uid;
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ])) {
$has_compiled_template = $this->compileInlineTemplate($compiler, $tpl, $t_hash);
@@ -269,16 +270,16 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
*
* @param \Smarty_Internal_SmartyTemplateCompiler $compiler
* @param \Smarty_Internal_Template $tpl
* @param string $t_hash
* @param string $t_hash
*
* @return bool
* @throws \Exception
* @throws \SmartyException
*/
public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler,
Smarty_Internal_Template $tpl,
$t_hash)
{
Smarty_Internal_Template $tpl,
$t_hash
) {
$uid = $tpl->source->type . $tpl->source->uid;
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
$compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'uid' ] = $tpl->source->uid;
@@ -317,9 +318,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if ($tpl->compiled->has_nocache_code) {
// replace nocache_hash
$compiled_code =
str_replace("{$tpl->compiled->nocache_hash}",
$compiler->template->compiled->nocache_hash,
$compiled_code);
str_replace(
"{$tpl->compiled->nocache_hash}",
$compiler->template->compiled->nocache_hash,
$compiled_code
);
$compiler->template->compiled->has_nocache_code = true;
}
$compiler->parent_compiler->mergedSubTemplatesCode[ $tpl->compiled->unifunc ] = $compiled_code;

View File

@@ -42,7 +42,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
/**
* Compiles code for the {include_php} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string
@@ -56,7 +56,10 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
}
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
/** @var Smarty_Internal_Template $_smarty_tpl
/**
*
*
* @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $compiler->template;

View File

@@ -41,7 +41,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
/**
* Compiles code for the {insert} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@@ -104,11 +104,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
}
// code for script file loading
$_output .= "require_once '{$_filepath}' ;";
require_once $_filepath;
include_once $_filepath;
if (!is_callable($_function)) {
$compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'",
null,
true);
$compiler->trigger_template_error(
" {insert} function '{$_function}' is not callable in script file '{$_script}'",
null,
true
);
}
} else {
$_filepath = 'null';
@@ -117,9 +119,11 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
if (!is_callable($_function)) {
// try plugin
if (!$_function = $compiler->getPlugin($_name, 'insert')) {
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'",
null,
true);
$compiler->trigger_template_error(
"{insert} no function or plugin found for '{$_name}'",
null,
true
);
}
}
}

View File

@@ -16,11 +16,11 @@
*/
class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
{
/**
/**
* Compiles code for the {ldelim} tag
* This tag does output the left delimiter
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code

View File

@@ -41,11 +41,11 @@ class Smarty_Internal_Compile_Make_Nocache extends Smarty_Internal_CompileBase
/**
* Compiles code for the {make_nocache} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes

View File

@@ -27,7 +27,7 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
* Compiles code for the {nocache} tag
* This tag does not generate compiled output. It only sets a compiler flag.
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool
@@ -57,7 +57,7 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase
* Compiles code for the {/nocache} tag
* This tag does not generate compiled output. It only sets a compiler flag.
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool

View File

@@ -29,4 +29,4 @@ class Smarty_Internal_Compile_Parent extends Smarty_Internal_Compile_Child
* @var string
*/
public $blockType = 'Parent';
}
}

View File

@@ -34,11 +34,11 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
/**
* Compiles code for the execution of block plugin
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of block plugin
* @param string $function PHP function name
* @param array $parameter array with compilation parameter
* @param string $tag name of block plugin
* @param string $function PHP function name
*
* @return string compiled code
* @throws \SmartyCompilerException
@@ -84,9 +84,11 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
$mod_content2 = "\$_block_content{$this->nesting}";
$mod_content = "\$_block_content{$this->nesting} = ob_get_clean();\n";
$mod_pre = "ob_start();\n";
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifier_list' ],
'value' => 'ob_get_clean()')) . ";\n";
$mod_post = 'echo ' . $compiler->compileTag(
'private_modifier', array(),
array('modifierlist' => $parameter[ 'modifier_list' ],
'value' => 'ob_get_clean()')
) . ";\n";
}
$output = "<?php {$mod_content}\$_block_repeat=false;\n{$mod_pre}echo {$callback}({$_params}, {$mod_content2}, \$_smarty_tpl, \$_block_repeat);\n{$mod_post}}\n";
$output .= 'array_pop($_smarty_tpl->smarty->_cache[\'_tag_stack\']);?>';
@@ -98,9 +100,9 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
* Setup callback and parameter array
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param array $_attr attributes
* @param string $tag
* @param string $function
* @param array $_attr attributes
* @param string $tag
* @param string $function
*
* @return array
*/

View File

@@ -74,7 +74,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
/**
* Scan sources for used tag attributes
*
* @param array $attributes
* @param array $attributes
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*
* @throws \SmartyException
@@ -178,11 +178,13 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
$_content = $nextCompiler->template->source->getContent();
if ($_content !== '') {
// run pre filter if required
if ((isset($nextCompiler->smarty->autoload_filters[ 'pre' ]) ||
isset($nextCompiler->smarty->registered_filters[ 'pre' ]))
if ((isset($nextCompiler->smarty->autoload_filters[ 'pre' ])
|| isset($nextCompiler->smarty->registered_filters[ 'pre' ]))
) {
$_content = $nextCompiler->smarty->ext->_filterHandler->runFilter('pre', $_content,
$nextCompiler->template);
$_content = $nextCompiler->smarty->ext->_filterHandler->runFilter(
'pre', $_content,
$nextCompiler->template
);
}
$this->matchProperty($_content);
}
@@ -202,9 +204,9 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
/**
* Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
@@ -223,4 +225,4 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
$tagVar = "'__smarty_{$tag}_{$name}'";
return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)";
}
}
}

View File

@@ -35,11 +35,11 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
/**
* Compiles code for the execution of function plugin
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function plugin
* @param string $function PHP function name
* @param array $parameter array with compilation parameter
* @param string $tag name of function plugin
* @param string $function PHP function name
*
* @return string compiled code
* @throws \SmartyCompilerException
@@ -64,9 +64,11 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
// compile code
$output = "{$function}({$_params},\$_smarty_tpl)";
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
$output = $compiler->compileTag(
'private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output)
);
}
$output = "<?php echo {$output};?>\n";
return $output;

View File

@@ -20,9 +20,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
/**
* Compiles code for modifier execution
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
@@ -47,99 +47,103 @@ 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 ])) {
$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 ])) {
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 =
call_user_func($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ],
$single_modifier, $compiler->smarty);
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 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;
}
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))
}
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)
) {
$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})";
$plugin = 'smarty_modifiercompiler_' . $modifier;
$output = $plugin($single_modifier, $compiler);
}
$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)) {
$output = "{$function}({$params})";
} else {
if (is_object($function[ 0 ])) {
$output = $function[ 0 ] . '->'. $function[ 1 ] . '(' . $params . ')';
} else {
if (is_object($function[ 0 ])) {
$output = $function[ 0 ] . '->'. $function[ 1 ] . '(' . $params . ')';
} else {
$output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')';
}
$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 ])) {
@@ -149,4 +153,4 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
return $output;
}
}
}

View File

@@ -20,9 +20,9 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
* Setup callback and parameter array
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param array $_attr attributes
* @param string $tag
* @param string $method
* @param array $_attr attributes
* @param string $tag
* @param string $method
*
* @return array
*/

View File

@@ -27,11 +27,11 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
/**
* Compiles code for the execution of function plugin
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function
* @param string $method name of method to call
* @param array $parameter array with compilation parameter
* @param string $tag name of function
* @param string $method name of method to call
*
* @return string compiled code
* @throws \SmartyCompilerException
@@ -70,8 +70,10 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
$output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
}
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output));
$output = $compiler->compileTag(
'private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output)
);
}
if (empty($_assign)) {
return "<?php echo {$output};?>\n";

View File

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

View File

@@ -49,9 +49,11 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
$output = $parameter[ 'value' ];
// tag modifier
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
$output = $compiler->compileTag(
'private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output)
);
}
if (isset($_attr[ 'assign' ])) {
// assign output to variable
@@ -64,8 +66,10 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
if (empty($compiler->default_modifier_list)) {
$modifierlist = array();
foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) {
preg_match_all('/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/',
$single_default_modifier, $mod_array);
preg_match_all(
'/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/',
$single_default_modifier, $mod_array
);
for ($i = 0, $count = count($mod_array[ 0 ]); $i < $count; $i ++) {
if ($mod_array[ 0 ][ $i ] !== ':') {
$modifierlist[ $key ][] = $mod_array[ 0 ][ $i ];
@@ -74,9 +78,11 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
$compiler->default_modifier_list = $modifierlist;
}
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $compiler->default_modifier_list,
'value' => $output));
$output = $compiler->compileTag(
'private_modifier', array(),
array('modifierlist' => $compiler->default_modifier_list,
'value' => $output)
);
}
// autoescape html
if ($compiler->template->smarty->escape_html) {
@@ -110,13 +116,15 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
}
foreach ($compiler->variable_filters as $filter) {
if (count($filter) === 1 &&
($result = $this->compile_variable_filter($compiler, $filter[ 0 ], $output)) !== false
if (count($filter) === 1
&& ($result = $this->compile_variable_filter($compiler, $filter[ 0 ], $output)) !== false
) {
$output = $result;
} else {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => array($filter), 'value' => $output));
$output = $compiler->compileTag(
'private_modifier', array(),
array('modifierlist' => array($filter), 'value' => $output)
);
}
}
}
@@ -136,12 +144,12 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
*/
private function compile_variable_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output)
{
$function= $compiler->getPlugin($name, 'variablefilter');
if ($function) {
$function= $compiler->getPlugin($name, 'variablefilter');
if ($function) {
return "{$function}({$output},\$_smarty_tpl)";
} else {
} else {
// not found
return false;
}
}
}
}

View File

@@ -20,9 +20,9 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
* Setup callback, parameter array and nocache mode
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param array $_attr attributes
* @param string $tag
* @param null $function
* @param array $_attr attributes
* @param string $tag
* @param null $function
*
* @return array
*/

View File

@@ -27,10 +27,10 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
/**
* Compiles code for the execution of a registered function
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function
* @param array $parameter array with compilation parameter
* @param string $tag name of function
*
* @return string compiled code
* @throws \SmartyCompilerException
@@ -76,11 +76,13 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
}
}
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
$output = $compiler->compileTag(
'private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output)
);
}
$output = "<?php echo {$output};?>\n";
return $output;
}
}
}

View File

@@ -19,9 +19,9 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
/**
* Compiles code for the special $smarty variables
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param $parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param $parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
@@ -33,86 +33,86 @@ 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) ||
$compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)
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");
break;
}
$compiled_ref = '$_COOKIE';
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;
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);
}
$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");
break;
}
$compiled_ref = '$_' . strtoupper($variable);
break;
case 'template':
return 'basename($_smarty_tpl->source->filepath)';
case 'template':
return 'basename($_smarty_tpl->source->filepath)';
case 'template_object':
return '$_smarty_tpl';
case 'template_object':
return '$_smarty_tpl';
case 'current_dir':
return 'dirname($_smarty_tpl->source->filepath)';
case 'current_dir':
return 'dirname($_smarty_tpl->source->filepath)';
case 'version':
return "Smarty::SMARTY_VERSION";
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');
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 (isset($_index[ 1 ])) {
array_shift($_index);

View File

@@ -20,7 +20,7 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_Compile_Ldelim
* Compiles code for the {rdelim} tag
* This tag does output the right delimiter.
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@@ -28,7 +28,7 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_Compile_Ldelim
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
parent::compile($args,$compiler);
parent::compile($args, $compiler);
return $compiler->smarty->right_delimiter;
}
}

View File

@@ -79,8 +79,8 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
/**
* Compiles code for the {section} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
@@ -132,50 +132,50 @@ 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";
$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";
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;
}
if ($t === 3 && $compiler->getId($attr_value)) {
$t = 1;
@@ -264,8 +264,10 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$start_code[ $i ] = '';
}
if ($propType[ 'start' ] === 0) {
$start_code = array(max($propValue[ 'step' ] > 0 ? 0 : - 1,
$propValue[ 'start' ] + $propValue[ 'loop' ]));
$start_code = array(max(
$propValue[ 'step' ] > 0 ? 0 : - 1,
$propValue[ 'start' ] + $propValue[ 'loop' ]
));
}
} else {
for ($i = 1; $i <= 11; $i ++) {
@@ -273,8 +275,10 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
}
if ($propType[ 'start' ] === 0) {
$start_code =
array(min($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1,
$propValue[ 'start' ]));
array(min(
$propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1,
$propValue[ 'start' ]
));
}
}
}
@@ -295,8 +299,12 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$propType[ 'start' ] + $propType[ 'loop' ] + $propType[ 'step' ] + $propType[ 'max' ];
if ($propType[ 'total' ] === 0) {
$propValue[ 'total' ] =
min(ceil(($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] - $propValue[ 'start' ] :
(int) $propValue[ 'start' ] + 1) / abs($propValue[ 'step' ])), $propValue[ 'max' ]);
min(
ceil(
($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] - $propValue[ 'start' ] :
(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 => ' : ',
@@ -404,7 +412,7 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
/**
* Compiles code for the {sectionelse} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@@ -432,7 +440,7 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/section} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code

View File

@@ -19,9 +19,9 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase
/**
* Compiles code for setfilter tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
@@ -48,7 +48,7 @@ class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase
* Compiles code for the {/setfilter} tag
* This tag does not generate compiled output. It resets variable filter.
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code

View File

@@ -37,12 +37,14 @@ class Smarty_Internal_Compile_Shared_Inheritance extends Smarty_Internal_Compile
public function registerInit(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
{
if ($initChildSequence || !isset($compiler->_cache['inheritanceInit'])) {
$compiler->registerPostCompileCallback(array('Smarty_Internal_Compile_Shared_Inheritance', 'postCompile'),
array($initChildSequence),
'inheritanceInit',
$initChildSequence);
$compiler->registerPostCompileCallback(
array('Smarty_Internal_Compile_Shared_Inheritance', 'postCompile'),
array($initChildSequence),
'inheritanceInit',
$initChildSequence
);
$compiler->_cache['inheritanceInit'] = true;
}
}
}
}

View File

@@ -19,9 +19,9 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
/**
* Compiles code for the {while} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
@@ -56,8 +56,10 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
$_output = "<?php while ({$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]}) {?>";
$_output .= $assignCompiler->compile($assignAttr, $compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
$_output .= $assignCompiler->compile(
$assignAttr, $compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
);
} else {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
$_output = "<?php while ({$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]}) {?>";
@@ -82,7 +84,7 @@ class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/while} tag
*
* @param array $args array with attributes from parser
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code

View File

@@ -65,8 +65,8 @@ abstract class Smarty_Internal_CompileBase
* the corresponding list. The keyword '_any' specifies that any attribute will be accepted
* as valid
*
* @param object $compiler compiler object
* @param array $attributes attributes applied to the tag
* @param object $compiler compiler object
* @param array $attributes attributes applied to the tag
*
* @return array of mapped attributes for further processing
*/
@@ -103,8 +103,10 @@ abstract class Smarty_Internal_CompileBase
if (isset($this->optionMap[ $v ])) {
$_indexed_attr[ $k ] = $this->optionMap[ $v ];
} else {
$compiler->trigger_template_error("illegal value '" . var_export($v, true) .
"' for option flag '{$k}'", null, true);
$compiler->trigger_template_error(
"illegal value '" . var_export($v, true) .
"' for option flag '{$k}'", null, true
);
}
}
// must be named attribute
@@ -124,8 +126,12 @@ abstract class Smarty_Internal_CompileBase
if ($this->optional_attributes !== array('_any')) {
if (!isset($this->mapCache[ 'all' ])) {
$this->mapCache[ 'all' ] =
array_fill_keys(array_merge($this->required_attributes, $this->optional_attributes,
$this->option_flags), true);
array_fill_keys(
array_merge(
$this->required_attributes, $this->optional_attributes,
$this->option_flags
), true
);
}
foreach ($_indexed_attr as $key => $dummy) {
if (!isset($this->mapCache[ 'all' ][ $key ]) && $key !== 0) {
@@ -162,8 +168,8 @@ abstract class Smarty_Internal_CompileBase
* Pop closing tag
* Raise an error if this stack-top doesn't match with expected opening tags
*
* @param object $compiler compiler object
* @param array|string $expectedTag the expected opening tag names
* @param object $compiler compiler object
* @param array|string $expectedTag the expected opening tag names
*
* @return mixed any type the opening tag's name or saved data
*/

View File

@@ -114,9 +114,13 @@ class Smarty_Internal_Config_File_Compiler
}
// init the lexer/parser to compile the config file
/* @var Smarty_Internal_ConfigFileLexer $this ->lex */
$this->lex = new $this->lexer_class(str_replace(array("\r\n",
"\r"), "\n", $template->source->getContent()) . "\n",
$this);
$this->lex = new $this->lexer_class(
str_replace(
array("\r\n",
"\r"), "\n", $template->source->getContent()
) . "\n",
$this
);
/* @var Smarty_Internal_ConfigFileParser $this ->parser */
$this->parser = new $this->parser_class($this->lex, $this);

View File

@@ -130,7 +130,7 @@ 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)
@@ -166,39 +166,47 @@ 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
);
}
}
@@ -206,11 +214,13 @@ 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
);
}
}
@@ -234,10 +244,14 @@ 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,8 +276,10 @@ 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);
@@ -332,10 +348,14 @@ 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
@@ -360,8 +380,10 @@ 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);
@@ -404,8 +426,9 @@ 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
@@ -447,10 +470,14 @@ 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
@@ -475,8 +502,10 @@ 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);
@@ -507,10 +536,14 @@ 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
@@ -535,8 +568,10 @@ 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);
@@ -577,10 +612,14 @@ 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
@@ -605,8 +644,10 @@ 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);
@@ -642,10 +683,14 @@ 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
@@ -670,8 +715,10 @@ 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

@@ -9,7 +9,7 @@ class TPC_yyStackEntry
** is the value of the token */
}
#line 12 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 12 "../smarty/lexer/smarty_internal_configfileparser.y"
/**
* Smarty Internal Plugin Configfileparse
@@ -23,7 +23,7 @@ class TPC_yyStackEntry
*/
class Smarty_Internal_Configfileparser
{
#line 25 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 25 "../smarty/lexer/smarty_internal_configfileparser.y"
const TPC_OPENB = 1;
const TPC_SECTION = 2;
const TPC_CLOSEB = 3;
@@ -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 */
}
}
@@ -375,9 +375,11 @@ 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);
@@ -429,7 +431,8 @@ 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 ])) {
@@ -439,8 +442,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);
@@ -515,7 +518,8 @@ 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;
@@ -523,10 +527,13 @@ 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;
@@ -584,15 +591,19 @@ 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);
}
@@ -616,8 +627,9 @@ 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 ];
@@ -635,7 +647,7 @@ class Smarty_Internal_Configfileparser
while ($this->yyidx >= 0) {
$this->yy_pop_parser_stack();
}
#line 239 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 239 "../smarty/lexer/smarty_internal_configfileparser.y"
$this->internalError = true;
$this->compiler->trigger_config_file_error('Stack overflow in configfile parser');
return;
@@ -646,15 +658,19 @@ 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");
}
@@ -677,100 +693,105 @@ class Smarty_Internal_Configfileparser
$this->_retvalue = null;
}
#line 245 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 245 "../smarty/lexer/smarty_internal_configfileparser.y"
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;
}
#line 250 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 250 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r6()
{
$this->_retvalue = $this->yystack[ $this->yyidx + -1 ]->minor;
}
#line 264 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 264 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r7()
{
$this->_retvalue =
array_merge($this->yystack[ $this->yyidx + -1 ]->minor, array($this->yystack[ $this->yyidx + 0 ]->minor));
}
#line 269 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 269 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r8()
{
$this->_retvalue = array();
}
#line 277 "../smarty/lexer/smarty_internal_configfileparser.y"
// 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);
}
#line 281 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 281 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r10()
{
$this->_retvalue = (float)$this->yystack[ $this->yyidx + 0 ]->minor;
}
#line 285 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 285 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r11()
{
$this->_retvalue = (int)$this->yystack[ $this->yyidx + 0 ]->minor;
}
#line 291 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 291 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r12()
{
$this->_retvalue = $this->parse_bool($this->yystack[ $this->yyidx + 0 ]->minor);
}
#line 296 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 296 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r13()
{
$this->_retvalue = self::parse_single_quoted_string($this->yystack[ $this->yyidx + 0 ]->minor);
}
#line 300 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 300 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r14()
{
$this->_retvalue = self::parse_double_quoted_string($this->yystack[ $this->yyidx + 0 ]->minor);
}
#line 304 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 304 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r15()
{
$this->_retvalue = self::parse_tripple_double_quoted_string($this->yystack[ $this->yyidx + -1 ]->minor);
}
#line 308 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 308 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r16()
{
$this->_retvalue = '';
}
#line 312 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 312 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r17()
{
$this->_retvalue = $this->yystack[ $this->yyidx + 0 ]->minor;
}
#line 316 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 316 "../smarty/lexer/smarty_internal_configfileparser.y"
public function yy_reduce($yyruleno)
{
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 ])) {
@@ -803,7 +824,7 @@ class Smarty_Internal_Configfileparser
}
}
#line 320 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 320 "../smarty/lexer/smarty_internal_configfileparser.y"
public function yy_parse_failed()
{
if ($this->yyTraceFILE) {
@@ -814,10 +835,10 @@ class Smarty_Internal_Configfileparser
}
}
#line 324 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 324 "../smarty/lexer/smarty_internal_configfileparser.y"
public function yy_syntax_error($yymajor, $TOKEN)
{
#line 232 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 232 "../smarty/lexer/smarty_internal_configfileparser.y"
$this->internalError = true;
$this->yymajor = $yymajor;
$this->compiler->trigger_config_file_error();
@@ -831,7 +852,7 @@ class Smarty_Internal_Configfileparser
while ($this->yyidx >= 0) {
$this->yy_pop_parser_stack();
}
#line 225 "../smarty/lexer/smarty_internal_configfileparser.y"
// line 225 "../smarty/lexer/smarty_internal_configfileparser.y"
$this->successful = !$this->internalError;
$this->internalError = false;
$this->retvalue = $this->_retvalue;
@@ -851,15 +872,18 @@ 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;
}
@@ -875,9 +899,11 @@ class Smarty_Internal_Configfileparser
$this->yy_reduce($yyact - self::YYNSTATE);
} else if ($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) {
@@ -886,10 +912,12 @@ 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;

View File

@@ -87,9 +87,9 @@ abstract class Smarty_Internal_Data
/**
* assigns a Smarty variable
*
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for
* chaining
@@ -103,7 +103,11 @@ abstract class Smarty_Internal_Data
} else {
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);
@@ -119,11 +123,11 @@ abstract class Smarty_Internal_Data
* @api Smarty::append()
* @link http://www.smarty.net/docs/en/api.append.tpl
*
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param bool $merge flag if array elements shall be merged
* @param bool $nocache if true any output of this variable will
* be not cached
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param bool $merge flag if array elements shall be merged
* @param bool $nocache if true any output of this variable will
* be not cached
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
@@ -135,9 +139,9 @@ abstract class Smarty_Internal_Data
/**
* assigns a global Smarty variable
*
* @param string $varName the global variable name
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
* @param string $varName the global variable name
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
@@ -149,9 +153,9 @@ abstract class Smarty_Internal_Data
/**
* appends values to template variables by reference
*
* @param string $tpl_var the template variable name
* @param mixed &$value the referenced value to append
* @param boolean $merge flag if array elements shall be merged
* @param string $tpl_var the template variable name
* @param mixed &$value the referenced value to append
* @param boolean $merge flag if array elements shall be merged
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
@@ -163,9 +167,9 @@ abstract class Smarty_Internal_Data
/**
* assigns values to template variables by reference
*
* @param string $tpl_var the template variable name
* @param $value
* @param boolean $nocache if true any output of this variable will be not cached
* @param string $tpl_var the template variable name
* @param $value
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
@@ -180,9 +184,9 @@ abstract class Smarty_Internal_Data
* @api Smarty::getTemplateVars()
* @link http://www.smarty.net/docs/en/api.get.template.vars.tpl
*
* @param string $varName variable name or null
* @param string $varName variable name or null
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
* @param bool $searchParents include parent templates?
* @param bool $searchParents include parent templates?
*
* @return mixed variable value or or array of variables
*/
@@ -194,17 +198,17 @@ abstract class Smarty_Internal_Data
/**
* gets the object of a Smarty variable
*
* @param string $variable the name of the Smarty variable
* @param Smarty_Internal_Data $_ptr optional pointer to data object
* @param boolean $searchParents search also in parent data
* @param bool $error_enable
* @param string $variable the name of the Smarty variable
* @param Smarty_Internal_Data $_ptr optional pointer to data object
* @param boolean $searchParents search also in parent data
* @param bool $error_enable
*
* @return Smarty_Variable|Smarty_Undefined_Variable the object of the variable
* @return Smarty_Variable|Smarty_Undefined_Variable the object of the variable
* @deprecated since 3.1.28 please use Smarty_Internal_Data::getTemplateVars() instead.
*/
public function getVariable($variable = null, Smarty_Internal_Data $_ptr = null, $searchParents = true,
$error_enable = true)
{
$error_enable = true
) {
return $this->ext->getTemplateVars->_getVariable($this, $variable, $_ptr, $searchParents, $error_enable);
}

View File

@@ -191,7 +191,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
/**
* Opens a window for the Smarty Debugging Console and display the data
*
* @param Smarty_Internal_Template|Smarty $obj object to debug
* @param Smarty_Internal_Template|Smarty $obj object to debug
* @param bool $full
*
* @throws \Exception
@@ -264,7 +264,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
/**
* Recursively gets variables from all template/data scopes
*
* @param Smarty_Internal_Template|Smarty_Data $obj object to debug
* @param Smarty_Internal_Template|Smarty_Data $obj object to debug
*
* @return StdClass
*/

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