1
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2025-08-07 17:42:53 +03:00

bump smarty to v4.1.1, some security fixes that probably do not affect PFA; adds PHP8.1 support

This commit is contained in:
David Goodwin
2022-06-28 13:56:41 +01:00
parent 835fd87d5f
commit 58e9538e6a
97 changed files with 3150 additions and 4677 deletions

View File

@@ -39,7 +39,7 @@ class Smarty_Autoloader
* *
* @var array * @var array
*/ */
public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',); public static $rootClasses = array('smarty' => 'Smarty.class.php');
/** /**
* Registers Smarty_Autoloader backward compatible to older installations. * Registers Smarty_Autoloader backward compatible to older installations.
@@ -76,11 +76,7 @@ class Smarty_Autoloader
self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR; self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR;
self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR :
self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR; self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR;
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
} else {
spl_autoload_register(array(__CLASS__, 'autoload'));
}
} }
/** /**
@@ -90,7 +86,7 @@ class Smarty_Autoloader
*/ */
public static function autoload($class) public static function autoload($class)
{ {
if ($class[ 0 ] !== 'S' && strpos($class, 'Smarty') !== 0) { if ($class[ 0 ] !== 'S' || strpos($class, 'Smarty') !== 0) {
return; return;
} }
$_class = strtolower($class); $_class = strtolower($class);

View File

@@ -6,7 +6,7 @@
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * version 3.0 of the License, or (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,14 +20,13 @@
* Smarty mailing list. Send a blank e-mail to * Smarty mailing list. Send a blank e-mail to
* smarty-discussion-subscribe@googlegroups.com * smarty-discussion-subscribe@googlegroups.com
* *
* @link http://www.smarty.net/ * @link https://www.smarty.net/
* @copyright 2018 New Digital Group, Inc. * @copyright 2018 New Digital Group, Inc.
* @copyright 2018 Uwe Tews * @copyright 2018 Uwe Tews
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews <uwe dot tews at gmail dot com> * @author Uwe Tews <uwe dot tews at gmail dot com>
* @author Rodney Rehm * @author Rodney Rehm
* @package Smarty * @package Smarty
* @version 3.1.33
*/ */
/** /**
* set SMARTY_DIR to absolute path to Smarty library files. * set SMARTY_DIR to absolute path to Smarty library files.
@@ -61,19 +60,6 @@ if (!defined('SMARTY_MBSTRING')) {
*/ */
define('SMARTY_MBSTRING', function_exists('mb_get_info')); define('SMARTY_MBSTRING', function_exists('mb_get_info'));
} }
if (!defined('SMARTY_RESOURCE_CHAR_SET')) {
// UTF-8 can only be done properly when mbstring is available!
/**
* @deprecated in favor of Smarty::$_CHARSET
*/
define('SMARTY_RESOURCE_CHAR_SET', SMARTY_MBSTRING ? 'UTF-8' : 'ISO-8859-1');
}
if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) {
/**
* @deprecated in favor of Smarty::$_DATE_FORMAT
*/
define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y');
}
/** /**
* Load Smarty_Autoloader * Load Smarty_Autoloader
*/ */
@@ -112,7 +98,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.33'; const SMARTY_VERSION = '4.1.1';
/** /**
* define variable scopes * define variable scopes
*/ */
@@ -144,13 +130,7 @@ class Smarty extends Smarty_Internal_TemplateBase
const DEBUG_OFF = 0; const DEBUG_OFF = 0;
const DEBUG_ON = 1; const DEBUG_ON = 1;
const DEBUG_INDIVIDUAL = 2; const DEBUG_INDIVIDUAL = 2;
/**
* modes for handling of "<?php ... ?>" tags in templates.
*/
const PHP_PASSTHRU = 0; //-> print tags as plain text
const PHP_QUOTE = 1; //-> escape tags as entities
const PHP_REMOVE = 2; //-> escape tags as entities
const PHP_ALLOW = 3; //-> escape tags as entities
/** /**
* filter types * filter types
*/ */
@@ -180,13 +160,13 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* The character set to adhere to (e.g. "UTF-8") * The character set to adhere to (e.g. "UTF-8")
*/ */
public static $_CHARSET = SMARTY_RESOURCE_CHAR_SET; public static $_CHARSET = SMARTY_MBSTRING ? 'UTF-8' : 'ISO-8859-1';
/** /**
* The date format to be used internally * The date format to be used internally
* (accepts date() and strftime()) * (accepts date() and strftime())
*/ */
public static $_DATE_FORMAT = SMARTY_RESOURCE_DATE_FORMAT; public static $_DATE_FORMAT = '%b %e, %Y';
/** /**
* Flag denoting if PCRE should run in UTF-8 mode * Flag denoting if PCRE should run in UTF-8 mode
@@ -370,13 +350,6 @@ class Smarty extends Smarty_Internal_TemplateBase
*/ */
public $security_policy = null; public $security_policy = null;
/**
* controls handling of PHP-blocks
*
* @var integer
*/
public $php_handling = self::PHP_PASSTHRU;
/** /**
* controls if the php template file resource is allowed * controls if the php template file resource is allowed
* *
@@ -667,6 +640,12 @@ class Smarty extends Smarty_Internal_TemplateBase
'cache_dir' => 'CacheDir', 'cache_dir' => 'CacheDir',
); );
/**
* PHP7 Compatibility mode
* @var bool
*/
private $isMutingUndefinedOrNullWarnings = false;
/** /**
* Initialize new Smarty object * Initialize new Smarty object
*/ */
@@ -689,27 +668,6 @@ class Smarty extends Smarty_Internal_TemplateBase
} }
} }
/**
* Enable error handler to mute expected messages
*
* @return boolean
* @deprecated
*/
public static function muteExpectedErrors()
{
return Smarty_Internal_ErrorHandler::muteExpectedErrors();
}
/**
* Disable error handler muting expected messages
*
* @deprecated
*/
public static function unmuteExpectedErrors()
{
restore_error_handler();
}
/** /**
* Check if a template resource exists * Check if a template resource exists
* *
@@ -800,7 +758,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param mixed $index index of directory to get, null to get all * @param mixed $index index of directory to get, null to get all
* @param bool $isConfig true for config_dir * @param bool $isConfig true for config_dir
* *
* @return array list of template directories, or directory of $index * @return array|string list of template directories, or directory of $index
*/ */
public function getTemplateDir($index = null, $isConfig = false) public function getTemplateDir($index = null, $isConfig = false)
{ {
@@ -909,7 +867,7 @@ class Smarty extends Smarty_Internal_TemplateBase
$this->plugins_dir = (array)$this->plugins_dir; $this->plugins_dir = (array)$this->plugins_dir;
} }
foreach ($this->plugins_dir as $k => $v) { foreach ($this->plugins_dir as $k => $v) {
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, '/\\') . DIRECTORY_SEPARATOR, true); $this->plugins_dir[ $k ] = $this->_realpath(rtrim($v ?? '', '/\\') . DIRECTORY_SEPARATOR, true);
} }
$this->_cache[ 'plugin_files' ] = array(); $this->_cache[ 'plugin_files' ] = array();
$this->_pluginsDirNormalized = true; $this->_pluginsDirNormalized = true;
@@ -1387,12 +1345,7 @@ class Smarty extends Smarty_Internal_TemplateBase
*/ */
private function _normalizeDir($dirName, $dir) private function _normalizeDir($dirName, $dir)
{ {
$this->{$dirName} = $this->_realpath(rtrim($dir, "/\\") . DIRECTORY_SEPARATOR, true); $this->{$dirName} = $this->_realpath(rtrim($dir ?? '', "/\\") . DIRECTORY_SEPARATOR, true);
if (class_exists('Smarty_Internal_ErrorHandler', false)) {
if (!isset(Smarty_Internal_ErrorHandler::$mutedDirectories[ $this->{$dirName} ])) {
Smarty_Internal_ErrorHandler::$mutedDirectories[ $this->{$dirName} ] = null;
}
}
} }
/** /**
@@ -1414,7 +1367,7 @@ class Smarty extends Smarty_Internal_TemplateBase
} }
foreach ($dir as $k => $v) { foreach ($dir as $k => $v) {
if (!isset($processed[ $k ])) { if (!isset($processed[ $k ])) {
$dir[ $k ] = $v = $this->_realpath(rtrim($v, "/\\") . DIRECTORY_SEPARATOR, true); $dir[ $k ] = $v = $this->_realpath(rtrim($v ?? '', "/\\") . DIRECTORY_SEPARATOR, true);
$processed[ $k ] = true; $processed[ $k ] = true;
} }
} }
@@ -1422,4 +1375,23 @@ class Smarty extends Smarty_Internal_TemplateBase
$isConfig ? $this->_joined_config_dir = join('#', $this->config_dir) : $isConfig ? $this->_joined_config_dir = join('#', $this->config_dir) :
$this->_joined_template_dir = join('#', $this->template_dir); $this->_joined_template_dir = join('#', $this->template_dir);
} }
/**
* Activates PHP7 compatibility mode:
* - converts E_WARNINGS for "undefined array key" and "trying to read property of null" errors to E_NOTICE
*
* @void
*/
public function muteUndefinedOrNullWarnings(): void {
$this->isMutingUndefinedOrNullWarnings = true;
}
/**
* Indicates if PHP7 compatibility mode is set.
* @bool
*/
public function isMutingUndefinedOrNullWarnings(): bool {
return $this->isMutingUndefinedOrNullWarnings;
}
} }

View File

@@ -1,477 +0,0 @@
<?php
/**
* Project: Smarty: the PHP compiling template engine
* File: SmartyBC.class.php
* SVN: $Id: $
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* For questions, help, comments, discussion, etc., please join the
* Smarty mailing list. Send a blank e-mail to
* smarty-discussion-subscribe@googlegroups.com
*
* @link http://www.smarty.net/
* @copyright 2008 New Digital Group, Inc.
* @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews
* @author Rodney Rehm
* @package Smarty
*/
/**
* @ignore
*/
require_once dirname(__FILE__) . '/Smarty.class.php';
/**
* Smarty Backward Compatibility Wrapper Class
*
* @package Smarty
*/
class SmartyBC extends Smarty
{
/**
* Smarty 2 BC
*
* @var string
*/
public $_version = self::SMARTY_VERSION;
/**
* This is an array of directories where trusted php scripts reside.
*
* @var array
*/
public $trusted_dir = array();
/**
* Initialize new SmartyBC object
*/
public function __construct()
{
parent::__construct();
}
/**
* wrapper for assign_by_ref
*
* @param string $tpl_var the template variable name
* @param mixed &$value the referenced value to assign
*/
public function assign_by_ref($tpl_var, &$value)
{
$this->assignByRef($tpl_var, $value);
}
/**
* wrapper for append_by_ref
*
* @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
*/
public function append_by_ref($tpl_var, &$value, $merge = false)
{
$this->appendByRef($tpl_var, $value, $merge);
}
/**
* clear the given assigned template variable.
*
* @param string $tpl_var the template variable to clear
*/
public function clear_assign($tpl_var)
{
$this->clearAssign($tpl_var);
}
/**
* Registers custom function to be used in templates
*
* @param string $function the name of the template function
* @param string $function_impl the name of the PHP function to register
* @param bool $cacheable
* @param mixed $cache_attrs
*
* @throws \SmartyException
*/
public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null)
{
$this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
}
/**
* Unregister custom function
*
* @param string $function name of template function
*/
public function unregister_function($function)
{
$this->unregisterPlugin('function', $function);
}
/**
* Registers object to be used in templates
*
* @param string $object name of template object
* @param object $object_impl the referenced PHP object to register
* @param array $allowed list of allowed methods (empty = all)
* @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_methods list of methods that are block format
*
* @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()
) {
settype($allowed, 'array');
settype($smarty_args, 'boolean');
$this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
}
/**
* Unregister object
*
* @param string $object name of template object
*/
public function unregister_object($object)
{
$this->unregisterObject($object);
}
/**
* Registers block function to be used in templates
*
* @param string $block name of template block
* @param string $block_impl PHP function to register
* @param bool $cacheable
* @param mixed $cache_attrs
*
* @throws \SmartyException
*/
public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null)
{
$this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
}
/**
* Unregister block function
*
* @param string $block name of template function
*/
public function unregister_block($block)
{
$this->unregisterPlugin('block', $block);
}
/**
* Registers compiler function
*
* @param string $function name of template function
* @param string $function_impl name of PHP function to register
* @param bool $cacheable
*
* @throws \SmartyException
*/
public function register_compiler_function($function, $function_impl, $cacheable = true)
{
$this->registerPlugin('compiler', $function, $function_impl, $cacheable);
}
/**
* Unregister compiler function
*
* @param string $function name of template function
*/
public function unregister_compiler_function($function)
{
$this->unregisterPlugin('compiler', $function);
}
/**
* Registers modifier to be used in templates
*
* @param string $modifier name of template modifier
* @param string $modifier_impl name of PHP function to register
*
* @throws \SmartyException
*/
public function register_modifier($modifier, $modifier_impl)
{
$this->registerPlugin('modifier', $modifier, $modifier_impl);
}
/**
* Unregister modifier
*
* @param string $modifier name of template modifier
*/
public function unregister_modifier($modifier)
{
$this->unregisterPlugin('modifier', $modifier);
}
/**
* Registers a resource to fetch a template
*
* @param string $type name of resource
* @param array $functions array of functions to handle resource
*/
public function register_resource($type, $functions)
{
$this->registerResource($type, $functions);
}
/**
* Unregister a resource
*
* @param string $type name of resource
*/
public function unregister_resource($type)
{
$this->unregisterResource($type);
}
/**
* Registers a prefilter function to apply
* to a template before compiling
*
* @param callable $function
*
* @throws \SmartyException
*/
public function register_prefilter($function)
{
$this->registerFilter('pre', $function);
}
/**
* Unregister a prefilter function
*
* @param callable $function
*/
public function unregister_prefilter($function)
{
$this->unregisterFilter('pre', $function);
}
/**
* Registers a postfilter function to apply
* to a compiled template after compilation
*
* @param callable $function
*
* @throws \SmartyException
*/
public function register_postfilter($function)
{
$this->registerFilter('post', $function);
}
/**
* Unregister a postfilter function
*
* @param callable $function
*/
public function unregister_postfilter($function)
{
$this->unregisterFilter('post', $function);
}
/**
* Registers an output filter function to apply
* to a template output
*
* @param callable $function
*
* @throws \SmartyException
*/
public function register_outputfilter($function)
{
$this->registerFilter('output', $function);
}
/**
* Unregister an outputfilter function
*
* @param callable $function
*/
public function unregister_outputfilter($function)
{
$this->unregisterFilter('output', $function);
}
/**
* load a filter of specified type and name
*
* @param string $type filter type
* @param string $name filter name
*
* @throws \SmartyException
*/
public function load_filter($type, $name)
{
$this->loadFilter($type, $name);
}
/**
* 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
*
* @return boolean
*/
public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
{
return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
}
/**
* clear the entire contents of cache (all templates)
*
* @param string $exp_time expire time
*
* @return boolean
*/
public function clear_all_cache($exp_time = null)
{
return $this->clearCache(null, null, null, $exp_time);
}
/**
* 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
*
* @return bool
* @throws \Exception
* @throws \SmartyException
*/
public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
{
return $this->isCached($tpl_file, $cache_id, $compile_id);
}
/**
* clear all the assigned template variables.
*/
public function clear_all_assign()
{
$this->clearAllAssign();
}
/**
* clears compiled version of specified template resource,
* 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
*
* @return boolean results of {@link smarty_core_rm_auto()}
*/
public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
{
return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
}
/**
* Checks whether requested template exists.
*
* @param string $tpl_file
*
* @return bool
* @throws \SmartyException
*/
public function template_exists($tpl_file)
{
return $this->templateExists($tpl_file);
}
/**
* Returns an array containing template variables
*
* @param string $name
*
* @return array
*/
public function get_template_vars($name = null)
{
return $this->getTemplateVars($name);
}
/**
* Returns an array containing config variables
*
* @param string $name
*
* @return array
*/
public function get_config_vars($name = null)
{
return $this->getConfigVars($name);
}
/**
* load configuration values
*
* @param string $file
* @param string $section
* @param string $scope
*/
public function config_load($file, $section = null, $scope = 'global')
{
$this->ConfigLoad($file, $section, $scope);
}
/**
* return a reference to a registered object
*
* @param string $name
*
* @return object
*/
public function get_registered_object($name)
{
return $this->getRegisteredObject($name);
}
/**
* clear configuration values
*
* @param string $var
*/
public function clear_config($var = null)
{
$this->clearConfig($var);
}
/**
* trigger Smarty error
*
* @param string $error_msg
* @param integer $error_type
*/
public function trigger_error($error_msg, $error_type = E_USER_WARNING)
{
trigger_error("Smarty error: $error_msg", $error_type);
}
}

View File

@@ -20,7 +20,7 @@
* - indent_char - string (" ") * - indent_char - string (" ")
* - wrap_boundary - boolean (true) * - wrap_boundary - boolean (true)
* *
* @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat} * @link https://www.smarty.net/manual/en/language.function.textformat.php {textformat}
* (Smarty online manual) * (Smarty online manual)
* *
* @param array $params parameters * @param array $params parameters

View File

@@ -12,7 +12,7 @@
* Purpose: print out a counter value * Purpose: print out a counter value
* *
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @link http://www.smarty.net/manual/en/language.function.counter.php {counter} * @link https://www.smarty.net/manual/en/language.function.counter.php {counter}
* (Smarty online manual) * (Smarty online manual)
* *
* @param array $params parameters * @param array $params parameters

View File

@@ -28,7 +28,7 @@
* {cycle name=row values="one,two,three" reset=true} * {cycle name=row values="one,two,three" reset=true}
* {cycle name=row} * {cycle name=row}
* *
* @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle} * @link https://www.smarty.net/manual/en/language.function.cycle.php {cycle}
* (Smarty online manual) * (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Mark Priatel <mpriatel@rogers.com> * @author credit to Mark Priatel <mpriatel@rogers.com>

View File

@@ -11,7 +11,7 @@
* Name: fetch * Name: fetch
* Purpose: fetch file, web or ftp data and display results * Purpose: fetch file, web or ftp data and display results
* *
* @link http://www.smarty.net/manual/en/language.function.fetch.php {fetch} * @link https://www.smarty.net/manual/en/language.function.fetch.php {fetch}
* (Smarty online manual) * (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *

View File

@@ -29,7 +29,7 @@
* - assign (optional) - assign the output as an array to this variable * - assign (optional) - assign the output as an array to this variable
* - escape (optional) - escape the content (not value), defaults to true * - escape (optional) - escape the content (not value), defaults to true
* *
* @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} * @link https://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
* (Smarty online manual) * (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com> * @author Christopher Kvarme <christopher.kvarme@flashjab.com>
* @author credits to Monte Ohrt <monte at ohrt dot com> * @author credits to Monte Ohrt <monte at ohrt dot com>

View File

@@ -21,7 +21,7 @@
* - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT * - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT
* - path_prefix - prefix for path output (optional, default empty) * - path_prefix - prefix for path output (optional, default empty)
* *
* @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image} * @link https://www.smarty.net/manual/en/language.function.html.image.php {html_image}
* (Smarty online manual) * (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author credits to Duda <duda@big.hu> * @author credits to Duda <duda@big.hu>

View File

@@ -21,7 +21,7 @@
* - id (optional) - string default not set * - id (optional) - string default not set
* - class (optional) - string default not set * - class (optional) - string default not set
* *
* @link http://www.smarty.net/manual/en/language.function.html.options.php {html_image} * @link https://www.smarty.net/manual/en/language.function.html.options.php {html_image}
* (Smarty online manual) * (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de> * @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de>

View File

@@ -29,7 +29,7 @@
* {html_radios values=$ids name='box' separator='<br>' output=$names} * {html_radios values=$ids name='box' separator='<br>' output=$names}
* {html_radios values=$ids checked=$checked separator='<br>' output=$names} * {html_radios values=$ids checked=$checked separator='<br>' output=$names}
* *
* @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios} * @link https://www.smarty.net/manual/en/language.function.html.radios.php {html_radios}
* (Smarty online manual) * (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com> * @author Christopher Kvarme <christopher.kvarme@flashjab.com>
* @author credits to Monte Ohrt <monte at ohrt dot com> * @author credits to Monte Ohrt <monte at ohrt dot com>

View File

@@ -28,7 +28,7 @@
* - 2.0 complete rewrite for performance, * - 2.0 complete rewrite for performance,
* added attributes month_names, *_id * added attributes month_names, *_id
* *
* @link http://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date} * @link https://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date}
* (Smarty online manual) * (Smarty online manual)
* @version 2.0 * @version 2.0
* @author Andrei Zmievski * @author Andrei Zmievski

View File

@@ -11,7 +11,7 @@
* Name: html_select_time * Name: html_select_time
* Purpose: Prints the dropdowns for time selection * Purpose: Prints the dropdowns for time selection
* *
* @link http://www.smarty.net/manual/en/language.function.html.select.time.php {html_select_time} * @link https://www.smarty.net/manual/en/language.function.html.select.time.php {html_select_time}
* (Smarty online manual) * (Smarty online manual)
* @author Roberto Berto <roberto@berto.net> * @author Roberto Berto <roberto@berto.net>
* @author Monte Ohrt <monte AT ohrt DOT com> * @author Monte Ohrt <monte AT ohrt DOT com>

View File

@@ -38,7 +38,7 @@
* @author credit to Messju Mohr <messju at lammfellpuschen dot de> * @author credit to Messju Mohr <messju at lammfellpuschen dot de>
* @author credit to boots <boots dot smarty at yahoo dot com> * @author credit to boots <boots dot smarty at yahoo dot com>
* @version 1.1 * @version 1.1
* @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table} * @link https://www.smarty.net/manual/en/language.function.html.table.php {html_table}
* (Smarty online manual) * (Smarty online manual)
* *
* @param array $params parameters * @param array $params parameters

View File

@@ -36,7 +36,7 @@
* {mailto address="me@domain.com" cc="you@domain.com,they@domain.com"} * {mailto address="me@domain.com" cc="you@domain.com,they@domain.com"}
* {mailto address="me@domain.com" extra='class="mailto"'} * {mailto address="me@domain.com" extra='class="mailto"'}
* *
* @link http://www.smarty.net/manual/en/language.function.mailto.php {mailto} * @link https://www.smarty.net/manual/en/language.function.mailto.php {mailto}
* (Smarty online manual) * (Smarty online manual)
* @version 1.2 * @version 1.2
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
@@ -94,22 +94,19 @@ function smarty_function_mailto($params)
); );
return; return;
} }
// FIXME: (rodneyrehm) document.write() excues me what? 1998 has passed!
if ($encode === 'javascript') { if ($encode === 'javascript') {
$string = 'document.write(\'<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>\');'; $string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
$js_encode = ''; $js_encode = '';
for ($x = 0, $_length = strlen($string); $x < $_length; $x++) { for ($x = 0, $_length = strlen($string); $x < $_length; $x++) {
$js_encode .= '%' . bin2hex($string[ $x ]); $js_encode .= '%' . bin2hex($string[ $x ]);
} }
return '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>'; return '<script type="text/javascript">document.write(unescape(\'' . $js_encode . '\'))</script>';
} elseif ($encode === 'javascript_charcode') { } elseif ($encode === 'javascript_charcode') {
$string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>'; $string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
for ($x = 0, $y = strlen($string); $x < $y; $x++) { for ($x = 0, $_length = strlen($string); $x < $_length; $x++) {
$ord[] = ord($string[ $x ]); $ord[] = ord($string[ $x ]);
} }
$_ret = "<script type=\"text/javascript\" language=\"javascript\">\n" . "{document.write(String.fromCharCode(" . return '<script type="text/javascript">document.write(String.fromCharCode(' . implode(',', $ord) . '))</script>';
implode(',', $ord) . "))" . "}\n" . "</script>\n";
return $_ret;
} elseif ($encode === 'hex') { } elseif ($encode === 'hex') {
preg_match('!^(.*)(\?.*)$!', $address, $match); preg_match('!^(.*)(\?.*)$!', $address, $match);
if (!empty($match[ 2 ])) { if (!empty($match[ 2 ])) {

View File

@@ -12,7 +12,7 @@
* Name: math * Name: math
* Purpose: handle math computations in template * Purpose: handle math computations in template
* *
* @link http://www.smarty.net/manual/en/language.function.math.php {math} * @link https://www.smarty.net/manual/en/language.function.math.php {math}
* (Smarty online manual) * (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *
@@ -28,7 +28,12 @@ function smarty_function_math($params, $template)
'int' => true, 'int' => true,
'abs' => true, 'abs' => true,
'ceil' => true, 'ceil' => true,
'acos' => true,
'acosh' => true,
'cos' => true, 'cos' => true,
'cosh' => true,
'deg2rad' => true,
'rad2deg' => true,
'exp' => true, 'exp' => true,
'floor' => true, 'floor' => true,
'log' => true, 'log' => true,
@@ -39,27 +44,51 @@ function smarty_function_math($params, $template)
'pow' => true, 'pow' => true,
'rand' => true, 'rand' => true,
'round' => true, 'round' => true,
'asin' => true,
'asinh' => true,
'sin' => true, 'sin' => true,
'sinh' => true,
'sqrt' => true, 'sqrt' => true,
'srand' => true, 'srand' => true,
'tan' => true 'atan' => true,
'atanh' => true,
'tan' => true,
'tanh' => true
); );
// be sure equation parameter is present // be sure equation parameter is present
if (empty($params[ 'equation' ])) { if (empty($params[ 'equation' ])) {
trigger_error("math: missing equation parameter", E_USER_WARNING); trigger_error("math: missing equation parameter", E_USER_WARNING);
return; return;
} }
$equation = $params[ 'equation' ]; $equation = $params[ 'equation' ];
// Remove whitespaces
$equation = preg_replace('/\s+/', '', $equation);
// Adapted from https://www.php.net/manual/en/function.eval.php#107377
$number = '(?:\d+(?:[,.]\d+)?|pi|π)'; // What is a number
$functionsOrVars = '((?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*))';
$operators = '[,+\/*\^%-]'; // Allowed math operators
$regexp = '/^(('.$number.'|'.$functionsOrVars.'|('.$functionsOrVars.'\s*\((?1)+\)|\((?1)+\)))(?:'.$operators.'(?1))?)+$/';
if (!preg_match($regexp, $equation)) {
trigger_error("math: illegal characters", E_USER_WARNING);
return;
}
// make sure parenthesis are balanced // make sure parenthesis are balanced
if (substr_count($equation, '(') !== substr_count($equation, ')')) { if (substr_count($equation, '(') !== substr_count($equation, ')')) {
trigger_error("math: unbalanced parenthesis", E_USER_WARNING); trigger_error("math: unbalanced parenthesis", E_USER_WARNING);
return; return;
} }
// disallow backticks // disallow backticks
if (strpos($equation, '`') !== false) { if (strpos($equation, '`') !== false) {
trigger_error("math: backtick character not allowed in equation", E_USER_WARNING); trigger_error("math: backtick character not allowed in equation", E_USER_WARNING);
return; return;
} }
// also disallow dollar signs // also disallow dollar signs
if (strpos($equation, '$') !== false) { if (strpos($equation, '$') !== false) {
trigger_error("math: dollar signs not allowed in equation", E_USER_WARNING); trigger_error("math: dollar signs not allowed in equation", E_USER_WARNING);
@@ -96,6 +125,7 @@ function smarty_function_math($params, $template)
} }
$smarty_math_result = null; $smarty_math_result = null;
eval("\$smarty_math_result = " . $equation . ";"); eval("\$smarty_math_result = " . $equation . ";");
if (empty($params[ 'format' ])) { if (empty($params[ 'format' ])) {
if (empty($params[ 'assign' ])) { if (empty($params[ 'assign' ])) {
return $smarty_math_result; return $smarty_math_result;

View File

@@ -15,7 +15,7 @@
* - format: strftime format for output * - format: strftime format for output
* - default_date: default date if $string is empty * - default_date: default date if $string is empty
* *
* @link http://www.smarty.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual) * @link https://www.smarty.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *
* @param string $string input date string * @param string $string input date string
@@ -41,9 +41,9 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
} }
$is_loaded = true; $is_loaded = true;
} }
if ($string !== '' && $string !== '0000-00-00' && $string !== '0000-00-00 00:00:00') { if (!empty($string) && $string !== '0000-00-00' && $string !== '0000-00-00 00:00:00') {
$timestamp = smarty_make_timestamp($string); $timestamp = smarty_make_timestamp($string);
} elseif ($default_date !== '') { } elseif (!empty($default_date)) {
$timestamp = smarty_make_timestamp($default_date); $timestamp = smarty_make_timestamp($default_date);
} else { } else {
return; return;

View File

@@ -11,7 +11,7 @@
* Name: escape * Name: escape
* Purpose: escape string for output * Purpose: escape string for output
* *
* @link http://www.smarty.net/docs/en/language.modifier.escape * @link https://www.smarty.net/docs/en/language.modifier.escape
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *
* @param string $string input string * @param string $string input string
@@ -23,15 +23,15 @@
*/ */
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true) function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true)
{ {
static $_double_encode = null; static $_double_encode = true;
static $is_loaded_1 = false; static $is_loaded_1 = false;
static $is_loaded_2 = false; static $is_loaded_2 = false;
if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
}
if (!$char_set) { if (!$char_set) {
$char_set = Smarty::$_CHARSET; $char_set = Smarty::$_CHARSET;
} }
$string = (string)$string;
switch ($esc_type) { switch ($esc_type) {
case 'html': case 'html':
if ($_double_encode) { if ($_double_encode) {
@@ -184,7 +184,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
'"' => '\\"', '"' => '\\"',
"\r" => '\\r', "\r" => '\\r',
"\n" => '\\n', "\n" => '\\n',
'</' => '<\/' '</' => '<\/',
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
'<!--' => '<\!--',
'<s' => '<\s',
'<S' => '<\S'
) )
); );
case 'mail': case 'mail':
@@ -250,6 +254,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
} }
return $return; return $return;
default: default:
trigger_error("escape: unsupported type: $esc_type - returning unmodified string", E_USER_NOTICE);
return $string; return $string;
} }
} }

View File

@@ -11,7 +11,7 @@
* Name: mb_wordwrap * Name: mb_wordwrap
* Purpose: Wrap a string to a given number of characters * Purpose: Wrap a string to a given number of characters
* *
* @link http://php.net/manual/en/function.wordwrap.php for similarity * @link https://php.net/manual/en/function.wordwrap.php for similarity
* *
* @param string $str the string to wrap * @param string $str the string to wrap
* @param int $width the width of the output * @param int $width the width of the output

View File

@@ -11,7 +11,7 @@
* Name: regex_replace * Name: regex_replace
* Purpose: regular expression search/replace * Purpose: regular expression search/replace
* *
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php * @link https://www.smarty.net/manual/en/language.modifier.regex.replace.php
* regex_replace (Smarty online manual) * regex_replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *

View File

@@ -11,7 +11,7 @@
* Name: replace * Name: replace
* Purpose: simple search/replace * Purpose: simple search/replace
* *
* @link http://smarty.php.net/manual/en/language.modifier.replace.php replace (Smarty online manual) * @link https://www.smarty.net/manual/en/language.modifier.replace.php replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews * @author Uwe Tews
* *

View File

@@ -11,7 +11,7 @@
* Name: spacify * Name: spacify
* Purpose: add spaces between characters in a string * Purpose: add spaces between characters in a string
* *
* @link http://smarty.php.net/manual/en/language.modifier.spacify.php spacify (Smarty online manual) * @link https://www.smarty.net/manual/en/language.modifier.spacify.php spacify (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 $string input string

View File

@@ -13,7 +13,7 @@
* optionally splitting in the middle of a word, and * optionally splitting in the middle of a word, and
* appending the $etc string or inserting $etc into the middle. * appending the $etc string or inserting $etc into the middle.
* *
* @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual) * @link https://www.smarty.net/manual/en/language.modifier.truncate.php truncate (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 $string input string
@@ -42,8 +42,8 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if (!$middle) { if (!$middle) {
return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc; return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
} }
return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . return mb_substr($string, 0, intval($length / 2), Smarty::$_CHARSET) . $etc .
mb_substr($string, -$length / 2, $length, Smarty::$_CHARSET); mb_substr($string, -intval($length / 2), $length, Smarty::$_CHARSET);
} }
return $string; return $string;
} }
@@ -56,7 +56,7 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if (!$middle) { if (!$middle) {
return substr($string, 0, $length) . $etc; return substr($string, 0, $length) . $etc;
} }
return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2); return substr($string, 0, intval($length / 2)) . $etc . substr($string, -intval($length / 2));
} }
return $string; return $string;
} }

View File

@@ -14,7 +14,7 @@
* Input: string to catenate * Input: string to catenate
* Example: {$var|cat:"foo"} * Example: {$var|cat:"foo"}
* *
* @link http://smarty.php.net/manual/en/language.modifier.cat.php cat * @link https://www.smarty.net/manual/en/language.modifier.cat.php cat
* (Smarty online manual) * (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* *

View File

@@ -11,7 +11,7 @@
* Name: count_characters * Name: count_characters
* Purpose: count the number of characters in a text * Purpose: count the number of characters in a text
* *
* @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online * @link https://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online
* manual) * manual)
* @author Uwe Tews * @author Uwe Tews
* *

View File

@@ -11,7 +11,7 @@
* Name: count_paragraphs * Name: count_paragraphs
* Purpose: count the number of paragraphs in a text * Purpose: count the number of paragraphs in a text
* *
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php * @link https://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_paragraphs (Smarty online manual) * count_paragraphs (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* *

View File

@@ -11,7 +11,7 @@
* Name: count_sentences * Name: count_sentences
* Purpose: count the number of sentences in a text * Purpose: count the number of sentences in a text
* *
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php * @link https://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_sentences (Smarty online manual) * count_sentences (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* *

View File

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

View File

@@ -11,7 +11,7 @@
* Name: default * Name: default
* Purpose: designate default value for empty variables * Purpose: designate default value for empty variables
* *
* @link http://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual) * @link https://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* *
* @param array $params parameters * @param array $params parameters
@@ -26,7 +26,7 @@ function smarty_modifiercompiler_default($params)
} }
array_shift($params); array_shift($params);
foreach ($params as $param) { foreach ($params as $param) {
$output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)'; $output = '(($tmp = ' . $output . ' ?? null)===null||$tmp===\'\' ? ' . $param . ' ?? null : $tmp)';
} }
return $output; return $output;
} }

View File

@@ -11,7 +11,7 @@
* Name: escape * Name: escape
* Purpose: escape string for output * Purpose: escape string for output
* *
* @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual) * @link https://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
* @author Rodney Rehm * @author Rodney Rehm
* *
* @param array $params parameters * @param array $params parameters
@@ -22,7 +22,7 @@
*/ */
function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompilerBase $compiler) function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
static $_double_encode = null; static $_double_encode = true;
static $is_loaded = false; static $is_loaded = false;
$compiler->template->_checkPlugins( $compiler->template->_checkPlugins(
array( array(
@@ -32,9 +32,6 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
) )
) )
); );
if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
}
try { try {
$esc_type = smarty_literal_compiler_param($params, 1, 'html'); $esc_type = smarty_literal_compiler_param($params, 1, 'html');
$char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET); $char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET);
@@ -45,10 +42,10 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
switch ($esc_type) { switch ($esc_type) {
case 'html': case 'html':
if ($_double_encode) { if ($_double_encode) {
return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' . return 'htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
var_export($double_encode, true) . ')'; var_export($double_encode, true) . ')';
} elseif ($double_encode) { } elseif ($double_encode) {
return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')'; return 'htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
} else { } else {
// fall back to modifier.escape.php // fall back to modifier.escape.php
} }
@@ -57,12 +54,12 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if ($_double_encode) { if ($_double_encode) {
// php >=5.2.3 - go native // php >=5.2.3 - go native
return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . return 'mb_convert_encoding(htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' .
var_export($char_set, true) . ', ' . var_export($double_encode, true) . var_export($char_set, true) . ', ' . var_export($double_encode, true) .
'), "HTML-ENTITIES", ' . var_export($char_set, true) . ')'; '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
} elseif ($double_encode) { } elseif ($double_encode) {
// php <5.2.3 - only handle double encoding // php <5.2.3 - only handle double encoding
return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . return 'mb_convert_encoding(htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' .
var_export($char_set, true) . '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')'; var_export($char_set, true) . '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
} else { } else {
// fall back to modifier.escape.php // fall back to modifier.escape.php
@@ -71,27 +68,28 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
// no MBString fallback // no MBString fallback
if ($_double_encode) { if ($_double_encode) {
// php >=5.2.3 - go native // php >=5.2.3 - go native
return 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' . return 'htmlentities((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
var_export($double_encode, true) . ')'; var_export($double_encode, true) . ')';
} elseif ($double_encode) { } elseif ($double_encode) {
// php <5.2.3 - only handle double encoding // php <5.2.3 - only handle double encoding
return 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')'; return 'htmlentities((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
} else { } else {
// fall back to modifier.escape.php // fall back to modifier.escape.php
} }
// no break // no break
case 'url': case 'url':
return 'rawurlencode(' . $params[ 0 ] . ')'; return 'rawurlencode((string)' . $params[ 0 ] . ')';
case 'urlpathinfo': case 'urlpathinfo':
return 'str_replace("%2F", "/", rawurlencode(' . $params[ 0 ] . '))'; return 'str_replace("%2F", "/", rawurlencode((string)' . $params[ 0 ] . '))';
case 'quotes': case 'quotes':
// escape unescaped single quotes // escape unescaped single quotes
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[ 0 ] . ')'; return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'", (string)' . $params[ 0 ] . ')';
case 'javascript': case 'javascript':
// escape quotes and backslashes, newlines, etc. // escape quotes and backslashes, newlines, etc.
return 'strtr(' . // see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
return 'strtr((string)' .
$params[ 0 ] . $params[ 0 ] .
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))'; ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S" ))';
} }
} catch (SmartyException $e) { } catch (SmartyException $e) {
// pass through to regular plugin fallback // pass through to regular plugin fallback

View File

@@ -11,7 +11,7 @@
* Name: indent * Name: indent
* Purpose: indent lines of text * Purpose: indent lines of text
* *
* @link http://www.smarty.net/manual/en/language.modifier.indent.php indent (Smarty online manual) * @link https://www.smarty.net/manual/en/language.modifier.indent.php indent (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* *
* @param array $params parameters * @param array $params parameters

View File

@@ -11,7 +11,7 @@
* Name: lower * Name: lower
* Purpose: convert string to lowercase * Purpose: convert string to lowercase
* *
* @link http://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual) * @link https://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews * @author Uwe Tews
* *

View File

@@ -11,7 +11,7 @@
* Name: string_format * Name: string_format
* Purpose: format strings via sprintf * Purpose: format strings via sprintf
* *
* @link http://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual) * @link https://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* *
* @param array $params parameters * @param array $params parameters

View File

@@ -14,7 +14,7 @@
* Example: {$var|strip} {$var|strip:"&nbsp;"} * Example: {$var|strip} {$var|strip:"&nbsp;"}
* Date: September 25th, 2002 * Date: September 25th, 2002
* *
* @link http://www.smarty.net/manual/en/language.modifier.strip.php strip (Smarty online manual) * @link https://www.smarty.net/manual/en/language.modifier.strip.php strip (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* *
* @param array $params parameters * @param array $params parameters

View File

@@ -11,7 +11,7 @@
* Name: strip_tags * Name: strip_tags
* Purpose: strip html tags from text * Purpose: strip html tags from text
* *
* @link http://www.smarty.net/docs/en/language.modifier.strip.tags.tpl strip_tags (Smarty online manual) * @link https://www.smarty.net/docs/en/language.modifier.strip.tags.tpl strip_tags (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* *
* @param array $params parameters * @param array $params parameters

View File

@@ -11,7 +11,7 @@
* Name: lower * Name: lower
* Purpose: convert string to uppercase * Purpose: convert string to uppercase
* *
* @link http://smarty.php.net/manual/en/language.modifier.upper.php lower (Smarty online manual) * @link https://www.smarty.net/manual/en/language.modifier.upper.php lower (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* *
* @param array $params parameters * @param array $params parameters

View File

@@ -11,7 +11,7 @@
* Name: wordwrap * Name: wordwrap
* Purpose: wrap a string of text at a given length * Purpose: wrap a string of text at a given length
* *
* @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual) * @link https://www.smarty.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* *
* @param array $params parameters * @param array $params parameters

View File

@@ -41,7 +41,7 @@ function smarty_outputfilter_trimwhitespace($source)
} }
} }
// Strip all HTML-Comments // Strip all HTML-Comments
// yes, even the ones in <script> - see http://stackoverflow.com/a/808850/515124 // yes, even the ones in <script> - see https://stackoverflow.com/a/808850/515124
$source = preg_replace('#<!--.*?-->#ms', '', $source); $source = preg_replace('#<!--.*?-->#ms', '', $source);
// capture html elements not to be messed with // capture html elements not to be messed with
$_offset = 0; $_offset = 0;

View File

@@ -20,13 +20,7 @@
function smarty_function_escape_special_chars($string) function smarty_function_escape_special_chars($string)
{ {
if (!is_array($string)) { if (!is_array($string)) {
if (version_compare(PHP_VERSION, '5.2.3', '>=')) {
$string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false); $string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false);
} else {
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string);
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
}
} }
return $string; return $string;
} }

View File

@@ -44,7 +44,7 @@ if (!function_exists('smarty_mb_str_replace')) {
} }
} }
} else { } else {
$parts = mb_split(preg_quote($search), $subject); $parts = mb_split(preg_quote($search), $subject) ?: array();
$count = count($parts) - 1; $count = count($parts) - 1;
$subject = implode($replace, $parts); $subject = implode($replace, $parts);
} }

View File

@@ -196,12 +196,8 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*/ */
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached) public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
{ {
if (version_compare(PHP_VERSION, '5.3.0', '>=')) { clearstatcache(true, $cached->lock_id ?? '');
clearstatcache(true, $cached->lock_id); if (null !== $cached->lock_id && is_file($cached->lock_id)) {
} else {
clearstatcache();
}
if (is_file($cached->lock_id)) {
$t = filemtime($cached->lock_id); $t = filemtime($cached->lock_id);
return $t && (time() - $t < $smarty->locking_timeout); return $t && (time() - $t < $smarty->locking_timeout);
} else { } else {

View File

@@ -83,7 +83,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
if (isset($parameter[ 'smarty_internal_index' ])) { if (isset($parameter[ 'smarty_internal_index' ])) {
$output = $output =
"<?php \$_tmp_array = isset(\$_smarty_tpl->tpl_vars[{$_var}]) ? \$_smarty_tpl->tpl_vars[{$_var}]->value : array();\n"; "<?php \$_tmp_array = isset(\$_smarty_tpl->tpl_vars[{$_var}]) ? \$_smarty_tpl->tpl_vars[{$_var}]->value : array();\n";
$output .= "if (!is_array(\$_tmp_array) || \$_tmp_array instanceof ArrayAccess) {\n"; $output .= "if (!(is_array(\$_tmp_array) || \$_tmp_array instanceof ArrayAccess)) {\n";
$output .= "settype(\$_tmp_array, 'array');\n"; $output .= "settype(\$_tmp_array, 'array');\n";
$output .= "}\n"; $output .= "}\n";
$output .= "\$_tmp_array{$parameter['smarty_internal_index']} = {$_attr['value']};\n"; $output .= "\$_tmp_array{$parameter['smarty_internal_index']} = {$_attr['value']};\n";

View File

@@ -125,7 +125,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
// setup buffer for template function code // setup buffer for template function code
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$output = "<?php\n"; $output = "<?php\n";
$output .= "/* {block {$_name}} */\n"; $output .= $compiler->cStyleComment(" {block {$_name}} ") . "\n";
$output .= "class {$_className} extends Smarty_Internal_Block\n"; $output .= "class {$_className} extends Smarty_Internal_Block\n";
$output .= "{\n"; $output .= "{\n";
foreach ($_block as $property => $value) { foreach ($_block as $property => $value) {
@@ -155,7 +155,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
} }
$output .= "}\n"; $output .= "}\n";
$output .= "}\n"; $output .= "}\n";
$output .= "/* {/block {$_name}} */\n\n"; $output .= $compiler->cStyleComment(" {/block {$_name}} ") . "\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree( $compiler->parser->current_buffer->append_subtree(
$compiler->parser, $compiler->parser,

View File

@@ -18,7 +18,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
{ {
/** /**
* Compiles code for the {for} tag * Compiles code for the {for} tag
* Smarty 3 does implement two different syntax's: * Smarty supports two different syntax's:
* - {for $var in $array} * - {for $var in $array}
* For looping over arrays or iterators * For looping over arrays or iterators
* - {for $x=0; $x<$y; $x++} * - {for $x=0; $x<$y; $x++}

View File

@@ -219,8 +219,9 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
if (isset($itemAttr[ 'index' ])) { if (isset($itemAttr[ 'index' ])) {
$output .= "{$itemVar}->index = -1;\n"; $output .= "{$itemVar}->index = -1;\n";
} }
$output .= "if (\$_from !== null) {\n"; $output .= "{$itemVar}->do_else = true;\n";
$output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n"; $output .= "if (\$_from !== null) foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
$output .= "{$itemVar}->do_else = false;\n";
if (isset($attributes[ 'key' ]) && isset($itemAttr[ 'key' ])) { if (isset($attributes[ 'key' ]) && isset($itemAttr[ 'key' ])) {
$output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n"; $output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n";
} }
@@ -296,7 +297,7 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
if ($restore === 2) { if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n"; $output .= "{$itemVar} = {$local}saved;\n";
} }
$output .= "}\n} else {\n?>"; $output .= "}\nif ({$itemVar}->do_else) {\n?>";
return $output; return $output;
} }
} }
@@ -332,9 +333,6 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
if ($restore === 2) { if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n"; $output .= "{$itemVar} = {$local}saved;\n";
} }
if ($restore > 0) {
$output .= "}\n";
}
$output .= "}\n"; $output .= "}\n";
/* @var Smarty_Internal_Compile_Foreach $foreachCompiler */ /* @var Smarty_Internal_Compile_Foreach $foreachCompiler */
$foreachCompiler = $compiler->getTagCompiler('foreach'); $foreachCompiler = $compiler->getTagCompiler('foreach');

View File

@@ -58,6 +58,11 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
} }
unset($_attr[ 'nocache' ]); unset($_attr[ 'nocache' ]);
$_name = trim($_attr[ 'name' ], '\'"'); $_name = trim($_attr[ 'name' ], '\'"');
if (!preg_match('/^[a-zA-Z0-9_\x80-\xff]+$/', $_name)) {
$compiler->trigger_template_error("Function name contains invalid characters: {$_name}", null, true);
}
$compiler->parent_compiler->tpl_function[ $_name ] = array(); $compiler->parent_compiler->tpl_function[ $_name ] = array();
$save = array( $save = array(
$_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code, $_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
@@ -129,7 +134,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
if ($compiler->template->compiled->has_nocache_code) { if ($compiler->template->compiled->has_nocache_code) {
$compiler->parent_compiler->tpl_function[ $_name ][ 'call_name_caching' ] = $_funcNameCaching; $compiler->parent_compiler->tpl_function[ $_name ][ 'call_name_caching' ] = $_funcNameCaching;
$output = "<?php\n"; $output = "<?php\n";
$output .= "/* {$_funcNameCaching} */\n"; $output .= $compiler->cStyleComment(" {$_funcNameCaching} ") . "\n";
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n"; $output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
$output .= "function {$_funcNameCaching} (Smarty_Internal_Template \$_smarty_tpl,\$params) {\n"; $output .= "function {$_funcNameCaching} (Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
$output .= "ob_start();\n"; $output .= "ob_start();\n";
@@ -152,9 +157,9 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php "; $output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n"; $output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>"; $output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>";
$output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash, ob_get_clean());\n"; $output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash ?? '', ob_get_clean());\n";
$output .= "}\n}\n"; $output .= "}\n}\n";
$output .= "/*/ {$_funcName}_nocache */\n\n"; $output .= $compiler->cStyleComment("/ {$_funcName}_nocache ") . "\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree( $compiler->parser->current_buffer->append_subtree(
$compiler->parser, $compiler->parser,
@@ -174,7 +179,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
} }
$compiler->parent_compiler->tpl_function[ $_name ][ 'call_name' ] = $_funcName; $compiler->parent_compiler->tpl_function[ $_name ][ 'call_name' ] = $_funcName;
$output = "<?php\n"; $output = "<?php\n";
$output .= "/* {$_funcName} */\n"; $output .= $compiler->cStyleComment(" {$_funcName} ") . "\n";
$output .= "if (!function_exists('{$_funcName}')) {\n"; $output .= "if (!function_exists('{$_funcName}')) {\n";
$output .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\n"; $output .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
$output .= $_paramsCode; $output .= $_paramsCode;
@@ -191,7 +196,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
); );
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php\n}}\n"; $output = "<?php\n}}\n";
$output .= "/*/ {$_funcName} */\n\n"; $output .= $compiler->cStyleComment("/ {$_funcName} ") . "\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree( $compiler->parser->current_buffer->append_subtree(
$compiler->parser, $compiler->parser,

View File

@@ -318,14 +318,14 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} }
// get compiled code // get compiled code
$compiled_code = "<?php\n\n"; $compiled_code = "<?php\n\n";
$compiled_code .= "/* Start inline template \"{$sourceInfo}\" =============================*/\n"; $compiled_code .= $compiler->cStyleComment(" Start inline template \"{$sourceInfo}\" =============================") . "\n";
$compiled_code .= "function {$tpl->compiled->unifunc} (Smarty_Internal_Template \$_smarty_tpl) {\n"; $compiled_code .= "function {$tpl->compiled->unifunc} (Smarty_Internal_Template \$_smarty_tpl) {\n";
$compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler); $compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler);
$compiled_code .= "<?php\n"; $compiled_code .= "<?php\n";
$compiled_code .= "}\n?>\n"; $compiled_code .= "}\n?>\n";
$compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode); $compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode);
$compiled_code .= "<?php\n\n"; $compiled_code .= "<?php\n\n";
$compiled_code .= "/* End inline template \"{$sourceInfo}\" =============================*/\n"; $compiled_code .= $compiler->cStyleComment(" End inline template \"{$sourceInfo}\" =============================") . "\n";
$compiled_code .= '?>'; $compiled_code .= '?>';
unset($tpl->compiler); unset($tpl->compiler);
if ($tpl->compiled->has_nocache_code) { if ($tpl->compiled->has_nocache_code) {

View File

@@ -1,110 +0,0 @@
<?php
/**
* Smarty Internal Plugin Compile Include PHP
* Compiles the {include_php} tag
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Insert Class
*
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
{
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('file');
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('file');
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('once', 'assign');
/**
* Compiles code for the {include_php} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
if (!($compiler->smarty instanceof SmartyBC)) {
throw new SmartyException("{include_php} is deprecated, use SmartyBC class to enable");
}
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
/**
*
*
* @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $compiler->template;
$_filepath = false;
$_file = null;
eval('$_file = @' . $_attr[ 'file' ] . ';');
if (!isset($compiler->smarty->security_policy) && file_exists($_file)) {
$_filepath = $compiler->smarty->_realpath($_file, true);
} else {
if (isset($compiler->smarty->security_policy)) {
$_dir = $compiler->smarty->security_policy->trusted_dir;
} else {
$_dir = $compiler->smarty->trusted_dir;
}
if (!empty($_dir)) {
foreach ((array)$_dir as $_script_dir) {
$_path = $compiler->smarty->_realpath($_script_dir . DIRECTORY_SEPARATOR . $_file, true);
if (file_exists($_path)) {
$_filepath = $_path;
break;
}
}
}
}
if ($_filepath === false) {
$compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", null, true);
}
if (isset($compiler->smarty->security_policy)) {
$compiler->smarty->security_policy->isTrustedPHPDir($_filepath);
}
if (isset($_attr[ 'assign' ])) {
// output will be stored in a smarty variable instead of being displayed
$_assign = $_attr[ 'assign' ];
}
$_once = '_once';
if (isset($_attr[ 'once' ])) {
if ($_attr[ 'once' ] === 'false') {
$_once = '';
}
}
if (isset($_assign)) {
return "<?php ob_start();\ninclude{$_once} ('{$_filepath}');\n\$_smarty_tpl->assign({$_assign},ob_get_clean());\n?>";
} else {
return "<?php include{$_once} ('{$_filepath}');?>\n";
}
}
}

View File

@@ -89,11 +89,11 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
if (isset($compiler->smarty->security_policy)) { if (isset($compiler->smarty->security_policy)) {
$_dir = $compiler->smarty->security_policy->trusted_dir; $_dir = $compiler->smarty->security_policy->trusted_dir;
} else { } else {
$_dir = $compiler->smarty instanceof SmartyBC ? $compiler->smarty->trusted_dir : null; $_dir = null;
} }
if (!empty($_dir)) { if (!empty($_dir)) {
foreach ((array)$_dir as $_script_dir) { foreach ((array)$_dir as $_script_dir) {
$_script_dir = rtrim($_script_dir, '/\\') . DIRECTORY_SEPARATOR; $_script_dir = rtrim($_script_dir ?? '', '/\\') . DIRECTORY_SEPARATOR;
if (file_exists($_script_dir . $_script)) { if (file_exists($_script_dir . $_script)) {
$_filepath = $_script_dir . $_script; $_filepath = $_script_dir . $_script;
break; break;
@@ -151,6 +151,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>"; $_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>";
} }
} }
$compiler->template->compiled->has_nocache_code = true;
return $_output; return $_output;
} }
} }

View File

@@ -1,253 +0,0 @@
<?php
/**
* Smarty Internal Plugin Compile PHP Expression
* Compiles any tag which will output an expression or variable
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile PHP Expression Class
*
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
{
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('code', 'type');
/**
* Compiles code for generating output from any expression
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string
* @throws \SmartyException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$compiler->has_code = false;
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
)
)
);
return '';
}
if ($_attr[ 'type' ] !== 'tag') {
if ($compiler->php_handling === Smarty::PHP_REMOVE) {
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)
);
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
)
)
);
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->has_code = true;
return $_attr[ 'code' ];
} else {
$compiler->trigger_template_error('Illegal $smarty->php_handling value', null, true);
}
} 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
);
}
$ldel = preg_quote($compiler->smarty->left_delimiter, '#');
$rdel = preg_quote($compiler->smarty->right_delimiter, '#');
preg_match("#^({$ldel}php\\s*)((.)*?)({$rdel})#", $_attr[ 'code' ], $match);
if (!empty($match[ 2 ])) {
if ('nocache' === trim($match[ 2 ])) {
$compiler->tag_nocache = true;
} else {
$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' ]
);
}
}
/**
* Lexer code for PHP tags
*
* This code has been moved from lexer here fo easier debugging and maintenance
*
* @param Smarty_Internal_Templatelexer $lex
*
* @throws \SmartyCompilerException
*/
public function parsePhp(Smarty_Internal_Templatelexer $lex)
{
$lex->token = Smarty_Internal_Templateparser::TP_PHP;
$close = 0;
$lex->taglineno = $lex->line;
$closeTag = '?>';
if (strpos($lex->value, '<?xml') === 0) {
$lex->is_xml = true;
$lex->phpType = 'xml';
return;
} elseif (strpos($lex->value, '<?') === 0) {
$lex->phpType = 'php';
} elseif (strpos($lex->value, '<%') === 0) {
$lex->phpType = 'asp';
$closeTag = '%>';
} elseif (strpos($lex->value, '%>') === 0) {
$lex->phpType = 'unmatched';
} elseif (strpos($lex->value, '?>') === 0) {
if ($lex->is_xml) {
$lex->is_xml = false;
$lex->phpType = 'xml';
return;
}
$lex->phpType = 'unmatched';
} elseif (strpos($lex->value, '<s') === 0) {
$lex->phpType = 'script';
$closeTag = '</script>';
} elseif (strpos($lex->value, $lex->smarty->left_delimiter) === 0) {
if ($lex->isAutoLiteral()) {
$lex->token = Smarty_Internal_Templateparser::TP_TEXT;
return;
}
$closeTag = "{$lex->smarty->left_delimiter}/php{$lex->smarty->right_delimiter}";
if ($lex->value === $closeTag) {
$lex->compiler->trigger_template_error("unexpected closing tag '{$closeTag}'");
}
$lex->phpType = 'tag';
}
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)
) {
return;
}
$start = $lex->counter + strlen($lex->value);
$body = true;
if (preg_match('~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $start)) {
$close = $match[ 0 ][ 1 ];
} else {
$lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'");
}
while ($body) {
if (preg_match(
'~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~',
$lex->data,
$match,
PREG_OFFSET_CAPTURE,
$start
)
) {
$value = $match[ 0 ][ 0 ];
$from = $pos = $match[ 0 ][ 1 ];
if ($pos > $close) {
$body = false;
} else {
$start = $pos + strlen($value);
$phpCommentStart = $value === '/*';
if ($phpCommentStart) {
$phpCommentEnd = preg_match('~([*][/])~', $lex->data, $match, PREG_OFFSET_CAPTURE, $start);
if ($phpCommentEnd) {
$pos2 = $match[ 0 ][ 1 ];
$start = $pos2 + strlen($match[ 0 ][ 0 ]);
}
}
while ($close > $pos && $close < $start) {
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 {
$lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'");
}
}
if ($phpCommentStart && (!$phpCommentEnd || $pos2 > $close)) {
$lex->taglineno = $lex->line + substr_count(substr($lex->data, $lex->counter, $start), "\n");
$lex->compiler->trigger_template_error("missing PHP comment closing tag '*/'");
}
}
} else {
$body = false;
}
}
$lex->value = substr($lex->data, $lex->counter, $close + strlen($closeTag) - $lex->counter);
}
/*
* Call back function for $php_handling = PHP_QUOTE
*
*/
/**
* @param $match
*
* @return string
*/
private function quote($match)
{
return htmlspecialchars($match[ 0 ], ENT_QUOTES);
}
}

View File

@@ -81,6 +81,10 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
case 'template': case 'template':
return 'basename($_smarty_tpl->source->filepath)'; return 'basename($_smarty_tpl->source->filepath)';
case 'template_object': case 'template_object':
if (isset($compiler->smarty->security_policy)) {
$compiler->trigger_template_error("(secure mode) template_object not permitted");
break;
}
return '$_smarty_tpl'; return '$_smarty_tpl';
case 'current_dir': case 'current_dir':
return 'dirname($_smarty_tpl->source->filepath)'; return 'dirname($_smarty_tpl->source->filepath)';
@@ -94,9 +98,9 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
break; break;
} }
if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) { if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) {
return "@constant('{$_index[1]}')"; return "(defined('{$_index[1]}') ? constant('{$_index[1]}') : null)";
} else { } else {
return "@constant({$_index[1]})"; return "(defined({$_index[1]}) ? constant({$_index[1]}) : null)";
} }
// no break // no break
case 'config': case 'config':

View File

@@ -115,7 +115,7 @@ class Smarty_Internal_Config_File_Compiler
$this->smarty->_debug->start_compile($this->template); $this->smarty->_debug->start_compile($this->template);
} }
// init the lexer/parser to compile the config file // init the lexer/parser to compile the config file
/* @var Smarty_Internal_ConfigFileLexer $this ->lex */ /* @var Smarty_Internal_ConfigFileLexer $this->lex */
$this->lex = new $this->lexer_class( $this->lex = new $this->lexer_class(
str_replace( str_replace(
array( array(
@@ -127,7 +127,7 @@ class Smarty_Internal_Config_File_Compiler
) . "\n", ) . "\n",
$this $this
); );
/* @var Smarty_Internal_ConfigFileParser $this ->parser */ /* @var Smarty_Internal_ConfigFileParser $this->parser */
$this->parser = new $this->parser_class($this->lex, $this); $this->parser = new $this->parser_class($this->lex, $this);
if (function_exists('mb_internal_encoding') if (function_exists('mb_internal_encoding')
&& function_exists('ini_get') && function_exists('ini_get')
@@ -157,10 +157,12 @@ class Smarty_Internal_Config_File_Compiler
$this->smarty->_debug->end_compile($this->template); $this->smarty->_debug->end_compile($this->template);
} }
// template header code // template header code
$template_header = $template_header = sprintf(
"<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "<?php /* Smarty version %s, created on %s\n compiled from '%s' */ ?>\n",
"\n"; Smarty::SMARTY_VERSION,
$template_header .= " compiled from '{$this->template->source->filepath}' */ ?>\n"; date("Y-m-d H:i:s"),
str_replace('*/', '* /' , $this->template->source->filepath)
);
$code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' . $code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
var_export($this->config_data, true) . '); ?>'; var_export($this->config_data, true) . '); ?>';
return $template_header . $this->template->smarty->ext->_codeFrame->create($this->template, $code); return $template_header . $this->template->smarty->ext->_codeFrame->create($this->template, $code);

View File

@@ -121,7 +121,7 @@ abstract class Smarty_Internal_Data
* appends values to template variables * appends values to template variables
* *
* @api Smarty::append() * @api Smarty::append()
* @link http://www.smarty.net/docs/en/api.append.tpl * @link https://www.smarty.net/docs/en/api.append.tpl
* *
* @param array|string $tpl_var the template variable name(s) * @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to append * @param mixed $value the value to append
@@ -182,7 +182,7 @@ abstract class Smarty_Internal_Data
* Returns a single or all template variables * Returns a single or all template variables
* *
* @api Smarty::getTemplateVars() * @api Smarty::getTemplateVars()
* @link http://www.smarty.net/docs/en/api.get.template.vars.tpl * @link https://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 \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
@@ -195,26 +195,6 @@ abstract class Smarty_Internal_Data
return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents); return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents);
} }
/**
* 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
*
* @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
) {
return $this->ext->getTemplateVars->_getVariable($this, $variable, $_ptr, $searchParents, $error_enable);
}
/** /**
* Follow the parent chain an merge template and config variables * Follow the parent chain an merge template and config variables
* *

View File

@@ -1,36 +1,37 @@
<?php <?php
/** /**
* Smarty error handler * Smarty error handler to fix new error levels in PHP8 for backwards compatibility
* *
* @package Smarty * @package Smarty
* @subpackage PluginsInternal * @subpackage PluginsInternal
* @author Uwe Tews * @author Simon Wisselink
* *
* @deprecated
Smarty does no longer use @filemtime()
*/ */
class Smarty_Internal_ErrorHandler class Smarty_Internal_ErrorHandler
{ {
/**
* contains directories outside of SMARTY_DIR that are to be muted by muteExpectedErrors()
*/
public static $mutedDirectories = array();
/** /**
* error handler returned by set_error_handler() in self::muteExpectedErrors() * Allows {$foo} where foo is unset.
* @var bool
*/ */
private static $previousErrorHandler = null; public $allowUndefinedVars = true;
/** /**
* Enable error handler to mute expected messages * Allows {$foo.bar} where bar is unset and {$foo.bar1.bar2} where either bar1 or bar2 is unset.
* * @var bool
*/ */
public static function muteExpectedErrors() public $allowUndefinedArrayKeys = true;
{
private $previousErrorHandler = null;
/**
* Enable error handler to intercept errors
*/
public function activate() {
/* /*
error muting is done because some people implemented custom error_handlers using Error muting is done because some people implemented custom error_handlers using
http://php.net/set_error_handler and for some reason did not understand the following paragraph: https://php.net/set_error_handler and for some reason did not understand the following paragraph:
It is important to remember that the standard PHP error handler is completely bypassed for the It is important to remember that the standard PHP error handler is completely bypassed for the
error types specified by error_types unless the callback function returns FALSE. error types specified by error_types unless the callback function returns FALSE.
@@ -38,24 +39,22 @@ class Smarty_Internal_ErrorHandler
however you are still able to read the current value of error_reporting and act appropriately. however you are still able to read the current value of error_reporting and act appropriately.
Of particular note is that this value will be 0 if the statement that caused the error was Of particular note is that this value will be 0 if the statement that caused the error was
prepended by the @ error-control operator. prepended by the @ error-control operator.
Smarty deliberately uses @filemtime() over file_exists() and filemtime() in some places. Reasons include
- @filemtime() is almost twice as fast as using an additional file_exists()
- between file_exists() and filemtime() a possible race condition is opened,
which does not exist using the simple @filemtime() approach.
*/ */
$error_handler = array('Smarty_Internal_ErrorHandler', 'mutingErrorHandler'); $this->previousErrorHandler = set_error_handler([$this, 'handleError']);
$previous = set_error_handler($error_handler);
// avoid dead loops
if ($previous !== $error_handler) {
self::$previousErrorHandler = $previous;
} }
/**
* Disable error handler
*/
public function deactivate() {
restore_error_handler();
$this->previousErrorHandler = null;
} }
/** /**
* Error Handler to mute expected messages * Error Handler to mute expected messages
* *
* @link http://php.net/set_error_handler * @link https://php.net/set_error_handler
* *
* @param integer $errno Error level * @param integer $errno Error level
* @param $errstr * @param $errstr
@@ -65,49 +64,21 @@ class Smarty_Internal_ErrorHandler
* *
* @return bool * @return bool
*/ */
public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) public function handleError($errno, $errstr, $errfile, $errline, $errcontext = [])
{ {
$_is_muted_directory = false; if ($this->allowUndefinedVars && $errstr == 'Attempt to read property "value" on null') {
// add the SMARTY_DIR to the list of muted directories return; // suppresses this error
if (!isset(self::$mutedDirectories[ SMARTY_DIR ])) {
$smarty_dir = realpath(SMARTY_DIR);
if ($smarty_dir !== false) {
self::$mutedDirectories[ SMARTY_DIR ] =
array('file' => $smarty_dir, 'length' => strlen($smarty_dir),);
}
}
// walk the muted directories and test against $errfile
foreach (self::$mutedDirectories as $key => &$dir) {
if (!$dir) {
// resolve directory and length for speedy comparisons
$file = realpath($key);
if ($file === false) {
// this directory does not exist, remove and skip it
unset(self::$mutedDirectories[ $key ]);
continue;
}
$dir = array('file' => $file, 'length' => strlen($file),);
}
if (!strncmp($errfile, $dir[ 'file' ], $dir[ 'length' ])) {
$_is_muted_directory = true;
break;
}
}
// pass to next error handler if this error did not occur inside SMARTY_DIR
// or the error was within smarty but masked to be ignored
if (!$_is_muted_directory || ($errno && $errno & error_reporting())) {
if (self::$previousErrorHandler) {
return call_user_func(
self::$previousErrorHandler,
$errno,
$errstr,
$errfile,
$errline,
$errcontext
);
} else {
return false;
} }
if ($this->allowUndefinedArrayKeys && preg_match(
'/^(Undefined array key|Trying to access array offset on value of type null)/',
$errstr
)) {
return; // suppresses this error
} }
// pass all other errors through to the previous error handler or to the default PHP error handler
return $this->previousErrorHandler ?
call_user_func($this->previousErrorHandler, $errno, $errstr, $errfile, $errline, $errcontext) : false;
} }
} }

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_Append
* appends values to template variables * appends values to template variables
* *
* @api Smarty::append() * @api Smarty::append()
* @link http://www.smarty.net/docs/en/api.append.tpl * @link https://www.smarty.net/docs/en/api.append.tpl
* *
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param array|string $tpl_var the template variable name(s) * @param array|string $tpl_var the template variable name(s)

View File

@@ -15,7 +15,7 @@ class Smarty_Internal_Method_AppendByRef
* appends values to template variables by reference * appends values to template variables by reference
* *
* @api Smarty::appendByRef() * @api Smarty::appendByRef()
* @link http://www.smarty.net/docs/en/api.append.by.ref.tpl * @link https://www.smarty.net/docs/en/api.append.by.ref.tpl
* *
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_ClearAllAssign
* clear all the assigned template variables. * clear all the assigned template variables.
* *
* @api Smarty::clearAllAssign() * @api Smarty::clearAllAssign()
* @link http://www.smarty.net/docs/en/api.clear.all.assign.tpl * @link https://www.smarty.net/docs/en/api.clear.all.assign.tpl
* *
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* *

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_ClearAllCache
* Empty cache folder * Empty cache folder
* *
* @api Smarty::clearAllCache() * @api Smarty::clearAllCache()
* @link http://www.smarty.net/docs/en/api.clear.all.cache.tpl * @link https://www.smarty.net/docs/en/api.clear.all.cache.tpl
* *
* @param \Smarty $smarty * @param \Smarty $smarty
* @param integer $exp_time expiration time * @param integer $exp_time expiration time

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_ClearAssign
* clear the given assigned template variable(s). * clear the given assigned template variable(s).
* *
* @api Smarty::clearAssign() * @api Smarty::clearAssign()
* @link http://www.smarty.net/docs/en/api.clear.assign.tpl * @link https://www.smarty.net/docs/en/api.clear.assign.tpl
* *
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string|array $tpl_var the template variable(s) to clear * @param string|array $tpl_var the template variable(s) to clear

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_ClearCache
* Empty cache for a specific template * Empty cache for a specific template
* *
* @api Smarty::clearCache() * @api Smarty::clearCache()
* @link http://www.smarty.net/docs/en/api.clear.cache.tpl * @link https://www.smarty.net/docs/en/api.clear.cache.tpl
* *
* @param \Smarty $smarty * @param \Smarty $smarty
* @param string $template_name template name * @param string $template_name template name

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_ClearCompiledTemplate
* Delete compiled template file * Delete compiled template file
* *
* @api Smarty::clearCompiledTemplate() * @api Smarty::clearCompiledTemplate()
* @link http://www.smarty.net/docs/en/api.clear.compiled.template.tpl * @link https://www.smarty.net/docs/en/api.clear.compiled.template.tpl
* *
* @param \Smarty $smarty * @param \Smarty $smarty
* @param string $resource_name template name * @param string $resource_name template name

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_ClearConfig
* clear a single or all config variables * clear a single or all config variables
* *
* @api Smarty::clearConfig() * @api Smarty::clearConfig()
* @link http://www.smarty.net/docs/en/api.clear.config.tpl * @link https://www.smarty.net/docs/en/api.clear.config.tpl
* *
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string|null $name variable name or null * @param string|null $name variable name or null

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_ConfigLoad
* load a config file, optionally load just selected sections * load a config file, optionally load just selected sections
* *
* @api Smarty::configLoad() * @api Smarty::configLoad()
* @link http://www.smarty.net/docs/en/api.config.load.tpl * @link https://www.smarty.net/docs/en/api.config.load.tpl
* *
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $config_file filename * @param string $config_file filename
@@ -42,7 +42,7 @@ class Smarty_Internal_Method_ConfigLoad
* load a config file, optionally load just selected sections * load a config file, optionally load just selected sections
* *
* @api Smarty::configLoad() * @api Smarty::configLoad()
* @link http://www.smarty.net/docs/en/api.config.load.tpl * @link https://www.smarty.net/docs/en/api.config.load.tpl
* *
* @param \Smarty|\Smarty_Internal_Data|\Smarty_Internal_Template $data * @param \Smarty|\Smarty_Internal_Data|\Smarty_Internal_Template $data
* @param string $config_file filename * @param string $config_file filename

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_CreateData
* creates a data object * creates a data object
* *
* @api Smarty::createData() * @api Smarty::createData()
* @link http://www.smarty.net/docs/en/api.create.data.tpl * @link https://www.smarty.net/docs/en/api.create.data.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param \Smarty_Internal_Template|\Smarty_Internal_Data|\Smarty_Data|\Smarty $parent next higher level of Smarty * @param \Smarty_Internal_Template|\Smarty_Internal_Data|\Smarty_Data|\Smarty $parent next higher level of Smarty

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_GetConfigVars
* Returns a single or all config variables * Returns a single or all config variables
* *
* @api Smarty::getConfigVars() * @api Smarty::getConfigVars()
* @link http://www.smarty.net/docs/en/api.get.config.vars.tpl * @link https://www.smarty.net/docs/en/api.get.config.vars.tpl
* *
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $varname variable name or null * @param string $varname variable name or null

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_GetRegisteredObject
* return a reference to a registered object * return a reference to a registered object
* *
* @api Smarty::getRegisteredObject() * @api Smarty::getRegisteredObject()
* @link http://www.smarty.net/docs/en/api.get.registered.object.tpl * @link https://www.smarty.net/docs/en/api.get.registered.object.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $object_name object name * @param string $object_name object name

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_GetTags
* Return array of tag/attributes of all tags used by an template * Return array of tag/attributes of all tags used by an template
* *
* @api Smarty::getTags() * @api Smarty::getTags()
* @link http://www.smarty.net/docs/en/api.get.tags.tpl * @link https://www.smarty.net/docs/en/api.get.tags.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param null|string|Smarty_Internal_Template $template * @param null|string|Smarty_Internal_Template $template

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_GetTemplateVars
* Returns a single or all template variables * Returns a single or all template variables
* *
* @api Smarty::getTemplateVars() * @api Smarty::getTemplateVars()
* @link http://www.smarty.net/docs/en/api.get.template.vars.tpl * @link https://www.smarty.net/docs/en/api.get.template.vars.tpl
* *
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $varName variable name or null * @param string $varName variable name or null

View File

@@ -30,7 +30,7 @@ class Smarty_Internal_Method_LoadFilter
* *
* @api Smarty::loadFilter() * @api Smarty::loadFilter()
* *
* @link http://www.smarty.net/docs/en/api.load.filter.tpl * @link https://www.smarty.net/docs/en/api.load.filter.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type filter type * @param string $type filter type

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_RegisterCacheResource
* Registers a resource to fetch a template * Registers a resource to fetch a template
* *
* @api Smarty::registerCacheResource() * @api Smarty::registerCacheResource()
* @link http://www.smarty.net/docs/en/api.register.cacheresource.tpl * @link https://www.smarty.net/docs/en/api.register.cacheresource.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $name name of resource type * @param string $name name of resource type

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_RegisterClass
* Registers static classes to be used in templates * Registers static classes to be used in templates
* *
* @api Smarty::registerClass() * @api Smarty::registerClass()
* @link http://www.smarty.net/docs/en/api.register.class.tpl * @link https://www.smarty.net/docs/en/api.register.class.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $class_name * @param string $class_name

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_RegisterDefaultPluginHandler
* Registers a default plugin handler * Registers a default plugin handler
* *
* @api Smarty::registerDefaultPluginHandler() * @api Smarty::registerDefaultPluginHandler()
* @link http://www.smarty.net/docs/en/api.register.default.plugin.handler.tpl * @link https://www.smarty.net/docs/en/api.register.default.plugin.handler.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param callable $callback class/method name * @param callable $callback class/method name

View File

@@ -30,7 +30,7 @@ class Smarty_Internal_Method_RegisterFilter
* *
* @api Smarty::registerFilter() * @api Smarty::registerFilter()
* *
* @link http://www.smarty.net/docs/en/api.register.filter.tpl * @link https://www.smarty.net/docs/en/api.register.filter.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type filter type * @param string $type filter type

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_RegisterObject
* Registers object to be used in templates * Registers object to be used in templates
* *
* @api Smarty::registerObject() * @api Smarty::registerObject()
* @link http://www.smarty.net/docs/en/api.register.object.tpl * @link https://www.smarty.net/docs/en/api.register.object.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $object_name * @param string $object_name

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_RegisterPlugin
* Registers plugin to be used in templates * Registers plugin to be used in templates
* *
* @api Smarty::registerPlugin() * @api Smarty::registerPlugin()
* @link http://www.smarty.net/docs/en/api.register.plugin.tpl * @link https://www.smarty.net/docs/en/api.register.plugin.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type plugin type * @param string $type plugin type
@@ -48,6 +48,8 @@ class Smarty_Internal_Method_RegisterPlugin
throw new SmartyException("Plugin tag '{$name}' already registered"); throw new SmartyException("Plugin tag '{$name}' already registered");
} elseif (!is_callable($callback)) { } elseif (!is_callable($callback)) {
throw new SmartyException("Plugin '{$name}' not callable"); throw new SmartyException("Plugin '{$name}' not callable");
} elseif ($cacheable && $cache_attr) {
throw new SmartyException("Cannot set caching attributes for plugin '{$name}' when it is cacheable.");
} else { } else {
$smarty->registered_plugins[ $type ][ $name ] = array($callback, (bool)$cacheable, (array)$cache_attr); $smarty->registered_plugins[ $type ][ $name ] = array($callback, (bool)$cacheable, (array)$cache_attr);
} }

View File

@@ -22,25 +22,18 @@ class Smarty_Internal_Method_RegisterResource
* Registers a resource to fetch a template * Registers a resource to fetch a template
* *
* @api Smarty::registerResource() * @api Smarty::registerResource()
* @link http://www.smarty.net/docs/en/api.register.resource.tpl * @link https://www.smarty.net/docs/en/api.register.resource.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $name name of resource type * @param string $name name of resource type
* @param Smarty_Resource|array $resource_handler or instance of * @param Smarty_Resource $resource_handler instance of Smarty_Resource
* Smarty_Resource,
* or array of
* callbacks to
* handle
* resource
* (deprecated)
* *
* @return \Smarty|\Smarty_Internal_Template * @return \Smarty|\Smarty_Internal_Template
*/ */
public function registerResource(Smarty_Internal_TemplateBase $obj, $name, $resource_handler) public function registerResource(Smarty_Internal_TemplateBase $obj, $name, Smarty_Resource $resource_handler)
{ {
$smarty = $obj->_getSmartyObj(); $smarty = $obj->_getSmartyObj();
$smarty->registered_resources[ $name ] = $smarty->registered_resources[ $name ] = $resource_handler;
$resource_handler instanceof Smarty_Resource ? $resource_handler : array($resource_handler, false);
return $obj; return $obj;
} }
} }

View File

@@ -16,7 +16,7 @@ class Smarty_Internal_Method_UnloadFilter extends Smarty_Internal_Method_LoadFil
* *
* @api Smarty::unloadFilter() * @api Smarty::unloadFilter()
* *
* @link http://www.smarty.net/docs/en/api.unload.filter.tpl * @link https://www.smarty.net/docs/en/api.unload.filter.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type filter type * @param string $type filter type

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_UnregisterCacheResource
* Registers a resource to fetch a template * Registers a resource to fetch a template
* *
* @api Smarty::unregisterCacheResource() * @api Smarty::unregisterCacheResource()
* @link http://www.smarty.net/docs/en/api.unregister.cacheresource.tpl * @link https://www.smarty.net/docs/en/api.unregister.cacheresource.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param $name * @param $name

View File

@@ -16,7 +16,7 @@ class Smarty_Internal_Method_UnregisterFilter extends Smarty_Internal_Method_Reg
* *
* @api Smarty::unregisterFilter() * @api Smarty::unregisterFilter()
* *
* @link http://www.smarty.net/docs/en/api.unregister.filter.tpl * @link https://www.smarty.net/docs/en/api.unregister.filter.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type filter type * @param string $type filter type

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_UnregisterObject
* Registers plugin to be used in templates * Registers plugin to be used in templates
* *
* @api Smarty::unregisterObject() * @api Smarty::unregisterObject()
* @link http://www.smarty.net/docs/en/api.unregister.object.tpl * @link https://www.smarty.net/docs/en/api.unregister.object.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $object_name name of object * @param string $object_name name of object

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_UnregisterPlugin
* Registers plugin to be used in templates * Registers plugin to be used in templates
* *
* @api Smarty::unregisterPlugin() * @api Smarty::unregisterPlugin()
* @link http://www.smarty.net/docs/en/api.unregister.plugin.tpl * @link https://www.smarty.net/docs/en/api.unregister.plugin.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type plugin type * @param string $type plugin type

View File

@@ -22,7 +22,7 @@ class Smarty_Internal_Method_UnregisterResource
* Registers a resource to fetch a template * Registers a resource to fetch a template
* *
* @api Smarty::unregisterResource() * @api Smarty::unregisterResource()
* @link http://www.smarty.net/docs/en/api.unregister.resource.tpl * @link https://www.smarty.net/docs/en/api.unregister.resource.tpl
* *
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param string $type name of resource type * @param string $type name of resource type

View File

@@ -85,45 +85,85 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
public function to_smarty_php(Smarty_Internal_Templateparser $parser) public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{ {
$code = ''; $code = '';
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {
if ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Text) { foreach ($this->getChunkedSubtrees() as $chunk) {
$subtree = $this->subtrees[ $key ]->to_smarty_php($parser); $text = '';
while ($key + 1 < $cnt && ($this->subtrees[ $key + 1 ] instanceof Smarty_Internal_ParseTree_Text || switch ($chunk['mode']) {
$this->subtrees[ $key + 1 ]->data === '')) { case 'textstripped':
$key++; foreach ($chunk['subtrees'] as $subtree) {
if ($this->subtrees[ $key ]->data === '') { $text .= $subtree->to_smarty_php($parser);
continue;
}
$subtree .= $this->subtrees[ $key ]->to_smarty_php($parser);
}
if ($subtree === '') {
continue;
} }
$code .= preg_replace( $code .= preg_replace(
'/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/', '/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/',
"<?php echo '\$1'; ?>\n", "<?php echo '\$1'; ?>\n",
$subtree $parser->compiler->processText($text)
); );
continue; break;
case 'text':
foreach ($chunk['subtrees'] as $subtree) {
$text .= $subtree->to_smarty_php($parser);
} }
if ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Tag) { $code .= preg_replace(
$subtree = $this->subtrees[ $key ]->to_smarty_php($parser); '/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/',
while ($key + 1 < $cnt && ($this->subtrees[ $key + 1 ] instanceof Smarty_Internal_ParseTree_Tag || "<?php echo '\$1'; ?>\n",
$this->subtrees[ $key + 1 ]->data === '')) { $text
$key++; );
if ($this->subtrees[ $key ]->data === '') { break;
continue; case 'tag':
foreach ($chunk['subtrees'] as $subtree) {
$text = $parser->compiler->appendCode($text, $subtree->to_smarty_php($parser));
} }
$subtree = $parser->compiler->appendCode($subtree, $this->subtrees[ $key ]->to_smarty_php($parser)); $code .= $text;
break;
default:
foreach ($chunk['subtrees'] as $subtree) {
$text = $subtree->to_smarty_php($parser);
} }
if ($subtree === '') { $code .= $text;
continue;
} }
$code .= $subtree;
continue;
}
$code .= $this->subtrees[ $key ]->to_smarty_php($parser);
} }
return $code; return $code;
} }
private function getChunkedSubtrees() {
$chunks = array();
$currentMode = null;
$currentChunk = array();
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {
if ($this->subtrees[ $key ]->data === '' && in_array($currentMode, array('textstripped', 'text', 'tag'))) {
continue;
}
if ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Text
&& $this->subtrees[ $key ]->isToBeStripped()) {
$newMode = 'textstripped';
} elseif ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Text) {
$newMode = 'text';
} elseif ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Tag) {
$newMode = 'tag';
} else {
$newMode = 'other';
}
if ($newMode == $currentMode) {
$currentChunk[] = $this->subtrees[ $key ];
} else {
$chunks[] = array(
'mode' => $currentMode,
'subtrees' => $currentChunk
);
$currentMode = $newMode;
$currentChunk = array($this->subtrees[ $key ]);
}
}
if ($currentMode && $currentChunk) {
$chunks[] = array(
'mode' => $currentMode,
'subtrees' => $currentChunk
);
}
return $chunks;
}
} }

View File

@@ -16,14 +16,31 @@
*/ */
class Smarty_Internal_ParseTree_Text extends Smarty_Internal_ParseTree class Smarty_Internal_ParseTree_Text extends Smarty_Internal_ParseTree
{ {
/**
* Wether this section should be stripped on output to smarty php
* @var bool
*/
private $toBeStripped = false;
/** /**
* Create template text buffer * Create template text buffer
* *
* @param string $data text * @param string $data text
* @param bool $toBeStripped wether this section should be stripped on output to smarty php
*/ */
public function __construct($data) public function __construct($data, $toBeStripped = false)
{ {
$this->data = $data; $this->data = $data;
$this->toBeStripped = $toBeStripped;
}
/**
* Wether this section should be stripped on output to smarty php
* @return bool
*/
public function isToBeStripped() {
return $this->toBeStripped;
} }
/** /**

View File

@@ -1,101 +0,0 @@
<?php
/**
* Smarty Internal Plugin Resource Registered
*
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
* @author Rodney Rehm
*/
/**
* Smarty Internal Plugin Resource Registered
* Implements the registered resource for Smarty template
*
* @package Smarty
* @subpackage TemplateResources
* @deprecated
*/
class Smarty_Internal_Resource_Registered extends Smarty_Resource
{
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->filepath = $source->type . ':' . $source->name;
$source->uid = sha1($source->filepath . $source->smarty->_joined_template_dir);
$source->timestamp = $this->getTemplateTimestamp($source);
$source->exists = !!$source->timestamp;
}
/**
* populate Source Object with timestamp and exists from Resource
*
* @param Smarty_Template_Source $source source object
*
* @return void
*/
public function populateTimestamp(Smarty_Template_Source $source)
{
$source->timestamp = $this->getTemplateTimestamp($source);
$source->exists = !!$source->timestamp;
}
/**
* Get timestamp (epoch) the template source was modified
*
* @param Smarty_Template_Source $source source object
*
* @return integer|boolean timestamp (epoch) the template was modified, false if resources has no timestamp
*/
public function getTemplateTimestamp(Smarty_Template_Source $source)
{
// return timestamp
$time_stamp = false;
call_user_func_array(
$source->smarty->registered_resources[ $source->type ][ 0 ][ 1 ],
array($source->name, &$time_stamp, $source->smarty)
);
return is_numeric($time_stamp) ? (int)$time_stamp : $time_stamp;
}
/**
* Load template's source by invoking the registered callback into current template object
*
* @param Smarty_Template_Source $source source object
*
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
public function getContent(Smarty_Template_Source $source)
{
// return template string
$content = null;
$t = call_user_func_array(
$source->smarty->registered_resources[ $source->type ][ 0 ][ 0 ],
array($source->name, &$content, $source->smarty)
);
if (is_bool($t) && !$t) {
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
}
return $content;
}
/**
* Determine basename for compiled filename
*
* @param Smarty_Template_Source $source source object
*
* @return string resource's basename
*/
public function getBasename(Smarty_Template_Source $source)
{
return basename($source->name);
}
}

View File

@@ -13,7 +13,7 @@
* Smarty Internal Plugin Resource Stream * Smarty Internal Plugin Resource Stream
* Implements the streams as resource for Smarty template * Implements the streams as resource for Smarty template
* *
* @link http://php.net/streams * @link https://php.net/streams
* @package Smarty * @package Smarty
* @subpackage TemplateResources * @subpackage TemplateResources
*/ */

View File

@@ -44,9 +44,12 @@ class Smarty_Internal_Runtime_CodeFrame
$properties[ 'file_dependency' ] = $_template->cached->file_dependency; $properties[ 'file_dependency' ] = $_template->cached->file_dependency;
$properties[ 'cache_lifetime' ] = $_template->cache_lifetime; $properties[ 'cache_lifetime' ] = $_template->cache_lifetime;
} }
$output = "<?php\n"; $output = sprintf(
$output .= "/* Smarty version {$properties[ 'version' ]}, created on " . strftime("%Y-%m-%d %H:%M:%S") . "<?php\n/* Smarty version %s, created on %s\n from '%s' */\n\n",
"\n from '" . str_replace('*/', '* /', $_template->source->filepath) . "' */\n\n"; $properties[ 'version' ],
date("Y-m-d H:i:s"),
str_replace('*/', '* /', $_template->source->filepath)
);
$output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n"; $output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
$dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' . $dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' .
($cache ? 'true' : 'false') . ')'; ($cache ? 'true' : 'false') . ')';

View File

@@ -150,7 +150,7 @@ class Smarty_Internal_Runtime_Inheritance
return; return;
} }
// make sure we got child block of child template of current block // make sure we got child block of child template of current block
while ($block->child && $block->tplIndex <= $block->child->tplIndex) { while ($block->child && $block->child->child && $block->tplIndex <= $block->child->tplIndex) {
$block->child = $block->child->child; $block->child = $block->child->child;
} }
$this->process($tpl, $block); $this->process($tpl, $block);

View File

@@ -138,7 +138,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* test if cache is valid * test if cache is valid
* *
* @api Smarty::isCached() * @api Smarty::isCached()
* @link http://www.smarty.net/docs/en/api.is.cached.tpl * @link https://www.smarty.net/docs/en/api.is.cached.tpl
* *
* @param null|string|\Smarty_Internal_Template $template the resource handle of the template file or template * @param null|string|\Smarty_Internal_Template $template the resource handle of the template file or template
* object * object
@@ -199,6 +199,12 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
try { try {
$_smarty_old_error_level = $_smarty_old_error_level =
isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null; isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null;
if ($smarty->isMutingUndefinedOrNullWarnings()) {
$errorHandler = new Smarty_Internal_ErrorHandler();
$errorHandler->activate();
}
if ($this->_objType === 2) { if ($this->_objType === 2) {
/* @var Smarty_Internal_Template $this */ /* @var Smarty_Internal_Template $this */
$template->tplFunctions = $this->tplFunctions; $template->tplFunctions = $this->tplFunctions;
@@ -242,6 +248,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
} }
} }
} }
if (isset($errorHandler)) {
$errorHandler->deactivate();
}
if (isset($_smarty_old_error_level)) { if (isset($_smarty_old_error_level)) {
error_reporting($_smarty_old_error_level); error_reporting($_smarty_old_error_level);
} }
@@ -250,6 +261,10 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
while (ob_get_level() > $level) { while (ob_get_level() > $level) {
ob_end_clean(); ob_end_clean();
} }
if (isset($errorHandler)) {
$errorHandler->deactivate();
}
if (isset($_smarty_old_error_level)) { if (isset($_smarty_old_error_level)) {
error_reporting($_smarty_old_error_level); error_reporting($_smarty_old_error_level);
} }
@@ -261,11 +276,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* Registers plugin to be used in templates * Registers plugin to be used in templates
* *
* @api Smarty::registerPlugin() * @api Smarty::registerPlugin()
* @link http://www.smarty.net/docs/en/api.register.plugin.tpl * @link https://www.smarty.net/docs/en/api.register.plugin.tpl
* *
* @param string $type plugin type * @param string $type plugin type
* @param string $name name of template tag * @param string $name name of template tag
* @param callback $callback PHP callback to register * @param callable $callback PHP callback to register
* @param bool $cacheable if true (default) this function is cache able * @param bool $cacheable if true (default) this function is cache able
* @param mixed $cache_attr caching attributes if any * @param mixed $cache_attr caching attributes if any
* *
@@ -281,7 +296,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* load a filter of specified type and name * load a filter of specified type and name
* *
* @api Smarty::loadFilter() * @api Smarty::loadFilter()
* @link http://www.smarty.net/docs/en/api.load.filter.tpl * @link https://www.smarty.net/docs/en/api.load.filter.tpl
* *
* @param string $type filter type * @param string $type filter type
* @param string $name filter name * @param string $name filter name
@@ -298,10 +313,10 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* Registers a filter function * Registers a filter function
* *
* @api Smarty::registerFilter() * @api Smarty::registerFilter()
* @link http://www.smarty.net/docs/en/api.register.filter.tpl * @link https://www.smarty.net/docs/en/api.register.filter.tpl
* *
* @param string $type filter type * @param string $type filter type
* @param callback $callback * @param callable $callback
* @param string|null $name optional filter name * @param string|null $name optional filter name
* *
* @return \Smarty|\Smarty_Internal_Template * @return \Smarty|\Smarty_Internal_Template
@@ -316,7 +331,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* Registers object to be used in templates * Registers object to be used in templates
* *
* @api Smarty::registerObject() * @api Smarty::registerObject()
* @link http://www.smarty.net/docs/en/api.register.object.tpl * @link https://www.smarty.net/docs/en/api.register.object.tpl
* *
* @param string $object_name * @param string $object_name
* @param object $object the referenced PHP object to register * @param object $object the referenced PHP object to register

View File

@@ -203,13 +203,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/ */
public $blockOrFunctionCode = ''; public $blockOrFunctionCode = '';
/**
* php_handling setting either from Smarty or security
*
* @var int
*/
public $php_handling = 0;
/** /**
* flags for used modifier plugins * flags for used modifier plugins
* *
@@ -438,11 +431,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
} }
$this->smarty->_debug->start_compile($this->template); $this->smarty->_debug->start_compile($this->template);
} }
if (isset($this->template->smarty->security_policy)) {
$this->php_handling = $this->template->smarty->security_policy->php_handling;
} else {
$this->php_handling = $this->template->smarty->php_handling;
}
$this->parent_compiler = $parent_compiler ? $parent_compiler : $this; $this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
$nocache = isset($nocache) ? $nocache : false; $nocache = isset($nocache) ? $nocache : false;
if (empty($template->compiled->nocache_hash)) { if (empty($template->compiled->nocache_hash)) {
@@ -621,22 +609,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
|| strcasecmp($name, 'array') === 0 || is_callable($name) || strcasecmp($name, 'array') === 0 || is_callable($name)
) { ) {
$func_name = strtolower($name); $func_name = strtolower($name);
$par = implode(',', $parameter);
$parHasFuction = strpos($par, '(') !== false;
if ($func_name === 'isset') { if ($func_name === 'isset') {
if (count($parameter) === 0) { if (count($parameter) === 0) {
$this->trigger_template_error('Illegal number of parameter in "isset()"'); $this->trigger_template_error('Illegal number of parameter in "isset()"');
} }
if ($parHasFuction) {
$pa = array(); $pa = array();
foreach ($parameter as $p) { foreach ($parameter as $p) {
$pa[] = (strpos($p, '(') === false) ? ('isset(' . $p . ')') : ('(' . $p . ' !== null )'); $pa[] = $this->syntaxMatchesVariable($p) ? 'isset(' . $p . ')' : '(' . $p . ' !== null )';
} }
return '(' . implode(' && ', $pa) . ')'; return '(' . implode(' && ', $pa) . ')';
} else {
$isset_par = str_replace("')->value", "',null,true,false)->value", $par);
}
return $name . '(' . $isset_par . ')';
} elseif (in_array( } elseif (in_array(
$func_name, $func_name,
array( array(
@@ -653,12 +637,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->trigger_template_error("Illegal number of parameter in '{$func_name()}'"); $this->trigger_template_error("Illegal number of parameter in '{$func_name()}'");
} }
if ($func_name === 'empty') { if ($func_name === 'empty') {
if ($parHasFuction && version_compare(PHP_VERSION, '5.5.0', '<')) {
return '(' . $parameter[ 0 ] . ' === false )';
} else {
return $func_name . '(' . return $func_name . '(' .
str_replace("')->value", "',null,true,false)->value", $parameter[ 0 ]) . ')'; str_replace("')->value", "',null,true,false)->value", $parameter[ 0 ]) . ')';
}
} else { } else {
return $func_name . '(' . $parameter[ 0 ] . ')'; return $func_name . '(' . $parameter[ 0 ] . ')';
} }
@@ -672,21 +652,35 @@ abstract class Smarty_Internal_TemplateCompilerBase
} }
/** /**
* This method is called from parser to process a text content section * Determines whether the passed string represents a valid (PHP) variable.
* This is important, because `isset()` only works on variables and `empty()` can only be passed
* a variable prior to php5.5
* @param $string
* @return bool
*/
private function syntaxMatchesVariable($string) {
static $regex_pattern = '/^\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*((->)[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*|\[.*]*\])*$/';
return 1 === preg_match($regex_pattern, trim($string));
}
/**
* This method is called from parser to process a text content section if strip is enabled
* - remove text from inheritance child templates as they may generate output * - remove text from inheritance child templates as they may generate output
* - strip text if strip is enabled
* *
* @param string $text * @param string $text
* *
* @return null|\Smarty_Internal_ParseTree_Text * @return string
*/ */
public function processText($text) public function processText($text)
{ {
if ((string)$text != '') {
if (strpos($text, '<') === false) {
return preg_replace($this->stripRegEx, '', $text);
}
$store = array(); $store = array();
$_store = 0; $_store = 0;
if ($this->parser->strip) {
if (strpos($text, '<') !== false) {
// capture html elements not to be messed with // capture html elements not to be messed with
$_offset = 0; $_offset = 0;
if (preg_match_all( if (preg_match_all(
@@ -732,13 +726,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$_store++; $_store++;
} }
} }
} else { return $text;
$text = preg_replace($this->stripRegEx, '', $text);
}
}
return new Smarty_Internal_ParseTree_Text($text);
}
return null;
} }
/** /**
@@ -1147,7 +1135,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
flush(); flush();
} }
$e = new SmartyCompilerException($error_text); $e = new SmartyCompilerException($error_text);
$e->line = $line; $e->setLine($line);
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ])); $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ]));
$e->desc = $args; $e->desc = $args;
$e->template = $this->template->source->filepath; $e->template = $this->template->source->filepath;
@@ -1451,6 +1439,10 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/ */
abstract protected function doCompile($_content, $isTemplateSource = false); abstract protected function doCompile($_content, $isTemplateSource = false);
public function cStyleComment($string) {
return '/*' . str_replace('*/', '* /' , $string) . '*/';
}
/** /**
* Compile Tag * Compile Tag
* *

View File

@@ -18,12 +18,6 @@
*/ */
class Smarty_Internal_Templatelexer class Smarty_Internal_Templatelexer
{ {
const TEXT = 1;
const TAG = 2;
const TAGBODY = 3;
const LITERAL = 4;
const DOUBLEQUOTEDSTRING = 5;
/** /**
* Source * Source
* *
@@ -215,9 +209,19 @@ class Smarty_Internal_Templatelexer
*/ */
private $yy_global_pattern5 = null; private $yy_global_pattern5 = null;
private $_yy_state = 1; /**
* preg token pattern for text
*
* @var null
*/
private $yy_global_text = null;
private $_yy_stack = array(); /**
* preg token pattern for literal
*
* @var null
*/
private $yy_global_literal = null;
/** /**
* constructor * constructor
@@ -231,14 +235,14 @@ class Smarty_Internal_Templatelexer
$this->dataLength = strlen($this->data); $this->dataLength = strlen($this->data);
$this->counter = 0; $this->counter = 0;
if (preg_match('/^\xEF\xBB\xBF/i', $this->data, $match)) { if (preg_match('/^\xEF\xBB\xBF/i', $this->data, $match)) {
$this->counter += strlen($match[ 0 ]); $this->counter += strlen($match[0]);
} }
$this->line = 1; $this->line = 1;
$this->smarty = $compiler->template->smarty; $this->smarty = $compiler->template->smarty;
$this->compiler = $compiler; $this->compiler = $compiler;
$this->compiler->initDelimiterPreg(); $this->compiler->initDelimiterPreg();
$this->smarty_token_names[ 'LDEL' ] = $this->smarty->getLeftDelimiter(); $this->smarty_token_names['LDEL'] = $this->smarty->getLeftDelimiter();
$this->smarty_token_names[ 'RDEL' ] = $this->smarty->getRightDelimiter(); $this->smarty_token_names['RDEL'] = $this->smarty->getRightDelimiter();
} }
/** /**
@@ -272,7 +276,11 @@ class Smarty_Internal_Templatelexer
{ {
return $this->smarty->getAutoLiteral() && isset($this->value[ $this->compiler->getLdelLength() ]) ? return $this->smarty->getAutoLiteral() && isset($this->value[ $this->compiler->getLdelLength() ]) ?
strpos(" \n\t\r", $this->value[ $this->compiler->getLdelLength() ]) !== false : false; strpos(" \n\t\r", $this->value[ $this->compiler->getLdelLength() ]) !== false : false;
} // end function }
private $_yy_state = 1;
private $_yy_stack = array();
public function yylex() public function yylex()
{ {
@@ -282,44 +290,41 @@ class Smarty_Internal_Templatelexer
public function yypushstate($state) public function yypushstate($state)
{ {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, 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);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
} }
array_push($this->_yy_stack, $this->_yy_state); array_push($this->_yy_stack, $this->_yy_state);
$this->_yy_state = $state; $this->_yy_state = $state;
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, 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);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
} }
} }
public function yypopstate() public function yypopstate()
{ {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, 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);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
} }
$this->_yy_state = array_pop($this->_yy_stack); $this->_yy_state = array_pop($this->_yy_stack);
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, 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);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
} }
} }
public function yybegin($state) public function yybegin($state)
{ {
$this->_yy_state = $state; $this->_yy_state = $state;
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, 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);
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
} }
} }
public function yylex1() public function yylex1()
{ {
if (!isset($this->yy_global_pattern1)) { if (!isset($this->yy_global_pattern1)) {
$this->yy_global_pattern1 = $this->yy_global_pattern1 = $this->replace("/\G([{][}])|\G((SMARTYldel)SMARTYal[*])|\G((SMARTYldel)SMARTYautoliteral\\s+SMARTYliteral)|\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([\S\s])/isS");
$this->replace("/\G([{][}])|\G((SMARTYldel)SMARTYal[*])|\G((SMARTYldel)SMARTYalphp([ ].*?)?SMARTYrdel|(SMARTYldel)SMARTYal[\/]phpSMARTYrdel)|\G((SMARTYldel)SMARTYautoliteral\\s+SMARTYliteral)|\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([<][?]((php\\s+|=)|\\s+)|[<][%]|[<][?]xml\\s+|[<]script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*[>]|[?][>]|[%][>])|\G((.*?)(?=((SMARTYldel)SMARTYal|[<][?]((php\\s+|=)|\\s+)|[<][%]|[<][?]xml\\s+|[<]script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*[>]|[?][>]|[%][>]SMARTYliteral))|[\s\S]+)/isS");
} }
if (!isset($this->dataLength)) { if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data); $this->dataLength = strlen($this->data);
@@ -327,20 +332,18 @@ class Smarty_Internal_Templatelexer
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
return false; // end of input return false; // end of input
} }
do { do {
if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, 0, $this->counter)) { if (preg_match($this->yy_global_pattern1,$this->data, $yymatches, 0, $this->counter)) {
if (!isset($yymatches[ 0 ][ 1 ])) { if (!isset($yymatches[ 0 ][1])) {
$yymatches = preg_grep("/(.|\s)+/", $yymatches); $yymatches = preg_grep("/(.|\s)+/", $yymatches);
} else { } else {
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr( ' an empty string. Input "' . substr($this->data,
$this->data, $this->counter, 5) . '... state TEXT');
$this->counter,
5
) . '... state TEXT');
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -363,76 +366,78 @@ class Smarty_Internal_Templatelexer
} }
// skip this token // skip this token
continue; continue;
} } } else {
} else {
throw new Exception('Unexpected input at line' . $this->line . throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[ $this->counter ]); ': ' . $this->data[$this->counter]);
} }
break; break;
} while (true); } while (true);
}
} // end function
const TEXT = 1;
public function yy_r1_1() public function yy_r1_1()
{ {
$this->token = Smarty_Internal_Templateparser::TP_TEXT; $this->token = Smarty_Internal_Templateparser::TP_TEXT;
} }
public function yy_r1_2() public function yy_r1_2()
{ {
preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/", $this->data, $match, PREG_OFFSET_CAPTURE,
$this->counter); $to = $this->dataLength;
if (isset($match[ 0 ][ 1 ])) { preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
$to = $match[ 0 ][ 1 ] + strlen($match[ 0 ][ 0 ]); if (isset($match[0][1])) {
$to = $match[0][1] + strlen($match[0][0]);
} else { } else {
$this->compiler->trigger_template_error("missing or misspelled comment closing tag '{$this->smarty->getRightDelimiter()}'"); $this->compiler->trigger_template_error ("missing or misspelled comment closing tag '{$this->smarty->getRightDelimiter()}'");
} }
$this->value = substr($this->data, $this->counter, $to - $this->counter); $this->value = substr($this->data,$this->counter,$to-$this->counter);
return false; return false;
} }
public function yy_r1_4() public function yy_r1_4()
{ {
$this->compiler->getTagCompiler('private_php')->parsePhp($this);
}
public function yy_r1_8()
{
$this->token = Smarty_Internal_Templateparser::TP_TEXT; $this->token = Smarty_Internal_Templateparser::TP_TEXT;
} }
public function yy_r1_6()
public function yy_r1_10()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART;
$this->yypushstate(self::LITERAL); $this->yypushstate(self::LITERAL);
} }
public function yy_r1_8()
public function yy_r1_12()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LITERALEND; $this->token = Smarty_Internal_Templateparser::TP_LITERALEND;
$this->yypushstate(self::LITERAL); $this->yypushstate(self::LITERAL);
} // end function }
public function yy_r1_10()
public function yy_r1_14()
{ {
$this->yypushstate(self::TAG); $this->yypushstate(self::TAG);
return true; return true;
} }
public function yy_r1_12()
public function yy_r1_16()
{ {
$this->compiler->getTagCompiler('private_php')->parsePhp($this);
if (!isset($this->yy_global_text)) {
$this->yy_global_text = $this->replace('/(SMARTYldel)SMARTYal/isS');
} }
$to = $this->dataLength;
public function yy_r1_19() preg_match($this->yy_global_text, $this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
{ if (isset($match[0][1])) {
$to = $match[0][1];
}
$this->value = substr($this->data,$this->counter,$to-$this->counter);
$this->token = Smarty_Internal_Templateparser::TP_TEXT; $this->token = Smarty_Internal_Templateparser::TP_TEXT;
} }
public function yylex2() public function yylex2()
{ {
if (!isset($this->yy_global_pattern2)) { if (!isset($this->yy_global_pattern2)) {
$this->yy_global_pattern2 = $this->yy_global_pattern2 = $this->replace("/\G((SMARTYldel)SMARTYal(if|elseif|else if|while)\\s+)|\G((SMARTYldel)SMARTYalfor\\s+)|\G((SMARTYldel)SMARTYalforeach(?![^\s]))|\G((SMARTYldel)SMARTYalsetfilter\\s+)|\G((SMARTYldel)SMARTYalmake_nocache\\s+)|\G((SMARTYldel)SMARTYal[0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[$]smarty\\.block\\.(child|parent)\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/][0-9]*[a-zA-Z_]\\w*\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[$][0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/])|\G((SMARTYldel)SMARTYal)/isS");
$this->replace("/\G((SMARTYldel)SMARTYal(if|elseif|else if|while)\\s+)|\G((SMARTYldel)SMARTYalfor\\s+)|\G((SMARTYldel)SMARTYalforeach(?![^\s]))|\G((SMARTYldel)SMARTYalsetfilter\\s+)|\G((SMARTYldel)SMARTYalmake_nocache\\s+)|\G((SMARTYldel)SMARTYal[0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[$]smarty\\.block\\.(child|parent)\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/][0-9]*[a-zA-Z_]\\w*\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[$][0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/])|\G((SMARTYldel)SMARTYal)/isS");
} }
if (!isset($this->dataLength)) { if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data); $this->dataLength = strlen($this->data);
@@ -440,20 +445,18 @@ class Smarty_Internal_Templatelexer
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
return false; // end of input return false; // end of input
} }
do { do {
if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, 0, $this->counter)) { if (preg_match($this->yy_global_pattern2,$this->data, $yymatches, 0, $this->counter)) {
if (!isset($yymatches[ 0 ][ 1 ])) { if (!isset($yymatches[ 0 ][1])) {
$yymatches = preg_grep("/(.|\s)+/", $yymatches); $yymatches = preg_grep("/(.|\s)+/", $yymatches);
} else { } else {
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr( ' an empty string. Input "' . substr($this->data,
$this->data, $this->counter, 5) . '... state TAG');
$this->counter,
5
) . '... state TAG');
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -476,74 +479,77 @@ class Smarty_Internal_Templatelexer
} }
// skip this token // skip this token
continue; continue;
} } } else {
} else {
throw new Exception('Unexpected input at line' . $this->line . throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[ $this->counter ]); ': ' . $this->data[$this->counter]);
} }
break; break;
} while (true); } while (true);
}
} // end function
const TAG = 2;
public function yy_r2_1() public function yy_r2_1()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LDELIF; $this->token = Smarty_Internal_Templateparser::TP_LDELIF;
$this->yybegin(self::TAGBODY); $this->yybegin(self::TAGBODY);
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
public function yy_r2_4() public function yy_r2_4()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LDELFOR; $this->token = Smarty_Internal_Templateparser::TP_LDELFOR;
$this->yybegin(self::TAGBODY); $this->yybegin(self::TAGBODY);
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
public function yy_r2_6() public function yy_r2_6()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH;
$this->yybegin(self::TAGBODY); $this->yybegin(self::TAGBODY);
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
public function yy_r2_8() public function yy_r2_8()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LDELSETFILTER; $this->token = Smarty_Internal_Templateparser::TP_LDELSETFILTER;
$this->yybegin(self::TAGBODY); $this->yybegin(self::TAGBODY);
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
public function yy_r2_10() public function yy_r2_10()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LDELMAKENOCACHE; $this->token = Smarty_Internal_Templateparser::TP_LDELMAKENOCACHE;
$this->yybegin(self::TAGBODY); $this->yybegin(self::TAGBODY);
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
public function yy_r2_12() public function yy_r2_12()
{ {
$this->yypopstate(); $this->yypopstate();
$this->token = Smarty_Internal_Templateparser::TP_SIMPLETAG; $this->token = Smarty_Internal_Templateparser::TP_SIMPLETAG;
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
public function yy_r2_15() public function yy_r2_15()
{ {
$this->yypopstate(); $this->yypopstate();
$this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT; $this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT;
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
public function yy_r2_18() public function yy_r2_18()
{ {
$this->yypopstate(); $this->yypopstate();
$this->token = Smarty_Internal_Templateparser::TP_CLOSETAG; $this->token = Smarty_Internal_Templateparser::TP_CLOSETAG;
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
public function yy_r2_20() public function yy_r2_20()
{ {
if ($this->_yy_stack[ count($this->_yy_stack) - 1 ] === self::TEXT) {
if ($this->_yy_stack[count($this->_yy_stack)-1] === self::TEXT) {
$this->yypopstate(); $this->yypopstate();
$this->token = Smarty_Internal_Templateparser::TP_SIMPELOUTPUT; $this->token = Smarty_Internal_Templateparser::TP_SIMPELOUTPUT;
$this->taglineno = $this->line; $this->taglineno = $this->line;
@@ -553,27 +559,27 @@ class Smarty_Internal_Templatelexer
$this->yybegin(self::TAGBODY); $this->yybegin(self::TAGBODY);
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
} // end function }
public function yy_r2_23() public function yy_r2_23()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
$this->yybegin(self::TAGBODY); $this->yybegin(self::TAGBODY);
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
public function yy_r2_25() public function yy_r2_25()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LDEL; $this->token = Smarty_Internal_Templateparser::TP_LDEL;
$this->yybegin(self::TAGBODY); $this->yybegin(self::TAGBODY);
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
public function yylex3() public function yylex3()
{ {
if (!isset($this->yy_global_pattern3)) { if (!isset($this->yy_global_pattern3)) {
$this->yy_global_pattern3 = $this->yy_global_pattern3 = $this->replace("/\G(\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*([!=][=]{1,2}|[<][=>]?|[>][=]?|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even|div)\\s+by\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G([!]\\s*|not\\s+)|\G([(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\\s*)|\G(\\s*[(]\\s*)|\G(\\s*[)])|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*[-][>]\\s*)|\G(\\s*[=][>]\\s*)|\G(\\s*[=]\\s*)|\G(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G(array\\s*[(]\\s*)|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|][@]?)|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS");
$this->replace("/\G(\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*([!=][=]{1,2}|[<][=>]?|[>][=]?|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even|div)\\s+by\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G([!]\\s*|not\\s+)|\G([(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\\s*)|\G(\\s*[(]\\s*)|\G(\\s*[)])|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*[-][>]\\s*)|\G(\\s*[=][>]\\s*)|\G(\\s*[=]\\s*)|\G(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|][@]?)|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS");
} }
if (!isset($this->dataLength)) { if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data); $this->dataLength = strlen($this->data);
@@ -581,20 +587,18 @@ class Smarty_Internal_Templatelexer
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
return false; // end of input return false; // end of input
} }
do { do {
if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, 0, $this->counter)) { if (preg_match($this->yy_global_pattern3,$this->data, $yymatches, 0, $this->counter)) {
if (!isset($yymatches[ 0 ][ 1 ])) { if (!isset($yymatches[ 0 ][1])) {
$yymatches = preg_grep("/(.|\s)+/", $yymatches); $yymatches = preg_grep("/(.|\s)+/", $yymatches);
} else { } else {
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr( ' an empty string. Input "' . substr($this->data,
$this->data, $this->counter, 5) . '... state TAGBODY');
$this->counter,
5
) . '... state TAGBODY');
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -617,253 +621,261 @@ class Smarty_Internal_Templatelexer
} }
// skip this token // skip this token
continue; continue;
} } } else {
} else {
throw new Exception('Unexpected input at line' . $this->line . throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[ $this->counter ]); ': ' . $this->data[$this->counter]);
} }
break; break;
} while (true); } while (true);
}
} // end function
const TAGBODY = 3;
public function yy_r3_1() public function yy_r3_1()
{ {
$this->token = Smarty_Internal_Templateparser::TP_RDEL; $this->token = Smarty_Internal_Templateparser::TP_RDEL;
$this->yypopstate(); $this->yypopstate();
} }
public function yy_r3_2() public function yy_r3_2()
{ {
$this->yypushstate(self::TAG); $this->yypushstate(self::TAG);
return true; return true;
} }
public function yy_r3_4() public function yy_r3_4()
{ {
$this->token = Smarty_Internal_Templateparser::TP_QUOTE; $this->token = Smarty_Internal_Templateparser::TP_QUOTE;
$this->yypushstate(self::DOUBLEQUOTEDSTRING); $this->yypushstate(self::DOUBLEQUOTEDSTRING);
$this->compiler->enterDoubleQuote(); $this->compiler->enterDoubleQuote();
} }
public function yy_r3_5() public function yy_r3_5()
{ {
$this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING; $this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING;
} }
public function yy_r3_6() public function yy_r3_6()
{ {
$this->token = Smarty_Internal_Templateparser::TP_DOLLARID; $this->token = Smarty_Internal_Templateparser::TP_DOLLARID;
} }
public function yy_r3_7() public function yy_r3_7()
{ {
$this->token = Smarty_Internal_Templateparser::TP_DOLLAR; $this->token = Smarty_Internal_Templateparser::TP_DOLLAR;
} }
public function yy_r3_8() public function yy_r3_8()
{ {
$this->token = Smarty_Internal_Templateparser::TP_ISIN; $this->token = Smarty_Internal_Templateparser::TP_ISIN;
} }
public function yy_r3_9() public function yy_r3_9()
{ {
$this->token = Smarty_Internal_Templateparser::TP_AS; $this->token = Smarty_Internal_Templateparser::TP_AS;
} }
public function yy_r3_10() public function yy_r3_10()
{ {
$this->token = Smarty_Internal_Templateparser::TP_TO; $this->token = Smarty_Internal_Templateparser::TP_TO;
} }
public function yy_r3_11() public function yy_r3_11()
{ {
$this->token = Smarty_Internal_Templateparser::TP_STEP; $this->token = Smarty_Internal_Templateparser::TP_STEP;
} }
public function yy_r3_12() public function yy_r3_12()
{ {
$this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF; $this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF;
} }
public function yy_r3_13() public function yy_r3_13()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LOGOP; $this->token = Smarty_Internal_Templateparser::TP_LOGOP;
} }
public function yy_r3_15() public function yy_r3_15()
{ {
$this->token = Smarty_Internal_Templateparser::TP_SLOGOP; $this->token = Smarty_Internal_Templateparser::TP_SLOGOP;
} }
public function yy_r3_17() public function yy_r3_17()
{ {
$this->token = Smarty_Internal_Templateparser::TP_TLOGOP; $this->token = Smarty_Internal_Templateparser::TP_TLOGOP;
} }
public function yy_r3_20() public function yy_r3_20()
{ {
$this->token = Smarty_Internal_Templateparser::TP_SINGLECOND; $this->token = Smarty_Internal_Templateparser::TP_SINGLECOND;
} }
public function yy_r3_23() public function yy_r3_23()
{ {
$this->token = Smarty_Internal_Templateparser::TP_NOT; $this->token = Smarty_Internal_Templateparser::TP_NOT;
} }
public function yy_r3_24() public function yy_r3_24()
{ {
$this->token = Smarty_Internal_Templateparser::TP_TYPECAST; $this->token = Smarty_Internal_Templateparser::TP_TYPECAST;
} }
public function yy_r3_28() public function yy_r3_28()
{ {
$this->token = Smarty_Internal_Templateparser::TP_OPENP; $this->token = Smarty_Internal_Templateparser::TP_OPENP;
} }
public function yy_r3_29() public function yy_r3_29()
{ {
$this->token = Smarty_Internal_Templateparser::TP_CLOSEP; $this->token = Smarty_Internal_Templateparser::TP_CLOSEP;
} }
public function yy_r3_30() public function yy_r3_30()
{ {
$this->token = Smarty_Internal_Templateparser::TP_OPENB; $this->token = Smarty_Internal_Templateparser::TP_OPENB;
} }
public function yy_r3_31() public function yy_r3_31()
{ {
$this->token = Smarty_Internal_Templateparser::TP_CLOSEB; $this->token = Smarty_Internal_Templateparser::TP_CLOSEB;
} }
public function yy_r3_32() public function yy_r3_32()
{ {
$this->token = Smarty_Internal_Templateparser::TP_PTR; $this->token = Smarty_Internal_Templateparser::TP_PTR;
} }
public function yy_r3_33() public function yy_r3_33()
{ {
$this->token = Smarty_Internal_Templateparser::TP_APTR; $this->token = Smarty_Internal_Templateparser::TP_APTR;
} }
public function yy_r3_34() public function yy_r3_34()
{ {
$this->token = Smarty_Internal_Templateparser::TP_EQUAL; $this->token = Smarty_Internal_Templateparser::TP_EQUAL;
} }
public function yy_r3_35() public function yy_r3_35()
{ {
$this->token = Smarty_Internal_Templateparser::TP_INCDEC; $this->token = Smarty_Internal_Templateparser::TP_INCDEC;
} }
public function yy_r3_37() public function yy_r3_37()
{ {
$this->token = Smarty_Internal_Templateparser::TP_UNIMATH; $this->token = Smarty_Internal_Templateparser::TP_UNIMATH;
} }
public function yy_r3_39() public function yy_r3_39()
{ {
$this->token = Smarty_Internal_Templateparser::TP_MATH; $this->token = Smarty_Internal_Templateparser::TP_MATH;
} }
public function yy_r3_41() public function yy_r3_41()
{ {
$this->token = Smarty_Internal_Templateparser::TP_AT; $this->token = Smarty_Internal_Templateparser::TP_AT;
} }
public function yy_r3_42() public function yy_r3_42()
{ {
$this->token = Smarty_Internal_Templateparser::TP_HATCH;
}
$this->token = Smarty_Internal_Templateparser::TP_ARRAYOPEN;
}
public function yy_r3_43() public function yy_r3_43()
{ {
$this->token = Smarty_Internal_Templateparser::TP_HATCH;
}
public function yy_r3_44()
{
// resolve conflicts with shorttag and right_delimiter starting with '=' // resolve conflicts with shorttag and right_delimiter starting with '='
if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->compiler->getRdelLength()) === if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->compiler->getRdelLength()) === $this->smarty->getRightDelimiter()) {
$this->smarty->getRightDelimiter()) { preg_match('/\s+/',$this->value,$match);
preg_match('/\s+/', $this->value, $match); $this->value = $match[0];
$this->value = $match[ 0 ];
$this->token = Smarty_Internal_Templateparser::TP_SPACE; $this->token = Smarty_Internal_Templateparser::TP_SPACE;
} else { } else {
$this->token = Smarty_Internal_Templateparser::TP_ATTR; $this->token = Smarty_Internal_Templateparser::TP_ATTR;
} }
} }
public function yy_r3_45()
public function yy_r3_44()
{ {
$this->token = Smarty_Internal_Templateparser::TP_NAMESPACE; $this->token = Smarty_Internal_Templateparser::TP_NAMESPACE;
} }
public function yy_r3_47()
{
$this->token = Smarty_Internal_Templateparser::TP_ID;
}
public function yy_r3_48() public function yy_r3_48()
{ {
$this->token = Smarty_Internal_Templateparser::TP_INTEGER;
}
$this->token = Smarty_Internal_Templateparser::TP_ID;
}
public function yy_r3_49() public function yy_r3_49()
{ {
$this->token = Smarty_Internal_Templateparser::TP_INTEGER;
}
public function yy_r3_50()
{
$this->token = Smarty_Internal_Templateparser::TP_BACKTICK; $this->token = Smarty_Internal_Templateparser::TP_BACKTICK;
$this->yypopstate(); $this->yypopstate();
} }
public function yy_r3_50()
{
$this->token = Smarty_Internal_Templateparser::TP_VERT;
}
public function yy_r3_51() public function yy_r3_51()
{ {
$this->token = Smarty_Internal_Templateparser::TP_DOT;
}
$this->token = Smarty_Internal_Templateparser::TP_VERT;
}
public function yy_r3_52() public function yy_r3_52()
{ {
$this->token = Smarty_Internal_Templateparser::TP_COMMA;
}
$this->token = Smarty_Internal_Templateparser::TP_DOT;
}
public function yy_r3_53() public function yy_r3_53()
{ {
$this->token = Smarty_Internal_Templateparser::TP_SEMICOLON;
}
$this->token = Smarty_Internal_Templateparser::TP_COMMA;
}
public function yy_r3_54() public function yy_r3_54()
{ {
$this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON;
}
$this->token = Smarty_Internal_Templateparser::TP_SEMICOLON;
}
public function yy_r3_55() public function yy_r3_55()
{ {
$this->token = Smarty_Internal_Templateparser::TP_COLON;
}
$this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON;
}
public function yy_r3_56() public function yy_r3_56()
{ {
$this->token = Smarty_Internal_Templateparser::TP_QMARK;
}
$this->token = Smarty_Internal_Templateparser::TP_COLON;
}
public function yy_r3_57() public function yy_r3_57()
{ {
$this->token = Smarty_Internal_Templateparser::TP_HEX;
}
$this->token = Smarty_Internal_Templateparser::TP_QMARK;
}
public function yy_r3_58() public function yy_r3_58()
{ {
$this->token = Smarty_Internal_Templateparser::TP_SPACE;
} // end function
$this->token = Smarty_Internal_Templateparser::TP_HEX;
}
public function yy_r3_59() public function yy_r3_59()
{ {
$this->token = Smarty_Internal_Templateparser::TP_SPACE;
}
public function yy_r3_60()
{
$this->token = Smarty_Internal_Templateparser::TP_TEXT; $this->token = Smarty_Internal_Templateparser::TP_TEXT;
} }
public function yylex4() public function yylex4()
{ {
if (!isset($this->yy_global_pattern4)) { if (!isset($this->yy_global_pattern4)) {
$this->yy_global_pattern4 = $this->yy_global_pattern4 = $this->replace("/\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G([\S\s])/isS");
$this->replace("/\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((.*?)(?=(SMARTYldel)SMARTYal[\/]?literalSMARTYrdel))/isS");
} }
if (!isset($this->dataLength)) { if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data); $this->dataLength = strlen($this->data);
@@ -871,20 +883,18 @@ class Smarty_Internal_Templatelexer
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
return false; // end of input return false; // end of input
} }
do { do {
if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, 0, $this->counter)) { if (preg_match($this->yy_global_pattern4,$this->data, $yymatches, 0, $this->counter)) {
if (!isset($yymatches[ 0 ][ 1 ])) { if (!isset($yymatches[ 0 ][1])) {
$yymatches = preg_grep("/(.|\s)+/", $yymatches); $yymatches = preg_grep("/(.|\s)+/", $yymatches);
} else { } else {
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr( ' an empty string. Input "' . substr($this->data,
$this->data, $this->counter, 5) . '... state LITERAL');
$this->counter,
5
) . '... state LITERAL');
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -907,23 +917,26 @@ class Smarty_Internal_Templatelexer
} }
// skip this token // skip this token
continue; continue;
} } } else {
} else {
throw new Exception('Unexpected input at line' . $this->line . throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[ $this->counter ]); ': ' . $this->data[$this->counter]);
} }
break; break;
} while (true); } while (true);
}
} // end function
const LITERAL = 4;
public function yy_r4_1() public function yy_r4_1()
{ {
$this->literal_cnt++; $this->literal_cnt++;
$this->token = Smarty_Internal_Templateparser::TP_LITERAL; $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
} }
public function yy_r4_3() public function yy_r4_3()
{ {
if ($this->literal_cnt) { if ($this->literal_cnt) {
$this->literal_cnt--; $this->literal_cnt--;
$this->token = Smarty_Internal_Templateparser::TP_LITERAL; $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
@@ -932,17 +945,28 @@ class Smarty_Internal_Templatelexer
$this->yypopstate(); $this->yypopstate();
} }
} }
public function yy_r4_5() public function yy_r4_5()
{ {
if (!isset($this->yy_global_literal)) {
$this->yy_global_literal = $this->replace('/(SMARTYldel)SMARTYal[\/]?literalSMARTYrdel/isS');
}
$to = $this->dataLength;
preg_match($this->yy_global_literal, $this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
if (isset($match[0][1])) {
$to = $match[0][1];
} else {
$this->compiler->trigger_template_error ("missing or misspelled literal closing tag");
}
$this->value = substr($this->data,$this->counter,$to-$this->counter);
$this->token = Smarty_Internal_Templateparser::TP_LITERAL; $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
} // end function }
public function yylex5() public function yylex5()
{ {
if (!isset($this->yy_global_pattern5)) { if (!isset($this->yy_global_pattern5)) {
$this->yy_global_pattern5 = $this->yy_global_pattern5 = $this->replace("/\G((SMARTYldel)SMARTYautoliteral\\s+SMARTYliteral)|\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/])|\G((SMARTYldel)SMARTYal[0-9]*[a-zA-Z_]\\w*)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G([`][$])|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=((SMARTYldel)SMARTYal|\\$|`\\$|\"SMARTYliteral)))|\G([\S\s])/isS");
$this->replace("/\G((SMARTYldel)SMARTYautoliteral\\s+SMARTYliteral)|\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/])|\G((SMARTYldel)SMARTYal[0-9]*[a-zA-Z_]\\w*)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G([`][$])|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=((SMARTYldel)SMARTYal|\\$|`\\$|\"SMARTYliteral)))/isS");
} }
if (!isset($this->dataLength)) { if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data); $this->dataLength = strlen($this->data);
@@ -950,20 +974,18 @@ class Smarty_Internal_Templatelexer
if ($this->counter >= $this->dataLength) { if ($this->counter >= $this->dataLength) {
return false; // end of input return false; // end of input
} }
do { do {
if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, 0, $this->counter)) { if (preg_match($this->yy_global_pattern5,$this->data, $yymatches, 0, $this->counter)) {
if (!isset($yymatches[ 0 ][ 1 ])) { if (!isset($yymatches[ 0 ][1])) {
$yymatches = preg_grep("/(.|\s)+/", $yymatches); $yymatches = preg_grep("/(.|\s)+/", $yymatches);
} else { } else {
$yymatches = array_filter($yymatches); $yymatches = array_filter($yymatches);
} }
if (empty($yymatches)) { if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr( ' an empty string. Input "' . substr($this->data,
$this->data, $this->counter, 5) . '... state DOUBLEQUOTEDSTRING');
$this->counter,
5
) . '... state DOUBLEQUOTEDSTRING');
} }
next($yymatches); // skip global match next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -986,75 +1008,88 @@ class Smarty_Internal_Templatelexer
} }
// skip this token // skip this token
continue; continue;
} } } else {
} else {
throw new Exception('Unexpected input at line' . $this->line . throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[ $this->counter ]); ': ' . $this->data[$this->counter]);
} }
break; break;
} while (true); } while (true);
}
} // end function
const DOUBLEQUOTEDSTRING = 5;
public function yy_r5_1() public function yy_r5_1()
{ {
$this->token = Smarty_Internal_Templateparser::TP_TEXT; $this->token = Smarty_Internal_Templateparser::TP_TEXT;
} }
public function yy_r5_3() public function yy_r5_3()
{ {
$this->token = Smarty_Internal_Templateparser::TP_TEXT; $this->token = Smarty_Internal_Templateparser::TP_TEXT;
} }
public function yy_r5_5() public function yy_r5_5()
{ {
$this->token = Smarty_Internal_Templateparser::TP_TEXT; $this->token = Smarty_Internal_Templateparser::TP_TEXT;
} }
public function yy_r5_7() public function yy_r5_7()
{ {
$this->yypushstate(self::TAG); $this->yypushstate(self::TAG);
return true; return true;
} }
public function yy_r5_9() public function yy_r5_9()
{ {
$this->yypushstate(self::TAG); $this->yypushstate(self::TAG);
return true; return true;
} }
public function yy_r5_11() public function yy_r5_11()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LDEL; $this->token = Smarty_Internal_Templateparser::TP_LDEL;
$this->taglineno = $this->line; $this->taglineno = $this->line;
$this->yypushstate(self::TAGBODY); $this->yypushstate(self::TAGBODY);
} }
public function yy_r5_13() public function yy_r5_13()
{ {
$this->token = Smarty_Internal_Templateparser::TP_QUOTE; $this->token = Smarty_Internal_Templateparser::TP_QUOTE;
$this->yypopstate(); $this->yypopstate();
} }
public function yy_r5_14() public function yy_r5_14()
{ {
$this->token = Smarty_Internal_Templateparser::TP_BACKTICK; $this->token = Smarty_Internal_Templateparser::TP_BACKTICK;
$this->value = substr($this->value, 0, -1); $this->value = substr($this->value,0,-1);
$this->yypushstate(self::TAGBODY); $this->yypushstate(self::TAGBODY);
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
public function yy_r5_15() public function yy_r5_15()
{ {
$this->token = Smarty_Internal_Templateparser::TP_DOLLARID; $this->token = Smarty_Internal_Templateparser::TP_DOLLARID;
} }
public function yy_r5_16() public function yy_r5_16()
{ {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
public function yy_r5_17()
{
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
public function yy_r5_22()
{
$to = $this->dataLength;
$this->value = substr($this->data,$this->counter,$to-$this->counter);
$this->token = Smarty_Internal_Templateparser::TP_TEXT; $this->token = Smarty_Internal_Templateparser::TP_TEXT;
} }
public function yy_r5_17()
{
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
} }
}

File diff suppressed because it is too large Load Diff

View File

@@ -362,7 +362,6 @@ class Smarty_Internal_TestInstall
'smarty_internal_compile_function.php' => true, 'smarty_internal_compile_function.php' => true,
'smarty_internal_compile_if.php' => true, 'smarty_internal_compile_if.php' => true,
'smarty_internal_compile_include.php' => true, 'smarty_internal_compile_include.php' => true,
'smarty_internal_compile_include_php.php' => true,
'smarty_internal_compile_insert.php' => true, 'smarty_internal_compile_insert.php' => true,
'smarty_internal_compile_ldelim.php' => true, 'smarty_internal_compile_ldelim.php' => true,
'smarty_internal_compile_make_nocache.php' => true, 'smarty_internal_compile_make_nocache.php' => true,
@@ -373,7 +372,6 @@ class Smarty_Internal_TestInstall
'smarty_internal_compile_private_modifier.php' => true, 'smarty_internal_compile_private_modifier.php' => true,
'smarty_internal_compile_private_object_block_function.php' => true, 'smarty_internal_compile_private_object_block_function.php' => true,
'smarty_internal_compile_private_object_function.php' => true, 'smarty_internal_compile_private_object_function.php' => true,
'smarty_internal_compile_private_php.php' => true,
'smarty_internal_compile_private_print_expression.php' => true, 'smarty_internal_compile_private_print_expression.php' => true,
'smarty_internal_compile_private_registered_block.php' => true, 'smarty_internal_compile_private_registered_block.php' => true,
'smarty_internal_compile_private_registered_function.php' => true, 'smarty_internal_compile_private_registered_function.php' => true,
@@ -388,7 +386,6 @@ class Smarty_Internal_TestInstall
'smarty_internal_config_file_compiler.php' => true, 'smarty_internal_config_file_compiler.php' => true,
'smarty_internal_data.php' => true, 'smarty_internal_data.php' => true,
'smarty_internal_debug.php' => true, 'smarty_internal_debug.php' => true,
'smarty_internal_errorhandler.php' => true,
'smarty_internal_extension_handler.php' => true, 'smarty_internal_extension_handler.php' => true,
'smarty_internal_method_addautoloadfilters.php' => true, 'smarty_internal_method_addautoloadfilters.php' => true,
'smarty_internal_method_adddefaultmodifiers.php' => true, 'smarty_internal_method_adddefaultmodifiers.php' => true,
@@ -450,7 +447,6 @@ class Smarty_Internal_TestInstall
'smarty_internal_resource_extends.php' => true, 'smarty_internal_resource_extends.php' => true,
'smarty_internal_resource_file.php' => true, 'smarty_internal_resource_file.php' => true,
'smarty_internal_resource_php.php' => true, 'smarty_internal_resource_php.php' => true,
'smarty_internal_resource_registered.php' => true,
'smarty_internal_resource_stream.php' => true, 'smarty_internal_resource_stream.php' => true,
'smarty_internal_resource_string.php' => true, 'smarty_internal_resource_string.php' => true,
'smarty_internal_runtime_cachemodify.php' => true, 'smarty_internal_runtime_cachemodify.php' => true,

View File

@@ -72,9 +72,7 @@ abstract class Smarty_Resource
} }
// try registered resource // try registered resource
if (isset($smarty->registered_resources[ $type ])) { if (isset($smarty->registered_resources[ $type ])) {
return $smarty->_cache[ 'resource_handlers' ][ $type ] = return $smarty->_cache[ 'resource_handlers' ][ $type ] = $smarty->registered_resources[ $type ];
$smarty->registered_resources[ $type ] instanceof Smarty_Resource ?
$smarty->registered_resources[ $type ] : new Smarty_Internal_Resource_Registered();
} }
// try sysplugins dir // try sysplugins dir
if (isset(self::$sysplugins[ $type ])) { if (isset(self::$sysplugins[ $type ])) {

View File

@@ -21,19 +21,6 @@
*/ */
class Smarty_Security class Smarty_Security
{ {
/**
* This determines how Smarty handles "<?php ... ?>" tags in templates.
* possible values:
* <ul>
* <li>Smarty::PHP_PASSTHRU -> echo PHP tags as they are</li>
* <li>Smarty::PHP_QUOTE -> escape tags as entities</li>
* <li>Smarty::PHP_REMOVE -> remove php tags</li>
* <li>Smarty::PHP_ALLOW -> execute php tags</li>
* </ul>
*
* @var integer
*/
public $php_handling = Smarty::PHP_PASSTHRU;
/** /**
* This is the list of template directories that are considered secure. * This is the list of template directories that are considered secure.

View File

@@ -16,12 +16,12 @@ class SmartyCompilerException extends SmartyException
} }
/** /**
* The line number of the template error * @param int $line
*
* @type int|null
*/ */
public $line = null; public function setLine($line)
{
$this->line = $line;
}
/** /**
* The template source snippet relating to the error * The template source snippet relating to the error
* *

View File

@@ -1,5 +1,5 @@
$Id$ $Id$
Smarty version: 3.1.33 Smarty version: 4.1.1
( https://github.com/smarty-php/smarty/archive/v3.1.33.tar.gz )
https://github.com/smarty-php/smarty/archive/refs/tags/v4.1.1.tar.gz