bump Smarty to v3.1.32 (possible security fix, numerous bugs listed at https://github.com/smarty-php/smarty/blob/master/change_log.txt

pull/167/head
David Goodwin 7 years ago
parent 9a07772626
commit 2ba2802774

@ -14,13 +14,13 @@
* require_once '...path/Autoloader.php';
* Smarty_Autoloader::register();
* or
* include '...path/bootstarp.php';
* include '...path/bootstrap.php';
*
* $smarty = new Smarty();
*/
class Smarty_Autoloader
{
/**
/**
* Filepath to Smarty root
*
* @var string
@ -76,7 +76,7 @@ class Smarty_Autoloader
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_DIR . 'sysplugins' . DIRECTORY_SEPARATOR;
if (version_compare(phpversion(), '5.3.0', '>=')) {
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
} else {
spl_autoload_register(array(__CLASS__, 'autoload'));

File diff suppressed because it is too large Load Diff

@ -100,6 +100,8 @@ class SmartyBC extends Smarty
* @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)
{
@ -153,6 +155,8 @@ class SmartyBC extends Smarty
* @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)
{
@ -175,6 +179,8 @@ class SmartyBC extends Smarty
* @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)
{
@ -196,6 +202,8 @@ class SmartyBC extends Smarty
*
* @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)
{
@ -238,6 +246,8 @@ class SmartyBC extends Smarty
* to a template before compiling
*
* @param callable $function
*
* @throws \SmartyException
*/
public function register_prefilter($function)
{
@ -259,6 +269,8 @@ class SmartyBC extends Smarty
* to a compiled template after compilation
*
* @param callable $function
*
* @throws \SmartyException
*/
public function register_postfilter($function)
{
@ -280,6 +292,8 @@ class SmartyBC extends Smarty
* to a template output
*
* @param callable $function
*
* @throws \SmartyException
*/
public function register_outputfilter($function)
{
@ -301,6 +315,8 @@ class SmartyBC extends Smarty
*
* @param string $type filter type
* @param string $name filter name
*
* @throws \SmartyException
*/
public function load_filter($type, $name)
{
@ -341,7 +357,9 @@ class SmartyBC extends Smarty
* @param string $cache_id
* @param string $compile_id
*
* @return boolean
* @return bool
* @throws \Exception
* @throws \SmartyException
*/
public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
{
@ -377,7 +395,8 @@ class SmartyBC extends Smarty
*
* @param string $tpl_file
*
* @return boolean
* @return bool
* @throws \SmartyException
*/
public function template_exists($tpl_file)
{

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

@ -5,22 +5,21 @@
* @package Smarty
* @subpackage PluginsBlock
*/
/**
* Smarty {textformat}{/textformat} block plugin
* Type: block function<br>
* Name: textformat<br>
* Type: block function
* Name: textformat
* Purpose: format text a certain way with preset styles
* or custom wrap/indent settings<br>
* or custom wrap/indent settings
* Params:
* <pre>
*
* - style - string (email)
* - indent - integer (0)
* - wrap - integer (80)
* - wrap_char - string ("\n")
* - indent_char - string (" ")
* - wrap_boundary - boolean (true)
* </pre>
*
*
* @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat}
* (Smarty online manual)
@ -32,14 +31,16 @@
*
* @return string content re-formatted
* @author Monte Ohrt <monte at ohrt dot com>
* @throws \SmartyException
*/
function smarty_block_textformat($params, $content, $template, &$repeat)
function smarty_block_textformat($params, $content, Smarty_Internal_Template $template, &$repeat)
{
if (is_null($content)) {
return;
}
if (Smarty::$_MBSTRING && !is_callable('smarty_mb_wordwrap')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php');
if (Smarty::$_MBSTRING) {
$template->_checkPlugins(array(array('function' => 'smarty_modifier_mb_wordwrap',
'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php')));
}
$style = null;
@ -71,11 +72,11 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
break;
default:
trigger_error("textformat: unknown attribute '$_key'");
trigger_error("textformat: unknown attribute '{$_key}'");
}
}
if ($style == 'email') {
if ($style === 'email') {
$wrap = 72;
}
// split into paragraphs
@ -87,15 +88,17 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
}
// convert mult. spaces & special chars to single space
$_paragraph =
preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER),
array(' ', ''), $_paragraph);
preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER,
'!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER),
array(' ',
''), $_paragraph);
// indent first line
if ($indent_first > 0) {
$_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;
}
// wordwrap sentences
if (Smarty::$_MBSTRING) {
$_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
$_paragraph = smarty_modifier_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
} else {
$_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
}

@ -8,8 +8,8 @@
/**
* Smarty {counter} function plugin
* Type: function<br>
* Name: counter<br>
* Type: function
* Name: counter
* Purpose: print out a counter value
*
* @author Monte Ohrt <monte at ohrt dot com>
@ -63,7 +63,7 @@ function smarty_function_counter($params, $template)
$counter[ 'direction' ] = $params[ 'direction' ];
}
if ($counter[ 'direction' ] == "down") {
if ($counter[ 'direction' ] === 'down') {
$counter[ 'count' ] -= $counter[ 'skip' ];
} else {
$counter[ 'count' ] += $counter[ 'skip' ];

@ -8,12 +8,12 @@
/**
* Smarty {cycle} function plugin
* Type: function<br>
* Name: cycle<br>
* Date: May 3, 2002<br>
* Purpose: cycle through given values<br>
* Type: function
* Name: cycle
* Date: May 3, 2002
* Purpose: cycle through given values
* Params:
* <pre>
*
* - name - name of cycle (optional)
* - values - comma separated list of values to cycle, or an array of values to cycle
* (this can be left out for subsequent calls)
@ -22,13 +22,13 @@
* - advance - boolean - whether or not to advance the cycle
* - delimiter - the value delimiter, default is ","
* - assign - boolean, assigns to template var instead of printed.
* </pre>
* Examples:<br>
* <pre>
*
* Examples:
*
* {cycle values="#eeeeee,#d0d0d0d"}
* {cycle name=row values="one,two,three" reset=true}
* {cycle name=row}
* </pre>
*
*
* @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle}
* (Smarty online manual)
@ -55,12 +55,12 @@ function smarty_function_cycle($params, $template)
if (!isset($params[ 'values' ])) {
if (!isset($cycle_vars[ $name ][ 'values' ])) {
trigger_error("cycle: missing 'values' parameter");
trigger_error('cycle: missing \'values\' parameter');
return;
}
} else {
if (isset($cycle_vars[ $name ][ 'values' ]) && $cycle_vars[ $name ][ 'values' ] != $params[ 'values' ]) {
if (isset($cycle_vars[ $name ][ 'values' ]) && $cycle_vars[ $name ][ 'values' ] !== $params[ 'values' ]) {
$cycle_vars[ $name ][ 'index' ] = 0;
}
$cycle_vars[ $name ][ 'values' ] = $params[ 'values' ];

@ -8,8 +8,8 @@
/**
* Smarty {fetch} plugin
* Type: function<br>
* Name: fetch<br>
* Type: function
* Name: fetch
* Purpose: fetch file, web or ftp data and display results
*
* @link http://www.smarty.net/manual/en/language.function.fetch.php {fetch}
@ -25,7 +25,7 @@
function smarty_function_fetch($params, $template)
{
if (empty($params[ 'file' ])) {
trigger_error("[plugin] fetch parameter 'file' cannot be empty", E_USER_NOTICE);
trigger_error('[plugin] fetch parameter \'file\' cannot be empty', E_USER_NOTICE);
return;
}
@ -55,15 +55,15 @@ function smarty_function_fetch($params, $template)
}
$content = '';
if ($protocol == 'http') {
if ($protocol === 'http') {
// http fetch
if ($uri_parts = parse_url($params[ 'file' ])) {
// set defaults
$host = $server_name = $uri_parts[ 'host' ];
$timeout = 30;
$accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
$agent = "Smarty Template Engine " . Smarty::SMARTY_VERSION;
$referer = "";
$accept = 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*';
$agent = 'Smarty Template Engine ' . Smarty::SMARTY_VERSION;
$referer = '';
$uri = !empty($uri_parts[ 'path' ]) ? $uri_parts[ 'path' ] : '/';
$uri .= !empty($uri_parts[ 'query' ]) ? '?' . $uri_parts[ 'query' ] : '';
$_is_proxy = false;
@ -81,29 +81,29 @@ function smarty_function_fetch($params, $template)
// loop through parameters, setup headers
foreach ($params as $param_key => $param_value) {
switch ($param_key) {
case "file":
case "assign":
case "assign_headers":
case 'file':
case 'assign':
case 'assign_headers':
break;
case "user":
case 'user':
if (!empty($param_value)) {
$user = $param_value;
}
break;
case "pass":
case 'pass':
if (!empty($param_value)) {
$pass = $param_value;
}
break;
case "accept":
case 'accept':
if (!empty($param_value)) {
$accept = $param_value;
}
break;
case "header":
case 'header':
if (!empty($param_value)) {
if (!preg_match('![\w\d-]+: .+!', $param_value)) {
trigger_error("[plugin] invalid header format '" . $param_value . "'", E_USER_NOTICE);
trigger_error("[plugin] invalid header format '{$param_value}'", E_USER_NOTICE);
return;
} else {
@ -111,41 +111,41 @@ function smarty_function_fetch($params, $template)
}
}
break;
case "proxy_host":
case 'proxy_host':
if (!empty($param_value)) {
$proxy_host = $param_value;
}
break;
case "proxy_port":
case 'proxy_port':
if (!preg_match('!\D!', $param_value)) {
$proxy_port = (int) $param_value;
} else {
trigger_error("[plugin] invalid value for attribute '" . $param_key . "'", E_USER_NOTICE);
trigger_error("[plugin] invalid value for attribute '{$param_key }'", E_USER_NOTICE);
return;
}
break;
case "agent":
case 'agent':
if (!empty($param_value)) {
$agent = $param_value;
}
break;
case "referer":
case 'referer':
if (!empty($param_value)) {
$referer = $param_value;
}
break;
case "timeout":
case 'timeout':
if (!preg_match('!\D!', $param_value)) {
$timeout = (int) $param_value;
} else {
trigger_error("[plugin] invalid value for attribute '" . $param_key . "'", E_USER_NOTICE);
trigger_error("[plugin] invalid value for attribute '{$param_key}'", E_USER_NOTICE);
return;
}
break;
default:
trigger_error("[plugin] unrecognized attribute '" . $param_key . "'", E_USER_NOTICE);
trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE);
return;
}
@ -185,7 +185,7 @@ function smarty_function_fetch($params, $template)
}
}
if (!empty($user) && !empty($pass)) {
fputs($fp, "Authorization: BASIC " . base64_encode("$user:$pass") . "\r\n");
fputs($fp, 'Authorization: BASIC ' . base64_encode("$user:$pass") . "\r\n");
}
fputs($fp, "\r\n");

@ -5,22 +5,21 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {html_checkboxes} function plugin
* File: function.html_checkboxes.php<br>
* Type: function<br>
* Name: html_checkboxes<br>
* Date: 24.Feb.2003<br>
* Purpose: Prints out a list of checkbox input types<br>
* File: function.html_checkboxes.php
* Type: function
* Name: html_checkboxes
* Date: 24.Feb.2003
* Purpose: Prints out a list of checkbox input types
* Examples:
* <pre>
*
* {html_checkboxes values=$ids output=$names}
* {html_checkboxes values=$ids name='box' separator='<br>' output=$names}
* {html_checkboxes values=$ids checked=$checked separator='<br>' output=$names}
* </pre>
*
* Params:
* <pre>
*
* - name (optional) - string default "checkbox"
* - values (required) - array
* - options (optional) - associative array
@ -29,7 +28,7 @@
* - output (optional) - the output next to each checkbox
* - assign (optional) - assign the output as an array to this variable
* - escape (optional) - escape the content (not value), defaults to true
* </pre>
*
*
* @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
* (Smarty online manual)
@ -37,17 +36,17 @@
* @author credits to Monte Ohrt <monte at ohrt dot com>
* @version 1.0
*
* @param array $params parameters
* @param object $template template object
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
*
* @return string
* @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/
function smarty_function_html_checkboxes($params, $template)
function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template)
{
if (!is_callable('smarty_function_escape_special_chars')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
}
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$name = 'checkbox';
$values = null;
@ -89,11 +88,11 @@ function smarty_function_html_checkboxes($params, $template)
$selected = array();
foreach ($_val as $_sel) {
if (is_object($_sel)) {
if (method_exists($_sel, "__toString")) {
if (method_exists($_sel, '__toString')) {
$_sel = smarty_function_escape_special_chars((string) $_sel->__toString());
} else {
trigger_error("html_checkboxes: selected attribute contains an object of class '" .
get_class($_sel) . "' without __toString() method", E_USER_NOTICE);
trigger_error('html_checkboxes: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method', E_USER_NOTICE);
continue;
}
} else {
@ -102,11 +101,11 @@ function smarty_function_html_checkboxes($params, $template)
$selected[ $_sel ] = true;
}
} elseif (is_object($_val)) {
if (method_exists($_val, "__toString")) {
if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
} else {
trigger_error("html_checkboxes: selected attribute is an object of class '" . get_class($_val) .
"' without __toString() method", E_USER_NOTICE);
trigger_error('html_checkboxes: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method', E_USER_NOTICE);
}
} else {
$selected = smarty_function_escape_special_chars((string) $_val);
@ -129,7 +128,7 @@ function smarty_function_html_checkboxes($params, $template)
case 'readonly':
if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
trigger_error("html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute",
E_USER_NOTICE);
}
@ -145,7 +144,7 @@ function smarty_function_html_checkboxes($params, $template)
if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
} else {
trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
trigger_error("html_checkboxes: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
}
@ -178,18 +177,30 @@ function smarty_function_html_checkboxes($params, $template)
return implode("\n", $_html_result);
}
}
/**
* @param $name
* @param $value
* @param $output
* @param $selected
* @param $extra
* @param $separator
* @param $labels
* @param $label_ids
* @param bool $escape
*
* @return string
*/
function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels,
$label_ids, $escape = true)
$label_ids, $escape = true)
{
$_output = '';
if (is_object($value)) {
if (method_exists($value, "__toString")) {
if (method_exists($value, '__toString')) {
$value = (string) $value->__toString();
} else {
trigger_error("html_options: value is an object of class '" . get_class($value) .
"' without __toString() method", E_USER_NOTICE);
trigger_error('html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method', E_USER_NOTICE);
return '';
}
@ -198,11 +209,11 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
}
if (is_object($output)) {
if (method_exists($output, "__toString")) {
if (method_exists($output, '__toString')) {
$output = (string) $output->__toString();
} else {
trigger_error("html_options: output is an object of class '" . get_class($output) .
"' without __toString() method", E_USER_NOTICE);
trigger_error('html_options: output is an object of class \'' . get_class($output) .
'\' without __toString() method', E_USER_NOTICE);
return '';
}

@ -8,20 +8,20 @@
/**
* Smarty {html_image} function plugin
* Type: function<br>
* Name: html_image<br>
* Date: Feb 24, 2003<br>
* Purpose: format HTML tags for the image<br>
* Examples: {html_image file="/images/masthead.gif"}<br>
* Output: <img src="/images/masthead.gif" width=400 height=23><br>
* Type: function
* Name: html_image
* Date: Feb 24, 2003
* Purpose: format HTML tags for the image
* Examples: {html_image file="/images/masthead.gif"}
* Output: <img src="/images/masthead.gif" width=400 height=23>
* Params:
* <pre>
*
* - file - (required) - file (and path) of image
* - height - (optional) - image height (default actual height)
* - width - (optional) - image width (default actual width)
* - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT
* - path_prefix - prefix for path output (optional, default empty)
* </pre>
*
*
* @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image}
* (Smarty online manual)
@ -36,11 +36,10 @@
* @return string
* @uses smarty_function_escape_special_chars()
*/
function smarty_function_html_image($params, $template)
function smarty_function_html_image($params, Smarty_Internal_Template $template)
{
if (!is_callable('smarty_function_escape_special_chars')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
}
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$alt = '';
$file = '';
@ -66,7 +65,7 @@ function smarty_function_html_image($params, $template)
if (!is_array($_val)) {
$$_key = smarty_function_escape_special_chars($_val);
} else {
throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
throw new SmartyException ("html_image: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
@ -80,19 +79,19 @@ function smarty_function_html_image($params, $template)
if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
} else {
throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
throw new SmartyException ("html_image: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
}
}
if (empty($file)) {
trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);
trigger_error('html_image: missing \'file\' parameter', E_USER_NOTICE);
return;
}
if ($file[ 0 ] == '/') {
if ($file[ 0 ] === '/') {
$_image_path = $basedir . $file;
} else {
$_image_path = $file;
@ -126,15 +125,15 @@ function smarty_function_html_image($params, $template)
// FIXME: (rodneyrehm) getimagesize() loads the complete file off a remote resource, use custom [jpg,png,gif]header reader!
if (!$_image_data = @getimagesize($_image_path)) {
if (!file_exists($_image_path)) {
trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
trigger_error("html_image: unable to find '{$_image_path}'", E_USER_NOTICE);
return;
} elseif (!is_readable($_image_path)) {
trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
trigger_error("html_image: unable to read '{$_image_path}'", E_USER_NOTICE);
return;
} else {
trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
trigger_error("html_image: '{$_image_path}' is not a valid image file", E_USER_NOTICE);
return;
}

@ -5,15 +5,14 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {html_options} function plugin
* Type: function<br>
* Name: html_options<br>
* Type: function
* Name: html_options
* Purpose: Prints the list of <option> tags generated from
* the passed parameters<br>
* the passed parameters
* Params:
* <pre>
*
* - name (optional) - string default "select"
* - values (required) - if no options supplied) - array
* - options (required) - if no values supplied) - associative array
@ -21,23 +20,25 @@
* - output (required) - if not options supplied) - array
* - id (optional) - string default not set
* - class (optional) - string default not set
* </pre>
*
*
* @link http://www.smarty.net/manual/en/language.function.html.options.php {html_image}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de>
*
* @param array $params parameters
* @param array $params parameters
*
* @param \Smarty_Internal_Template $template
*
* @return string
* @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/
function smarty_function_html_options($params)
function smarty_function_html_options($params, Smarty_Internal_Template $template)
{
if (!is_callable('smarty_function_escape_special_chars')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
}
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$name = null;
$values = null;
@ -71,11 +72,11 @@ function smarty_function_html_options($params)
$selected = array();
foreach ($_val as $_sel) {
if (is_object($_sel)) {
if (method_exists($_sel, "__toString")) {
if (method_exists($_sel, '__toString')) {
$_sel = smarty_function_escape_special_chars((string) $_sel->__toString());
} else {
trigger_error("html_options: selected attribute contains an object of class '" .
get_class($_sel) . "' without __toString() method", E_USER_NOTICE);
trigger_error('html_options: selected attribute contains an object of class \'' .
get_class($_sel) . '\' without __toString() method', E_USER_NOTICE);
continue;
}
} else {
@ -84,11 +85,11 @@ function smarty_function_html_options($params)
$selected[ $_sel ] = true;
}
} elseif (is_object($_val)) {
if (method_exists($_val, "__toString")) {
if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
} else {
trigger_error("html_options: selected attribute is an object of class '" . get_class($_val) .
"' without __toString() method", E_USER_NOTICE);
trigger_error('html_options: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method', E_USER_NOTICE);
}
} else {
$selected = smarty_function_escape_special_chars((string) $_val);
@ -102,7 +103,7 @@ function smarty_function_html_options($params)
case 'readonly':
if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
trigger_error("html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute",
E_USER_NOTICE);
}
@ -118,7 +119,7 @@ function smarty_function_html_options($params)
if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
} else {
trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
trigger_error("html_options: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
}
@ -154,7 +155,16 @@ function smarty_function_html_options($params)
return $_html_result;
}
/**
* @param $key
* @param $value
* @param $selected
* @param $id
* @param $class
* @param $idx
*
* @return string
*/
function smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, &$idx)
{
if (!is_array($value)) {
@ -170,11 +180,11 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
$_html_class = !empty($class) ? ' class="' . $class . ' option"' : '';
$_html_id = !empty($id) ? ' id="' . $id . '-' . $idx . '"' : '';
if (is_object($value)) {
if (method_exists($value, "__toString")) {
if (method_exists($value, '__toString')) {
$value = smarty_function_escape_special_chars((string) $value->__toString());
} else {
trigger_error("html_options: value is an object of class '" . get_class($value) .
"' without __toString() method", E_USER_NOTICE);
trigger_error('html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method', E_USER_NOTICE);
return '';
}
@ -193,7 +203,16 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
return $_html_result;
}
/**
* @param $key
* @param $values
* @param $selected
* @param $id
* @param $class
* @param $idx
*
* @return string
*/
function smarty_function_html_options_optgroup($key, $values, $selected, $id, $class, &$idx)
{
$optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n";

@ -5,16 +5,15 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {html_radios} function plugin
* File: function.html_radios.php<br>
* Type: function<br>
* Name: html_radios<br>
* Date: 24.Feb.2003<br>
* Purpose: Prints out a list of radio input types<br>
* File: function.html_radios.php
* Type: function
* Name: html_radios
* Date: 24.Feb.2003
* Purpose: Prints out a list of radio input types
* Params:
* <pre>
*
* - name (optional) - string default "radio"
* - values (required) - array
* - options (required) - associative array
@ -23,13 +22,13 @@
* - output (optional) - the output next to each radio button
* - assign (optional) - assign the output as an array to this variable
* - escape (optional) - escape the content (not value), defaults to true
* </pre>
*
* Examples:
* <pre>
*
* {html_radios values=$ids output=$names}
* {html_radios values=$ids name='box' separator='<br>' output=$names}
* {html_radios values=$ids checked=$checked separator='<br>' output=$names}
* </pre>
*
*
* @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios}
* (Smarty online manual)
@ -42,12 +41,12 @@
*
* @return string
* @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/
function smarty_function_html_radios($params, $template)
function smarty_function_html_radios($params, Smarty_Internal_Template $template)
{
if (!is_callable('smarty_function_escape_special_chars')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
}
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$name = 'radio';
$values = null;
@ -72,11 +71,11 @@ function smarty_function_html_radios($params, $template)
if (is_array($_val)) {
trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING);
} elseif (is_object($_val)) {
if (method_exists($_val, "__toString")) {
if (method_exists($_val, '__toString')) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
} else {
trigger_error("html_radios: selected attribute is an object of class '" . get_class($_val) .
"' without __toString() method", E_USER_NOTICE);
trigger_error('html_radios: selected attribute is an object of class \'' . get_class($_val) .
'\' without __toString() method', E_USER_NOTICE);
}
} else {
$selected = (string) $_val;
@ -114,7 +113,7 @@ function smarty_function_html_radios($params, $template)
case 'readonly':
if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
trigger_error("html_options: {$_key} attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
E_USER_NOTICE);
}
@ -130,7 +129,7 @@ function smarty_function_html_radios($params, $template)
if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
} else {
trigger_error("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
trigger_error("html_radios: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
}
@ -165,18 +164,30 @@ function smarty_function_html_radios($params, $template)
return implode("\n", $_html_result);
}
}
/**
* @param $name
* @param $value
* @param $output
* @param $selected
* @param $extra
* @param $separator
* @param $labels
* @param $label_ids
* @param $escape
*
* @return string
*/
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids,
$escape)
$escape)
{
$_output = '';
if (is_object($value)) {
if (method_exists($value, "__toString")) {
if (method_exists($value, '__toString')) {
$value = (string) $value->__toString();
} else {
trigger_error("html_options: value is an object of class '" . get_class($value) .
"' without __toString() method", E_USER_NOTICE);
trigger_error('html_options: value is an object of class \'' . get_class($value) .
'\' without __toString() method', E_USER_NOTICE);
return '';
}
@ -185,11 +196,11 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
}
if (is_object($output)) {
if (method_exists($output, "__toString")) {
if (method_exists($output, '__toString')) {
$output = (string) $output->__toString();
} else {
trigger_error("html_options: output is an object of class '" . get_class($output) .
"' without __toString() method", E_USER_NOTICE);
trigger_error('html_options: output is an object of class \'' . get_class($output) .
'\' without __toString() method', E_USER_NOTICE);
return '';
}

@ -5,14 +5,13 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {html_select_date} plugin
* Type: function<br>
* Name: html_select_date<br>
* Type: function
* Name: html_select_date
* Purpose: Prints the dropdowns for date selection.
* ChangeLog:
* <pre>
*
* - 1.0 initial release
* - 1.1 added support for +/- N syntax for begin
* and end year values. (Monte)
@ -28,7 +27,7 @@
* of 0000-00-00 dates (cybot, boots)
* - 2.0 complete rewrite for performance,
* added attributes month_names, *_id
* </pre>
*
*
* @link http://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date}
* (Smarty online manual)
@ -37,18 +36,17 @@
* @author Monte Ohrt <monte at ohrt dot com>
* @author Rodney Rehm
*
* @param array $params parameters
* @param array $params parameters
*
* @param \Smarty_Internal_Template $template
*
* @return string
* @throws \SmartyException
*/
function smarty_function_html_select_date($params)
function smarty_function_html_select_date($params, Smarty_Internal_Template $template)
{
if (!is_callable('smarty_function_escape_special_chars')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
}
if (!is_callable('smarty_make_timestamp')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
}
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
// generate timestamps used for month names only
static $_month_timestamps = null;
static $_current_year = null;
@ -61,18 +59,18 @@ function smarty_function_html_select_date($params)
}
/* Default values. */
$prefix = "Date_";
$prefix = 'Date_';
$start_year = null;
$end_year = null;
$display_days = true;
$display_months = true;
$display_years = true;
$month_format = "%B";
$month_format = '%B';
/* Write months as numbers by default GL */
$month_value_format = "%m";
$day_format = "%02d";
$month_value_format = '%m';
$day_format = '%02d';
/* Write day values using this format MB */
$day_value_format = "%d";
$day_value_format = '%d';
$year_as_text = false;
/* Display years in reverse order? Ie. 2000,1999,.... */
$reverse_years = false;
@ -113,15 +111,17 @@ function smarty_function_html_select_date($params)
switch ($_key) {
case 'time':
if (!is_array($_value) && $_value !== null) {
$template->_checkPlugins(array(array('function' => 'smarty_make_timestamp',
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php')));
$time = smarty_make_timestamp($_value);
}
break;
case 'month_names':
if (is_array($_value) && count($_value) == 12) {
if (is_array($_value) && count($_value) === 12) {
$$_key = $_value;
} else {
trigger_error("html_select_date: month_names must be an array of 12 strings", E_USER_NOTICE);
trigger_error('html_select_date: month_names must be an array of 12 strings', E_USER_NOTICE);
}
break;
@ -166,7 +166,7 @@ function smarty_function_html_select_date($params)
if (!is_array($_value)) {
$extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"';
} else {
trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
trigger_error("html_select_date: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
}
@ -177,7 +177,9 @@ function smarty_function_html_select_date($params)
if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
if (isset($params[ 'time' ][ $prefix . 'Year' ])) {
// $_REQUEST[$field_array] given
foreach (array('Y' => 'Year', 'm' => 'Month', 'd' => 'Day') as $_elementKey => $_elementName) {
foreach (array('Y' => 'Year',
'm' => 'Month',
'd' => 'Day') as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName);
$$_variableName =
isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
@ -185,7 +187,9 @@ function smarty_function_html_select_date($params)
}
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Year' ])) {
// $_REQUEST given
foreach (array('Y' => 'Year', 'm' => 'Month', 'd' => 'Day') as $_elementKey => $_elementName) {
foreach (array('Y' => 'Year',
'm' => 'Month',
'd' => 'Day') as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName);
$$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
$params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
@ -206,14 +210,15 @@ function smarty_function_html_select_date($params)
// make syntax "+N" or "-N" work with $start_year and $end_year
// Note preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match) is slower than trim+substr
foreach (array('start', 'end') as $key) {
foreach (array('start',
'end') as $key) {
$key .= '_year';
$t = $$key;
if ($t === null) {
$$key = (int) $_current_year;
} elseif ($t[ 0 ] == '+') {
} elseif ($t[ 0 ] === '+') {
$$key = (int) ($_current_year + (int) trim(substr($t, 1)));
} elseif ($t[ 0 ] == '-') {
} elseif ($t[ 0 ] === '-') {
$$key = (int) ($_current_year - (int) trim(substr($t, 1)));
} else {
$$key = (int) $$key;
@ -301,8 +306,8 @@ function smarty_function_html_select_date($params)
for ($i = 1; $i <= 12; $i ++) {
$_val = sprintf('%02d', $i);
$_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[ $i ]) :
($month_format == "%m" ? $_val : strftime($month_format, $_month_timestamps[ $i ]));
$_value = $month_value_format == "%m" ? $_val : strftime($month_value_format, $_month_timestamps[ $i ]);
($month_format === '%m' ? $_val : strftime($month_format, $_month_timestamps[ $i ]));
$_value = $month_value_format === '%m' ? $_val : strftime($month_value_format, $_month_timestamps[ $i ]);
$_html_months .= '<option value="' . $_value . '"' . ($_val == $_month ? ' selected="selected"' : '') .
'>' . $_text . '</option>' . $option_separator;
}
@ -339,8 +344,8 @@ function smarty_function_html_select_date($params)
for ($i = 1; $i <= 31; $i ++) {
$_val = sprintf('%02d', $i);
$_text = $day_format == '%02d' ? $_val : sprintf($day_format, $i);
$_value = $day_value_format == '%02d' ? $_val : sprintf($day_value_format, $i);
$_text = $day_format === '%02d' ? $_val : sprintf($day_format, $i);
$_value = $day_value_format === '%02d' ? $_val : sprintf($day_value_format, $i);
$_html_days .= '<option value="' . $_value . '"' . ($_val == $_day ? ' selected="selected"' : '') . '>' .
$_text . '</option>' . $option_separator;
}

@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {html_select_time} function plugin
* Type: function<br>
* Name: html_select_time<br>
* Type: function
* Name: html_select_time
* Purpose: Prints the dropdowns for time selection
*
* @link http://www.smarty.net/manual/en/language.function.html.select.time.php {html_select_time}
@ -17,20 +16,19 @@
* @author Roberto Berto <roberto@berto.net>
* @author Monte Ohrt <monte AT ohrt DOT com>
*
* @param array $params parameters
* @param array $params parameters
*
* @param \Smarty_Internal_Template $template
*
* @return string
* @uses smarty_make_timestamp()
* @throws \SmartyException
*/
function smarty_function_html_select_time($params)
function smarty_function_html_select_time($params, Smarty_Internal_Template $template)
{
if (!is_callable('smarty_function_escape_special_chars')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
}
if (!is_callable('smarty_make_timestamp')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
}
$prefix = "Time_";
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$prefix = 'Time_';
$field_array = null;
$field_separator = "\n";
$option_separator = "\n";
@ -80,6 +78,8 @@ function smarty_function_html_select_time($params)
switch ($_key) {
case 'time':
if (!is_array($_value) && $_value !== null) {
$template->_checkPlugins(array(array('function' => 'smarty_make_timestamp',
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php')));
$time = smarty_make_timestamp($_value);
}
break;
@ -139,7 +139,7 @@ function smarty_function_html_select_time($params)
if (!is_array($_value)) {
$extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"';
} else {
trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
trigger_error("html_select_date: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
}
@ -148,7 +148,9 @@ function smarty_function_html_select_time($params)
if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
if (isset($params[ 'time' ][ $prefix . 'Hour' ])) {
// $_REQUEST[$field_array] given
foreach (array('H' => 'Hour', 'i' => 'Minute', 's' => 'Second') as $_elementKey => $_elementName) {
foreach (array('H' => 'Hour',
'i' => 'Minute',
's' => 'Second') as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName);
$$_variableName =
isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
@ -161,7 +163,9 @@ function smarty_function_html_select_time($params)
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Hour' ])) {
// $_REQUEST given
foreach (array('H' => 'Hour', 'i' => 'Minute', 's' => 'Second') as $_elementKey => $_elementName) {
foreach (array('H' => 'Hour',
'i' => 'Minute',
's' => 'Second') as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName);
$$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
$params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
@ -216,8 +220,8 @@ function smarty_function_html_select_time($params)
$end = $use_24_hours ? 23 : 12;
for ($i = $start; $i <= $end; $i ++) {
$_val = sprintf('%02d', $i);
$_text = $hour_format == '%02d' ? $_val : sprintf($hour_format, $i);
$_value = $hour_value_format == '%02d' ? $_val : sprintf($hour_value_format, $i);
$_text = $hour_format === '%02d' ? $_val : sprintf($hour_format, $i);
$_value = $hour_value_format === '%02d' ? $_val : sprintf($hour_value_format, $i);
if (!$use_24_hours) {
$_hour12 = $_hour == 0 ? 12 : ($_hour <= 12 ? $_hour : $_hour - 12);
@ -263,8 +267,8 @@ function smarty_function_html_select_time($params)
$selected = $_minute !== null ? ($_minute - $_minute % $minute_interval) : null;
for ($i = 0; $i <= 59; $i += $minute_interval) {
$_val = sprintf('%02d', $i);
$_text = $minute_format == '%02d' ? $_val : sprintf($minute_format, $i);
$_value = $minute_value_format == '%02d' ? $_val : sprintf($minute_value_format, $i);
$_text = $minute_format === '%02d' ? $_val : sprintf($minute_format, $i);
$_value = $minute_value_format === '%02d' ? $_val : sprintf($minute_value_format, $i);
$_html_minutes .= '<option value="' . $_value . '"' . ($selected === $i ? ' selected="selected"' : '') .
'>' . $_text . '</option>' . $option_separator;
}
@ -304,8 +308,8 @@ function smarty_function_html_select_time($params)
$selected = $_second !== null ? ($_second - $_second % $second_interval) : null;
for ($i = 0; $i <= 59; $i += $second_interval) {
$_val = sprintf('%02d', $i);
$_text = $second_format == '%02d' ? $_val : sprintf($second_format, $i);
$_value = $second_value_format == '%02d' ? $_val : sprintf($second_value_format, $i);
$_text = $second_format === '%02d' ? $_val : sprintf($second_format, $i);
$_value = $second_value_format === '%02d' ? $_val : sprintf($second_value_format, $i);
$_html_seconds .= '<option value="' . $_value . '"' . ($selected === $i ? ' selected="selected"' : '') .
'>' . $_text . '</option>' . $option_separator;
}
@ -350,7 +354,10 @@ function smarty_function_html_select_time($params)
}
$_html = '';
foreach (array('_html_hours', '_html_minutes', '_html_seconds', '_html_meridian') as $k) {
foreach (array('_html_hours',
'_html_minutes',
'_html_seconds',
'_html_meridian') as $k) {
if (isset($$k)) {
if ($_html) {
$_html .= $field_separator;

@ -8,12 +8,12 @@
/**
* Smarty {html_table} function plugin
* Type: function<br>
* Name: html_table<br>
* Date: Feb 17, 2003<br>
* Purpose: make an html table from an array of data<br>
* Type: function
* Name: html_table
* Date: Feb 17, 2003
* Purpose: make an html table from an array of data
* Params:
* <pre>
*
* - loop - array to loop through
* - cols - number of columns, comma separated list of column names
* or array of column names
@ -28,13 +28,13 @@
* - hdir - horizontal direction (default: "right", means left-to-right)
* - inner - inner loop (default "cols": print $loop line by line,
* $loop will be printed column by column otherwise)
* </pre>
*
* Examples:
* <pre>
*
* {table loop=$data}
* {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
* {table loop=$data cols="first,second,third" tr_attr=$colors}
* </pre>
*
*
* @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Messju Mohr <messju at lammfellpuschen dot de>
@ -127,7 +127,7 @@ function smarty_function_html_table($params)
}
if (is_array($cols)) {
$cols = ($hdir == 'right') ? $cols : array_reverse($cols);
$cols = ($hdir === 'right') ? $cols : array_reverse($cols);
$output .= "<thead><tr>\n";
for ($r = 0; $r < $cols_count; $r ++) {
@ -141,11 +141,11 @@ function smarty_function_html_table($params)
$output .= "<tbody>\n";
for ($r = 0; $r < $rows; $r ++) {
$output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
$rx = ($vdir == 'down') ? $r * $cols_count : ($rows - 1 - $r) * $cols_count;
$rx = ($vdir === 'down') ? $r * $cols_count : ($rows - 1 - $r) * $cols_count;
for ($c = 0; $c < $cols_count; $c ++) {
$x = ($hdir == 'right') ? $rx + $c : $rx + $cols_count - 1 - $c;
if ($inner != 'cols') {
$x = ($hdir === 'right') ? $rx + $c : $rx + $cols_count - 1 - $c;
if ($inner !== 'cols') {
/* shuffle x to loop over rows*/
$x = floor($x / $cols_count) + ($x % $cols_count) * $rows;
}
@ -163,7 +163,13 @@ function smarty_function_html_table($params)
return $output;
}
/**
* @param $name
* @param $var
* @param $no
*
* @return string
*/
function smarty_function_html_table_cycle($name, $var, $no)
{
if (!is_array($var)) {

@ -8,35 +8,35 @@
/**
* Smarty {mailto} function plugin
* Type: function<br>
* Name: mailto<br>
* Type: function
* Name: mailto
* Date: May 21, 2002
* Purpose: automate mailto address link creation, and optionally encode them.<br>
* Purpose: automate mailto address link creation, and optionally encode them.
* Params:
* <pre>
*
* - address - (required) - e-mail address
* - text - (optional) - text to display, default is address
* - encode - (optional) - can be one of:
* * none : no encoding (default)
* * javascript : encode with javascript
* * javascript_charcode : encode with javascript charcode
* * hex : encode with hexidecimal (no javascript)
* * hex : encode with hexadecimal (no javascript)
* - cc - (optional) - address(es) to carbon copy
* - bcc - (optional) - address(es) to blind carbon copy
* - subject - (optional) - e-mail subject
* - newsgroups - (optional) - newsgroup(s) to post to
* - followupto - (optional) - address(es) to follow up to
* - extra - (optional) - extra tags for the href link
* </pre>
*
* Examples:
* <pre>
*
* {mailto address="me@domain.com"}
* {mailto address="me@domain.com" encode="javascript"}
* {mailto address="me@domain.com" encode="hex"}
* {mailto address="me@domain.com" subject="Hello to you!"}
* {mailto address="me@domain.com" cc="you@domain.com,they@domain.com"}
* {mailto address="me@domain.com" extra='class="mailto"'}
* </pre>
*
*
* @link http://www.smarty.net/manual/en/language.function.mailto.php {mailto}
* (Smarty online manual)
@ -103,7 +103,7 @@ function smarty_function_mailto($params)
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>\');';
$js_encode = '';
@ -112,7 +112,7 @@ function smarty_function_mailto($params)
}
return '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>';
} elseif ($encode == 'javascript_charcode') {
} elseif ($encode === 'javascript_charcode') {
$string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
for ($x = 0, $y = strlen($string); $x < $y; $x ++) {
@ -123,7 +123,7 @@ function smarty_function_mailto($params)
implode(',', $ord) . "))" . "}\n" . "</script>\n";
return $_ret;
} elseif ($encode == 'hex') {
} elseif ($encode === 'hex') {
preg_match('!^(.*)(\?.*)$!', $address, $match);
if (!empty($match[ 2 ])) {
trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.", E_USER_WARNING);

@ -9,8 +9,8 @@
/**
* Smarty {math} function plugin
* Type: function<br>
* Name: math<br>
* Type: function
* Name: math
* Purpose: handle math computations in template
*
* @link http://www.smarty.net/manual/en/language.function.math.php {math}
@ -38,7 +38,7 @@ function smarty_function_math($params, $template)
$equation = $params[ 'equation' ];
// 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);
return;
@ -59,9 +59,9 @@ function smarty_function_math($params, $template)
}
foreach ($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') {
// make sure value is not empty
if (strlen($val) == 0) {
if (strlen($val) === 0) {
trigger_error("math: parameter '{$key}' is empty", E_USER_WARNING);
return;
@ -86,7 +86,7 @@ function smarty_function_math($params, $template)
}
foreach ($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') {
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
}
}

@ -8,8 +8,8 @@
/**
* Smarty capitalize modifier plugin
* Type: modifier<br>
* Name: capitalize<br>
* Type: modifier
* Name: capitalize
* Purpose: capitalize words in the string
* {@internal {$string|capitalize:true:true} is the fastest option for MBString enabled systems }}
*
@ -72,7 +72,7 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
return $upper_string;
}
/*
/*
*
* Bug: create_function() use exhausts memory when used in long loops
* Fix: use declared functions for callbacks instead of using create_function()
@ -80,21 +80,38 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
*
* @author Kyle Renfrow
*/
/**
* @param $matches
*
* @return string
*/
function smarty_mod_cap_mbconvert_cb($matches)
{
return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 2 ]), MB_CASE_UPPER, Smarty::$_CHARSET);
}
/**
* @param $matches
*
* @return string
*/
function smarty_mod_cap_mbconvert2_cb($matches)
{
return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 3 ]), MB_CASE_UPPER, Smarty::$_CHARSET);
}
/**
* @param $matches
*
* @return string
*/
function smarty_mod_cap_ucfirst_cb($matches)
{
return stripslashes($matches[ 1 ]) . ucfirst(stripslashes($matches[ 2 ]));
}
/**
* @param $matches
*
* @return string
*/
function smarty_mod_cap_ucfirst2_cb($matches)
{
return stripslashes($matches[ 1 ]) . ucfirst(stripslashes($matches[ 3 ]));

@ -8,10 +8,10 @@
/**
* Smarty date_format modifier plugin
* Type: modifier<br>
* Name: date_format<br>
* Purpose: format datestamps via strftime<br>
* Input:<br>
* Type: modifier
* Name: date_format
* Purpose: format datestamps via strftime
* Input:
* - string: input date string
* - format: strftime format for output
* - default_date: default date if $string is empty
@ -35,20 +35,36 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
/**
* require_once the {@link shared.make_timestamp.php} plugin
*/
if (!is_callable('smarty_make_timestamp')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
static $is_loaded = false;
if (!$is_loaded) {
if (!is_callable('smarty_make_timestamp')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
}
$is_loaded = true;
}
if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') {
if ($string !== '' && $string !== '0000-00-00' && $string !== '0000-00-00 00:00:00') {
$timestamp = smarty_make_timestamp($string);
} elseif ($default_date != '') {
} elseif ($default_date !== '') {
$timestamp = smarty_make_timestamp($default_date);
} else {
return;
}
if ($formatter == 'strftime' || ($formatter == 'auto' && strpos($format, '%') !== false)) {
if ($formatter === 'strftime' || ($formatter === 'auto' && strpos($format, '%') !== false)) {
if (Smarty::$_IS_WINDOWS) {
$_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
$_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
$_win_from = array('%D',
'%h',
'%n',
'%r',
'%R',
'%t',
'%T');
$_win_to = array('%m/%d/%y',
'%b',
"\n",
'%I:%M:%S %p',
'%H:%M',
"\t",
'%H:%M:%S');
if (strpos($format, '%e') !== false) {
$_win_from[] = '%e';
$_win_to[] = sprintf('%\' 2d', date('j', $timestamp));

@ -8,8 +8,8 @@
/**
* Smarty debug_print_var modifier plugin
* Type: modifier<br>
* Name: debug_print_var<br>
* Type: modifier
* Name: debug_print_var
* Purpose: formats variable contents for display in the console
*
* @author Monte Ohrt <monte at ohrt dot com>
@ -28,7 +28,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
switch (gettype($var)) {
case 'array' :
$results = '<b>Array (' . count($var) . ')</b>';
if ($depth == $max) {
if ($depth === $max) {
break;
}
foreach ($var as $curr_key => $curr_val) {
@ -46,7 +46,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$results .= ' called recursive';
break;
}
if ($depth == $max) {
if ($depth === $max) {
break;
}
$objects[] = $var;

@ -8,8 +8,8 @@
/**
* Smarty escape modifier plugin
* Type: modifier<br>
* Name: escape<br>
* Type: modifier
* Name: escape
* Purpose: escape string for output
*
* @link http://www.smarty.net/docs/en/language.modifier.escape
@ -25,6 +25,8 @@
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true)
{
static $_double_encode = null;
static $is_loaded_1 = false;
static $is_loaded_2 = false;
if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
}
@ -46,7 +48,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// php <5.2.3 - prevent double encoding
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
$string = str_replace(array('%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'), array('&',
';'), $string);
return $string;
}
@ -67,7 +71,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
$string =
str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
str_replace(array('%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'), array('&',
';'), $string);
return $string;
}
@ -86,7 +92,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
} else {
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlentities($string, ENT_QUOTES, $char_set);
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
$string = str_replace(array('%%%SMARTY_START%%%',
'%%%SMARTY_END%%%'), array('&',
';'), $string);
return $string;
}
@ -116,8 +124,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
case 'hexentity':
$return = '';
if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
}
$is_loaded_1 = true;
}
$return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
@ -137,8 +148,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
case 'decentity':
$return = '';
if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
}
$is_loaded_1 = true;
}
$return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
@ -157,25 +171,39 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
case 'javascript':
// escape quotes and backslashes, newlines, etc.
return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n',
return strtr($string, array('\\' => '\\\\',
"'" => "\\'",
'"' => '\\"',
"\r" => '\\r',
"\n" => '\\n',
'</' => '<\/'));
case 'mail':
if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
if (!$is_loaded_2) {
if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
}
$is_loaded_2 = true;
}
return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
return smarty_mb_str_replace(array('@',
'.'), array(' [AT] ',
' [DOT] '), $string);
}
// no MBString fallback
return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
return str_replace(array('@',
'.'), array(' [AT] ',
' [DOT] '), $string);
case 'nonstd':
// escape non-standard chars, such as ms document quotes
$return = '';
if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
}
$is_loaded_1 = true;
}
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
if ($unicode >= 126) {

@ -0,0 +1,75 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty wordwrap modifier plugin
* Type: modifier
* Name: mb_wordwrap
* Purpose: Wrap a string to a given number of characters
*
* @link http://php.net/manual/en/function.wordwrap.php for similarity
*
* @param string $str the string to wrap
* @param int $width the width of the output
* @param string $break the character used to break the line
* @param boolean $cut ignored parameter, just for the sake of
*
* @return string wrapped string
* @author Rodney Rehm
*/
function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = false)
{
// break words into tokens using white space as a delimiter
$tokens = preg_split('!(\s)!S' . Smarty::$_UTF8_MODIFIER, $str, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
$length = 0;
$t = '';
$_previous = false;
$_space = false;
foreach ($tokens as $_token) {
$token_length = mb_strlen($_token, Smarty::$_CHARSET);
$_tokens = array($_token);
if ($token_length > $width) {
if ($cut) {
$_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER,
$_token,
-1,
PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
}
}
foreach ($_tokens as $token) {
$_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token);
$token_length = mb_strlen($token, Smarty::$_CHARSET);
$length += $token_length;
if ($length > $width) {
// remove space before inserted break
if ($_previous) {
$t = mb_substr($t, 0, -1, Smarty::$_CHARSET);
}
if (!$_space) {
// add the break before the token
if (!empty($t)) {
$t .= $break;
}
$length = $token_length;
}
} else if ($token === "\n") {
// hard break must reset counters
$length = 0;
}
$_previous = $_space;
// add the token
$t .= $token;
}
}
return $t;
}

@ -1,55 +0,0 @@
<?php
/**
* Smarty shared plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Function: smarty_needle
* Purpose: Used to find a string in a string
* Options: enter "case" to make case senstative
* Example: needle( 'Gabe-was-here', 'here' ) returns true
* Example2: needle( 'Gabe was here', 'gabe' ) returns true
* Example: needle ('Gabe was there', 'sde') returns false
* Smarty Sample: {$haystack|needle:"string"}
* Smarty Sample: {$haystack|needle:"string":"case"}
* @author Gabe LeBlanc "raven"
* @param string
* @return boolean
*/
function smarty_modifier_needle($haystack, $needle, $cases = "nocase") {
if(!empty($haystack) ) {
if($cases == "nocase") {
if(stristr($haystack, $needle)) {
return true;
}else{
return false;
}
}elseif($cases == "case") {
if(strstr($haystack, $needle)) {
return true;
}else{
return false;
}
}
}else{
return false;
}
}
?>

@ -8,8 +8,8 @@
/**
* Smarty regex_replace modifier plugin
* Type: modifier<br>
* Name: regex_replace<br>
* Type: modifier
* Name: regex_replace
* Purpose: regular expression search/replace
*
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php

@ -8,8 +8,8 @@
/**
* Smarty replace modifier plugin
* Type: modifier<br>
* Name: replace<br>
* Type: modifier
* Name: replace
* Purpose: simple search/replace
*
* @link http://smarty.php.net/manual/en/language.modifier.replace.php replace (Smarty online manual)
@ -24,11 +24,15 @@
*/
function smarty_modifier_replace($string, $search, $replace)
{
static $is_loaded = false;
if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
if (!$is_loaded) {
if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
}
$is_loaded = true;
}
return smarty_mb_str_replace($search, $replace, $string);
return smarty_mb_str_replace($search, $replace, $string);
}
return str_replace($search, $replace, $string);

@ -8,8 +8,8 @@
/**
* Smarty spacify modifier plugin
* Type: modifier<br>
* Name: spacify<br>
* Type: modifier
* Name: spacify
* Purpose: add spaces between characters in a string
*
* @link http://smarty.php.net/manual/en/language.modifier.spacify.php spacify (Smarty online manual)

@ -8,8 +8,8 @@
/**
* Smarty truncate modifier plugin
* Type: modifier<br>
* Name: truncate<br>
* Type: modifier
* Name: truncate
* Purpose: Truncate a string to a certain length if necessary,
* optionally splitting in the middle of a word, and
* appending the $etc string or inserting $etc into the middle.
@ -27,7 +27,7 @@
*/
function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
{
if ($length == 0) {
if ($length === 0) {
return '';
}

@ -8,11 +8,11 @@
/**
* Smarty cat modifier plugin
* Type: modifier<br>
* Name: cat<br>
* Date: Feb 24, 2003<br>
* Purpose: catenate a value to a variable<br>
* Input: string to catenate<br>
* Type: modifier
* Name: cat
* Date: Feb 24, 2003
* Purpose: catenate a value to a variable
* Input: string to catenate
* Example: {$var|cat:"foo"}
*
* @link http://smarty.php.net/manual/en/language.modifier.cat.php cat

@ -8,8 +8,8 @@
/**
* Smarty count_characters modifier plugin
* Type: modifier<br>
* Name: count_characteres<br>
* Type: modifier
* Name: count_characters
* Purpose: count the number of characters in a text
*
* @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual)
@ -21,7 +21,7 @@
*/
function smarty_modifiercompiler_count_characters($params)
{
if (!isset($params[ 1 ]) || $params[ 1 ] != 'true') {
if (!isset($params[ 1 ]) || $params[ 1 ] !== 'true') {
return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[ 0 ] . ', $tmp)';
}
if (Smarty::$_MBSTRING) {

@ -8,8 +8,8 @@
/**
* Smarty count_paragraphs modifier plugin
* Type: modifier<br>
* Name: count_paragraphs<br>
* Type: modifier
* Name: count_paragraphs
* Purpose: count the number of paragraphs in a text
*
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php

@ -8,7 +8,7 @@
/**
* Smarty count_sentences modifier plugin
* Type: modifier<br>
* Type: modifier
* Name: count_sentences
* Purpose: count the number of sentences in a text
*

@ -8,8 +8,8 @@
/**
* Smarty count_words modifier plugin
* Type: modifier<br>
* Name: count_words<br>
* Type: modifier
* Name: count_words
* 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)

@ -8,8 +8,8 @@
/**
* Smarty default modifier plugin
* Type: modifier<br>
* Name: default<br>
* Type: modifier
* Name: default
* Purpose: designate default value for empty variables
*
* @link http://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual)

@ -5,27 +5,27 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty escape modifier plugin
* Type: modifier<br>
* Name: escape<br>
* Type: modifier
* Name: escape
* Purpose: escape string for output
*
* @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
* @author Rodney Rehm
*
* @param array $params parameters
* @param $compiler
* @param array $params parameters
* @param Smarty_Internal_TemplateCompilerBase $compiler
*
* @return string with compiled code
* @throws \SmartyException
*/
function smarty_modifiercompiler_escape($params, $compiler)
function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompilerBase $compiler)
{
static $_double_encode = null;
if (!is_callable('smarty_literal_compiler_param')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php');
}
static $is_loaded = false;
$compiler->template->_checkPlugins(array(array('function' => 'smarty_literal_compiler_param',
'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php')));
if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
}
@ -100,14 +100,14 @@ function smarty_modifiercompiler_escape($params, $compiler)
// could not optimize |escape call, so fallback to regular plugin
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
$compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] =
$compiler->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] =
SMARTY_PLUGINS_DIR . 'modifier.escape.php';
$compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'function' ] =
$compiler->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'function' ] =
'smarty_modifier_escape';
} else {
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'file' ] =
$compiler->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'file' ] =
SMARTY_PLUGINS_DIR . 'modifier.escape.php';
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] =
$compiler->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] =
'smarty_modifier_escape';
}

@ -8,8 +8,8 @@
/**
* Smarty from_charset modifier plugin
* Type: modifier<br>
* Name: from_charset<br>
* Type: modifier
* Name: from_charset
* Purpose: convert character encoding from $charset to internal encoding
*
* @author Rodney Rehm

@ -8,8 +8,8 @@
/**
* Smarty indent modifier plugin
* Type: modifier<br>
* Name: indent<br>
* Type: modifier
* Name: indent
* Purpose: indent lines of text
*
* @link http://www.smarty.net/manual/en/language.modifier.indent.php indent (Smarty online manual)

@ -8,8 +8,8 @@
/**
* Smarty lower modifier plugin
* Type: modifier<br>
* Name: lower<br>
* Type: modifier
* Name: lower
* Purpose: convert string to lowercase
*
* @link http://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual)

@ -8,8 +8,8 @@
/**
* Smarty noprint modifier plugin
* Type: modifier<br>
* Name: noprint<br>
* Type: modifier
* Name: noprint
* Purpose: return an empty string
*
* @author Uwe Tews

@ -8,8 +8,8 @@
/**
* Smarty string_format modifier plugin
* Type: modifier<br>
* Name: string_format<br>
* Type: modifier
* Name: string_format
* Purpose: format strings via sprintf
*
* @link http://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual)

@ -8,11 +8,11 @@
/**
* Smarty strip modifier plugin
* Type: modifier<br>
* Name: strip<br>
* Type: modifier
* Name: strip
* Purpose: Replace all repeated spaces, newlines, tabs
* with a single space or supplied replacement string.<br>
* Example: {$var|strip} {$var|strip:"&nbsp;"}<br>
* with a single space or supplied replacement string.
* Example: {$var|strip} {$var|strip:"&nbsp;"}
* Date: September 25th, 2002
*
* @link http://www.smarty.net/manual/en/language.modifier.strip.php strip (Smarty online manual)

@ -8,8 +8,8 @@
/**
* Smarty strip_tags modifier plugin
* Type: modifier<br>
* Name: strip_tags<br>
* Type: modifier
* Name: strip_tags
* Purpose: strip html tags from text
*
* @link http://www.smarty.net/docs/en/language.modifier.strip.tags.tpl strip_tags (Smarty online manual)
@ -21,7 +21,7 @@
*/
function smarty_modifiercompiler_strip_tags($params)
{
if (!isset($params[ 1 ]) || $params[ 1 ] === true || trim($params[ 1 ], '"') == 'true') {
if (!isset($params[ 1 ]) || $params[ 1 ] === true || trim($params[ 1 ], '"') === 'true') {
return "preg_replace('!<[^>]*?>!', ' ', {$params[0]})";
} else {
return 'strip_tags(' . $params[ 0 ] . ')';

@ -8,8 +8,8 @@
/**
* Smarty to_charset modifier plugin
* Type: modifier<br>
* Name: to_charset<br>
* Type: modifier
* Name: to_charset
* Purpose: convert character encoding from internal encoding to $charset
*
* @author Rodney Rehm

@ -8,8 +8,8 @@
/**
* Smarty unescape modifier plugin
* Type: modifier<br>
* Name: unescape<br>
* Type: modifier
* Name: unescape
* Purpose: unescape html entities
*
* @author Rodney Rehm
@ -26,7 +26,7 @@ function smarty_modifiercompiler_unescape($params)
if (!isset($params[ 2 ])) {
$params[ 2 ] = '\'' . addslashes(Smarty::$_CHARSET) . '\'';
} else {
$params[ 2 ] = "'" . $params[ 2 ] . "'";
$params[ 2 ] = "'{$params[ 2 ]}'";
}
switch (trim($params[ 1 ], '"\'')) {

@ -8,8 +8,8 @@
/**
* Smarty upper modifier plugin
* Type: modifier<br>
* Name: lower<br>
* Type: modifier
* Name: lower
* Purpose: convert string to uppercase
*
* @link http://smarty.php.net/manual/en/language.modifier.upper.php lower (Smarty online manual)

@ -5,22 +5,22 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty wordwrap modifier plugin
* Type: modifier<br>
* Name: wordwrap<br>
* Type: modifier
* Name: wordwrap
* 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)
* @author Uwe Tews
*
* @param array $params parameters
* @param $compiler
* @param array $params parameters
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*
* @return string with compiled code
* @throws \SmartyException
*/
function smarty_modifiercompiler_wordwrap($params, $compiler)
function smarty_modifiercompiler_wordwrap($params, Smarty_Internal_TemplateCompilerBase $compiler)
{
if (!isset($params[ 1 ])) {
$params[ 1 ] = 80;
@ -33,19 +33,7 @@ function smarty_modifiercompiler_wordwrap($params, $compiler)
}
$function = 'wordwrap';
if (Smarty::$_MBSTRING) {
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
$compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'wordwrap' ][ 'modifier' ][ 'file' ] =
SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
$compiler->template->required_plugins[ 'nocache' ][ 'wordwrap' ][ 'modifier' ][ 'function' ] =
'smarty_mb_wordwrap';
} else {
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'wordwrap' ][ 'modifier' ][ 'file' ] =
SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'wordwrap' ][ 'modifier' ][ 'function' ] =
'smarty_mb_wordwrap';
}
$function = 'smarty_mb_wordwrap';
$function = $compiler->getPlugin('mb_wordwrap','modifier');
}
return $function . '(' . $params[ 0 ] . ',' . $params[ 1 ] . ',' . $params[ 2 ] . ',' . $params[ 3 ] . ')';
}

@ -24,7 +24,7 @@ function smarty_outputfilter_trimwhitespace($source)
$_offset = 0;
// Unify Line-Breaks to \n
$source = preg_replace("/\015\012|\015|\012/", "\n", $source);
$source = preg_replace('/\015\012|\015|\012/', "\n", $source);
// capture Internet Explorer and KnockoutJS Conditional Comments
if (preg_match_all('#<!--((\[[^\]]+\]>.*?<!\[[^\]]+\])|(\s*/?ko\s+.+))-->#is', $source, $matches,

@ -8,7 +8,7 @@
/**
* escape_special_chars common function
* Function: smarty_function_escape_special_chars<br>
* Function: smarty_function_escape_special_chars
* Purpose: used by other smarty functions to escape
* special chars except for already escaped ones
*

@ -7,7 +7,7 @@
*/
/**
* Function: smarty_make_timestamp<br>
* Function: smarty_make_timestamp
* Purpose: used by other smarty functions to make a timestamp from a string.
*
* @author Monte Ohrt <monte at ohrt dot com>
@ -25,7 +25,7 @@ function smarty_make_timestamp($string)
(interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)
) {
return (int) $string->format('U'); // PHP 5.2 BC
} elseif (strlen($string) == 14 && ctype_digit($string)) {
} elseif (strlen($string) === 14 && ctype_digit($string)) {
// it is mysql timestamp format of YYYYMMDDHHMMSS?
return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), substr($string, 4, 2),
substr($string, 6, 2), substr($string, 0, 4));
@ -35,7 +35,7 @@ function smarty_make_timestamp($string)
} else {
// strtotime should handle it
$time = strtotime($string);
if ($time == - 1 || $time === false) {
if ($time === - 1 || $time === false) {
// strtotime() was not able to parse $string, use "now":
return time();
}

@ -6,14 +6,13 @@
* @subpackage PluginsShared
*/
if (!function_exists('smarty_mb_str_replace')) {
/**
* Multibyte string replace
*
* @param string $search the string to be searched
* @param string $replace the replacement string
* @param string $subject the source string
* @param int &$count number of matches found
* @param string|string[] $search the string to be searched
* @param string|string[] $replace the replacement string
* @param string $subject the source string
* @param int &$count number of matches found
*
* @return string replaced string
* @author Rodney Rehm
@ -29,7 +28,7 @@ if (!function_exists('smarty_mb_str_replace')) {
$string = smarty_mb_str_replace($search, $replace, $string, $c);
$count += $c;
}
} elseif (is_array($search)) {
} else if (is_array($search)) {
if (!is_array($replace)) {
foreach ($search as &$string) {
$subject = smarty_mb_str_replace($string, $replace, $subject, $c);
@ -37,7 +36,7 @@ if (!function_exists('smarty_mb_str_replace')) {
}
} else {
$n = max(count($search), count($replace));
while ($n --) {
while ($n--) {
$subject = smarty_mb_str_replace(current($search), current($replace), $subject, $c);
$count += $c;
next($search);
@ -49,7 +48,6 @@ if (!function_exists('smarty_mb_str_replace')) {
$count = count($parts) - 1;
$subject = implode($replace, $parts);
}
return $subject;
}
}

@ -20,12 +20,12 @@
function smarty_mb_to_unicode($string, $encoding = null)
{
if ($encoding) {
$expanded = mb_convert_encoding($string, "UTF-32BE", $encoding);
$expanded = mb_convert_encoding($string, 'UTF-32BE', $encoding);
} else {
$expanded = mb_convert_encoding($string, "UTF-32BE");
$expanded = mb_convert_encoding($string, 'UTF-32BE');
}
return unpack("N*", $expanded);
return unpack('N*', $expanded);
}
/**
@ -46,8 +46,8 @@ function smarty_mb_from_unicode($unicode, $encoding = null)
$encoding = mb_internal_encoding();
}
foreach ((array) $unicode as $utf32be) {
$character = pack("N*", $utf32be);
$t .= mb_convert_encoding($character, $encoding, "UTF-32BE");
$character = pack('N*', $utf32be);
$t .= mb_convert_encoding($character, $encoding, 'UTF-32BE');
}
return $t;

@ -1,75 +0,0 @@
<?php
/**
* Smarty shared plugin
*
* @package Smarty
* @subpackage PluginsShared
*/
if (!function_exists('smarty_mb_wordwrap')) {
/**
* Wrap a string to a given number of characters
*
* @link http://php.net/manual/en/function.wordwrap.php for similarity
*
* @param string $str the string to wrap
* @param int $width the width of the output
* @param string $break the character used to break the line
* @param boolean $cut ignored parameter, just for the sake of
*
* @return string wrapped string
* @author Rodney Rehm
*/
function smarty_mb_wordwrap($str, $width = 75, $break = "\n", $cut = false)
{
// break words into tokens using white space as a delimiter
$tokens =
preg_split('!(\s)!S' . Smarty::$_UTF8_MODIFIER, $str, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
$length = 0;
$t = '';
$_previous = false;
$_space = false;
foreach ($tokens as $_token) {
$token_length = mb_strlen($_token, Smarty::$_CHARSET);
$_tokens = array($_token);
if ($token_length > $width) {
if ($cut) {
$_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1,
PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
}
}
foreach ($_tokens as $token) {
$_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token);
$token_length = mb_strlen($token, Smarty::$_CHARSET);
$length += $token_length;
if ($length > $width) {
// remove space before inserted break
if ($_previous) {
$t = mb_substr($t, 0, - 1, Smarty::$_CHARSET);
}
if (!$_space) {
// add the break before the token
if (!empty($t)) {
$t .= $break;
}
$length = $token_length;
}
} elseif ($token == "\n") {
// hard break must reset counters
$_previous = 0;
$length = 0;
}
$_previous = $_space;
// add the token
$t .= $token;
}
}
return $t;
}
}

@ -5,15 +5,15 @@
* @package Smarty
* @subpackage PluginsFilter
*/
/**
* Smarty htmlspecialchars variablefilter plugin
*
* @param string $source input string
* @param string $source input string
* @param \Smarty_Internal_Template $template
*
* @return string filtered output
*/
function smarty_variablefilter_htmlspecialchars($source)
function smarty_variablefilter_htmlspecialchars($source, Smarty_Internal_Template $template)
{
return htmlspecialchars($source, ENT_QUOTES, Smarty::$_CHARSET);
}

@ -138,7 +138,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
$_smarty_tpl->compile_id, $content, $timestamp);
}
if (isset($content)) {
eval("?>" . $content);
eval('?>' . $content);
$cached->content = null;
return true;
}
@ -204,7 +204,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
* @param string $compile_id compile id
* @param integer $exp_time expiration time (number of seconds, not timestamp)
*
* @return integer number of cache files deleted
* @return int number of cache files deleted
* @throws \SmartyException
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{

@ -104,7 +104,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
}
}
if (isset($content)) {
eval("?>" . $content);
eval('?>' . $content);
return true;
}
@ -180,7 +180,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* @param string $compile_id compile id
* @param integer $exp_time expiration time [being ignored]
*
* @return integer number of cache files deleted [always -1]
* @return int number of cache files deleted [always -1]
* @throws \SmartyException
* @uses buildCachedFilepath() to generate the CacheID
* @uses invalidate() to mark CacheIDs parent chain as outdated
* @uses delete() to remove CacheID from cache
@ -272,8 +273,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*/
protected function addMetaTimestamp(&$content)
{
$mt = explode(" ", microtime());
$ts = pack("NN", $mt[ 1 ], (int) ($mt[ 0 ] * 100000000));
$mt = explode(' ', microtime());
$ts = pack('NN', $mt[ 1 ], (int) ($mt[ 0 ] * 100000000));
$content = $ts . $content;
}
@ -370,7 +371,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Translate a CacheID into the list of applicable InvalidationKeys.
* Splits "some|chain|into|an|array" into array( '#clearAll#', 'some', 'some|chain', 'some|chain|into', ... )
* Splits 'some|chain|into|an|array' into array( '#clearAll#', 'some', 'some|chain', 'some|chain|into', ... )
*
* @param string $cid CacheID to translate
* @param string $resource_name template name

@ -61,8 +61,8 @@ class Smarty_Data extends Smarty_Internal_Data
foreach ($_parent as $_key => $_val) {
$this->tpl_vars[ $_key ] = new Smarty_Variable($_val);
}
} elseif ($_parent != null) {
throw new SmartyException("Wrong type for template variables");
} elseif ($_parent !== null) {
throw new SmartyException('Wrong type for template variables');
}
}
}

@ -38,7 +38,7 @@ class Smarty_Internal_Block
public $prepend = false;
/**
* Block calls {$smarty.block.child}
* Block calls $smarty.block.child
*
* @var bool
*/
@ -67,7 +67,7 @@ class Smarty_Internal_Block
/**
* Smarty_Internal_Block constructor.
* - if outer level {block} of child template ($state == 1) save it as child root block
* - if outer level {block} of child template ($state === 1) save it as child root block
* - otherwise process inheritance and render
*
* @param string $name block name

@ -7,7 +7,6 @@
* @author Uwe Tews
* @author Rodney Rehm
*/
/**
* This class does contain all necessary methods for the HTML cache on file system
* Implements the file system as resource for the HTML cache Version ussing nocache inserts.
@ -29,11 +28,14 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
{
$source = &$_template->source;
$smarty = &$_template->smarty;
$_compile_dir_sep = $smarty->use_sub_dirs ? $smarty->ds : '^';
$_compile_dir_sep = $smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';
$_filepath = sha1($source->uid . $smarty->_joined_template_dir);
$cached->filepath = $smarty->getCacheDir();
if (isset($_template->cache_id)) {
$cached->filepath .= preg_replace(array('![^\w|]+!', '![|]+!'), array('_', $_compile_dir_sep),
$cached->filepath .= preg_replace(array('![^\w|]+!',
'![|]+!'),
array('_',
$_compile_dir_sep),
$_template->cache_id) . $_compile_dir_sep;
}
if (isset($_template->compile_id)) {
@ -41,8 +43,10 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
}
// if use_sub_dirs, break file into directories
if ($smarty->use_sub_dirs) {
$cached->filepath .= $_filepath[ 0 ] . $_filepath[ 1 ] . $smarty->ds . $_filepath[ 2 ] . $_filepath[ 3 ] . $smarty->ds .
$_filepath[ 4 ] . $_filepath[ 5 ] . $smarty->ds;
$cached->filepath .= $_filepath[ 0 ] . $_filepath[ 1 ] . DIRECTORY_SEPARATOR . $_filepath[ 2 ] .
$_filepath[ 3 ] .
DIRECTORY_SEPARATOR .
$_filepath[ 4 ] . $_filepath[ 5 ] . DIRECTORY_SEPARATOR;
}
$cached->filepath .= $_filepath;
$basename = $source->handler->getBasename($source);
@ -83,12 +87,13 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Template_Cached $cached = null,
public function process(Smarty_Internal_Template $_smarty_tpl,
Smarty_Template_Cached $cached = null,
$update = false)
{
$_smarty_tpl->cached->valid = false;
if ($update && defined('HHVM_VERSION')) {
eval("?>" . file_get_contents($_smarty_tpl->cached->filepath));
eval('?>' . file_get_contents($_smarty_tpl->cached->filepath));
return true;
} else {
return @include $_smarty_tpl->cached->filepath;
@ -101,16 +106,20 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @return boolean success
* @return bool success
* @throws \SmartyException
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content,
if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath,
$content,
$_template->smarty) === true
) {
if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) {
if (function_exists('opcache_invalidate') &&
(!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api'))) < 1
) {
opcache_invalidate($_template->cached->filepath, true);
} elseif (function_exists('apc_compile_file')) {
} else if (function_exists('apc_compile_file')) {
apc_compile_file($_template->cached->filepath);
}
$cached = $_template->cached;

@ -24,6 +24,7 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{

@ -71,7 +71,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
$_scope = $compiler->convertScope($_attr, $this->valid_scopes);
}
// optional parameter
$_params = "";
$_params = '';
if ($_nocache || $_scope) {
$_params .= ' ,' . var_export($_nocache, true);
}
@ -85,9 +85,9 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
$output .= "settype(\$_tmp_array, 'array');\n";
$output .= "}\n";
$output .= "\$_tmp_array{$parameter['smarty_internal_index']} = {$_attr['value']};\n";
$output .= "\$_smarty_tpl->_assignInScope({$_var}, \$_tmp_array{$_params});\n?>";
$output .= "\$_smarty_tpl->_assignInScope({$_var}, \$_tmp_array{$_params});?>";
} else {
$output = "<?php \$_smarty_tpl->_assignInScope({$_var}, {$_attr['value']}{$_params});\n?>";
$output = "<?php \$_smarty_tpl->_assignInScope({$_var}, {$_attr['value']}{$_params});?>";
}
return $output;
}

@ -22,7 +22,6 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -30,7 +29,6 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -38,7 +36,6 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @see Smarty_Internal_CompileBase
*/
public $option_flags = array('hide', 'nocache');
/**
* Attribute definition: Overwrites base class.
*
@ -47,13 +44,6 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
*/
public $optional_attributes = array('assign');
/**
* Saved compiler object
*
* @var Smarty_Internal_TemplateCompilerBase
*/
public $compiler = null;
/**
* Compiles code for the {block} tag
*
@ -61,14 +51,13 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return bool true
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
if (!isset($compiler->_cache[ 'blockNesting' ])) {
$compiler->_cache[ 'blockNesting' ] = 0;
}
if ($compiler->_cache[ 'blockNesting' ] == 0) {
if ($compiler->_cache[ 'blockNesting' ] === 0) {
// make sure that inheritance gets initialized in template code
$this->registerInit($compiler);
$this->option_flags = array('hide', 'nocache', 'append', 'prepend');
@ -77,30 +66,24 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
}
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$compiler->_cache[ 'blockNesting' ] ++;
++$compiler->_cache[ 'blockNesting' ];
$_className = 'Block_' . preg_replace('![^\w]+!', '_', uniqid(rand(), true));
$compiler->_cache[ 'blockName' ][ $compiler->_cache[ 'blockNesting' ] ] = $_attr[ 'name' ];
$compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ] = $_className;
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ] = array();
$compiler->_cache[ 'blockParams' ][ 1 ][ 'subBlocks' ][ trim($_attr[ 'name' ], '"\'') ][] = $_className;
$this->openTag($compiler, 'block', array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
$compiler->template->compiled->has_nocache_code,
$compiler->template->caching));
// must whole block be nocache ?
if ($compiler->tag_nocache) {
$i = 0;
}
$this->openTag($compiler,
'block',
array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
$compiler->template->compiled->has_nocache_code,
$compiler->template->caching));
$compiler->saveRequiredPlugins(true);
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
// $compiler->suppressNocacheProcessing = true;
if ($_attr[ 'nocache' ] === true) {
//$compiler->trigger_template_error('nocache option not allowed', $compiler->parser->lex->taglineno);
}
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$compiler->template->compiled->has_nocache_code = false;
$compiler->suppressNocacheProcessing = true;
}
}
/**
* Smarty Internal Plugin Compile BlockClose Class
*
@ -126,7 +109,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null;
unset($_attr[ 'assign' ], $_attr[ 'name' ]);
foreach ($_attr as $name => $stat) {
if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat != 'false')) {
if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat !== 'false')) {
$_block[ $name ] = 'true';
}
}
@ -144,7 +127,8 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$output .= "public \${$property} = " . var_export($value,true) .";\n";
}
$output .= "public function callBlock(Smarty_Internal_Template \$_smarty_tpl) {\n";
//$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n";
$output .= $compiler->compileRequiredPlugins();
$compiler->restoreRequiredPlugins();
if ($compiler->template->compiled->has_nocache_code) {
$output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n";
}
@ -167,32 +151,22 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->blockOrFunctionCode .= $f = $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
$compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
// nocache plugins must be copied
if (!empty($compiler->template->compiled->required_plugins[ 'nocache' ])) {
foreach ($compiler->template->compiled->required_plugins[ 'nocache' ] as $plugin => $tmp) {
foreach ($tmp as $type => $data) {
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin ][ $type ] =
$data;
}
}
}
// restore old status
$compiler->template->compiled->has_nocache_code = $_has_nocache_code;
$compiler->tag_nocache = $compiler->nocache;
$compiler->nocache = $_nocache;
$compiler->parser->current_buffer = $_buffer;
$output = "<?php \n";
if ($compiler->_cache[ 'blockNesting' ] == 1) {
if ($compiler->_cache[ 'blockNesting' ] === 1) {
$output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n";
} else {
$output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name, \$this->tplIndex);\n";
}
$output .= "?>\n";
$compiler->_cache[ 'blockNesting' ] --;
if ($compiler->_cache[ 'blockNesting' ] == 0) {
--$compiler->_cache[ 'blockNesting' ];
if ($compiler->_cache[ 'blockNesting' ] === 0) {
unset($compiler->_cache[ 'blockNesting' ]);
}
$compiler->has_code = true;

@ -9,46 +9,16 @@
*/
/**
* Smarty Internal Plugin Compile Block Parent Class
* Smarty Internal Plugin Compile Block Child Class
*
* @author Uwe Tews <uwe.tews@googlemail.com>
*/
class Smarty_Internal_Compile_Block_Child extends Smarty_Internal_CompileBase
class Smarty_Internal_Compile_Block_Child extends Smarty_Internal_Compile_Child
{
/**
* Attribute definition: Overwrites base class.
* Tag name
*
* @var array
* @see Smarty_Internal_CompileBase
* @var string
*/
public $option_flags = array();
/**
* Saved compiler object
*
* @var Smarty_Internal_TemplateCompilerBase
*/
public $compiler = null;
/**
* Compiles code for the {block_parent} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return bool true
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
if (!isset($compiler->_cache[ 'blockNesting' ])) {
$compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ',
$compiler->parser->lex->taglineno);
}
$compiler->has_code = true;
$compiler->suppressNocacheProcessing = true;
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 'callsChild' ] = 'true';
$output = "<?php \n\$_smarty_tpl->inheritance->callChild(\$_smarty_tpl, \$this);\n?>\n";
return $output;
}
public $tag = 'block_child';
}

@ -13,61 +13,19 @@
*
* @author Uwe Tews <uwe.tews@googlemail.com>
*/
class Smarty_Internal_Compile_Block_Parent extends Smarty_Internal_Compile_Shared_Inheritance
class Smarty_Internal_Compile_Block_Parent extends Smarty_Internal_Compile_Child
{
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('name');
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('name');
/**
* Attribute definition: Overwrites base class.
* Tag name
*
* @var array
* @see Smarty_Internal_CompileBase
* @var string
*/
public $option_flags = array();
public $tag = 'block_parent';
/**
* Saved compiler object
*
* @var Smarty_Internal_TemplateCompilerBase
*/
public $compiler = null;
/**
* Compiles code for the {block_parent} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* Block type
*
* @return bool true
* @var string
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if (!isset($compiler->_cache[ 'blockNesting' ])) {
$compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ',
$compiler->parser->lex->taglineno);
}
$compiler->suppressNocacheProcessing = true;
$compiler->has_code = true;
$output = "<?php \n\$_smarty_tpl->inheritance->callParent(\$_smarty_tpl, \$this" .
(isset($_attr[ 'name' ]) ? ", {$_attr[ 'name' ]}" : '') . ");\n?>\n";
return $output;
}
public $blockType = 'Parent';
}

@ -32,25 +32,35 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
*/
public $shorttag_order = array('levels');
/**
* Tag name may be overloaded by Smarty_Internal_Compile_Continue
*
* @var string
*/
public $tag = 'break';
/**
* Compiles code for the {break} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
list($levels, $foreachLevels) = $this->checkLevels($args, $compiler);
$output = "<?php\n";
if ($foreachLevels) {
$output = "<?php ";
if ($foreachLevels > 0 && $this->tag === 'continue') {
$foreachLevels--;
}
if ($foreachLevels > 0) {
/* @var Smarty_Internal_Compile_Foreach $foreachCompiler */
$foreachCompiler = $compiler->getTagCompiler('foreach');
$output .= $foreachCompiler->compileRestore($foreachLevels);
}
$output .= "break {$levels};?>";
$output .= "{$this->tag} {$levels};?>";
return $output;
}
@ -59,12 +69,11 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param string $tag tag name
*
* @return array
* @throws \SmartyCompilerException
*/
public function checkLevels($args, Smarty_Internal_TemplateCompilerBase $compiler, $tag = 'break')
public function checkLevels($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
// check and get attributes
@ -86,7 +95,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
$stack_count = count($compiler->_tag_stack) - 1;
$foreachLevels = 0;
$lastTag = '';
while ($level_count >= 0 && $stack_count >= 0) {
while ($level_count > 0 && $stack_count >= 0) {
if (isset($_is_loopy[ $compiler->_tag_stack[ $stack_count ][ 0 ] ])) {
$lastTag = $compiler->_tag_stack[ $stack_count ][ 0 ];
if ($level_count === 0) {
@ -99,10 +108,10 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
}
$stack_count --;
}
if ($level_count != 0) {
$compiler->trigger_template_error("cannot {$tag} {$levels} level(s)", null, true);
if ($level_count !== 0) {
$compiler->trigger_template_error("cannot {$this->tag} {$levels} level(s)", null, true);
}
if ($lastTag === 'foreach' && $tag === 'break') {
if ($lastTag === 'foreach' && $this->tag === 'break' && $foreachLevels > 0) {
$foreachLevels --;
}
return array($levels, $foreachLevels);

@ -57,7 +57,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
// output will be stored in a smarty variable instead of being displayed
$_assign = $_attr[ 'assign' ];
}
//$_name = trim($_attr['name'], "'\"");
//$_name = trim($_attr['name'], "''");
$_name = $_attr[ 'name' ];
unset($_attr[ 'name' ], $_attr[ 'assign' ], $_attr[ 'nocache' ]);
// set flag (compiled code of {function} must be included in cache file
@ -74,7 +74,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
$_paramsArray[] = "'$_key'=>$_value";
}
}
$_params = 'array(' . implode(",", $_paramsArray) . ')';
$_params = 'array(' . implode(',', $_paramsArray) . ')';
//$compiler->suppressNocacheProcessing = true;
// was there an assign attribute
if (isset($_assign)) {

@ -45,11 +45,11 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
{
$tag = trim($parameter[ 0 ], '"\'');
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false;
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : null;
if (!$name) {
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
//$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
}
return "\$_smarty_tpl->smarty->ext->_capture->getBuffer(\$_smarty_tpl, '{$name}')";
return '$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl'.(isset($name)?", '{$name}')":')');
}
/**

@ -0,0 +1,77 @@
<?php
/*
* This file is part of Smarty.
*
* (c) 2015 Uwe Tews
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Smarty Internal Plugin Compile Child Class
*
* @author Uwe Tews <uwe.tews@googlemail.com>
*/
class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
{
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('assign');
/**
* Tag name
*
* @var string
*/
public $tag = 'child';
/**
* Block type
*
* @var string
*/
public $blockType = 'Child';
/**
* Compiles code for the {child} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$tag = isset($parameter[0]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'";
if (!isset($compiler->_cache[ 'blockNesting' ])) {
$compiler->trigger_template_error("{$tag} used outside {block} tags ",
$compiler->parser->lex->taglineno);
}
$compiler->has_code = true;
$compiler->suppressNocacheProcessing = true;
if ($this->blockType === 'Child') {
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 'callsChild' ] = 'true';
}
$_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null;
$output = "<?php \n";
if (isset($_assign)) {
$output .= "ob_start();\n";
}
$output .= '$_smarty_tpl->inheritance->call' . $this->blockType . '($_smarty_tpl, $this' .
($this->blockType === 'Child' ? '' : ", {$tag}"). ");\n";
if (isset($_assign)) {
$output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
}
$output .="?>\n";
return $output;
}
}

@ -16,27 +16,10 @@
*/
class Smarty_Internal_Compile_Continue extends Smarty_Internal_Compile_Break
{
/**
* Compiles code for the {continue} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
list($levels, $foreachLevels) = $this->checkLevels($args, $compiler, 'continue');
$output = "<?php\n";
if ($foreachLevels > 1) {
/* @var Smarty_Internal_Compile_Foreach $foreachCompiler */
$foreachCompiler = $compiler->getTagCompiler('foreach');
$output .= $foreachCompiler->compileRestore($foreachLevels - 1);
}
$output .= "continue {$levels};?>";
return $output;
}
* Tag name
*
* @var string
*/
public $tag = 'continue';
}

@ -58,13 +58,12 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
}
// create template object
$_output = "\$_template = new {$compiler->smarty->template_class}('eval:'." . $_attr[ 'var' ] .
", \$_smarty_tpl->smarty, \$_smarty_tpl);";
$_output = "\$_template = new {$compiler->smarty->template_class}('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->smarty, \$_smarty_tpl);";
//was there an assign attribute?
if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
} else {
$_output .= "echo \$_template->fetch();";
$_output .= 'echo $_template->fetch();';
}
return "<?php $_output ?>";

@ -64,18 +64,18 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
// add code to initialize inheritance
$this->registerInit($compiler, true);
$file = trim($_attr[ 'file' ], '\'"');
if (strlen($file) > 8 && substr($file, 0, 8) == 'extends:') {
if (strlen($file) > 8 && substr($file, 0, 8) === 'extends:') {
// generate code for each template
$files = array_reverse(explode('|', substr($file, 8)));
$i = 0;
foreach ($files as $file) {
if ($file[ 0 ] == '"') {
if ($file[ 0 ] === '"') {
$file = trim($file, '".');
} else {
$file = "'{$file}'";
}
$i ++;
if ($i == count($files) && isset($_attr[ 'extends_resource' ])) {
if ($i === count($files) && isset($_attr[ 'extends_resource' ])) {
$this->compileEndChild($compiler);
}
$this->compileInclude($compiler, $file);
@ -95,21 +95,24 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param null|string $template optional inheritance parent template
*
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler, $template = null)
{
$inlineUids = '';
if (isset($template) && $compiler->smarty->merge_compiled_includes) {
$code = $compiler->compileTag('include', array($template, array('scope' => 'parent')));
if (preg_match("/([,][\s]*['][a-z0-9]+['][,][\s]*[']content.*['])[)]/", $code, $match)) {
if (preg_match('/([,][\s]*[\'][a-z0-9]+[\'][,][\s]*[\']content.*[\'])[)]/', $code, $match)) {
$inlineUids = $match[ 1 ];
}
}
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
"<?php \$_smarty_tpl->inheritance->endChild(\$_smarty_tpl" .
'<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl' .
(isset($template) ?
', ' . $template . $inlineUids :
'') . ");\n?>\n");
", {$template}{$inlineUids}" :
'') . ");\n?>");
}
/**
@ -117,6 +120,9 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param string $template subtemplate name
*
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $template)
{
@ -129,16 +135,17 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
/**
* Create source code for {extends} from source components array
*
* @param []\Smarty_Internal_Template_Source $components
* @param \Smarty_Internal_Template $template
*
* @return string
*/
public static function extendsSourceArrayCode($components)
public static function extendsSourceArrayCode(Smarty_Internal_Template $template)
{
$resources = array();
foreach ($components as $source) {
foreach ($template->source->components as $source) {
$resources[] = $source->resource;
}
return '{extends file=\'extends:' . join('|', $resources) . '\' extends_resource=true}';
return $template->smarty->left_delimiter . 'extends file=\'extends:' . join('|', $resources) .
'\' extends_resource=true' . $template->smarty->right_delimiter;
}
}

@ -35,7 +35,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
public function compile($args, $compiler, $parameter)
{
$compiler->loopNesting ++;
if ($parameter == 0) {
if ($parameter === 0) {
$this->required_attributes = array('start', 'to');
$this->optional_attributes = array('max', 'step');
} else {
@ -47,7 +47,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
$_attr = $this->getAttributes($compiler, $args);
$output = "<?php\n";
if ($parameter == 1) {
if ($parameter === 1) {
foreach ($_attr[ 'start' ] as $_statement) {
if (is_array($_statement[ 'var' ])) {
$var = $_statement[ 'var' ][ 'var' ];
@ -89,10 +89,10 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
}
$output .= "if (\$_smarty_tpl->tpl_vars[$var]->total > 0) {\n";
$output .= "for (\$_smarty_tpl->tpl_vars[$var]->value{$index} = $_statement[value], \$_smarty_tpl->tpl_vars[$var]->iteration = 1;\$_smarty_tpl->tpl_vars[$var]->iteration <= \$_smarty_tpl->tpl_vars[$var]->total;\$_smarty_tpl->tpl_vars[$var]->value{$index} += \$_smarty_tpl->tpl_vars[$var]->step, \$_smarty_tpl->tpl_vars[$var]->iteration++) {\n";
$output .= "\$_smarty_tpl->tpl_vars[$var]->first = \$_smarty_tpl->tpl_vars[$var]->iteration == 1;";
$output .= "\$_smarty_tpl->tpl_vars[$var]->last = \$_smarty_tpl->tpl_vars[$var]->iteration == \$_smarty_tpl->tpl_vars[$var]->total;";
$output .= "\$_smarty_tpl->tpl_vars[$var]->first = \$_smarty_tpl->tpl_vars[$var]->iteration === 1;";
$output .= "\$_smarty_tpl->tpl_vars[$var]->last = \$_smarty_tpl->tpl_vars[$var]->iteration === \$_smarty_tpl->tpl_vars[$var]->total;";
}
$output .= "?>";
$output .= '?>';
$this->openTag($compiler, 'for', array('for', $compiler->nocache));
// maybe nocache because of nocache variables
@ -161,10 +161,10 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse'));
$output = "<?php }\n";
if ($openTag != 'forelse') {
if ($openTag !== 'forelse') {
$output .= "}\n";
}
$output .= "?>\n";
$output .= "?>";
return $output;
}
}

@ -78,14 +78,14 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
/**
* Compiles code for the {foreach} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$compiler->loopNesting ++;
// init
@ -118,7 +118,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
$fromName = $compiler->getVariableName($_attr[ 'from' ]);
if ($fromName) {
foreach (array('item', 'key') as $a) {
if (isset($attributes[ $a ]) && $attributes[ $a ] == $fromName) {
if (isset($attributes[ $a ]) && $attributes[ $a ] === $fromName) {
$compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'",
null, true);
}
@ -137,7 +137,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
if (!empty($this->matchResults[ 'named' ])) {
$namedAttr = $this->matchResults[ 'named' ];
}
if (isset($_attr[ 'properties' ]) && preg_match_all("/['](.*?)[']/", $_attr[ 'properties' ], $match)) {
if (isset($_attr[ 'properties' ]) && preg_match_all('/[\'](.*?)[\']/', $_attr[ 'properties' ], $match)) {
foreach ($match[ 1 ] as $prop) {
if (in_array($prop, $this->itemProperties)) {
$itemAttr[ $prop ] = true;
@ -229,7 +229,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
$output .= "{$itemVar}->first = !{$itemVar}->index;\n";
}
if (isset($itemAttr[ 'last' ])) {
$output .= "{$itemVar}->last = {$itemVar}->iteration == {$itemVar}->total;\n";
$output .= "{$itemVar}->last = {$itemVar}->iteration === {$itemVar}->total;\n";
}
if (isset($foreachVar)) {
if (isset($namedAttr[ 'iteration' ])) {
@ -242,13 +242,13 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
$output .= "{$foreachVar}->value['first'] = !{$foreachVar}->value['index'];\n";
}
if (isset($namedAttr[ 'last' ])) {
$output .= "{$foreachVar}->value['last'] = {$foreachVar}->value['iteration'] == {$foreachVar}->value['total'];\n";
$output .= "{$foreachVar}->value['last'] = {$foreachVar}->value['iteration'] === {$foreachVar}->value['total'];\n";
}
}
if (!empty($itemAttr)) {
$output .= "{$local}saved = {$itemVar};\n";
}
$output .= "?>";
$output .= '?>';
return $output;
}
@ -262,7 +262,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
*/
public function compileRestore($levels)
{
return "\$_smarty_tpl->smarty->ext->_foreach->restore(\$_smarty_tpl, {$levels});\n";
return "\$_smarty_tpl->smarty->ext->_foreach->restore(\$_smarty_tpl, {$levels});";
}
}
@ -277,13 +277,12 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
/**
* Compiles code for the {foreachelse} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@ -291,10 +290,10 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
list($openTag, $nocache, $local, $itemVar, $restore) = $this->closeTag($compiler, array('foreach'));
$this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $itemVar, 0));
$output = "<?php\n";
if ($restore == 2) {
if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n";
}
$output .= "}\n} else {\n?>\n";
$output .= "}\n} else {\n?>";
return $output;
}
}
@ -310,13 +309,13 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/foreach} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
* @throws \SmartyCompilerException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$compiler->loopNesting --;
// must endblock be nocache?
@ -328,7 +327,7 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
$this->closeTag($compiler, array('foreach', 'foreachelse'));
$output = "<?php\n";
if ($restore == 2) {
if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n";
}
if ($restore > 0) {
@ -338,7 +337,7 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
/* @var Smarty_Internal_Compile_Foreach $foreachCompiler */
$foreachCompiler = $compiler->getTagCompiler('foreach');
$output .= $foreachCompiler->compileRestore(1);
$output .= "?>\n";
$output .= "?>";
return $output;
}
}

@ -44,14 +44,13 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
/**
* Compiles code for the {function} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool true
* @throws \SmartyCompilerException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@ -60,7 +59,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
unset($_attr[ 'nocache' ]);
$_name = trim($_attr[ 'name' ], "'\"");
$_name = trim($_attr[ 'name' ], '\'"');
$compiler->parent_compiler->tpl_function[ $_name ] = array();
$save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
$compiler->template->caching);
@ -68,6 +67,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
// Init temporary context
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$compiler->template->compiled->has_nocache_code = false;
$compiler->saveRequiredPlugins(true);
return true;
}
}
@ -91,18 +91,17 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/function} tag
*
* @param array $args array with attributes from parser
* @param object|\Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param object|\Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool true
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$this->compiler = $compiler;
$saved_data = $this->closeTag($compiler, array('function'));
$_attr = $saved_data[ 0 ];
$_name = trim($_attr[ 'name' ], "'\"");
$_name = trim($_attr[ 'name' ], '\'"');
$compiler->parent_compiler->tpl_function[ $_name ][ 'compiled_filepath' ] =
$compiler->parent_compiler->template->compiled->filepath;
$compiler->parent_compiler->tpl_function[ $_name ][ 'uid' ] = $compiler->template->source->uid;
@ -118,7 +117,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
}
}
if (!empty($_paramsArray)) {
$_params = 'array(' . implode(",", $_paramsArray) . ')';
$_params = 'array(' . implode(',', $_paramsArray) . ')';
$_paramsCode = "\$params = array_merge($_params, \$params);\n";
} else {
$_paramsCode = '';
@ -134,15 +133,16 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output = "<?php\n";
$output .= "/* {$_funcNameCaching} */\n";
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
$output .= "function {$_funcNameCaching} (\$_smarty_tpl,\$params) {\n";
$output .= "function {$_funcNameCaching} (Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
$output .= "ob_start();\n";
$output .= $compiler->compileRequiredPlugins();
$output .= "\$_smarty_tpl->compiled->has_nocache_code = true;\n";
$output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\n}";
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\n}\n";
$output .= "\$params = var_export(\$params, true);\n";
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->saveTemplateVariables(\\\$_smarty_tpl, '{$_name}');\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value, \\\$_smarty_tpl->isRenderingCache);\n}\n?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n\";?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";?>";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
@ -166,9 +166,11 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output = "<?php\n";
$output .= "/* {$_funcName} */\n";
$output .= "if (!function_exists('{$_funcName}')) {\n";
$output .= "function {$_funcName}(\$_smarty_tpl,\$params) {\n";
$output .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
$output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\n}?>";
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\n}\n";
$output .= $compiler->compileCheckPlugins(array_merge($compiler->required_plugins[ 'compiled' ], $compiler->required_plugins[ 'nocache' ]));
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
@ -180,19 +182,10 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
// nocache plugins must be copied
if (!empty($compiler->template->compiled->required_plugins[ 'nocache' ])) {
foreach ($compiler->template->compiled->required_plugins[ 'nocache' ] as $plugin => $tmp) {
foreach ($tmp as $type => $data) {
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin ][ $type ] =
$data;
}
}
}
// restore old buffer
// restore old buffer
$compiler->parser->current_buffer = $saved_data[ 1 ];
// restore old status
$compiler->restoreRequiredPlugins();
$compiler->template->compiled->has_nocache_code = $saved_data[ 2 ];
$compiler->template->caching = $saved_data[ 3 ];
return true;
@ -200,7 +193,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
/**
* Remove nocache code
*
*
* @param $match
*
* @return string

@ -34,8 +34,8 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
// must whole block be nocache ?
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
if (!array_key_exists("if condition", $parameter)) {
$compiler->trigger_template_error("missing if condition", null, true);
if (!isset($parameter['if condition'])) {
$compiler->trigger_template_error('missing if condition', null, true);
}
if (is_array($parameter[ 'if condition' ])) {
@ -49,9 +49,9 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$compiler->setNocacheInVariable($var);
}
$prefixVar = $compiler->getNewPrefixVariable();
$_output = "<?php {$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ";?>\n";
$_output = "<?php {$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]};?>\n";
$assignAttr = array();
$assignAttr[][ 'value' ] = "{$prefixVar}";
$assignAttr[][ 'value' ] = $prefixVar;
$assignCompiler = new Smarty_Internal_Compile_Assign();
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
@ -80,18 +80,17 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
/**
* Compiles code for the {else} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
$this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache));
return "<?php } else { ?>";
return '<?php } else { ?>';
}
}
@ -120,8 +119,8 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
if (!array_key_exists("if condition", $parameter)) {
$compiler->trigger_template_error("missing elseif condition", null, true);
if (!isset($parameter['if condition'])) {
$compiler->trigger_template_error('missing elseif condition', null, true);
}
$assignCode = '';
@ -138,10 +137,10 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
$compiler->setNocacheInVariable($var);
}
$prefixVar = $compiler->getNewPrefixVariable();
$assignCode = "<?php {$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ";?>\n";
$assignCode = "<?php {$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]};?>\n";
$assignCompiler = new Smarty_Internal_Compile_Assign();
$assignAttr = array();
$assignAttr[][ 'value' ] = "{$prefixVar}";
$assignAttr[][ 'value' ] = $prefixVar;
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
$assignCode .= $assignCompiler->compile($assignAttr, $compiler,
@ -188,13 +187,12 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/if} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// must endblock be nocache?
if ($compiler->nocache) {

@ -7,7 +7,6 @@
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Include Class
*
@ -20,7 +19,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* caching mode to create nocache code but no cache file
*/
const CACHING_NOCACHE_CODE = 9999;
/**
* Attribute definition: Overwrites base class.
*
@ -28,7 +26,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('file');
/**
* Attribute definition: Overwrites base class.
*
@ -36,7 +33,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('file');
/**
* Attribute definition: Overwrites base class.
*
@ -44,7 +40,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $option_flags = array('nocache', 'inline', 'caching');
/**
* Attribute definition: Overwrites base class.
*
@ -52,7 +47,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('_any');
/**
* Valid scope names
*
@ -65,19 +59,19 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
/**
* Compiles code for the {include} tag
*
* @param array $args array with attributes from parser
* @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object
*
* @throws SmartyCompilerException
* @return string compiled code
* @return string
* @throws \Exception
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
public function compile($args, Smarty_Internal_SmartyTemplateCompiler $compiler, $parameter)
public function compile($args, Smarty_Internal_SmartyTemplateCompiler $compiler)
{
$uid = $t_hash = null;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$fullResourceName = $source_resource = $_attr[ 'file' ];
$variable_template = false;
$cache_tpl = false;
@ -90,11 +84,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$variable_template = true;
}
if (!$variable_template) {
if ($type != 'string') {
if ($type !== 'string') {
$fullResourceName = "{$type}:{$name}";
$compiled = $compiler->parent_compiler->template->compiled;
if (isset($compiled->includes[ $fullResourceName ])) {
$compiled->includes[ $fullResourceName ] ++;
$compiled->includes[ $fullResourceName ]++;
$cache_tpl = true;
} else {
if ("{$compiler->template->source->type}:{$compiler->template->source->name}" ==
@ -116,10 +110,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} else {
$variable_template = true;
}
// scope setup
$_scope = $compiler->convertScope($_attr, $this->valid_scopes);
// set flag to cache subtemplate object when called within loop or template name is variable.
if ($cache_tpl || $variable_template || $compiler->loopNesting > 0) {
$_cache_tpl = 'true';
@ -128,18 +120,14 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
}
// assume caching is off
$_caching = Smarty::CACHING_OFF;
$call_nocache = $compiler->tag_nocache || $compiler->nocache;
// caching was on and {include} is not in nocache mode
if ($compiler->template->caching && !$compiler->nocache && !$compiler->tag_nocache) {
$_caching = self::CACHING_NOCACHE_CODE;
}
// flag if included template code should be merged into caller
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr[ 'inline' ] === true) &&
!$compiler->template->source->handler->recompiled;
if ($merge_compiled_includes) {
// variable template name ?
if ($variable_template) {
@ -150,7 +138,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$merge_compiled_includes = false;
}
}
/*
* if the {include} tag provides individual parameter for caching or compile_id
* the subtemplate must not be included into the common cache file and is treated like
@ -158,7 +145,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
*
*/
if ($_attr[ 'nocache' ] !== true && $_attr[ 'caching' ]) {
$_caching = $_new_caching = (int) $_attr[ 'caching' ];
$_caching = $_new_caching = (int)$_attr[ 'caching' ];
$call_nocache = true;
} else {
$_new_caching = Smarty::CACHING_LIFETIME_CURRENT;
@ -182,7 +169,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} else {
$_compile_id = '$_smarty_tpl->compile_id';
}
// if subtemplate will be called in nocache mode do not merge
if ($compiler->template->caching && $call_nocache) {
$merge_compiled_includes = false;
@ -200,7 +186,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$_assign = $_attr[ 'assign' ];
}
}
$has_compiled_template = false;
if ($merge_compiled_includes) {
$c_id = isset($_attr[ 'compile_id' ]) ? $_attr[ 'compile_id' ] : $compiler->template->compile_id;
@ -232,17 +217,17 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$_vars = 'array(' . join(',', $_pairs) . ')';
}
$update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache &&
$_compile_id != '$_smarty_tpl->compile_id';
$_compile_id !== '$_smarty_tpl->compile_id';
if ($has_compiled_template && !$call_nocache) {
$_output = "<?php\n";
if ($update_compile_id) {
$_output .= $compiler->makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n");
}
if (!empty($_attr) && $_caching == 9999 && $compiler->template->caching) {
if (!empty($_attr) && $_caching === 9999 && $compiler->template->caching) {
$_vars_nc = "foreach ($_vars as \$ik => \$iv) {\n";
$_vars_nc .= "\$_smarty_tpl->tpl_vars[\$ik] = new Smarty_Variable(\$iv);\n";
$_vars_nc .= "}\n";
$_output .= substr($compiler->processNocacheCode('<?php ' . $_vars_nc . "?>\n", true), 6, - 3);
$_output .= substr($compiler->processNocacheCode('<?php ' . $_vars_nc . "?>\n", true), 6, -3);
}
if (isset($_assign)) {
$_output .= "ob_start();\n";
@ -254,11 +239,9 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if ($update_compile_id) {
$_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n");
}
$_output .= "?>\n";
$_output .= "?>";
return $_output;
}
if ($call_nocache) {
$compiler->tag_nocache = true;
}
@ -277,7 +260,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if ($update_compile_id) {
$_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n";
}
$_output .= "?>\n";
$_output .= "?>";
return $_output;
}
@ -289,9 +272,12 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @param string $t_hash
*
* @return bool
* @throws \Exception
* @throws \SmartyException
*/
public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler,
Smarty_Internal_Template $tpl, $t_hash)
Smarty_Internal_Template $tpl,
$t_hash)
{
$uid = $tpl->source->type . $tpl->source->uid;
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
@ -309,29 +295,30 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$tpl->mustCompile = true;
$compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'nocache_hash' ] =
$tpl->compiled->nocache_hash;
if ($compiler->template->source->type == 'file') {
$sourceInfo = $compiler->template->source->filepath;
if ($tpl->source->type === 'file') {
$sourceInfo = $tpl->source->filepath;
} else {
$basename = $compiler->template->source->handler->getBasename($compiler->template->source);
$sourceInfo = $compiler->template->source->type . ':' .
($basename ? $basename : $compiler->template->source->name);
$basename = $tpl->source->handler->getBasename($tpl->source);
$sourceInfo = $tpl->source->type . ':' .
($basename ? $basename : $tpl->source->name);
}
// get compiled code
$compiled_code = "<?php\n\n";
$compiled_code .= "/* Start inline template \"{$sourceInfo}\" =============================*/\n";
$compiled_code .= "function {$tpl->compiled->unifunc} (\$_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 .= "<?php\n";
$compiled_code .= "}\n?>\n";
$compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode);
$compiled_code .= "<?php\n\n";
$compiled_code .= "/* End inline template \"{$sourceInfo}\" =============================*/\n";
$compiled_code .= "?>";
$compiled_code .= '?>';
unset($tpl->compiler);
if ($tpl->compiled->has_nocache_code) {
// replace nocache_hash
$compiled_code =
str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash,
str_replace("{$tpl->compiled->nocache_hash}",
$compiler->template->compiled->nocache_hash,
$compiled_code);
$compiler->template->compiled->has_nocache_code = true;
}

@ -7,7 +7,6 @@
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Insert Class
*
@ -57,7 +56,6 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
}
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
@ -74,8 +72,8 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
$_dir = $compiler->smarty->trusted_dir;
}
if (!empty($_dir)) {
foreach ((array) $_dir as $_script_dir) {
$_path = $compiler->smarty->_realpath($_script_dir . $compiler->smarty->ds . $_file, true);
foreach ((array)$_dir as $_script_dir) {
$_path = $compiler->smarty->_realpath($_script_dir . DIRECTORY_SEPARATOR . $_file, true);
if (file_exists($_path)) {
$_filepath = $_path;
break;
@ -83,25 +81,22 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
}
}
}
if ($_filepath == false) {
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') {
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 {

@ -1,5 +1,4 @@
<?php
/**
* Smarty Internal Plugin Compile Insert
* Compiles the {insert} tag
@ -24,7 +23,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -32,7 +30,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -49,14 +46,12 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
//Does tag create output
$compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
$nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache);
if (!$nocacheParam) {
// do not compile as nocache code
@ -66,7 +61,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_smarty_tpl = $compiler->template;
$_name = null;
$_script = null;
$_output = '<?php ';
// save possible attributes
eval('$_name = @' . $_attr[ 'name' ] . ';');
@ -74,7 +68,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
// output will be stored in a smarty variable instead of being displayed
$_assign = $_attr[ 'assign' ];
// create variable to make sure that the compiler knows about its nocache status
$var = trim($_attr[ 'assign' ], "'");
$var = trim($_attr[ 'assign' ], '\'');
if (isset($compiler->template->tpl_vars[ $var ])) {
$compiler->template->tpl_vars[ $var ]->nocache = true;
} else {
@ -96,8 +90,8 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_dir = $compiler->smarty instanceof SmartyBC ? $compiler->smarty->trusted_dir : null;
}
if (!empty($_dir)) {
foreach ((array) $_dir as $_script_dir) {
$_script_dir = rtrim($_script_dir, '/\\') . $compiler->smarty->ds;
foreach ((array)$_dir as $_script_dir) {
$_script_dir = rtrim($_script_dir, '/\\') . DIRECTORY_SEPARATOR;
if (file_exists($_script_dir . $_script)) {
$_filepath = $_script_dir . $_script;
break;
@ -105,7 +99,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
}
}
}
if ($_filepath == false) {
if ($_filepath === false) {
$compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true);
}
// code for script file loading
@ -113,7 +107,8 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
require_once $_filepath;
if (!is_callable($_function)) {
$compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'",
null, true);
null,
true);
}
} else {
$_filepath = 'null';
@ -122,7 +117,8 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
if (!is_callable($_function)) {
// try plugin
if (!$_function = $compiler->getPlugin($_name, 'insert')) {
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", null,
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'",
null,
true);
}
}
@ -149,7 +145,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>";
}
}
return $_output;
}
}

@ -16,7 +16,7 @@
*/
class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
{
/**
/**
* Compiles code for the {ldelim} tag
* This tag does output the left delimiter
*
@ -32,9 +32,6 @@ class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
// this tag does not return compiled code
$compiler->has_code = true;
return $compiler->smarty->left_delimiter;
}
}

@ -41,20 +41,18 @@ class Smarty_Internal_Compile_Make_Nocache extends Smarty_Internal_CompileBase
/**
* Compiles code for the {make_nocache} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($compiler->template->caching) {
$output = "<?php \$_smarty_tpl->smarty->ext->_make_nocache->save(\$_smarty_tpl, {$_attr[ 'var' ]});\n?>\n";
$compiler->has_code = true;
$compiler->template->compiled->has_nocache_code = true;
$compiler->suppressNocacheProcessing = true;
return $output;
} else {

@ -0,0 +1,32 @@
<?php
/*
* This file is part of Smarty.
*
* (c) 2015 Uwe Tews
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Smarty Internal Plugin Compile Parent Class
*
* @author Uwe Tews <uwe.tews@googlemail.com>
*/
class Smarty_Internal_Compile_Parent extends Smarty_Internal_Compile_Child
{
/**
* Tag name
*
* @var string
*/
public $tag = 'parent';
/**
* Block type
*
* @var string
*/
public $blockType = 'Parent';
}

@ -41,17 +41,19 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
* @param string $function PHP function name
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function = null)
{
if (!isset($tag[ 5 ]) || substr($tag, - 5) != 'close') {
if (!isset($tag[ 5 ]) || substr($tag, - 5) !== 'close') {
// opening tag of block plugin
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$this->nesting ++;
unset($_attr[ 'nocache' ]);
list($callback, $_paramsArray, $callable) = $this->setup($compiler, $_attr, $tag, $function);
$_params = 'array(' . implode(",", $_paramsArray) . ')';
$_params = 'array(' . implode(',', $_paramsArray) . ')';
// compile code
$output = "<?php ";
@ -63,7 +65,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
$output .= "if (!is_callable({$callable})) {\nthrow new SmartyException('block tag \'{$tag}\' not callable or registered');\n}\n";
}
$output .= "\$_smarty_tpl->smarty->_cache['_tag_stack'][] = array('{$tag}', {$_params});\n";
$output .= "\$_block_repeat=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat);\nwhile (\$_block_repeat) {\nob_start();\n?>";
$output .= "\$_block_repeat=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat);\nwhile (\$_block_repeat) {\nob_start();?>";
$this->openTag($compiler, $tag, array($_params, $compiler->nocache, $callback));
// maybe nocache because of nocache variables or nocache plugin
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
@ -74,8 +76,6 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
}
// closing tag of block plugin, restore nocache
list($_params, $compiler->nocache, $callback) = $this->closeTag($compiler, substr($tag, 0, - 5));
//Does tag create output
$compiler->has_output = isset($_params[ 'assign' ]) ? false : true;
// compile code
if (!isset($parameter[ 'modifier_list' ])) {
$mod_pre = $mod_post = $mod_content = '';
@ -88,13 +88,10 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
array('modifierlist' => $parameter[ 'modifier_list' ],
'value' => 'ob_get_clean()')) . ";\n";
}
$output = "<?php " . $mod_content . "\$_block_repeat=false;\n" . $mod_pre .
"echo {$callback}({$_params}, " . $mod_content2 .
", \$_smarty_tpl, \$_block_repeat);\n" . $mod_post . "}\n";
$output .= "array_pop(\$_smarty_tpl->smarty->_cache['_tag_stack']);";
$output .= "?>";
$output = "<?php {$mod_content}\$_block_repeat=false;\n{$mod_pre}echo {$callback}({$_params}, {$mod_content2}, \$_smarty_tpl, \$_block_repeat);\n{$mod_post}}\n";
$output .= 'array_pop($_smarty_tpl->smarty->_cache[\'_tag_stack\']);?>';
}
return $output . "\n";
return $output;
}
/**

@ -76,6 +76,8 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*
* @param array $attributes
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*
* @throws \SmartyException
*/
public function scanForProperties($attributes, Smarty_Internal_TemplateCompilerBase $compiler)
{
@ -110,8 +112,9 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
public function buildPropertyPreg($named, $attributes)
{
if ($named) {
$this->resultOffsets[ 'named' ] = $this->startOffset + 3;
$this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.](";
$this->resultOffsets[ 'named' ] = $this->startOffset + 4;
$this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" . ($this->tagName === 'section' ? "|[\[]\s*" : '')
. "){$attributes['name']}[.](";
$properties = $this->nameProperties;
} else {
$this->resultOffsets[ 'item' ] = $this->startOffset + 3;
@ -161,6 +164,8 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
* Find matches in all parent template source
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*
* @throws \SmartyException
*/
public function matchParentTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler)
{
@ -171,7 +176,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
if ($compiler !== $nextCompiler) {
// get template source
$_content = $nextCompiler->template->source->getContent();
if ($_content != '') {
if ($_content !== '') {
// run pre filter if required
if ((isset($nextCompiler->smarty->autoload_filters[ 'pre' ]) ||
isset($nextCompiler->smarty->registered_filters[ 'pre' ]))

@ -42,6 +42,8 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
* @param string $function PHP function name
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
{
@ -58,7 +60,7 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
$_paramsArray[] = "'$_key'=>$_value";
}
}
$_params = 'array(' . implode(",", $_paramsArray) . ')';
$_params = 'array(' . implode(',', $_paramsArray) . ')';
// compile code
$output = "{$function}({$_params},\$_smarty_tpl)";
if (!empty($parameter[ 'modifierlist' ])) {
@ -66,8 +68,6 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
}
//Does tag create output
$compiler->has_output = true;
$output = "<?php echo {$output};?>\n";
return $output;
}

@ -26,6 +26,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
@ -34,6 +35,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
$output = $parameter[ 'value' ];
// loop over list of modifiers
foreach ($parameter[ 'modifierlist' ] as $single_modifier) {
/* @var string $modifier */
$modifier = $single_modifier[ 0 ];
$single_modifier[ 0 ] = $output;
$params = implode(',', $single_modifier);
@ -48,20 +50,13 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
case 1:
// registered modifier
if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) {
$function =
$compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ];
if (!is_array($function)) {
$output = "{$function}({$params})";
} else {
if (is_object($function[ 0 ])) {
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
$modifier . '\'][0][0]->' . $function[ 1 ] . '(' . $params . ')';
} else {
$output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')';
}
if (is_callable($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ])) {
$output =
sprintf('call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))',
Smarty::PLUGIN_MODIFIER, var_export($modifier, true), $params);
$compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
$compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
break;
case 2:
@ -135,8 +130,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
}
}
}
if (isset($compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) ||
isset($compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
if (isset($compiler->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) ||
isset($compiler->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
) {
// was a plugin
$compiler->known_modifier_type[ $modifier ] = 4;
@ -148,10 +143,10 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
}
}
if (!isset($compiler->known_modifier_type[ $modifier ])) {
$compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", null, true);
$compiler->trigger_template_error("unknown modifier '{$modifier}'", null, true);
}
}
return $output;
}
}
}

@ -34,14 +34,13 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
* @param string $method name of method to call
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
//Does tag create output
$compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
unset($_attr[ 'nocache' ]);
$_assign = null;
if (isset($_attr[ 'assign' ])) {
@ -60,10 +59,10 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
$_paramsArray[] = "'$_key'=>$_value";
}
}
$_params = 'array(' . implode(",", $_paramsArray) . ')';
$_params = 'array(' . implode(',', $_paramsArray) . ')';
$output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)";
} else {
$_params = implode(",", $_attr);
$_params = implode(',', $_attr);
$output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})";
}
} else {
@ -74,9 +73,6 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output));
}
//Does tag create output
$compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
if (empty($_assign)) {
return "<?php echo {$output};?>\n";
} else {

@ -40,38 +40,34 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$compiler->has_code = false;
if ($_attr[ 'type' ] == 'xml') {
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 .
"';?>",
$compiler->processNocacheCode("<?php echo '{$output}';?>",
true)));
return '';
}
if ($_attr[ 'type' ] != 'tag') {
if ($compiler->php_handling == Smarty::PHP_REMOVE) {
if ($_attr[ 'type' ] !== 'tag') {
if ($compiler->php_handling === Smarty::PHP_REMOVE) {
return '';
} elseif ($compiler->php_handling == Smarty::PHP_QUOTE) {
} 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') {
} 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 .
"';?>",
$compiler->processNocacheCode("<?php echo '{$output}';?>",
true)));
return '';
} elseif ($compiler->php_handling == Smarty::PHP_ALLOW) {
} 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);
@ -91,10 +87,10 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
$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 ])) {
if ('nocache' === trim($match[ 2 ])) {
$compiler->tag_nocache = true;
} else {
$compiler->trigger_template_error("illegal value of option flag \"{$match[2]}\"", null, true);
$compiler->trigger_template_error("illegal value of option flag '{$match[2]}'", null, true);
}
}
return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"),
@ -107,9 +103,11 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
*
* This code has been moved from lexer here fo easier debugging and maintenance
*
* @param $lex
* @param Smarty_Internal_Templatelexer $lex
*
* @throws \SmartyCompilerException
*/
public function parsePhp($lex)
public function parsePhp(Smarty_Internal_Templatelexer $lex)
{
$lex->token = Smarty_Internal_Templateparser::TP_PHP;
$close = 0;
@ -142,16 +140,16 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
return;
}
$closeTag = "{$lex->smarty->left_delimiter}/php{$lex->smarty->right_delimiter}";
if ($lex->value == $closeTag) {
if ($lex->value === $closeTag) {
$lex->compiler->trigger_template_error("unexpected closing tag '{$closeTag}'");
}
$lex->phpType = 'tag';
}
if ($lex->phpType == 'unmatched') {
if ($lex->phpType === 'unmatched') {
return;
}
if (($lex->phpType == 'php' || $lex->phpType == 'asp') &&
($lex->compiler->php_handling == Smarty::PHP_PASSTHRU || $lex->compiler->php_handling == Smarty::PHP_QUOTE)
if (($lex->phpType === 'php' || $lex->phpType === 'asp') &&
($lex->compiler->php_handling === Smarty::PHP_PASSTHRU || $lex->compiler->php_handling === Smarty::PHP_QUOTE)
) {
return;
}
@ -171,7 +169,7 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
$body = false;
} else {
$start = $pos + strlen($value);
$phpCommentStart = $value == '/*';
$phpCommentStart = $value === '/*';
if ($phpCommentStart) {
$phpCommentEnd = preg_match('~([*][/])~', $lex->data, $match, PREG_OFFSET_CAPTURE, $start);
if ($phpCommentEnd) {

@ -67,7 +67,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
preg_match_all('/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/',
$single_default_modifier, $mod_array);
for ($i = 0, $count = count($mod_array[ 0 ]); $i < $count; $i ++) {
if ($mod_array[ 0 ][ $i ] != ':') {
if ($mod_array[ 0 ][ $i ] !== ':') {
$modifierlist[ $key ][] = $mod_array[ 0 ][ $i ];
}
}
@ -100,18 +100,18 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
if (isset($compiler->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ])) {
foreach ((array) $compiler->template->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ] as $name)
{
$result = $this->compile_output_filter($compiler, $name, $output);
$result = $this->compile_variable_filter($compiler, $name, $output);
if ($result !== false) {
$output = $result;
} else {
// not found, throw exception
throw new SmartyException("Unable to load filter '{$name}'");
throw new SmartyException("Unable to load variable filter '{$name}'");
}
}
}
foreach ($compiler->variable_filters as $filter) {
if (count($filter) == 1 &&
($result = $this->compile_output_filter($compiler, $filter[ 0 ], $output)) !== false
if (count($filter) === 1 &&
($result = $this->compile_variable_filter($compiler, $filter[ 0 ], $output)) !== false
) {
$output = $result;
} else {
@ -120,9 +120,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
}
}
$compiler->has_output = true;
$output = "<?php echo {$output};?>";
$output = "<?php echo {$output};?>\n";
}
return $output;
@ -134,29 +132,16 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
* @param string $output embedded output
*
* @return string
* @throws \SmartyException
*/
private function compile_output_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output)
private function compile_variable_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output)
{
$plugin_name = "smarty_variablefilter_{$name}";
$path = $compiler->smarty->loadPlugin($plugin_name);
if ($path) {
/**
if ($compiler->template->caching) {
$compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'file' ] =
$path;
$compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'function' ] =
$plugin_name;
} else {
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'file' ] =
$path;
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'function' ] =
$plugin_name;
}
* */
return "{$plugin_name}({$output},\$_smarty_tpl)";
} else {
$function= $compiler->getPlugin($name, 'variablefilter');
if ($function) {
return "{$function}({$output},\$_smarty_tpl)";
} else {
// not found
return false;
}
}
}
}

@ -61,7 +61,7 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
if (is_int($_key)) {
$_paramsArray[] = "$_key=>$_value";
} elseif ($compiler->template->caching && in_array($_key, $tag_info[ 2 ])) {
$_value = str_replace("'", "^#^", $_value);
$_value = str_replace('\'', "^#^", $_value);
$_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
} else {
$_paramsArray[] = "'$_key'=>$_value";

@ -33,6 +33,8 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
* @param string $tag name of function
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag)
{
@ -41,10 +43,12 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
unset($_attr[ 'nocache' ]);
if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ])) {
$tag_info = $compiler->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
$is_registered = true;
} else {
$tag_info = $compiler->default_handler_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
$tag_info = $compiler->default_handler_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
$is_registered = false;
}
// not cachable?
// not cacheable?
$compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[ 1 ];
// convert attributes into parameter array string
$_paramsArray = array();
@ -52,31 +56,31 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
if (is_int($_key)) {
$_paramsArray[] = "$_key=>$_value";
} elseif ($compiler->template->caching && in_array($_key, $tag_info[ 2 ])) {
$_value = str_replace("'", "^#^", $_value);
$_value = str_replace('\'', "^#^", $_value);
$_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
} else {
$_paramsArray[] = "'$_key'=>$_value";
}
}
$_params = 'array(' . implode(",", $_paramsArray) . ')';
$function = $tag_info[ 0 ];
$_params = 'array(' . implode(',', $_paramsArray) . ')';
// compile code
if (!is_array($function)) {
$output = "{$function}({$_params},\$_smarty_tpl)";
} elseif (is_object($function[ 0 ])) {
if ($is_registered) {
$output =
"\$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl)";
"call_user_func_array( \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0], array( {$_params},\$_smarty_tpl ) )";
} else {
$output = "{$function[0]}::{$function[1]}({$_params},\$_smarty_tpl)";
$function = $tag_info[ 0 ];
if (!is_array($function)) {
$output = "{$function}({$_params},\$_smarty_tpl)";
} else {
$output = "{$function[0]}::{$function[1]}({$_params},\$_smarty_tpl)";
}
}
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
}
//Does tag create output
$compiler->has_output = true;
$output = "<?php echo {$output};?>\n";
return $output;
}
}
}

@ -14,7 +14,7 @@
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase
class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_Compile_Ldelim
{
/**
* Compiles code for the {rdelim} tag
@ -28,13 +28,7 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$_attr = $this->getAttributes($compiler, $args);
if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
// this tag does not return compiled code
$compiler->has_code = true;
parent::compile($args,$compiler);
return $compiler->smarty->right_delimiter;
}
}

@ -84,6 +84,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
@ -103,8 +104,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$initLocal =
array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}'] : false",);
$initLocal = array();
$initNamedProperty = array();
$initFor = array();
$incFor = array();
@ -140,12 +140,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$v = "(is_array(@\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop))";
$t = 1;
}
if (isset($namedAttr[ 'loop' ])) {
$initNamedProperty[ 'loop' ] = "'loop' => {$v}";
if ($t == 1) {
$v = "{$sectionVar}->value['loop']";
}
} elseif ($t == 1) {
if ($t === 1) {
$initLocal[ 'loop' ] = $v;
$v = "{$local}loop";
}
@ -162,11 +157,11 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
case 'step':
if (is_numeric($attr_value)) {
$v = (int) $attr_value;
$v = ($v == 0) ? 1 : $v;
$v = ($v === 0) ? 1 : $v;
$t = 0;
break;
}
$initLocal[ 'step' ] = "((int)@$attr_value) == 0 ? 1 : (int)@$attr_value";
$initLocal[ 'step' ] = "((int)@$attr_value) === 0 ? 1 : (int)@$attr_value";
$v = "{$local}step";
$t = 2;
break;
@ -182,7 +177,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$t = 3;
break;
}
if ($t == 3 && $compiler->getId($attr_value)) {
if ($t === 3 && $compiler->getId($attr_value)) {
$t = 1;
}
$propValue[ $attr_name ] = $v;
@ -198,8 +193,8 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$incFor[ 'iteration' ] = "{$propValue['iteration']}++";
$initFor[ 'iteration' ] = "{$propValue['iteration']} = 1";
if ($propType[ 'step' ] == 0) {
if ($propValue[ 'step' ] == 1) {
if ($propType[ 'step' ] === 0) {
if ($propValue[ 'step' ] === 1) {
$incFor[ 'index' ] = "{$sectionVar}->value['index']++";
} elseif ($propValue[ 'step' ] > 1) {
$incFor[ 'index' ] = "{$sectionVar}->value['index'] += {$propValue['step']}";
@ -213,7 +208,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
if (!isset($propValue[ 'max' ])) {
$propValue[ 'max' ] = $propValue[ 'loop' ];
$propType[ 'max' ] = $propType[ 'loop' ];
} elseif ($propType[ 'max' ] != 0) {
} elseif ($propType[ 'max' ] !== 0) {
$propValue[ 'max' ] = "{$propValue['max']} < 0 ? {$propValue['loop']} : {$propValue['max']}";
$propType[ 'max' ] = 1;
} else {
@ -226,11 +221,11 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
if (!isset($propValue[ 'start' ])) {
$start_code =
array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue[ 'loop' ], 5 => ' - 1');
if ($propType[ 'loop' ] == 0) {
if ($propType[ 'loop' ] === 0) {
$start_code[ 5 ] = '';
$start_code[ 4 ] = $propValue[ 'loop' ] - 1;
}
if ($propType[ 'step' ] == 0) {
if ($propType[ 'step' ] === 0) {
if ($propValue[ 'step' ] > 0) {
$start_code = array(1 => '0');
$propType[ 'start' ] = 0;
@ -248,9 +243,9 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
5 => ' : ', 6 => '-1', 7 => ', ', 8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')',
11 => ' : ', 12 => 'min(', 13 => $propValue[ 'start' ], 14 => ', ',
15 => "{$propValue['step']} > 0 ? ", 16 => $propValue[ 'loop' ], 17 => ' : ',
18 => $propType[ 'loop' ] == 0 ? $propValue[ 'loop' ] - 1 : "{$propValue['loop']} - 1",
18 => $propType[ 'loop' ] === 0 ? $propValue[ 'loop' ] - 1 : "{$propValue['loop']} - 1",
19 => ')');
if ($propType[ 'step' ] == 0) {
if ($propType[ 'step' ] === 0) {
$start_code[ 3 ] = $start_code[ 5 ] = $start_code[ 15 ] = $start_code[ 17 ] = '';
if ($propValue[ 'step' ] > 0) {
$start_code[ 6 ] = $start_code[ 18 ] = '';
@ -258,8 +253,8 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$start_code[ 4 ] = $start_code[ 16 ] = '';
}
}
if ($propType[ 'start' ] == 0) {
if ($propType[ 'loop' ] == 0) {
if ($propType[ 'start' ] === 0) {
if ($propType[ 'loop' ] === 0) {
$start_code[ 8 ] = $propValue[ 'start' ] + $propValue[ 'loop' ];
}
$propType[ 'start' ] = $propType[ 'step' ] + $propType[ 'loop' ];
@ -268,7 +263,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
for ($i = 11; $i <= 19; $i ++) {
$start_code[ $i ] = '';
}
if ($propType[ 'start' ] == 0) {
if ($propType[ 'start' ] === 0) {
$start_code = array(max($propValue[ 'step' ] > 0 ? 0 : - 1,
$propValue[ 'start' ] + $propValue[ 'loop' ]));
}
@ -276,7 +271,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
for ($i = 1; $i <= 11; $i ++) {
$start_code[ $i ] = '';
}
if ($propType[ 'start' ] == 0) {
if ($propType[ 'start' ] === 0) {
$start_code =
array(min($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1,
$propValue[ 'start' ]));
@ -285,7 +280,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
}
$propValue[ 'start' ] = join('', $start_code);
}
if ($propType[ 'start' ] != 0) {
if ($propType[ 'start' ] !== 0) {
$initLocal[ 'start' ] = $propValue[ 'start' ];
$propValue[ 'start' ] = "{$local}start";
}
@ -298,7 +293,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
} else {
$propType[ 'total' ] =
$propType[ 'start' ] + $propType[ 'loop' ] + $propType[ 'step' ] + $propType[ 'max' ];
if ($propType[ 'total' ] == 0) {
if ($propType[ 'total' ] === 0) {
$propValue[ 'total' ] =
min(ceil(($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] - $propValue[ 'start' ] :
(int) $propValue[ 'start' ] + 1) / abs($propValue[ 'step' ])), $propValue[ 'max' ]);
@ -310,17 +305,17 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
if (!isset($propValue[ 'max' ])) {
$total_code[ 1 ] = $total_code[ 17 ] = '';
}
if ($propType[ 'loop' ] + $propType[ 'start' ] == 0) {
if ($propType[ 'loop' ] + $propType[ 'start' ] === 0) {
$total_code[ 5 ] = $propValue[ 'loop' ] - $propValue[ 'start' ];
$total_code[ 6 ] = $total_code[ 7 ] = '';
}
if ($propType[ 'start' ] == 0) {
if ($propType[ 'start' ] === 0) {
$total_code[ 9 ] = (int) $propValue[ 'start' ] + 1;
$total_code[ 10 ] = '';
}
if ($propType[ 'step' ] == 0) {
if ($propType[ 'step' ] === 0) {
$total_code[ 13 ] = $total_code[ 15 ] = '';
if ($propValue[ 'step' ] == 1 || $propValue[ 'step' ] == - 1) {
if ($propValue[ 'step' ] === 1 || $propValue[ 'step' ] === - 1) {
$total_code[ 2 ] = $total_code[ 12 ] = $total_code[ 14 ] = $total_code[ 16 ] = '';
} elseif ($propValue[ 'step' ] < 0) {
$total_code[ 14 ] = - $propValue[ 'step' ];
@ -337,7 +332,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
}
if (isset($namedAttr[ 'loop' ])) {
$initNamedProperty[ 'loop' ] = "'loop' => {$propValue['total']}";
$initNamedProperty[ 'loop' ] = "'loop' => {$propValue['loop']}";
}
if (isset($namedAttr[ 'total' ])) {
$initNamedProperty[ 'total' ] = "'total' => {$propValue['total']}";
@ -357,9 +352,9 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$_vars = 'array(' . join(', ', $initNamedProperty) . ')';
$output .= "{$sectionVar} = new Smarty_Variable({$_vars});\n";
$cond_code = "{$propValue['total']} != 0";
if ($propType[ 'total' ] == 0) {
if ($propValue[ 'total' ] == 0) {
$cond_code = "{$propValue['total']} !== 0";
if ($propType[ 'total' ] === 0) {
if ($propValue[ 'total' ] === 0) {
$cond_code = 'false';
} else {
$cond_code = 'true';
@ -368,7 +363,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
if ($propType[ 'show' ] > 0) {
$output .= "{$local}show = {$propValue['show']} ? {$cond_code} : false;\n";
$output .= "if ({$local}show) {\n";
} elseif ($propValue[ 'show' ] == 'true') {
} elseif ($propValue[ 'show' ] === 'true') {
$output .= "if ({$cond_code}) {\n";
} else {
$output .= "if (false) {\n";
@ -387,12 +382,12 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$output .= "{$sectionVar}->value['index_next'] = {$propValue['index']} + {$propValue['step']};\n";
}
if (isset($namedAttr[ 'first' ])) {
$output .= "{$sectionVar}->value['first'] = ({$propValue['iteration']} == 1);\n";
$output .= "{$sectionVar}->value['first'] = ({$propValue['iteration']} === 1);\n";
}
if (isset($namedAttr[ 'last' ])) {
$output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} == {$propValue['total']});\n";
$output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} === {$propValue['total']});\n";
}
$output .= "?>";
$output .= '?>';
return $output;
}
@ -454,15 +449,12 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
$this->closeTag($compiler, array('section', 'sectionelse'));
$output = "<?php\n";
if ($openTag == 'sectionelse') {
if ($openTag === 'sectionelse') {
$output .= "}\n";
} else {
$output .= "}\n}\n";
}
$output .= "if ({$local}saved) {\n";
$output .= "{$sectionVar} = {$local}saved;\n";
$output .= "}\n";
$output .= "?>";
$output .= '?>';
return $output;
}

@ -17,30 +17,32 @@
class Smarty_Internal_Compile_Shared_Inheritance extends Smarty_Internal_CompileBase
{
/**
* Register post compile callback to compile inheritance initialization code
* Compile inheritance initialization code as prefix
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param bool|false $initChildSequence if true force child template
*/
public function registerInit(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
static function postCompile(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
{
if ($initChildSequence || !isset($compiler->_cache[ 'inheritanceInit' ])) {
$compiler->registerPostCompileCallback(array('Smarty_Internal_Compile_Shared_Inheritance', 'postCompile'),
array($initChildSequence), 'inheritanceInit', $initChildSequence);
$compiler->_cache[ 'inheritanceInit' ] = true;
}
$compiler->prefixCompiledCode .= "<?php \$_smarty_tpl->_loadInheritance();\n\$_smarty_tpl->inheritance->init(\$_smarty_tpl, " .
var_export($initChildSequence, true) . ");\n?>\n";
}
/**
* Compile inheritance initialization code as prefix
* Register post compile callback to compile inheritance initialization code
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param bool|false $initChildSequence if true force child template
*/
static function postCompile(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
public function registerInit(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
{
$compiler->prefixCompiledCode .= "<?php \$_smarty_tpl->_loadInheritance();\n\$_smarty_tpl->inheritance->init(\$_smarty_tpl, " .
var_export($initChildSequence, true) . ");\n?>\n";
if ($initChildSequence || !isset($compiler->_cache['inheritanceInit'])) {
$compiler->registerPostCompileCallback(array('Smarty_Internal_Compile_Shared_Inheritance', 'postCompile'),
array($initChildSequence),
'inheritanceInit',
$initChildSequence);
$compiler->_cache['inheritanceInit'] = true;
}
}
}

@ -33,8 +33,8 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
$_attr = $this->getAttributes($compiler, $args);
$this->openTag($compiler, 'while', $compiler->nocache);
if (!array_key_exists("if condition", $parameter)) {
$compiler->trigger_template_error("missing while condition", null, true);
if (!array_key_exists('if condition', $parameter)) {
$compiler->trigger_template_error('missing while condition', null, true);
}
// maybe nocache because of nocache variables
@ -52,15 +52,15 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
$prefixVar = $compiler->getNewPrefixVariable();
$assignCompiler = new Smarty_Internal_Compile_Assign();
$assignAttr = array();
$assignAttr[][ 'value' ] = "{$prefixVar}";
$assignAttr[][ 'value' ] = $prefixVar;
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
$_output = "<?php while ({$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
$_output = "<?php while ({$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]}) {?>";
$_output .= $assignCompiler->compile($assignAttr, $compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
} else {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
$_output = "<?php while ({$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
$_output = "<?php while ({$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]}) {?>";
$_output .= $assignCompiler->compile($assignAttr, $compiler, array());
}

@ -45,15 +45,15 @@ abstract class Smarty_Internal_CompileBase
public $option_flags = array('nocache');
/**
* Mapping array for boolqn option value
*
* Mapping array for boolean option value
*
* @var array
*/
public $optionMap = array(1 => true, 0 => false, 'true' => true, 'false' => false);
/**
* Mapping array with attributes as key
*
*
* @var array
*/
public $mapCache = array();
@ -117,11 +117,11 @@ abstract class Smarty_Internal_CompileBase
// check if all required attributes present
foreach ($this->required_attributes as $attr) {
if (!isset($_indexed_attr[ $attr ])) {
$compiler->trigger_template_error("missing \"" . $attr . "\" attribute", null, true);
$compiler->trigger_template_error("missing '{$attr}' attribute", null, true);
}
}
// check for not allowed attributes
if ($this->optional_attributes != array('_any')) {
if ($this->optional_attributes !== array('_any')) {
if (!isset($this->mapCache[ 'all' ])) {
$this->mapCache[ 'all' ] =
array_fill_keys(array_merge($this->required_attributes, $this->optional_attributes,
@ -129,7 +129,7 @@ abstract class Smarty_Internal_CompileBase
}
foreach ($_indexed_attr as $key => $dummy) {
if (!isset($this->mapCache[ 'all' ][ $key ]) && $key !== 0) {
$compiler->trigger_template_error("unexpected \"" . $key . "\" attribute", null, true);
$compiler->trigger_template_error("unexpected '{$key}' attribute", null, true);
}
}
}
@ -183,13 +183,12 @@ abstract class Smarty_Internal_CompileBase
}
}
// wrong nesting of tags
$compiler->trigger_template_error("unclosed {$compiler->smarty->left_delimiter}" . $_openTag .
"{$compiler->smarty->right_delimiter} tag");
$compiler->trigger_template_error("unclosed '{$compiler->smarty->left_delimiter}{$_openTag}{$compiler->smarty->right_delimiter}' tag");
return;
}
// wrong nesting of tags
$compiler->trigger_template_error("unexpected closing tag", null, true);
$compiler->trigger_template_error('unexpected closing tag', null, true);
return;
}

@ -97,33 +97,38 @@ class Smarty_Internal_Config_File_Compiler
* @param Smarty_Internal_Template $template
*
* @return bool true if compiling succeeded, false if it failed
* @throws \SmartyException
*/
public function compileTemplate(Smarty_Internal_Template $template)
{
$this->template = $template;
$this->template->compiled->file_dependency[ $this->template->source->uid ] =
array($this->template->source->filepath, $this->template->source->getTimeStamp(),
array($this->template->source->filepath,
$this->template->source->getTimeStamp(),
$this->template->source->type);
if ($this->smarty->debugging) {
if (!isset( $this->smarty->_debug)) {
$this->smarty->_debug = new Smarty_Internal_Debug();
if (!isset($this->smarty->_debug)) {
$this->smarty->_debug = new Smarty_Internal_Debug();
}
$this->smarty->_debug->start_compile($this->template);
}
// init the lexer/parser to compile the config file
/* @var Smarty_Internal_ConfigFileLexer $this->lex */
$this->lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->getContent()) . "\n",
$this);
/* @var Smarty_Internal_ConfigFileParser $this->parser */
/* @var Smarty_Internal_ConfigFileLexer $this ->lex */
$this->lex = new $this->lexer_class(str_replace(array("\r\n",
"\r"), "\n", $template->source->getContent()) . "\n",
$this);
/* @var Smarty_Internal_ConfigFileParser $this ->parser */
$this->parser = new $this->parser_class($this->lex, $this);
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
if (function_exists('mb_internal_encoding')
&& function_exists('ini_get')
&& ((int) ini_get('mbstring.func_overload')) & 2
) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
} else {
$mbEncoding = null;
}
if ($this->smarty->_parserdebug) {
$this->parser->PrintTrace();
}
@ -147,7 +152,7 @@ class Smarty_Internal_Config_File_Compiler
$template_header =
"<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") .
"\n";
$template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n";
$template_header .= " compiled from '{$this->template->source->filepath}' */ ?>\n";
$code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
var_export($this->config_data, true) . '); ?>';

@ -21,90 +21,72 @@
*/
class Smarty_Internal_Configfilelexer
{
const START = 1;
const VALUE = 2;
const NAKED_STRING_VALUE = 3;
const COMMENT = 4;
const SECTION = 5;
const TRIPPLE = 6;
/**
* Source
*
* @var string
*/
public $data;
/**
* Source length
*
* @var int
*/
public $dataLength = null;
/**
* byte counter
*
* @var int
*/
public $counter;
/**
* token number
*
* @var int
*/
public $token;
/**
* token value
*
* @var string
*/
public $value;
/**
* current line
*
* @var int
*/
public $line;
/**
* state number
*
* @var int
*/
public $state = 1;
/**
* Smarty object
*
* @var Smarty
*/
public $smarty = null;
/**
* compiler object
*
* @var Smarty_Internal_Config_File_Compiler
*/
private $compiler = null;
/**
* copy of config_booleanize
*
* @var bool
*/
private $configBooleanize = false;
/**
* trace file
*
* @var resource
*/
public $yyTraceFILE;
/**
* trace prompt
*
* @var string
*/
public $yyTracePrompt;
/**
* state names
*
@ -112,31 +94,38 @@ class Smarty_Internal_Configfilelexer
*/
public $state_name = array(1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION',
6 => 'TRIPPLE');
/**
* token names
*
* @var array
*/
public $smarty_token_names = array( // Text for parser error messages
);
/**
* compiler object
*
* @var Smarty_Internal_Config_File_Compiler
*/
private $compiler = null;
/**
* copy of config_booleanize
*
* @var bool
*/
private $configBooleanize = false;
/**
* storage for assembled token patterns
*
* @var string
*/
private $yy_global_pattern1 = null;
private $yy_global_pattern2 = null;
private $yy_global_pattern3 = null;
private $yy_global_pattern4 = null;
private $yy_global_pattern5 = null;
private $yy_global_pattern6 = null;
/**
* token names
*
* @var array
*/
public $smarty_token_names = array( // Text for parser error messages
);
private $_yy_state = 1;
private $_yy_stack = array();
/**
* constructor
@ -158,16 +147,17 @@ class Smarty_Internal_Configfilelexer
$this->configBooleanize = $this->smarty->config_booleanize;
}
public function replace($input)
{
return $input;
} // end function
public function PrintTrace()
{
$this->yyTraceFILE = fopen('php://output', 'w');
$this->yyTracePrompt = '<br>';
}
private $_yy_state = 1;
private $_yy_stack = array();
public function yylex()
{
return $this->{'yylex' . $this->_yy_state}();
@ -176,14 +166,18 @@ class Smarty_Internal_Configfilelexer
public function yypushstate($state)
{
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);
}
array_push($this->_yy_stack, $this->_yy_state);
$this->_yy_state = $state;
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);
}
@ -192,13 +186,17 @@ class Smarty_Internal_Configfilelexer
public function yypopstate()
{
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);
}
$this->_yy_state = array_pop($this->_yy_stack);
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);
}
@ -208,7 +206,9 @@ class Smarty_Internal_Configfilelexer
{
$this->_yy_state = $state;
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);
}
@ -218,7 +218,7 @@ class Smarty_Internal_Configfilelexer
{
if (!isset($this->yy_global_pattern1)) {
$this->yy_global_pattern1 =
"/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/isS";
$this->replace("/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/isS");
}
if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data);
@ -226,17 +226,18 @@ class Smarty_Internal_Configfilelexer
if ($this->counter >= $this->dataLength) {
return false; // end of input
}
do {
if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, null, $this->counter)) {
if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, 0, $this->counter)) {
if (!isset($yymatches[ 0 ][ 1 ])) {
$yymatches = preg_grep("/(.|\s)+/", $yymatches);
} else {
$yymatches = array_filter($yymatches);
}
if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' .
substr($this->data, $this->counter, 5) . '... state START');
throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data,
$this->counter,
5) . '... state START');
}
next($yymatches); // skip global match
$this->token = key($yymatches); // token number
@ -247,11 +248,11 @@ class Smarty_Internal_Configfilelexer
$this->line += substr_count($this->value, "\n");
// accept this token
return true;
} elseif ($r === true) {
} else if ($r === true) {
// we have changed state
// process this token in the new state
return $this->yylex();
} elseif ($r === false) {
} else if ($r === false) {
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) {
@ -261,63 +262,53 @@ class Smarty_Internal_Configfilelexer
continue;
}
} else {
throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[ $this->counter ]);
}
break;
}
while (true);
} // end function
const START = 1;
} while (true);
}
function yy_r1_1()
{
$this->token = Smarty_Internal_Configfileparser::TPC_COMMENTSTART;
$this->yypushstate(self::COMMENT);
}
function yy_r1_2()
{
$this->token = Smarty_Internal_Configfileparser::TPC_OPENB;
$this->yypushstate(self::SECTION);
}
function yy_r1_3()
{
$this->token = Smarty_Internal_Configfileparser::TPC_CLOSEB;
}
function yy_r1_4()
{
$this->token = Smarty_Internal_Configfileparser::TPC_EQUAL;
$this->yypushstate(self::VALUE);
}
} // end function
function yy_r1_5()
{
return false;
}
function yy_r1_6()
{
$this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
}
function yy_r1_7()
{
$this->token = Smarty_Internal_Configfileparser::TPC_ID;
}
function yy_r1_8()
{
$this->token = Smarty_Internal_Configfileparser::TPC_OTHER;
}
@ -325,7 +316,7 @@ class Smarty_Internal_Configfilelexer
{
if (!isset($this->yy_global_pattern2)) {
$this->yy_global_pattern2 =
"/\G([ \t\r]+)|\G(\\d+\\.\\d+(?=[ \t\r]*[\n#;]))|\G(\\d+(?=[ \t\r]*[\n#;]))|\G(\"\"\")|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*'(?=[ \t\r]*[\n#;]))|\G(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"(?=[ \t\r]*[\n#;]))|\G([a-zA-Z]+(?=[ \t\r]*[\n#;]))|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS";
$this->replace("/\G([ \t\r]+)|\G(\\d+\\.\\d+(?=[ \t\r]*[\n#;]))|\G(\\d+(?=[ \t\r]*[\n#;]))|\G(\"\"\")|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*'(?=[ \t\r]*[\n#;]))|\G(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"(?=[ \t\r]*[\n#;]))|\G([a-zA-Z]+(?=[ \t\r]*[\n#;]))|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS");
}
if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data);
@ -333,17 +324,18 @@ class Smarty_Internal_Configfilelexer
if ($this->counter >= $this->dataLength) {
return false; // end of input
}
do {
if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, null, $this->counter)) {
if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, 0, $this->counter)) {
if (!isset($yymatches[ 0 ][ 1 ])) {
$yymatches = preg_grep("/(.|\s)+/", $yymatches);
} else {
$yymatches = array_filter($yymatches);
}
if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' .
substr($this->data, $this->counter, 5) . '... state VALUE');
throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data,
$this->counter,
5) . '... state VALUE');
}
next($yymatches); // skip global match
$this->token = key($yymatches); // token number
@ -354,11 +346,11 @@ class Smarty_Internal_Configfilelexer
$this->line += substr_count($this->value, "\n");
// accept this token
return true;
} elseif ($r === true) {
} else if ($r === true) {
// we have changed state
// process this token in the new state
return $this->yylex();
} elseif ($r === false) {
} else if ($r === false) {
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) {
@ -368,62 +360,52 @@ class Smarty_Internal_Configfilelexer
continue;
}
} else {
throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[ $this->counter ]);
}
break;
}
while (true);
} // end function
const VALUE = 2;
} while (true);
}
function yy_r2_1()
{
return false;
}
function yy_r2_2()
{
$this->token = Smarty_Internal_Configfileparser::TPC_FLOAT;
$this->yypopstate();
}
function yy_r2_3()
{
$this->token = Smarty_Internal_Configfileparser::TPC_INT;
$this->yypopstate();
}
function yy_r2_4()
{
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES;
$this->yypushstate(self::TRIPPLE);
}
function yy_r2_5()
{
$this->token = Smarty_Internal_Configfileparser::TPC_SINGLE_QUOTED_STRING;
$this->yypopstate();
}
function yy_r2_6()
{
$this->token = Smarty_Internal_Configfileparser::TPC_DOUBLE_QUOTED_STRING;
$this->yypopstate();
}
} // end function
function yy_r2_7()
{
if (!$this->configBooleanize ||
!in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", "no"))
) {
!in_array(strtolower($this->value), array('true', 'false', 'on', 'off', 'yes', 'no'))) {
$this->yypopstate();
$this->yypushstate(self::NAKED_STRING_VALUE);
return true; //reprocess in new state
@ -435,23 +417,21 @@ class Smarty_Internal_Configfilelexer
function yy_r2_8()
{
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->yypopstate();
}
function yy_r2_9()
{
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->value = "";
$this->value = '';
$this->yypopstate();
}
} // end function
public function yylex3()
{
if (!isset($this->yy_global_pattern3)) {
$this->yy_global_pattern3 = "/\G([^\n]+?(?=[ \t\r]*\n))/isS";
$this->yy_global_pattern3 = $this->replace("/\G([^\n]+?(?=[ \t\r]*\n))/isS");
}
if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data);
@ -459,17 +439,18 @@ class Smarty_Internal_Configfilelexer
if ($this->counter >= $this->dataLength) {
return false; // end of input
}
do {
if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, null, $this->counter)) {
if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, 0, $this->counter)) {
if (!isset($yymatches[ 0 ][ 1 ])) {
$yymatches = preg_grep("/(.|\s)+/", $yymatches);
} else {
$yymatches = array_filter($yymatches);
}
if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' .
substr($this->data, $this->counter, 5) . '... state NAKED_STRING_VALUE');
throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data,
$this->counter,
5) . '... state NAKED_STRING_VALUE');
}
next($yymatches); // skip global match
$this->token = key($yymatches); // token number
@ -480,11 +461,11 @@ class Smarty_Internal_Configfilelexer
$this->line += substr_count($this->value, "\n");
// accept this token
return true;
} elseif ($r === true) {
} else if ($r === true) {
// we have changed state
// process this token in the new state
return $this->yylex();
} elseif ($r === false) {
} else if ($r === false) {
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) {
@ -494,18 +475,15 @@ class Smarty_Internal_Configfilelexer
continue;
}
} else {
throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[ $this->counter ]);
}
break;
}
while (true);
} // end function
const NAKED_STRING_VALUE = 3;
} while (true);
}
function yy_r3_1()
{
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
$this->yypopstate();
}
@ -513,7 +491,7 @@ class Smarty_Internal_Configfilelexer
public function yylex4()
{
if (!isset($this->yy_global_pattern4)) {
$this->yy_global_pattern4 = "/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS";
$this->yy_global_pattern4 = $this->replace("/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS");
}
if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data);
@ -521,17 +499,18 @@ class Smarty_Internal_Configfilelexer
if ($this->counter >= $this->dataLength) {
return false; // end of input
}
do {
if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, null, $this->counter)) {
if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, 0, $this->counter)) {
if (!isset($yymatches[ 0 ][ 1 ])) {
$yymatches = preg_grep("/(.|\s)+/", $yymatches);
} else {
$yymatches = array_filter($yymatches);
}
if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' .
substr($this->data, $this->counter, 5) . '... state COMMENT');
throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data,
$this->counter,
5) . '... state COMMENT');
}
next($yymatches); // skip global match
$this->token = key($yymatches); // token number
@ -542,11 +521,11 @@ class Smarty_Internal_Configfilelexer
$this->line += substr_count($this->value, "\n");
// accept this token
return true;
} elseif ($r === true) {
} else if ($r === true) {
// we have changed state
// process this token in the new state
return $this->yylex();
} elseif ($r === false) {
} else if ($r === false) {
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) {
@ -556,30 +535,25 @@ class Smarty_Internal_Configfilelexer
continue;
}
} else {
throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[ $this->counter ]);
}
break;
}
while (true);
} // end function
const COMMENT = 4;
} while (true);
}
function yy_r4_1()
{
return false;
}
function yy_r4_2()
{
$this->token = Smarty_Internal_Configfileparser::TPC_NAKED_STRING;
}
} // end function
function yy_r4_3()
{
$this->token = Smarty_Internal_Configfileparser::TPC_NEWLINE;
$this->yypopstate();
}
@ -587,7 +561,7 @@ class Smarty_Internal_Configfilelexer
public function yylex5()
{
if (!isset($this->yy_global_pattern5)) {
$this->yy_global_pattern5 = "/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/isS";
$this->yy_global_pattern5 = $this->replace("/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/isS");
}
if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data);
@ -595,17 +569,18 @@ class Smarty_Internal_Configfilelexer
if ($this->counter >= $this->dataLength) {
return false; // end of input
}
do {
if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, null, $this->counter)) {
if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, 0, $this->counter)) {
if (!isset($yymatches[ 0 ][ 1 ])) {
$yymatches = preg_grep("/(.|\s)+/", $yymatches);
} else {
$yymatches = array_filter($yymatches);
}
if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' .
substr($this->data, $this->counter, 5) . '... state SECTION');
throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data,
$this->counter,
5) . '... state SECTION');
}
next($yymatches); // skip global match
$this->token = key($yymatches); // token number
@ -616,11 +591,11 @@ class Smarty_Internal_Configfilelexer
$this->line += substr_count($this->value, "\n");
// accept this token
return true;
} elseif ($r === true) {
} else if ($r === true) {
// we have changed state
// process this token in the new state
return $this->yylex();
} elseif ($r === false) {
} else if ($r === false) {
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) {
@ -630,32 +605,28 @@ class Smarty_Internal_Configfilelexer
continue;
}
} else {
throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[ $this->counter ]);
}
break;
}
while (true);
} // end function
const SECTION = 5;
} while (true);
}
function yy_r5_1()
{
$this->token = Smarty_Internal_Configfileparser::TPC_DOT;
}
function yy_r5_2()
{
$this->token = Smarty_Internal_Configfileparser::TPC_SECTION;
$this->yypopstate();
}
} // end function
public function yylex6()
{
if (!isset($this->yy_global_pattern6)) {
$this->yy_global_pattern6 = "/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/isS";
$this->yy_global_pattern6 = $this->replace("/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/isS");
}
if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data);
@ -663,17 +634,18 @@ class Smarty_Internal_Configfilelexer
if ($this->counter >= $this->dataLength) {
return false; // end of input
}
do {
if (preg_match($this->yy_global_pattern6, $this->data, $yymatches, null, $this->counter)) {
if (preg_match($this->yy_global_pattern6, $this->data, $yymatches, 0, $this->counter)) {
if (!isset($yymatches[ 0 ][ 1 ])) {
$yymatches = preg_grep("/(.|\s)+/", $yymatches);
} else {
$yymatches = array_filter($yymatches);
}
if (empty($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' .
substr($this->data, $this->counter, 5) . '... state TRIPPLE');
throw new Exception('Error: lexing failed because a rule matched' .
' an empty string. Input "' . substr($this->data,
$this->counter,
5) . '... state TRIPPLE');
}
next($yymatches); // skip global match
$this->token = key($yymatches); // token number
@ -684,11 +656,11 @@ class Smarty_Internal_Configfilelexer
$this->line += substr_count($this->value, "\n");
// accept this token
return true;
} elseif ($r === true) {
} else if ($r === true) {
// we have changed state
// process this token in the new state
return $this->yylex();
} elseif ($r === false) {
} else if ($r === false) {
$this->counter += strlen($this->value);
$this->line += substr_count($this->value, "\n");
if ($this->counter >= $this->dataLength) {
@ -698,18 +670,15 @@ class Smarty_Internal_Configfilelexer
continue;
}
} else {
throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]);
throw new Exception('Unexpected input at line' . $this->line .
': ' . $this->data[ $this->counter ]);
}
break;
}
while (true);
} // end function
const TRIPPLE = 6;
} while (true);
}
function yy_r6_1()
{
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_QUOTES_END;
$this->yypopstate();
$this->yypushstate(self::START);
@ -717,16 +686,14 @@ class Smarty_Internal_Configfilelexer
function yy_r6_2()
{
$to = strlen($this->data);
preg_match("/\"\"\"[ \t\r]*[\n#;]/", $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->compiler->trigger_template_error('missing or misspelled literal closing tag');
}
$this->value = substr($this->data, $this->counter, $to - $this->counter);
$this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT;
}
}

File diff suppressed because it is too large Load Diff

@ -19,6 +19,7 @@
* The following methods will be dynamically loaded by the extension handler when they are called.
* They are located in a corresponding Smarty_Internal_Method_xxxx class
*
* @method mixed _getConfigVariable(string $varName, bool $errorEnable = true)
* @method mixed getConfigVariable(string $varName, bool $errorEnable = true)
* @method mixed getConfigVars(string $varName = null, bool $searchParents = true)
* @method mixed getGlobal(string $varName = null)
@ -28,7 +29,7 @@
* @method Smarty_Internal_Data clearConfig(string $varName = null)
* @method Smarty_Internal_Data configLoad(string $config_file, mixed $sections = null, string $scope = 'local')
*/
class Smarty_Internal_Data
abstract class Smarty_Internal_Data
{
/**
* This object type (Smarty = 1, template = 2, data = 4)
@ -54,7 +55,7 @@ class Smarty_Internal_Data
/**
* parent template (if any)
*
* @var Smarty|Smarty_Internal_Template|Smarty_Internal_Data
* @var Smarty|Smarty_Internal_Template|Smarty_Data
*/
public $parent = null;
@ -100,7 +101,7 @@ class Smarty_Internal_Data
$this->assign($_key, $_val, $nocache);
}
} else {
if ($tpl_var != '') {
if ($tpl_var !== '') {
if ($this->_objType === 2) {
/** @var Smarty_Internal_Template $this */
$this->_assignInScope($tpl_var, $value, $nocache);

@ -193,6 +193,9 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @param Smarty_Internal_Template|Smarty $obj object to debug
* @param bool $full
*
* @throws \Exception
* @throws \SmartyException
*/
public function display_debug($obj, $full = false)
{
@ -210,7 +213,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
// init properties by hand as user may have edited the original Smarty class
$debObj->setPluginsDir(is_dir(__DIR__ . '/../plugins') ? __DIR__ . '/../plugins' : $smarty->getPluginsDir());
$debObj->force_compile = false;
$debObj->compile_check = true;
$debObj->compile_check = Smarty::COMPILECHECK_ON;
$debObj->left_delimiter = '{';
$debObj->right_delimiter = '}';
$debObj->security_policy = null;
@ -224,7 +227,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$debObj->autoload_filters = array();
$debObj->default_modifiers = array();
$debObj->escape_html = true;
$debObj->caching = false;
$debObj->caching = Smarty::CACHING_OFF;
$debObj->compile_id = null;
$debObj->cache_id = null;
// prepare information of assigned variables
@ -239,7 +242,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
if ($obj->_isTplObj()) {
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
}
if ($obj->_objType == 1 || $full) {
if ($obj->_objType === 1 || $full) {
$_template->assign('template_data', $this->template_data[ $this->index ]);
} else {
$_template->assign('template_data', null);
@ -247,7 +250,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$_template->assign('assigned_vars', $_assigned_vars);
$_template->assign('config_vars', $_config_vars);
$_template->assign('execution_time', microtime(true) - $smarty->start_time);
$_template->assign('display_mode', $debugging == 2 || !$full);
$_template->assign('display_mode', $debugging === 2 || !$full);
$_template->assign('offset', $this->offset * 50);
echo $_template->fetch();
if (isset($full)) {
@ -281,15 +284,15 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$tpl_vars = array();
foreach ($obj->tpl_vars as $key => $var) {
foreach ($var as $varkey => $varvalue) {
if ($varkey == 'value') {
if ($varkey === 'value') {
$tpl_vars[ $key ][ $varkey ] = $varvalue;
} else {
if ($varkey == 'nocache') {
if ($varvalue == true) {
if ($varkey === 'nocache') {
if ($varvalue === true) {
$tpl_vars[ $key ][ $varkey ] = $varvalue;
}
} else {
if ($varkey != 'scope' || $varvalue !== 0) {
if ($varkey !== 'scope' || $varvalue !== 0) {
$tpl_vars[ $key ][ 'attributes' ][ $varkey ] = $varvalue;
}
}
@ -323,15 +326,15 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
foreach (Smarty::$global_tpl_vars as $key => $var) {
if (!array_key_exists($key, $tpl_vars)) {
foreach ($var as $varkey => $varvalue) {
if ($varkey == 'value') {
if ($varkey === 'value') {
$tpl_vars[ $key ][ $varkey ] = $varvalue;
} else {
if ($varkey == 'nocache') {
if ($varvalue == true) {
if ($varkey === 'nocache') {
if ($varvalue === true) {
$tpl_vars[ $key ][ $varkey ] = $varvalue;
}
} else {
if ($varkey != 'scope' || $varvalue !== 0) {
if ($varkey !== 'scope' || $varvalue !== 0) {
$tpl_vars[ $key ][ 'attributes' ][ $varkey ] = $varvalue;
}
}
@ -356,7 +359,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
{
static $_is_stringy = array('string' => true, 'eval' => true);
// calculate Uid if not already done
if ($template->source->uid == '') {
if ($template->source->uid === '') {
$template->source->filepath;
}
$key = $template->source->uid;
@ -386,7 +389,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
public function ignore(Smarty_Internal_Template $template)
{
// calculate Uid if not already done
if ($template->source->uid == '') {
if ($template->source->uid === '') {
$template->source->filepath;
}
$this->ignore_uid[ $template->source->uid ] = true;

@ -0,0 +1,112 @@
<?php
/**
* Smarty error handler
*
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*
* @deprecated
Smarty does no longer use @filemtime()
*/
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()
*/
private static $previousErrorHandler = null;
/**
* Enable error handler to mute expected messages
*
* @return boolean
*/
public static function muteExpectedErrors()
{
/*
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:
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_reporting() settings will have no effect and your error handler will be called regardless -
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
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');
$previous = set_error_handler($error_handler);
// avoid dead loops
if ($previous !== $error_handler) {
self::$previousErrorHandler = $previous;
}
}
/**
* Error Handler to mute expected messages
*
* @link http://php.net/set_error_handler
*
* @param integer $errno Error level
* @param $errstr
* @param $errfile
* @param $errline
* @param $errcontext
*
* @return bool
*/
public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
{
$_is_muted_directory = false;
// add the SMARTY_DIR to the list of muted directories
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;
}
}
}
}

@ -27,14 +27,15 @@
* Method extensions
* @property Smarty_Internal_Method_GetTemplateVars $getTemplateVars
* @property Smarty_Internal_Method_Append $append
* @property Smarty_Internal_Method_AppendByRef $appendByRef
* @property Smarty_Internal_Method_AssignGlobal $assignGlobal
* @property Smarty_Internal_Method_AssignByRef $assignByRef
* @property Smarty_Internal_Method_LoadFilter $loadFilter
* @property Smarty_Internal_Method_LoadPlugin $loadPlugin
* @property Smarty_Internal_Method_RegisterFilter $registerFilter
* @property Smarty_Internal_Method_RegisterObject $registerObject
* @property Smarty_Internal_Method_RegisterPlugin $registerPlugin
* @property Smarty_Internal_Method_AppendByRef $appendByRef
* @property Smarty_Internal_Method_AssignGlobal $assignGlobal
* @property Smarty_Internal_Method_AssignByRef $assignByRef
* @property Smarty_Internal_Method_LoadFilter $loadFilter
* @property Smarty_Internal_Method_LoadPlugin $loadPlugin
* @property Smarty_Internal_Method_RegisterFilter $registerFilter
* @property Smarty_Internal_Method_RegisterObject $registerObject
* @property Smarty_Internal_Method_RegisterPlugin $registerPlugin
* @property mixed|\Smarty_Template_Cached configLoad
*/
class Smarty_Internal_Extension_Handler
{
@ -47,9 +48,9 @@ class Smarty_Internal_Extension_Handler
*
* @var array
*/
private $_property_info = array('AutoloadFilters' => 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0,
'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0,
'TemplateVars' => 0,);#
private $_property_info = array('AutoloadFilters' => 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0,
'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0,
'TemplateVars' => 0, 'Literals' => 'Literals',);#
private $resolvedProperties = array();
@ -68,38 +69,62 @@ class Smarty_Internal_Extension_Handler
/* @var Smarty $data ->smarty */
$smarty = isset($data->smarty) ? $data->smarty : $data;
if (!isset($smarty->ext->$name)) {
$class = 'Smarty_Internal_Method_' . $this->upperCase($name);
if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) {
$pn = '';
if (!isset($this->_property_info[ $prop = $match[ 2 ] ])) {
// convert camel case to underscored name
$this->resolvedProperties[ $prop ] = $pn = strtolower(join('_',
preg_split('/([A-Z][^A-Z]*)/', $prop,
- 1, PREG_SPLIT_NO_EMPTY |
PREG_SPLIT_DELIM_CAPTURE)));
$this->_property_info[ $prop ] =
property_exists($data, $pn) ? 1 : ($data->_isTplObj() && property_exists($smarty, $pn) ? 2 : 0);
if (preg_match('/^((set|get)|(.*?))([A-Z].*)$/', $name, $match)) {
$basename = $this->upperCase($match[4]);
if (!isset($smarty->ext->$basename) && isset($this->_property_info[ $basename ]) &&
is_string($this->_property_info[ $basename ])) {
$class = 'Smarty_Internal_Method_' . $this->_property_info[ $basename ];
if (class_exists($class)) {
$classObj = new $class();
$methodes = get_class_methods($classObj);
foreach ($methodes as $method) {
$smarty->ext->$method = $classObj;
}
}
}
if ($this->_property_info[ $prop ]) {
$pn = $this->resolvedProperties[ $prop ];
if ($match[ 1 ] == 'get') {
return $this->_property_info[ $prop ] == 1 ? $data->$pn : $data->smarty->$pn;
} else {
return $this->_property_info[ $prop ] == 1 ? $data->$pn = $args[ 0 ] :
$data->smarty->$pn = $args[ 0 ];
if (!empty($match[2]) && !isset($smarty->ext->$name)) {
$class = 'Smarty_Internal_Method_' . $this->upperCase($name);
if (!class_exists($class)) {
$objType = $data->_objType;
$propertyType = false;
if (!isset($this->resolvedProperties[ $match[0] ][ $objType ])) {
$property = isset($this->resolvedProperties['property'][ $basename ]) ?
$this->resolvedProperties['property'][ $basename ] :
$property = $this->resolvedProperties['property'][ $basename ] = strtolower(join('_',
preg_split('/([A-Z][^A-Z]*)/',
$basename,
-1,
PREG_SPLIT_NO_EMPTY |
PREG_SPLIT_DELIM_CAPTURE)));
if ($property !== false) {
if (property_exists($data, $property)) {
$propertyType = $this->resolvedProperties[ $match[0] ][ $objType ] = 1;
} else if (property_exists($smarty, $property)) {
$propertyType = $this->resolvedProperties[ $match[0] ][ $objType ] = 2;
} else {
$this->resolvedProperties['property'][ $basename ] = $property = false;
}
}
} else {
$propertyType = $this->resolvedProperties[ $match[0] ][ $objType ];
$property = $this->resolvedProperties['property'][ $basename ];
}
if ($propertyType) {
$obj = $propertyType === 1 ? $data : $smarty;
if ($match[2] === 'get') {
return $obj->$property;
} else if ($match[2] === 'set') {
return $obj->$property = $args[0];
}
}
}
} elseif (!class_exists($class)) {
throw new SmartyException("property '$pn' does not exist.");
}
}
if (class_exists($class)) {
$callback = array($smarty->ext->$name = new $class(), $name);
}
} else {
$callback = array($smarty->ext->$name, $name);
}
$callback = array($smarty->ext->$name, $name);
array_unshift($args, $data);
if (isset($callback) && $callback[ 0 ]->objMap | $data->_objType) {
if (isset($callback) && $callback[0]->objMap | $data->_objType) {
return call_user_func_array($callback, $args);
}
return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), $args);
@ -119,19 +144,6 @@ class Smarty_Internal_Extension_Handler
return implode('_', $_name);
}
/**
* set extension property
*
* @param string $property_name property name
* @param mixed $value value
*
* @throws SmartyException
*/
public function __set($property_name, $value)
{
$this->$property_name = $value;
}
/**
* get extension object
*
@ -143,7 +155,7 @@ class Smarty_Internal_Extension_Handler
public function __get($property_name)
{
// object properties of runtime template extensions will start with '_'
if ($property_name[ 0 ] == '_') {
if ($property_name[0] === '_') {
$class = 'Smarty_Internal_Runtime' . $this->upperCase($property_name);
} else {
$class = 'Smarty_Internal_Method_' . $this->upperCase($property_name);
@ -154,6 +166,19 @@ class Smarty_Internal_Extension_Handler
return $this->$property_name = new $class();
}
/**
* set extension property
*
* @param string $property_name property name
* @param mixed $value value
*
* @throws SmartyException
*/
public function __set($property_name, $value)
{
$this->$property_name = $value;
}
/**
* Call error handler for undefined method
*

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

Loading…
Cancel
Save