- reformat all code for unique style

This commit is contained in:
uwetews
2016-02-09 01:27:15 +01:00
parent c59ca44b9f
commit b04486a091
163 changed files with 3259 additions and 2713 deletions

View File

@@ -1,6 +1,7 @@
 ===== 3.1.30-dev ===== (xx.xx.xx)  ===== 3.1.30-dev ===== (xx.xx.xx)
09.02.2016 09.02.2016
- move some code from parser into compiler - move some code from parser into compiler
- reformat all code for unique style
05.02.2016 05.02.2016
- improvement internal compiler changes - improvement internal compiler changes

View File

@@ -17,8 +17,8 @@ $smarty->cache_lifetime = 120;
$smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true); $smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true);
$smarty->assign("FirstName", array("John", "Mary", "James", "Henry")); $smarty->assign("FirstName", array("John", "Mary", "James", "Henry"));
$smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case")); $smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case"));
$smarty->assign("Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"), $smarty->assign("Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"), array("I", "J", "K", "L"),
array("I", "J", "K", "L"), array("M", "N", "O", "P"))); array("M", "N", "O", "P")));
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"), $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234"))); array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));

View File

@@ -32,7 +32,7 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
$_res = array(); $_res = array();
$res = apc_fetch($keys); $res = apc_fetch($keys);
foreach ($res as $k => $v) { foreach ($res as $k => $v) {
$_res[$k] = $v; $_res[ $k ] = $v;
} }
return $_res; return $_res;

View File

@@ -43,12 +43,12 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
foreach ($keys as $k) { foreach ($keys as $k) {
$_k = sha1($k); $_k = sha1($k);
$_keys[] = $_k; $_keys[] = $_k;
$lookup[$_k] = $k; $lookup[ $_k ] = $k;
} }
$_res = array(); $_res = array();
$res = $this->memcache->get($_keys); $res = $this->memcache->get($_keys);
foreach ($res as $k => $v) { foreach ($res as $k => $v) {
$_res[$lookup[$k]] = $v; $_res[ $lookup[ $k ] ] = $v;
} }
return $_res; return $_res;

View File

@@ -26,8 +26,11 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
{ {
// PDO instance // PDO instance
protected $db; protected $db;
protected $fetch; protected $fetch;
protected $fetchTimestamp; protected $fetchTimestamp;
protected $save; protected $save;
public function __construct() public function __construct()
@@ -62,8 +65,8 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
$row = $this->fetch->fetch(); $row = $this->fetch->fetch();
$this->fetch->closeCursor(); $this->fetch->closeCursor();
if ($row) { if ($row) {
$content = $row['content']; $content = $row[ 'content' ];
$mtime = strtotime($row['modified']); $mtime = strtotime($row[ 'modified' ]);
} else { } else {
$content = null; $content = null;
$mtime = null; $mtime = null;
@@ -105,13 +108,8 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
*/ */
protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content) protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content)
{ {
$this->save->execute(array( $this->save->execute(array('id' => $id, 'name' => $name, 'cache_id' => $cache_id, 'compile_id' => $compile_id,
'id' => $id, 'content' => $content,));
'name' => $name,
'cache_id' => $cache_id,
'compile_id' => $compile_id,
'content' => $content,
));
return !!$this->save->rowCount(); return !!$this->save->rowCount();
} }
@@ -151,8 +149,8 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
} }
// equal test cache_id and match sub-groups // equal test cache_id and match sub-groups
if ($cache_id !== null) { if ($cache_id !== null) {
$where[] = '(cache_id = ' . $this->db->quote($cache_id) $where[] = '(cache_id = ' . $this->db->quote($cache_id) . ' OR cache_id LIKE ' .
. ' OR cache_id LIKE ' . $this->db->quote($cache_id . '|%') . ')'; $this->db->quote($cache_id . '|%') . ')';
} }
// run delete query // run delete query
$query = $this->db->query('DELETE FROM output_cache WHERE ' . join(' AND ', $where)); $query = $this->db->query('DELETE FROM output_cache WHERE ' . join(' AND ', $where));

View File

@@ -30,21 +30,21 @@
class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
{ {
protected $fetchStatements = Array('default' => 'SELECT %2$s protected $fetchStatements = Array('default' => 'SELECT %2$s
FROM %1$s FROM %1$s
WHERE 1 WHERE 1
AND id = :id AND id = :id
AND cache_id IS NULL AND cache_id IS NULL
AND compile_id IS NULL', AND compile_id IS NULL',
'withCacheId' => 'SELECT %2$s 'withCacheId' => 'SELECT %2$s
FROM %1$s FROM %1$s
WHERE 1 WHERE 1
AND id = :id AND id = :id
AND cache_id = :cache_id AND cache_id = :cache_id
AND compile_id IS NULL', AND compile_id IS NULL',
'withCompileId' => 'SELECT %2$s 'withCompileId' => 'SELECT %2$s
FROM %1$s FROM %1$s
WHERE 1 WHERE 1
AND id = :id AND id = :id
@@ -57,6 +57,7 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
AND id = :id AND id = :id
AND cache_id = :cache_id AND cache_id = :cache_id
AND compile_id = :compile_id'); AND compile_id = :compile_id');
protected $insertStatement = 'INSERT INTO %s protected $insertStatement = 'INSERT INTO %s
SET id = :id, SET id = :id,
@@ -76,9 +77,11 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
content = :content'; content = :content';
protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s'; protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s';
protected $truncateStatement = 'TRUNCATE TABLE %s'; protected $truncateStatement = 'TRUNCATE TABLE %s';
protected $fetchColumns = 'modified, content'; protected $fetchColumns = 'modified, content';
protected $fetchTimestampColumns = 'modified'; protected $fetchTimestampColumns = 'modified';
protected $pdo, $table, $database; protected $pdo, $table, $database;
@@ -137,13 +140,15 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
{ {
if (!is_null($cache_id) && !is_null($compile_id)) { if (!is_null($cache_id) && !is_null($compile_id)) {
$query = $this->fetchStatements['withCacheIdAndCompileId'] AND $args = Array('id' => $id, 'cache_id' => $cache_id, 'compile_id' => $compile_id); $query = $this->fetchStatements[ 'withCacheIdAndCompileId' ] AND
$args = Array('id' => $id, 'cache_id' => $cache_id, 'compile_id' => $compile_id);
} elseif (is_null($cache_id) && !is_null($compile_id)) { } elseif (is_null($cache_id) && !is_null($compile_id)) {
$query = $this->fetchStatements['withCompileId'] AND $args = Array('id' => $id, 'compile_id' => $compile_id); $query = $this->fetchStatements[ 'withCompileId' ] AND
$args = Array('id' => $id, 'compile_id' => $compile_id);
} elseif (!is_null($cache_id) && is_null($compile_id)) { } elseif (!is_null($cache_id) && is_null($compile_id)) {
$query = $this->fetchStatements['withCacheId'] AND $args = Array('id' => $id, 'cache_id' => $cache_id); $query = $this->fetchStatements[ 'withCacheId' ] AND $args = Array('id' => $id, 'cache_id' => $cache_id);
} else { } else {
$query = $this->fetchStatements['default'] AND $args = Array('id' => $id); $query = $this->fetchStatements[ 'default' ] AND $args = Array('id' => $id);
} }
$query = sprintf($query, $columns); $query = sprintf($query, $columns);
@@ -174,13 +179,13 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
{ {
$stmt = $this->getFetchStatement($this->fetchColumns, $id, $cache_id, $compile_id); $stmt = $this->getFetchStatement($this->fetchColumns, $id, $cache_id, $compile_id);
$stmt ->execute(); $stmt->execute();
$row = $stmt->fetch(); $row = $stmt->fetch();
$stmt ->closeCursor(); $stmt->closeCursor();
if ($row) { if ($row) {
$content = $this->outputContent($row['content']); $content = $this->outputContent($row[ 'content' ]);
$mtime = strtotime($row['modified']); $mtime = strtotime($row[ 'modified' ]);
} else { } else {
$content = null; $content = null;
$mtime = null; $mtime = null;
@@ -226,13 +231,13 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
$stmt = $this->pdo->prepare($this->insertStatement); $stmt = $this->pdo->prepare($this->insertStatement);
$stmt ->bindValue('id', $id); $stmt->bindValue('id', $id);
$stmt ->bindValue('name', $name); $stmt->bindValue('name', $name);
$stmt ->bindValue('cache_id', $cache_id, (is_null($cache_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR); $stmt->bindValue('cache_id', $cache_id, (is_null($cache_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
$stmt ->bindValue('compile_id', $compile_id, (is_null($compile_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR); $stmt->bindValue('compile_id', $compile_id, (is_null($compile_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
$stmt ->bindValue('expire', (int) $exp_time, PDO::PARAM_INT); $stmt->bindValue('expire', (int) $exp_time, PDO::PARAM_INT);
$stmt ->bindValue('content', $this->inputContent($content)); $stmt->bindValue('content', $this->inputContent($content));
$stmt ->execute(); $stmt->execute();
return !!$stmt->rowCount(); return !!$stmt->rowCount();
} }
@@ -289,8 +294,8 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
} }
// equal test cache_id and match sub-groups // equal test cache_id and match sub-groups
if ($cache_id !== null) { if ($cache_id !== null) {
$where[] = '(cache_id = ' . $this->pdo->quote($cache_id) $where[] = '(cache_id = ' . $this->pdo->quote($cache_id) . ' OR cache_id LIKE ' .
. ' OR cache_id LIKE ' . $this->pdo->quote($cache_id . '|%') . ')'; $this->pdo->quote($cache_id . '|%') . ')';
} }
// equal test compile_id // equal test compile_id
if ($compile_id !== null) { if ($compile_id !== null) {

View File

@@ -21,8 +21,10 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
{ {
// PDO instance // PDO instance
protected $db; protected $db;
// prepared fetch() statement // prepared fetch() statement
protected $fetch; protected $fetch;
// prepared fetchTimestamp() statement // prepared fetchTimestamp() statement
protected $mtime; protected $mtime;
@@ -53,8 +55,8 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
$row = $this->fetch->fetch(); $row = $this->fetch->fetch();
$this->fetch->closeCursor(); $this->fetch->closeCursor();
if ($row) { if ($row) {
$source = $row['source']; $source = $row[ 'source' ];
$mtime = strtotime($row['modified']); $mtime = strtotime($row[ 'modified' ]);
} else { } else {
$source = null; $source = null;
$mtime = null; $mtime = null;

View File

@@ -23,6 +23,7 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
{ {
// PDO instance // PDO instance
protected $db; protected $db;
// prepared fetch() statement // prepared fetch() statement
protected $fetch; protected $fetch;
@@ -52,8 +53,8 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
$row = $this->fetch->fetch(); $row = $this->fetch->fetch();
$this->fetch->closeCursor(); $this->fetch->closeCursor();
if ($row) { if ($row) {
$source = $row['source']; $source = $row[ 'source' ];
$mtime = strtotime($row['modified']); $mtime = strtotime($row[ 'modified' ]);
} else { } else {
$source = null; $source = null;
$mtime = null; $mtime = null;

View File

@@ -57,7 +57,7 @@ class Smarty_Autoloader
set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
) { ) {
$registeredAutoLoadFunctions = spl_autoload_functions(); $registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions['spl_autoload'])) { if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {
spl_autoload_register(); spl_autoload_register();
} }
} else { } else {
@@ -103,11 +103,11 @@ class Smarty_Autoloader
} }
if (preg_match('/^(smarty_(((template_(source|config|cache|compiled|resource_base))|((cached|compiled)?resource)|(variable|security)))|(smarty(bc)?)$)/', if (preg_match('/^(smarty_(((template_(source|config|cache|compiled|resource_base))|((cached|compiled)?resource)|(variable|security)))|(smarty(bc)?)$)/',
$_class, $match)) { $_class, $match)) {
if (!empty($match[3])) { if (!empty($match[ 3 ])) {
@include $file; @include $file;
return; return;
} elseif (!empty($match[9]) && isset(self::$rootClasses[$_class])) { } elseif (!empty($match[ 9 ]) && isset(self::$rootClasses[ $_class ])) {
$file = self::$rootClasses[$_class]; $file = self::$rootClasses[ $_class ];
require $file; require $file;
return; return;
} }

View File

@@ -684,8 +684,8 @@ class Smarty extends Smarty_Internal_TemplateBase
* @var string[] * @var string[]
*/ */
private $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir', private $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir',
'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir', 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir',
'cache_dir' => 'CacheDir',); 'cache_dir' => 'CacheDir',);
/**#@-*/ /**#@-*/
@@ -1144,12 +1144,13 @@ class Smarty extends Smarty_Internal_TemplateBase
if (strpos($path, $nds) !== false) { if (strpos($path, $nds) !== false) {
$path = str_replace($nds, DS, $path); $path = str_replace($nds, DS, $path);
} }
preg_match('%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(?:[[:print:]]*))$%', $path, $parts); preg_match('%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(?:[[:print:]]*))$%',
$path = $parts['path']; $path, $parts);
if ($parts['root'] == '\\') { $path = $parts[ 'path' ];
$parts['root'] = substr(getcwd(), 0, 2) . $parts['root']; if ($parts[ 'root' ] == '\\') {
$parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ];
} else { } else {
if ($realpath !== null && !$parts['root']) { if ($realpath !== null && !$parts[ 'root' ]) {
$path = getcwd() . DS . $path; $path = getcwd() . DS . $path;
} }
} }
@@ -1159,15 +1160,16 @@ class Smarty extends Smarty_Internal_TemplateBase
preg_replace('#([\\\\/][^\\\\/]+[\\\\/]([.]?[\\\\/])*[.][.][\\\\/]([.]?[\\\\/])*)+|([\\\\/]([.]?[\\\\/])+)#', preg_replace('#([\\\\/][^\\\\/]+[\\\\/]([.]?[\\\\/])*[.][.][\\\\/]([.]?[\\\\/])*)+|([\\\\/]([.]?[\\\\/])+)#',
DS, $path, - 1, $count); DS, $path, - 1, $count);
} }
return $parts['root'] . $path; return $parts[ 'root' ] . $path;
} }
/** /**
* Empty template objects cache * Empty template objects cache
*/ */
public function _clearTemplateCache() { public function _clearTemplateCache()
$this->_cache['isCached'] = array(); {
$this->_cache['tplObjects'] = array(); $this->_cache[ 'isCached' ] = array();
$this->_cache[ 'tplObjects' ] = array();
} }
/** /**
@@ -1345,7 +1347,7 @@ class Smarty extends Smarty_Internal_TemplateBase
if (isset($this->accessMap[ $name ])) { if (isset($this->accessMap[ $name ])) {
$method = 'set' . $this->accessMap[ $name ]; $method = 'set' . $this->accessMap[ $name ];
$this->{$method}($value); $this->{$method}($value);
} elseif (in_array($name, $this->obsoleteProperties)) { } elseif (in_array($name, $this->obsoleteProperties)) {
return; return;
} else { } else {
if (is_object($value) && method_exists($value, $name)) { if (is_object($value) && method_exists($value, $name)) {
@@ -1399,7 +1401,7 @@ class Smarty extends Smarty_Internal_TemplateBase
break; break;
} }
} }
// pass to next error handler if this error did not occur inside SMARTY_DIR // 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 // or the error was within smarty but masked to be ignored
if (!$_is_muted_directory || ($errno && $errno & error_reporting())) { if (!$_is_muted_directory || ($errno && $errno & error_reporting())) {
if (Smarty::$_previous_error_handler) { if (Smarty::$_previous_error_handler) {

View File

@@ -128,7 +128,8 @@ class SmartyBC extends Smarty
* @throws SmartyException * @throws SmartyException
* @internal param array $block_functs list of methods that are block format * @internal param array $block_functs list of methods that are block format
*/ */
public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true,
$block_methods = array())
{ {
settype($allowed, 'array'); settype($allowed, 'array');
settype($smarty_args, 'boolean'); settype($smarty_args, 'boolean');

View File

@@ -83,7 +83,9 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
continue; continue;
} }
// convert mult. spaces & special chars to single space // convert mult. spaces & special chars to single space
$_paragraph = preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), array(' ', ''), $_paragraph); $_paragraph =
preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER),
array(' ', ''), $_paragraph);
// indent first line // indent first line
if ($indent_first > 0) { if ($indent_first > 0) {
$_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph; $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;

View File

@@ -25,53 +25,48 @@ function smarty_function_counter($params, $template)
{ {
static $counters = array(); static $counters = array();
$name = (isset($params['name'])) ? $params['name'] : 'default'; $name = (isset($params[ 'name' ])) ? $params[ 'name' ] : 'default';
if (!isset($counters[$name])) { if (!isset($counters[ $name ])) {
$counters[$name] = array( $counters[ $name ] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1);
'start' => 1,
'skip' => 1,
'direction' => 'up',
'count' => 1
);
} }
$counter =& $counters[$name]; $counter =& $counters[ $name ];
if (isset($params['start'])) { if (isset($params[ 'start' ])) {
$counter['start'] = $counter['count'] = (int) $params['start']; $counter[ 'start' ] = $counter[ 'count' ] = (int) $params[ 'start' ];
} }
if (!empty($params['assign'])) { if (!empty($params[ 'assign' ])) {
$counter['assign'] = $params['assign']; $counter[ 'assign' ] = $params[ 'assign' ];
} }
if (isset($counter['assign'])) { if (isset($counter[ 'assign' ])) {
$template->assign($counter['assign'], $counter['count']); $template->assign($counter[ 'assign' ], $counter[ 'count' ]);
} }
if (isset($params['print'])) { if (isset($params[ 'print' ])) {
$print = (bool) $params['print']; $print = (bool) $params[ 'print' ];
} else { } else {
$print = empty($counter['assign']); $print = empty($counter[ 'assign' ]);
} }
if ($print) { if ($print) {
$retval = $counter['count']; $retval = $counter[ 'count' ];
} else { } else {
$retval = null; $retval = null;
} }
if (isset($params['skip'])) { if (isset($params[ 'skip' ])) {
$counter['skip'] = $params['skip']; $counter[ 'skip' ] = $params[ 'skip' ];
} }
if (isset($params['direction'])) { if (isset($params[ 'direction' ])) {
$counter['direction'] = $params['direction']; $counter[ 'direction' ] = $params[ 'direction' ];
} }
if ($counter['direction'] == "down") { if ($counter[ 'direction' ] == "down") {
$counter['count'] -= $counter['skip']; $counter[ 'count' ] -= $counter[ 'skip' ];
} else { } else {
$counter['count'] += $counter['skip']; $counter[ 'count' ] += $counter[ 'skip' ];
} }
return $retval; return $retval;

View File

@@ -48,58 +48,56 @@ function smarty_function_cycle($params, $template)
{ {
static $cycle_vars; static $cycle_vars;
$name = (empty($params['name'])) ? 'default' : $params['name']; $name = (empty($params[ 'name' ])) ? 'default' : $params[ 'name' ];
$print = (isset($params['print'])) ? (bool) $params['print'] : true; $print = (isset($params[ 'print' ])) ? (bool) $params[ 'print' ] : true;
$advance = (isset($params['advance'])) ? (bool) $params['advance'] : true; $advance = (isset($params[ 'advance' ])) ? (bool) $params[ 'advance' ] : true;
$reset = (isset($params['reset'])) ? (bool) $params['reset'] : false; $reset = (isset($params[ 'reset' ])) ? (bool) $params[ 'reset' ] : false;
if (!isset($params['values'])) { if (!isset($params[ 'values' ])) {
if (!isset($cycle_vars[$name]['values'])) { if (!isset($cycle_vars[ $name ][ 'values' ])) {
trigger_error("cycle: missing 'values' parameter"); trigger_error("cycle: missing 'values' parameter");
return; return;
} }
} else { } else {
if (isset($cycle_vars[$name]['values']) if (isset($cycle_vars[ $name ][ 'values' ]) && $cycle_vars[ $name ][ 'values' ] != $params[ 'values' ]) {
&& $cycle_vars[$name]['values'] != $params['values'] $cycle_vars[ $name ][ 'index' ] = 0;
) {
$cycle_vars[$name]['index'] = 0;
} }
$cycle_vars[$name]['values'] = $params['values']; $cycle_vars[ $name ][ 'values' ] = $params[ 'values' ];
} }
if (isset($params['delimiter'])) { if (isset($params[ 'delimiter' ])) {
$cycle_vars[$name]['delimiter'] = $params['delimiter']; $cycle_vars[ $name ][ 'delimiter' ] = $params[ 'delimiter' ];
} elseif (!isset($cycle_vars[$name]['delimiter'])) { } elseif (!isset($cycle_vars[ $name ][ 'delimiter' ])) {
$cycle_vars[$name]['delimiter'] = ','; $cycle_vars[ $name ][ 'delimiter' ] = ',';
} }
if (is_array($cycle_vars[$name]['values'])) { if (is_array($cycle_vars[ $name ][ 'values' ])) {
$cycle_array = $cycle_vars[$name]['values']; $cycle_array = $cycle_vars[ $name ][ 'values' ];
} else { } else {
$cycle_array = explode($cycle_vars[$name]['delimiter'], $cycle_vars[$name]['values']); $cycle_array = explode($cycle_vars[ $name ][ 'delimiter' ], $cycle_vars[ $name ][ 'values' ]);
} }
if (!isset($cycle_vars[$name]['index']) || $reset) { if (!isset($cycle_vars[ $name ][ 'index' ]) || $reset) {
$cycle_vars[$name]['index'] = 0; $cycle_vars[ $name ][ 'index' ] = 0;
} }
if (isset($params['assign'])) { if (isset($params[ 'assign' ])) {
$print = false; $print = false;
$template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]); $template->assign($params[ 'assign' ], $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]);
} }
if ($print) { if ($print) {
$retval = $cycle_array[$cycle_vars[$name]['index']]; $retval = $cycle_array[ $cycle_vars[ $name ][ 'index' ] ];
} else { } else {
$retval = null; $retval = null;
} }
if ($advance) { if ($advance) {
if ($cycle_vars[$name]['index'] >= count($cycle_array) - 1) { if ($cycle_vars[ $name ][ 'index' ] >= count($cycle_array) - 1) {
$cycle_vars[$name]['index'] = 0; $cycle_vars[ $name ][ 'index' ] = 0;
} else { } else {
$cycle_vars[$name]['index'] ++; $cycle_vars[ $name ][ 'index' ] ++;
} }
} }

View File

@@ -24,31 +24,31 @@
*/ */
function smarty_function_fetch($params, $template) function smarty_function_fetch($params, $template)
{ {
if (empty($params['file'])) { 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; return;
} }
// strip file protocol // strip file protocol
if (stripos($params['file'], 'file://') === 0) { if (stripos($params[ 'file' ], 'file://') === 0) {
$params['file'] = substr($params['file'], 7); $params[ 'file' ] = substr($params[ 'file' ], 7);
} }
$protocol = strpos($params['file'], '://'); $protocol = strpos($params[ 'file' ], '://');
if ($protocol !== false) { if ($protocol !== false) {
$protocol = strtolower(substr($params['file'], 0, $protocol)); $protocol = strtolower(substr($params[ 'file' ], 0, $protocol));
} }
if (isset($template->smarty->security_policy)) { if (isset($template->smarty->security_policy)) {
if ($protocol) { if ($protocol) {
// remote resource (or php stream, …) // remote resource (or php stream, …)
if (!$template->smarty->security_policy->isTrustedUri($params['file'])) { if (!$template->smarty->security_policy->isTrustedUri($params[ 'file' ])) {
return; return;
} }
} else { } else {
// local file // local file
if (!$template->smarty->security_policy->isTrustedResourceDir($params['file'])) { if (!$template->smarty->security_policy->isTrustedResourceDir($params[ 'file' ])) {
return; return;
} }
} }
@@ -57,26 +57,26 @@ function smarty_function_fetch($params, $template)
$content = ''; $content = '';
if ($protocol == 'http') { if ($protocol == 'http') {
// http fetch // http fetch
if ($uri_parts = parse_url($params['file'])) { if ($uri_parts = parse_url($params[ 'file' ])) {
// set defaults // set defaults
$host = $server_name = $uri_parts['host']; $host = $server_name = $uri_parts[ 'host' ];
$timeout = 30; $timeout = 30;
$accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
$agent = "Smarty Template Engine " . Smarty::SMARTY_VERSION; $agent = "Smarty Template Engine " . Smarty::SMARTY_VERSION;
$referer = ""; $referer = "";
$uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/'; $uri = !empty($uri_parts[ 'path' ]) ? $uri_parts[ 'path' ] : '/';
$uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : ''; $uri .= !empty($uri_parts[ 'query' ]) ? '?' . $uri_parts[ 'query' ] : '';
$_is_proxy = false; $_is_proxy = false;
if (empty($uri_parts['port'])) { if (empty($uri_parts[ 'port' ])) {
$port = 80; $port = 80;
} else { } else {
$port = $uri_parts['port']; $port = $uri_parts[ 'port' ];
} }
if (!empty($uri_parts['user'])) { if (!empty($uri_parts[ 'user' ])) {
$user = $uri_parts['user']; $user = $uri_parts[ 'user' ];
} }
if (!empty($uri_parts['pass'])) { if (!empty($uri_parts[ 'pass' ])) {
$pass = $uri_parts['pass']; $pass = $uri_parts[ 'pass' ];
} }
// loop through parameters, setup headers // loop through parameters, setup headers
foreach ($params as $param_key => $param_value) { foreach ($params as $param_key => $param_value) {
@@ -163,7 +163,7 @@ function smarty_function_fetch($params, $template)
return; return;
} else { } else {
if ($_is_proxy) { if ($_is_proxy) {
fputs($fp, 'GET ' . $params['file'] . " HTTP/1.0\r\n"); fputs($fp, 'GET ' . $params[ 'file' ] . " HTTP/1.0\r\n");
} else { } else {
fputs($fp, "GET $uri HTTP/1.0\r\n"); fputs($fp, "GET $uri HTTP/1.0\r\n");
} }
@@ -195,10 +195,10 @@ function smarty_function_fetch($params, $template)
fclose($fp); fclose($fp);
$csplit = preg_split("!\r\n\r\n!", $content, 2); $csplit = preg_split("!\r\n\r\n!", $content, 2);
$content = $csplit[1]; $content = $csplit[ 1 ];
if (!empty($params['assign_headers'])) { if (!empty($params[ 'assign_headers' ])) {
$template->assign($params['assign_headers'], preg_split("!\r\n!", $csplit[0])); $template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ]));
} }
} }
} else { } else {
@@ -207,14 +207,14 @@ function smarty_function_fetch($params, $template)
return; return;
} }
} else { } else {
$content = @file_get_contents($params['file']); $content = @file_get_contents($params[ 'file' ]);
if ($content === false) { if ($content === false) {
throw new SmartyException("{fetch} cannot read resource '" . $params['file'] . "'"); throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'");
} }
} }
if (!empty($params['assign'])) { if (!empty($params[ 'assign' ])) {
$template->assign($params['assign'], $content); $template->assign($params[ 'assign' ], $content);
} else { } else {
return $content; return $content;
} }

View File

@@ -90,19 +90,21 @@ function smarty_function_html_checkboxes($params, $template)
if (method_exists($_sel, "__toString")) { if (method_exists($_sel, "__toString")) {
$_sel = smarty_function_escape_special_chars((string) $_sel->__toString()); $_sel = smarty_function_escape_special_chars((string) $_sel->__toString());
} else { } 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; continue;
} }
} else { } else {
$_sel = smarty_function_escape_special_chars((string) $_sel); $_sel = smarty_function_escape_special_chars((string) $_sel);
} }
$selected[$_sel] = true; $selected[ $_sel ] = true;
} }
} elseif (is_object($_val)) { } elseif (is_object($_val)) {
if (method_exists($_val, "__toString")) { if (method_exists($_val, "__toString")) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString()); $selected = smarty_function_escape_special_chars((string) $_val->__toString());
} else { } 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 { } else {
$selected = smarty_function_escape_special_chars((string) $_val); $selected = smarty_function_escape_special_chars((string) $_val);
@@ -110,7 +112,8 @@ function smarty_function_html_checkboxes($params, $template)
break; break;
case 'checkboxes': case 'checkboxes':
trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING); trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead',
E_USER_WARNING);
$options = (array) $_val; $options = (array) $_val;
break; break;
@@ -122,9 +125,10 @@ function smarty_function_html_checkboxes($params, $template)
case 'disabled': case 'disabled':
case 'readonly': case 'readonly':
if (!empty($params['strict'])) { if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) { if (!is_scalar($_val)) {
trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE); trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
E_USER_NOTICE);
} }
if ($_val === true || $_val === $_key) { if ($_val === true || $_val === $_key) {
@@ -153,23 +157,28 @@ function smarty_function_html_checkboxes($params, $template)
if (isset($options)) { if (isset($options)) {
foreach ($options as $_key => $_val) { foreach ($options as $_key => $_val) {
$_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape); $_html_result[] =
smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape);
} }
} else { } else {
foreach ($values as $_i => $_key) { foreach ($values as $_i => $_key) {
$_val = isset($output[$_i]) ? $output[$_i] : ''; $_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
$_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape); $_html_result[] =
smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape);
} }
} }
if (!empty($params['assign'])) { if (!empty($params[ 'assign' ])) {
$template->assign($params['assign'], $_html_result); $template->assign($params[ 'assign' ], $_html_result);
} else { } else {
return implode("\n", $_html_result); return implode("\n", $_html_result);
} }
} }
function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape = true) function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels,
$label_ids, $escape = true)
{ {
$_output = ''; $_output = '';
@@ -177,7 +186,8 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
if (method_exists($value, "__toString")) { if (method_exists($value, "__toString")) {
$value = (string) $value->__toString(); $value = (string) $value->__toString();
} else { } 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 ''; return '';
} }
@@ -189,7 +199,8 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
if (method_exists($output, "__toString")) { if (method_exists($output, "__toString")) {
$output = (string) $output->__toString(); $output = (string) $output->__toString();
} else { } 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 ''; return '';
} }
@@ -199,7 +210,8 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
if ($labels) { if ($labels) {
if ($label_ids) { if ($label_ids) {
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', $name . '_' . $value)); $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_',
$name . '_' . $value));
$_output .= '<label for="' . $_id . '">'; $_output .= '<label for="' . $_id . '">';
} else { } else {
$_output .= '<label>'; $_output .= '<label>';
@@ -219,7 +231,7 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
} }
if (is_array($selected)) { if (is_array($selected)) {
if (isset($selected[$value])) { if (isset($selected[ $value ])) {
$_output .= ' checked="checked"'; $_output .= ' checked="checked"';
} }
} elseif ($value === $selected) { } elseif ($value === $selected) {

View File

@@ -48,7 +48,7 @@ function smarty_function_html_image($params, $template)
$prefix = ''; $prefix = '';
$suffix = ''; $suffix = '';
$path_prefix = ''; $path_prefix = '';
$basedir = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : ''; $basedir = isset($_SERVER[ 'DOCUMENT_ROOT' ]) ? $_SERVER[ 'DOCUMENT_ROOT' ] : '';
foreach ($params as $_key => $_val) { foreach ($params as $_key => $_val) {
switch ($_key) { switch ($_key) {
case 'file': case 'file':
@@ -90,26 +90,26 @@ function smarty_function_html_image($params, $template)
return; return;
} }
if ($file[0] == '/') { if ($file[ 0 ] == '/') {
$_image_path = $basedir . $file; $_image_path = $basedir . $file;
} else { } else {
$_image_path = $file; $_image_path = $file;
} }
// strip file protocol // strip file protocol
if (stripos($params['file'], 'file://') === 0) { if (stripos($params[ 'file' ], 'file://') === 0) {
$params['file'] = substr($params['file'], 7); $params[ 'file' ] = substr($params[ 'file' ], 7);
} }
$protocol = strpos($params['file'], '://'); $protocol = strpos($params[ 'file' ], '://');
if ($protocol !== false) { if ($protocol !== false) {
$protocol = strtolower(substr($params['file'], 0, $protocol)); $protocol = strtolower(substr($params[ 'file' ], 0, $protocol));
} }
if (isset($template->smarty->security_policy)) { if (isset($template->smarty->security_policy)) {
if ($protocol) { if ($protocol) {
// remote resource (or php stream, …) // remote resource (or php stream, …)
if (!$template->smarty->security_policy->isTrustedUri($params['file'])) { if (!$template->smarty->security_policy->isTrustedUri($params[ 'file' ])) {
return; return;
} }
} else { } else {
@@ -120,7 +120,7 @@ function smarty_function_html_image($params, $template)
} }
} }
if (!isset($params['width']) || !isset($params['height'])) { if (!isset($params[ 'width' ]) || !isset($params[ 'height' ])) {
// FIXME: (rodneyrehm) getimagesize() loads the complete file off a remote resource, use custom [jpg,png,gif]header reader! // 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 (!$_image_data = @getimagesize($_image_path)) {
if (!file_exists($_image_path)) { if (!file_exists($_image_path)) {
@@ -138,26 +138,27 @@ function smarty_function_html_image($params, $template)
} }
} }
if (!isset($params['width'])) { if (!isset($params[ 'width' ])) {
$width = $_image_data[0]; $width = $_image_data[ 0 ];
} }
if (!isset($params['height'])) { if (!isset($params[ 'height' ])) {
$height = $_image_data[1]; $height = $_image_data[ 1 ];
} }
} }
if (isset($params['dpi'])) { if (isset($params[ 'dpi' ])) {
if (strstr($_SERVER['HTTP_USER_AGENT'], 'Mac')) { if (strstr($_SERVER[ 'HTTP_USER_AGENT' ], 'Mac')) {
// FIXME: (rodneyrehm) wrong dpi assumption // FIXME: (rodneyrehm) wrong dpi assumption
// don't know who thought this up… even if it was true in 1998, it's definitely wrong in 2011. // don't know who thought this up… even if it was true in 1998, it's definitely wrong in 2011.
$dpi_default = 72; $dpi_default = 72;
} else { } else {
$dpi_default = 96; $dpi_default = 96;
} }
$_resize = $dpi_default / $params['dpi']; $_resize = $dpi_default / $params[ 'dpi' ];
$width = round($width * $_resize); $width = round($width * $_resize);
$height = round($height * $_resize); $height = round($height * $_resize);
} }
return $prefix . '<img src="' . $path_prefix . $file . '" alt="' . $alt . '" width="' . $width . '" height="' . $height . '"' . $extra . ' />' . $suffix; return $prefix . '<img src="' . $path_prefix . $file . '" alt="' . $alt . '" width="' . $width . '" height="' .
$height . '"' . $extra . ' />' . $suffix;
} }

View File

@@ -72,19 +72,21 @@ function smarty_function_html_options($params)
if (method_exists($_sel, "__toString")) { if (method_exists($_sel, "__toString")) {
$_sel = smarty_function_escape_special_chars((string) $_sel->__toString()); $_sel = smarty_function_escape_special_chars((string) $_sel->__toString());
} else { } 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; continue;
} }
} else { } else {
$_sel = smarty_function_escape_special_chars((string) $_sel); $_sel = smarty_function_escape_special_chars((string) $_sel);
} }
$selected[$_sel] = true; $selected[ $_sel ] = true;
} }
} elseif (is_object($_val)) { } elseif (is_object($_val)) {
if (method_exists($_val, "__toString")) { if (method_exists($_val, "__toString")) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString()); $selected = smarty_function_escape_special_chars((string) $_val->__toString());
} else { } 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 { } else {
$selected = smarty_function_escape_special_chars((string) $_val); $selected = smarty_function_escape_special_chars((string) $_val);
@@ -96,9 +98,10 @@ function smarty_function_html_options($params)
case 'disabled': case 'disabled':
case 'readonly': case 'readonly':
if (!empty($params['strict'])) { if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) { if (!is_scalar($_val)) {
trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE); trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
E_USER_NOTICE);
} }
if ($_val === true || $_val === $_key) { if ($_val === true || $_val === $_key) {
@@ -134,7 +137,7 @@ function smarty_function_html_options($params)
} }
} else { } else {
foreach ($values as $_i => $_key) { foreach ($values as $_i => $_key) {
$_val = isset($output[$_i]) ? $output[$_i] : ''; $_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx); $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx);
} }
} }
@@ -142,7 +145,9 @@ function smarty_function_html_options($params)
if (!empty($name)) { if (!empty($name)) {
$_html_class = !empty($class) ? ' class="' . $class . '"' : ''; $_html_class = !empty($class) ? ' class="' . $class . '"' : '';
$_html_id = !empty($id) ? ' id="' . $id . '"' : ''; $_html_id = !empty($id) ? ' id="' . $id . '"' : '';
$_html_result = '<select name="' . $name . '"' . $_html_class . $_html_id . $extra . '>' . "\n" . $_html_result . '</select>' . "\n"; $_html_result =
'<select name="' . $name . '"' . $_html_class . $_html_id . $extra . '>' . "\n" . $_html_result .
'</select>' . "\n";
} }
return $_html_result; return $_html_result;
@@ -154,7 +159,7 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
$_key = smarty_function_escape_special_chars($key); $_key = smarty_function_escape_special_chars($key);
$_html_result = '<option value="' . $_key . '"'; $_html_result = '<option value="' . $_key . '"';
if (is_array($selected)) { if (is_array($selected)) {
if (isset($selected[$_key])) { if (isset($selected[ $_key ])) {
$_html_result .= ' selected="selected"'; $_html_result .= ' selected="selected"';
} }
} elseif ($_key === $selected) { } elseif ($_key === $selected) {
@@ -166,7 +171,8 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
if (method_exists($value, "__toString")) { if (method_exists($value, "__toString")) {
$value = smarty_function_escape_special_chars((string) $value->__toString()); $value = smarty_function_escape_special_chars((string) $value->__toString());
} else { } 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 ''; return '';
} }
@@ -177,7 +183,9 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
$idx ++; $idx ++;
} else { } else {
$_idx = 0; $_idx = 0;
$_html_result = smarty_function_html_options_optgroup($key, $value, $selected, !empty($id) ? ($id . '-' . $idx) : null, $class, $_idx); $_html_result =
smarty_function_html_options_optgroup($key, $value, $selected, !empty($id) ? ($id . '-' . $idx) : null,
$class, $_idx);
$idx ++; $idx ++;
} }

View File

@@ -73,7 +73,8 @@ function smarty_function_html_radios($params, $template)
if (method_exists($_val, "__toString")) { if (method_exists($_val, "__toString")) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString()); $selected = smarty_function_escape_special_chars((string) $_val->__toString());
} else { } 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 { } else {
$selected = (string) $_val; $selected = (string) $_val;
@@ -96,7 +97,8 @@ function smarty_function_html_radios($params, $template)
break; break;
case 'radios': case 'radios':
trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING); trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead',
E_USER_WARNING);
$options = (array) $_val; $options = (array) $_val;
break; break;
@@ -108,9 +110,10 @@ function smarty_function_html_radios($params, $template)
case 'disabled': case 'disabled':
case 'readonly': case 'readonly':
if (!empty($params['strict'])) { if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) { if (!is_scalar($_val)) {
trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE); trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
E_USER_NOTICE);
} }
if ($_val === true || $_val === $_key) { if ($_val === true || $_val === $_key) {
@@ -141,23 +144,28 @@ function smarty_function_html_radios($params, $template)
if (isset($options)) { if (isset($options)) {
foreach ($options as $_key => $_val) { foreach ($options as $_key => $_val) {
$_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape); $_html_result[] =
smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape);
} }
} else { } else {
foreach ($values as $_i => $_key) { foreach ($values as $_i => $_key) {
$_val = isset($output[$_i]) ? $output[$_i] : ''; $_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
$_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape); $_html_result[] =
smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
$label_ids, $escape);
} }
} }
if (!empty($params['assign'])) { if (!empty($params[ 'assign' ])) {
$template->assign($params['assign'], $_html_result); $template->assign($params[ 'assign' ], $_html_result);
} else { } else {
return implode("\n", $_html_result); return implode("\n", $_html_result);
} }
} }
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape) function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids,
$escape)
{ {
$_output = ''; $_output = '';
@@ -165,7 +173,8 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
if (method_exists($value, "__toString")) { if (method_exists($value, "__toString")) {
$value = (string) $value->__toString(); $value = (string) $value->__toString();
} else { } 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 ''; return '';
} }
@@ -177,7 +186,8 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
if (method_exists($output, "__toString")) { if (method_exists($output, "__toString")) {
$output = (string) $output->__toString(); $output = (string) $output->__toString();
} else { } 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 ''; return '';
} }
@@ -187,7 +197,8 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
if ($labels) { if ($labels) {
if ($label_ids) { if ($label_ids) {
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', $name . '_' . $value)); $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_',
$name . '_' . $value));
$_output .= '<label for="' . $_id . '">'; $_output .= '<label for="' . $_id . '">';
} else { } else {
$_output .= '<label>'; $_output .= '<label>';

View File

@@ -59,7 +59,7 @@ function smarty_function_html_select_date($params)
$_current_year = date('Y'); $_current_year = date('Y');
$_month_timestamps = array(); $_month_timestamps = array();
for ($i = 1; $i <= 12; $i ++) { for ($i = 1; $i <= 12; $i ++) {
$_month_timestamps[$i] = mktime(0, 0, 0, $i, 1, 2000); $_month_timestamps[ $i ] = mktime(0, 0, 0, $i, 1, 2000);
} }
} }
@@ -177,22 +177,21 @@ function smarty_function_html_select_date($params)
// Note: date() is faster than strftime() // Note: date() is faster than strftime()
// Note: explode(date()) is faster than date() date() date() // Note: explode(date()) is faster than date() date() date()
if (isset($params['time']) && is_array($params['time'])) { if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
if (isset($params['time'][$prefix . 'Year'])) { if (isset($params[ 'time' ][ $prefix . 'Year' ])) {
// $_REQUEST[$field_array] given // $_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 = '_' . strtolower($_elementName);
$$_variableName = isset($params['time'][$prefix . $_elementName]) $$_variableName =
? $params['time'][$prefix . $_elementName] isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
: date($_elementKey); date($_elementKey);
} }
} elseif (isset($params['time'][$field_array][$prefix . 'Year'])) { } elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Year' ])) {
// $_REQUEST given // $_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 = '_' . strtolower($_elementName);
$$_variableName = isset($params['time'][$field_array][$prefix . $_elementName]) $$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
? $params['time'][$field_array][$prefix . $_elementName] $params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
: date($_elementKey);
} }
} else { } else {
// no date found, use NOW // no date found, use NOW
@@ -215,10 +214,10 @@ function smarty_function_html_select_date($params)
$t = $$key; $t = $$key;
if ($t === null) { if ($t === null) {
$$key = (int) $_current_year; $$key = (int) $_current_year;
} elseif ($t[0] == '+') { } elseif ($t[ 0 ] == '+') {
$$key = (int) ($_current_year + (int)trim(substr($t, 1))); $$key = (int) ($_current_year + (int) trim(substr($t, 1)));
} elseif ($t[0] == '-') { } elseif ($t[ 0 ] == '-') {
$$key = (int) ($_current_year - (int)trim(substr($t, 1))); $$key = (int) ($_current_year - (int) trim(substr($t, 1)));
} else { } else {
$$key = (int) $$key; $$key = (int) $$key;
} }
@@ -243,13 +242,16 @@ function smarty_function_html_select_date($params)
} }
if ($year_as_text) { if ($year_as_text) {
$_html_years = '<input type="text" name="' . $_name . '" value="' . $_year . '" size="4" maxlength="4"' . $_extra . $extra_attrs . ' />'; $_html_years =
'<input type="text" name="' . $_name . '" value="' . $_year . '" size="4" maxlength="4"' . $_extra .
$extra_attrs . ' />';
} else { } else {
$_html_years = '<select name="' . $_name . '"'; $_html_years = '<select name="' . $_name . '"';
if ($year_id !== null || $all_id !== null) { if ($year_id !== null || $all_id !== null) {
$_html_years .= ' id="' . smarty_function_escape_special_chars( $_html_years .= ' id="' . smarty_function_escape_special_chars($year_id !== null ?
$year_id !== null ? ($year_id ? $year_id : $_name) : ($all_id ? ($all_id . $_name) : $_name) ($year_id ? $year_id : $_name) :
) . '"'; ($all_id ? ($all_id . $_name) :
$_name)) . '"';
} }
if ($year_size) { if ($year_size) {
$_html_years .= ' size="' . $year_size . '"'; $_html_years .= ' size="' . $year_size . '"';
@@ -257,14 +259,14 @@ function smarty_function_html_select_date($params)
$_html_years .= $_extra . $extra_attrs . '>' . $option_separator; $_html_years .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($year_empty) || isset($all_empty)) { if (isset($year_empty) || isset($all_empty)) {
$_html_years .= '<option value="">' . (isset($year_empty) ? $year_empty : $all_empty) . '</option>' . $option_separator; $_html_years .= '<option value="">' . (isset($year_empty) ? $year_empty : $all_empty) . '</option>' .
$option_separator;
} }
$op = $start_year > $end_year ? - 1 : 1; $op = $start_year > $end_year ? - 1 : 1;
for ($i = $start_year; $op > 0 ? $i <= $end_year : $i >= $end_year; $i += $op) { for ($i = $start_year; $op > 0 ? $i <= $end_year : $i >= $end_year; $i += $op) {
$_html_years .= '<option value="' . $i . '"' $_html_years .= '<option value="' . $i . '"' . ($_year == $i ? ' selected="selected"' : '') . '>' . $i .
. ($_year == $i ? ' selected="selected"' : '') '</option>' . $option_separator;
. '>' . $i . '</option>' . $option_separator;
} }
$_html_years .= '</select>'; $_html_years .= '</select>';
@@ -284,9 +286,10 @@ function smarty_function_html_select_date($params)
$_html_months = '<select name="' . $_name . '"'; $_html_months = '<select name="' . $_name . '"';
if ($month_id !== null || $all_id !== null) { if ($month_id !== null || $all_id !== null) {
$_html_months .= ' id="' . smarty_function_escape_special_chars( $_html_months .= ' id="' . smarty_function_escape_special_chars($month_id !== null ?
$month_id !== null ? ($month_id ? $month_id : $_name) : ($all_id ? ($all_id . $_name) : $_name) ($month_id ? $month_id : $_name) :
) . '"'; ($all_id ? ($all_id . $_name) :
$_name)) . '"';
} }
if ($month_size) { if ($month_size) {
$_html_months .= ' size="' . $month_size . '"'; $_html_months .= ' size="' . $month_size . '"';
@@ -294,16 +297,17 @@ function smarty_function_html_select_date($params)
$_html_months .= $_extra . $extra_attrs . '>' . $option_separator; $_html_months .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($month_empty) || isset($all_empty)) { if (isset($month_empty) || isset($all_empty)) {
$_html_months .= '<option value="">' . (isset($month_empty) ? $month_empty : $all_empty) . '</option>' . $option_separator; $_html_months .= '<option value="">' . (isset($month_empty) ? $month_empty : $all_empty) . '</option>' .
$option_separator;
} }
for ($i = 1; $i <= 12; $i ++) { for ($i = 1; $i <= 12; $i ++) {
$_val = sprintf('%02d', $i); $_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])); $_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[ $i ]) :
$_value = $month_value_format == "%m" ? $_val : strftime($month_value_format, $_month_timestamps[$i]); ($month_format == "%m" ? $_val : strftime($month_format, $_month_timestamps[ $i ]));
$_html_months .= '<option value="' . $_value . '"' $_value = $month_value_format == "%m" ? $_val : strftime($month_value_format, $_month_timestamps[ $i ]);
. ($_val == $_month ? ' selected="selected"' : '') $_html_months .= '<option value="' . $_value . '"' . ($_val == $_month ? ' selected="selected"' : '') .
. '>' . $_text . '</option>' . $option_separator; '>' . $_text . '</option>' . $option_separator;
} }
$_html_months .= '</select>'; $_html_months .= '</select>';
@@ -322,9 +326,9 @@ function smarty_function_html_select_date($params)
$_html_days = '<select name="' . $_name . '"'; $_html_days = '<select name="' . $_name . '"';
if ($day_id !== null || $all_id !== null) { if ($day_id !== null || $all_id !== null) {
$_html_days .= ' id="' . smarty_function_escape_special_chars( $_html_days .= ' id="' .
$day_id !== null ? ($day_id ? $day_id : $_name) : ($all_id ? ($all_id . $_name) : $_name) smarty_function_escape_special_chars($day_id !== null ? ($day_id ? $day_id : $_name) :
) . '"'; ($all_id ? ($all_id . $_name) : $_name)) . '"';
} }
if ($day_size) { if ($day_size) {
$_html_days .= ' size="' . $day_size . '"'; $_html_days .= ' size="' . $day_size . '"';
@@ -332,16 +336,16 @@ function smarty_function_html_select_date($params)
$_html_days .= $_extra . $extra_attrs . '>' . $option_separator; $_html_days .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($day_empty) || isset($all_empty)) { if (isset($day_empty) || isset($all_empty)) {
$_html_days .= '<option value="">' . (isset($day_empty) ? $day_empty : $all_empty) . '</option>' . $option_separator; $_html_days .= '<option value="">' . (isset($day_empty) ? $day_empty : $all_empty) . '</option>' .
$option_separator;
} }
for ($i = 1; $i <= 31; $i ++) { for ($i = 1; $i <= 31; $i ++) {
$_val = sprintf('%02d', $i); $_val = sprintf('%02d', $i);
$_text = $day_format == '%02d' ? $_val : sprintf($day_format, $i); $_text = $day_format == '%02d' ? $_val : sprintf($day_format, $i);
$_value = $day_value_format == '%02d' ? $_val : sprintf($day_value_format, $i); $_value = $day_value_format == '%02d' ? $_val : sprintf($day_value_format, $i);
$_html_days .= '<option value="' . $_value . '"' $_html_days .= '<option value="' . $_value . '"' . ($_val == $_day ? ' selected="selected"' : '') . '>' .
. ($_val == $_day ? ' selected="selected"' : '') $_text . '</option>' . $option_separator;
. '>' . $_text . '</option>' . $option_separator;
} }
$_html_days .= '</select>'; $_html_days .= '</select>';
@@ -350,7 +354,7 @@ function smarty_function_html_select_date($params)
// order the fields for output // order the fields for output
$_html = ''; $_html = '';
for ($i = 0; $i <= 2; $i ++) { for ($i = 0; $i <= 2; $i ++) {
switch ($field_order[$i]) { switch ($field_order[ $i ]) {
case 'Y': case 'Y':
case 'y': case 'y':
if (isset($_html_years)) { if (isset($_html_years)) {

View File

@@ -148,31 +148,29 @@ function smarty_function_html_select_time($params)
} }
} }
if (isset($params['time']) && is_array($params['time'])) { if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
if (isset($params['time'][$prefix . 'Hour'])) { if (isset($params[ 'time' ][ $prefix . 'Hour' ])) {
// $_REQUEST[$field_array] given // $_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 = '_' . strtolower($_elementName);
$$_variableName = isset($params['time'][$prefix . $_elementName]) $$_variableName =
? $params['time'][$prefix . $_elementName] isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
: date($_elementKey); date($_elementKey);
} }
$_meridian = isset($params['time'][$prefix . 'Meridian']) $_meridian =
? (' ' . $params['time'][$prefix . 'Meridian']) isset($params[ 'time' ][ $prefix . 'Meridian' ]) ? (' ' . $params[ 'time' ][ $prefix . 'Meridian' ]) :
: ''; '';
$time = strtotime($_hour . ':' . $_minute . ':' . $_second . $_meridian); $time = strtotime($_hour . ':' . $_minute . ':' . $_second . $_meridian);
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time)); list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
} elseif (isset($params['time'][$field_array][$prefix . 'Hour'])) { } elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Hour' ])) {
// $_REQUEST given // $_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 = '_' . strtolower($_elementName);
$$_variableName = isset($params['time'][$field_array][$prefix . $_elementName]) $$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
? $params['time'][$field_array][$prefix . $_elementName] $params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
: date($_elementKey);
} }
$_meridian = isset($params['time'][$field_array][$prefix . 'Meridian']) $_meridian = isset($params[ 'time' ][ $field_array ][ $prefix . 'Meridian' ]) ?
? (' ' . $params['time'][$field_array][$prefix . 'Meridian']) (' ' . $params[ 'time' ][ $field_array ][ $prefix . 'Meridian' ]) : '';
: '';
$time = strtotime($_hour . ':' . $_minute . ':' . $_second . $_meridian); $time = strtotime($_hour . ':' . $_minute . ':' . $_second . $_meridian);
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time)); list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
} else { } else {
@@ -203,9 +201,9 @@ function smarty_function_html_select_time($params)
$_html_hours = '<select name="' . $_name . '"'; $_html_hours = '<select name="' . $_name . '"';
if ($hour_id !== null || $all_id !== null) { if ($hour_id !== null || $all_id !== null) {
$_html_hours .= ' id="' . smarty_function_escape_special_chars( $_html_hours .= ' id="' .
$hour_id !== null ? ($hour_id ? $hour_id : $_name) : ($all_id ? ($all_id . $_name) : $_name) smarty_function_escape_special_chars($hour_id !== null ? ($hour_id ? $hour_id : $_name) :
) . '"'; ($all_id ? ($all_id . $_name) : $_name)) . '"';
} }
if ($hour_size) { if ($hour_size) {
$_html_hours .= ' size="' . $hour_size . '"'; $_html_hours .= ' size="' . $hour_size . '"';
@@ -213,7 +211,8 @@ function smarty_function_html_select_time($params)
$_html_hours .= $_extra . $extra_attrs . '>' . $option_separator; $_html_hours .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($hour_empty) || isset($all_empty)) { if (isset($hour_empty) || isset($all_empty)) {
$_html_hours .= '<option value="">' . (isset($hour_empty) ? $hour_empty : $all_empty) . '</option>' . $option_separator; $_html_hours .= '<option value="">' . (isset($hour_empty) ? $hour_empty : $all_empty) . '</option>' .
$option_separator;
} }
$start = $use_24_hours ? 0 : 1; $start = $use_24_hours ? 0 : 1;
@@ -224,15 +223,12 @@ function smarty_function_html_select_time($params)
$_value = $hour_value_format == '%02d' ? $_val : sprintf($hour_value_format, $i); $_value = $hour_value_format == '%02d' ? $_val : sprintf($hour_value_format, $i);
if (!$use_24_hours) { if (!$use_24_hours) {
$_hour12 = $_hour == 0 $_hour12 = $_hour == 0 ? 12 : ($_hour <= 12 ? $_hour : $_hour - 12);
? 12
: ($_hour <= 12 ? $_hour : $_hour - 12);
} }
$selected = $_hour !== null ? ($use_24_hours ? $_hour == $_val : $_hour12 == $_val) : null; $selected = $_hour !== null ? ($use_24_hours ? $_hour == $_val : $_hour12 == $_val) : null;
$_html_hours .= '<option value="' . $_value . '"' $_html_hours .= '<option value="' . $_value . '"' . ($selected ? ' selected="selected"' : '') . '>' .
. ($selected ? ' selected="selected"' : '') $_text . '</option>' . $option_separator;
. '>' . $_text . '</option>' . $option_separator;
} }
$_html_hours .= '</select>'; $_html_hours .= '</select>';
@@ -252,9 +248,10 @@ function smarty_function_html_select_time($params)
$_html_minutes = '<select name="' . $_name . '"'; $_html_minutes = '<select name="' . $_name . '"';
if ($minute_id !== null || $all_id !== null) { if ($minute_id !== null || $all_id !== null) {
$_html_minutes .= ' id="' . smarty_function_escape_special_chars( $_html_minutes .= ' id="' . smarty_function_escape_special_chars($minute_id !== null ?
$minute_id !== null ? ($minute_id ? $minute_id : $_name) : ($all_id ? ($all_id . $_name) : $_name) ($minute_id ? $minute_id : $_name) :
) . '"'; ($all_id ? ($all_id . $_name) :
$_name)) . '"';
} }
if ($minute_size) { if ($minute_size) {
$_html_minutes .= ' size="' . $minute_size . '"'; $_html_minutes .= ' size="' . $minute_size . '"';
@@ -262,7 +259,8 @@ function smarty_function_html_select_time($params)
$_html_minutes .= $_extra . $extra_attrs . '>' . $option_separator; $_html_minutes .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($minute_empty) || isset($all_empty)) { if (isset($minute_empty) || isset($all_empty)) {
$_html_minutes .= '<option value="">' . (isset($minute_empty) ? $minute_empty : $all_empty) . '</option>' . $option_separator; $_html_minutes .= '<option value="">' . (isset($minute_empty) ? $minute_empty : $all_empty) . '</option>' .
$option_separator;
} }
$selected = $_minute !== null ? ($_minute - $_minute % $minute_interval) : null; $selected = $_minute !== null ? ($_minute - $_minute % $minute_interval) : null;
@@ -270,9 +268,8 @@ function smarty_function_html_select_time($params)
$_val = sprintf('%02d', $i); $_val = sprintf('%02d', $i);
$_text = $minute_format == '%02d' ? $_val : sprintf($minute_format, $i); $_text = $minute_format == '%02d' ? $_val : sprintf($minute_format, $i);
$_value = $minute_value_format == '%02d' ? $_val : sprintf($minute_value_format, $i); $_value = $minute_value_format == '%02d' ? $_val : sprintf($minute_value_format, $i);
$_html_minutes .= '<option value="' . $_value . '"' $_html_minutes .= '<option value="' . $_value . '"' . ($selected === $i ? ' selected="selected"' : '') .
. ($selected === $i ? ' selected="selected"' : '') '>' . $_text . '</option>' . $option_separator;
. '>' . $_text . '</option>' . $option_separator;
} }
$_html_minutes .= '</select>'; $_html_minutes .= '</select>';
@@ -292,9 +289,10 @@ function smarty_function_html_select_time($params)
$_html_seconds = '<select name="' . $_name . '"'; $_html_seconds = '<select name="' . $_name . '"';
if ($second_id !== null || $all_id !== null) { if ($second_id !== null || $all_id !== null) {
$_html_seconds .= ' id="' . smarty_function_escape_special_chars( $_html_seconds .= ' id="' . smarty_function_escape_special_chars($second_id !== null ?
$second_id !== null ? ($second_id ? $second_id : $_name) : ($all_id ? ($all_id . $_name) : $_name) ($second_id ? $second_id : $_name) :
) . '"'; ($all_id ? ($all_id . $_name) :
$_name)) . '"';
} }
if ($second_size) { if ($second_size) {
$_html_seconds .= ' size="' . $second_size . '"'; $_html_seconds .= ' size="' . $second_size . '"';
@@ -302,7 +300,8 @@ function smarty_function_html_select_time($params)
$_html_seconds .= $_extra . $extra_attrs . '>' . $option_separator; $_html_seconds .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($second_empty) || isset($all_empty)) { if (isset($second_empty) || isset($all_empty)) {
$_html_seconds .= '<option value="">' . (isset($second_empty) ? $second_empty : $all_empty) . '</option>' . $option_separator; $_html_seconds .= '<option value="">' . (isset($second_empty) ? $second_empty : $all_empty) . '</option>' .
$option_separator;
} }
$selected = $_second !== null ? ($_second - $_second % $second_interval) : null; $selected = $_second !== null ? ($_second - $_second % $second_interval) : null;
@@ -310,9 +309,8 @@ function smarty_function_html_select_time($params)
$_val = sprintf('%02d', $i); $_val = sprintf('%02d', $i);
$_text = $second_format == '%02d' ? $_val : sprintf($second_format, $i); $_text = $second_format == '%02d' ? $_val : sprintf($second_format, $i);
$_value = $second_value_format == '%02d' ? $_val : sprintf($second_value_format, $i); $_value = $second_value_format == '%02d' ? $_val : sprintf($second_value_format, $i);
$_html_seconds .= '<option value="' . $_value . '"' $_html_seconds .= '<option value="' . $_value . '"' . ($selected === $i ? ' selected="selected"' : '') .
. ($selected === $i ? ' selected="selected"' : '') '>' . $_text . '</option>' . $option_separator;
. '>' . $_text . '</option>' . $option_separator;
} }
$_html_seconds .= '</select>'; $_html_seconds .= '</select>';
@@ -332,9 +330,11 @@ function smarty_function_html_select_time($params)
$_html_meridian = '<select name="' . $_name . '"'; $_html_meridian = '<select name="' . $_name . '"';
if ($meridian_id !== null || $all_id !== null) { if ($meridian_id !== null || $all_id !== null) {
$_html_meridian .= ' id="' . smarty_function_escape_special_chars( $_html_meridian .= ' id="' . smarty_function_escape_special_chars($meridian_id !== null ?
$meridian_id !== null ? ($meridian_id ? $meridian_id : $_name) : ($all_id ? ($all_id . $_name) : $_name) ($meridian_id ? $meridian_id :
) . '"'; $_name) :
($all_id ? ($all_id . $_name) :
$_name)) . '"';
} }
if ($meridian_size) { if ($meridian_size) {
$_html_meridian .= ' size="' . $meridian_size . '"'; $_html_meridian .= ' size="' . $meridian_size . '"';
@@ -342,12 +342,14 @@ function smarty_function_html_select_time($params)
$_html_meridian .= $_extra . $extra_attrs . '>' . $option_separator; $_html_meridian .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($meridian_empty) || isset($all_empty)) { if (isset($meridian_empty) || isset($all_empty)) {
$_html_meridian .= '<option value="">' . (isset($meridian_empty) ? $meridian_empty : $all_empty) . '</option>' . $option_separator; $_html_meridian .= '<option value="">' . (isset($meridian_empty) ? $meridian_empty : $all_empty) .
'</option>' . $option_separator;
} }
$_html_meridian .= '<option value="am"' . ($_hour > 0 && $_hour < 12 ? ' selected="selected"' : '') . '>AM</option>' . $option_separator $_html_meridian .= '<option value="am"' . ($_hour > 0 && $_hour < 12 ? ' selected="selected"' : '') .
. '<option value="pm"' . ($_hour < 12 ? '' : ' selected="selected"') . '>PM</option>' . $option_separator '>AM</option>' . $option_separator . '<option value="pm"' .
. '</select>'; ($_hour < 12 ? '' : ' selected="selected"') . '>PM</option>' . $option_separator .
'</select>';
} }
$_html = ''; $_html = '';

View File

@@ -62,7 +62,7 @@ function smarty_function_html_table($params)
$caption = ''; $caption = '';
$loop = null; $loop = null;
if (!isset($params['loop'])) { if (!isset($params[ 'loop' ])) {
trigger_error("html_table: missing 'loop' parameter", E_USER_WARNING); trigger_error("html_table: missing 'loop' parameter", E_USER_WARNING);
return; return;
@@ -110,11 +110,11 @@ function smarty_function_html_table($params)
} }
$loop_count = count($loop); $loop_count = count($loop);
if (empty($params['rows'])) { if (empty($params[ 'rows' ])) {
/* no rows specified */ /* no rows specified */
$rows = ceil($loop_count / $cols_count); $rows = ceil($loop_count / $cols_count);
} elseif (empty($params['cols'])) { } elseif (empty($params[ 'cols' ])) {
if (!empty($params['rows'])) { if (!empty($params[ 'rows' ])) {
/* no cols specified, but rows */ /* no cols specified, but rows */
$cols_count = ceil($loop_count / $rows); $cols_count = ceil($loop_count / $rows);
} }
@@ -132,7 +132,7 @@ function smarty_function_html_table($params)
for ($r = 0; $r < $cols_count; $r ++) { for ($r = 0; $r < $cols_count; $r ++) {
$output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>'; $output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>';
$output .= $cols[$r]; $output .= $cols[ $r ];
$output .= "</th>\n"; $output .= "</th>\n";
} }
$output .= "</tr></thead>\n"; $output .= "</tr></thead>\n";
@@ -151,7 +151,7 @@ function smarty_function_html_table($params)
} }
if ($x < $loop_count) { if ($x < $loop_count) {
$output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n"; $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[ $x ] . "</td>\n";
} else { } else {
$output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">$trailpad</td>\n"; $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">$trailpad</td>\n";
} }
@@ -169,7 +169,7 @@ function smarty_function_html_table_cycle($name, $var, $no)
if (!is_array($var)) { if (!is_array($var)) {
$ret = $var; $ret = $var;
} else { } else {
$ret = $var[$no % count($var)]; $ret = $var[ $no % count($var) ];
} }
return ($ret) ? ' ' . $ret : ''; return ($ret) ? ' ' . $ret : '';

View File

@@ -50,15 +50,16 @@
*/ */
function smarty_function_mailto($params) function smarty_function_mailto($params)
{ {
static $_allowed_encoding = array('javascript' => true, 'javascript_charcode' => true, 'hex' => true, 'none' => true); static $_allowed_encoding =
array('javascript' => true, 'javascript_charcode' => true, 'hex' => true, 'none' => true);
$extra = ''; $extra = '';
if (empty($params['address'])) { if (empty($params[ 'address' ])) {
trigger_error("mailto: missing 'address' parameter", E_USER_WARNING); trigger_error("mailto: missing 'address' parameter", E_USER_WARNING);
return; return;
} else { } else {
$address = $params['address']; $address = $params[ 'address' ];
} }
$text = $address; $text = $address;
@@ -72,9 +73,9 @@ function smarty_function_mailto($params)
case 'cc': case 'cc':
case 'bcc': case 'bcc':
case 'followupto': case 'followupto':
if (!empty($value)) { if (!empty($value)) {
$mail_parms[] = $var . '=' . str_replace($search, $replace, rawurlencode($value)); $mail_parms[] = $var . '=' . str_replace($search, $replace, rawurlencode($value));
} }
break; break;
case 'subject': case 'subject':
@@ -94,9 +95,10 @@ function smarty_function_mailto($params)
$address .= '?' . join('&', $mail_parms); $address .= '?' . join('&', $mail_parms);
} }
$encode = (empty($params['encode'])) ? 'none' : $params['encode']; $encode = (empty($params[ 'encode' ])) ? 'none' : $params[ 'encode' ];
if (!isset($_allowed_encoding[$encode])) { if (!isset($_allowed_encoding[ $encode ])) {
trigger_error("mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex", E_USER_WARNING); trigger_error("mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex",
E_USER_WARNING);
return; return;
} }
@@ -106,7 +108,7 @@ function smarty_function_mailto($params)
$js_encode = ''; $js_encode = '';
for ($x = 0, $_length = strlen($string); $x < $_length; $x ++) { for ($x = 0, $_length = strlen($string); $x < $_length; $x ++) {
$js_encode .= '%' . bin2hex($string[$x]); $js_encode .= '%' . bin2hex($string[ $x ]);
} }
return '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>'; return '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>';
@@ -114,35 +116,31 @@ function smarty_function_mailto($params)
$string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>'; $string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
for ($x = 0, $y = strlen($string); $x < $y; $x ++) { for ($x = 0, $y = strlen($string); $x < $y; $x ++) {
$ord[] = ord($string[$x]); $ord[] = ord($string[ $x ]);
} }
$_ret = "<script type=\"text/javascript\" language=\"javascript\">\n" $_ret = "<script type=\"text/javascript\" language=\"javascript\">\n" . "{document.write(String.fromCharCode(" .
. "{document.write(String.fromCharCode(" implode(',', $ord) . "))" . "}\n" . "</script>\n";
. implode(',', $ord)
. "))"
. "}\n"
. "</script>\n";
return $_ret; return $_ret;
} elseif ($encode == 'hex') { } elseif ($encode == 'hex') {
preg_match('!^(.*)(\?.*)$!', $address, $match); preg_match('!^(.*)(\?.*)$!', $address, $match);
if (!empty($match[2])) { if (!empty($match[ 2 ])) {
trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.", E_USER_WARNING); trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.", E_USER_WARNING);
return; return;
} }
$address_encode = ''; $address_encode = '';
for ($x = 0, $_length = strlen($address); $x < $_length; $x ++) { for ($x = 0, $_length = strlen($address); $x < $_length; $x ++) {
if (preg_match('!\w!' . Smarty::$_UTF8_MODIFIER, $address[$x])) { if (preg_match('!\w!' . Smarty::$_UTF8_MODIFIER, $address[ $x ])) {
$address_encode .= '%' . bin2hex($address[$x]); $address_encode .= '%' . bin2hex($address[ $x ]);
} else { } else {
$address_encode .= $address[$x]; $address_encode .= $address[ $x ];
} }
} }
$text_encode = ''; $text_encode = '';
for ($x = 0, $_length = strlen($text); $x < $_length; $x ++) { for ($x = 0, $_length = strlen($text); $x < $_length; $x ++) {
$text_encode .= '&#x' . bin2hex($text[$x]) . ';'; $text_encode .= '&#x' . bin2hex($text[ $x ]) . ';';
} }
$mailto = "&#109;&#97;&#105;&#108;&#116;&#111;&#58;"; $mailto = "&#109;&#97;&#105;&#108;&#116;&#111;&#58;";

View File

@@ -24,19 +24,18 @@
*/ */
function smarty_function_math($params, $template) function smarty_function_math($params, $template)
{ {
static $_allowed_funcs = array( static $_allowed_funcs =
'int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true, array('int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true,
'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true, 'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true, 'rand' => true,
'rand' => true, 'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true 'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true);
);
// be sure equation parameter is present // be sure equation parameter is present
if (empty($params['equation'])) { if (empty($params[ 'equation' ])) {
trigger_error("math: missing equation parameter", E_USER_WARNING); trigger_error("math: missing equation parameter", E_USER_WARNING);
return; return;
} }
$equation = $params['equation']; $equation = $params[ 'equation' ];
// make sure parenthesis are balanced // make sure parenthesis are balanced
if (substr_count($equation, "(") != substr_count($equation, ")")) { if (substr_count($equation, "(") != substr_count($equation, ")")) {
@@ -48,8 +47,8 @@ function smarty_function_math($params, $template)
// match all vars in equation, make sure all are passed // match all vars in equation, make sure all are passed
preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]*)!", $equation, $match); preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]*)!", $equation, $match);
foreach ($match[1] as $curr_var) { foreach ($match[ 1 ] as $curr_var) {
if ($curr_var && !isset($params[$curr_var]) && !isset($_allowed_funcs[$curr_var])) { if ($curr_var && !isset($params[ $curr_var ]) && !isset($_allowed_funcs[ $curr_var ])) {
trigger_error("math: function call $curr_var not allowed", E_USER_WARNING); trigger_error("math: function call $curr_var not allowed", E_USER_WARNING);
return; return;
@@ -75,17 +74,17 @@ function smarty_function_math($params, $template)
$smarty_math_result = null; $smarty_math_result = null;
eval("\$smarty_math_result = " . $equation . ";"); eval("\$smarty_math_result = " . $equation . ";");
if (empty($params['format'])) { if (empty($params[ 'format' ])) {
if (empty($params['assign'])) { if (empty($params[ 'assign' ])) {
return $smarty_math_result; return $smarty_math_result;
} else { } else {
$template->assign($params['assign'], $smarty_math_result); $template->assign($params[ 'assign' ], $smarty_math_result);
} }
} else { } else {
if (empty($params['assign'])) { if (empty($params[ 'assign' ])) {
printf($params['format'], $smarty_math_result); printf($params[ 'format' ], $smarty_math_result);
} else { } else {
$template->assign($params['assign'], sprintf($params['format'], $smarty_math_result)); $template->assign($params[ 'assign' ], sprintf($params[ 'format' ], $smarty_math_result));
} }
} }
} }

View File

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

View File

@@ -33,7 +33,8 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
} }
foreach ($var as $curr_key => $curr_val) { foreach ($var as $curr_key => $curr_val) {
$results .= '<br>' . str_repeat('&nbsp;', $depth * 2) . '<b>' . strtr($curr_key, $_replace) . $results .= '<br>' . str_repeat('&nbsp;', $depth * 2) . '<b>' . strtr($curr_key, $_replace) .
'</b> =&gt; ' . smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects); '</b> =&gt; ' .
smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects);
$depth --; $depth --;
} }
break; break;
@@ -51,7 +52,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$objects[] = $var; $objects[] = $var;
foreach ($object_vars as $curr_key => $curr_val) { foreach ($object_vars as $curr_key => $curr_val) {
$results .= '<br>' . str_repeat('&nbsp;', $depth * 2) . '<b> -&gt;' . strtr($curr_key, $_replace) . $results .= '<br>' . str_repeat('&nbsp;', $depth * 2) . '<b> -&gt;' . strtr($curr_key, $_replace) .
'</b> = ' . smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects); '</b> = ' . smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects);
$depth --; $depth --;
} }
break; break;

View File

@@ -66,7 +66,8 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// php <5.2.3 - prevent double encoding // php <5.2.3 - prevent double encoding
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string, ENT_QUOTES, $char_set); $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; return $string;
} }
@@ -107,7 +108,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
$return = ''; $return = '';
$_length = strlen($string); $_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) { for ($x = 0; $x < $_length; $x ++) {
$return .= '%' . bin2hex($string[$x]); $return .= '%' . bin2hex($string[ $x ]);
} }
return $return; return $return;
@@ -126,7 +127,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// no MBString fallback // no MBString fallback
$_length = strlen($string); $_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) { for ($x = 0; $x < $_length; $x ++) {
$return .= '&#x' . bin2hex($string[$x]) . ';'; $return .= '&#x' . bin2hex($string[ $x ]) . ';';
} }
return $return; return $return;
@@ -145,14 +146,15 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// no MBString fallback // no MBString fallback
$_length = strlen($string); $_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) { for ($x = 0; $x < $_length; $x ++) {
$return .= '&#' . ord($string[$x]) . ';'; $return .= '&#' . ord($string[ $x ]) . ';';
} }
return $return; return $return;
case 'javascript': case 'javascript':
// escape quotes and backslashes, newlines, etc. // escape quotes and backslashes, newlines, etc.
return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', '</' => '<\/')); return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n',
'</' => '<\/'));
case 'mail': case 'mail':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {

View File

@@ -23,11 +23,11 @@
* *
* @return string * @return string
*/ */
function smarty_modifier_regex_replace($string, $search, $replace, $limit = -1) function smarty_modifier_regex_replace($string, $search, $replace, $limit = - 1)
{ {
if (is_array($search)) { if (is_array($search)) {
foreach ($search as $idx => $s) { foreach ($search as $idx => $s) {
$search[$idx] = _smarty_regex_replace_check($s); $search[ $idx ] = _smarty_regex_replace_check($s);
} }
} else { } else {
$search = _smarty_regex_replace_check($search); $search = _smarty_regex_replace_check($search);
@@ -50,8 +50,8 @@ function _smarty_regex_replace_check($search)
$search = substr($search, 0, $pos); $search = substr($search, 0, $pos);
} }
// remove eval-modifier from $search // remove eval-modifier from $search
if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) { if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[ 1 ], 'e') !== false)) {
$search = substr($search, 0, - strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]); $search = substr($search, 0, - strlen($match[ 1 ])) . preg_replace('![e\s]+!', '', $match[ 1 ]);
} }
return $search; return $search;

View File

@@ -35,20 +35,22 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if (mb_strlen($string, Smarty::$_CHARSET) > $length) { if (mb_strlen($string, Smarty::$_CHARSET) > $length) {
$length -= min($length, mb_strlen($etc, Smarty::$_CHARSET)); $length -= min($length, mb_strlen($etc, Smarty::$_CHARSET));
if (!$break_words && !$middle) { if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '', mb_substr($string, 0, $length + 1, Smarty::$_CHARSET)); $string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '',
mb_substr($string, 0, $length + 1, Smarty::$_CHARSET));
} }
if (!$middle) { if (!$middle) {
return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc; return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
} }
return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET); return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc .
mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET);
} }
return $string; return $string;
} }
// no MBString fallback // no MBString fallback
if (isset($string[$length])) { if (isset($string[ $length ])) {
$length -= min($length, strlen($etc)); $length -= min($length, strlen($etc));
if (!$break_words && !$middle) { if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1)); $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1));

View File

@@ -21,12 +21,12 @@
*/ */
function smarty_modifiercompiler_count_characters($params) 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)'; return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[ 0 ] . ', $tmp)';
} }
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_strlen(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; return 'mb_strlen(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
} }
// no MBString fallback // no MBString fallback
return 'strlen(' . $params[0] . ')'; return 'strlen(' . $params[ 0 ] . ')';
} }

View File

@@ -23,5 +23,5 @@
function smarty_modifiercompiler_count_paragraphs($params) function smarty_modifiercompiler_count_paragraphs($params)
{ {
// count \r or \n characters // count \r or \n characters
return '(preg_match_all(\'#[\r\n]+#\', ' . $params[0] . ', $tmp)+1)'; return '(preg_match_all(\'#[\r\n]+#\', ' . $params[ 0 ] . ', $tmp)+1)';
} }

View File

@@ -23,5 +23,5 @@
function smarty_modifiercompiler_count_sentences($params) function smarty_modifiercompiler_count_sentences($params)
{ {
// find periods, question marks, exclamation marks with a word before but not after. // find periods, question marks, exclamation marks with a word before but not after.
return 'preg_match_all("#\w[\.\?\!](\W|$)#S' . Smarty::$_UTF8_MODIFIER . '", ' . $params[0] . ', $tmp)'; return 'preg_match_all("#\w[\.\?\!](\W|$)#S' . Smarty::$_UTF8_MODIFIER . '", ' . $params[ 0 ] . ', $tmp)';
} }

View File

@@ -24,8 +24,9 @@ function smarty_modifiercompiler_count_words($params)
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
// return 'preg_match_all(\'#[\w\pL]+#' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)'; // return 'preg_match_all(\'#[\w\pL]+#' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)';
// expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592 // expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592
return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)'; return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . Smarty::$_UTF8_MODIFIER . '\', ' .
$params[ 0 ] . ', $tmp)';
} }
// no MBString fallback // no MBString fallback
return 'str_word_count(' . $params[0] . ')'; return 'str_word_count(' . $params[ 0 ] . ')';
} }

View File

@@ -21,9 +21,9 @@
*/ */
function smarty_modifiercompiler_default($params) function smarty_modifiercompiler_default($params)
{ {
$output = $params[0]; $output = $params[ 0 ];
if (!isset($params[1])) { if (!isset($params[ 1 ])) {
$params[1] = "''"; $params[ 1 ] = "''";
} }
array_shift($params); array_shift($params);

View File

@@ -44,14 +44,10 @@ function smarty_modifiercompiler_escape($params, $compiler)
switch ($esc_type) { switch ($esc_type) {
case 'html': case 'html':
if ($_double_encode) { if ($_double_encode) {
return 'htmlspecialchars(' return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
. $params[0] . ', ENT_QUOTES, ' var_export($double_encode, true) . ')';
. var_export($char_set, true) . ', '
. var_export($double_encode, true) . ')';
} elseif ($double_encode) { } elseif ($double_encode) {
return 'htmlspecialchars(' return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
. $params[0] . ', ENT_QUOTES, '
. var_export($char_set, true) . ')';
} else { } else {
// fall back to modifier.escape.php // fall back to modifier.escape.php
} }
@@ -60,19 +56,13 @@ function smarty_modifiercompiler_escape($params, $compiler)
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if ($_double_encode) { if ($_double_encode) {
// php >=5.2.3 - go native // php >=5.2.3 - go native
return 'mb_convert_encoding(htmlspecialchars(' return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' .
. $params[0] . ', ENT_QUOTES, ' var_export($char_set, true) . ', ' . var_export($double_encode, true) .
. var_export($char_set, true) . ', ' '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
. var_export($double_encode, true)
. '), "HTML-ENTITIES", '
. var_export($char_set, true) . ')';
} elseif ($double_encode) { } elseif ($double_encode) {
// php <5.2.3 - only handle double encoding // php <5.2.3 - only handle double encoding
return 'mb_convert_encoding(htmlspecialchars(' return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' .
. $params[0] . ', ENT_QUOTES, ' var_export($char_set, true) . '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
. var_export($char_set, true)
. '), "HTML-ENTITIES", '
. var_export($char_set, true) . ')';
} else { } else {
// fall back to modifier.escape.php // fall back to modifier.escape.php
} }
@@ -81,32 +71,29 @@ function smarty_modifiercompiler_escape($params, $compiler)
// no MBString fallback // no MBString fallback
if ($_double_encode) { if ($_double_encode) {
// php >=5.2.3 - go native // php >=5.2.3 - go native
return 'htmlentities(' return 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
. $params[0] . ', ENT_QUOTES, ' var_export($double_encode, true) . ')';
. var_export($char_set, true) . ', '
. var_export($double_encode, true) . ')';
} elseif ($double_encode) { } elseif ($double_encode) {
// php <5.2.3 - only handle double encoding // php <5.2.3 - only handle double encoding
return 'htmlentities(' return 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
. $params[0] . ', ENT_QUOTES, '
. var_export($char_set, true) . ')';
} else { } else {
// fall back to modifier.escape.php // fall back to modifier.escape.php
} }
case 'url': case 'url':
return 'rawurlencode(' . $params[0] . ')'; return 'rawurlencode(' . $params[ 0 ] . ')';
case 'urlpathinfo': case 'urlpathinfo':
return 'str_replace("%2F", "/", rawurlencode(' . $params[0] . '))'; return 'str_replace("%2F", "/", rawurlencode(' . $params[ 0 ] . '))';
case 'quotes': case 'quotes':
// escape unescaped single quotes // escape unescaped single quotes
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[0] . ')'; return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[ 0 ] . ')';
case 'javascript': case 'javascript':
// escape quotes and backslashes, newlines, etc. // escape quotes and backslashes, newlines, etc.
return 'strtr(' . $params[0] . ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))'; return 'strtr(' . $params[ 0 ] .
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))';
} }
} }
catch (SmartyException $e) { catch (SmartyException $e) {
@@ -115,11 +102,15 @@ function smarty_modifiercompiler_escape($params, $compiler)
// could not optimize |escape call, so fallback to regular plugin // could not optimize |escape call, so fallback to regular plugin
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) { if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
$compiler->parent_compiler->template->compiled->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php'; $compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] =
$compiler->parent_compiler->template->compiled->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape'; SMARTY_PLUGINS_DIR . 'modifier.escape.php';
$compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'function' ] =
'smarty_modifier_escape';
} else { } else {
$compiler->parent_compiler->template->compiled->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php'; $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'file' ] =
$compiler->parent_compiler->template->compiled->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape'; SMARTY_PLUGINS_DIR . 'modifier.escape.php';
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] =
'smarty_modifier_escape';
} }
return 'smarty_modifier_escape(' . join(', ', $params) . ')'; return 'smarty_modifier_escape(' . join(', ', $params) . ')';

View File

@@ -22,12 +22,12 @@ function smarty_modifiercompiler_from_charset($params)
{ {
if (!Smarty::$_MBSTRING) { if (!Smarty::$_MBSTRING) {
// FIXME: (rodneyrehm) shouldn't this throw an error? // FIXME: (rodneyrehm) shouldn't this throw an error?
return $params[0]; return $params[ 0 ];
} }
if (!isset($params[1])) { if (!isset($params[ 1 ])) {
$params[1] = '"ISO-8859-1"'; $params[ 1 ] = '"ISO-8859-1"';
} }
return 'mb_convert_encoding(' . $params[0] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[1] . ')'; return 'mb_convert_encoding(' . $params[ 0 ] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[ 1 ] . ')';
} }

View File

@@ -22,12 +22,12 @@
function smarty_modifiercompiler_indent($params) function smarty_modifiercompiler_indent($params)
{ {
if (!isset($params[1])) { if (!isset($params[ 1 ])) {
$params[1] = 4; $params[ 1 ] = 4;
} }
if (!isset($params[2])) { if (!isset($params[ 2 ])) {
$params[2] = "' '"; $params[ 2 ] = "' '";
} }
return 'preg_replace(\'!^!m\',str_repeat(' . $params[2] . ',' . $params[1] . '),' . $params[0] . ')'; return 'preg_replace(\'!^!m\',str_repeat(' . $params[ 2 ] . ',' . $params[ 1 ] . '),' . $params[ 0 ] . ')';
} }

View File

@@ -24,8 +24,8 @@
function smarty_modifiercompiler_lower($params) function smarty_modifiercompiler_lower($params)
{ {
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_strtolower(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; return 'mb_strtolower(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
} }
// no MBString fallback // no MBString fallback
return 'strtolower(' . $params[0] . ')'; return 'strtolower(' . $params[ 0 ] . ')';
} }

View File

@@ -21,5 +21,5 @@
*/ */
function smarty_modifiercompiler_string_format($params) function smarty_modifiercompiler_string_format($params)
{ {
return 'sprintf(' . $params[1] . ',' . $params[0] . ')'; return 'sprintf(' . $params[ 1 ] . ',' . $params[ 0 ] . ')';
} }

View File

@@ -25,8 +25,8 @@
function smarty_modifiercompiler_strip($params) function smarty_modifiercompiler_strip($params)
{ {
if (!isset($params[1])) { if (!isset($params[ 1 ])) {
$params[1] = "' '"; $params[ 1 ] = "' '";
} }
return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})"; return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})";

View File

@@ -21,9 +21,9 @@
*/ */
function smarty_modifiercompiler_strip_tags($params) 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]})"; return "preg_replace('!<[^>]*?>!', ' ', {$params[0]})";
} else { } else {
return 'strip_tags(' . $params[0] . ')'; return 'strip_tags(' . $params[ 0 ] . ')';
} }
} }

View File

@@ -22,12 +22,12 @@ function smarty_modifiercompiler_to_charset($params)
{ {
if (!Smarty::$_MBSTRING) { if (!Smarty::$_MBSTRING) {
// FIXME: (rodneyrehm) shouldn't this throw an error? // FIXME: (rodneyrehm) shouldn't this throw an error?
return $params[0]; return $params[ 0 ];
} }
if (!isset($params[1])) { if (!isset($params[ 1 ])) {
$params[1] = '"ISO-8859-1"'; $params[ 1 ] = '"ISO-8859-1"';
} }
return 'mb_convert_encoding(' . $params[0] . ', ' . $params[1] . ', "' . addslashes(Smarty::$_CHARSET) . '")'; return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 1 ] . ', "' . addslashes(Smarty::$_CHARSET) . '")';
} }

View File

@@ -20,31 +20,31 @@
*/ */
function smarty_modifiercompiler_unescape($params) function smarty_modifiercompiler_unescape($params)
{ {
if (!isset($params[1])) { if (!isset($params[ 1 ])) {
$params[1] = 'html'; $params[ 1 ] = 'html';
} }
if (!isset($params[2])) { if (!isset($params[ 2 ])) {
$params[2] = '\'' . addslashes(Smarty::$_CHARSET) . '\''; $params[ 2 ] = '\'' . addslashes(Smarty::$_CHARSET) . '\'';
} else { } else {
$params[2] = "'" . $params[2] . "'"; $params[ 2 ] = "'" . $params[ 2 ] . "'";
} }
switch (trim($params[1], '"\'')) { switch (trim($params[ 1 ], '"\'')) {
case 'entity': case 'entity':
case 'htmlall': case 'htmlall':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')'; return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 2 ] . ', \'HTML-ENTITIES\')';
} }
return 'html_entity_decode(' . $params[0] . ', ENT_NOQUOTES, ' . $params[2] . ')'; return 'html_entity_decode(' . $params[ 0 ] . ', ENT_NOQUOTES, ' . $params[ 2 ] . ')';
case 'html': case 'html':
return 'htmlspecialchars_decode(' . $params[0] . ', ENT_QUOTES)'; return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)';
case 'url': case 'url':
return 'rawurldecode(' . $params[0] . ')'; return 'rawurldecode(' . $params[ 0 ] . ')';
default: default:
return $params[0]; return $params[ 0 ];
} }
} }

View File

@@ -22,8 +22,8 @@
function smarty_modifiercompiler_upper($params) function smarty_modifiercompiler_upper($params)
{ {
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_strtoupper(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; return 'mb_strtoupper(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
} }
// no MBString fallback // no MBString fallback
return 'strtoupper(' . $params[0] . ')'; return 'strtoupper(' . $params[ 0 ] . ')';
} }

View File

@@ -22,26 +22,30 @@
*/ */
function smarty_modifiercompiler_wordwrap($params, $compiler) function smarty_modifiercompiler_wordwrap($params, $compiler)
{ {
if (!isset($params[1])) { if (!isset($params[ 1 ])) {
$params[1] = 80; $params[ 1 ] = 80;
} }
if (!isset($params[2])) { if (!isset($params[ 2 ])) {
$params[2] = '"\n"'; $params[ 2 ] = '"\n"';
} }
if (!isset($params[3])) { if (!isset($params[ 3 ])) {
$params[3] = 'false'; $params[ 3 ] = 'false';
} }
$function = 'wordwrap'; $function = 'wordwrap';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) { 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->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'wordwrap' ][ 'modifier' ][ 'file' ] =
$compiler->template->required_plugins['nocache']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
$compiler->template->required_plugins[ 'nocache' ][ 'wordwrap' ][ 'modifier' ][ 'function' ] =
'smarty_mb_wordwrap';
} else { } 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' ][ 'file' ] =
$compiler->parent_compiler->template->compiled->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; 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 = 'smarty_mb_wordwrap';
} }
return $function . '(' . $params[0] . ',' . $params[1] . ',' . $params[2] . ',' . $params[3] . ')'; return $function . '(' . $params[ 0 ] . ',' . $params[ 1 ] . ',' . $params[ 2 ] . ',' . $params[ 3 ] . ')';
} }

View File

@@ -27,12 +27,13 @@ function smarty_outputfilter_trimwhitespace($source)
$source = preg_replace("/\015\012|\015|\012/", "\n", $source); $source = preg_replace("/\015\012|\015|\012/", "\n", $source);
// capture Internet Explorer Conditional Comments // capture Internet Explorer Conditional Comments
if (preg_match_all('#<!--\[[^\]]+\]>.*?<!\[[^\]]+\]-->#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { if (preg_match_all('#<!--\[[^\]]+\]>.*?<!\[[^\]]+\]-->#is', $source, $matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) { foreach ($matches as $match) {
$store[] = $match[0][0]; $store[] = $match[ 0 ][ 0 ];
$_length = strlen($match[0][0]); $_length = strlen($match[ 0 ][ 0 ]);
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
$source = substr_replace($source, $replace, $match[0][1] - $_offset, $_length); $source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
$_offset += $_length - strlen($replace); $_offset += $_length - strlen($replace);
$_store ++; $_store ++;
@@ -45,29 +46,27 @@ function smarty_outputfilter_trimwhitespace($source)
// capture html elements not to be messed with // capture html elements not to be messed with
$_offset = 0; $_offset = 0;
if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is',
$source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) { foreach ($matches as $match) {
$store[] = $match[0][0]; $store[] = $match[ 0 ][ 0 ];
$_length = strlen($match[0][0]); $_length = strlen($match[ 0 ][ 0 ]);
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
$source = substr_replace($source, $replace, $match[0][1] - $_offset, $_length); $source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
$_offset += $_length - strlen($replace); $_offset += $_length - strlen($replace);
$_store ++; $_store ++;
} }
} }
$expressions = array( $expressions = array(// replace multiple spaces between tags by a single space
// replace multiple spaces between tags by a single space // can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements
// can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements '#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
'#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2', // remove spaces between attributes (but not in attribute values!)
// remove spaces between attributes (but not in attribute values!) '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',
'#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', // note: for some very weird reason trim() seems to remove spaces inside attributes.
// note: for some very weird reason trim() seems to remove spaces inside attributes. // maybe a \0 byte or something is interfering?
// maybe a \0 byte or something is interfering? '#^\s+<#Ss' => '<', '#>\s+$#Ss' => '>',);
'#^\s+<#Ss' => '<',
'#>\s+$#Ss' => '>',
);
$source = preg_replace(array_keys($expressions), array_values($expressions), $source); $source = preg_replace(array_keys($expressions), array_values($expressions), $source);
// note: for some very weird reason trim() seems to remove spaces inside attributes. // note: for some very weird reason trim() seems to remove spaces inside attributes.
@@ -77,9 +76,9 @@ function smarty_outputfilter_trimwhitespace($source)
$_offset = 0; $_offset = 0;
if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) { foreach ($matches as $match) {
$_length = strlen($match[0][0]); $_length = strlen($match[ 0 ][ 0 ]);
$replace = $store[$match[1][0]]; $replace = $store[ $match[ 1 ][ 0 ] ];
$source = substr_replace($source, $replace, $match[0][1] + $_offset, $_length); $source = substr_replace($source, $replace, $match[ 0 ][ 1 ] + $_offset, $_length);
$_offset += strlen($replace) - $_length; $_offset += strlen($replace) - $_length;
$_store ++; $_store ++;

View File

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

View File

@@ -21,12 +21,14 @@ function smarty_make_timestamp($string)
if (empty($string)) { if (empty($string)) {
// use "now": // use "now":
return time(); return time();
} elseif ($string instanceof DateTime || (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)) { } elseif ($string instanceof DateTime ||
(interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)
) {
return (int) $string->format('U'); // PHP 5.2 BC 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? // it is mysql timestamp format of YYYYMMDDHHMMSS?
return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), substr($string, 4, 2),
substr($string, 4, 2), substr($string, 6, 2), substr($string, 0, 4)); substr($string, 6, 2), substr($string, 0, 4));
} elseif (is_numeric($string)) { } elseif (is_numeric($string)) {
// it is a numeric string, we handle it as timestamp // it is a numeric string, we handle it as timestamp
return (int) $string; return (int) $string;

View File

@@ -26,7 +26,7 @@ if (!function_exists('smarty_mb_str_replace')) {
if (is_array($subject)) { if (is_array($subject)) {
// call mb_replace for each single string in $subject // call mb_replace for each single string in $subject
foreach ($subject as &$string) { foreach ($subject as &$string) {
$string = & smarty_mb_str_replace($search, $replace, $string, $c); $string = &smarty_mb_str_replace($search, $replace, $string, $c);
$count += $c; $count += $c;
} }
} elseif (is_array($search)) { } elseif (is_array($search)) {

View File

@@ -24,7 +24,8 @@ if (!function_exists('smarty_mb_wordwrap')) {
function smarty_mb_wordwrap($str, $width = 75, $break = "\n", $cut = false) function smarty_mb_wordwrap($str, $width = 75, $break = "\n", $cut = false)
{ {
// break words into tokens using white space as a delimiter // 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); $tokens =
preg_split('!(\s)!S' . Smarty::$_UTF8_MODIFIER, $str, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
$length = 0; $length = 0;
$t = ''; $t = '';
$_previous = false; $_previous = false;
@@ -34,8 +35,9 @@ if (!function_exists('smarty_mb_wordwrap')) {
$token_length = mb_strlen($_token, Smarty::$_CHARSET); $token_length = mb_strlen($_token, Smarty::$_CHARSET);
$_tokens = array($_token); $_tokens = array($_token);
if ($token_length > $width) { if ($token_length > $width) {
if ($cut) { if ($cut) {
$_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE); $_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1,
PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
} }
} }

View File

@@ -50,7 +50,8 @@ abstract class Smarty_CacheResource
* *
* @return bool true or false if the cached content does not exist * @return bool true or false if the cached content does not exist
*/ */
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false); abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null,
$update = false);
/** /**
* Write the rendered template output to cache * Write the rendered template output to cache
@@ -185,24 +186,24 @@ abstract class Smarty_CacheResource
} }
// try smarty's cache // try smarty's cache
if (isset($smarty->_cache['cacheresource_handlers'][$type])) { if (isset($smarty->_cache[ 'cacheresource_handlers' ][ $type ])) {
return $smarty->_cache['cacheresource_handlers'][$type]; return $smarty->_cache[ 'cacheresource_handlers' ][ $type ];
} }
// try registered resource // try registered resource
if (isset($smarty->registered_cache_resources[$type])) { if (isset($smarty->registered_cache_resources[ $type ])) {
// do not cache these instances as they may vary from instance to instance // do not cache these instances as they may vary from instance to instance
return $smarty->_cache['cacheresource_handlers'][$type] = $smarty->registered_cache_resources[$type]; return $smarty->_cache[ 'cacheresource_handlers' ][ $type ] = $smarty->registered_cache_resources[ $type ];
} }
// try sysplugins dir // try sysplugins dir
if (isset(self::$sysplugins[$type])) { if (isset(self::$sysplugins[ $type ])) {
$cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type); $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class(); return $smarty->_cache[ 'cacheresource_handlers' ][ $type ] = new $cache_resource_class();
} }
// try plugins dir // try plugins dir
$cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type); $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
if ($smarty->loadPlugin($cache_resource_class)) { if ($smarty->loadPlugin($cache_resource_class)) {
return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class(); return $smarty->_cache[ 'cacheresource_handlers' ][ $type ] = new $cache_resource_class();
} }
// give up // give up
throw new SmartyException("Unable to load cache resource '{$type}'"); throw new SmartyException("Unable to load cache resource '{$type}'");

View File

@@ -101,7 +101,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/ */
public function populateTimestamp(Smarty_Template_Cached $cached) public function populateTimestamp(Smarty_Template_Cached $cached)
{ {
$mtime = $this->fetchTimestamp($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id); $mtime =
$this->fetchTimestamp($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id);
if ($mtime !== null) { if ($mtime !== null) {
$cached->timestamp = $mtime; $cached->timestamp = $mtime;
$cached->exists = !!$cached->timestamp; $cached->exists = !!$cached->timestamp;
@@ -109,7 +110,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
return; return;
} }
$timestamp = null; $timestamp = null;
$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $cached->content, $timestamp); $this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $cached->content,
$timestamp);
$cached->timestamp = isset($timestamp) ? $timestamp : false; $cached->timestamp = isset($timestamp) ? $timestamp : false;
$cached->exists = !!$cached->timestamp; $cached->exists = !!$cached->timestamp;
} }
@@ -131,7 +133,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
$content = $cached->content ? $cached->content : null; $content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null; $timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) { if ($content === null || !$timestamp) {
$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp); $this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $content, $timestamp);
} }
if (isset($content)) { if (isset($content)) {
/** @var Smarty_Internal_Template $_smarty_tpl /** @var Smarty_Internal_Template $_smarty_tpl
@@ -156,7 +159,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/ */
public function writeCachedContent(Smarty_Internal_Template $_template, $content) public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{ {
return $this->save($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $_template->cache_lifetime, $content); return $this->save($_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $_template->cache_lifetime, $content);
} }
/** /**
@@ -172,7 +176,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
$timestamp = null; $timestamp = null;
if ($content === null) { if ($content === null) {
$timestamp = null; $timestamp = null;
$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp); $this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $content, $timestamp);
} }
if (isset($content)) { if (isset($content)) {
return $content; return $content;

View File

@@ -55,7 +55,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template) public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
{ {
$cached->filepath = sha1($_template->source->uid) . '#' . $this->sanitize($cached->source->resource) . '#' . $cached->filepath = sha1($_template->source->uid) . '#' . $this->sanitize($cached->source->resource) . '#' .
$this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id); $this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
$this->populateTimestamp($cached); $this->populateTimestamp($cached);
} }
@@ -69,7 +69,9 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*/ */
public function populateTimestamp(Smarty_Template_Cached $cached) public function populateTimestamp(Smarty_Template_Cached $cached)
{ {
if (!$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content, $timestamp, $cached->source->uid)) { if (!$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content,
$timestamp, $cached->source->uid)
) {
return; return;
} }
$cached->content = $content; $cached->content = $content;
@@ -94,7 +96,9 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$content = $cached->content ? $cached->content : null; $content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null; $timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) { if ($content === null || !$timestamp) {
if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, $_template->source->uid)) { if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $content, $timestamp, $_template->source->uid)
) {
return false; return false;
} }
} }
@@ -138,7 +142,9 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$content = $_template->cached->content ? $_template->cached->content : null; $content = $_template->cached->content ? $_template->cached->content : null;
$timestamp = null; $timestamp = null;
if ($content === null) { if ($content === null) {
if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, $_template->source->uid)) { if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id,
$_template->compile_id, $content, $timestamp, $_template->source->uid)
) {
return false; return false;
} }
} }
@@ -186,7 +192,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
{ {
$uid = $this->getTemplateUid($smarty, $resource_name); $uid = $this->getTemplateUid($smarty, $resource_name);
$cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . $cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' .
$this->sanitize($compile_id); $this->sanitize($compile_id);
$this->delete(array($cid)); $this->delete(array($cid));
$this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid); $this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid);
return - 1; return - 1;
@@ -242,14 +248,16 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* *
* @return boolean success * @return boolean success
*/ */
protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null, &$timestamp = null, $resource_uid = null) protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null,
&$timestamp = null, $resource_uid = null)
{ {
$t = $this->read(array($cid)); $t = $this->read(array($cid));
$content = !empty($t[$cid]) ? $t[$cid] : null; $content = !empty($t[ $cid ]) ? $t[ $cid ] : null;
$timestamp = null; $timestamp = null;
if ($content && ($timestamp = $this->getMetaTimestamp($content))) { if ($content && ($timestamp = $this->getMetaTimestamp($content))) {
$invalidated = $this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id, $resource_uid); $invalidated =
$this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id, $resource_uid);
if ($invalidated > $timestamp) { if ($invalidated > $timestamp) {
$timestamp = null; $timestamp = null;
$content = null; $content = null;
@@ -268,7 +276,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
protected function addMetaTimestamp(&$content) protected function addMetaTimestamp(&$content)
{ {
$mt = explode(" ", microtime()); $mt = explode(" ", microtime());
$ts = pack("NN", $mt[1], (int) ($mt[0] * 100000000)); $ts = pack("NN", $mt[ 1 ], (int) ($mt[ 0 ] * 100000000));
$content = $ts . $content; $content = $ts . $content;
} }
@@ -296,7 +304,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* *
* @return void * @return void
*/ */
protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null) protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null,
$resource_uid = null)
{ {
$now = microtime(true); $now = microtime(true);
$key = null; $key = null;
@@ -336,7 +345,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* *
* @return float the microtime the CacheID was invalidated * @return float the microtime the CacheID was invalidated
*/ */
protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null) protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null,
$resource_uid = null)
{ {
// abort if there is no CacheID // abort if there is no CacheID
if (false && !$cid) { if (false && !$cid) {
@@ -370,7 +380,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* @return array list of InvalidationKeys * @return array list of InvalidationKeys
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey * @uses $invalidationKeyPrefix to prepend to each InvalidationKey
*/ */
protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null) protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null,
$resource_uid = null)
{ {
$t = array('IVK#ALL'); $t = array('IVK#ALL');
$_name = $_compile = '#'; $_name = $_compile = '#';
@@ -422,7 +433,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$key = 'LOCK#' . $cached->filepath; $key = 'LOCK#' . $cached->filepath;
$data = $this->read(array($key)); $data = $this->read(array($key));
return $data && time() - $data[$key] < $smarty->locking_timeout; return $data && time() - $data[ $key ] < $smarty->locking_timeout;
} }
/** /**

View File

@@ -59,7 +59,7 @@ class Smarty_Data extends Smarty_Internal_Data
} elseif (is_array($_parent)) { } elseif (is_array($_parent)) {
// set up variable values // set up variable values
foreach ($_parent as $_key => $_val) { foreach ($_parent as $_key => $_val) {
$this->tpl_vars[$_key] = new Smarty_Variable($_val); $this->tpl_vars[ $_key ] = new Smarty_Variable($_val);
} }
} elseif ($_parent != null) { } elseif ($_parent != null) {
throw new SmartyException("Wrong type for template variables"); throw new SmartyException("Wrong type for template variables");

View File

@@ -34,7 +34,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
// if use_sub_dirs, break file into directories // if use_sub_dirs, break file into directories
if ($_template->smarty->use_sub_dirs) { if ($_template->smarty->use_sub_dirs) {
$_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS . $_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS .
$_filepath; $_filepath;
} }
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^'; $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
if (isset($_cache_id)) { if (isset($_cache_id)) {
@@ -58,8 +58,8 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
} }
$cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock'; $cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock';
} }
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . $cached->filepath =
'.php'; $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
$cached->timestamp = $cached->exists = is_file($cached->filepath); $cached->timestamp = $cached->exists = is_file($cached->filepath);
if ($cached->exists) { if ($cached->exists) {
$cached->timestamp = filemtime($cached->filepath); $cached->timestamp = filemtime($cached->filepath);
@@ -86,7 +86,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
* *
* @param Smarty_Internal_Template $_template template object * @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object * @param Smarty_Template_Cached $cached cached object
* @param bool $update flag if called because cache update * @param bool $update flag if called because cache update
* *
* @return boolean true or false if the cached content does not exist * @return boolean true or false if the cached content does not exist
*/ */
@@ -115,7 +115,9 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*/ */
public function writeCachedContent(Smarty_Internal_Template $_template, $content) public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{ {
if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) { if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content,
$_template->smarty) === true
) {
if (function_exists('opcache_invalidate')) { if (function_exists('opcache_invalidate')) {
opcache_invalidate($_template->cached->filepath, true); opcache_invalidate($_template->cached->filepath, true);
} elseif (function_exists('apc_compile_file')) { } elseif (function_exists('apc_compile_file')) {

View File

@@ -19,9 +19,9 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign
/** /**
* Compiles code for the {append} tag * Compiles code for the {append} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
*/ */
@@ -34,11 +34,11 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
// map to compile assign attributes // map to compile assign attributes
if (isset($_attr['index'])) { if (isset($_attr[ 'index' ])) {
$_params['smarty_internal_index'] = '[' . $_attr['index'] . ']'; $_params[ 'smarty_internal_index' ] = '[' . $_attr[ 'index' ] . ']';
unset($_attr['index']); unset($_attr[ 'index' ]);
} else { } else {
$_params['smarty_internal_index'] = '[]'; $_params[ 'smarty_internal_index' ] = '[]';
} }
$_new_attr = array(); $_new_attr = array();
foreach ($_attr as $key => $value) { foreach ($_attr as $key => $value) {

View File

@@ -21,7 +21,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
* *
* @var array * @var array
*/ */
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true, public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
'tpl_root' => true); 'tpl_root' => true);
/** /**

View File

@@ -176,7 +176,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
} }
} }
$_className = 'Block_' . preg_replace('#[^\w\|]+#S', '_', $_name) . '_' . $_className = 'Block_' . preg_replace('#[^\w\|]+#S', '_', $_name) . '_' .
preg_replace('![^\w]+!', '_', uniqid(rand(), true)); preg_replace('![^\w]+!', '_', uniqid(rand(), true));
// get compiled block code // get compiled block code
$_functionCode = $compiler->parser->current_buffer; $_functionCode = $compiler->parser->current_buffer;
// setup buffer for template function code // setup buffer for template function code
@@ -185,7 +185,8 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$sourceInfo = $compiler->template->source->filepath; $sourceInfo = $compiler->template->source->filepath;
} else { } else {
$basename = $compiler->template->source->handler->getBasename($compiler->template->source); $basename = $compiler->template->source->handler->getBasename($compiler->template->source);
$sourceInfo = $compiler->template->source->type .':' . ($basename ? $basename : $compiler->template->source->name); $sourceInfo =
$compiler->template->source->type . ':' . ($basename ? $basename : $compiler->template->source->name);
} }
$output = "<?php\n"; $output = "<?php\n";

View File

@@ -35,9 +35,9 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
/** /**
* Compiles code for the {break} tag * Compiles code for the {break} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \SmartyCompilerException
@@ -48,22 +48,22 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
if (isset($_attr['levels'])) { if (isset($_attr[ 'levels' ])) {
if (!is_numeric($_attr['levels'])) { if (!is_numeric($_attr[ 'levels' ])) {
$compiler->trigger_template_error('level attribute must be a numeric constant', null, true); $compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
} }
$_levels = $_attr['levels']; $_levels = $_attr[ 'levels' ];
} else { } else {
$_levels = 1; $_levels = 1;
} }
$level_count = $_levels; $level_count = $_levels;
$stack_count = count($compiler->_tag_stack) - 1; $stack_count = count($compiler->_tag_stack) - 1;
while ($level_count > 0 && $stack_count >= 0) { while ($level_count > 0 && $stack_count >= 0) {
if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) { if (isset($_is_loopy[ $compiler->_tag_stack[ $stack_count ][ 0 ] ])) {
$level_count --; $level_count --;
} }
$stack_count --; $stack_count --;

View File

@@ -53,13 +53,13 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
// save possible attributes // save possible attributes
if (isset($_attr['assign'])) { if (isset($_attr[ 'assign' ])) {
// output will be stored in a smarty variable instead of being displayed // output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign']; $_assign = $_attr[ 'assign' ];
} }
//$_name = trim($_attr['name'], "'\""); //$_name = trim($_attr['name'], "'\"");
$_name = $_attr['name']; $_name = $_attr[ 'name' ];
unset($_attr['name'], $_attr['assign'], $_attr['nocache']); unset($_attr[ 'name' ], $_attr[ 'assign' ], $_attr[ 'nocache' ]);
// set flag (compiled code of {function} must be included in cache file // set flag (compiled code of {function} must be included in cache file
if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) { if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) {
$_nocache = 'true'; $_nocache = 'true';

View File

@@ -45,14 +45,15 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$buffer = isset($_attr['name']) ? $_attr['name'] : "'default'"; $buffer = isset($_attr[ 'name' ]) ? $_attr[ 'name' ] : "'default'";
$assign = isset($_attr['assign']) ? $_attr['assign'] : 'null'; $assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : 'null';
$append = isset($_attr['append']) ? $_attr['append'] : 'null'; $append = isset($_attr[ 'append' ]) ? $_attr[ 'append' ] : 'null';
$compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache); $compiler->_capture_stack[ 0 ][] = array($buffer, $assign, $append, $compiler->nocache);
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$_output = "<?php \$_smarty_tpl->smarty->_cache['capture_stack'][] = array($buffer, $assign, $append); ob_start(); ?>"; $_output =
"<?php \$_smarty_tpl->smarty->_cache['capture_stack'][] = array($buffer, $assign, $append); ob_start(); ?>";
return $_output; return $_output;
} }
@@ -103,9 +104,10 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[0]); list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[ 0 ]);
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->smarty->_cache['capture_stack']);\n"; $_output =
"<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->smarty->_cache['capture_stack']);\n";
$_output .= "if (!empty(\$_capture_buffer)) {\n"; $_output .= "if (!empty(\$_capture_buffer)) {\n";
$_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n"; $_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n";
$_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n"; $_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n";

View File

@@ -45,8 +45,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
* *
* @var array * @var array
*/ */
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'tpl_root' => true);
'tpl_root' => true);
/** /**
* Compiles code for the {config_load} tag * Compiles code for the {config_load} tag
@@ -62,32 +61,34 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
// save possible attributes // save possible attributes
$conf_file = $_attr['file']; $conf_file = $_attr[ 'file' ];
if (isset($_attr['section'])) { if (isset($_attr[ 'section' ])) {
$section = $_attr['section']; $section = $_attr[ 'section' ];
} else { } else {
$section = 'null'; $section = 'null';
} }
$_scope = Smarty::SCOPE_LOCAL; $_scope = Smarty::SCOPE_LOCAL;
if (isset($_attr['scope'])) { if (isset($_attr[ 'scope' ])) {
$_attr['scope'] = trim($_attr['scope'], "'\""); $_attr[ 'scope' ] = trim($_attr[ 'scope' ], "'\"");
if (!isset($this->valid_scopes[$_attr['scope']])) { if (!isset($this->valid_scopes[ $_attr[ 'scope' ] ])) {
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true); $compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null,
true);
} }
if ($_attr['scope'] != 'local') { if ($_attr[ 'scope' ] != 'local') {
if ($_attr['scope'] == 'parent') { if ($_attr[ 'scope' ] == 'parent') {
$_scope = Smarty::SCOPE_PARENT; $_scope = Smarty::SCOPE_PARENT;
} elseif ($_attr['scope'] == 'root') { } elseif ($_attr[ 'scope' ] == 'root') {
$_scope = Smarty::SCOPE_ROOT; $_scope = Smarty::SCOPE_ROOT;
} elseif ($_attr['scope'] == 'tpl_root') { } elseif ($_attr[ 'scope' ] == 'tpl_root') {
$_scope = Smarty::SCOPE_TPL_ROOT; $_scope = Smarty::SCOPE_TPL_ROOT;
} }
$_scope += (isset($_attr['bubble_up']) && $_attr['bubble_up'] == 'false') ? 0 : Smarty::SCOPE_BUBBLE_UP; $_scope += (isset($_attr[ 'bubble_up' ]) && $_attr[ 'bubble_up' ] == 'false') ? 0 :
Smarty::SCOPE_BUBBLE_UP;
} }
} }

View File

@@ -48,22 +48,22 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
if (isset($_attr['levels'])) { if (isset($_attr[ 'levels' ])) {
if (!is_numeric($_attr['levels'])) { if (!is_numeric($_attr[ 'levels' ])) {
$compiler->trigger_template_error('level attribute must be a numeric constant', null, true); $compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
} }
$_levels = $_attr['levels']; $_levels = $_attr[ 'levels' ];
} else { } else {
$_levels = 1; $_levels = 1;
} }
$level_count = $_levels; $level_count = $_levels;
$stack_count = count($compiler->_tag_stack) - 1; $stack_count = count($compiler->_tag_stack) - 1;
while ($level_count > 0 && $stack_count >= 0) { while ($level_count > 0 && $stack_count >= 0) {
if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) { if (isset($_is_loopy[ $compiler->_tag_stack[ $stack_count ][ 0 ] ])) {
$level_count --; $level_count --;
} }
$stack_count --; $stack_count --;

View File

@@ -34,7 +34,8 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
// display debug template // display debug template
$_output = "<?php \$_smarty_debug = new Smarty_Internal_Debug;\n \$_smarty_debug->display_debug(\$_smarty_tpl);\n"; $_output =
"<?php \$_smarty_debug = new Smarty_Internal_Debug;\n \$_smarty_debug->display_debug(\$_smarty_tpl);\n";
$_output .= "unset(\$_smarty_debug);\n?>"; $_output .= "unset(\$_smarty_debug);\n?>";
return $_output; return $_output;
} }

View File

@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $required_attributes = array('var'); public $required_attributes = array('var');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $optional_attributes = array('assign'); public $optional_attributes = array('assign');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -52,13 +54,14 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
$this->optional_attributes = array('assign'); $this->optional_attributes = array('assign');
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if (isset($_attr['assign'])) { if (isset($_attr[ 'assign' ])) {
// output will be stored in a smarty variable instead of being displayed // output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign']; $_assign = $_attr[ 'assign' ];
} }
// create template object // 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? //was there an assign attribute?
if (isset($_assign)) { if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());"; $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";

View File

@@ -55,37 +55,37 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->parser->lex->line - 1); $compiler->trigger_template_error('nocache option not allowed', $compiler->parser->lex->line - 1);
} }
if (strpos($_attr['file'], '$_tmp') !== false) { if (strpos($_attr[ 'file' ], '$_tmp') !== false) {
$compiler->trigger_template_error('illegal value for file attribute', $compiler->parser->lex->line - 1); $compiler->trigger_template_error('illegal value for file attribute', $compiler->parser->lex->line - 1);
} }
// add code to initialize inheritance // add code to initialize inheritance
$this->registerInit($compiler, true); $this->registerInit($compiler, true);
$file = trim($_attr['file'], '\'"'); $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 // generate code for each template
$files = array_reverse(explode('|', substr($file, 8))); $files = array_reverse(explode('|', substr($file, 8)));
$i = 0; $i = 0;
foreach ($files as $file) { foreach ($files as $file) {
if ($file[0] == '"') { if ($file[ 0 ] == '"') {
$file = trim($file, '".'); $file = trim($file, '".');
} else { } else {
$file = "'{$file}'"; $file = "'{$file}'";
} }
$i ++; $i ++;
if ($i == count($files) && isset($_attr['extends_resource'])) { if ($i == count($files) && isset($_attr[ 'extends_resource' ])) {
$this->compileEndChild($compiler); $this->compileEndChild($compiler);
} }
$this->compileInclude($compiler, $file); $this->compileInclude($compiler, $file);
} }
if (!isset($_attr['extends_resource'])) { if (!isset($_attr[ 'extends_resource' ])) {
$this->compileEndChild($compiler); $this->compileEndChild($compiler);
} }
} else { } else {
$this->compileEndChild($compiler); $this->compileEndChild($compiler);
$this->compileInclude($compiler, $_attr['file']); $this->compileInclude($compiler, $_attr[ 'file' ]);
} }
$compiler->has_code = false; $compiler->has_code = false;
return ''; return '';

View File

@@ -34,7 +34,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, $compiler, $parameter)
{ {
$compiler->loopNesting++; $compiler->loopNesting ++;
if ($parameter == 0) { if ($parameter == 0) {
$this->required_attributes = array('start', 'to'); $this->required_attributes = array('start', 'to');
$this->optional_attributes = array('max', 'step'); $this->optional_attributes = array('max', 'step');
@@ -47,41 +47,41 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
$output = "<?php\n"; $output = "<?php\n";
if ($parameter == 1) { if ($parameter == 1) {
foreach ($_attr['start'] as $_statement) { foreach ($_attr[ 'start' ] as $_statement) {
if (is_array($_statement['var'])) { if (is_array($_statement[ 'var' ])) {
$var = $_statement['var']['var']; $var = $_statement[ 'var' ][ 'var' ];
$index = $_statement['var']['smarty_internal_index']; $index = $_statement[ 'var' ][ 'smarty_internal_index' ];
} else { } else {
$var = $_statement['var']; $var = $_statement[ 'var' ];
$index = ''; $index = '';
} }
$output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable;\n"; $output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable;\n";
$output .= "\$_smarty_tpl->tpl_vars[$var]->value{$index} = {$_statement['value']};\n"; $output .= "\$_smarty_tpl->tpl_vars[$var]->value{$index} = {$_statement['value']};\n";
} }
if (is_array($_attr['var'])) { if (is_array($_attr[ 'var' ])) {
$var = $_attr['var']['var']; $var = $_attr[ 'var' ][ 'var' ];
$index = $_attr['var']['smarty_internal_index']; $index = $_attr[ 'var' ][ 'smarty_internal_index' ];
} else { } else {
$var = $_attr['var']; $var = $_attr[ 'var' ];
$index = ''; $index = '';
} }
$output .= "if ($_attr[ifexp]) {\nfor (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$var]->value{$index}$_attr[step]) {\n"; $output .= "if ($_attr[ifexp]) {\nfor (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$var]->value{$index}$_attr[step]) {\n";
} else { } else {
$_statement = $_attr['start']; $_statement = $_attr[ 'start' ];
if (is_array($_statement['var'])) { if (is_array($_statement[ 'var' ])) {
$var = $_statement['var']['var']; $var = $_statement[ 'var' ][ 'var' ];
$index = $_statement['var']['smarty_internal_index']; $index = $_statement[ 'var' ][ 'smarty_internal_index' ];
} else { } else {
$var = $_statement['var']; $var = $_statement[ 'var' ];
$index = ''; $index = '';
} }
$output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable;"; $output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable;";
if (isset($_attr['step'])) { if (isset($_attr[ 'step' ])) {
$output .= "\$_smarty_tpl->tpl_vars[$var]->step = $_attr[step];"; $output .= "\$_smarty_tpl->tpl_vars[$var]->step = $_attr[step];";
} else { } else {
$output .= "\$_smarty_tpl->tpl_vars[$var]->step = 1;"; $output .= "\$_smarty_tpl->tpl_vars[$var]->step = 1;";
} }
if (isset($_attr['max'])) { if (isset($_attr[ 'max' ])) {
$output .= "\$_smarty_tpl->tpl_vars[$var]->total = (int) min(ceil((\$_smarty_tpl->tpl_vars[$var]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$var]->step)),$_attr[max]);\n"; $output .= "\$_smarty_tpl->tpl_vars[$var]->total = (int) min(ceil((\$_smarty_tpl->tpl_vars[$var]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$var]->step)),$_attr[max]);\n";
} else { } else {
$output .= "\$_smarty_tpl->tpl_vars[$var]->total = (int) ceil((\$_smarty_tpl->tpl_vars[$var]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$var]->step));\n"; $output .= "\$_smarty_tpl->tpl_vars[$var]->total = (int) ceil((\$_smarty_tpl->tpl_vars[$var]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$var]->step));\n";
@@ -149,7 +149,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, $compiler, $parameter)
{ {
$compiler->loopNesting--; $compiler->loopNesting --;
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
// must endblock be nocache? // must endblock be nocache?
@@ -162,7 +162,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
$output = "<?php }\n"; $output = "<?php }\n";
if ($openTag != 'forelse') { if ($openTag != 'forelse') {
$output .= "}\n"; $output .= "}\n";
} }
$output .= "?>\n"; $output .= "?>\n";
return $output; return $output;
} }

View File

@@ -164,11 +164,11 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$needTotal = isset($itemAttr[ 'show' ]) || isset($itemAttr[ 'total' ]) || isset($namedAttr[ 'total' ]) || $needTotal = isset($itemAttr[ 'show' ]) || isset($itemAttr[ 'total' ]) || isset($namedAttr[ 'total' ]) ||
isset($namedAttr[ 'show' ]) || isset($itemAttr[ 'last' ]) || isset($namedAttr[ 'last' ]); isset($namedAttr[ 'show' ]) || isset($itemAttr[ 'last' ]) || isset($namedAttr[ 'last' ]);
// generate output code // generate output code
$output = "<?php\n"; $output = "<?php\n";
$output .= "\$_from = \$_smarty_tpl->smarty->ext->_foreach->init(\$_smarty_tpl, $from, " . $output .= "\$_from = \$_smarty_tpl->smarty->ext->_foreach->init(\$_smarty_tpl, $from, " .
var_export($item, true); var_export($item, true);
if ($name || $needTotal || $key) { if ($name || $needTotal || $key) {
$output .= ', ' . var_export($needTotal, true); $output .= ', ' . var_export($needTotal, true);
} }

View File

@@ -53,16 +53,17 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
$compiler->loopNesting++; $compiler->loopNesting ++;
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
unset($_attr['nocache']); unset($_attr[ 'nocache' ]);
$_name = trim($_attr['name'], "'\""); $_name = trim($_attr[ 'name' ], "'\"");
$compiler->parent_compiler->tpl_function[$_name] = $compiler->parent_compiler->template->tpl_function[$_name] = array(); $compiler->parent_compiler->tpl_function[ $_name ] =
$compiler->parent_compiler->template->tpl_function[ $_name ] = array();
$save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code, $save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
$compiler->template->caching); $compiler->template->caching);
$this->openTag($compiler, 'function', $save); $this->openTag($compiler, 'function', $save);
@@ -100,17 +101,22 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
$compiler->loopNesting--; $compiler->loopNesting --;
$this->compiler = $compiler; $this->compiler = $compiler;
$saved_data = $this->closeTag($compiler, array('function')); $saved_data = $this->closeTag($compiler, array('function'));
$_attr = $saved_data[0]; $_attr = $saved_data[ 0 ];
$_name = trim($_attr['name'], "'\""); $_name = trim($_attr[ 'name' ], "'\"");
$compiler->parent_compiler->tpl_function[$_name]['called_functions'] = $compiler->parent_compiler->template->tpl_function[$_name]['called_functions'] = $compiler->called_functions; $compiler->parent_compiler->tpl_function[ $_name ][ 'called_functions' ] =
$compiler->parent_compiler->tpl_function[$_name]['compiled_filepath'] = $compiler->parent_compiler->template->tpl_function[$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath; $compiler->parent_compiler->template->tpl_function[ $_name ][ 'called_functions' ] =
$compiler->parent_compiler->tpl_function[$_name]['uid'] = $compiler->parent_compiler->template->tpl_function[$_name]['uid'] = $compiler->template->source->uid; $compiler->called_functions;
$compiler->parent_compiler->tpl_function[ $_name ][ 'compiled_filepath' ] =
$compiler->parent_compiler->template->tpl_function[ $_name ][ 'compiled_filepath' ] =
$compiler->parent_compiler->template->compiled->filepath;
$compiler->parent_compiler->tpl_function[ $_name ][ 'uid' ] =
$compiler->parent_compiler->template->tpl_function[ $_name ][ 'uid' ] = $compiler->template->source->uid;
$compiler->called_functions = array(); $compiler->called_functions = array();
$_parameter = $_attr; $_parameter = $_attr;
unset($_parameter['name']); unset($_parameter[ 'name' ]);
// default parameter // default parameter
$_paramsArray = array(); $_paramsArray = array();
foreach ($_parameter as $_key => $_value) { foreach ($_parameter as $_key => $_value) {
@@ -133,7 +139,8 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}"; $_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}";
$_funcNameCaching = $_funcName . '_nocache'; $_funcNameCaching = $_funcName . '_nocache';
if ($compiler->template->compiled->has_nocache_code) { if ($compiler->template->compiled->has_nocache_code) {
$compiler->parent_compiler->tpl_function[$_name]['call_name_caching'] = $compiler->parent_compiler->template->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching; $compiler->parent_compiler->tpl_function[ $_name ][ 'call_name_caching' ] =
$compiler->parent_compiler->template->tpl_function[ $_name ][ 'call_name_caching' ] = $_funcNameCaching;
$output = "<?php\n"; $output = "<?php\n";
$output .= "/* {$_funcNameCaching} */\n"; $output .= "/* {$_funcNameCaching} */\n";
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n"; $output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
@@ -147,7 +154,9 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php "; $output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value);\n}\n?>"; $output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value);\n}\n?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n\";?>"; $output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n\";?>";
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); $compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php "; $output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value){\n"; $output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value){\n";
@@ -158,11 +167,16 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "\$_smarty_tpl->tpl_vars = array_pop(\$_smarty_tpl->_cache['saved_tpl_vars']);\n}\n}\n"; $output .= "\$_smarty_tpl->tpl_vars = array_pop(\$_smarty_tpl->_cache['saved_tpl_vars']);\n}\n}\n";
$output .= "/*/ {$_funcName}_nocache */\n\n"; $output .= "/*/ {$_funcName}_nocache */\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); $compiler->parser->current_buffer->append_subtree($compiler->parser,
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", array($this, new Smarty_Internal_ParseTree_Tag($compiler->parser,
'removeNocache'), $_functionCode->to_smarty_php($compiler->parser))); $output));
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser,
preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
array($this, 'removeNocache'),
$_functionCode->to_smarty_php($compiler->parser)));
} }
$compiler->parent_compiler->tpl_function[$_name]['call_name'] = $compiler->parent_compiler->template->tpl_function[$_name]['call_name'] = $_funcName; $compiler->parent_compiler->tpl_function[ $_name ][ 'call_name' ] =
$compiler->parent_compiler->template->tpl_function[ $_name ][ 'call_name' ] = $_funcName;
$output = "<?php\n"; $output = "<?php\n";
$output .= "/* {$_funcName} */\n"; $output .= "/* {$_funcName} */\n";
$output .= "if (!function_exists('{$_funcName}')) {\n"; $output .= "if (!function_exists('{$_funcName}')) {\n";
@@ -170,29 +184,34 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n"; $output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n";
$output .= $_paramsCode; $output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}?>"; $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}?>";
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); $compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php foreach (Smarty::\$global_tpl_vars as \$key => \$value){\n"; $output = "<?php foreach (Smarty::\$global_tpl_vars as \$key => \$value){\n";
$output .= "if (!isset(\$_smarty_tpl->tpl_vars[\$key]) || \$_smarty_tpl->tpl_vars[\$key] === \$value) \$saved_tpl_vars[\$key] = \$value;\n}\n"; $output .= "if (!isset(\$_smarty_tpl->tpl_vars[\$key]) || \$_smarty_tpl->tpl_vars[\$key] === \$value) \$saved_tpl_vars[\$key] = \$value;\n}\n";
$output .= "\$_smarty_tpl->tpl_vars = \$saved_tpl_vars;\n}\n}\n"; $output .= "\$_smarty_tpl->tpl_vars = \$saved_tpl_vars;\n}\n}\n";
$output .= "/*/ {$_funcName} */\n\n"; $output .= "/*/ {$_funcName} */\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); $compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); $compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
// nocache plugins must be copied // nocache plugins must be copied
if (!empty($compiler->template->compiled->required_plugins['nocache'])) { if (!empty($compiler->template->compiled->required_plugins[ 'nocache' ])) {
foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) { foreach ($compiler->template->compiled->required_plugins[ 'nocache' ] as $plugin => $tmp) {
foreach ($tmp as $type => $data) { foreach ($tmp as $type => $data) {
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][$plugin][$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]; $compiler->parser->current_buffer = $saved_data[ 1 ];
// restore old status // restore old status
$compiler->template->compiled->has_nocache_code = $saved_data[2]; $compiler->template->compiled->has_nocache_code = $saved_data[ 2 ];
$compiler->template->caching = $saved_data[3]; $compiler->template->caching = $saved_data[ 3 ];
return true; return true;
} }
@@ -203,7 +222,9 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
*/ */
function removeNocache($match) function removeNocache($match)
{ {
$code = preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", '', $match[0]); $code =
preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
'', $match[ 0 ]);
$code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code); $code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code);
return $code; return $code;
} }

View File

@@ -38,37 +38,38 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$compiler->trigger_template_error("missing if condition", null, true); $compiler->trigger_template_error("missing if condition", null, true);
} }
if (is_array($parameter['if condition'])) { if (is_array($parameter[ 'if condition' ])) {
if ($compiler->nocache) { if ($compiler->nocache) {
$_nocache = ',true'; $_nocache = ',true';
// create nocache var to make it know for further compiling // create nocache var to make it know for further compiling
if (is_array($parameter['if condition']['var'])) { if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$var = trim($parameter['if condition']['var']['var'], "'"); $var = trim($parameter[ 'if condition' ][ 'var' ][ 'var' ], "'");
} else { } else {
$var = trim($parameter['if condition']['var'], "'"); $var = trim($parameter[ 'if condition' ][ 'var' ], "'");
} }
if (isset($compiler->template->tpl_vars[$var])) { if (isset($compiler->template->tpl_vars[ $var ])) {
$compiler->template->tpl_vars[$var]->nocache = true; $compiler->template->tpl_vars[ $var ]->nocache = true;
} else { } else {
$compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true); $compiler->template->tpl_vars[ $var ] = new Smarty_Variable(null, true);
} }
} else { } else {
$_nocache = ''; $_nocache = '';
} }
if (is_array($parameter['if condition']['var'])) { if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . $_output =
"]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
"]->value)) \$_smarty_tpl->_createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
"$_nocache);\n"; "]->value)) \$_smarty_tpl->_createLocalArrayVariable(" .
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter[ 'if condition' ][ 'var' ][ 'var' ] . "$_nocache);\n";
$parameter['if condition']['var']['smarty_internal_index'] . " = " . $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
$parameter['if condition']['value'] . ") {?>"; "]->value" . $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] . " = " .
$parameter[ 'if condition' ][ 'value' ] . ") {?>";
} else { } else {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ] .
"])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ] .
"] = new Smarty_Variable(null{$_nocache});"; "] = new Smarty_Variable(null{$_nocache});";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ] . "]->value = " .
$parameter['if condition']['value'] . ") {?>"; $parameter[ 'if condition' ][ 'value' ] . ") {?>";
} }
return $_output; return $_output;
@@ -133,20 +134,20 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
$compiler->trigger_template_error("missing elseif condition", null, true); $compiler->trigger_template_error("missing elseif condition", null, true);
} }
if (is_array($parameter['if condition'])) { if (is_array($parameter[ 'if condition' ])) {
$condition_by_assign = true; $condition_by_assign = true;
if ($compiler->nocache) { if ($compiler->nocache) {
$_nocache = ',true'; $_nocache = ',true';
// create nocache var to make it know for further compiling // create nocache var to make it know for further compiling
if (is_array($parameter['if condition']['var'])) { if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$var = trim($parameter['if condition']['var']['var'], "'"); $var = trim($parameter[ 'if condition' ][ 'var' ][ 'var' ], "'");
} else { } else {
$var = trim($parameter['if condition']['var'], "'"); $var = trim($parameter[ 'if condition' ][ 'var' ], "'");
} }
if (isset($compiler->template->tpl_vars[$var])) { if (isset($compiler->template->tpl_vars[ $var ])) {
$compiler->template->tpl_vars[$var]->nocache = true; $compiler->template->tpl_vars[ $var ]->nocache = true;
} else { } else {
$compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true); $compiler->template->tpl_vars[ $var ] = new Smarty_Variable(null, true);
} }
} else { } else {
$_nocache = ''; $_nocache = '';
@@ -158,21 +159,23 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
if (empty($compiler->prefix_code)) { if (empty($compiler->prefix_code)) {
if ($condition_by_assign) { if ($condition_by_assign) {
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache)); $this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
if (is_array($parameter['if condition']['var'])) { if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" . $_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
$parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" .
"]->value)) \$_smarty_tpl->_createLocalArrayVariable(" . $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
$parameter['if condition']['var']['var'] . "$_nocache);\n"; "]->value)) \$_smarty_tpl->_createLocalArrayVariable(" .
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter[ 'if condition' ][ 'var' ][ 'var' ] . "$_nocache);\n";
$parameter['if condition']['var']['smarty_internal_index'] . " = " . $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
$parameter['if condition']['value'] . ") {?>"; "]->value" . $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] . " = " .
$parameter[ 'if condition' ][ 'value' ] . ") {?>";
} else { } else {
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" . $_output =
$parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ] .
$parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});"; "])) \$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ] .
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . "] = new Smarty_Variable(null{$_nocache});";
$parameter['if condition']['value'] . ") {?>"; $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ] . "]->value = " .
$parameter[ 'if condition' ][ 'value' ] . ") {?>";
} }
return $_output; return $_output;
@@ -190,24 +193,25 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
$tmp = $compiler->appendCode("<?php } else {?>", $tmp); $tmp = $compiler->appendCode("<?php } else {?>", $tmp);
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache)); $this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
if ($condition_by_assign) { if ($condition_by_assign) {
if (is_array($parameter['if condition']['var'])) { if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var']['var'] . $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
"]) || !is_array(\$_smarty_tpl->tpl_vars[" . "]) || !is_array(\$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var']['var'] . $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
"]->value)) \$_smarty_tpl->_createLocalArrayVariable(" . "]->value)) \$_smarty_tpl->_createLocalArrayVariable(" .
$parameter['if condition']['var']['var'] . "$_nocache);\n"); $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . "$_nocache);\n");
$parameter['if condition']['var']['smarty_internal_index'] . " = " . $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
$parameter['if condition']['value'] . ") {?>"; "]->value" . $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] . " = " .
$parameter[ 'if condition' ][ 'value' ] . ") {?>";
} else { } else {
$_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var'] . $parameter[ 'if condition' ][ 'var' ] .
"])) \$_smarty_tpl->tpl_vars[" . "])) \$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var'] . $parameter[ 'if condition' ][ 'var' ] .
"] = new Smarty_Variable(null{$_nocache});"); "] = new Smarty_Variable(null{$_nocache});");
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ] . "]->value = " .
$parameter['if condition']['value'] . ") {?>"; $parameter[ 'if condition' ][ 'value' ] . ") {?>";
} }
return $_output; return $_output;

View File

@@ -58,8 +58,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* *
* @var array * @var array
*/ */
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'tpl_root' => true);
'tpl_root' => true);
/** /**
* Compiles code for the {include} tag * Compiles code for the {include} tag
@@ -76,13 +75,13 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$hashResourceName = $fullResourceName = $source_resource = $_attr['file']; $hashResourceName = $fullResourceName = $source_resource = $_attr[ 'file' ];
$variable_template = false; $variable_template = false;
$cache_tpl = false; $cache_tpl = false;
// parse resource_name // parse resource_name
if (preg_match('/^([\'"])(([A-Za-z0-9_\-]{2,})[:])?(([^$()]+)|(.+))\1$/', $source_resource, $match)) { if (preg_match('/^([\'"])(([A-Za-z0-9_\-]{2,})[:])?(([^$()]+)|(.+))\1$/', $source_resource, $match)) {
$type = !empty($match[3]) ? $match[3] : $compiler->template->smarty->default_resource_type; $type = !empty($match[ 3 ]) ? $match[ 3 ] : $compiler->template->smarty->default_resource_type;
$name = !empty($match[5]) ? $match[5] : $match[6]; $name = !empty($match[ 5 ]) ? $match[ 5 ] : $match[ 6 ];
$handler = Smarty_Resource::load($compiler->smarty, $type); $handler = Smarty_Resource::load($compiler->smarty, $type);
if ($handler->recompiled || $handler->uncompiled) { if ($handler->recompiled || $handler->uncompiled) {
$variable_template = true; $variable_template = true;
@@ -91,40 +90,41 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if ($type != 'string') { if ($type != 'string') {
$fullResourceName = "{$type}:{$name}"; $fullResourceName = "{$type}:{$name}";
$compiled = $compiler->parent_compiler->template->compiled; $compiled = $compiler->parent_compiler->template->compiled;
if (isset($compiled->includes[$fullResourceName])) { if (isset($compiled->includes[ $fullResourceName ])) {
$compiled->includes[$fullResourceName] ++; $compiled->includes[ $fullResourceName ] ++;
$cache_tpl = true; $cache_tpl = true;
} else { } else {
$compiled->includes[$fullResourceName] = 1; $compiled->includes[ $fullResourceName ] = 1;
} }
$fullResourceName = '"' . $fullResourceName . '"'; $fullResourceName = '"' . $fullResourceName . '"';
} }
} }
if (empty($match[5])) { if (empty($match[ 5 ])) {
$variable_template = true; $variable_template = true;
} }
} else { } else {
$variable_template = true; $variable_template = true;
} }
if (isset($_attr['assign'])) { if (isset($_attr[ 'assign' ])) {
// output will be stored in a smarty variable instead of being displayed // output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign']; $_assign = $_attr[ 'assign' ];
} }
// scope setup // scope setup
$_scope = Smarty::SCOPE_LOCAL; $_scope = Smarty::SCOPE_LOCAL;
if (isset($_attr['scope'])) { if (isset($_attr[ 'scope' ])) {
$_attr['scope'] = trim($_attr['scope'], "'\""); $_attr[ 'scope' ] = trim($_attr[ 'scope' ], "'\"");
if (!isset($this->valid_scopes[$_attr['scope']])) { if (!isset($this->valid_scopes[ $_attr[ 'scope' ] ])) {
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true); $compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null,
true);
} }
if ($_attr['scope'] != 'local') { if ($_attr[ 'scope' ] != 'local') {
if ($_attr['scope'] == 'parent') { if ($_attr[ 'scope' ] == 'parent') {
$_scope = Smarty::SCOPE_PARENT; $_scope = Smarty::SCOPE_PARENT;
} elseif ($_attr['scope'] == 'root') { } elseif ($_attr[ 'scope' ] == 'root') {
$_scope = Smarty::SCOPE_ROOT; $_scope = Smarty::SCOPE_ROOT;
} elseif ($_attr['scope'] == 'tpl_root') { } elseif ($_attr[ 'scope' ] == 'tpl_root') {
$_scope = Smarty::SCOPE_TPL_ROOT; $_scope = Smarty::SCOPE_TPL_ROOT;
} }
$_scope += (isset($_attr[ 'bubble_up' ]) && $_attr[ 'bubble_up' ] == 'false') ? 0 : $_scope += (isset($_attr[ 'bubble_up' ]) && $_attr[ 'bubble_up' ] == 'false') ? 0 :
@@ -141,7 +141,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
// assume caching is off // assume caching is off
$_caching = Smarty::CACHING_OFF; $_caching = Smarty::CACHING_OFF;
if ($_attr['nocache'] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
@@ -153,10 +153,10 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} }
// flag if included template code should be merged into caller // flag if included template code should be merged into caller
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) && $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr[ 'inline' ] === true) &&
!$compiler->template->source->handler->recompiled; !$compiler->template->source->handler->recompiled;
if ($merge_compiled_includes && $_attr['inline'] !== true) { if ($merge_compiled_includes && $_attr[ 'inline' ] !== true) {
// variable template name ? // variable template name ?
if ($variable_template) { if ($variable_template) {
$merge_compiled_includes = false; $merge_compiled_includes = false;
@@ -166,10 +166,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} }
} }
// variable compile_id? // variable compile_id?
if (isset($_attr['compile_id'])) { if (isset($_attr[ 'compile_id' ])) {
if (!((substr_count($_attr['compile_id'], '"') == 2 || substr_count($_attr['compile_id'], "'") == 2 || if (!((substr_count($_attr[ 'compile_id' ], '"') == 2 ||
is_numeric($_attr['compile_id']))) || substr_count($_attr['compile_id'], '(') != 0 || substr_count($_attr[ 'compile_id' ], "'") == 2 || is_numeric($_attr[ 'compile_id' ]))) ||
substr_count($_attr['compile_id'], '$_smarty_tpl->') != 0 substr_count($_attr[ 'compile_id' ], '(') != 0 ||
substr_count($_attr[ 'compile_id' ], '$_smarty_tpl->') != 0
) { ) {
$merge_compiled_includes = false; $merge_compiled_includes = false;
if ($compiler->template->caching) { if ($compiler->template->caching) {
@@ -186,28 +187,28 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* a call in nocache mode. * a call in nocache mode.
* *
*/ */
if ($_attr['nocache'] !== true && $_attr['caching']) { if ($_attr[ 'nocache' ] !== true && $_attr[ 'caching' ]) {
$_caching = $_new_caching = (int) $_attr['caching']; $_caching = $_new_caching = (int) $_attr[ 'caching' ];
$call_nocache = true; $call_nocache = true;
} else { } else {
$_new_caching = Smarty::CACHING_LIFETIME_CURRENT; $_new_caching = Smarty::CACHING_LIFETIME_CURRENT;
} }
if (isset($_attr['cache_lifetime'])) { if (isset($_attr[ 'cache_lifetime' ])) {
$_cache_lifetime = $_attr['cache_lifetime']; $_cache_lifetime = $_attr[ 'cache_lifetime' ];
$call_nocache = true; $call_nocache = true;
$_caching = $_new_caching; $_caching = $_new_caching;
} else { } else {
$_cache_lifetime = '$_smarty_tpl->cache_lifetime'; $_cache_lifetime = '$_smarty_tpl->cache_lifetime';
} }
if (isset($_attr['cache_id'])) { if (isset($_attr[ 'cache_id' ])) {
$_cache_id = $_attr['cache_id']; $_cache_id = $_attr[ 'cache_id' ];
$call_nocache = true; $call_nocache = true;
$_caching = $_new_caching; $_caching = $_new_caching;
} else { } else {
$_cache_id = '$_smarty_tpl->cache_id'; $_cache_id = '$_smarty_tpl->cache_id';
} }
if (isset($_attr['compile_id'])) { if (isset($_attr[ 'compile_id' ])) {
$_compile_id = $_attr['compile_id']; $_compile_id = $_attr[ 'compile_id' ];
} else { } else {
$_compile_id = '$_smarty_tpl->compile_id'; $_compile_id = '$_smarty_tpl->compile_id';
} }
@@ -219,10 +220,10 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$has_compiled_template = false; $has_compiled_template = false;
if ($merge_compiled_includes) { if ($merge_compiled_includes) {
$c_id = isset($_attr['compile_id']) ? $_attr['compile_id'] : $compiler->template->compile_id; $c_id = isset($_attr[ 'compile_id' ]) ? $_attr[ 'compile_id' ] : $compiler->template->compile_id;
// we must observe different compile_id and caching // we must observe different compile_id and caching
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching')); $t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash])) { if (!isset($compiler->parent_compiler->mergedSubTemplatesData[ $hashResourceName ][ $t_hash ])) {
$has_compiled_template = $has_compiled_template =
$this->compileInlineTemplate($compiler, $fullResourceName, $_caching, $hashResourceName, $t_hash, $this->compileInlineTemplate($compiler, $fullResourceName, $_caching, $hashResourceName, $t_hash,
$c_id); $c_id);
@@ -231,7 +232,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} }
} }
// delete {include} standard attributes // delete {include} standard attributes
unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline'], $_attr['bubble_up']); unset($_attr[ 'file' ], $_attr[ 'assign' ], $_attr[ 'cache_id' ], $_attr[ 'compile_id' ], $_attr[ 'cache_lifetime' ], $_attr[ 'nocache' ], $_attr[ 'caching' ], $_attr[ 'scope' ], $_attr[ 'inline' ], $_attr[ 'bubble_up' ]);
// remaining attributes must be assigned as smarty variable // remaining attributes must be assigned as smarty variable
$_vars_nc = ''; $_vars_nc = '';
if (!empty($_attr)) { if (!empty($_attr)) {
@@ -250,7 +251,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$_vars = 'array()'; $_vars = 'array()';
} }
$update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache && $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) { if ($has_compiled_template && !$call_nocache) {
$_output = "<?php\n"; $_output = "<?php\n";
if ($update_compile_id) { if ($update_compile_id) {
@@ -315,11 +316,12 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
{ {
$compiler->smarty->allow_ambiguous_resources = true; $compiler->smarty->allow_ambiguous_resources = true;
/* @var Smarty_Internal_Template $tpl */ /* @var Smarty_Internal_Template $tpl */
$tpl = $tpl = new $compiler->smarty->template_class (trim($fullResourceName, '"\''), $compiler->smarty,
new $compiler->smarty->template_class (trim($fullResourceName, '"\''), $compiler->smarty, $compiler->template, $compiler->template, $compiler->template->cache_id, $c_id,
$compiler->template->cache_id, $c_id, $_caching); $_caching);
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) { if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid'] = $tpl->source->uid; $compiler->parent_compiler->mergedSubTemplatesData[ $hashResourceName ][ $t_hash ][ 'uid' ] =
$tpl->source->uid;
if (isset($compiler->template->ext->_inheritance)) { if (isset($compiler->template->ext->_inheritance)) {
$tpl->ext->_inheritance = clone $compiler->template->ext->_inheritance; $tpl->ext->_inheritance = clone $compiler->template->ext->_inheritance;
} }
@@ -327,17 +329,18 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash; $tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
$tpl->loadCompiler(); $tpl->loadCompiler();
// save unique function name // save unique function name
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func'] = $compiler->parent_compiler->mergedSubTemplatesData[ $hashResourceName ][ $t_hash ][ 'func' ] =
$tpl->compiled->unifunc = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); $tpl->compiled->unifunc = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
// make sure whole chain gets compiled // make sure whole chain gets compiled
$tpl->mustCompile = true; $tpl->mustCompile = true;
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['nocache_hash'] = $compiler->parent_compiler->mergedSubTemplatesData[ $hashResourceName ][ $t_hash ][ 'nocache_hash' ] =
$tpl->compiled->nocache_hash; $tpl->compiled->nocache_hash;
if ($compiler->template->source->type == 'file') { if ($compiler->template->source->type == 'file') {
$sourceInfo = $compiler->template->source->filepath; $sourceInfo = $compiler->template->source->filepath;
} else { } else {
$basename = $compiler->template->source->handler->getBasename($compiler->template->source); $basename = $compiler->template->source->handler->getBasename($compiler->template->source);
$sourceInfo = $compiler->template->source->type .':' . ($basename ? $basename : $compiler->template->source->name); $sourceInfo = $compiler->template->source->type . ':' .
($basename ? $basename : $compiler->template->source->name);
} }
// get compiled code // get compiled code
$compiled_code = "<?php\n\n"; $compiled_code = "<?php\n\n";
@@ -358,7 +361,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$compiled_code); $compiled_code);
$compiler->template->compiled->has_nocache_code = true; $compiler->template->compiled->has_nocache_code = true;
} }
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code; $compiler->parent_compiler->mergedSubTemplatesCode[ $tpl->compiled->unifunc ] = $compiled_code;
return true; return true;
} else { } else {
return false; return false;

View File

@@ -64,7 +64,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
$_smarty_tpl = $compiler->template; $_smarty_tpl = $compiler->template;
$_filepath = false; $_filepath = false;
$_file = null; $_file = null;
eval('$_file = @' . $_attr['file'] . ';'); eval('$_file = @' . $_attr[ 'file' ] . ';');
if (!isset($compiler->smarty->security_policy) && file_exists($_file)) { if (!isset($compiler->smarty->security_policy) && file_exists($_file)) {
$_filepath = $compiler->smarty->_realpath($_file, true); $_filepath = $compiler->smarty->_realpath($_file, true);
} else { } else {
@@ -91,13 +91,13 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
$compiler->smarty->security_policy->isTrustedPHPDir($_filepath); $compiler->smarty->security_policy->isTrustedPHPDir($_filepath);
} }
if (isset($_attr['assign'])) { if (isset($_attr[ 'assign' ])) {
// output will be stored in a smarty variable instead of being displayed // output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign']; $_assign = $_attr[ 'assign' ];
} }
$_once = '_once'; $_once = '_once';
if (isset($_attr['once'])) { if (isset($_attr[ 'once' ])) {
if ($_attr['once'] == 'false') { if ($_attr[ 'once' ] == 'false') {
$_once = ''; $_once = '';
} }
} }

View File

@@ -66,24 +66,24 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_output = '<?php '; $_output = '<?php ';
// save possible attributes // save possible attributes
eval('$_name = @' . $_attr['name'] . ';'); eval('$_name = @' . $_attr[ 'name' ] . ';');
if (isset($_attr['assign'])) { if (isset($_attr[ 'assign' ])) {
// output will be stored in a smarty variable instead of being displayed // output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign']; $_assign = $_attr[ 'assign' ];
// create variable to make sure that the compiler knows about its nocache status // 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])) { if (isset($compiler->template->tpl_vars[ $var ])) {
$compiler->template->tpl_vars[$var]->nocache = true; $compiler->template->tpl_vars[ $var ]->nocache = true;
} else { } else {
$compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true); $compiler->template->tpl_vars[ $var ] = new Smarty_Variable(null, true);
} }
} }
if (isset($_attr['script'])) { if (isset($_attr[ 'script' ])) {
// script which must be included // script which must be included
$_function = "smarty_insert_{$_name}"; $_function = "smarty_insert_{$_name}";
$_smarty_tpl = $compiler->template; $_smarty_tpl = $compiler->template;
$_filepath = false; $_filepath = false;
eval('$_script = @' . $_attr['script'] . ';'); eval('$_script = @' . $_attr[ 'script' ] . ';');
if (!isset($compiler->smarty->security_policy) && file_exists($_script)) { if (!isset($compiler->smarty->security_policy) && file_exists($_script)) {
$_filepath = $_script; $_filepath = $_script;
} else { } else {
@@ -109,7 +109,8 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_output .= "require_once '{$_filepath}' ;"; $_output .= "require_once '{$_filepath}' ;";
require_once $_filepath; require_once $_filepath;
if (!is_callable($_function)) { if (!is_callable($_function)) {
$compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", null, true); $compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'",
null, true);
} }
} else { } else {
$_filepath = 'null'; $_filepath = 'null';
@@ -118,12 +119,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
if (!is_callable($_function)) { if (!is_callable($_function)) {
// try plugin // try plugin
if (!$_function = $compiler->getPlugin($_name, 'insert')) { if (!$_function = $compiler->getPlugin($_name, 'insert')) {
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", null, true); $compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", null,
true);
} }
} }
} }
// delete {insert} standard attributes // delete {insert} standard attributes
unset($_attr['name'], $_attr['assign'], $_attr['script'], $_attr['nocache']); unset($_attr[ 'name' ], $_attr[ 'assign' ], $_attr[ 'script' ], $_attr[ 'nocache' ]);
// convert attributes into parameter array string // convert attributes into parameter array string
$_paramsArray = array(); $_paramsArray = array();
foreach ($_attr as $_key => $_value) { foreach ($_attr as $_key => $_value) {

View File

@@ -29,7 +29,7 @@ class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
// this tag does not return compiled code // this tag does not return compiled code

View File

@@ -66,8 +66,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 .= "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 .= "\$_smarty_tpl->smarty->_cache['_tag_stack'][] = array('{$tag}', {$_params});\n";
$output .= $output .= "\$_block_repeat{$this->nesting}=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat{$this->nesting});\nwhile (\$_block_repeat{$this->nesting}) {\nob_start();\n?>";
"\$_block_repeat{$this->nesting}=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat{$this->nesting});\nwhile (\$_block_repeat{$this->nesting}) {\nob_start();\n?>";
$this->openTag($compiler, $tag, array($_params, $compiler->nocache, $callback)); $this->openTag($compiler, $tag, array($_params, $compiler->nocache, $callback));
// maybe nocache because of nocache variables or nocache plugin // maybe nocache because of nocache variables or nocache plugin
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
@@ -90,11 +89,11 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
$mod_pre = "ob_start();\n"; $mod_pre = "ob_start();\n";
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), $mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifier_list' ], array('modifierlist' => $parameter[ 'modifier_list' ],
'value' => 'ob_get_clean()')) . ";\n"; 'value' => 'ob_get_clean()')) . ";\n";
} }
$output = "<?php " . $mod_content . "\$_block_repeat{$this->nesting}=false;\n" . $mod_pre . $output = "<?php " . $mod_content . "\$_block_repeat{$this->nesting}=false;\n" . $mod_pre .
"echo {$callback}({$_params}, " . $mod_content2 . "echo {$callback}({$_params}, " . $mod_content2 .
", \$_smarty_tpl, \$_block_repeat{$this->nesting});\n" . $mod_post . "}\n"; ", \$_smarty_tpl, \$_block_repeat{$this->nesting});\n" . $mod_post . "}\n";
$output .= "array_pop(\$_smarty_tpl->smarty->_cache['_tag_stack']);"; $output .= "array_pop(\$_smarty_tpl->smarty->_cache['_tag_stack']);";
$output .= "?>"; $output .= "?>";
$this->nesting --; $this->nesting --;

View File

@@ -110,11 +110,11 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
public function buildPropertyPreg($named, $attributes) public function buildPropertyPreg($named, $attributes)
{ {
if ($named) { if ($named) {
$this->resultOffsets['named'] = $this->startOffset + 3; $this->resultOffsets[ 'named' ] = $this->startOffset + 3;
$this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.]("; $this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.](";
$properties = $this->nameProperties; $properties = $this->nameProperties;
} else { } else {
$this->resultOffsets['item'] = $this->startOffset + 3; $this->resultOffsets[ 'item' ] = $this->startOffset + 3;
$this->propertyPreg .= "([\$]{$attributes['item']}[@]("; $this->propertyPreg .= "([\$]{$attributes['item']}[@](";
$properties = $this->itemProperties; $properties = $this->itemProperties;
} }
@@ -140,8 +140,8 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
preg_match_all($this->propertyPreg, $source, $match, PREG_SET_ORDER); preg_match_all($this->propertyPreg, $source, $match, PREG_SET_ORDER);
foreach ($this->resultOffsets as $key => $offset) { foreach ($this->resultOffsets as $key => $offset) {
foreach ($match as $m) { foreach ($match as $m) {
if (isset($m[$offset]) && !empty($m[$offset])) { if (isset($m[ $offset ]) && !empty($m[ $offset ])) {
$this->matchResults[$key][strtolower($m[$offset])] = true; $this->matchResults[ $key ][ strtolower($m[ $offset ]) ] = true;
} }
} }
} }
@@ -173,9 +173,11 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
$_content = $nextCompiler->template->source->getContent(); $_content = $nextCompiler->template->source->getContent();
if ($_content != '') { if ($_content != '') {
// run pre filter if required // run pre filter if required
if ((isset($nextCompiler->smarty->autoload_filters['pre']) || if ((isset($nextCompiler->smarty->autoload_filters[ 'pre' ]) ||
isset($nextCompiler->smarty->registered_filters['pre']))) { isset($nextCompiler->smarty->registered_filters[ 'pre' ]))
$_content = $nextCompiler->smarty->ext->_filterHandler->runFilter('pre', $_content, $nextCompiler->template); ) {
$_content = $nextCompiler->smarty->ext->_filterHandler->runFilter('pre', $_content,
$nextCompiler->template);
} }
$this->matchProperty($_content); $this->matchProperty($_content);
} }
@@ -190,7 +192,6 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*/ */
public function matchBlockSource(Smarty_Internal_TemplateCompilerBase $compiler) public function matchBlockSource(Smarty_Internal_TemplateCompilerBase $compiler)
{ {
} }
/** /**

View File

@@ -35,25 +35,25 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
/** /**
* Compiles code for the execution of function plugin * Compiles code for the execution of function plugin
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @param string $tag name of function plugin * @param string $tag name of function plugin
* @param string $function PHP function name * @param string $function PHP function name
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
{ {
// This tag does create output // This tag does create output
$compiler->has_output = true; $compiler->has_output = true;
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
unset($_attr['nocache']); unset($_attr[ 'nocache' ]);
// convert attributes into parameter array string // convert attributes into parameter array string
$_paramsArray = array(); $_paramsArray = array();
foreach ($_attr as $_key => $_value) { foreach ($_attr as $_key => $_value) {

View File

@@ -31,15 +31,15 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$output = $parameter['value']; $output = $parameter[ 'value' ];
// loop over list of modifiers // loop over list of modifiers
foreach ($parameter['modifierlist'] as $single_modifier) { foreach ($parameter[ 'modifierlist' ] as $single_modifier) {
$modifier = $single_modifier[0]; $modifier = $single_modifier[ 0 ];
$single_modifier[0] = $output; $single_modifier[ 0 ] = $output;
$params = implode(',', $single_modifier); $params = implode(',', $single_modifier);
// check if we know already the type of modifier // check if we know already the type of modifier
if (isset($compiler->known_modifier_type[$modifier])) { if (isset($compiler->known_modifier_type[ $modifier ])) {
$modifier_types = array($compiler->known_modifier_type[$modifier]); $modifier_types = array($compiler->known_modifier_type[ $modifier ]);
} else { } else {
$modifier_types = array(1, 2, 3, 4, 5, 6); $modifier_types = array(1, 2, 3, 4, 5, 6);
} }
@@ -47,27 +47,30 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
switch ($type) { switch ($type) {
case 1: case 1:
// registered modifier // registered modifier
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) { if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) {
$function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; $function =
$compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ];
if (!is_array($function)) { if (!is_array($function)) {
$output = "{$function}({$params})"; $output = "{$function}({$params})";
} else { } else {
if (is_object($function[0])) { if (is_object($function[ 0 ])) {
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
$modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; $modifier . '\'][0][0]->' . $function[ 1 ] . '(' . $params . ')';
} else { } else {
$output = $function[0] . '::' . $function[1] . '(' . $params . ')'; $output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')';
} }
} }
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[ $modifier ] = $type;
break 2; break 2;
} }
break; break;
case 2: case 2:
// registered modifier compiler // registered modifier compiler
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) { if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ])) {
$output = call_user_func($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], $single_modifier, $compiler->smarty); $output =
$compiler->known_modifier_type[$modifier] = $type; call_user_func($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ],
$single_modifier, $compiler->smarty);
$compiler->known_modifier_type[ $modifier ] = $type;
break 2; break 2;
} }
break; break;
@@ -81,7 +84,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
$plugin = 'smarty_modifiercompiler_' . $modifier; $plugin = 'smarty_modifiercompiler_' . $modifier;
$output = $plugin($single_modifier, $compiler); $output = $plugin($single_modifier, $compiler);
} }
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[ $modifier ] = $type;
break 2; break 2;
} }
break; break;
@@ -94,7 +97,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
) { ) {
$output = "{$function}({$params})"; $output = "{$function}({$params})";
} }
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[ $modifier ] = $type;
break 2; break 2;
} }
break; break;
@@ -107,17 +110,17 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
) { ) {
$output = "{$modifier}({$params})"; $output = "{$modifier}({$params})";
} }
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[ $modifier ] = $type;
break 2; break 2;
} }
break; break;
case 6: case 6:
// default plugin handler // default plugin handler
if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || if (isset($compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ]) ||
(is_callable($compiler->smarty->default_plugin_handler_func) && (is_callable($compiler->smarty->default_plugin_handler_func) &&
$compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER)) $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))
) { ) {
$function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; $function = $compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ];
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
@@ -125,27 +128,28 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
if (!is_array($function)) { if (!is_array($function)) {
$output = "{$function}({$params})"; $output = "{$function}({$params})";
} else { } else {
if (is_object($function[0])) { if (is_object($function[ 0 ])) {
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $output =
$modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
$modifier . '\'][0][0]->' . $function[ 1 ] . '(' . $params . ')';
} else { } else {
$output = $function[0] . '::' . $function[1] . '(' . $params . ')'; $output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')';
} }
} }
} }
if (isset($compiler->parent_compiler->template->compiled->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || 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']) isset($compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
) { ) {
// was a plugin // was a plugin
$compiler->known_modifier_type[$modifier] = 4; $compiler->known_modifier_type[ $modifier ] = 4;
} else { } else {
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[ $modifier ] = $type;
} }
break 2; break 2;
} }
} }
} }
if (!isset($compiler->known_modifier_type[$modifier])) { 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);
} }
} }

View File

@@ -27,11 +27,11 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
/** /**
* Compiles code for the execution of function plugin * Compiles code for the execution of function plugin
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @param string $tag name of function * @param string $tag name of function
* @param string $method name of method to call * @param string $method name of method to call
* *
* @return string compiled code * @return string compiled code
*/ */
@@ -39,19 +39,19 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
unset($_attr['nocache']); unset($_attr[ 'nocache' ]);
$_assign = null; $_assign = null;
if (isset($_attr['assign'])) { if (isset($_attr[ 'assign' ])) {
$_assign = $_attr['assign']; $_assign = $_attr[ 'assign' ];
unset($_attr['assign']); unset($_attr[ 'assign' ]);
} }
// method or property ? // method or property ?
if (method_exists($compiler->smarty->registered_objects[$tag][0], $method)) { if (method_exists($compiler->smarty->registered_objects[ $tag ][ 0 ], $method)) {
// convert attributes into parameter array string // convert attributes into parameter array string
if ($compiler->smarty->registered_objects[$tag][2]) { if ($compiler->smarty->registered_objects[ $tag ][ 2 ]) {
$_paramsArray = array(); $_paramsArray = array();
foreach ($_attr as $_key => $_value) { foreach ($_attr as $_key => $_value) {
if (is_int($_key)) { if (is_int($_key)) {

View File

@@ -40,59 +40,69 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$compiler->has_code = false; $compiler->has_code = false;
if ($_attr['type'] == 'xml') { if ($_attr[ 'type' ] == 'xml') {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
$save = $compiler->template->compiled->has_nocache_code; $save = $compiler->template->compiled->has_nocache_code;
$output = addcslashes($_attr['code'], "'\\"); $output = addcslashes($_attr[ 'code' ], "'\\");
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" . $compiler->parser->current_buffer->append_subtree($compiler->parser,
$output . new Smarty_Internal_ParseTree_Tag($compiler->parser,
"';?>", true))); $compiler->processNocacheCode("<?php echo '" .
$output .
"';?>",
true)));
$compiler->template->compiled->has_nocache_code = $save; $compiler->template->compiled->has_nocache_code = $save;
return ''; return '';
} }
if ($_attr['type'] != 'tag') { if ($_attr[ 'type' ] != 'tag') {
if ($compiler->php_handling == Smarty::PHP_REMOVE) { if ($compiler->php_handling == Smarty::PHP_REMOVE) {
return ''; 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, $output =
'quote'), $_attr['code']); preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i',
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Text($output)); array($this, 'quote'), $_attr[ 'code' ]);
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Text($output));
return ''; 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; $compiler->tag_nocache = true;
$save = $compiler->template->compiled->has_nocache_code; $save = $compiler->template->compiled->has_nocache_code;
$output = addcslashes($_attr['code'], "'\\"); $output = addcslashes($_attr[ 'code' ], "'\\");
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" . $compiler->parser->current_buffer->append_subtree($compiler->parser,
$output . new Smarty_Internal_ParseTree_Tag($compiler->parser,
"';?>", true))); $compiler->processNocacheCode("<?php echo '" .
$output .
"';?>",
true)));
$compiler->template->compiled->has_nocache_code = $save; $compiler->template->compiled->has_nocache_code = $save;
return ''; return '';
} elseif ($compiler->php_handling == Smarty::PHP_ALLOW) { } elseif ($compiler->php_handling == Smarty::PHP_ALLOW) {
if (!($compiler->smarty instanceof SmartyBC)) { if (!($compiler->smarty instanceof SmartyBC)) {
$compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', null, true); $compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it',
null, true);
} }
$compiler->has_code = true; $compiler->has_code = true;
return $_attr['code']; return $_attr[ 'code' ];
} else { } else {
$compiler->trigger_template_error('Illegal $smarty->php_handling value', null, true); $compiler->trigger_template_error('Illegal $smarty->php_handling value', null, true);
} }
} else { } else {
$compiler->has_code = true; $compiler->has_code = true;
if (!($compiler->smarty instanceof SmartyBC)) { if (!($compiler->smarty instanceof SmartyBC)) {
$compiler->trigger_template_error('{php}{/php} tags not allowed. Use SmartyBC to enable them', null, true); $compiler->trigger_template_error('{php}{/php} tags not allowed. Use SmartyBC to enable them', null,
true);
} }
$ldel = preg_quote($compiler->smarty->left_delimiter, '#'); $ldel = preg_quote($compiler->smarty->left_delimiter, '#');
$rdel = preg_quote($compiler->smarty->right_delimiter, '#'); $rdel = preg_quote($compiler->smarty->right_delimiter, '#');
preg_match("#^({$ldel}php\\s*)((.)*?)({$rdel})#", $_attr['code'], $match); preg_match("#^({$ldel}php\\s*)((.)*?)({$rdel})#", $_attr[ 'code' ], $match);
if (!empty($match[2])) { if (!empty($match[ 2 ])) {
if ('nocache' == trim($match[2])) { if ('nocache' == trim($match[ 2 ])) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} else { } 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}#", return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"),
"#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), array('<?php ', '?>'), $_attr['code']); array('<?php ', '?>'), $_attr[ 'code' ]);
} }
} }
@@ -152,14 +162,15 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
$start = $lex->counter + strlen($lex->value); $start = $lex->counter + strlen($lex->value);
$body = true; $body = true;
if (preg_match('~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $start)) { if (preg_match('~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $start)) {
$close = $match[0][1]; $close = $match[ 0 ][ 1 ];
} else { } else {
$lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'"); $lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'");
} }
while ($body) { while ($body) {
if (preg_match('~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~', $lex->data, $match, PREG_OFFSET_CAPTURE, $start)) { if (preg_match('~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~',
$value = $match[0][0]; $lex->data, $match, PREG_OFFSET_CAPTURE, $start)) {
$from = $pos = $match[0][1]; $value = $match[ 0 ][ 0 ];
$from = $pos = $match[ 0 ][ 1 ];
if ($pos > $close) { if ($pos > $close) {
$body = false; $body = false;
} else { } else {
@@ -168,15 +179,15 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
if ($phpCommentStart) { if ($phpCommentStart) {
$phpCommentEnd = preg_match('~([*][/])~', $lex->data, $match, PREG_OFFSET_CAPTURE, $start); $phpCommentEnd = preg_match('~([*][/])~', $lex->data, $match, PREG_OFFSET_CAPTURE, $start);
if ($phpCommentEnd) { if ($phpCommentEnd) {
$pos2 = $match[0][1]; $pos2 = $match[ 0 ][ 1 ];
$start = $pos2 + strlen($match[0][0]); $start = $pos2 + strlen($match[ 0 ][ 0 ]);
} }
} }
while ($close > $pos && $close < $start) { while ($close > $pos && $close < $start) {
if (preg_match('~' . preg_quote($closeTag, '~') . if (preg_match('~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE,
'~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $from)) { $from)) {
$close = $match[0][1]; $close = $match[ 0 ][ 1 ];
$from = $close + strlen($match[0][0]); $from = $close + strlen($match[ 0 ][ 0 ]);
} else { } else {
$lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'"); $lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'");
} }
@@ -204,6 +215,6 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
*/ */
private function quote($match) private function quote($match)
{ {
return htmlspecialchars($match[0], ENT_QUOTES); return htmlspecialchars($match[ 0 ], ENT_QUOTES);
} }
} }

View File

@@ -47,58 +47,63 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
// nocache option // nocache option
if ($_attr['nocache'] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
if (isset($_attr['assign'])) { if (isset($_attr[ 'assign' ])) {
// assign output to variable // assign output to variable
$output = "<?php \$_smarty_tpl->assign({$_attr['assign']},{$parameter['value']});?>"; $output = "<?php \$_smarty_tpl->assign({$_attr['assign']},{$parameter['value']});?>";
} else { } else {
// display value // display value
$output = $parameter['value']; $output = $parameter[ 'value' ];
// tag modifier // tag modifier
if (!empty($parameter['modifierlist'])) { if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'], $output = $compiler->compileTag('private_modifier', array(),
'value' => $output)); array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
} }
if (!$_attr['nofilter']) { if (!$_attr[ 'nofilter' ]) {
// default modifier // default modifier
if (!empty($compiler->smarty->default_modifiers)) { if (!empty($compiler->smarty->default_modifiers)) {
if (empty($compiler->default_modifier_list)) { if (empty($compiler->default_modifier_list)) {
$modifierlist = array(); $modifierlist = array();
foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) { foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) {
preg_match_all('/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/', $single_default_modifier, $mod_array); preg_match_all('/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/',
for ($i = 0, $count = count($mod_array[0]); $i < $count; $i ++) { $single_default_modifier, $mod_array);
if ($mod_array[0][$i] != ':') { for ($i = 0, $count = count($mod_array[ 0 ]); $i < $count; $i ++) {
$modifierlist[$key][] = $mod_array[0][$i]; if ($mod_array[ 0 ][ $i ] != ':') {
$modifierlist[ $key ][] = $mod_array[ 0 ][ $i ];
} }
} }
} }
$compiler->default_modifier_list = $modifierlist; $compiler->default_modifier_list = $modifierlist;
} }
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $compiler->default_modifier_list, $output = $compiler->compileTag('private_modifier', array(),
'value' => $output)); array('modifierlist' => $compiler->default_modifier_list,
'value' => $output));
} }
// autoescape html // autoescape html
if ($compiler->template->smarty->escape_html) { if ($compiler->template->smarty->escape_html) {
$output = "htmlspecialchars({$output}, ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')"; $output = "htmlspecialchars({$output}, ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')";
} }
// loop over registered filters // loop over registered filters
if (!empty($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE])) { if (!empty($compiler->template->smarty->registered_filters[ Smarty::FILTER_VARIABLE ])) {
foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key => foreach ($compiler->template->smarty->registered_filters[ Smarty::FILTER_VARIABLE ] as $key =>
$function) { $function) {
if (!is_array($function)) { if (!is_array($function)) {
$output = "{$function}({$output},\$_smarty_tpl)"; $output = "{$function}({$output},\$_smarty_tpl)";
} elseif (is_object($function[0])) { } elseif (is_object($function[ 0 ])) {
$output = "\$_smarty_tpl->smarty->registered_filters[Smarty::FILTER_VARIABLE]['{$key}'][0]->{$function[1]}({$output},\$_smarty_tpl)"; $output =
"\$_smarty_tpl->smarty->registered_filters[Smarty::FILTER_VARIABLE]['{$key}'][0]->{$function[1]}({$output},\$_smarty_tpl)";
} else { } else {
$output = "{$function[0]}::{$function[1]}({$output},\$_smarty_tpl)"; $output = "{$function[0]}::{$function[1]}({$output},\$_smarty_tpl)";
} }
} }
} }
// auto loaded filters // auto loaded filters
if (isset($compiler->smarty->autoload_filters[Smarty::FILTER_VARIABLE])) { if (isset($compiler->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ])) {
foreach ((array) $compiler->template->smarty->autoload_filters[Smarty::FILTER_VARIABLE] as $name) { foreach ((array) $compiler->template->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ] as $name)
{
$result = $this->compile_output_filter($compiler, $name, $output); $result = $this->compile_output_filter($compiler, $name, $output);
if ($result !== false) { if ($result !== false) {
$output = $result; $output = $result;
@@ -110,12 +115,12 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
} }
foreach ($compiler->variable_filters as $filter) { foreach ($compiler->variable_filters as $filter) {
if (count($filter) == 1 && if (count($filter) == 1 &&
($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false ($result = $this->compile_output_filter($compiler, $filter[ 0 ], $output)) !== false
) { ) {
$output = $result; $output = $result;
} else { } else {
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter), $output = $compiler->compileTag('private_modifier', array(),
'value' => $output)); array('modifierlist' => array($filter), 'value' => $output));
} }
} }
} }
@@ -140,11 +145,15 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
$path = $compiler->smarty->loadPlugin($plugin_name, false); $path = $compiler->smarty->loadPlugin($plugin_name, false);
if ($path) { if ($path) {
if ($compiler->template->caching) { 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 ][ 'file' ] =
$compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name; $path;
$compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'function' ] =
$plugin_name;
} else { } 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 ][ 'file' ] =
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name; $path;
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'function' ] =
$plugin_name;
} }
} else { } else {
// not found // not found

View File

@@ -28,28 +28,30 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
*/ */
public function setup(Smarty_Internal_TemplateCompilerBase $compiler, $_attr, $tag, $function) public function setup(Smarty_Internal_TemplateCompilerBase $compiler, $_attr, $tag, $function)
{ {
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag])) { if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_BLOCK ][ $tag ])) {
$tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag]; $tag_info = $compiler->smarty->registered_plugins[ Smarty::PLUGIN_BLOCK ][ $tag ];
$callback = $tag_info[ 0 ]; $callback = $tag_info[ 0 ];
if (is_array($callback)) { if (is_array($callback)) {
if (is_object($callback[ 0 ])) { if (is_object($callback[ 0 ])) {
$callable = "array(\$_block_plugin{$this->nesting}, '{$callback[1]}')"; $callable = "array(\$_block_plugin{$this->nesting}, '{$callback[1]}')";
$callback = array("\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]", "->{$callback[1]}"); $callback =
array("\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]", "->{$callback[1]}");
} else { } else {
$callable = "array(\$_block_plugin{$this->nesting}, '{$callback[1]}')"; $callable = "array(\$_block_plugin{$this->nesting}, '{$callback[1]}')";
$callback = array("\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]", "::{$callback[1]}"); $callback =
array("\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]", "::{$callback[1]}");
} }
} else { } else {
$callable = "\$_block_plugin{$this->nesting}"; $callable = "\$_block_plugin{$this->nesting}";
$callback = array("\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0]", ''); $callback = array("\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0]", '');
} }
} else { } else {
$tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag]; $tag_info = $compiler->default_handler_plugins[ Smarty::PLUGIN_BLOCK ][ $tag ];
$callback = $tag_info[ 0 ]; $callback = $tag_info[ 0 ];
if (is_array($callback)) { if (is_array($callback)) {
$callable = "array('{$callback[0]}', '{$callback[1]}')"; $callable = "array('{$callback[0]}', '{$callback[1]}')";
$callback = "{$callback[1]}::{$callback[1]}"; $callback = "{$callback[1]}::{$callback[1]}";
} else { } else {
$callable = null; $callable = null;
} }
} }

View File

@@ -27,10 +27,10 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
/** /**
* Compiles code for the execution of a registered function * Compiles code for the execution of a registered function
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @param string $tag name of function * @param string $tag name of function
* *
* @return string compiled code * @return string compiled code
*/ */
@@ -40,23 +40,23 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
$compiler->has_output = true; $compiler->has_output = true;
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache']) { if ($_attr[ 'nocache' ]) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
unset($_attr['nocache']); unset($_attr[ 'nocache' ]);
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) { if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ])) {
$tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag]; $tag_info = $compiler->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
} else { } else {
$tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_FUNCTION][$tag]; $tag_info = $compiler->default_handler_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
} }
// not cachable? // not cachable?
$compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[1]; $compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[ 1 ];
// convert attributes into parameter array string // convert attributes into parameter array string
$_paramsArray = array(); $_paramsArray = array();
foreach ($_attr as $_key => $_value) { foreach ($_attr as $_key => $_value) {
if (is_int($_key)) { if (is_int($_key)) {
$_paramsArray[] = "$_key=>$_value"; $_paramsArray[] = "$_key=>$_value";
} elseif ($compiler->template->caching && in_array($_key, $tag_info[2])) { } elseif ($compiler->template->caching && in_array($_key, $tag_info[ 2 ])) {
$_value = str_replace("'", "^#^", $_value); $_value = str_replace("'", "^#^", $_value);
$_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^"; $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
} else { } else {
@@ -64,12 +64,13 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
} }
} }
$_params = 'array(' . implode(",", $_paramsArray) . ')'; $_params = 'array(' . implode(",", $_paramsArray) . ')';
$function = $tag_info[0]; $function = $tag_info[ 0 ];
// compile code // compile code
if (!is_array($function)) { if (!is_array($function)) {
$output = "<?php echo {$function}({$_params},\$_smarty_tpl);?>\n"; $output = "<?php echo {$function}({$_params},\$_smarty_tpl);?>\n";
} elseif (is_object($function[0])) { } elseif (is_object($function[ 0 ])) {
$output = "<?php echo \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl);?>\n"; $output =
"<?php echo \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl);?>\n";
} else { } else {
$output = "<?php echo {$function[0]}::{$function[1]}({$_params},\$_smarty_tpl);?>\n"; $output = "<?php echo {$function[0]}::{$function[1]}({$_params},\$_smarty_tpl);?>\n";
} }

View File

@@ -85,7 +85,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
return 'dirname($_smarty_tpl->source->filepath)'; return 'dirname($_smarty_tpl->source->filepath)';
case 'version': case 'version':
return "Smarty::SMARTY_VERSION"; return "Smarty::SMARTY_VERSION";
case 'const': case 'const':
if (isset($compiler->smarty->security_policy) && if (isset($compiler->smarty->security_policy) &&

View File

@@ -20,7 +20,7 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase
* Compiles code for the {rdelim} tag * Compiles code for the {rdelim} tag
* This tag does output the right delimiter. * This tag does output the right delimiter.
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* *
* @return string compiled code * @return string compiled code
@@ -29,7 +29,7 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
// this tag does not return compiled code // this tag does not return compiled code

View File

@@ -59,8 +59,8 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
* *
* @var array * @var array
*/ */
public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum', public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum', 'index_prev',
'index_prev', 'index_next', 'loop'); 'index_next', 'loop');
/** /**
* {section} tag has no item properties * {section} tag has no item properties
@@ -87,11 +87,11 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$compiler->loopNesting++; $compiler->loopNesting ++;
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$attributes = array('name' => $compiler->getId($_attr['name'])); $attributes = array('name' => $compiler->getId($_attr[ 'name' ]));
unset($_attr['name']); unset($_attr[ 'name' ]);
foreach ($attributes as $a => $v) { foreach ($attributes as $a => $v) {
if ($v === false) { if ($v === false) {
$compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true); $compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true);
@@ -103,22 +103,23 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $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('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}'] : false",);
$initNamedProperty = array(); $initNamedProperty = array();
$initFor = array(); $initFor = array();
$incFor = array(); $incFor = array();
$cmpFor = array(); $cmpFor = array();
$propValue = array('index' => "{$sectionVar}->value['index']", 'show' => 'true', 'step' => 1, $propValue = array('index' => "{$sectionVar}->value['index']", 'show' => 'true', 'step' => 1,
'iteration' => "{$local}iteration", 'iteration' => "{$local}iteration",
); );
$propType = array('index' => 2, 'iteration' => 2, 'show' => 0, 'step' => 0,); $propType = array('index' => 2, 'iteration' => 2, 'show' => 0, 'step' => 0,);
// search for used tag attributes // search for used tag attributes
$this->scanForProperties($attributes, $compiler); $this->scanForProperties($attributes, $compiler);
if (!empty($this->matchResults['named'])) { if (!empty($this->matchResults[ 'named' ])) {
$namedAttr = $this->matchResults['named']; $namedAttr = $this->matchResults[ 'named' ];
} }
$namedAttr['index'] = true; $namedAttr[ 'index' ] = true;
$output = "<?php\n"; $output = "<?php\n";
foreach ($_attr as $attr_name => $attr_value) { foreach ($_attr as $attr_name => $attr_value) {
switch ($attr_name) { switch ($attr_name) {
@@ -130,13 +131,13 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$v = "(is_array(@\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop))"; $v = "(is_array(@\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop))";
$t = 1; $t = 1;
} }
if (isset($namedAttr['loop'])) { if (isset($namedAttr[ 'loop' ])) {
$initNamedProperty['loop'] = "'loop' => {$v}"; $initNamedProperty[ 'loop' ] = "'loop' => {$v}";
if ($t == 1) { if ($t == 1) {
$v = "{$sectionVar}->value['loop']"; $v = "{$sectionVar}->value['loop']";
} }
} elseif ($t == 1) { } elseif ($t == 1) {
$initLocal['loop'] = $v; $initLocal[ 'loop' ] = $v;
$v = "{$local}loop"; $v = "{$local}loop";
} }
break; break;
@@ -156,7 +157,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$t = 0; $t = 0;
break; break;
} }
$initLocal['step'] = "((int)@$attr_value) == 0 ? 1 : (int)@$attr_value"; $initLocal[ 'step' ] = "((int)@$attr_value) == 0 ? 1 : (int)@$attr_value";
$v = "{$local}step"; $v = "{$local}step";
$t = 2; $t = 2;
break; break;
@@ -175,169 +176,171 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
if ($t == 3 && $compiler->getId($attr_value)) { if ($t == 3 && $compiler->getId($attr_value)) {
$t = 1; $t = 1;
} }
$propValue[$attr_name] = $v; $propValue[ $attr_name ] = $v;
$propType[$attr_name] = $t; $propType[ $attr_name ] = $t;
} }
if (isset($namedAttr['step'])) { if (isset($namedAttr[ 'step' ])) {
$initNamedProperty['step'] = $propValue['step']; $initNamedProperty[ 'step' ] = $propValue[ 'step' ];
} }
if (isset($namedAttr['iteration'])) { if (isset($namedAttr[ 'iteration' ])) {
$propValue['iteration'] = "{$sectionVar}->value['iteration']"; $propValue[ 'iteration' ] = "{$sectionVar}->value['iteration']";
} }
$incFor['iteration'] = "{$propValue['iteration']}++"; $incFor[ 'iteration' ] = "{$propValue['iteration']}++";
$initFor['iteration'] = "{$propValue['iteration']} = 1"; $initFor[ 'iteration' ] = "{$propValue['iteration']} = 1";
if ($propType['step'] == 0) { if ($propType[ 'step' ] == 0) {
if ($propValue['step'] == 1) { if ($propValue[ 'step' ] == 1) {
$incFor['index'] = "{$sectionVar}->value['index']++"; $incFor[ 'index' ] = "{$sectionVar}->value['index']++";
} elseif ($propValue['step'] > 1) { } elseif ($propValue[ 'step' ] > 1) {
$incFor['index'] = "{$sectionVar}->value['index'] += {$propValue['step']}"; $incFor[ 'index' ] = "{$sectionVar}->value['index'] += {$propValue['step']}";
} else { } else {
$incFor['index'] = "{$sectionVar}->value['index'] -= " . - $propValue['step']; $incFor[ 'index' ] = "{$sectionVar}->value['index'] -= " . - $propValue[ 'step' ];
} }
} else { } else {
$incFor['index'] = "{$sectionVar}->value['index'] += {$propValue['step']}"; $incFor[ 'index' ] = "{$sectionVar}->value['index'] += {$propValue['step']}";
} }
if (!isset($propValue['max'])) { if (!isset($propValue[ 'max' ])) {
$propValue['max'] = $propValue['loop']; $propValue[ 'max' ] = $propValue[ 'loop' ];
$propType['max'] = $propType['loop']; $propType[ 'max' ] = $propType[ 'loop' ];
} elseif ($propType['max'] != 0) { } elseif ($propType[ 'max' ] != 0) {
$propValue['max'] = "{$propValue['max']} < 0 ? {$propValue['loop']} : {$propValue['max']}"; $propValue[ 'max' ] = "{$propValue['max']} < 0 ? {$propValue['loop']} : {$propValue['max']}";
$propType['max'] = 1; $propType[ 'max' ] = 1;
} else { } else {
if ($propValue['max'] < 0) { if ($propValue[ 'max' ] < 0) {
$propValue['max'] = $propValue['loop']; $propValue[ 'max' ] = $propValue[ 'loop' ];
$propType['max'] = $propType['loop']; $propType[ 'max' ] = $propType[ 'loop' ];
} }
} }
if (!isset($propValue['start'])) { if (!isset($propValue[ 'start' ])) {
$start_code = array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue['loop'], $start_code =
5 => ' - 1'); 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[ 5 ] = '';
$start_code[4] = $propValue['loop'] - 1; $start_code[ 4 ] = $propValue[ 'loop' ] - 1;
} }
if ($propType['step'] == 0) { if ($propType[ 'step' ] == 0) {
if ($propValue['step'] > 0) { if ($propValue[ 'step' ] > 0) {
$start_code = array(1 => '0'); $start_code = array(1 => '0');
$propType['start'] = 0; $propType[ 'start' ] = 0;
} else { } else {
$start_code[1] = $start_code[2] = $start_code[3] = ''; $start_code[ 1 ] = $start_code[ 2 ] = $start_code[ 3 ] = '';
$propType['start'] = $propType['loop']; $propType[ 'start' ] = $propType[ 'loop' ];
} }
} else { } else {
$propType['start'] = 1; $propType[ 'start' ] = 1;
} }
$propValue['start'] = join('', $start_code); $propValue[ 'start' ] = join('', $start_code);
} else { } else {
$start_code = array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ", $start_code =
4 => '0', 5 => ' : ', 6 => '-1', 7 => ', ', array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ", 4 => '0',
8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')', 11 => ' : ', 5 => ' : ', 6 => '-1', 7 => ', ', 8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')',
12 => 'min(', 13 => $propValue['start'], 14 => ', ', 11 => ' : ', 12 => 'min(', 13 => $propValue[ 'start' ], 14 => ', ',
15 => "{$propValue['step']} > 0 ? ", 16 => $propValue['loop'], 17 => ' : ', 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 => ')'); 19 => ')');
if ($propType['step'] == 0) { if ($propType[ 'step' ] == 0) {
$start_code[3] = $start_code[5] = $start_code[15] = $start_code[17] = ''; $start_code[ 3 ] = $start_code[ 5 ] = $start_code[ 15 ] = $start_code[ 17 ] = '';
if ($propValue['step'] > 0) { if ($propValue[ 'step' ] > 0) {
$start_code[6] = $start_code[18] = ''; $start_code[ 6 ] = $start_code[ 18 ] = '';
} else { } else {
$start_code[4] = $start_code[16] = ''; $start_code[ 4 ] = $start_code[ 16 ] = '';
} }
} }
if ($propType['start'] == 0) { if ($propType[ 'start' ] == 0) {
if ($propType['loop'] == 0) { if ($propType[ 'loop' ] == 0) {
$start_code[8] = $propValue['start'] + $propValue['loop']; $start_code[ 8 ] = $propValue[ 'start' ] + $propValue[ 'loop' ];
} }
$propType['start'] = $propType['step'] + $propType['loop']; $propType[ 'start' ] = $propType[ 'step' ] + $propType[ 'loop' ];
$start_code[1] = ''; $start_code[ 1 ] = '';
if ($propValue['start'] < 0) { if ($propValue[ 'start' ] < 0) {
for ($i = 11; $i <= 19; $i ++) { for ($i = 11; $i <= 19; $i ++) {
$start_code[$i] = ''; $start_code[ $i ] = '';
} }
if ($propType['start'] == 0) { if ($propType[ 'start' ] == 0) {
$start_code = array(max($propValue['step'] > 0 ? 0 : - 1, $propValue['start'] + $start_code = array(max($propValue[ 'step' ] > 0 ? 0 : - 1,
$propValue['loop'])); $propValue[ 'start' ] + $propValue[ 'loop' ]));
} }
} else { } else {
for ($i = 1; $i <= 11; $i ++) { for ($i = 1; $i <= 11; $i ++) {
$start_code[$i] = ''; $start_code[ $i ] = '';
} }
if ($propType['start'] == 0) { if ($propType[ 'start' ] == 0) {
$start_code = array(min($propValue['step'] > 0 ? $propValue['loop'] : $propValue['loop'] - $start_code =
1, $propValue['start'])); array(min($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1,
$propValue[ 'start' ]));
} }
} }
} }
$propValue['start'] = join('', $start_code); $propValue[ 'start' ] = join('', $start_code);
} }
if ($propType['start'] != 0) { if ($propType[ 'start' ] != 0) {
$initLocal['start'] = $propValue['start']; $initLocal[ 'start' ] = $propValue[ 'start' ];
$propValue['start'] = "{$local}start"; $propValue[ 'start' ] = "{$local}start";
} }
$initFor['index'] = "{$sectionVar}->value['index'] = {$propValue['start']}"; $initFor[ 'index' ] = "{$sectionVar}->value['index'] = {$propValue['start']}";
if (!isset($_attr['start']) && !isset($_attr['step']) && !isset($_attr['max'])) { if (!isset($_attr[ 'start' ]) && !isset($_attr[ 'step' ]) && !isset($_attr[ 'max' ])) {
$propValue['total'] = $propValue['loop']; $propValue[ 'total' ] = $propValue[ 'loop' ];
$propType['total'] = $propType['loop']; $propType[ 'total' ] = $propType[ 'loop' ];
} else { } else {
$propType['total'] = $propType['start'] + $propType['loop'] + $propType['step'] + $propType['max']; $propType[ 'total' ] =
if ($propType['total'] == 0) { $propType[ 'start' ] + $propType[ 'loop' ] + $propType[ 'step' ] + $propType[ 'max' ];
$propValue['total'] = min(ceil(($propValue['step'] > 0 ? $propValue['loop'] - if ($propType[ 'total' ] == 0) {
$propValue['start'] : (int) $propValue['start'] + 1) / $propValue[ 'total' ] =
abs($propValue['step'])), $propValue['max']); min(ceil(($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] - $propValue[ 'start' ] :
(int) $propValue[ 'start' ] + 1) / abs($propValue[ 'step' ])), $propValue[ 'max' ]);
} else { } else {
$total_code = array(1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ", $total_code = array(1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ",
5 => $propValue['loop'], 6 => ' - ', 7 => $propValue['start'], 8 => ' : ', 5 => $propValue[ 'loop' ], 6 => ' - ', 7 => $propValue[ 'start' ], 8 => ' : ',
9 => $propValue['start'], 10 => '+ 1', 11 => ')', 12 => '/ ', 13 => 'abs(', 9 => $propValue[ 'start' ], 10 => '+ 1', 11 => ')', 12 => '/ ', 13 => 'abs(',
14 => $propValue['step'], 15 => ')', 16 => ')', 17 => ", {$propValue['max']})",); 14 => $propValue[ 'step' ], 15 => ')', 16 => ')', 17 => ", {$propValue['max']})",);
if (!isset($propValue['max'])) { if (!isset($propValue[ 'max' ])) {
$total_code[1] = $total_code[17] = ''; $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[ 5 ] = $propValue[ 'loop' ] - $propValue[ 'start' ];
$total_code[6] = $total_code[7] = ''; $total_code[ 6 ] = $total_code[ 7 ] = '';
} }
if ($propType['start'] == 0) { if ($propType[ 'start' ] == 0) {
$total_code[9] = (int) $propValue['start'] + 1; $total_code[ 9 ] = (int) $propValue[ 'start' ] + 1;
$total_code[10] = ''; $total_code[ 10 ] = '';
} }
if ($propType['step'] == 0) { if ($propType[ 'step' ] == 0) {
$total_code[13] = $total_code[15] = ''; $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] = ''; $total_code[ 2 ] = $total_code[ 12 ] = $total_code[ 14 ] = $total_code[ 16 ] = '';
} elseif ($propValue['step'] < 0) { } elseif ($propValue[ 'step' ] < 0) {
$total_code[14] = - $propValue['step']; $total_code[ 14 ] = - $propValue[ 'step' ];
} }
$total_code[4] = ''; $total_code[ 4 ] = '';
if ($propValue['step'] > 0) { if ($propValue[ 'step' ] > 0) {
$total_code[8] = $total_code[9] = $total_code[10] = ''; $total_code[ 8 ] = $total_code[ 9 ] = $total_code[ 10 ] = '';
} else { } else {
$total_code[5] = $total_code[6] = $total_code[7] = $total_code[8] = ''; $total_code[ 5 ] = $total_code[ 6 ] = $total_code[ 7 ] = $total_code[ 8 ] = '';
} }
} }
$propValue['total'] = join('', $total_code); $propValue[ 'total' ] = join('', $total_code);
} }
} }
if (isset($namedAttr[ 'loop' ])) { if (isset($namedAttr[ 'loop' ])) {
$initNamedProperty[ 'loop' ] = "'loop' => {$propValue['total']}"; $initNamedProperty[ 'loop' ] = "'loop' => {$propValue['total']}";
} }
if (isset($namedAttr['total'])) { if (isset($namedAttr[ 'total' ])) {
$initNamedProperty['total'] = "'total' => {$propValue['total']}"; $initNamedProperty[ 'total' ] = "'total' => {$propValue['total']}";
if ($propType['total'] > 0) { if ($propType[ 'total' ] > 0) {
$propValue['total'] = "{$sectionVar}->value['total']"; $propValue[ 'total' ] = "{$sectionVar}->value['total']";
} }
} elseif ($propType['total'] > 0) { } elseif ($propType[ 'total' ] > 0) {
$initLocal['total'] = $propValue['total']; $initLocal[ 'total' ] = $propValue[ 'total' ];
$propValue['total'] = "{$local}total"; $propValue[ 'total' ] = "{$local}total";
} }
$cmpFor['iteration'] = "{$propValue['iteration']} <= {$propValue['total']}"; $cmpFor[ 'iteration' ] = "{$propValue['iteration']} <= {$propValue['total']}";
foreach ($initLocal as $key => $code) { foreach ($initLocal as $key => $code) {
$output .= "{$local}{$key} = {$code};\n"; $output .= "{$local}{$key} = {$code};\n";
@@ -346,17 +349,17 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$_vars = 'array(' . join(', ', $initNamedProperty) . ')'; $_vars = 'array(' . join(', ', $initNamedProperty) . ')';
$output .= "{$sectionVar} = new Smarty_Variable({$_vars});\n"; $output .= "{$sectionVar} = new Smarty_Variable({$_vars});\n";
$cond_code = "{$propValue['total']} != 0"; $cond_code = "{$propValue['total']} != 0";
if ($propType['total'] == 0) { if ($propType[ 'total' ] == 0) {
if ($propValue['total'] == 0) { if ($propValue[ 'total' ] == 0) {
$cond_code = 'false'; $cond_code = 'false';
} else { } else {
$cond_code = 'true'; $cond_code = 'true';
} }
} }
if ($propType['show'] > 0) { if ($propType[ 'show' ] > 0) {
$output .= "{$local}show = {$propValue['show']} ? {$cond_code} : false;\n"; $output .= "{$local}show = {$propValue['show']} ? {$cond_code} : false;\n";
$output .= "if ({$local}show) {\n"; $output .= "if ({$local}show) {\n";
} elseif ($propValue['show'] == 'true') { } elseif ($propValue[ 'show' ] == 'true') {
$output .= "if ({$cond_code}) {\n"; $output .= "if ({$cond_code}) {\n";
} else { } else {
$output .= "if (false) {\n"; $output .= "if (false) {\n";
@@ -365,19 +368,19 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$jcmp = join(', ', $cmpFor); $jcmp = join(', ', $cmpFor);
$jinc = join(', ', $incFor); $jinc = join(', ', $incFor);
$output .= "for ({$jinit}; {$jcmp}; {$jinc}){\n"; $output .= "for ({$jinit}; {$jcmp}; {$jinc}){\n";
if (isset($namedAttr['rownum'])) { if (isset($namedAttr[ 'rownum' ])) {
$output .= "{$sectionVar}->value['rownum'] = {$propValue['iteration']};\n"; $output .= "{$sectionVar}->value['rownum'] = {$propValue['iteration']};\n";
} }
if (isset($namedAttr['index_prev'])) { if (isset($namedAttr[ 'index_prev' ])) {
$output .= "{$sectionVar}->value['index_prev'] = {$propValue['index']} - {$propValue['step']};\n"; $output .= "{$sectionVar}->value['index_prev'] = {$propValue['index']} - {$propValue['step']};\n";
} }
if (isset($namedAttr['index_next'])) { if (isset($namedAttr[ 'index_next' ])) {
$output .= "{$sectionVar}->value['index_next'] = {$propValue['index']} + {$propValue['step']};\n"; $output .= "{$sectionVar}->value['index_next'] = {$propValue['index']} + {$propValue['step']};\n";
} }
if (isset($namedAttr['first'])) { if (isset($namedAttr[ 'first' ])) {
$output .= "{$sectionVar}->value['first'] = ({$propValue['iteration']} == 1);\n"; $output .= "{$sectionVar}->value['first'] = ({$propValue['iteration']} == 1);\n";
} }
if (isset($namedAttr['last'])) { if (isset($namedAttr[ 'last' ])) {
$output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} == {$propValue['total']});\n"; $output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} == {$propValue['total']});\n";
} }
$output .= "?>"; $output .= "?>";
@@ -432,14 +435,14 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$compiler->loopNesting--; $compiler->loopNesting --;
// must endblock be nocache? // must endblock be nocache?
if ($compiler->nocache) { if ($compiler->nocache) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
list($openTag, $compiler->nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section', list($openTag, $compiler->nocache, $local, $sectionVar) =
'sectionelse')); $this->closeTag($compiler, array('section', 'sectionelse'));
$output = "<?php\n"; $output = "<?php\n";
if ($openTag == 'sectionelse') { if ($openTag == 'sectionelse') {

View File

@@ -19,16 +19,16 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase
/** /**
* Compiles code for setfilter tag * Compiles code for setfilter tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
$compiler->variable_filter_stack[] = $compiler->variable_filters; $compiler->variable_filter_stack[] = $compiler->variable_filters;
$compiler->variable_filters = $parameter['modifier_list']; $compiler->variable_filters = $parameter[ 'modifier_list' ];
// this tag does not return compiled code // this tag does not return compiled code
$compiler->has_code = false; $compiler->has_code = false;
@@ -48,7 +48,7 @@ class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase
* Compiles code for the {/setfilter} tag * Compiles code for the {/setfilter} tag
* This tag does not generate compiled output. It resets variable filter. * This tag does not generate compiled output. It resets variable filter.
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* *
* @return string compiled code * @return string compiled code

View File

@@ -24,11 +24,11 @@ class Smarty_Internal_Compile_Shared_Inheritance extends Smarty_Internal_Compile
*/ */
public function registerInit(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false) public function registerInit(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
{ {
if ($initChildSequence || !isset($compiler->_cache['inheritanceInit'])) { if ($initChildSequence || !isset($compiler->_cache[ 'inheritanceInit' ])) {
$compiler->registerPostCompileCallback(array('Smarty_Internal_Compile_Shared_Inheritance', 'postCompile'), $compiler->registerPostCompileCallback(array('Smarty_Internal_Compile_Shared_Inheritance', 'postCompile'),
array($initChildSequence), 'inheritanceInit', $initChildSequence); array($initChildSequence), 'inheritanceInit', $initChildSequence);
$compiler->_cache['inheritanceInit'] = true; $compiler->_cache[ 'inheritanceInit' ] = true;
} }
} }
@@ -41,6 +41,6 @@ class Smarty_Internal_Compile_Shared_Inheritance extends Smarty_Internal_Compile
static function postCompile(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false) static function postCompile(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
{ {
$compiler->prefixCompiledCode .= "<?php \$_smarty_tpl->ext->_inheritance->init(\$_smarty_tpl, " . $compiler->prefixCompiledCode .= "<?php \$_smarty_tpl->ext->_inheritance->init(\$_smarty_tpl, " .
var_export($initChildSequence, true) . ");\n?>\n"; var_export($initChildSequence, true) . ");\n?>\n";
} }
} }

View File

@@ -19,16 +19,16 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
/** /**
* Compiles code for the {while} tag * Compiles code for the {while} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \SmartyCompilerException
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
$compiler->loopNesting++; $compiler->loopNesting ++;
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$this->openTag($compiler, 'while', $compiler->nocache); $this->openTag($compiler, 'while', $compiler->nocache);
@@ -40,41 +40,42 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$_output = "<?php\n"; $_output = "<?php\n";
if (is_array($parameter['if condition'])) { if (is_array($parameter[ 'if condition' ])) {
if ($compiler->nocache) { if ($compiler->nocache) {
$_nocache = ',true'; $_nocache = ',true';
// create nocache var to make it know for further compiling // create nocache var to make it know for further compiling
if (is_array($parameter['if condition']['var'])) { if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$var = trim($parameter['if condition']['var']['var'], "'"); $var = trim($parameter[ 'if condition' ][ 'var' ][ 'var' ], "'");
} else { } else {
$var = trim($parameter['if condition']['var'], "'"); $var = trim($parameter[ 'if condition' ][ 'var' ], "'");
} }
if (isset($compiler->template->tpl_vars[$var])) { if (isset($compiler->template->tpl_vars[ $var ])) {
$compiler->template->tpl_vars[$var]->nocache = true; $compiler->template->tpl_vars[ $var ]->nocache = true;
} else { } else {
$compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true); $compiler->template->tpl_vars[ $var ] = new Smarty_Variable(null, true);
} }
} else { } else {
$_nocache = ''; $_nocache = '';
} }
if (is_array($parameter['if condition']['var'])) { if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . $_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
"]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" .
"]->value)) \$_smarty_tpl->_createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
"$_nocache);\n"; "]->value)) \$_smarty_tpl->_createLocalArrayVariable(" .
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter[ 'if condition' ][ 'var' ][ 'var' ] . "$_nocache);\n";
$parameter['if condition']['var']['smarty_internal_index'] . " = " . $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ][ 'var' ] .
$parameter['if condition']['value'] . ") {?>"; "]->value" . $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] . " = " .
$parameter[ 'if condition' ][ 'value' ] . ") {?>";
} else { } else {
$_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . $_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ] .
"])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ] .
"] = new Smarty_Variable(null{$_nocache});"; "] = new Smarty_Variable(null{$_nocache});";
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter[ 'if condition' ][ 'var' ] . "]->value = " .
$parameter['if condition']['value'] . ") {?>"; $parameter[ 'if condition' ][ 'value' ] . ") {?>";
} }
} else { } else {
$_output .= "while ({$parameter['if condition']}) {?>"; $_output .= "while ({$parameter['if condition']}) {?>";
} }
return $_output; return $_output;
} }
} }
@@ -90,14 +91,14 @@ class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
/** /**
* Compiles code for the {/while} tag * Compiles code for the {/while} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$compiler->loopNesting--; $compiler->loopNesting --;
// must endblock be nocache? // must endblock be nocache?
if ($compiler->nocache) { if ($compiler->nocache) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;

View File

@@ -65,10 +65,10 @@ abstract class Smarty_Internal_CompileBase
if (!is_array($mixed)) { if (!is_array($mixed)) {
// option flag ? // option flag ?
if (in_array(trim($mixed, '\'"'), $this->option_flags)) { if (in_array(trim($mixed, '\'"'), $this->option_flags)) {
$_indexed_attr[trim($mixed, '\'"')] = true; $_indexed_attr[ trim($mixed, '\'"') ] = true;
// shorthand attribute ? // shorthand attribute ?
} elseif (isset($this->shorttag_order[$key])) { } elseif (isset($this->shorttag_order[ $key ])) {
$_indexed_attr[$this->shorttag_order[$key]] = $mixed; $_indexed_attr[ $this->shorttag_order[ $key ] ] = $mixed;
} else { } else {
// too many shorthands // too many shorthands
$compiler->trigger_template_error('too many shorthand attributes', null, true); $compiler->trigger_template_error('too many shorthand attributes', null, true);
@@ -77,20 +77,22 @@ abstract class Smarty_Internal_CompileBase
} else { } else {
$kv = each($mixed); $kv = each($mixed);
// option flag? // option flag?
if (in_array($kv['key'], $this->option_flags)) { if (in_array($kv[ 'key' ], $this->option_flags)) {
if (is_bool($kv['value'])) { if (is_bool($kv[ 'value' ])) {
$_indexed_attr[$kv['key']] = $kv['value']; $_indexed_attr[ $kv[ 'key' ] ] = $kv[ 'value' ];
} elseif (is_string($kv['value']) && in_array(trim($kv['value'], '\'"'), array('true', 'false'))) { } elseif (is_string($kv[ 'value' ]) &&
if (trim($kv['value']) == 'true') { in_array(trim($kv[ 'value' ], '\'"'), array('true', 'false'))
$_indexed_attr[$kv['key']] = true; ) {
if (trim($kv[ 'value' ]) == 'true') {
$_indexed_attr[ $kv[ 'key' ] ] = true;
} else { } else {
$_indexed_attr[$kv['key']] = false; $_indexed_attr[ $kv[ 'key' ] ] = false;
} }
} elseif (is_numeric($kv['value']) && in_array($kv['value'], array(0, 1))) { } elseif (is_numeric($kv[ 'value' ]) && in_array($kv[ 'value' ], array(0, 1))) {
if ($kv['value'] == 1) { if ($kv[ 'value' ] == 1) {
$_indexed_attr[$kv['key']] = true; $_indexed_attr[ $kv[ 'key' ] ] = true;
} else { } else {
$_indexed_attr[$kv['key']] = false; $_indexed_attr[ $kv[ 'key' ] ] = false;
} }
} else { } else {
$compiler->trigger_template_error("illegal value of option flag \"{$kv['key']}\"", null, true); $compiler->trigger_template_error("illegal value of option flag \"{$kv['key']}\"", null, true);
@@ -98,7 +100,7 @@ abstract class Smarty_Internal_CompileBase
// must be named attribute // must be named attribute
} else { } else {
reset($mixed); reset($mixed);
$_indexed_attr[key($mixed)] = $mixed[key($mixed)]; $_indexed_attr[ key($mixed) ] = $mixed[ key($mixed) ];
} }
} }
} }
@@ -119,8 +121,8 @@ abstract class Smarty_Internal_CompileBase
} }
// default 'false' for all option flags not set // default 'false' for all option flags not set
foreach ($this->option_flags as $flag) { foreach ($this->option_flags as $flag) {
if (!isset($_indexed_attr[$flag])) { if (!isset($_indexed_attr[ $flag ])) {
$_indexed_attr[$flag] = false; $_indexed_attr[ $flag ] = false;
} }
} }

View File

@@ -87,8 +87,8 @@ class Smarty_Internal_Config_File_Compiler
$this->lexer_class = $lexer_class; $this->lexer_class = $lexer_class;
$this->parser_class = $parser_class; $this->parser_class = $parser_class;
$this->smarty = $smarty; $this->smarty = $smarty;
$this->config_data['sections'] = array(); $this->config_data[ 'sections' ] = array();
$this->config_data['vars'] = array(); $this->config_data[ 'vars' ] = array();
} }
/** /**
@@ -101,16 +101,16 @@ class Smarty_Internal_Config_File_Compiler
public function compileTemplate(Smarty_Internal_Template $template) public function compileTemplate(Smarty_Internal_Template $template)
{ {
$this->template = $template; $this->template = $template;
$this->template->compiled->file_dependency[$this->template->source->uid] = array($this->template->source->filepath, $this->template->compiled->file_dependency[ $this->template->source->uid ] =
$this->template->source->getTimeStamp(), array($this->template->source->filepath, $this->template->source->getTimeStamp(),
$this->template->source->type); $this->template->source->type);
if ($this->smarty->debugging) { if ($this->smarty->debugging) {
$this->smarty->_debug->start_compile($this->template); $this->smarty->_debug->start_compile($this->template);
} }
// init the lexer/parser to compile the config file // init the lexer/parser to compile the config file
/* @var Smarty_Internal_ConfigFileLexer $lex */ /* @var Smarty_Internal_ConfigFileLexer $lex */
$lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->getContent()) . $lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->getContent()) . "\n",
"\n", $this); $this);
/* @var Smarty_Internal_ConfigFileParser $parser */ /* @var Smarty_Internal_ConfigFileParser $parser */
$parser = new $this->parser_class($lex, $this); $parser = new $this->parser_class($lex, $this);
@@ -141,12 +141,13 @@ class Smarty_Internal_Config_File_Compiler
$this->smarty->_debug->end_compile($this->template); $this->smarty->_debug->end_compile($this->template);
} }
// template header code // template header code
$template_header = "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . $template_header =
strftime("%Y-%m-%d %H:%M:%S") . "\n"; "<?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, ' . $code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
var_export($this->config_data, true) . '); ?>'; var_export($this->config_data, true) . '); ?>';
return $template_header . $this->template->smarty->ext->_codeFrame->create($this->template, $code); return $template_header . $this->template->smarty->ext->_codeFrame->create($this->template, $code);
} }
@@ -170,20 +171,21 @@ class Smarty_Internal_Config_File_Compiler
// $line--; // $line--;
} }
$match = preg_split("/\n/", $this->lex->data); $match = preg_split("/\n/", $this->lex->data);
$error_text = "Syntax error in config file '{$this->template->source->filepath}' on line {$line} '{$match[$line - 1]}' "; $error_text =
"Syntax error in config file '{$this->template->source->filepath}' on line {$line} '{$match[$line - 1]}' ";
if (isset($args)) { if (isset($args)) {
// individual error message // individual error message
$error_text .= $args; $error_text .= $args;
} else { } else {
// expected token from parser // expected token from parser
foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
$exp_token = $this->parser->yyTokenName[$token]; $exp_token = $this->parser->yyTokenName[ $token ];
if (isset($this->lex->smarty_token_names[$exp_token])) { if (isset($this->lex->smarty_token_names[ $exp_token ])) {
// token type from lexer // token type from lexer
$expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"'; $expect[] = '"' . $this->lex->smarty_token_names[ $exp_token ] . '"';
} else { } else {
// otherwise internal token name // otherwise internal token name
$expect[] = $this->parser->yyTokenName[$token]; $expect[] = $this->parser->yyTokenName[ $token ];
} }
} }
// output parser error message // output parser error message

View File

@@ -144,7 +144,7 @@ class Smarty_Internal_Configfilelexer
$this->data = $data . "\n"; //now all lines are \n-terminated $this->data = $data . "\n"; //now all lines are \n-terminated
$this->counter = 0; $this->counter = 0;
if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) { if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) {
$this->counter += strlen($match[0]); $this->counter += strlen($match[ 0 ]);
} }
$this->line = 1; $this->line = 1;
$this->compiler = $compiler; $this->compiler = $compiler;
@@ -179,23 +179,31 @@ class Smarty_Internal_Configfilelexer
public function yypushstate($state) public function yypushstate($state)
{ {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt,
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state);
} }
array_push($this->_yy_stack, $this->_yy_state); array_push($this->_yy_stack, $this->_yy_state);
$this->_yy_state = $state; $this->_yy_state = $state;
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt,
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state);
} }
} }
public function yypopstate() public function yypopstate()
{ {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt,
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state);
} }
$this->_yy_state = array_pop($this->_yy_stack); $this->_yy_state = array_pop($this->_yy_stack);
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt,
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state);
} }
} }
@@ -203,14 +211,17 @@ class Smarty_Internal_Configfilelexer
{ {
$this->_yy_state = $state; $this->_yy_state = $state;
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt,
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
$this->_yy_state);
} }
} }
public function yylex1() public function yylex1()
{ {
if (!isset($this->yy_global_pattern1)) { 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->yy_global_pattern1 =
"/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/isS";
} }
if ($this->counter >= strlen($this->data)) { if ($this->counter >= strlen($this->data)) {
return false; // end of input return false; // end of input
@@ -219,13 +230,14 @@ class Smarty_Internal_Configfilelexer
do { do {
if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, null, $this->counter)) { if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, null, $this->counter)) {
$yysubmatches = $yymatches; $yysubmatches = $yymatches;
if (strlen($yysubmatches[0]) < 200) { if (strlen($yysubmatches[ 0 ]) < 200) {
$yymatches = preg_grep("/(.|\s)+/", $yysubmatches); $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
} else { } else {
$yymatches = array_filter($yymatches, 'strlen'); $yymatches = array_filter($yymatches, 'strlen');
} }
if (empty($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 next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -250,10 +262,11 @@ class Smarty_Internal_Configfilelexer
continue; continue;
} }
} else { } 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; break;
} while (true); }
while (true);
} // end function } // end function
const START = 1; const START = 1;
@@ -312,7 +325,8 @@ class Smarty_Internal_Configfilelexer
public function yylex2() public function yylex2()
{ {
if (!isset($this->yy_global_pattern2)) { 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->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";
} }
if ($this->counter >= strlen($this->data)) { if ($this->counter >= strlen($this->data)) {
return false; // end of input return false; // end of input
@@ -321,13 +335,14 @@ class Smarty_Internal_Configfilelexer
do { do {
if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, null, $this->counter)) { if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, null, $this->counter)) {
$yysubmatches = $yymatches; $yysubmatches = $yymatches;
if (strlen($yysubmatches[0]) < 200) { if (strlen($yysubmatches[ 0 ]) < 200) {
$yymatches = preg_grep("/(.|\s)+/", $yysubmatches); $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
} else { } else {
$yymatches = array_filter($yymatches, 'strlen'); $yymatches = array_filter($yymatches, 'strlen');
} }
if (empty($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 next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -352,10 +367,11 @@ class Smarty_Internal_Configfilelexer
continue; continue;
} }
} else { } 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; break;
} while (true); }
while (true);
} // end function } // end function
const VALUE = 2; const VALUE = 2;
@@ -404,8 +420,8 @@ class Smarty_Internal_Configfilelexer
function yy_r2_7() function yy_r2_7()
{ {
if (!$this->configBooleanize || !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", if (!$this->configBooleanize ||
"no")) !in_array(strtolower($this->value), Array("true", "false", "on", "off", "yes", "no"))
) { ) {
$this->yypopstate(); $this->yypopstate();
$this->yypushstate(self::NAKED_STRING_VALUE); $this->yypushstate(self::NAKED_STRING_VALUE);
@@ -443,13 +459,14 @@ class Smarty_Internal_Configfilelexer
do { do {
if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, null, $this->counter)) { if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, null, $this->counter)) {
$yysubmatches = $yymatches; $yysubmatches = $yymatches;
if (strlen($yysubmatches[0]) < 200) { if (strlen($yysubmatches[ 0 ]) < 200) {
$yymatches = preg_grep("/(.|\s)+/", $yysubmatches); $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
} else { } else {
$yymatches = array_filter($yymatches, 'strlen'); $yymatches = array_filter($yymatches, 'strlen');
} }
if (empty($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 next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -474,10 +491,11 @@ class Smarty_Internal_Configfilelexer
continue; continue;
} }
} else { } 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; break;
} while (true); }
while (true);
} // end function } // end function
const NAKED_STRING_VALUE = 3; const NAKED_STRING_VALUE = 3;
@@ -501,13 +519,14 @@ class Smarty_Internal_Configfilelexer
do { do {
if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, null, $this->counter)) { if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, null, $this->counter)) {
$yysubmatches = $yymatches; $yysubmatches = $yymatches;
if (strlen($yysubmatches[0]) < 200) { if (strlen($yysubmatches[ 0 ]) < 200) {
$yymatches = preg_grep("/(.|\s)+/", $yysubmatches); $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
} else { } else {
$yymatches = array_filter($yymatches, 'strlen'); $yymatches = array_filter($yymatches, 'strlen');
} }
if (empty($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 next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -532,10 +551,11 @@ class Smarty_Internal_Configfilelexer
continue; continue;
} }
} else { } 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; break;
} while (true); }
while (true);
} // end function } // end function
const COMMENT = 4; const COMMENT = 4;
@@ -571,13 +591,14 @@ class Smarty_Internal_Configfilelexer
do { do {
if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, null, $this->counter)) { if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, null, $this->counter)) {
$yysubmatches = $yymatches; $yysubmatches = $yymatches;
if (strlen($yysubmatches[0]) < 200) { if (strlen($yysubmatches[ 0 ]) < 200) {
$yymatches = preg_grep("/(.|\s)+/", $yysubmatches); $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
} else { } else {
$yymatches = array_filter($yymatches, 'strlen'); $yymatches = array_filter($yymatches, 'strlen');
} }
if (empty($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 next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -602,10 +623,11 @@ class Smarty_Internal_Configfilelexer
continue; continue;
} }
} else { } 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; break;
} while (true); }
while (true);
} // end function } // end function
const SECTION = 5; const SECTION = 5;
@@ -635,13 +657,14 @@ class Smarty_Internal_Configfilelexer
do { do {
if (preg_match($this->yy_global_pattern6, $this->data, $yymatches, null, $this->counter)) { if (preg_match($this->yy_global_pattern6, $this->data, $yymatches, null, $this->counter)) {
$yysubmatches = $yymatches; $yysubmatches = $yymatches;
if (strlen($yysubmatches[0]) < 200) { if (strlen($yysubmatches[ 0 ]) < 200) {
$yymatches = preg_grep("/(.|\s)+/", $yysubmatches); $yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
} else { } else {
$yymatches = array_filter($yymatches, 'strlen'); $yymatches = array_filter($yymatches, 'strlen');
} }
if (empty($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 next($yymatches); // skip global match
$this->token = key($yymatches); // token number $this->token = key($yymatches); // token number
@@ -666,10 +689,11 @@ class Smarty_Internal_Configfilelexer
continue; continue;
} }
} else { } 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; break;
} while (true); }
while (true);
} // end function } // end function
const TRIPPLE = 6; const TRIPPLE = 6;
@@ -687,8 +711,8 @@ class Smarty_Internal_Configfilelexer
$to = strlen($this->data); $to = strlen($this->data);
preg_match("/\"\"\"[ \t\r]*[\n#;]/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); preg_match("/\"\"\"[ \t\r]*[\n#;]/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter);
if (isset($match[0][1])) { if (isset($match[ 0 ][ 1 ])) {
$to = $match[0][1]; $to = $match[ 0 ][ 1 ];
} else { } else {
$this->compiler->trigger_template_error("missing or misspelled literal closing tag"); $this->compiler->trigger_template_error("missing or misspelled literal closing tag");
} }

View File

@@ -28,18 +28,18 @@ class TPC_yyToken implements ArrayAccess
public function offsetExists($offset) public function offsetExists($offset)
{ {
return isset($this->metadata[$offset]); return isset($this->metadata[ $offset ]);
} }
public function offsetGet($offset) public function offsetGet($offset)
{ {
return $this->metadata[$offset]; return $this->metadata[ $offset ];
} }
public function offsetSet($offset, $value) public function offsetSet($offset, $value)
{ {
if ($offset === null) { if ($offset === null) {
if (isset($value[0])) { if (isset($value[ 0 ])) {
$x = ($value instanceof TPC_yyToken) ? $value->metadata : $value; $x = ($value instanceof TPC_yyToken) ? $value->metadata : $value;
$this->metadata = array_merge($this->metadata, $x); $this->metadata = array_merge($this->metadata, $x);
@@ -52,16 +52,16 @@ class TPC_yyToken implements ArrayAccess
} }
if ($value instanceof TPC_yyToken) { if ($value instanceof TPC_yyToken) {
if ($value->metadata) { if ($value->metadata) {
$this->metadata[$offset] = $value->metadata; $this->metadata[ $offset ] = $value->metadata;
} }
} elseif ($value) { } elseif ($value) {
$this->metadata[$offset] = $value; $this->metadata[ $offset ] = $value;
} }
} }
public function offsetUnset($offset) public function offsetUnset($offset)
{ {
unset($this->metadata[$offset]); unset($this->metadata[ $offset ]);
} }
} }
@@ -226,9 +226,9 @@ class Smarty_Internal_Configfileparser
$str = ""; $str = "";
foreach ($ss as $s) { foreach ($ss as $s) {
if (strlen($s) === 2 && $s[0] === '\\') { if (strlen($s) === 2 && $s[ 0 ] === '\\') {
if (isset(self::$escapes_single[$s[1]])) { if (isset(self::$escapes_single[ $s[ 1 ] ])) {
$s = self::$escapes_single[$s[1]]; $s = self::$escapes_single[ $s[ 1 ] ];
} }
} }
$str .= $s; $str .= $s;
@@ -269,14 +269,14 @@ class Smarty_Internal_Configfileparser
*/ */
private function set_var(Array $var, Array &$target_array) private function set_var(Array $var, Array &$target_array)
{ {
$key = $var["key"]; $key = $var[ "key" ];
$value = $var["value"]; $value = $var[ "value" ];
if ($this->configOverwrite || !isset($target_array['vars'][$key])) { if ($this->configOverwrite || !isset($target_array[ 'vars' ][ $key ])) {
$target_array['vars'][$key] = $value; $target_array[ 'vars' ][ $key ] = $value;
} else { } else {
settype($target_array['vars'][$key], 'array'); settype($target_array[ 'vars' ][ $key ], 'array');
$target_array['vars'][$key][] = $value; $target_array[ 'vars' ][ $key ][] = $value;
} }
} }
@@ -287,8 +287,8 @@ class Smarty_Internal_Configfileparser
*/ */
private function add_global_vars(Array $vars) private function add_global_vars(Array $vars)
{ {
if (!isset($this->compiler->config_data['vars'])) { if (!isset($this->compiler->config_data[ 'vars' ])) {
$this->compiler->config_data['vars'] = Array(); $this->compiler->config_data[ 'vars' ] = Array();
} }
foreach ($vars as $var) { foreach ($vars as $var) {
$this->set_var($var, $this->compiler->config_data); $this->set_var($var, $this->compiler->config_data);
@@ -303,11 +303,11 @@ class Smarty_Internal_Configfileparser
*/ */
private function add_section_vars($section_name, Array $vars) private function add_section_vars($section_name, Array $vars)
{ {
if (!isset($this->compiler->config_data['sections'][$section_name]['vars'])) { if (!isset($this->compiler->config_data[ 'sections' ][ $section_name ][ 'vars' ])) {
$this->compiler->config_data['sections'][$section_name]['vars'] = Array(); $this->compiler->config_data[ 'sections' ][ $section_name ][ 'vars' ] = Array();
} }
foreach ($vars as $var) { foreach ($vars as $var) {
$this->set_var($var, $this->compiler->config_data['sections'][$section_name]); $this->set_var($var, $this->compiler->config_data[ 'sections' ][ $section_name ]);
} }
} }
@@ -356,17 +356,17 @@ class Smarty_Internal_Configfileparser
const YY_SZ_ACTTAB = 38; const YY_SZ_ACTTAB = 38;
static public $yy_action = array(29, 30, 34, 33, 24, 13, 19, 25, 35, 21, 59, 8, 3, 1, 20, 12, 14, 31, 20, 12, 15, static public $yy_action = array(29, 30, 34, 33, 24, 13, 19, 25, 35, 21, 59, 8, 3, 1, 20, 12, 14, 31, 20, 12, 15,
17, 23, 18, 27, 26, 4, 5, 6, 32, 2, 11, 28, 22, 16, 9, 7, 10,); 17, 23, 18, 27, 26, 4, 5, 6, 32, 2, 11, 28, 22, 16, 9, 7, 10,);
static public $yy_lookahead = array(7, 8, 9, 10, 11, 12, 5, 27, 15, 16, 20, 21, 23, 23, 17, 18, 13, 14, 17, 18, 15, static public $yy_lookahead = array(7, 8, 9, 10, 11, 12, 5, 27, 15, 16, 20, 21, 23, 23, 17, 18, 13, 14, 17, 18, 15,
2, 17, 4, 25, 26, 6, 3, 3, 14, 23, 1, 24, 17, 2, 25, 22, 25,); 2, 17, 4, 25, 26, 6, 3, 3, 14, 23, 1, 24, 17, 2, 25, 22, 25,);
const YY_SHIFT_USE_DFLT = - 8; const YY_SHIFT_USE_DFLT = - 8;
const YY_SHIFT_MAX = 19; const YY_SHIFT_MAX = 19;
static public $yy_shift_ofst = array(- 8, 1, 1, 1, - 7, - 3, - 3, 30, - 8, - 8, - 8, 19, 5, 3, 15, 16, 24, 25, 32, static public $yy_shift_ofst = array(- 8, 1, 1, 1, - 7, - 3, - 3, 30, - 8, - 8, - 8, 19, 5, 3, 15, 16, 24, 25, 32,
20,); 20,);
const YY_REDUCE_USE_DFLT = - 21; const YY_REDUCE_USE_DFLT = - 21;
@@ -375,13 +375,15 @@ class Smarty_Internal_Configfileparser
static public $yy_reduce_ofst = array(- 10, - 1, - 1, - 1, - 20, 10, 12, 8, 14, 7, - 11,); static public $yy_reduce_ofst = array(- 10, - 1, - 1, - 1, - 20, 10, 12, 8, 14, 7, - 11,);
static public $yyExpectedTokens = array(array(), array(5, 17, 18,), array(5, 17, 18,), array(5, 17, 18,), static public $yyExpectedTokens = array(array(), array(5, 17, 18,), array(5, 17, 18,), array(5, 17, 18,),
array(7, 8, 9, 10, 11, 12, 15, 16,), array(17, 18,), array(17, 18,), array(1,), array(), array(), array(), array(7, 8, 9, 10, 11, 12, 15, 16,), array(17, 18,), array(17, 18,),
array(2, 4,), array(15, 17,), array(13, 14,), array(14,), array(17,), array(3,), array(3,), array(2,), array(1,), array(), array(), array(), array(2, 4,), array(15, 17,),
array(6,), array(), array(), array(), array(), array(), array(), array(), array(), array(), array(), array(), array(13, 14,), array(14,), array(17,), array(3,), array(3,), array(2,),
array(), array(), array(), array(), array(),); array(6,), array(), array(), array(), array(), array(), array(), array(),
array(), array(), array(), array(), array(), array(), array(), array(),
array(),);
static public $yy_default = array(44, 37, 41, 40, 58, 58, 58, 36, 39, 44, 44, 58, 58, 58, 58, 58, 58, 58, 58, 58, static public $yy_default = array(44, 37, 41, 40, 58, 58, 58, 36, 39, 44, 44, 58, 58, 58, 58, 58, 58, 58, 58, 58,
55, 54, 57, 56, 50, 45, 43, 42, 38, 46, 47, 52, 51, 49, 48, 53,); 55, 54, 57, 56, 50, 45, 43, 42, 38, 46, 47, 52, 51, 49, 48, 53,);
const YYNOCODE = 29; const YYNOCODE = 29;
@@ -425,18 +427,21 @@ class Smarty_Internal_Configfileparser
public $yystack = array(); /* The parser's stack */ public $yystack = array(); /* The parser's stack */
public $yyTokenName = array('$', 'OPENB', 'SECTION', 'CLOSEB', 'DOT', 'ID', 'EQUAL', 'FLOAT', 'INT', 'BOOL', public $yyTokenName = array('$', 'OPENB', 'SECTION', 'CLOSEB', 'DOT', 'ID', 'EQUAL', 'FLOAT', 'INT', 'BOOL',
'SINGLE_QUOTED_STRING', 'DOUBLE_QUOTED_STRING', 'TRIPPLE_QUOTES', 'TRIPPLE_TEXT', 'TRIPPLE_QUOTES_END', 'SINGLE_QUOTED_STRING', 'DOUBLE_QUOTED_STRING', 'TRIPPLE_QUOTES', 'TRIPPLE_TEXT',
'NAKED_STRING', 'OTHER', 'NEWLINE', 'COMMENTSTART', 'error', 'start', 'global_vars', 'sections', 'var_list', 'TRIPPLE_QUOTES_END', 'NAKED_STRING', 'OTHER', 'NEWLINE', 'COMMENTSTART', 'error',
'section', 'newline', 'var', 'value',); 'start', 'global_vars', 'sections', 'var_list', 'section', 'newline', 'var', 'value',);
public static $yyRuleName = array('start ::= global_vars sections', 'global_vars ::= var_list', public static $yyRuleName = array('start ::= global_vars sections', 'global_vars ::= var_list',
'sections ::= sections section', 'sections ::=', 'section ::= OPENB SECTION CLOSEB newline var_list', 'sections ::= sections section', 'sections ::=',
'section ::= OPENB DOT SECTION CLOSEB newline var_list', 'var_list ::= var_list newline', 'section ::= OPENB SECTION CLOSEB newline var_list',
'var_list ::= var_list var', 'var_list ::=', 'var ::= ID EQUAL value', 'value ::= FLOAT', 'value ::= INT', 'section ::= OPENB DOT SECTION CLOSEB newline var_list',
'value ::= BOOL', 'value ::= SINGLE_QUOTED_STRING', 'value ::= DOUBLE_QUOTED_STRING', 'var_list ::= var_list newline', 'var_list ::= var_list var', 'var_list ::=',
'value ::= TRIPPLE_QUOTES TRIPPLE_TEXT TRIPPLE_QUOTES_END', 'value ::= TRIPPLE_QUOTES TRIPPLE_QUOTES_END', 'var ::= ID EQUAL value', 'value ::= FLOAT', 'value ::= INT', 'value ::= BOOL',
'value ::= NAKED_STRING', 'value ::= OTHER', 'newline ::= NEWLINE', 'newline ::= COMMENTSTART NEWLINE', 'value ::= SINGLE_QUOTED_STRING', 'value ::= DOUBLE_QUOTED_STRING',
'newline ::= COMMENTSTART NAKED_STRING NEWLINE',); 'value ::= TRIPPLE_QUOTES TRIPPLE_TEXT TRIPPLE_QUOTES_END',
'value ::= TRIPPLE_QUOTES TRIPPLE_QUOTES_END', 'value ::= NAKED_STRING',
'value ::= OTHER', 'newline ::= NEWLINE', 'newline ::= COMMENTSTART NEWLINE',
'newline ::= COMMENTSTART NAKED_STRING NEWLINE',);
public function tokenName($tokenType) public function tokenName($tokenType)
{ {
@@ -444,7 +449,7 @@ class Smarty_Internal_Configfileparser
return 'End of Input'; return 'End of Input';
} }
if ($tokenType > 0 && $tokenType < count($this->yyTokenName)) { if ($tokenType > 0 && $tokenType < count($this->yyTokenName)) {
return $this->yyTokenName[$tokenType]; return $this->yyTokenName[ $tokenType ];
} else { } else {
return "Unknown"; return "Unknown";
} }
@@ -465,7 +470,7 @@ class Smarty_Internal_Configfileparser
} }
$yytos = array_pop($this->yystack); $yytos = array_pop($this->yystack);
if ($this->yyTraceFILE && $this->yyidx >= 0) { if ($this->yyTraceFILE && $this->yyidx >= 0) {
fwrite($this->yyTraceFILE, $this->yyTracePrompt . 'Popping ' . $this->yyTokenName[$yytos->major] . "\n"); fwrite($this->yyTraceFILE, $this->yyTracePrompt . 'Popping ' . $this->yyTokenName[ $yytos->major ] . "\n");
} }
$yymajor = $yytos->major; $yymajor = $yytos->major;
self::yy_destructor($yymajor, $yytos->minor); self::yy_destructor($yymajor, $yytos->minor);
@@ -488,14 +493,14 @@ class Smarty_Internal_Configfileparser
{ {
static $res3 = array(); static $res3 = array();
static $res4 = array(); static $res4 = array();
$state = $this->yystack[$this->yyidx]->stateno; $state = $this->yystack[ $this->yyidx ]->stateno;
$expected = self::$yyExpectedTokens[$state]; $expected = self::$yyExpectedTokens[ $state ];
if (isset($res3[$state][$token])) { if (isset($res3[ $state ][ $token ])) {
if ($res3[$state][$token]) { if ($res3[ $state ][ $token ]) {
return $expected; return $expected;
} }
} else { } else {
if ($res3[$state][$token] = in_array($token, self::$yyExpectedTokens[$state], true)) { if ($res3[ $state ][ $token ] = in_array($token, self::$yyExpectedTokens[ $state ], true)) {
return $expected; return $expected;
} }
} }
@@ -515,18 +520,21 @@ class Smarty_Internal_Configfileparser
return array_unique($expected); return array_unique($expected);
} }
$yyruleno = $yyact - self::YYNSTATE; $yyruleno = $yyact - self::YYNSTATE;
$this->yyidx -= self::$yyRuleInfo[$yyruleno][1]; $this->yyidx -= self::$yyRuleInfo[ $yyruleno ][ 1 ];
$nextstate = $this->yy_find_reduce_action($this->yystack[$this->yyidx]->stateno, self::$yyRuleInfo[$yyruleno][0]); $nextstate = $this->yy_find_reduce_action($this->yystack[ $this->yyidx ]->stateno,
if (isset(self::$yyExpectedTokens[$nextstate])) { self::$yyRuleInfo[ $yyruleno ][ 0 ]);
$expected = array_merge($expected, self::$yyExpectedTokens[$nextstate]); if (isset(self::$yyExpectedTokens[ $nextstate ])) {
if (isset($res4[$nextstate][$token])) { $expected = array_merge($expected, self::$yyExpectedTokens[ $nextstate ]);
if ($res4[$nextstate][$token]) { if (isset($res4[ $nextstate ][ $token ])) {
if ($res4[ $nextstate ][ $token ]) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
return array_unique($expected); return array_unique($expected);
} }
} else { } else {
if ($res4[$nextstate][$token] = in_array($token, self::$yyExpectedTokens[$nextstate], true)) { if ($res4[ $nextstate ][ $token ] =
in_array($token, self::$yyExpectedTokens[ $nextstate ], true)
) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
return array_unique($expected); return array_unique($expected);
@@ -538,8 +546,8 @@ class Smarty_Internal_Configfileparser
$this->yyidx ++; $this->yyidx ++;
$x = new TPC_yyStackEntry; $x = new TPC_yyStackEntry;
$x->stateno = $nextstate; $x->stateno = $nextstate;
$x->major = self::$yyRuleInfo[$yyruleno][0]; $x->major = self::$yyRuleInfo[ $yyruleno ][ 0 ];
$this->yystack[$this->yyidx] = $x; $this->yystack[ $this->yyidx ] = $x;
continue 2; continue 2;
} elseif ($nextstate == self::YYNSTATE + self::YYNRULE + 1) { } elseif ($nextstate == self::YYNSTATE + self::YYNRULE + 1) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
@@ -556,10 +564,12 @@ class Smarty_Internal_Configfileparser
} else { } else {
$yyact = $nextstate; $yyact = $nextstate;
} }
} while (true); }
while (true);
} }
break; break;
} while (true); }
while (true);
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
@@ -573,13 +583,13 @@ class Smarty_Internal_Configfileparser
if ($token === 0) { if ($token === 0) {
return true; // 0 is not part of this return true; // 0 is not part of this
} }
$state = $this->yystack[$this->yyidx]->stateno; $state = $this->yystack[ $this->yyidx ]->stateno;
if (isset($res[$state][$token])) { if (isset($res[ $state ][ $token ])) {
if ($res[$state][$token]) { if ($res[ $state ][ $token ]) {
return true; return true;
} }
} else { } else {
if ($res[$state][$token] = in_array($token, self::$yyExpectedTokens[$state], true)) { if ($res[ $state ][ $token ] = in_array($token, self::$yyExpectedTokens[ $state ], true)) {
return true; return true;
} }
} }
@@ -599,16 +609,20 @@ class Smarty_Internal_Configfileparser
return true; return true;
} }
$yyruleno = $yyact - self::YYNSTATE; $yyruleno = $yyact - self::YYNSTATE;
$this->yyidx -= self::$yyRuleInfo[$yyruleno][1]; $this->yyidx -= self::$yyRuleInfo[ $yyruleno ][ 1 ];
$nextstate = $this->yy_find_reduce_action($this->yystack[$this->yyidx]->stateno, self::$yyRuleInfo[$yyruleno][0]); $nextstate = $this->yy_find_reduce_action($this->yystack[ $this->yyidx ]->stateno,
if (isset($res2[$nextstate][$token])) { self::$yyRuleInfo[ $yyruleno ][ 0 ]);
if ($res2[$nextstate][$token]) { if (isset($res2[ $nextstate ][ $token ])) {
if ($res2[ $nextstate ][ $token ]) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
return true; return true;
} }
} else { } else {
if ($res2[$nextstate][$token] = (isset(self::$yyExpectedTokens[$nextstate]) && in_array($token, self::$yyExpectedTokens[$nextstate], true))) { if ($res2[ $nextstate ][ $token ] = (isset(self::$yyExpectedTokens[ $nextstate ]) &&
in_array($token, self::$yyExpectedTokens[ $nextstate ],
true))
) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
return true; return true;
@@ -619,8 +633,8 @@ class Smarty_Internal_Configfileparser
$this->yyidx ++; $this->yyidx ++;
$x = new TPC_yyStackEntry; $x = new TPC_yyStackEntry;
$x->stateno = $nextstate; $x->stateno = $nextstate;
$x->major = self::$yyRuleInfo[$yyruleno][0]; $x->major = self::$yyRuleInfo[ $yyruleno ][ 0 ];
$this->yystack[$this->yyidx] = $x; $this->yystack[ $this->yyidx ] = $x;
continue 2; continue 2;
} elseif ($nextstate == self::YYNSTATE + self::YYNRULE + 1) { } elseif ($nextstate == self::YYNSTATE + self::YYNRULE + 1) {
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
@@ -641,10 +655,12 @@ class Smarty_Internal_Configfileparser
} else { } else {
$yyact = $nextstate; $yyact = $nextstate;
} }
} while (true); }
while (true);
} }
break; break;
} while (true); }
while (true);
$this->yyidx = $yyidx; $this->yyidx = $yyidx;
$this->yystack = $stack; $this->yystack = $stack;
@@ -653,33 +669,37 @@ class Smarty_Internal_Configfileparser
public function yy_find_shift_action($iLookAhead) public function yy_find_shift_action($iLookAhead)
{ {
$stateno = $this->yystack[$this->yyidx]->stateno; $stateno = $this->yystack[ $this->yyidx ]->stateno;
/* if ($this->yyidx < 0) return self::YY_NO_ACTION; */ /* if ($this->yyidx < 0) return self::YY_NO_ACTION; */
if (!isset(self::$yy_shift_ofst[$stateno])) { if (!isset(self::$yy_shift_ofst[ $stateno ])) {
// no shift actions // no shift actions
return self::$yy_default[$stateno]; return self::$yy_default[ $stateno ];
} }
$i = self::$yy_shift_ofst[$stateno]; $i = self::$yy_shift_ofst[ $stateno ];
if ($i === self::YY_SHIFT_USE_DFLT) { if ($i === self::YY_SHIFT_USE_DFLT) {
return self::$yy_default[$stateno]; return self::$yy_default[ $stateno ];
} }
if ($iLookAhead == self::YYNOCODE) { if ($iLookAhead == self::YYNOCODE) {
return self::YY_NO_ACTION; return self::YY_NO_ACTION;
} }
$i += $iLookAhead; $i += $iLookAhead;
if ($i < 0 || $i >= self::YY_SZ_ACTTAB || self::$yy_lookahead[$i] != $iLookAhead) { if ($i < 0 || $i >= self::YY_SZ_ACTTAB || self::$yy_lookahead[ $i ] != $iLookAhead) {
if (count(self::$yyFallback) && $iLookAhead < count(self::$yyFallback) && ($iFallback = self::$yyFallback[$iLookAhead]) != 0) { if (count(self::$yyFallback) && $iLookAhead < count(self::$yyFallback) &&
($iFallback = self::$yyFallback[ $iLookAhead ]) != 0
) {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fwrite($this->yyTraceFILE, $this->yyTracePrompt . "FALLBACK " . $this->yyTokenName[$iLookAhead] . " => " . $this->yyTokenName[$iFallback] . "\n"); fwrite($this->yyTraceFILE,
$this->yyTracePrompt . "FALLBACK " . $this->yyTokenName[ $iLookAhead ] . " => " .
$this->yyTokenName[ $iFallback ] . "\n");
} }
return $this->yy_find_shift_action($iFallback); return $this->yy_find_shift_action($iFallback);
} }
return self::$yy_default[$stateno]; return self::$yy_default[ $stateno ];
} else { } else {
return self::$yy_action[$i]; return self::$yy_action[ $i ];
} }
} }
@@ -687,21 +707,21 @@ class Smarty_Internal_Configfileparser
{ {
/* $stateno = $this->yystack[$this->yyidx]->stateno; */ /* $stateno = $this->yystack[$this->yyidx]->stateno; */
if (!isset(self::$yy_reduce_ofst[$stateno])) { if (!isset(self::$yy_reduce_ofst[ $stateno ])) {
return self::$yy_default[$stateno]; return self::$yy_default[ $stateno ];
} }
$i = self::$yy_reduce_ofst[$stateno]; $i = self::$yy_reduce_ofst[ $stateno ];
if ($i == self::YY_REDUCE_USE_DFLT) { if ($i == self::YY_REDUCE_USE_DFLT) {
return self::$yy_default[$stateno]; return self::$yy_default[ $stateno ];
} }
if ($iLookAhead == self::YYNOCODE) { if ($iLookAhead == self::YYNOCODE) {
return self::YY_NO_ACTION; return self::YY_NO_ACTION;
} }
$i += $iLookAhead; $i += $iLookAhead;
if ($i < 0 || $i >= self::YY_SZ_ACTTAB || self::$yy_lookahead[$i] != $iLookAhead) { if ($i < 0 || $i >= self::YY_SZ_ACTTAB || self::$yy_lookahead[ $i ] != $iLookAhead) {
return self::$yy_default[$stateno]; return self::$yy_default[ $stateno ];
} else { } else {
return self::$yy_action[$i]; return self::$yy_action[ $i ];
} }
} }
@@ -732,22 +752,24 @@ class Smarty_Internal_Configfileparser
fprintf($this->yyTraceFILE, "%sShift %d\n", $this->yyTracePrompt, $yyNewState); fprintf($this->yyTraceFILE, "%sShift %d\n", $this->yyTracePrompt, $yyNewState);
fprintf($this->yyTraceFILE, "%sStack:", $this->yyTracePrompt); fprintf($this->yyTraceFILE, "%sStack:", $this->yyTracePrompt);
for ($i = 1; $i <= $this->yyidx; $i ++) { for ($i = 1; $i <= $this->yyidx; $i ++) {
fprintf($this->yyTraceFILE, " %s", $this->yyTokenName[$this->yystack[$i]->major]); fprintf($this->yyTraceFILE, " %s", $this->yyTokenName[ $this->yystack[ $i ]->major ]);
} }
fwrite($this->yyTraceFILE, "\n"); fwrite($this->yyTraceFILE, "\n");
} }
} }
public static $yyRuleInfo = array(array(0 => 20, 1 => 2), array(0 => 21, 1 => 1), array(0 => 22, 1 => 2), public static $yyRuleInfo = array(array(0 => 20, 1 => 2), array(0 => 21, 1 => 1), array(0 => 22, 1 => 2),
array(0 => 22, 1 => 0), array(0 => 24, 1 => 5), array(0 => 24, 1 => 6), array(0 => 23, 1 => 2), array(0 => 22, 1 => 0), array(0 => 24, 1 => 5), array(0 => 24, 1 => 6),
array(0 => 23, 1 => 2), array(0 => 23, 1 => 0), array(0 => 26, 1 => 3), array(0 => 27, 1 => 1), array(0 => 23, 1 => 2), array(0 => 23, 1 => 2), array(0 => 23, 1 => 0),
array(0 => 27, 1 => 1), array(0 => 27, 1 => 1), array(0 => 27, 1 => 1), array(0 => 27, 1 => 1), array(0 => 26, 1 => 3), array(0 => 27, 1 => 1), array(0 => 27, 1 => 1),
array(0 => 27, 1 => 3), array(0 => 27, 1 => 2), array(0 => 27, 1 => 1), array(0 => 27, 1 => 1), array(0 => 27, 1 => 1), array(0 => 27, 1 => 1), array(0 => 27, 1 => 1),
array(0 => 25, 1 => 1), array(0 => 25, 1 => 2), array(0 => 25, 1 => 3),); array(0 => 27, 1 => 3), array(0 => 27, 1 => 2), array(0 => 27, 1 => 1),
array(0 => 27, 1 => 1), array(0 => 25, 1 => 1), array(0 => 25, 1 => 2),
array(0 => 25, 1 => 3),);
public static $yyReduceMap = array(0 => 0, 2 => 0, 3 => 0, 19 => 0, 20 => 0, 21 => 0, 1 => 1, 4 => 4, 5 => 5, public static $yyReduceMap = array(0 => 0, 2 => 0, 3 => 0, 19 => 0, 20 => 0, 21 => 0, 1 => 1, 4 => 4, 5 => 5,
6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12, 13 => 13, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12, 13 => 13, 14 => 14,
14 => 14, 15 => 15, 16 => 16, 17 => 17, 18 => 17,); 15 => 15, 16 => 16, 17 => 17, 18 => 17,);
#line 261 "../smarty/lexer/smarty_internal_configfileparser.y" #line 261 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r0() function yy_r0()
@@ -758,14 +780,14 @@ class Smarty_Internal_Configfileparser
#line 266 "../smarty/lexer/smarty_internal_configfileparser.y" #line 266 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r1() function yy_r1()
{ {
$this->add_global_vars($this->yystack[$this->yyidx + 0]->minor); $this->add_global_vars($this->yystack[ $this->yyidx + 0 ]->minor);
$this->_retvalue = null; $this->_retvalue = null;
} }
#line 280 "../smarty/lexer/smarty_internal_configfileparser.y" #line 280 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r4() function yy_r4()
{ {
$this->add_section_vars($this->yystack[$this->yyidx + - 3]->minor, $this->yystack[$this->yyidx + 0]->minor); $this->add_section_vars($this->yystack[ $this->yyidx + - 3 ]->minor, $this->yystack[ $this->yyidx + 0 ]->minor);
$this->_retvalue = null; $this->_retvalue = null;
} }
@@ -773,7 +795,8 @@ class Smarty_Internal_Configfileparser
function yy_r5() function yy_r5()
{ {
if ($this->configReadHidden) { if ($this->configReadHidden) {
$this->add_section_vars($this->yystack[$this->yyidx + - 3]->minor, $this->yystack[$this->yyidx + 0]->minor); $this->add_section_vars($this->yystack[ $this->yyidx + - 3 ]->minor,
$this->yystack[ $this->yyidx + 0 ]->minor);
} }
$this->_retvalue = null; $this->_retvalue = null;
} }
@@ -781,13 +804,14 @@ class Smarty_Internal_Configfileparser
#line 293 "../smarty/lexer/smarty_internal_configfileparser.y" #line 293 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r6() function yy_r6()
{ {
$this->_retvalue = $this->yystack[$this->yyidx + - 1]->minor; $this->_retvalue = $this->yystack[ $this->yyidx + - 1 ]->minor;
} }
#line 297 "../smarty/lexer/smarty_internal_configfileparser.y" #line 297 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r7() function yy_r7()
{ {
$this->_retvalue = array_merge($this->yystack[$this->yyidx + - 1]->minor, Array($this->yystack[$this->yyidx + 0]->minor)); $this->_retvalue =
array_merge($this->yystack[ $this->yyidx + - 1 ]->minor, Array($this->yystack[ $this->yyidx + 0 ]->minor));
} }
#line 301 "../smarty/lexer/smarty_internal_configfileparser.y" #line 301 "../smarty/lexer/smarty_internal_configfileparser.y"
@@ -799,44 +823,44 @@ class Smarty_Internal_Configfileparser
#line 307 "../smarty/lexer/smarty_internal_configfileparser.y" #line 307 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r9() function yy_r9()
{ {
$this->_retvalue = Array("key" => $this->yystack[$this->yyidx + - 2]->minor, $this->_retvalue = Array("key" => $this->yystack[ $this->yyidx + - 2 ]->minor,
"value" => $this->yystack[$this->yyidx + 0]->minor); "value" => $this->yystack[ $this->yyidx + 0 ]->minor);
} }
#line 312 "../smarty/lexer/smarty_internal_configfileparser.y" #line 312 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r10() function yy_r10()
{ {
$this->_retvalue = (float) $this->yystack[$this->yyidx + 0]->minor; $this->_retvalue = (float) $this->yystack[ $this->yyidx + 0 ]->minor;
} }
#line 316 "../smarty/lexer/smarty_internal_configfileparser.y" #line 316 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r11() function yy_r11()
{ {
$this->_retvalue = (int) $this->yystack[$this->yyidx + 0]->minor; $this->_retvalue = (int) $this->yystack[ $this->yyidx + 0 ]->minor;
} }
#line 320 "../smarty/lexer/smarty_internal_configfileparser.y" #line 320 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r12() function yy_r12()
{ {
$this->_retvalue = $this->parse_bool($this->yystack[$this->yyidx + 0]->minor); $this->_retvalue = $this->parse_bool($this->yystack[ $this->yyidx + 0 ]->minor);
} }
#line 324 "../smarty/lexer/smarty_internal_configfileparser.y" #line 324 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r13() function yy_r13()
{ {
$this->_retvalue = self::parse_single_quoted_string($this->yystack[$this->yyidx + 0]->minor); $this->_retvalue = self::parse_single_quoted_string($this->yystack[ $this->yyidx + 0 ]->minor);
} }
#line 328 "../smarty/lexer/smarty_internal_configfileparser.y" #line 328 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r14() function yy_r14()
{ {
$this->_retvalue = self::parse_double_quoted_string($this->yystack[$this->yyidx + 0]->minor); $this->_retvalue = self::parse_double_quoted_string($this->yystack[ $this->yyidx + 0 ]->minor);
} }
#line 332 "../smarty/lexer/smarty_internal_configfileparser.y" #line 332 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r15() function yy_r15()
{ {
$this->_retvalue = self::parse_tripple_double_quoted_string($this->yystack[$this->yyidx + - 1]->minor); $this->_retvalue = self::parse_tripple_double_quoted_string($this->yystack[ $this->yyidx + - 1 ]->minor);
} }
#line 336 "../smarty/lexer/smarty_internal_configfileparser.y" #line 336 "../smarty/lexer/smarty_internal_configfileparser.y"
@@ -848,7 +872,7 @@ class Smarty_Internal_Configfileparser
#line 340 "../smarty/lexer/smarty_internal_configfileparser.y" #line 340 "../smarty/lexer/smarty_internal_configfileparser.y"
function yy_r17() function yy_r17()
{ {
$this->_retvalue = $this->yystack[$this->yyidx + 0]->minor; $this->_retvalue = $this->yystack[ $this->yyidx + 0 ]->minor;
} }
private $_retvalue; private $_retvalue;
@@ -856,24 +880,25 @@ class Smarty_Internal_Configfileparser
public function yy_reduce($yyruleno) public function yy_reduce($yyruleno)
{ {
if ($this->yyTraceFILE && $yyruleno >= 0 && $yyruleno < count(self::$yyRuleName)) { if ($this->yyTraceFILE && $yyruleno >= 0 && $yyruleno < count(self::$yyRuleName)) {
fprintf($this->yyTraceFILE, "%sReduce (%d) [%s].\n", $this->yyTracePrompt, $yyruleno, self::$yyRuleName[$yyruleno]); fprintf($this->yyTraceFILE, "%sReduce (%d) [%s].\n", $this->yyTracePrompt, $yyruleno,
self::$yyRuleName[ $yyruleno ]);
} }
$this->_retvalue = $yy_lefthand_side = null; $this->_retvalue = $yy_lefthand_side = null;
if (isset(self::$yyReduceMap[$yyruleno])) { if (isset(self::$yyReduceMap[ $yyruleno ])) {
// call the action // call the action
$this->_retvalue = null; $this->_retvalue = null;
$this->{'yy_r' . self::$yyReduceMap[$yyruleno]}(); $this->{'yy_r' . self::$yyReduceMap[ $yyruleno ]}();
$yy_lefthand_side = $this->_retvalue; $yy_lefthand_side = $this->_retvalue;
} }
$yygoto = self::$yyRuleInfo[$yyruleno][0]; $yygoto = self::$yyRuleInfo[ $yyruleno ][ 0 ];
$yysize = self::$yyRuleInfo[$yyruleno][1]; $yysize = self::$yyRuleInfo[ $yyruleno ][ 1 ];
$this->yyidx -= $yysize; $this->yyidx -= $yysize;
for ($i = $yysize; $i; $i --) { for ($i = $yysize; $i; $i --) {
// pop all of the right-hand side parameters // pop all of the right-hand side parameters
array_pop($this->yystack); array_pop($this->yystack);
} }
$yyact = $this->yy_find_reduce_action($this->yystack[$this->yyidx]->stateno, $yygoto); $yyact = $this->yy_find_reduce_action($this->yystack[ $this->yyidx ]->stateno, $yygoto);
if ($yyact < self::YYNSTATE) { if ($yyact < self::YYNSTATE) {
if (!$this->yyTraceFILE && $yysize) { if (!$this->yyTraceFILE && $yysize) {
$this->yyidx ++; $this->yyidx ++;
@@ -881,7 +906,7 @@ class Smarty_Internal_Configfileparser
$x->stateno = $yyact; $x->stateno = $yyact;
$x->major = $yygoto; $x->major = $yygoto;
$x->minor = $yy_lefthand_side; $x->minor = $yy_lefthand_side;
$this->yystack[$this->yyidx] = $x; $this->yystack[ $this->yyidx ] = $x;
} else { } else {
$this->yy_shift($yyact, $yygoto, $yy_lefthand_side); $this->yy_shift($yyact, $yygoto, $yy_lefthand_side);
} }
@@ -940,7 +965,7 @@ class Smarty_Internal_Configfileparser
$yyendofinput = ($yymajor == 0); $yyendofinput = ($yymajor == 0);
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sInput %s\n", $this->yyTracePrompt, $this->yyTokenName[$yymajor]); fprintf($this->yyTraceFILE, "%sInput %s\n", $this->yyTracePrompt, $this->yyTokenName[ $yymajor ]);
} }
do { do {
@@ -967,15 +992,17 @@ class Smarty_Internal_Configfileparser
if ($this->yyerrcnt < 0) { if ($this->yyerrcnt < 0) {
$this->yy_syntax_error($yymajor, $yytokenvalue); $this->yy_syntax_error($yymajor, $yytokenvalue);
} }
$yymx = $this->yystack[$this->yyidx]->major; $yymx = $this->yystack[ $this->yyidx ]->major;
if ($yymx == self::YYERRORSYMBOL || $yyerrorhit) { if ($yymx == self::YYERRORSYMBOL || $yyerrorhit) {
if ($this->yyTraceFILE) { if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sDiscard input token %s\n", $this->yyTracePrompt, $this->yyTokenName[$yymajor]); fprintf($this->yyTraceFILE, "%sDiscard input token %s\n", $this->yyTracePrompt,
$this->yyTokenName[ $yymajor ]);
} }
$this->yy_destructor($yymajor, $yytokenvalue); $this->yy_destructor($yymajor, $yytokenvalue);
$yymajor = self::YYNOCODE; $yymajor = self::YYNOCODE;
} else { } else {
while ($this->yyidx >= 0 && $yymx != self::YYERRORSYMBOL && ($yyact = $this->yy_find_shift_action(self::YYERRORSYMBOL)) >= self::YYNSTATE) { while ($this->yyidx >= 0 && $yymx != self::YYERRORSYMBOL &&
($yyact = $this->yy_find_shift_action(self::YYERRORSYMBOL)) >= self::YYNSTATE) {
$this->yy_pop_parser_stack(); $this->yy_pop_parser_stack();
} }
if ($this->yyidx < 0 || $yymajor == 0) { if ($this->yyidx < 0 || $yymajor == 0) {
@@ -1004,7 +1031,8 @@ class Smarty_Internal_Configfileparser
$this->yy_accept(); $this->yy_accept();
$yymajor = self::YYNOCODE; $yymajor = self::YYNOCODE;
} }
} while ($yymajor != self::YYNOCODE && $this->yyidx >= 0); }
while ($yymajor != self::YYNOCODE && $this->yyidx >= 0);
} }
} }

View File

@@ -15,7 +15,6 @@
* @subpackage Template * @subpackage Template
* *
* @property int $scope * @property int $scope
* The following methods will be dynamically loaded by the extension handler when they are called. * 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 * They are located in a corresponding Smarty_Internal_Method_xxxx class
* *
@@ -97,7 +96,7 @@ class Smarty_Internal_Data
if (is_array($tpl_var)) { if (is_array($tpl_var)) {
foreach ($tpl_var as $_key => $_val) { foreach ($tpl_var as $_key => $_val) {
if ($_key != '') { if ($_key != '') {
$this->tpl_vars[$_key] = new Smarty_Variable($_val, $nocache); $this->tpl_vars[ $_key ] = new Smarty_Variable($_val, $nocache);
if ($this->_objType == 2 && $this->scope) { if ($this->_objType == 2 && $this->scope) {
$this->ext->_updateScope->updateScope($this, $_key); $this->ext->_updateScope->updateScope($this, $_key);
} }
@@ -105,7 +104,7 @@ class Smarty_Internal_Data
} }
} else { } else {
if ($tpl_var != '') { if ($tpl_var != '') {
$this->tpl_vars[$tpl_var] = new Smarty_Variable($value, $nocache); $this->tpl_vars[ $tpl_var ] = new Smarty_Variable($value, $nocache);
if ($this->_objType == 2 && $this->scope) { if ($this->_objType == 2 && $this->scope) {
$this->ext->_updateScope->updateScope($this, $tpl_var); $this->ext->_updateScope->updateScope($this, $tpl_var);
} }
@@ -195,15 +194,17 @@ class Smarty_Internal_Data
/** /**
* gets the object of a Smarty variable * gets the object of a Smarty variable
* *
* @param string $variable the name of the Smarty variable * @param string $variable the name of the Smarty variable
* @param Smarty_Internal_Data $_ptr optional pointer to data object * @param Smarty_Internal_Data $_ptr optional pointer to data object
* @param boolean $searchParents search also in parent data * @param boolean $searchParents search also in parent data
* @param bool $error_enable * @param bool $error_enable
* *
* @return Smarty_Variable|Smarty_Undefined_Variable the object of the variable * @return Smarty_Variable|Smarty_Undefined_Variable the object of the variable
* @deprecated since 3.1.28 please use Smarty_Internal_Data::getTemplateVars() instead. * @deprecated since 3.1.28 please use Smarty_Internal_Data::getTemplateVars() instead.
*/ */
public function getVariable($variable = null, Smarty_Internal_Data $_ptr = null, $searchParents = true, $error_enable = true){ public function getVariable($variable = null, Smarty_Internal_Data $_ptr = null, $searchParents = true,
$error_enable = true)
{
return $this->ext->getTemplateVars->_getVariable($this, $variable, $_ptr, $searchParents, $error_enable); return $this->ext->getTemplateVars->_getVariable($this, $variable, $_ptr, $searchParents, $error_enable);
} }

View File

@@ -55,10 +55,10 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
if (isset($mode)) { if (isset($mode)) {
$this->index ++; $this->index ++;
$this->offset ++; $this->offset ++;
$this->template_data[$this->index] = null; $this->template_data[ $this->index ] = null;
} }
$key = $this->get_key($template); $key = $this->get_key($template);
$this->template_data[$this->index][$key]['start_template_time'] = microtime(true); $this->template_data[ $this->index ][ $key ][ 'start_template_time' ] = microtime(true);
} }
/** /**
@@ -69,8 +69,8 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
public function end_template(Smarty_Internal_Template $template) public function end_template(Smarty_Internal_Template $template)
{ {
$key = $this->get_key($template); $key = $this->get_key($template);
$this->template_data[$this->index][$key]['total_time'] += $this->template_data[ $this->index ][ $key ][ 'total_time' ] +=
microtime(true) - $this->template_data[$this->index][$key]['start_template_time']; microtime(true) - $this->template_data[ $this->index ][ $key ][ 'start_template_time' ];
//$this->template_data[$this->index][$key]['properties'] = $template->properties; //$this->template_data[$this->index][$key]['properties'] = $template->properties;
} }
@@ -84,24 +84,24 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
static $_is_stringy = array('string' => true, 'eval' => true); static $_is_stringy = array('string' => true, 'eval' => true);
if (!empty($template->compiler->trace_uid)) { if (!empty($template->compiler->trace_uid)) {
$key = $template->compiler->trace_uid; $key = $template->compiler->trace_uid;
if (!isset($this->template_data[$this->index][$key])) { if (!isset($this->template_data[ $this->index ][ $key ])) {
if (isset($_is_stringy[$template->source->type])) { if (isset($_is_stringy[ $template->source->type ])) {
$this->template_data[$this->index][$key]['name'] = $this->template_data[ $this->index ][ $key ][ 'name' ] =
'\'' . substr($template->source->name, 0, 25) . '...\''; '\'' . substr($template->source->name, 0, 25) . '...\'';
} else { } else {
$this->template_data[$this->index][$key]['name'] = $template->source->filepath; $this->template_data[ $this->index ][ $key ][ 'name' ] = $template->source->filepath;
} }
$this->template_data[$this->index][$key]['compile_time'] = 0; $this->template_data[ $this->index ][ $key ][ 'compile_time' ] = 0;
$this->template_data[$this->index][$key]['render_time'] = 0; $this->template_data[ $this->index ][ $key ][ 'render_time' ] = 0;
$this->template_data[$this->index][$key]['cache_time'] = 0; $this->template_data[ $this->index ][ $key ][ 'cache_time' ] = 0;
} }
} else { } else {
if (isset($this->ignore_uid[$template->source->uid])) { if (isset($this->ignore_uid[ $template->source->uid ])) {
return; return;
} }
$key = $this->get_key($template); $key = $this->get_key($template);
} }
$this->template_data[$this->index][$key]['start_time'] = microtime(true); $this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
} }
/** /**
@@ -114,14 +114,14 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
if (!empty($template->compiler->trace_uid)) { if (!empty($template->compiler->trace_uid)) {
$key = $template->compiler->trace_uid; $key = $template->compiler->trace_uid;
} else { } else {
if (isset($this->ignore_uid[$template->source->uid])) { if (isset($this->ignore_uid[ $template->source->uid ])) {
return; return;
} }
$key = $this->get_key($template); $key = $this->get_key($template);
} }
$this->template_data[$this->index][$key]['compile_time'] += $this->template_data[ $this->index ][ $key ][ 'compile_time' ] +=
microtime(true) - $this->template_data[$this->index][$key]['start_time']; microtime(true) - $this->template_data[ $this->index ][ $key ][ 'start_time' ];
} }
/** /**
@@ -132,7 +132,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
public function start_render(Smarty_Internal_Template $template) public function start_render(Smarty_Internal_Template $template)
{ {
$key = $this->get_key($template); $key = $this->get_key($template);
$this->template_data[$this->index][$key]['start_time'] = microtime(true); $this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
} }
/** /**
@@ -143,8 +143,8 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
public function end_render(Smarty_Internal_Template $template) public function end_render(Smarty_Internal_Template $template)
{ {
$key = $this->get_key($template); $key = $this->get_key($template);
$this->template_data[$this->index][$key]['render_time'] += $this->template_data[ $this->index ][ $key ][ 'render_time' ] +=
microtime(true) - $this->template_data[$this->index][$key]['start_time']; microtime(true) - $this->template_data[ $this->index ][ $key ][ 'start_time' ];
} }
/** /**
@@ -155,7 +155,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
public function start_cache(Smarty_Internal_Template $template) public function start_cache(Smarty_Internal_Template $template)
{ {
$key = $this->get_key($template); $key = $this->get_key($template);
$this->template_data[$this->index][$key]['start_time'] = microtime(true); $this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
} }
/** /**
@@ -166,8 +166,8 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
public function end_cache(Smarty_Internal_Template $template) public function end_cache(Smarty_Internal_Template $template)
{ {
$key = $this->get_key($template); $key = $this->get_key($template);
$this->template_data[$this->index][$key]['cache_time'] += $this->template_data[ $this->index ][ $key ][ 'cache_time' ] +=
microtime(true) - $this->template_data[$this->index][$key]['start_time']; microtime(true) - $this->template_data[ $this->index ][ $key ][ 'start_time' ];
} }
/** /**
@@ -244,7 +244,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name); $_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]); $_template->assign('template_data', $this->template_data[ $this->index ]);
} else { } else {
$_template->assign('template_data', null); $_template->assign('template_data', null);
} }
@@ -273,53 +273,53 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
{ {
$config_vars = array(); $config_vars = array();
foreach ($obj->config_vars as $key => $var) { foreach ($obj->config_vars as $key => $var) {
$config_vars[$key]['value'] = $var; $config_vars[ $key ][ 'value' ] = $var;
if ($obj->_objType == 2) { if ($obj->_objType == 2) {
$config_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name; $config_vars[ $key ][ 'scope' ] = $obj->source->type . ':' . $obj->source->name;
} elseif ($obj->_objType == 4) { } elseif ($obj->_objType == 4) {
$tpl_vars[$key]['scope'] = $obj->dataObjectName; $tpl_vars[ $key ][ 'scope' ] = $obj->dataObjectName;
} else { } else {
$config_vars[$key]['scope'] = 'Smarty object'; $config_vars[ $key ][ 'scope' ] = 'Smarty object';
} }
} }
$tpl_vars = array(); $tpl_vars = array();
foreach ($obj->tpl_vars as $key => $var) { foreach ($obj->tpl_vars as $key => $var) {
foreach ($var as $varkey => $varvalue) { foreach ($var as $varkey => $varvalue) {
if ($varkey == 'value') { if ($varkey == 'value') {
$tpl_vars[$key][$varkey] = $varvalue; $tpl_vars[ $key ][ $varkey ] = $varvalue;
} else { } else {
if ($varkey == 'nocache') { if ($varkey == 'nocache') {
if ($varvalue == true) { if ($varvalue == true) {
$tpl_vars[$key][$varkey] = $varvalue; $tpl_vars[ $key ][ $varkey ] = $varvalue;
} }
} else { } else {
if ($varkey != 'scope' || $varvalue !== 0) { if ($varkey != 'scope' || $varvalue !== 0) {
$tpl_vars[$key]['attributes'][$varkey] = $varvalue; $tpl_vars[ $key ][ 'attributes' ][ $varkey ] = $varvalue;
} }
} }
} }
} }
if ($obj->_objType == 2) { if ($obj->_objType == 2) {
$tpl_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name; $tpl_vars[ $key ][ 'scope' ] = $obj->source->type . ':' . $obj->source->name;
} elseif ($obj->_objType == 4) { } elseif ($obj->_objType == 4) {
$tpl_vars[$key]['scope'] = $obj->dataObjectName; $tpl_vars[ $key ][ 'scope' ] = $obj->dataObjectName;
} else { } else {
$tpl_vars[$key]['scope'] = 'Smarty object'; $tpl_vars[ $key ][ 'scope' ] = 'Smarty object';
} }
} }
if (isset($obj->parent)) { if (isset($obj->parent)) {
$parent = $this->get_debug_vars($obj->parent); $parent = $this->get_debug_vars($obj->parent);
foreach ($parent->tpl_vars as $name => $pvar) { foreach ($parent->tpl_vars as $name => $pvar) {
if (isset($tpl_vars[$name]) && $tpl_vars[$name]['value'] === $pvar['value']) { if (isset($tpl_vars[ $name ]) && $tpl_vars[ $name ][ 'value' ] === $pvar[ 'value' ]) {
$tpl_vars[$name]['scope'] = $pvar['scope']; $tpl_vars[ $name ][ 'scope' ] = $pvar[ 'scope' ];
} }
} }
$tpl_vars = array_merge($parent->tpl_vars, $tpl_vars); $tpl_vars = array_merge($parent->tpl_vars, $tpl_vars);
foreach ($parent->config_vars as $name => $pvar) { foreach ($parent->config_vars as $name => $pvar) {
if (isset($config_vars[$name]) && $config_vars[$name]['value'] === $pvar['value']) { if (isset($config_vars[ $name ]) && $config_vars[ $name ][ 'value' ] === $pvar[ 'value' ]) {
$config_vars[$name]['scope'] = $pvar['scope']; $config_vars[ $name ][ 'scope' ] = $pvar[ 'scope' ];
} }
} }
$config_vars = array_merge($parent->config_vars, $config_vars); $config_vars = array_merge($parent->config_vars, $config_vars);
@@ -328,20 +328,20 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
if (!array_key_exists($key, $tpl_vars)) { if (!array_key_exists($key, $tpl_vars)) {
foreach ($var as $varkey => $varvalue) { foreach ($var as $varkey => $varvalue) {
if ($varkey == 'value') { if ($varkey == 'value') {
$tpl_vars[$key][$varkey] = $varvalue; $tpl_vars[ $key ][ $varkey ] = $varvalue;
} else { } else {
if ($varkey == 'nocache') { if ($varkey == 'nocache') {
if ($varvalue == true) { if ($varvalue == true) {
$tpl_vars[$key][$varkey] = $varvalue; $tpl_vars[ $key ][ $varkey ] = $varvalue;
} }
} else { } else {
if ($varkey != 'scope' || $varvalue !== 0) { if ($varkey != 'scope' || $varvalue !== 0) {
$tpl_vars[$key]['attributes'][$varkey] = $varvalue; $tpl_vars[ $key ][ 'attributes' ][ $varkey ] = $varvalue;
} }
} }
} }
} }
$tpl_vars[$key]['scope'] = 'Global'; $tpl_vars[ $key ][ 'scope' ] = 'Global';
} }
} }
} }
@@ -364,19 +364,19 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$template->source->filepath; $template->source->filepath;
} }
$key = $template->source->uid; $key = $template->source->uid;
if (isset($this->template_data[$this->index][$key])) { if (isset($this->template_data[ $this->index ][ $key ])) {
return $key; return $key;
} else { } else {
if (isset($_is_stringy[$template->source->type])) { if (isset($_is_stringy[ $template->source->type ])) {
$this->template_data[$this->index][$key]['name'] = $this->template_data[ $this->index ][ $key ][ 'name' ] =
'\'' . substr($template->source->name, 0, 25) . '...\''; '\'' . substr($template->source->name, 0, 25) . '...\'';
} else { } else {
$this->template_data[$this->index][$key]['name'] = $template->source->filepath; $this->template_data[ $this->index ][ $key ][ 'name' ] = $template->source->filepath;
} }
$this->template_data[$this->index][$key]['compile_time'] = 0; $this->template_data[ $this->index ][ $key ][ 'compile_time' ] = 0;
$this->template_data[$this->index][$key]['render_time'] = 0; $this->template_data[ $this->index ][ $key ][ 'render_time' ] = 0;
$this->template_data[$this->index][$key]['cache_time'] = 0; $this->template_data[ $this->index ][ $key ][ 'cache_time' ] = 0;
$this->template_data[$this->index][$key]['total_time'] = 0; $this->template_data[ $this->index ][ $key ][ 'total_time' ] = 0;
return $key; return $key;
} }
@@ -393,7 +393,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
if ($template->source->uid == '') { if ($template->source->uid == '') {
$template->source->filepath; $template->source->filepath;
} }
$this->ignore_uid[$template->source->uid] = true; $this->ignore_uid[ $template->source->uid ] = true;
} }
/** /**
@@ -403,8 +403,8 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*/ */
public function debugUrl(Smarty $smarty) public function debugUrl(Smarty $smarty)
{ {
if (isset($_SERVER['QUERY_STRING'])) { if (isset($_SERVER[ 'QUERY_STRING' ])) {
$_query_string = $_SERVER['QUERY_STRING']; $_query_string = $_SERVER[ 'QUERY_STRING' ];
} else { } else {
$_query_string = ''; $_query_string = '';
} }
@@ -422,7 +422,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$smarty->debugging = true; $smarty->debugging = true;
} }
} else { } else {
if (isset($_COOKIE['SMARTY_DEBUG'])) { if (isset($_COOKIE[ 'SMARTY_DEBUG' ])) {
$smarty->debugging = true; $smarty->debugging = true;
} }
} }

View File

@@ -77,13 +77,13 @@ class Smarty_Internal_Extension_Clear
$_parts_count = count($_parts); $_parts_count = count($_parts);
// check name // check name
if (isset($resource_name)) { if (isset($resource_name)) {
if ($_parts[$_parts_count - 1] != $_resourcename_parts) { if ($_parts[ $_parts_count - 1 ] != $_resourcename_parts) {
continue; continue;
} }
} }
// check compile id // check compile id
if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || if (isset($_compile_id) && (!isset($_parts[ $_parts_count - 2 - $_compile_id_offset ]) ||
$_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id) $_parts[ $_parts_count - 2 - $_compile_id_offset ] != $_compile_id)
) { ) {
continue; continue;
} }
@@ -96,7 +96,7 @@ class Smarty_Internal_Extension_Clear
continue; continue;
} }
for ($i = 0; $i < $_cache_id_parts_count; $i ++) { for ($i = 0; $i < $_cache_id_parts_count; $i ++) {
if ($_parts[$i] != $_cache_id_parts[$i]) { if ($_parts[ $i ] != $_cache_id_parts[ $i ]) {
continue 2; continue 2;
} }
} }
@@ -105,7 +105,7 @@ class Smarty_Internal_Extension_Clear
if (isset($exp_time)) { if (isset($exp_time)) {
if ($exp_time < 0) { if ($exp_time < 0) {
preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match); preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match);
if ($_time < (@filemtime($_file) + $match[1])) { if ($_time < (@filemtime($_file) + $match[ 1 ])) {
continue; continue;
} }
} else { } else {

View File

@@ -10,26 +10,26 @@
* @subpackage PluginsInternal * @subpackage PluginsInternal
* @author Uwe Tews * @author Uwe Tews
* *
* @property Smarty_Internal_Runtime_Inheritance $_inheritance * @property Smarty_Internal_Runtime_Inheritance $_inheritance
* @property Smarty_Internal_Runtime_TplFunction $_tplFunction * @property Smarty_Internal_Runtime_TplFunction $_tplFunction
* @property Smarty_Internal_Runtime_Foreach $_foreach * @property Smarty_Internal_Runtime_Foreach $_foreach
* @property Smarty_Internal_Runtime_WriteFile $_writeFile * @property Smarty_Internal_Runtime_WriteFile $_writeFile
* @property Smarty_Internal_Runtime_CodeFrame $_codeFrame * @property Smarty_Internal_Runtime_CodeFrame $_codeFrame
* @property Smarty_Internal_Runtime_FilterHandler $_filterHandler * @property Smarty_Internal_Runtime_FilterHandler $_filterHandler
* @property Smarty_Internal_Runtime_GetIncludePath $_getIncludePath * @property Smarty_Internal_Runtime_GetIncludePath $_getIncludePath
* @property Smarty_Internal_Runtime_UpdateScope $_updateScope * @property Smarty_Internal_Runtime_UpdateScope $_updateScope
* @property Smarty_Internal_Runtime_CacheModify $_cacheModify * @property Smarty_Internal_Runtime_CacheModify $_cacheModify
* @property Smarty_Internal_Runtime_UpdateCache $_updateCache * @property Smarty_Internal_Runtime_UpdateCache $_updateCache
* @property Smarty_Internal_Method_GetTemplateVars $getTemplateVars * @property Smarty_Internal_Method_GetTemplateVars $getTemplateVars
* @property Smarty_Internal_Method_Append $append * @property Smarty_Internal_Method_Append $append
* @property Smarty_Internal_Method_AppendByRef $appendByRef * @property Smarty_Internal_Method_AppendByRef $appendByRef
* @property Smarty_Internal_Method_AssignGlobal $assignGlobal * @property Smarty_Internal_Method_AssignGlobal $assignGlobal
* @property Smarty_Internal_Method_AssignByRef $assignByRef * @property Smarty_Internal_Method_AssignByRef $assignByRef
* @property Smarty_Internal_Method_LoadFilter $loadFilter * @property Smarty_Internal_Method_LoadFilter $loadFilter
* @property Smarty_Internal_Method_LoadPlugin $loadPlugin * @property Smarty_Internal_Method_LoadPlugin $loadPlugin
* @property Smarty_Internal_Method_RegisterFilter $registerFilter * @property Smarty_Internal_Method_RegisterFilter $registerFilter
* @property Smarty_Internal_Method_RegisterObject $registerObject * @property Smarty_Internal_Method_RegisterObject $registerObject
* @property Smarty_Internal_Method_RegisterPlugin $registerPlugin * @property Smarty_Internal_Method_RegisterPlugin $registerPlugin
*/ */
class Smarty_Internal_Extension_Handler class Smarty_Internal_Extension_Handler
{ {
@@ -43,8 +43,8 @@ class Smarty_Internal_Extension_Handler
* @var array * @var array
*/ */
private $_property_info = array('AutoloadFilters' => 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0, private $_property_info = array('AutoloadFilters' => 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0,
'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0, 'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0,
'TemplateVars' => 0,);# 'TemplateVars' => 0,);#
private $resolvedProperties = array(); private $resolvedProperties = array();
@@ -65,22 +65,22 @@ class Smarty_Internal_Extension_Handler
if (!isset($smarty->ext->$name)) { if (!isset($smarty->ext->$name)) {
$class = 'Smarty_Internal_Method_' . ucfirst($name); $class = 'Smarty_Internal_Method_' . ucfirst($name);
if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) { if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) {
if (!isset($this->_property_info[$prop = $match[2]])) { if (!isset($this->_property_info[ $prop = $match[ 2 ] ])) {
// convert camel case to underscored name // convert camel case to underscored name
$this->resolvedProperties[$prop] = $pn = strtolower(join('_', $this->resolvedProperties[ $prop ] = $pn = strtolower(join('_',
preg_split('/([A-Z][^A-Z]*)/', $prop, - 1, preg_split('/([A-Z][^A-Z]*)/', $prop,
PREG_SPLIT_NO_EMPTY | - 1, PREG_SPLIT_NO_EMPTY |
PREG_SPLIT_DELIM_CAPTURE))); PREG_SPLIT_DELIM_CAPTURE)));
$this->_property_info[$prop] = property_exists($data, $pn) ? 1 : $this->_property_info[ $prop ] = property_exists($data, $pn) ? 1 :
($data->_objType == 2 && property_exists($smarty, $pn) ? 2 : 0); ($data->_objType == 2 && property_exists($smarty, $pn) ? 2 : 0);
} }
if ($this->_property_info[$prop]) { if ($this->_property_info[ $prop ]) {
$pn = $this->resolvedProperties[$prop]; $pn = $this->resolvedProperties[ $prop ];
if ($match[1] == 'get') { if ($match[ 1 ] == 'get') {
return $this->_property_info[$prop] == 1 ? $data->$pn : $data->smarty->$pn; return $this->_property_info[ $prop ] == 1 ? $data->$pn : $data->smarty->$pn;
} else { } else {
return $this->_property_info[$prop] == 1 ? $data->$pn = $args[0] : return $this->_property_info[ $prop ] == 1 ? $data->$pn = $args[ 0 ] :
$data->smarty->$pn = $args[0]; $data->smarty->$pn = $args[ 0 ];
} }
} elseif (!class_exists($class)) { } elseif (!class_exists($class)) {
throw new SmartyException("property '$pn' does not exist."); throw new SmartyException("property '$pn' does not exist.");
@@ -93,7 +93,7 @@ class Smarty_Internal_Extension_Handler
$callback = array($smarty->ext->$name, $name); $callback = array($smarty->ext->$name, $name);
} }
array_unshift($args, $data); 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($callback, $args);
} }
return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), $args); return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), $args);

View File

@@ -31,18 +31,19 @@ class Smarty_Internal_Method_AddAutoloadFilters extends Smarty_Internal_Method_S
$smarty = isset($obj->smarty) ? $obj->smarty : $obj; $smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if ($type !== null) { if ($type !== null) {
$this->_checkFilterType($type); $this->_checkFilterType($type);
if (!empty($smarty->autoload_filters[$type])) { if (!empty($smarty->autoload_filters[ $type ])) {
$smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $filters); $smarty->autoload_filters[ $type ] = array_merge($smarty->autoload_filters[ $type ], (array) $filters);
} else { } else {
$smarty->autoload_filters[$type] = (array) $filters; $smarty->autoload_filters[ $type ] = (array) $filters;
} }
} else { } else {
foreach ((array) $filters as $type => $value) { foreach ((array) $filters as $type => $value) {
$this->_checkFilterType($type); $this->_checkFilterType($type);
if (!empty($smarty->autoload_filters[$type])) { if (!empty($smarty->autoload_filters[ $type ])) {
$smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $value); $smarty->autoload_filters[ $type ] =
array_merge($smarty->autoload_filters[ $type ], (array) $value);
} else { } else {
$smarty->autoload_filters[$type] = (array) $value; $smarty->autoload_filters[ $type ] = (array) $value;
} }
} }
} }

View File

@@ -44,25 +44,25 @@ class Smarty_Internal_Method_Append
} }
} else { } else {
if ($tpl_var != '' && isset($value)) { if ($tpl_var != '' && isset($value)) {
if (!isset($data->tpl_vars[$tpl_var])) { if (!isset($data->tpl_vars[ $tpl_var ])) {
$tpl_var_inst = $data->ext->getTemplateVars->_getVariable($data, $tpl_var, null, true, false); $tpl_var_inst = $data->ext->getTemplateVars->_getVariable($data, $tpl_var, null, true, false);
if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { if ($tpl_var_inst instanceof Smarty_Undefined_Variable) {
$data->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); $data->tpl_vars[ $tpl_var ] = new Smarty_Variable(null, $nocache);
} else { } else {
$data->tpl_vars[$tpl_var] = clone $tpl_var_inst; $data->tpl_vars[ $tpl_var ] = clone $tpl_var_inst;
} }
} }
if (!(is_array($data->tpl_vars[$tpl_var]->value) || if (!(is_array($data->tpl_vars[ $tpl_var ]->value) ||
$data->tpl_vars[$tpl_var]->value instanceof ArrayAccess) $data->tpl_vars[ $tpl_var ]->value instanceof ArrayAccess)
) { ) {
settype($data->tpl_vars[$tpl_var]->value, 'array'); settype($data->tpl_vars[ $tpl_var ]->value, 'array');
} }
if ($merge && is_array($value)) { if ($merge && is_array($value)) {
foreach ($value as $_mkey => $_mval) { foreach ($value as $_mkey => $_mval) {
$data->tpl_vars[$tpl_var]->value[$_mkey] = $_mval; $data->tpl_vars[ $tpl_var ]->value[ $_mkey ] = $_mval;
} }
} else { } else {
$data->tpl_vars[$tpl_var]->value[] = $value; $data->tpl_vars[ $tpl_var ]->value[] = $value;
} }
} }
if ($data->_objType == 2 && $data->scope) { if ($data->_objType == 2 && $data->scope) {

View File

@@ -28,18 +28,18 @@ class Smarty_Internal_Method_AppendByRef
public static function appendByRef(Smarty_Internal_Data $data, $tpl_var, &$value, $merge = false) public static function appendByRef(Smarty_Internal_Data $data, $tpl_var, &$value, $merge = false)
{ {
if ($tpl_var != '' && isset($value)) { if ($tpl_var != '' && isset($value)) {
if (!isset($data->tpl_vars[$tpl_var])) { if (!isset($data->tpl_vars[ $tpl_var ])) {
$data->tpl_vars[$tpl_var] = new Smarty_Variable(); $data->tpl_vars[ $tpl_var ] = new Smarty_Variable();
} }
if (!is_array($data->tpl_vars[$tpl_var]->value)) { if (!is_array($data->tpl_vars[ $tpl_var ]->value)) {
settype($data->tpl_vars[$tpl_var]->value, 'array'); settype($data->tpl_vars[ $tpl_var ]->value, 'array');
} }
if ($merge && is_array($value)) { if ($merge && is_array($value)) {
foreach ($value as $_key => $_val) { foreach ($value as $_key => $_val) {
$data->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key]; $data->tpl_vars[ $tpl_var ]->value[ $_key ] = &$value[ $_key ];
} }
} else { } else {
$data->tpl_vars[$tpl_var]->value[] = &$value; $data->tpl_vars[ $tpl_var ]->value[] = &$value;
} }
if ($data->_objType == 2 && $data->scope) { if ($data->_objType == 2 && $data->scope) {
$data->ext->_updateScope->updateScope($data, $tpl_var); $data->ext->_updateScope->updateScope($data, $tpl_var);

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