mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 18:04:26 +02:00
- reformating for PSR-2 coding standards https://github.com/smarty-php/smarty/pull/483
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
===== 3.1.33-dev-9 =====
|
||||
===== 3.1.33-dev-10 =====
|
||||
31.08.2018
|
||||
- reformating for PSR-2 coding standards https://github.com/smarty-php/smarty/pull/483
|
||||
|
||||
- bugfix on Windows absolute filepathes did fail if the drive letter was followed by a linux DIRECTORY_SEPARATOR
|
||||
like C:/ at Smarty > 3.1.33-dev-5 https://github.com/smarty-php/smarty/issues/451
|
||||
|
||||
|
@@ -4,31 +4,32 @@
|
||||
*
|
||||
* @package Example-application
|
||||
*/
|
||||
|
||||
require '../libs/Smarty.class.php';
|
||||
|
||||
$smarty = new Smarty;
|
||||
|
||||
//$smarty->force_compile = true;
|
||||
$smarty->debugging = true;
|
||||
$smarty->caching = true;
|
||||
$smarty->cache_lifetime = 120;
|
||||
|
||||
$smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true);
|
||||
$smarty->assign("FirstName", array("John", "Mary", "James", "Henry"));
|
||||
$smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case"));
|
||||
$smarty->assign(
|
||||
"Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"), array("I", "J", "K", "L"),
|
||||
array("M", "N", "O", "P"))
|
||||
"Class",
|
||||
array(
|
||||
array("A", "B", "C", "D"),
|
||||
array("E", "F", "G", "H"),
|
||||
array("I", "J", "K", "L"),
|
||||
array("M", "N", "O", "P")
|
||||
)
|
||||
);
|
||||
|
||||
$smarty->assign(
|
||||
"contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234"))
|
||||
"contacts",
|
||||
array(
|
||||
array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")
|
||||
)
|
||||
);
|
||||
|
||||
$smarty->assign("option_values", array("NY", "NE", "KS", "IA", "OK", "TX"));
|
||||
$smarty->assign("option_output", array("New York", "Nebraska", "Kansas", "Iowa", "Oklahoma", "Texas"));
|
||||
$smarty->assign("option_selected", "NE");
|
||||
|
||||
$smarty->display('index.tpl');
|
||||
|
@@ -39,7 +39,6 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
|
||||
foreach ($res as $k => $v) {
|
||||
$_res[ $k ] = $v;
|
||||
}
|
||||
|
||||
return $_res;
|
||||
}
|
||||
|
||||
@@ -56,7 +55,6 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
|
||||
foreach ($keys as $k => $v) {
|
||||
apc_store($k, $v, $expire);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -72,7 +70,6 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
|
||||
foreach ($keys as $k) {
|
||||
apc_delete($k);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -19,6 +19,9 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
|
||||
*/
|
||||
protected $memcache = null;
|
||||
|
||||
/**
|
||||
* Smarty_CacheResource_Memcache constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (class_exists('Memcached')) {
|
||||
@@ -50,7 +53,6 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
|
||||
foreach ($res as $k => $v) {
|
||||
$_res[ $lookup[ $k ] ] = $v;
|
||||
}
|
||||
|
||||
return $_res;
|
||||
}
|
||||
|
||||
@@ -68,7 +70,6 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
|
||||
$k = sha1($k);
|
||||
$this->memcache->set($k, $v, 0, $expire);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -85,7 +86,6 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
|
||||
$k = sha1($k);
|
||||
$this->memcache->delete($k);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -24,13 +24,24 @@
|
||||
*/
|
||||
class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
|
||||
{
|
||||
// PDO instance
|
||||
/**
|
||||
* @var \PDO
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var \PDOStatement
|
||||
*/
|
||||
protected $fetch;
|
||||
|
||||
/**
|
||||
* @var \PDOStatement
|
||||
*/
|
||||
protected $fetchTimestamp;
|
||||
|
||||
/**
|
||||
* @var \PDOStatement
|
||||
*/
|
||||
protected $save;
|
||||
|
||||
/**
|
||||
@@ -42,8 +53,7 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
|
||||
{
|
||||
try {
|
||||
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
} catch (PDOException $e) {
|
||||
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
|
||||
}
|
||||
$this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id');
|
||||
@@ -83,7 +93,8 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
|
||||
/**
|
||||
* Fetch cached content's modification timestamp from data source
|
||||
*
|
||||
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the complete cached content.
|
||||
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than
|
||||
* loading the complete cached content.
|
||||
*
|
||||
* @param string $id unique cache content identifier
|
||||
* @param string $name template name
|
||||
@@ -97,7 +108,6 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
|
||||
$this->fetchTimestamp->execute(array('id' => $id));
|
||||
$mtime = strtotime($this->fetchTimestamp->fetchColumn());
|
||||
$this->fetchTimestamp->closeCursor();
|
||||
|
||||
return $mtime;
|
||||
}
|
||||
|
||||
@@ -116,10 +126,12 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
|
||||
protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content)
|
||||
{
|
||||
$this->save->execute(
|
||||
array('id' => $id, 'name' => $name, 'cache_id' => $cache_id, 'compile_id' => $compile_id,
|
||||
'content' => $content,)
|
||||
array('id' => $id,
|
||||
'name' => $name,
|
||||
'cache_id' => $cache_id,
|
||||
'compile_id' => $compile_id,
|
||||
'content' => $content,)
|
||||
);
|
||||
|
||||
return !!$this->save->rowCount();
|
||||
}
|
||||
|
||||
@@ -139,8 +151,7 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
|
||||
if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) {
|
||||
// returning the number of deleted caches would require a second query to count them
|
||||
$query = $this->db->query('TRUNCATE TABLE output_cache');
|
||||
|
||||
return - 1;
|
||||
return -1;
|
||||
}
|
||||
// build the filter
|
||||
$where = array();
|
||||
@@ -158,12 +169,15 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
|
||||
}
|
||||
// equal test cache_id and match sub-groups
|
||||
if ($cache_id !== null) {
|
||||
$where[] = '(cache_id = ' . $this->db->quote($cache_id) . ' OR cache_id LIKE ' .
|
||||
$this->db->quote($cache_id . '|%') . ')';
|
||||
$where[] =
|
||||
'(cache_id = ' .
|
||||
$this->db->quote($cache_id) .
|
||||
' OR cache_id LIKE ' .
|
||||
$this->db->quote($cache_id . '|%') .
|
||||
')';
|
||||
}
|
||||
// run delete query
|
||||
$query = $this->db->query('DELETE FROM output_cache WHERE ' . join(' AND ', $where));
|
||||
|
||||
return $query->rowCount();
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,10 @@
|
||||
*/
|
||||
class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
{
|
||||
protected $fetchStatements = Array('default' => 'SELECT %2$s
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fetchStatements = array('default' => 'SELECT %2$s
|
||||
FROM %1$s
|
||||
WHERE 1
|
||||
AND id = :id
|
||||
@@ -53,6 +56,10 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
AND id = :id
|
||||
AND cache_id = :cache_id
|
||||
AND compile_id = :compile_id');
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $insertStatement = 'INSERT INTO %s
|
||||
|
||||
SET id = :id,
|
||||
@@ -70,25 +77,48 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
modified = CURRENT_TIMESTAMP,
|
||||
expire = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :expire SECOND),
|
||||
content = :content';
|
||||
protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s';
|
||||
protected $truncateStatement = 'TRUNCATE TABLE %s';
|
||||
protected $fetchColumns = 'modified, content';
|
||||
protected $fetchTimestampColumns = 'modified';
|
||||
protected $pdo, $table, $database;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*
|
||||
* @param PDO $pdo PDO : active connection
|
||||
* @param string $table : table (or view) name
|
||||
* @param string $database : optional - if table is located in another db
|
||||
*/
|
||||
/**
|
||||
* Smarty_CacheResource_Pdo constructor.
|
||||
* @var string
|
||||
*/
|
||||
protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $truncateStatement = 'TRUNCATE TABLE %s';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $fetchColumns = 'modified, content';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $fetchTimestampColumns = 'modified';
|
||||
|
||||
/**
|
||||
* @var \PDO
|
||||
*/
|
||||
protected $pdo;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* @var null
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \PDO $pdo
|
||||
* @param $table
|
||||
* @param null $database
|
||||
* @param PDO $pdo PDO : active connection
|
||||
* @param string $table : table (or view) name
|
||||
* @param string $database : optional - if table is located in another db
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
@@ -103,15 +133,15 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
$this->fillStatementsWithTableName();
|
||||
}
|
||||
|
||||
/*
|
||||
* Fills the table name into the statements.
|
||||
*
|
||||
* @return Current Instance
|
||||
* @access protected
|
||||
/**
|
||||
* Fills the table name into the statements.
|
||||
*
|
||||
* @return $this Current Instance
|
||||
* @access protected
|
||||
*/
|
||||
protected function fillStatementsWithTableName()
|
||||
{
|
||||
foreach ($this->fetchStatements AS &$statement) {
|
||||
foreach ($this->fetchStatements as &$statement) {
|
||||
$statement = sprintf($statement, $this->getTableName(), '%s');
|
||||
}
|
||||
$this->insertStatement = sprintf($this->insertStatement, $this->getTableName());
|
||||
@@ -120,31 +150,34 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
return $this;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the fetch statement, depending on what you specify
|
||||
*
|
||||
* @param string $columns : the column(s) name(s) you want to retrieve from the database
|
||||
* @param string $id unique cache content identifier
|
||||
* @param string|null $cache_id cache id
|
||||
* @param string|null $compile_id compile id
|
||||
* @access protected
|
||||
/**
|
||||
* Gets the fetch statement, depending on what you specify
|
||||
*
|
||||
* @param string $columns : the column(s) name(s) you want to retrieve from the database
|
||||
* @param string $id unique cache content identifier
|
||||
* @param string|null $cache_id cache id
|
||||
* @param string|null $compile_id compile id
|
||||
*
|
||||
* @access protected
|
||||
* @return \PDOStatement
|
||||
*/
|
||||
protected function getFetchStatement($columns, $id, $cache_id = null, $compile_id = null)
|
||||
{
|
||||
$args = array();
|
||||
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)) {
|
||||
$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)) {
|
||||
$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 {
|
||||
$query = $this->fetchStatements[ 'default' ] AND $args = Array('id' => $id);
|
||||
$query = $this->fetchStatements[ 'default' ] and $args = array('id' => $id);
|
||||
}
|
||||
$query = sprintf($query, $columns);
|
||||
$stmt = $this->pdo->prepare($query);
|
||||
foreach ($args AS $key => $value) {
|
||||
foreach ($args as $key => $value) {
|
||||
$stmt->bindValue($key, $value);
|
||||
}
|
||||
return $stmt;
|
||||
@@ -224,24 +257,26 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
return !!$stmt->rowCount();
|
||||
}
|
||||
|
||||
/*
|
||||
* Encodes the content before saving to database
|
||||
*
|
||||
* @param string $content
|
||||
* @return string $content
|
||||
* @access protected
|
||||
/**
|
||||
* Encodes the content before saving to database
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @return string $content
|
||||
* @access protected
|
||||
*/
|
||||
protected function inputContent($content)
|
||||
{
|
||||
return $content;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decodes the content before saving to database
|
||||
*
|
||||
* @param string $content
|
||||
* @return string $content
|
||||
* @access protected
|
||||
/**
|
||||
* Decodes the content before saving to database
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @return string $content
|
||||
* @access protected
|
||||
*/
|
||||
protected function outputContent($content)
|
||||
{
|
||||
@@ -254,7 +289,7 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
* @param string|null $name template name
|
||||
* @param string|null $cache_id cache id
|
||||
* @param string|null $compile_id compile id
|
||||
* @param integer|null|-1 $exp_time seconds till expiration or null
|
||||
* @param integer|null|-1 $exp_time seconds till expiration or null
|
||||
*
|
||||
* @return integer number of deleted caches
|
||||
* @access protected
|
||||
@@ -263,33 +298,37 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
{
|
||||
// delete the whole cache
|
||||
if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) {
|
||||
// returning the number of deleted caches would require a second query to count them
|
||||
// returning the number of deleted caches would require a second query to count them
|
||||
$this->pdo->query($this->truncateStatement);
|
||||
return -1;
|
||||
}
|
||||
// build the filter
|
||||
// build the filter
|
||||
$where = array();
|
||||
// equal test name
|
||||
// equal test name
|
||||
if ($name !== null) {
|
||||
$where[] = 'name = ' . $this->pdo->quote($name);
|
||||
}
|
||||
// equal test cache_id and match sub-groups
|
||||
// equal test cache_id and match sub-groups
|
||||
if ($cache_id !== null) {
|
||||
$where[] = '(cache_id = ' . $this->pdo->quote($cache_id) . ' OR cache_id LIKE ' .
|
||||
$this->pdo->quote($cache_id . '|%') . ')';
|
||||
$where[] =
|
||||
'(cache_id = ' .
|
||||
$this->pdo->quote($cache_id) .
|
||||
' OR cache_id LIKE ' .
|
||||
$this->pdo->quote($cache_id . '|%') .
|
||||
')';
|
||||
}
|
||||
// equal test compile_id
|
||||
// equal test compile_id
|
||||
if ($compile_id !== null) {
|
||||
$where[] = 'compile_id = ' . $this->pdo->quote($compile_id);
|
||||
}
|
||||
// for clearing expired caches
|
||||
// for clearing expired caches
|
||||
if ($exp_time === Smarty::CLEAR_EXPIRED) {
|
||||
$where[] = 'expire < CURRENT_TIMESTAMP';
|
||||
} // range test expiration time
|
||||
elseif ($exp_time !== null) {
|
||||
$where[] = 'modified < DATE_SUB(NOW(), INTERVAL ' . intval($exp_time) . ' SECOND)';
|
||||
}
|
||||
// run delete query
|
||||
// run delete query
|
||||
$query = $this->pdo->query(sprintf($this->deleteStatement, join(' AND ', $where)));
|
||||
return $query->rowCount();
|
||||
}
|
||||
@@ -305,4 +344,3 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
return (is_null($this->database)) ? "`{$this->table}`" : "`{$this->database}`.`{$this->table}`";
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
require_once 'cacheresource.pdo.php';
|
||||
|
||||
/**
|
||||
* PDO Cache Handler with GZIP support
|
||||
@@ -11,33 +12,31 @@
|
||||
* @require Smarty_CacheResource_Pdo class
|
||||
* @author Beno!t POLASZEK - 2014
|
||||
*/
|
||||
require_once 'cacheresource.pdo.php';
|
||||
|
||||
class Smarty_CacheResource_Pdo_Gzip extends Smarty_CacheResource_Pdo
|
||||
{
|
||||
|
||||
/*
|
||||
* Encodes the content before saving to database
|
||||
*
|
||||
* @param string $content
|
||||
* @return string $content
|
||||
* @access protected
|
||||
/**
|
||||
* Encodes the content before saving to database
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @return string $content
|
||||
* @access protected
|
||||
*/
|
||||
protected function inputContent($content)
|
||||
{
|
||||
return gzdeflate($content);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decodes the content before saving to database
|
||||
*
|
||||
* @param string $content
|
||||
* @return string $content
|
||||
* @access protected
|
||||
/**
|
||||
* Decodes the content before saving to database
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @return string $content
|
||||
* @access protected
|
||||
*/
|
||||
protected function outputContent($content)
|
||||
{
|
||||
return gzinflate($content);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -32,15 +32,13 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
|
||||
$sources[ $s->uid ] = $s;
|
||||
$uid .= $s->filepath;
|
||||
$timestamp = $s->timestamp > $timestamp ? $s->timestamp : $timestamp;
|
||||
}
|
||||
catch (SmartyException $e) {
|
||||
} catch (SmartyException $e) {
|
||||
}
|
||||
}
|
||||
if (!$sources) {
|
||||
$source->exists = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$sources = array_reverse($sources, true);
|
||||
reset($sources);
|
||||
$s = current($sources);
|
||||
@@ -51,15 +49,14 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
|
||||
$source->timestamp = $timestamp;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Disable timestamp checks for extendsall resource.
|
||||
* The individual source components will be checked.
|
||||
*
|
||||
* @return bool
|
||||
* @return bool false
|
||||
*/
|
||||
public function checkTimestamps()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,20 +12,34 @@
|
||||
* PRIMARY KEY (`name`)
|
||||
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8;</pre>
|
||||
* Demo data:
|
||||
* <pre>INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');</pre>
|
||||
* <pre>INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello
|
||||
* world"}{$x}');</pre>
|
||||
*
|
||||
*
|
||||
* @package Resource-examples
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Resource_Mysql extends Smarty_Resource_Custom
|
||||
{
|
||||
// PDO instance
|
||||
/**
|
||||
* PDO instance
|
||||
*
|
||||
* @var \PDO
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
// prepared fetch() statement
|
||||
/**
|
||||
* prepared fetch() statement
|
||||
*
|
||||
* @var \PDOStatement
|
||||
*/
|
||||
protected $fetch;
|
||||
|
||||
// prepared fetchTimestamp() statement
|
||||
/**
|
||||
* prepared fetchTimestamp() statement
|
||||
*
|
||||
* @var \PDOStatement
|
||||
*/
|
||||
protected $mtime;
|
||||
|
||||
/**
|
||||
@@ -37,8 +51,7 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
|
||||
{
|
||||
try {
|
||||
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
} catch (PDOException $e) {
|
||||
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
|
||||
}
|
||||
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
|
||||
@@ -71,7 +84,8 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
|
||||
/**
|
||||
* Fetch a template's modification time from database
|
||||
*
|
||||
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source.
|
||||
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than
|
||||
* loading the comple template source.
|
||||
*
|
||||
* @param string $name template name
|
||||
*
|
||||
@@ -82,7 +96,6 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
|
||||
$this->mtime->execute(array('name' => $name));
|
||||
$mtime = $this->mtime->fetchColumn();
|
||||
$this->mtime->closeCursor();
|
||||
|
||||
return strtotime($mtime);
|
||||
}
|
||||
}
|
||||
|
@@ -14,17 +14,27 @@
|
||||
* PRIMARY KEY (`name`)
|
||||
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8;</pre>
|
||||
* Demo data:
|
||||
* <pre>INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');</pre>
|
||||
* <pre>INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello
|
||||
* world"}{$x}');</pre>
|
||||
*
|
||||
*
|
||||
* @package Resource-examples
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
|
||||
{
|
||||
// PDO instance
|
||||
/**
|
||||
* PDO instance
|
||||
*
|
||||
* @var \PDO
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
// prepared fetch() statement
|
||||
/**
|
||||
* prepared fetch() statement
|
||||
*
|
||||
* @var \PDOStatement
|
||||
*/
|
||||
protected $fetch;
|
||||
|
||||
/**
|
||||
@@ -36,8 +46,7 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
|
||||
{
|
||||
try {
|
||||
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
} catch (PDOException $e) {
|
||||
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
|
||||
}
|
||||
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
|
||||
|
@@ -54,7 +54,7 @@ class Smarty_Autoloader
|
||||
if (!defined('SMARTY_SPL_AUTOLOAD')) {
|
||||
define('SMARTY_SPL_AUTOLOAD', 0);
|
||||
}
|
||||
if (SMARTY_SPL_AUTOLOAD
|
||||
if (SMARTY_SPL_AUTOLOAD
|
||||
&& set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
|
||||
) {
|
||||
$registeredAutoLoadFunctions = spl_autoload_functions();
|
||||
|
@@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.33-dev-9';
|
||||
const SMARTY_VERSION = '3.1.33-dev-10';
|
||||
/**
|
||||
* define variable scopes
|
||||
*/
|
||||
@@ -650,18 +650,22 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $obsoleteProperties = array('resource_caching', 'template_resource_caching', 'direct_access_security',
|
||||
'_dir_perms', '_file_perms', 'plugin_search_order',
|
||||
'inheritance_merge_compiled_includes', 'resource_cache_mode',);
|
||||
protected $obsoleteProperties = array(
|
||||
'resource_caching', 'template_resource_caching', 'direct_access_security',
|
||||
'_dir_perms', '_file_perms', 'plugin_search_order',
|
||||
'inheritance_merge_compiled_includes', 'resource_cache_mode',
|
||||
);
|
||||
|
||||
/**
|
||||
* List of private properties which will call getter/setter on a direct access
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir',
|
||||
'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir',
|
||||
'cache_dir' => 'CacheDir',);
|
||||
protected $accessMap = array(
|
||||
'template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir',
|
||||
'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir',
|
||||
'cache_dir' => 'CacheDir',
|
||||
);
|
||||
|
||||
/**
|
||||
* Initialize new Smarty object
|
||||
@@ -1074,13 +1078,13 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
* @return string
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function _getTemplateId($template_name,
|
||||
$cache_id = null,
|
||||
$compile_id = null,
|
||||
$caching = null,
|
||||
Smarty_Internal_Template $template = null
|
||||
)
|
||||
{
|
||||
public function _getTemplateId(
|
||||
$template_name,
|
||||
$cache_id = null,
|
||||
$compile_id = null,
|
||||
$caching = null,
|
||||
Smarty_Internal_Template $template = null
|
||||
) {
|
||||
$template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
|
||||
$template_name;
|
||||
$cache_id = $cache_id === null ? $this->cache_id : $cache_id;
|
||||
@@ -1129,8 +1133,8 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
}
|
||||
}
|
||||
// normalize DIRECTORY_SEPARATOR
|
||||
$path = str_replace($nds[DIRECTORY_SEPARATOR], DIRECTORY_SEPARATOR, $path);
|
||||
$parts[ 'root' ] = str_replace($nds[DIRECTORY_SEPARATOR], DIRECTORY_SEPARATOR, $parts[ 'root' ]);
|
||||
$path = str_replace($nds[ DIRECTORY_SEPARATOR ], DIRECTORY_SEPARATOR, $path);
|
||||
$parts[ 'root' ] = str_replace($nds[ DIRECTORY_SEPARATOR ], DIRECTORY_SEPARATOR, $parts[ 'root' ]);
|
||||
do {
|
||||
$path = preg_replace(
|
||||
array('#[\\\\/]{2}#', '#[\\\\/][.][\\\\/]#', '#[\\\\/]([^\\\\/.]+)[\\\\/][.][.][\\\\/]#'),
|
||||
|
@@ -129,7 +129,11 @@ class SmartyBC extends Smarty
|
||||
* @throws SmartyException
|
||||
* @internal param array $block_functs list of methods that are block format
|
||||
*/
|
||||
public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true,
|
||||
public function register_object(
|
||||
$object,
|
||||
$object_impl,
|
||||
$allowed = array(),
|
||||
$smarty_args = true,
|
||||
$block_methods = array()
|
||||
) {
|
||||
settype($allowed, 'array');
|
||||
@@ -150,8 +154,8 @@ class SmartyBC extends Smarty
|
||||
/**
|
||||
* Registers block function to be used in templates
|
||||
*
|
||||
* @param string $block name of template block
|
||||
* @param string $block_impl PHP function to register
|
||||
* @param string $block name of template block
|
||||
* @param string $block_impl PHP function to register
|
||||
* @param bool $cacheable
|
||||
* @param mixed $cache_attrs
|
||||
*
|
||||
@@ -352,7 +356,7 @@ class SmartyBC extends Smarty
|
||||
/**
|
||||
* test to see if valid cache exists for this template
|
||||
*
|
||||
* @param string $tpl_file name of template file
|
||||
* @param string $tpl_file name of template file
|
||||
* @param string $cache_id
|
||||
* @param string $compile_id
|
||||
*
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
/**
|
||||
* This file is part of the Smarty package.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
@@ -7,8 +7,7 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*
|
||||
/**
|
||||
* Load and register Smarty Autoloader
|
||||
*/
|
||||
if (!class_exists('Smarty_Autoloader')) {
|
||||
|
@@ -113,10 +113,10 @@
|
||||
<div>
|
||||
{foreach $template_data as $template}
|
||||
<font color=brown>{$template.name}</font>
|
||||
<br> <span class="exectime">
|
||||
<br /> <span class="exectime">
|
||||
(compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"})
|
||||
</span>
|
||||
<br>
|
||||
<br />
|
||||
{/foreach}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -127,7 +127,7 @@
|
||||
{foreach $assigned_vars as $vars}
|
||||
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
|
||||
<td><h3><font color=blue>${$vars@key}</font></h3>
|
||||
{if isset($vars['nocache'])}<b>Nocache</b><br>{/if}
|
||||
{if isset($vars['nocache'])}<b>Nocache</b><br />{/if}
|
||||
{if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if}
|
||||
</td>
|
||||
<td><h3>Value</h3>{$vars['value']|debug_print_var:10:80 nofilter}</td>
|
||||
|
@@ -39,8 +39,12 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
|
||||
}
|
||||
if (Smarty::$_MBSTRING) {
|
||||
$template->_checkPlugins(
|
||||
array(array('function' => 'smarty_modifier_mb_wordwrap',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php'))
|
||||
array(
|
||||
array(
|
||||
'function' => 'smarty_modifier_mb_wordwrap',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
$style = null;
|
||||
@@ -83,10 +87,14 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
|
||||
// convert mult. spaces & special chars to single space
|
||||
$_paragraph =
|
||||
preg_replace(
|
||||
array('!\s+!' . Smarty::$_UTF8_MODIFIER,
|
||||
'!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER),
|
||||
array(' ',
|
||||
''),
|
||||
array(
|
||||
'!\s+!' . Smarty::$_UTF8_MODIFIER,
|
||||
'!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER
|
||||
),
|
||||
array(
|
||||
' ',
|
||||
''
|
||||
),
|
||||
$_paragraph
|
||||
);
|
||||
// indent first line
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {counter} function plugin
|
||||
* Type: function
|
||||
@@ -24,50 +23,40 @@
|
||||
function smarty_function_counter($params, $template)
|
||||
{
|
||||
static $counters = array();
|
||||
|
||||
$name = (isset($params[ 'name' ])) ? $params[ 'name' ] : 'default';
|
||||
if (!isset($counters[ $name ])) {
|
||||
$counters[ $name ] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1);
|
||||
}
|
||||
$counter =& $counters[ $name ];
|
||||
|
||||
if (isset($params[ 'start' ])) {
|
||||
$counter[ 'start' ] = $counter[ 'count' ] = (int) $params[ 'start' ];
|
||||
$counter[ 'start' ] = $counter[ 'count' ] = (int)$params[ 'start' ];
|
||||
}
|
||||
|
||||
if (!empty($params[ 'assign' ])) {
|
||||
$counter[ 'assign' ] = $params[ 'assign' ];
|
||||
}
|
||||
|
||||
if (isset($counter[ 'assign' ])) {
|
||||
$template->assign($counter[ 'assign' ], $counter[ 'count' ]);
|
||||
}
|
||||
|
||||
if (isset($params[ 'print' ])) {
|
||||
$print = (bool) $params[ 'print' ];
|
||||
$print = (bool)$params[ 'print' ];
|
||||
} else {
|
||||
$print = empty($counter[ 'assign' ]);
|
||||
}
|
||||
|
||||
if ($print) {
|
||||
$retval = $counter[ 'count' ];
|
||||
} else {
|
||||
$retval = null;
|
||||
}
|
||||
|
||||
if (isset($params[ 'skip' ])) {
|
||||
$counter[ 'skip' ] = $params[ 'skip' ];
|
||||
}
|
||||
|
||||
if (isset($params[ 'direction' ])) {
|
||||
$counter[ 'direction' ] = $params[ 'direction' ];
|
||||
}
|
||||
|
||||
if ($counter[ 'direction' ] === 'down') {
|
||||
$counter[ 'count' ] -= $counter[ 'skip' ];
|
||||
} else {
|
||||
$counter[ 'count' ] += $counter[ 'skip' ];
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {cycle} function plugin
|
||||
* Type: function
|
||||
@@ -42,20 +41,16 @@
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
|
||||
function smarty_function_cycle($params, $template)
|
||||
{
|
||||
static $cycle_vars;
|
||||
|
||||
$name = (empty($params[ 'name' ])) ? 'default' : $params[ 'name' ];
|
||||
$print = (isset($params[ 'print' ])) ? (bool) $params[ 'print' ] : true;
|
||||
$advance = (isset($params[ 'advance' ])) ? (bool) $params[ 'advance' ] : true;
|
||||
$reset = (isset($params[ 'reset' ])) ? (bool) $params[ 'reset' ] : false;
|
||||
|
||||
$print = (isset($params[ 'print' ])) ? (bool)$params[ 'print' ] : true;
|
||||
$advance = (isset($params[ 'advance' ])) ? (bool)$params[ 'advance' ] : true;
|
||||
$reset = (isset($params[ 'reset' ])) ? (bool)$params[ 'reset' ] : false;
|
||||
if (!isset($params[ 'values' ])) {
|
||||
if (!isset($cycle_vars[ $name ][ 'values' ])) {
|
||||
trigger_error('cycle: missing \'values\' parameter');
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -64,41 +59,34 @@ function smarty_function_cycle($params, $template)
|
||||
}
|
||||
$cycle_vars[ $name ][ 'values' ] = $params[ 'values' ];
|
||||
}
|
||||
|
||||
if (isset($params[ 'delimiter' ])) {
|
||||
$cycle_vars[ $name ][ 'delimiter' ] = $params[ 'delimiter' ];
|
||||
} elseif (!isset($cycle_vars[ $name ][ 'delimiter' ])) {
|
||||
$cycle_vars[ $name ][ 'delimiter' ] = ',';
|
||||
}
|
||||
|
||||
if (is_array($cycle_vars[ $name ][ 'values' ])) {
|
||||
$cycle_array = $cycle_vars[ $name ][ 'values' ];
|
||||
} else {
|
||||
$cycle_array = explode($cycle_vars[ $name ][ 'delimiter' ], $cycle_vars[ $name ][ 'values' ]);
|
||||
}
|
||||
|
||||
if (!isset($cycle_vars[ $name ][ 'index' ]) || $reset) {
|
||||
$cycle_vars[ $name ][ 'index' ] = 0;
|
||||
}
|
||||
|
||||
if (isset($params[ 'assign' ])) {
|
||||
$print = false;
|
||||
$template->assign($params[ 'assign' ], $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]);
|
||||
}
|
||||
|
||||
if ($print) {
|
||||
$retval = $cycle_array[ $cycle_vars[ $name ][ 'index' ] ];
|
||||
} else {
|
||||
$retval = null;
|
||||
}
|
||||
|
||||
if ($advance) {
|
||||
if ($cycle_vars[ $name ][ 'index' ] >= count($cycle_array) - 1) {
|
||||
$cycle_vars[ $name ][ 'index' ] = 0;
|
||||
} else {
|
||||
$cycle_vars[ $name ][ 'index' ] ++;
|
||||
$cycle_vars[ $name ][ 'index' ]++;
|
||||
}
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
@@ -45,8 +45,12 @@
|
||||
function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template)
|
||||
{
|
||||
$template->_checkPlugins(
|
||||
array(array('function' => 'smarty_function_escape_special_chars',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
|
||||
array(
|
||||
array(
|
||||
'function' => 'smarty_function_escape_special_chars',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
|
||||
)
|
||||
)
|
||||
);
|
||||
$name = 'checkbox';
|
||||
$values = null;
|
||||
@@ -137,6 +141,7 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
|
||||
break;
|
||||
}
|
||||
// omit break; to fall through!
|
||||
// no break
|
||||
default:
|
||||
if (!is_array($_val)) {
|
||||
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
|
||||
@@ -202,17 +207,17 @@ function smarty_function_html_checkboxes($params, Smarty_Internal_Template $temp
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_html_checkboxes_output($name,
|
||||
$value,
|
||||
$output,
|
||||
$selected,
|
||||
$extra,
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
$escape = true
|
||||
)
|
||||
{
|
||||
function smarty_function_html_checkboxes_output(
|
||||
$name,
|
||||
$value,
|
||||
$output,
|
||||
$selected,
|
||||
$extra,
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
$escape = true
|
||||
) {
|
||||
$_output = '';
|
||||
if (is_object($value)) {
|
||||
if (method_exists($value, '__toString')) {
|
||||
|
@@ -37,8 +37,12 @@
|
||||
function smarty_function_html_image($params, Smarty_Internal_Template $template)
|
||||
{
|
||||
$template->_checkPlugins(
|
||||
array(array('function' => 'smarty_function_escape_special_chars',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
|
||||
array(
|
||||
array(
|
||||
'function' => 'smarty_function_escape_special_chars',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
|
||||
)
|
||||
)
|
||||
);
|
||||
$alt = '';
|
||||
$file = '';
|
||||
@@ -63,8 +67,10 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template)
|
||||
if (!is_array($_val)) {
|
||||
$$_key = smarty_function_escape_special_chars($_val);
|
||||
} else {
|
||||
throw new SmartyException("html_image: extra attribute '{$_key}' cannot be an array",
|
||||
E_USER_NOTICE);
|
||||
throw new SmartyException(
|
||||
"html_image: extra attribute '{$_key}' cannot be an array",
|
||||
E_USER_NOTICE
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'link':
|
||||
@@ -76,8 +82,10 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template)
|
||||
if (!is_array($_val)) {
|
||||
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
|
||||
} else {
|
||||
throw new SmartyException("html_image: extra attribute '{$_key}' cannot be an array",
|
||||
E_USER_NOTICE);
|
||||
throw new SmartyException(
|
||||
"html_image: extra attribute '{$_key}' cannot be an array",
|
||||
E_USER_NOTICE
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@@ -37,8 +37,12 @@
|
||||
function smarty_function_html_options($params, Smarty_Internal_Template $template)
|
||||
{
|
||||
$template->_checkPlugins(
|
||||
array(array('function' => 'smarty_function_escape_special_chars',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
|
||||
array(
|
||||
array(
|
||||
'function' => 'smarty_function_escape_special_chars',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
|
||||
)
|
||||
)
|
||||
);
|
||||
$name = null;
|
||||
$values = null;
|
||||
@@ -113,6 +117,7 @@ function smarty_function_html_options($params, Smarty_Internal_Template $templat
|
||||
break;
|
||||
}
|
||||
// omit break; to fall through!
|
||||
// no break
|
||||
default:
|
||||
if (!is_array($_val)) {
|
||||
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
|
||||
|
@@ -45,8 +45,12 @@
|
||||
function smarty_function_html_radios($params, Smarty_Internal_Template $template)
|
||||
{
|
||||
$template->_checkPlugins(
|
||||
array(array('function' => 'smarty_function_escape_special_chars',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
|
||||
array(
|
||||
array(
|
||||
'function' => 'smarty_function_escape_special_chars',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
|
||||
)
|
||||
)
|
||||
);
|
||||
$name = 'radio';
|
||||
$values = null;
|
||||
@@ -120,6 +124,7 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
|
||||
break;
|
||||
}
|
||||
// omit break; to fall through!
|
||||
// no break
|
||||
default:
|
||||
if (!is_array($_val)) {
|
||||
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
|
||||
@@ -186,17 +191,17 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_html_radios_output($name,
|
||||
$value,
|
||||
$output,
|
||||
$selected,
|
||||
$extra,
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
$escape
|
||||
)
|
||||
{
|
||||
function smarty_function_html_radios_output(
|
||||
$name,
|
||||
$value,
|
||||
$output,
|
||||
$selected,
|
||||
$extra,
|
||||
$separator,
|
||||
$labels,
|
||||
$label_ids,
|
||||
$escape
|
||||
) {
|
||||
$_output = '';
|
||||
if (is_object($value)) {
|
||||
if (method_exists($value, '__toString')) {
|
||||
|
@@ -45,8 +45,12 @@
|
||||
function smarty_function_html_select_date($params, Smarty_Internal_Template $template)
|
||||
{
|
||||
$template->_checkPlugins(
|
||||
array(array('function' => 'smarty_function_escape_special_chars',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
|
||||
array(
|
||||
array(
|
||||
'function' => 'smarty_function_escape_special_chars',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
|
||||
)
|
||||
)
|
||||
);
|
||||
// generate timestamps used for month names only
|
||||
static $_month_timestamps = null;
|
||||
@@ -111,8 +115,12 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
|
||||
case 'time':
|
||||
if (!is_array($_value) && $_value !== null) {
|
||||
$template->_checkPlugins(
|
||||
array(array('function' => 'smarty_make_timestamp',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'))
|
||||
array(
|
||||
array(
|
||||
'function' => 'smarty_make_timestamp',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'
|
||||
)
|
||||
)
|
||||
);
|
||||
$time = smarty_make_timestamp($_value);
|
||||
}
|
||||
@@ -173,9 +181,11 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
|
||||
if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
|
||||
if (isset($params[ 'time' ][ $prefix . 'Year' ])) {
|
||||
// $_REQUEST[$field_array] given
|
||||
foreach (array('Y' => 'Year',
|
||||
'm' => 'Month',
|
||||
'd' => 'Day') as $_elementKey => $_elementName) {
|
||||
foreach (array(
|
||||
'Y' => 'Year',
|
||||
'm' => 'Month',
|
||||
'd' => 'Day'
|
||||
) as $_elementKey => $_elementName) {
|
||||
$_variableName = '_' . strtolower($_elementName);
|
||||
$$_variableName =
|
||||
isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
|
||||
@@ -183,9 +193,11 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
|
||||
}
|
||||
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Year' ])) {
|
||||
// $_REQUEST given
|
||||
foreach (array('Y' => 'Year',
|
||||
'm' => 'Month',
|
||||
'd' => 'Day') as $_elementKey => $_elementName) {
|
||||
foreach (array(
|
||||
'Y' => 'Year',
|
||||
'm' => 'Month',
|
||||
'd' => 'Day'
|
||||
) as $_elementKey => $_elementName) {
|
||||
$_variableName = '_' . strtolower($_elementName);
|
||||
$$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
|
||||
$params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
|
||||
@@ -205,8 +217,10 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
|
||||
}
|
||||
// make syntax "+N" or "-N" work with $start_year and $end_year
|
||||
// Note preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match) is slower than trim+substr
|
||||
foreach (array('start',
|
||||
'end') as $key) {
|
||||
foreach (array(
|
||||
'start',
|
||||
'end'
|
||||
) as $key) {
|
||||
$key .= '_year';
|
||||
$t = $$key;
|
||||
if ($t === null) {
|
||||
|
@@ -27,8 +27,12 @@
|
||||
function smarty_function_html_select_time($params, Smarty_Internal_Template $template)
|
||||
{
|
||||
$template->_checkPlugins(
|
||||
array(array('function' => 'smarty_function_escape_special_chars',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))
|
||||
array(
|
||||
array(
|
||||
'function' => 'smarty_function_escape_special_chars',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'
|
||||
)
|
||||
)
|
||||
);
|
||||
$prefix = 'Time_';
|
||||
$field_array = null;
|
||||
@@ -73,8 +77,12 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
|
||||
case 'time':
|
||||
if (!is_array($_value) && $_value !== null) {
|
||||
$template->_checkPlugins(
|
||||
array(array('function' => 'smarty_make_timestamp',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'))
|
||||
array(
|
||||
array(
|
||||
'function' => 'smarty_make_timestamp',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'
|
||||
)
|
||||
)
|
||||
);
|
||||
$time = smarty_make_timestamp($_value);
|
||||
}
|
||||
@@ -133,9 +141,11 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
|
||||
if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
|
||||
if (isset($params[ 'time' ][ $prefix . 'Hour' ])) {
|
||||
// $_REQUEST[$field_array] given
|
||||
foreach (array('H' => 'Hour',
|
||||
'i' => 'Minute',
|
||||
's' => 'Second') as $_elementKey => $_elementName) {
|
||||
foreach (array(
|
||||
'H' => 'Hour',
|
||||
'i' => 'Minute',
|
||||
's' => 'Second'
|
||||
) as $_elementKey => $_elementName) {
|
||||
$_variableName = '_' . strtolower($_elementName);
|
||||
$$_variableName =
|
||||
isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
|
||||
@@ -148,9 +158,11 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
|
||||
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
|
||||
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Hour' ])) {
|
||||
// $_REQUEST given
|
||||
foreach (array('H' => 'Hour',
|
||||
'i' => 'Minute',
|
||||
's' => 'Second') as $_elementKey => $_elementName) {
|
||||
foreach (array(
|
||||
'H' => 'Hour',
|
||||
'i' => 'Minute',
|
||||
's' => 'Second'
|
||||
) as $_elementKey => $_elementName) {
|
||||
$_variableName = '_' . strtolower($_elementName);
|
||||
$$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
|
||||
$params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
|
||||
@@ -325,10 +337,12 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
|
||||
'</select>';
|
||||
}
|
||||
$_html = '';
|
||||
foreach (array('_html_hours',
|
||||
'_html_minutes',
|
||||
'_html_seconds',
|
||||
'_html_meridian') as $k) {
|
||||
foreach (array(
|
||||
'_html_hours',
|
||||
'_html_minutes',
|
||||
'_html_seconds',
|
||||
'_html_meridian'
|
||||
) as $k) {
|
||||
if (isset($$k)) {
|
||||
if ($_html) {
|
||||
$_html .= $field_separator;
|
||||
|
@@ -79,6 +79,7 @@ function smarty_function_mailto($params)
|
||||
case 'extra':
|
||||
case 'text':
|
||||
$$var = $value;
|
||||
// no break
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {math} function plugin
|
||||
* Type: function
|
||||
@@ -25,66 +24,71 @@
|
||||
function smarty_function_math($params, $template)
|
||||
{
|
||||
static $_allowed_funcs =
|
||||
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, 'rand' => true,
|
||||
'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => 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,
|
||||
'rand' => true,
|
||||
'round' => true,
|
||||
'sin' => true,
|
||||
'sqrt' => true,
|
||||
'srand' => true,
|
||||
'tan' => true
|
||||
);
|
||||
// be sure equation parameter is present
|
||||
if (empty($params[ 'equation' ])) {
|
||||
trigger_error("math: missing equation parameter", E_USER_WARNING);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$equation = $params[ 'equation' ];
|
||||
|
||||
// make sure parenthesis are balanced
|
||||
if (substr_count($equation, '(') !== substr_count($equation, ')')) {
|
||||
trigger_error("math: unbalanced parenthesis", E_USER_WARNING);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// disallow backticks
|
||||
if (strpos($equation, '`') !== false) {
|
||||
trigger_error("math: backtick character not allowed in equation", E_USER_WARNING);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// also disallow dollar signs
|
||||
if (strpos($equation, '$') !== false) {
|
||||
trigger_error("math: dollar signs not allowed in equation", E_USER_WARNING);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($params as $key => $val) {
|
||||
if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') {
|
||||
// make sure value is not empty
|
||||
if (strlen($val) === 0) {
|
||||
trigger_error("math: parameter '{$key}' is empty", E_USER_WARNING);
|
||||
|
||||
return;
|
||||
}
|
||||
if (!is_numeric($val)) {
|
||||
trigger_error("math: parameter '{$key}' is not numeric", E_USER_WARNING);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// match all vars in equation, make sure all are passed
|
||||
preg_match_all('!(?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)!', $equation, $match);
|
||||
|
||||
foreach ($match[ 1 ] as $curr_var) {
|
||||
if ($curr_var && !isset($params[ $curr_var ]) && !isset($_allowed_funcs[ $curr_var ])) {
|
||||
trigger_error("math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'", E_USER_WARNING);
|
||||
|
||||
trigger_error(
|
||||
"math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'",
|
||||
E_USER_WARNING
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($params as $key => $val) {
|
||||
if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') {
|
||||
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
|
||||
@@ -92,7 +96,6 @@ function smarty_function_math($params, $template)
|
||||
}
|
||||
$smarty_math_result = null;
|
||||
eval("\$smarty_math_result = " . $equation . ";");
|
||||
|
||||
if (empty($params[ 'format' ])) {
|
||||
if (empty($params[ 'assign' ])) {
|
||||
return $smarty_math_result;
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty capitalize modifier plugin
|
||||
* Type: modifier
|
||||
@@ -31,20 +30,25 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
|
||||
// uppercase word breaks
|
||||
$upper_string = preg_replace_callback(
|
||||
"!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER,
|
||||
'smarty_mod_cap_mbconvert_cb', $string
|
||||
'smarty_mod_cap_mbconvert_cb',
|
||||
$string
|
||||
);
|
||||
}
|
||||
// check uc_digits case
|
||||
if (!$uc_digits) {
|
||||
if (preg_match_all(
|
||||
"!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches,
|
||||
"!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER,
|
||||
$string,
|
||||
$matches,
|
||||
PREG_OFFSET_CAPTURE
|
||||
)
|
||||
) {
|
||||
foreach ($matches[ 1 ] as $match) {
|
||||
$upper_string =
|
||||
substr_replace(
|
||||
$upper_string, mb_strtolower($match[ 0 ], Smarty::$_CHARSET), $match[ 1 ],
|
||||
$upper_string,
|
||||
mb_strtolower($match[ 0 ], Smarty::$_CHARSET),
|
||||
$match[ 1 ],
|
||||
strlen($match[ 0 ])
|
||||
);
|
||||
}
|
||||
@@ -52,12 +56,12 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
|
||||
}
|
||||
$upper_string =
|
||||
preg_replace_callback(
|
||||
"!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert2_cb',
|
||||
"!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER,
|
||||
'smarty_mod_cap_mbconvert2_cb',
|
||||
$upper_string
|
||||
);
|
||||
return $upper_string;
|
||||
}
|
||||
|
||||
// lowercase first
|
||||
if ($lc_rest) {
|
||||
$string = strtolower($string);
|
||||
@@ -65,13 +69,16 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
|
||||
// uppercase (including hyphenated words)
|
||||
$upper_string =
|
||||
preg_replace_callback(
|
||||
"!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst_cb',
|
||||
"!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER,
|
||||
'smarty_mod_cap_ucfirst_cb',
|
||||
$string
|
||||
);
|
||||
// check uc_digits case
|
||||
if (!$uc_digits) {
|
||||
if (preg_match_all(
|
||||
"!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches,
|
||||
"!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER,
|
||||
$string,
|
||||
$matches,
|
||||
PREG_OFFSET_CAPTURE
|
||||
)
|
||||
) {
|
||||
@@ -82,13 +89,14 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
|
||||
}
|
||||
}
|
||||
$upper_string = preg_replace_callback(
|
||||
"!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst2_cb',
|
||||
"!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER,
|
||||
'smarty_mod_cap_ucfirst2_cb',
|
||||
$upper_string
|
||||
);
|
||||
return $upper_string;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
*
|
||||
* Bug: create_function() use exhausts memory when used in long loops
|
||||
* Fix: use declared functions for callbacks instead of using create_function()
|
||||
@@ -105,6 +113,7 @@ function smarty_mod_cap_mbconvert_cb($matches)
|
||||
{
|
||||
return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 2 ]), MB_CASE_UPPER, Smarty::$_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $matches
|
||||
*
|
||||
@@ -114,6 +123,7 @@ function smarty_mod_cap_mbconvert2_cb($matches)
|
||||
{
|
||||
return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 3 ]), MB_CASE_UPPER, Smarty::$_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $matches
|
||||
*
|
||||
@@ -123,6 +133,7 @@ function smarty_mod_cap_ucfirst_cb($matches)
|
||||
{
|
||||
return stripslashes($matches[ 1 ]) . ucfirst(stripslashes($matches[ 2 ]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $matches
|
||||
*
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty date_format modifier plugin
|
||||
* Type: modifier
|
||||
@@ -51,20 +50,24 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
|
||||
}
|
||||
if ($formatter === 'strftime' || ($formatter === 'auto' && strpos($format, '%') !== false)) {
|
||||
if (Smarty::$_IS_WINDOWS) {
|
||||
$_win_from = array('%D',
|
||||
'%h',
|
||||
'%n',
|
||||
'%r',
|
||||
'%R',
|
||||
'%t',
|
||||
'%T');
|
||||
$_win_to = array('%m/%d/%y',
|
||||
'%b',
|
||||
"\n",
|
||||
'%I:%M:%S %p',
|
||||
'%H:%M',
|
||||
"\t",
|
||||
'%H:%M:%S');
|
||||
$_win_from = array(
|
||||
'%D',
|
||||
'%h',
|
||||
'%n',
|
||||
'%r',
|
||||
'%R',
|
||||
'%t',
|
||||
'%T'
|
||||
);
|
||||
$_win_to = array(
|
||||
'%m/%d/%y',
|
||||
'%b',
|
||||
"\n",
|
||||
'%I:%M:%S %p',
|
||||
'%H:%M',
|
||||
"\t",
|
||||
'%H:%M:%S'
|
||||
);
|
||||
if (strpos($format, '%e') !== false) {
|
||||
$_win_from[] = '%e';
|
||||
$_win_to[] = sprintf('%\' 2d', date('j', $timestamp));
|
||||
@@ -75,7 +78,6 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
|
||||
}
|
||||
$format = str_replace($_win_from, $_win_to, $format);
|
||||
}
|
||||
|
||||
return strftime($format, $timestamp);
|
||||
} else {
|
||||
return date($format, $timestamp);
|
||||
|
@@ -25,7 +25,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
|
||||
{
|
||||
$_replace = array("\n" => '\n', "\r" => '\r', "\t" => '\t');
|
||||
switch (gettype($var)) {
|
||||
case 'array' :
|
||||
case 'array':
|
||||
$results = '<b>Array (' . count($var) . ')</b>';
|
||||
if ($depth === $max) {
|
||||
break;
|
||||
@@ -37,7 +37,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
|
||||
$depth--;
|
||||
}
|
||||
break;
|
||||
case 'object' :
|
||||
case 'object':
|
||||
$object_vars = get_object_vars($var);
|
||||
$results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
|
||||
if (in_array($var, $objects)) {
|
||||
@@ -54,9 +54,9 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
|
||||
$depth--;
|
||||
}
|
||||
break;
|
||||
case 'boolean' :
|
||||
case 'NULL' :
|
||||
case 'resource' :
|
||||
case 'boolean':
|
||||
case 'NULL':
|
||||
case 'resource':
|
||||
if (true === $var) {
|
||||
$results = 'true';
|
||||
} elseif (false === $var) {
|
||||
@@ -68,11 +68,11 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
|
||||
}
|
||||
$results = '<i>' . $results . '</i>';
|
||||
break;
|
||||
case 'integer' :
|
||||
case 'float' :
|
||||
case 'integer':
|
||||
case 'float':
|
||||
$results = htmlspecialchars((string)$var);
|
||||
break;
|
||||
case 'string' :
|
||||
case 'string':
|
||||
$results = strtr($var, $_replace);
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if (mb_strlen($var, Smarty::$_CHARSET) > $length) {
|
||||
@@ -85,8 +85,8 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
|
||||
}
|
||||
$results = htmlspecialchars('"' . $results . '"', ENT_QUOTES, Smarty::$_CHARSET);
|
||||
break;
|
||||
case 'unknown type' :
|
||||
default :
|
||||
case 'unknown type':
|
||||
default:
|
||||
$results = strtr((string)$var, $_replace);
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if (mb_strlen($results, Smarty::$_CHARSET) > $length) {
|
||||
|
@@ -46,15 +46,20 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
|
||||
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
$string = str_replace(
|
||||
array('%%%SMARTY_START%%%',
|
||||
'%%%SMARTY_END%%%'),
|
||||
array('&',
|
||||
';'),
|
||||
array(
|
||||
'%%%SMARTY_START%%%',
|
||||
'%%%SMARTY_END%%%'
|
||||
),
|
||||
array(
|
||||
'&',
|
||||
';'
|
||||
),
|
||||
$string
|
||||
);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
// no break
|
||||
case 'htmlall':
|
||||
if (Smarty::$_MBSTRING) {
|
||||
// mb_convert_encoding ignores htmlspecialchars()
|
||||
@@ -71,10 +76,14 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
$string =
|
||||
str_replace(
|
||||
array('%%%SMARTY_START%%%',
|
||||
'%%%SMARTY_END%%%'),
|
||||
array('&',
|
||||
';'),
|
||||
array(
|
||||
'%%%SMARTY_START%%%',
|
||||
'%%%SMARTY_END%%%'
|
||||
),
|
||||
array(
|
||||
'&',
|
||||
';'
|
||||
),
|
||||
$string
|
||||
);
|
||||
return $string;
|
||||
@@ -93,15 +102,20 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
|
||||
$string = htmlentities($string, ENT_QUOTES, $char_set);
|
||||
$string = str_replace(
|
||||
array('%%%SMARTY_START%%%',
|
||||
'%%%SMARTY_END%%%'),
|
||||
array('&',
|
||||
';'),
|
||||
array(
|
||||
'%%%SMARTY_START%%%',
|
||||
'%%%SMARTY_END%%%'
|
||||
),
|
||||
array(
|
||||
'&',
|
||||
';'
|
||||
),
|
||||
$string
|
||||
);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
// no break
|
||||
case 'url':
|
||||
return rawurlencode($string);
|
||||
case 'urlpathinfo':
|
||||
@@ -164,12 +178,14 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
// escape quotes and backslashes, newlines, etc.
|
||||
return strtr(
|
||||
$string,
|
||||
array('\\' => '\\\\',
|
||||
"'" => "\\'",
|
||||
'"' => '\\"',
|
||||
"\r" => '\\r',
|
||||
"\n" => '\\n',
|
||||
'</' => '<\/')
|
||||
array(
|
||||
'\\' => '\\\\',
|
||||
"'" => "\\'",
|
||||
'"' => '\\"',
|
||||
"\r" => '\\r',
|
||||
"\n" => '\\n',
|
||||
'</' => '<\/'
|
||||
)
|
||||
);
|
||||
case 'mail':
|
||||
if (Smarty::$_MBSTRING) {
|
||||
@@ -180,19 +196,27 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
$is_loaded_2 = true;
|
||||
}
|
||||
return smarty_mb_str_replace(
|
||||
array('@',
|
||||
'.'),
|
||||
array(' [AT] ',
|
||||
' [DOT] '),
|
||||
array(
|
||||
'@',
|
||||
'.'
|
||||
),
|
||||
array(
|
||||
' [AT] ',
|
||||
' [DOT] '
|
||||
),
|
||||
$string
|
||||
);
|
||||
}
|
||||
// no MBString fallback
|
||||
return str_replace(
|
||||
array('@',
|
||||
'.'),
|
||||
array(' [AT] ',
|
||||
' [DOT] '),
|
||||
array(
|
||||
'@',
|
||||
'.'
|
||||
),
|
||||
array(
|
||||
' [AT] ',
|
||||
' [DOT] '
|
||||
),
|
||||
$string
|
||||
);
|
||||
case 'nonstd':
|
||||
|
@@ -11,7 +11,7 @@
|
||||
* Name: mb_wordwrap
|
||||
* Purpose: Wrap a string to a given number of characters
|
||||
*
|
||||
* @link http://php.net/manual/en/function.wordwrap.php for similarity
|
||||
* @link http://php.net/manual/en/function.wordwrap.php for similarity
|
||||
*
|
||||
* @param string $str the string to wrap
|
||||
* @param int $width the width of the output
|
||||
@@ -29,7 +29,6 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa
|
||||
$t = '';
|
||||
$_previous = false;
|
||||
$_space = false;
|
||||
|
||||
foreach ($tokens as $_token) {
|
||||
$token_length = mb_strlen($_token, Smarty::$_CHARSET);
|
||||
$_tokens = array($_token);
|
||||
@@ -43,18 +42,15 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($_tokens as $token) {
|
||||
$_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token);
|
||||
$token_length = mb_strlen($token, Smarty::$_CHARSET);
|
||||
$length += $token_length;
|
||||
|
||||
if ($length > $width) {
|
||||
// remove space before inserted break
|
||||
if ($_previous) {
|
||||
$t = mb_substr($t, 0, -1, Smarty::$_CHARSET);
|
||||
}
|
||||
|
||||
if (!$_space) {
|
||||
// add the break before the token
|
||||
if (!empty($t)) {
|
||||
@@ -71,6 +67,5 @@ function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = fa
|
||||
$t .= $token;
|
||||
}
|
||||
}
|
||||
|
||||
return $t;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty regex_replace modifier plugin
|
||||
* Type: modifier
|
||||
@@ -23,7 +22,7 @@
|
||||
*
|
||||
* @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)) {
|
||||
foreach ($search as $idx => $s) {
|
||||
@@ -32,7 +31,6 @@ function smarty_modifier_regex_replace($string, $search, $replace, $limit = - 1)
|
||||
} else {
|
||||
$search = _smarty_regex_replace_check($search);
|
||||
}
|
||||
|
||||
return preg_replace($search, $replace, $string, $limit);
|
||||
}
|
||||
|
||||
@@ -51,8 +49,7 @@ function _smarty_regex_replace_check($search)
|
||||
}
|
||||
// remove eval-modifier from $search
|
||||
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;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty replace modifier plugin
|
||||
* Type: modifier
|
||||
@@ -32,8 +31,7 @@ function smarty_modifier_replace($string, $search, $replace)
|
||||
}
|
||||
$is_loaded = true;
|
||||
}
|
||||
return smarty_mb_str_replace($search, $replace, $string);
|
||||
return smarty_mb_str_replace($search, $replace, $string);
|
||||
}
|
||||
|
||||
return str_replace($search, $replace, $string);
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty spacify modifier plugin
|
||||
* Type: modifier
|
||||
@@ -23,5 +22,5 @@
|
||||
function smarty_modifier_spacify($string, $spacify_char = ' ')
|
||||
{
|
||||
// well… what about charsets besides latin and UTF-8?
|
||||
return implode($spacify_char, preg_split('//' . Smarty::$_UTF8_MODIFIER, $string, - 1, PREG_SPLIT_NO_EMPTY));
|
||||
return implode($spacify_char, preg_split('//' . Smarty::$_UTF8_MODIFIER, $string, -1, PREG_SPLIT_NO_EMPTY));
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty truncate modifier plugin
|
||||
* Type: modifier
|
||||
@@ -30,27 +29,24 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
|
||||
if ($length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if (mb_strlen($string, Smarty::$_CHARSET) > $length) {
|
||||
$length -= min($length, mb_strlen($etc, Smarty::$_CHARSET));
|
||||
if (!$break_words && !$middle) {
|
||||
$string = preg_replace(
|
||||
'/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '',
|
||||
'/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER,
|
||||
'',
|
||||
mb_substr($string, 0, $length + 1, Smarty::$_CHARSET)
|
||||
);
|
||||
}
|
||||
if (!$middle) {
|
||||
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);
|
||||
mb_substr($string, -$length / 2, $length, Smarty::$_CHARSET);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
// no MBString fallback
|
||||
if (isset($string[ $length ])) {
|
||||
$length -= min($length, strlen($etc));
|
||||
@@ -60,9 +56,7 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
|
||||
if (!$middle) {
|
||||
return substr($string, 0, $length) . $etc;
|
||||
}
|
||||
|
||||
return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
|
||||
return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty cat modifier plugin
|
||||
* Type: modifier
|
||||
|
@@ -5,14 +5,14 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty count_characters modifier plugin
|
||||
* Type: modifier
|
||||
* Name: count_characters
|
||||
* Purpose: count the number of characters in a text
|
||||
*
|
||||
* @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual)
|
||||
* @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online
|
||||
* manual)
|
||||
* @author Uwe Tews
|
||||
*
|
||||
* @param array $params parameters
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty count_paragraphs modifier plugin
|
||||
* Type: modifier
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty count_sentences modifier plugin
|
||||
* Type: modifier
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty count_words modifier plugin
|
||||
* Type: modifier
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty default modifier plugin
|
||||
* Type: modifier
|
||||
@@ -25,11 +24,9 @@ function smarty_modifiercompiler_default($params)
|
||||
if (!isset($params[ 1 ])) {
|
||||
$params[ 1 ] = "''";
|
||||
}
|
||||
|
||||
array_shift($params);
|
||||
foreach ($params as $param) {
|
||||
$output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
@@ -25,8 +25,12 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
|
||||
static $_double_encode = null;
|
||||
static $is_loaded = false;
|
||||
$compiler->template->_checkPlugins(
|
||||
array(array('function' => 'smarty_literal_compiler_param',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'))
|
||||
array(
|
||||
array(
|
||||
'function' => 'smarty_literal_compiler_param',
|
||||
'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'
|
||||
)
|
||||
)
|
||||
);
|
||||
if ($_double_encode === null) {
|
||||
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
|
||||
@@ -48,6 +52,7 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
|
||||
} else {
|
||||
// fall back to modifier.escape.php
|
||||
}
|
||||
// no break
|
||||
case 'htmlall':
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if ($_double_encode) {
|
||||
@@ -74,6 +79,7 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
|
||||
} else {
|
||||
// fall back to modifier.escape.php
|
||||
}
|
||||
// no break
|
||||
case 'url':
|
||||
return 'rawurlencode(' . $params[ 0 ] . ')';
|
||||
case 'urlpathinfo':
|
||||
@@ -87,8 +93,7 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
|
||||
$params[ 0 ] .
|
||||
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))';
|
||||
}
|
||||
}
|
||||
catch (SmartyException $e) {
|
||||
} catch (SmartyException $e) {
|
||||
// pass through to regular plugin fallback
|
||||
}
|
||||
// could not optimize |escape call, so fallback to regular plugin
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty from_charset modifier plugin
|
||||
* Type: modifier
|
||||
@@ -24,10 +23,8 @@ function smarty_modifiercompiler_from_charset($params)
|
||||
// FIXME: (rodneyrehm) shouldn't this throw an error?
|
||||
return $params[ 0 ];
|
||||
}
|
||||
|
||||
if (!isset($params[ 1 ])) {
|
||||
$params[ 1 ] = '"ISO-8859-1"';
|
||||
}
|
||||
|
||||
return 'mb_convert_encoding(' . $params[ 0 ] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[ 1 ] . ')';
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty indent modifier plugin
|
||||
* Type: modifier
|
||||
@@ -19,7 +18,6 @@
|
||||
*
|
||||
* @return string with compiled code
|
||||
*/
|
||||
|
||||
function smarty_modifiercompiler_indent($params)
|
||||
{
|
||||
if (!isset($params[ 1 ])) {
|
||||
@@ -28,6 +26,5 @@ function smarty_modifiercompiler_indent($params)
|
||||
if (!isset($params[ 2 ])) {
|
||||
$params[ 2 ] = "' '";
|
||||
}
|
||||
|
||||
return 'preg_replace(\'!^!m\',str_repeat(' . $params[ 2 ] . ',' . $params[ 1 ] . '),' . $params[ 0 ] . ')';
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty lower modifier plugin
|
||||
* Type: modifier
|
||||
@@ -20,7 +19,6 @@
|
||||
*
|
||||
* @return string with compiled code
|
||||
*/
|
||||
|
||||
function smarty_modifiercompiler_lower($params)
|
||||
{
|
||||
if (Smarty::$_MBSTRING) {
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty noprint modifier plugin
|
||||
* Type: modifier
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty string_format modifier plugin
|
||||
* Type: modifier
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty strip modifier plugin
|
||||
* Type: modifier
|
||||
@@ -22,12 +21,10 @@
|
||||
*
|
||||
* @return string with compiled code
|
||||
*/
|
||||
|
||||
function smarty_modifiercompiler_strip($params)
|
||||
{
|
||||
if (!isset($params[ 1 ])) {
|
||||
$params[ 1 ] = "' '";
|
||||
}
|
||||
|
||||
return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})";
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty strip_tags modifier plugin
|
||||
* Type: modifier
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty to_charset modifier plugin
|
||||
* Type: modifier
|
||||
@@ -24,10 +23,8 @@ function smarty_modifiercompiler_to_charset($params)
|
||||
// FIXME: (rodneyrehm) shouldn't this throw an error?
|
||||
return $params[ 0 ];
|
||||
}
|
||||
|
||||
if (!isset($params[ 1 ])) {
|
||||
$params[ 1 ] = '"ISO-8859-1"';
|
||||
}
|
||||
|
||||
return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 1 ] . ', "' . addslashes(Smarty::$_CHARSET) . '")';
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty upper modifier plugin
|
||||
* Type: modifier
|
||||
|
@@ -14,7 +14,7 @@
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual)
|
||||
* @author Uwe Tews
|
||||
*
|
||||
* @param array $params parameters
|
||||
* @param array $params parameters
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler
|
||||
*
|
||||
* @return string with compiled code
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFilter
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty trimwhitespace outputfilter plugin
|
||||
* Trim unnecessary whitespace from HTML markup.
|
||||
@@ -22,13 +21,13 @@ function smarty_outputfilter_trimwhitespace($source)
|
||||
$store = array();
|
||||
$_store = 0;
|
||||
$_offset = 0;
|
||||
|
||||
// Unify Line-Breaks to \n
|
||||
$source = preg_replace('/\015\012|\015|\012/', "\n", $source);
|
||||
|
||||
// capture Internet Explorer and KnockoutJS Conditional Comments
|
||||
if (preg_match_all(
|
||||
'#<!--((\[[^\]]+\]>.*?<!\[[^\]]+\])|(\s*/?ko\s+.+))-->#is', $source, $matches,
|
||||
'#<!--((\[[^\]]+\]>.*?<!\[[^\]]+\])|(\s*/?ko\s+.+))-->#is',
|
||||
$source,
|
||||
$matches,
|
||||
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
|
||||
)
|
||||
) {
|
||||
@@ -37,21 +36,20 @@ function smarty_outputfilter_trimwhitespace($source)
|
||||
$_length = strlen($match[ 0 ][ 0 ]);
|
||||
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
|
||||
$source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
|
||||
|
||||
$_offset += $_length - strlen($replace);
|
||||
$_store ++;
|
||||
$_store++;
|
||||
}
|
||||
}
|
||||
|
||||
// Strip all HTML-Comments
|
||||
// yes, even the ones in <script> - see http://stackoverflow.com/a/808850/515124
|
||||
$source = preg_replace('#<!--.*?-->#ms', '', $source);
|
||||
|
||||
// capture html elements not to be messed with
|
||||
$_offset = 0;
|
||||
if (preg_match_all(
|
||||
'#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is',
|
||||
$source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER
|
||||
$source,
|
||||
$matches,
|
||||
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
|
||||
)
|
||||
) {
|
||||
foreach ($matches as $match) {
|
||||
@@ -59,37 +57,33 @@ function smarty_outputfilter_trimwhitespace($source)
|
||||
$_length = strlen($match[ 0 ][ 0 ]);
|
||||
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
|
||||
$source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
|
||||
|
||||
$_offset += $_length - strlen($replace);
|
||||
$_store ++;
|
||||
$_store++;
|
||||
}
|
||||
}
|
||||
|
||||
$expressions = array(// 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
|
||||
'#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
|
||||
'#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
|
||||
// remove spaces between attributes (but not in attribute values!)
|
||||
'#(([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.
|
||||
// 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);
|
||||
// note: for some very weird reason trim() seems to remove spaces inside attributes.
|
||||
// maybe a \0 byte or something is interfering?
|
||||
// $source = trim( $source );
|
||||
|
||||
$_offset = 0;
|
||||
if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
|
||||
foreach ($matches as $match) {
|
||||
$_length = strlen($match[ 0 ][ 0 ]);
|
||||
$replace = $store[ $match[ 1 ][ 0 ] ];
|
||||
$source = substr_replace($source, $replace, $match[ 0 ][ 1 ] + $_offset, $_length);
|
||||
|
||||
$_offset += strlen($replace) - $_length;
|
||||
$_store ++;
|
||||
$_store++;
|
||||
}
|
||||
}
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsShared
|
||||
*/
|
||||
|
||||
/**
|
||||
* escape_special_chars common function
|
||||
* Function: smarty_function_escape_special_chars
|
||||
@@ -29,6 +28,5 @@ function smarty_function_escape_special_chars($string)
|
||||
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsShared
|
||||
*/
|
||||
|
||||
/**
|
||||
* evaluate compiler parameter
|
||||
*
|
||||
@@ -30,9 +29,7 @@ function smarty_literal_compiler_param($params, $index, $default = null)
|
||||
'] is not a literal and is thus not evaluatable at compile time'
|
||||
);
|
||||
}
|
||||
|
||||
$t = null;
|
||||
eval("\$t = " . $params[ $index ] . ";");
|
||||
|
||||
return $t;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsShared
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function: smarty_make_timestamp
|
||||
* Purpose: used by other smarty functions to make a timestamp from a string.
|
||||
@@ -21,27 +20,30 @@ function smarty_make_timestamp($string)
|
||||
if (empty($string)) {
|
||||
// use "now":
|
||||
return time();
|
||||
} elseif ($string instanceof DateTime
|
||||
|| (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)
|
||||
} elseif ($string instanceof DateTime
|
||||
|| (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)
|
||||
) {
|
||||
return (int) $string->format('U'); // PHP 5.2 BC
|
||||
return (int)$string->format('U'); // PHP 5.2 BC
|
||||
} elseif (strlen($string) === 14 && ctype_digit($string)) {
|
||||
// it is mysql timestamp format of YYYYMMDDHHMMSS?
|
||||
return mktime(
|
||||
substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), substr($string, 4, 2),
|
||||
substr($string, 6, 2), substr($string, 0, 4)
|
||||
substr($string, 8, 2),
|
||||
substr($string, 10, 2),
|
||||
substr($string, 12, 2),
|
||||
substr($string, 4, 2),
|
||||
substr($string, 6, 2),
|
||||
substr($string, 0, 4)
|
||||
);
|
||||
} elseif (is_numeric($string)) {
|
||||
// it is a numeric string, we handle it as timestamp
|
||||
return (int) $string;
|
||||
return (int)$string;
|
||||
} else {
|
||||
// strtotime should handle it
|
||||
$time = strtotime($string);
|
||||
if ($time === - 1 || $time === false) {
|
||||
if ($time === -1 || $time === false) {
|
||||
// strtotime() was not able to parse $string, use "now":
|
||||
return time();
|
||||
}
|
||||
|
||||
return $time;
|
||||
}
|
||||
}
|
||||
|
@@ -5,11 +5,10 @@
|
||||
* @package Smarty
|
||||
* @subpackage PluginsShared
|
||||
*/
|
||||
|
||||
/**
|
||||
* convert characters to their decimal unicode equivalents
|
||||
*
|
||||
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
|
||||
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
|
||||
*
|
||||
* @param string $string characters to calculate unicode of
|
||||
* @param string $encoding encoding of $string, if null mb_internal_encoding() is used
|
||||
@@ -24,14 +23,13 @@ function smarty_mb_to_unicode($string, $encoding = null)
|
||||
} else {
|
||||
$expanded = mb_convert_encoding($string, 'UTF-32BE');
|
||||
}
|
||||
|
||||
return unpack('N*', $expanded);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert unicodes to the character of given encoding
|
||||
*
|
||||
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
|
||||
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
|
||||
*
|
||||
* @param integer|array $unicode single unicode or list of unicodes to convert
|
||||
* @param string $encoding encoding of returned string, if null mb_internal_encoding() is used
|
||||
@@ -45,10 +43,9 @@ function smarty_mb_from_unicode($unicode, $encoding = null)
|
||||
if (!$encoding) {
|
||||
$encoding = mb_internal_encoding();
|
||||
}
|
||||
foreach ((array) $unicode as $utf32be) {
|
||||
foreach ((array)$unicode as $utf32be) {
|
||||
$character = pack('N*', $utf32be);
|
||||
$t .= mb_convert_encoding($character, $encoding, 'UTF-32BE');
|
||||
}
|
||||
|
||||
return $t;
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
/**
|
||||
* Smarty htmlspecialchars variablefilter plugin
|
||||
*
|
||||
* @param string $source input string
|
||||
* @param string $source input string
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*
|
||||
* @return string filtered output
|
||||
|
@@ -25,7 +25,7 @@ abstract class Smarty_CacheResource
|
||||
/**
|
||||
* populate Cached Object with meta data from Resource
|
||||
*
|
||||
* @param \Smarty_Template_Cached $cached cached object
|
||||
* @param \Smarty_Template_Cached $cached cached object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
@@ -50,7 +50,9 @@ abstract class Smarty_CacheResource
|
||||
*
|
||||
* @return boolean true or false if the cached content does not exist
|
||||
*/
|
||||
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null,
|
||||
abstract public function process(
|
||||
Smarty_Internal_Template $_template,
|
||||
Smarty_Template_Cached $cached = null,
|
||||
$update = false
|
||||
);
|
||||
|
||||
@@ -71,7 +73,7 @@ abstract class Smarty_CacheResource
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
abstract function readCachedContent(Smarty_Internal_Template $_template);
|
||||
abstract public function readCachedContent(Smarty_Internal_Template $_template);
|
||||
|
||||
/**
|
||||
* Return cached content
|
||||
@@ -88,7 +90,6 @@ abstract class Smarty_CacheResource
|
||||
$unifunc($_template);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -134,7 +135,6 @@ abstract class Smarty_CacheResource
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return $hadLock;
|
||||
}
|
||||
|
||||
@@ -194,12 +194,10 @@ abstract class Smarty_CacheResource
|
||||
if (!isset($type)) {
|
||||
$type = $smarty->caching_type;
|
||||
}
|
||||
|
||||
// try smarty's cache
|
||||
if (isset($smarty->_cache[ 'cacheresource_handlers' ][ $type ])) {
|
||||
return $smarty->_cache[ 'cacheresource_handlers' ][ $type ];
|
||||
}
|
||||
|
||||
// try registered resource
|
||||
if (isset($smarty->registered_cache_resources[ $type ])) {
|
||||
// do not cache these instances as they may vary from instance to instance
|
||||
|
@@ -106,12 +106,15 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
if ($mtime !== null) {
|
||||
$cached->timestamp = $mtime;
|
||||
$cached->exists = !!$cached->timestamp;
|
||||
|
||||
return;
|
||||
}
|
||||
$timestamp = null;
|
||||
$this->fetch(
|
||||
$cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $cached->content,
|
||||
$cached->filepath,
|
||||
$cached->source->name,
|
||||
$cached->cache_id,
|
||||
$cached->compile_id,
|
||||
$cached->content,
|
||||
$timestamp
|
||||
);
|
||||
$cached->timestamp = isset($timestamp) ? $timestamp : false;
|
||||
@@ -127,7 +130,9 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
*
|
||||
* @return boolean true or false if the cached content does not exist
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Template_Cached $cached = null,
|
||||
public function process(
|
||||
Smarty_Internal_Template $_smarty_tpl,
|
||||
Smarty_Template_Cached $cached = null,
|
||||
$update = false
|
||||
) {
|
||||
if (!$cached) {
|
||||
@@ -137,8 +142,12 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
$timestamp = $cached->timestamp ? $cached->timestamp : null;
|
||||
if ($content === null || !$timestamp) {
|
||||
$this->fetch(
|
||||
$_smarty_tpl->cached->filepath, $_smarty_tpl->source->name, $_smarty_tpl->cache_id,
|
||||
$_smarty_tpl->compile_id, $content, $timestamp
|
||||
$_smarty_tpl->cached->filepath,
|
||||
$_smarty_tpl->source->name,
|
||||
$_smarty_tpl->cache_id,
|
||||
$_smarty_tpl->compile_id,
|
||||
$content,
|
||||
$timestamp
|
||||
);
|
||||
}
|
||||
if (isset($content)) {
|
||||
@@ -146,7 +155,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
$cached->content = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -161,8 +169,12 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
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
|
||||
$_template->cached->filepath,
|
||||
$_template->source->name,
|
||||
$_template->cache_id,
|
||||
$_template->compile_id,
|
||||
$_template->cache_lifetime,
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
@@ -180,8 +192,12 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
if ($content === null) {
|
||||
$timestamp = null;
|
||||
$this->fetch(
|
||||
$_template->cached->filepath, $_template->source->name, $_template->cache_id,
|
||||
$_template->compile_id, $content, $timestamp
|
||||
$_template->cached->filepath,
|
||||
$_template->source->name,
|
||||
$_template->cache_id,
|
||||
$_template->compile_id,
|
||||
$content,
|
||||
$timestamp
|
||||
);
|
||||
}
|
||||
if (isset($content)) {
|
||||
@@ -218,7 +234,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
|
||||
{
|
||||
$cache_name = null;
|
||||
|
||||
if (isset($resource_name)) {
|
||||
$source = Smarty_Template_Source::load(null, $smarty, $resource_name);
|
||||
if ($source->exists) {
|
||||
@@ -227,7 +242,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->delete($cache_name, $cache_id, $compile_id, $exp_time);
|
||||
}
|
||||
|
||||
@@ -243,7 +257,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
{
|
||||
$id = $cached->lock_id;
|
||||
$name = $cached->source->name . '.lock';
|
||||
|
||||
$mtime = $this->fetchTimestamp($id, $name, $cached->cache_id, $cached->compile_id);
|
||||
if ($mtime === null) {
|
||||
$this->fetch($id, $name, $cached->cache_id, $cached->compile_id, $content, $mtime);
|
||||
|
@@ -56,7 +56,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
{
|
||||
$cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' .
|
||||
$this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
|
||||
|
||||
$this->populateTimestamp($cached);
|
||||
}
|
||||
|
||||
@@ -70,14 +69,19 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
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
|
||||
$cached->filepath,
|
||||
$cached->source->name,
|
||||
$cached->cache_id,
|
||||
$cached->compile_id,
|
||||
$content,
|
||||
$timestamp,
|
||||
$cached->source->uid
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
$cached->content = $content;
|
||||
$cached->timestamp = (int) $timestamp;
|
||||
$cached->timestamp = (int)$timestamp;
|
||||
$cached->exists = !!$cached->timestamp;
|
||||
}
|
||||
|
||||
@@ -90,7 +94,9 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
*
|
||||
* @return boolean true or false if the cached content does not exist
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Template_Cached $cached = null,
|
||||
public function process(
|
||||
Smarty_Internal_Template $_smarty_tpl,
|
||||
Smarty_Template_Cached $cached = null,
|
||||
$update = false
|
||||
) {
|
||||
if (!$cached) {
|
||||
@@ -100,8 +106,13 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
$timestamp = $cached->timestamp ? $cached->timestamp : null;
|
||||
if ($content === null || !$timestamp) {
|
||||
if (!$this->fetch(
|
||||
$_smarty_tpl->cached->filepath, $_smarty_tpl->source->name, $_smarty_tpl->cache_id,
|
||||
$_smarty_tpl->compile_id, $content, $timestamp, $_smarty_tpl->source->uid
|
||||
$_smarty_tpl->cached->filepath,
|
||||
$_smarty_tpl->source->name,
|
||||
$_smarty_tpl->cache_id,
|
||||
$_smarty_tpl->compile_id,
|
||||
$content,
|
||||
$timestamp,
|
||||
$_smarty_tpl->source->uid
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
@@ -109,10 +120,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
}
|
||||
if (isset($content)) {
|
||||
eval('?>' . $content);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -127,7 +136,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
$this->addMetaTimestamp($content);
|
||||
|
||||
return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime);
|
||||
}
|
||||
|
||||
@@ -144,8 +152,13 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
$timestamp = null;
|
||||
if ($content === null) {
|
||||
if (!$this->fetch(
|
||||
$_template->cached->filepath, $_template->source->name, $_template->cache_id,
|
||||
$_template->compile_id, $content, $timestamp, $_template->source->uid
|
||||
$_template->cached->filepath,
|
||||
$_template->source->name,
|
||||
$_template->cache_id,
|
||||
$_template->compile_id,
|
||||
$content,
|
||||
$timestamp,
|
||||
$_template->source->uid
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
@@ -173,7 +186,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
if (!$this->purge()) {
|
||||
$this->invalidate(null);
|
||||
}
|
||||
return - 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,7 +212,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
$this->sanitize($compile_id);
|
||||
$this->delete(array($cid));
|
||||
$this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid);
|
||||
return - 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,13 +264,18 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
*
|
||||
* @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));
|
||||
$content = !empty($t[ $cid ]) ? $t[ $cid ] : null;
|
||||
$timestamp = null;
|
||||
|
||||
if ($content && ($timestamp = $this->getMetaTimestamp($content))) {
|
||||
$invalidated =
|
||||
$this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id, $resource_uid);
|
||||
@@ -266,7 +284,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
$content = null;
|
||||
}
|
||||
}
|
||||
|
||||
return !!$content;
|
||||
}
|
||||
|
||||
@@ -279,7 +296,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
protected function addMetaTimestamp(&$content)
|
||||
{
|
||||
$mt = explode(' ', microtime());
|
||||
$ts = pack('NN', $mt[ 1 ], (int) ($mt[ 0 ] * 100000000));
|
||||
$ts = pack('NN', $mt[ 1 ], (int)($mt[ 0 ] * 100000000));
|
||||
$content = $ts . $content;
|
||||
}
|
||||
|
||||
@@ -311,7 +328,11 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null,
|
||||
protected function invalidate(
|
||||
$cid = null,
|
||||
$resource_name = null,
|
||||
$cache_id = null,
|
||||
$compile_id = null,
|
||||
$resource_uid = null
|
||||
) {
|
||||
$now = microtime(true);
|
||||
@@ -352,7 +373,11 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
*
|
||||
* @return float the microtime the CacheID was invalidated
|
||||
*/
|
||||
protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null,
|
||||
protected function getLatestInvalidationTimestamp(
|
||||
$cid,
|
||||
$resource_name = null,
|
||||
$cache_id = null,
|
||||
$compile_id = null,
|
||||
$resource_uid = null
|
||||
) {
|
||||
// abort if there is no CacheID
|
||||
@@ -363,14 +388,12 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
if (!($_cid = $this->listInvalidationKeys($cid, $resource_name, $cache_id, $compile_id, $resource_uid))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// there are no InValidationKeys
|
||||
if (!($values = $this->read($_cid))) {
|
||||
return 0;
|
||||
}
|
||||
// make sure we're dealing with floats
|
||||
$values = array_map('floatval', $values);
|
||||
|
||||
return max($values);
|
||||
}
|
||||
|
||||
@@ -387,7 +410,11 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
* @return array list of InvalidationKeys
|
||||
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey
|
||||
*/
|
||||
protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null,
|
||||
protected function listInvalidationKeys(
|
||||
$cid,
|
||||
$resource_name = null,
|
||||
$cache_id = null,
|
||||
$compile_id = null,
|
||||
$resource_uid = null
|
||||
) {
|
||||
$t = array('IVK#ALL');
|
||||
@@ -421,9 +448,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
$t[] = 'IVK#CACHE#' . $part;
|
||||
$t[] = 'IVK#CID' . $_name . $part . $_compile;
|
||||
// skip past delimiter position
|
||||
$i ++;
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $t;
|
||||
}
|
||||
|
||||
@@ -439,7 +465,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
{
|
||||
$key = 'LOCK#' . $cached->filepath;
|
||||
$data = $this->read(array($key));
|
||||
|
||||
return $data && time() - $data[ $key ] < $smarty->locking_timeout;
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ class Smarty_Data extends Smarty_Internal_Data
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
static $count = 0;
|
||||
public static $count = 0;
|
||||
|
||||
/**
|
||||
* Data block name
|
||||
@@ -50,7 +50,7 @@ class Smarty_Data extends Smarty_Internal_Data
|
||||
public function __construct($_parent = null, $smarty = null, $name = null)
|
||||
{
|
||||
parent::__construct();
|
||||
self::$count ++;
|
||||
self::$count++;
|
||||
$this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count);
|
||||
$this->smarty = $smarty;
|
||||
if (is_object($_parent)) {
|
||||
|
@@ -7,6 +7,7 @@
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class does contain all necessary methods for the HTML cache on file system
|
||||
* Implements the file system as resource for the HTML cache Version ussing nocache inserts.
|
||||
@@ -33,12 +34,16 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
||||
$cached->filepath = $smarty->getCacheDir();
|
||||
if (isset($_template->cache_id)) {
|
||||
$cached->filepath .= preg_replace(
|
||||
array('![^\w|]+!',
|
||||
'![|]+!'),
|
||||
array('_',
|
||||
$_compile_dir_sep),
|
||||
$_template->cache_id
|
||||
) . $_compile_dir_sep;
|
||||
array(
|
||||
'![^\w|]+!',
|
||||
'![|]+!'
|
||||
),
|
||||
array(
|
||||
'_',
|
||||
$_compile_dir_sep
|
||||
),
|
||||
$_template->cache_id
|
||||
) . $_compile_dir_sep;
|
||||
}
|
||||
if (isset($_template->compile_id)) {
|
||||
$cached->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) . $_compile_dir_sep;
|
||||
@@ -89,7 +94,8 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
||||
*
|
||||
* @return boolean true or false if the cached content does not exist
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_smarty_tpl,
|
||||
public function process(
|
||||
Smarty_Internal_Template $_smarty_tpl,
|
||||
Smarty_Template_Cached $cached = null,
|
||||
$update = false
|
||||
) {
|
||||
@@ -114,12 +120,12 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
||||
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
if ($_template->smarty->ext->_writeFile->writeFile(
|
||||
$_template->cached->filepath,
|
||||
$content,
|
||||
$_template->smarty
|
||||
) === true
|
||||
$_template->cached->filepath,
|
||||
$content,
|
||||
$_template->smarty
|
||||
) === true
|
||||
) {
|
||||
if (function_exists('opcache_invalidate')
|
||||
if (function_exists('opcache_invalidate')
|
||||
&& (!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api'))) < 1
|
||||
) {
|
||||
opcache_invalidate($_template->cached->filepath, true);
|
||||
|
@@ -29,9 +29,11 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $valid_scopes = array('local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
|
||||
'root' => Smarty::SCOPE_ROOT, 'global' => Smarty::SCOPE_GLOBAL,
|
||||
'tpl_root' => Smarty::SCOPE_TPL_ROOT, 'smarty' => Smarty::SCOPE_SMARTY);
|
||||
public $valid_scopes = array(
|
||||
'local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
|
||||
'root' => Smarty::SCOPE_ROOT, 'global' => Smarty::SCOPE_GLOBAL,
|
||||
'tpl_root' => Smarty::SCOPE_TPL_ROOT, 'smarty' => Smarty::SCOPE_SMARTY
|
||||
);
|
||||
|
||||
/**
|
||||
* Compiles code for the {assign} tag
|
||||
@@ -66,7 +68,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
||||
}
|
||||
// scope setup
|
||||
if ($_attr[ 'noscope' ]) {
|
||||
$_scope = - 1;
|
||||
$_scope = -1;
|
||||
} else {
|
||||
$_scope = $compiler->convertScope($_attr, $this->valid_scopes);
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
/**
|
||||
* This file is part of Smarty.
|
||||
*
|
||||
* (c) 2015 Uwe Tews
|
||||
@@ -22,6 +22,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -29,6 +30,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -36,6 +38,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $option_flags = array('hide', 'nocache');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -74,9 +77,11 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
|
||||
$this->openTag(
|
||||
$compiler,
|
||||
'block',
|
||||
array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
|
||||
$compiler->template->compiled->has_nocache_code,
|
||||
$compiler->template->caching)
|
||||
array(
|
||||
$_attr, $compiler->nocache, $compiler->parser->current_buffer,
|
||||
$compiler->template->compiled->has_nocache_code,
|
||||
$compiler->template->caching
|
||||
)
|
||||
);
|
||||
$compiler->saveRequiredPlugins(true);
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
@@ -85,6 +90,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile BlockClose Class
|
||||
*/
|
||||
@@ -118,13 +124,12 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
|
||||
$_functionCode = $compiler->parser->current_buffer;
|
||||
// setup buffer for template function code
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||
|
||||
$output = "<?php\n";
|
||||
$output .= "/* {block {$_name}} */\n";
|
||||
$output .= "class {$_className} extends Smarty_Internal_Block\n";
|
||||
$output .= "{\n";
|
||||
foreach ($_block as $property => $value) {
|
||||
$output .= "public \${$property} = " . var_export($value, true) .";\n";
|
||||
$output .= "public \${$property} = " . var_export($value, true) . ";\n";
|
||||
}
|
||||
$output .= "public function callBlock(Smarty_Internal_Template \$_smarty_tpl) {\n";
|
||||
$output .= $compiler->compileRequiredPlugins();
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
/**
|
||||
* This file is part of Smarty.
|
||||
*
|
||||
* (c) 2015 Uwe Tews
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
/**
|
||||
* This file is part of Smarty.
|
||||
*
|
||||
* (c) 2015 Uwe Tews
|
||||
|
@@ -78,11 +78,9 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
|
||||
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
if ($_attr[ 'nocache' ] === true) {
|
||||
$compiler->trigger_template_error('nocache option not allowed', null, true);
|
||||
}
|
||||
|
||||
if (isset($_attr[ 'levels' ])) {
|
||||
if (!is_numeric($_attr[ 'levels' ])) {
|
||||
$compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
|
||||
@@ -101,18 +99,18 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
|
||||
if ($level_count === 0) {
|
||||
break;
|
||||
}
|
||||
$level_count --;
|
||||
$level_count--;
|
||||
if ($compiler->_tag_stack[ $stack_count ][ 0 ] === 'foreach') {
|
||||
$foreachLevels ++;
|
||||
$foreachLevels++;
|
||||
}
|
||||
}
|
||||
$stack_count --;
|
||||
$stack_count--;
|
||||
}
|
||||
if ($level_count !== 0) {
|
||||
$compiler->trigger_template_error("cannot {$this->tag} {$levels} level(s)", null, true);
|
||||
}
|
||||
if ($lastTag === 'foreach' && $this->tag === 'break' && $foreachLevels > 0) {
|
||||
$foreachLevels --;
|
||||
$foreachLevels--;
|
||||
}
|
||||
return array($levels, $foreachLevels);
|
||||
}
|
||||
|
@@ -41,16 +41,20 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
|
||||
{
|
||||
return '$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl'.(isset($parameter[ 1 ])?", {$parameter[ 1 ]})":')');
|
||||
public static function compileSpecialVariable(
|
||||
$args,
|
||||
Smarty_Internal_TemplateCompilerBase $compiler,
|
||||
$parameter = null
|
||||
) {
|
||||
return '$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl' .
|
||||
(isset($parameter[ 1 ]) ? ", {$parameter[ 1 ]})" : ')');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles code for the {capture} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param null $parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
@@ -59,16 +63,13 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args, $parameter, 'capture');
|
||||
|
||||
$buffer = isset($_attr[ 'name' ]) ? $_attr[ 'name' ] : "'default'";
|
||||
$assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : 'null';
|
||||
$append = isset($_attr[ 'append' ]) ? $_attr[ 'append' ] : 'null';
|
||||
|
||||
$compiler->_cache[ 'capture_stack' ][] = array($compiler->nocache);
|
||||
// maybe nocache because of nocache variables
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
$_output = "<?php \$_smarty_tpl->smarty->ext->_capture->open(\$_smarty_tpl, $buffer, $assign, $append);?>";
|
||||
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
@@ -84,8 +85,8 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {/capture} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param null $parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
@@ -98,9 +99,7 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
|
||||
if ($compiler->nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
list($compiler->nocache) = array_pop($compiler->_cache[ 'capture_stack' ]);
|
||||
|
||||
return "<?php \$_smarty_tpl->smarty->ext->_capture->close(\$_smarty_tpl);?>";
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
/**
|
||||
* This file is part of Smarty.
|
||||
*
|
||||
* (c) 2015 Uwe Tews
|
||||
@@ -51,7 +51,7 @@ class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$tag = isset($parameter[0]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'";
|
||||
$tag = isset($parameter[ 0 ]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'";
|
||||
if (!isset($compiler->_cache[ 'blockNesting' ])) {
|
||||
$compiler->trigger_template_error(
|
||||
"{$tag} used outside {block} tags ",
|
||||
@@ -69,11 +69,11 @@ class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
|
||||
$output .= "ob_start();\n";
|
||||
}
|
||||
$output .= '$_smarty_tpl->inheritance->call' . $this->blockType . '($_smarty_tpl, $this' .
|
||||
($this->blockType === 'Child' ? '' : ", {$tag}"). ");\n";
|
||||
($this->blockType === 'Child' ? '' : ", {$tag}") . ");\n";
|
||||
if (isset($_assign)) {
|
||||
$output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
|
||||
}
|
||||
$output .="?>\n";
|
||||
$output .= "?>\n";
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
@@ -53,9 +53,11 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $valid_scopes = array('local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
|
||||
'root' => Smarty::SCOPE_ROOT, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
|
||||
'smarty' => Smarty::SCOPE_SMARTY, 'global' => Smarty::SCOPE_SMARTY);
|
||||
public $valid_scopes = array(
|
||||
'local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
|
||||
'root' => Smarty::SCOPE_ROOT, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
|
||||
'smarty' => Smarty::SCOPE_SMARTY, 'global' => Smarty::SCOPE_SMARTY
|
||||
);
|
||||
|
||||
/**
|
||||
* Compiles code for the {config_load} tag
|
||||
@@ -70,11 +72,9 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
if ($_attr[ 'nocache' ] === true) {
|
||||
$compiler->trigger_template_error('nocache option not allowed', null, true);
|
||||
}
|
||||
|
||||
// save possible attributes
|
||||
$conf_file = $_attr[ 'file' ];
|
||||
if (isset($_attr[ 'section' ])) {
|
||||
@@ -84,15 +84,13 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
|
||||
}
|
||||
// scope setup
|
||||
if ($_attr[ 'noscope' ]) {
|
||||
$_scope = - 1;
|
||||
$_scope = -1;
|
||||
} else {
|
||||
$_scope = $compiler->convertScope($_attr, $this->valid_scopes);
|
||||
}
|
||||
|
||||
// create config object
|
||||
$_output =
|
||||
"<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n";
|
||||
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
|
@@ -29,10 +29,8 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
// compile always as nocache
|
||||
$compiler->tag_nocache = true;
|
||||
|
||||
// display debug template
|
||||
$_output =
|
||||
"<?php \$_smarty_debug = new Smarty_Internal_Debug;\n \$_smarty_debug->display_debug(\$_smarty_tpl);\n";
|
||||
|
@@ -56,16 +56,15 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
|
||||
// output will be stored in a smarty variable instead of being displayed
|
||||
$_assign = $_attr[ 'assign' ];
|
||||
}
|
||||
|
||||
// create template object
|
||||
$_output = "\$_template = new {$compiler->smarty->template_class}('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->smarty, \$_smarty_tpl);";
|
||||
$_output =
|
||||
"\$_template = new {$compiler->smarty->template_class}('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->smarty, \$_smarty_tpl);";
|
||||
//was there an assign attribute?
|
||||
if (isset($_assign)) {
|
||||
$_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
|
||||
} else {
|
||||
$_output .= 'echo $_template->fetch();';
|
||||
}
|
||||
|
||||
return "<?php $_output ?>";
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile extend
|
||||
* Compiles the {extends} tag
|
||||
@@ -74,7 +73,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
|
||||
} else {
|
||||
$file = "'{$file}'";
|
||||
}
|
||||
$i ++;
|
||||
$i++;
|
||||
if ($i === count($files) && isset($_attr[ 'extends_resource' ])) {
|
||||
$this->compileEndChild($compiler);
|
||||
}
|
||||
@@ -111,9 +110,9 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
|
||||
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag(
|
||||
$compiler->parser,
|
||||
'<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl' .
|
||||
(isset($template) ?
|
||||
", {$template}{$inlineUids}" :
|
||||
'') . ");\n?>"
|
||||
(isset($template) ?
|
||||
", {$template}{$inlineUids}" :
|
||||
'') . ");\n?>"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -132,8 +131,10 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
|
||||
$compiler->parser,
|
||||
$compiler->compileTag(
|
||||
'include',
|
||||
array($template,
|
||||
array('scope' => 'parent'))
|
||||
array(
|
||||
$template,
|
||||
array('scope' => 'parent')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$compiler->loopNesting ++;
|
||||
$compiler->loopNesting++;
|
||||
if ($parameter === 0) {
|
||||
$this->required_attributes = array('start', 'to');
|
||||
$this->optional_attributes = array('max', 'step');
|
||||
@@ -45,7 +45,6 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
|
||||
$this->mapCache = array();
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
$output = "<?php\n";
|
||||
if ($parameter === 1) {
|
||||
foreach ($_attr[ 'start' ] as $_statement) {
|
||||
@@ -93,7 +92,6 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$var]->last = \$_smarty_tpl->tpl_vars[$var]->iteration === \$_smarty_tpl->tpl_vars[$var]->total;";
|
||||
}
|
||||
$output .= '?>';
|
||||
|
||||
$this->openTag($compiler, 'for', array('for', $compiler->nocache));
|
||||
// maybe nocache because of nocache variables
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
@@ -123,10 +121,8 @@ class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
list($openTag, $nocache) = $this->closeTag($compiler, array('for'));
|
||||
$this->openTag($compiler, 'forelse', array('forelse', $nocache));
|
||||
|
||||
return "<?php }} else { ?>";
|
||||
}
|
||||
}
|
||||
@@ -150,16 +146,14 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$compiler->loopNesting --;
|
||||
$compiler->loopNesting--;
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// must endblock be nocache?
|
||||
if ($compiler->nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse'));
|
||||
|
||||
$output = "<?php }\n";
|
||||
if ($openTag !== 'forelse') {
|
||||
$output .= "}\n";
|
||||
|
@@ -87,7 +87,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$compiler->loopNesting ++;
|
||||
$compiler->loopNesting++;
|
||||
// init
|
||||
$this->isNamed = false;
|
||||
// check and get attributes
|
||||
@@ -121,14 +121,14 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
|
||||
if (isset($attributes[ $a ]) && $attributes[ $a ] === $fromName) {
|
||||
$compiler->trigger_template_error(
|
||||
"'{$a}' and 'from' may not have same variable name '{$fromName}'",
|
||||
null, true
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$itemVar = "\$_smarty_tpl->tpl_vars['{$item}']";
|
||||
$local = '$__foreach_' . $attributes[ 'item' ] . '_' . $this->counter ++ . '_';
|
||||
$local = '$__foreach_' . $attributes[ 'item' ] . '_' . $this->counter++ . '_';
|
||||
// search for used tag attributes
|
||||
$itemAttr = array();
|
||||
$namedAttr = array();
|
||||
@@ -190,7 +190,8 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
|
||||
$needTotal = isset($itemAttr[ 'total' ]);
|
||||
// Register tag
|
||||
$this->openTag(
|
||||
$compiler, 'foreach',
|
||||
$compiler,
|
||||
'foreach',
|
||||
array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2)
|
||||
);
|
||||
// maybe nocache because of nocache variables
|
||||
@@ -253,7 +254,6 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
|
||||
$output .= "{$local}saved = {$itemVar};\n";
|
||||
}
|
||||
$output .= '?>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
@@ -290,7 +290,6 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
list($openTag, $nocache, $local, $itemVar, $restore) = $this->closeTag($compiler, array('foreach'));
|
||||
$this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $itemVar, 0));
|
||||
$output = "<?php\n";
|
||||
@@ -321,16 +320,14 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$compiler->loopNesting --;
|
||||
$compiler->loopNesting--;
|
||||
// must endblock be nocache?
|
||||
if ($compiler->nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
list($openTag, $compiler->nocache, $local, $itemVar, $restore) =
|
||||
$this->closeTag($compiler, array('foreach', 'foreachelse'));
|
||||
$output = "<?php\n";
|
||||
|
||||
if ($restore === 2) {
|
||||
$output .= "{$itemVar} = {$local}saved;\n";
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -54,15 +53,16 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
if ($_attr[ 'nocache' ] === true) {
|
||||
$compiler->trigger_template_error('nocache option not allowed', null, true);
|
||||
}
|
||||
unset($_attr[ 'nocache' ]);
|
||||
$_name = trim($_attr[ 'name' ], '\'"');
|
||||
$compiler->parent_compiler->tpl_function[ $_name ] = array();
|
||||
$save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
|
||||
$compiler->template->caching);
|
||||
$save = array(
|
||||
$_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
|
||||
$compiler->template->caching
|
||||
);
|
||||
$this->openTag($compiler, 'function', $save);
|
||||
// Init temporary context
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||
@@ -80,7 +80,6 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Compiler object
|
||||
*
|
||||
@@ -125,7 +124,6 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
$_functionCode = $compiler->parser->current_buffer;
|
||||
// setup buffer for template function code
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||
|
||||
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}";
|
||||
$_funcNameCaching = $_funcName . '_nocache';
|
||||
if ($compiler->template->compiled->has_nocache_code) {
|
||||
@@ -181,7 +179,8 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
$output .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
|
||||
$output .= $_paramsCode;
|
||||
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\n}\n";
|
||||
$output .= $compiler->compileCheckPlugins(array_merge($compiler->required_plugins[ 'compiled' ], $compiler->required_plugins[ 'nocache' ]));
|
||||
$output .= $compiler->compileCheckPlugins(array_merge($compiler->required_plugins[ 'compiled' ],
|
||||
$compiler->required_plugins[ 'nocache' ]));
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree(
|
||||
$compiler->parser,
|
||||
@@ -218,12 +217,13 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function removeNocache($match)
|
||||
public 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 ]
|
||||
'',
|
||||
$match[ 0 ]
|
||||
);
|
||||
$code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code);
|
||||
return $code;
|
||||
|
@@ -33,11 +33,9 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
||||
$this->openTag($compiler, 'if', array(1, $compiler->nocache));
|
||||
// must whole block be nocache ?
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
|
||||
if (!isset($parameter['if condition'])) {
|
||||
if (!isset($parameter[ 'if condition' ])) {
|
||||
$compiler->trigger_template_error('missing if condition', null, true);
|
||||
}
|
||||
|
||||
if (is_array($parameter[ 'if condition' ])) {
|
||||
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
||||
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||
@@ -56,7 +54,8 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
||||
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
||||
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||
$_output .= $assignCompiler->compile(
|
||||
$assignAttr, $compiler,
|
||||
$assignAttr,
|
||||
$compiler,
|
||||
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
|
||||
);
|
||||
} else {
|
||||
@@ -91,7 +90,6 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
|
||||
{
|
||||
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
|
||||
$this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache));
|
||||
|
||||
return '<?php } else { ?>';
|
||||
}
|
||||
}
|
||||
@@ -118,13 +116,10 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
|
||||
|
||||
if (!isset($parameter['if condition'])) {
|
||||
if (!isset($parameter[ 'if condition' ])) {
|
||||
$compiler->trigger_template_error('missing elseif condition', null, true);
|
||||
}
|
||||
|
||||
$assignCode = '';
|
||||
$var = '';
|
||||
if (is_array($parameter[ 'if condition' ])) {
|
||||
@@ -146,7 +141,8 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
||||
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||
$assignCode .= $assignCompiler->compile(
|
||||
$assignAttr, $compiler,
|
||||
$assignAttr,
|
||||
$compiler,
|
||||
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
|
||||
);
|
||||
} else {
|
||||
@@ -156,7 +152,6 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
} else {
|
||||
$condition_by_assign = false;
|
||||
}
|
||||
|
||||
$prefixCode = $compiler->getPrefixCode();
|
||||
if (empty($prefixCode)) {
|
||||
if ($condition_by_assign) {
|
||||
@@ -204,10 +199,9 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
|
||||
}
|
||||
list($nesting, $compiler->nocache) = $this->closeTag($compiler, array('if', 'else', 'elseif'));
|
||||
$tmp = '';
|
||||
for ($i = 0; $i < $nesting; $i ++) {
|
||||
for ($i = 0; $i < $nesting; $i++) {
|
||||
$tmp .= '}';
|
||||
}
|
||||
|
||||
return "<?php {$tmp}?>";
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Include Class
|
||||
*
|
||||
@@ -19,6 +20,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* caching mode to create nocache code but no cache file
|
||||
*/
|
||||
const CACHING_NOCACHE_CODE = 9999;
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -26,6 +28,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -33,6 +36,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -40,6 +44,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $option_flags = array('nocache', 'inline', 'caching');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -47,14 +52,17 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Valid scope names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $valid_scopes = array('parent' => Smarty::SCOPE_PARENT, 'root' => Smarty::SCOPE_ROOT,
|
||||
'global' => Smarty::SCOPE_GLOBAL, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
|
||||
'smarty' => Smarty::SCOPE_SMARTY);
|
||||
public $valid_scopes = array(
|
||||
'parent' => Smarty::SCOPE_PARENT, 'root' => Smarty::SCOPE_ROOT,
|
||||
'global' => Smarty::SCOPE_GLOBAL, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
|
||||
'smarty' => Smarty::SCOPE_SMARTY
|
||||
);
|
||||
|
||||
/**
|
||||
* Compiles code for the {include} tag
|
||||
@@ -91,7 +99,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$compiled->includes[ $fullResourceName ]++;
|
||||
$cache_tpl = true;
|
||||
} else {
|
||||
if ("{$compiler->template->source->type}:{$compiler->template->source->name}" == $fullResourceName
|
||||
if ("{$compiler->template->source->type}:{$compiler->template->source->name}" ==
|
||||
$fullResourceName
|
||||
) {
|
||||
// recursive call of current template
|
||||
$compiled->includes[ $fullResourceName ] = 2;
|
||||
@@ -193,8 +202,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$compiler->smarty->allow_ambiguous_resources = true;
|
||||
/* @var Smarty_Internal_Template $tpl */
|
||||
$tpl = new $compiler->smarty->template_class(
|
||||
trim($fullResourceName, '"\''), $compiler->smarty,
|
||||
$compiler->template, $compiler->template->cache_id, $c_id,
|
||||
trim($fullResourceName, '"\''),
|
||||
$compiler->smarty,
|
||||
$compiler->template,
|
||||
$compiler->template->cache_id,
|
||||
$c_id,
|
||||
$_caching
|
||||
);
|
||||
$uid = $tpl->source->type . $tpl->source->uid;
|
||||
@@ -276,7 +288,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @throws \Exception
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler,
|
||||
public function compileInlineTemplate(
|
||||
Smarty_Internal_SmartyTemplateCompiler $compiler,
|
||||
Smarty_Internal_Template $tpl,
|
||||
$t_hash
|
||||
) {
|
||||
|
@@ -7,6 +7,7 @@
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Insert Class
|
||||
*
|
||||
@@ -57,9 +58,9 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var Smarty_Internal_Template $_smarty_tpl
|
||||
*
|
||||
* @var Smarty_Internal_Template $_smarty_tpl
|
||||
* used in evaluated code
|
||||
*/
|
||||
$_smarty_tpl = $compiler->template;
|
||||
|
@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
|
@@ -40,7 +40,6 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
|
||||
$compiler->nocache = true;
|
||||
// this tag does not return compiled code
|
||||
$compiler->has_code = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -69,7 +68,6 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase
|
||||
list($compiler->nocache) = $this->closeTag($compiler, array('nocache'));
|
||||
// this tag does not return compiled code
|
||||
$compiler->has_code = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
/**
|
||||
* This file is part of Smarty.
|
||||
*
|
||||
* (c) 2015 Uwe Tews
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
class Smarty_Internal_Compile_Parent extends Smarty_Internal_Compile_Child
|
||||
{
|
||||
|
||||
/**
|
||||
* Tag name
|
||||
*
|
||||
|
@@ -46,15 +46,14 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function = null)
|
||||
{
|
||||
if (!isset($tag[ 5 ]) || substr($tag, - 5) !== 'close') {
|
||||
if (!isset($tag[ 5 ]) || substr($tag, -5) !== 'close') {
|
||||
// opening tag of block plugin
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$this->nesting ++;
|
||||
$this->nesting++;
|
||||
unset($_attr[ 'nocache' ]);
|
||||
list($callback, $_paramsArray, $callable) = $this->setup($compiler, $_attr, $tag, $function);
|
||||
$_params = 'array(' . implode(',', $_paramsArray) . ')';
|
||||
|
||||
// compile code
|
||||
$output = "<?php ";
|
||||
if (is_array($callback)) {
|
||||
@@ -75,7 +74,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
// closing tag of block plugin, restore nocache
|
||||
list($_params, $compiler->nocache, $callback) = $this->closeTag($compiler, substr($tag, 0, - 5));
|
||||
list($_params, $compiler->nocache, $callback) = $this->closeTag($compiler, substr($tag, 0, -5));
|
||||
// compile code
|
||||
if (!isset($parameter[ 'modifier_list' ])) {
|
||||
$mod_pre = $mod_post = $mod_content = '';
|
||||
@@ -85,12 +84,16 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
||||
$mod_content = "\$_block_content{$this->nesting} = ob_get_clean();\n";
|
||||
$mod_pre = "ob_start();\n";
|
||||
$mod_post = 'echo ' . $compiler->compileTag(
|
||||
'private_modifier', array(),
|
||||
array('modifierlist' => $parameter[ 'modifier_list' ],
|
||||
'value' => 'ob_get_clean()')
|
||||
) . ";\n";
|
||||
'private_modifier',
|
||||
array(),
|
||||
array(
|
||||
'modifierlist' => $parameter[ 'modifier_list' ],
|
||||
'value' => 'ob_get_clean()'
|
||||
)
|
||||
) . ";\n";
|
||||
}
|
||||
$output = "<?php {$mod_content}\$_block_repeat=false;\n{$mod_pre}echo {$callback}({$_params}, {$mod_content2}, \$_smarty_tpl, \$_block_repeat);\n{$mod_post}}\n";
|
||||
$output =
|
||||
"<?php {$mod_content}\$_block_repeat=false;\n{$mod_pre}echo {$callback}({$_params}, {$mod_content2}, \$_smarty_tpl, \$_block_repeat);\n{$mod_post}}\n";
|
||||
$output .= 'array_pop($_smarty_tpl->smarty->_cache[\'_tag_stack\']);?>';
|
||||
}
|
||||
return $output;
|
||||
@@ -100,7 +103,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
||||
* Setup callback and parameter array
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler
|
||||
* @param array $_attr attributes
|
||||
* @param array $_attr attributes
|
||||
* @param string $tag
|
||||
* @param string $function
|
||||
*
|
||||
|
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_CompileBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Preg search pattern
|
||||
*
|
||||
@@ -113,8 +112,10 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
|
||||
{
|
||||
if ($named) {
|
||||
$this->resultOffsets[ 'named' ] = $this->startOffset + 4;
|
||||
$this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" . ($this->tagName === 'section' ? "|[\[]\s*" : '')
|
||||
. "){$attributes['name']}[.](";
|
||||
$this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" .
|
||||
($this->tagName === 'section' ? "|[\[]\s*" : '')
|
||||
.
|
||||
"){$attributes['name']}[.](";
|
||||
$properties = $this->nameProperties;
|
||||
} else {
|
||||
$this->resultOffsets[ 'item' ] = $this->startOffset + 3;
|
||||
@@ -178,11 +179,12 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
|
||||
$_content = $nextCompiler->template->source->getContent();
|
||||
if ($_content !== '') {
|
||||
// run pre filter if required
|
||||
if ((isset($nextCompiler->smarty->autoload_filters[ 'pre' ])
|
||||
|| isset($nextCompiler->smarty->registered_filters[ 'pre' ]))
|
||||
if ((isset($nextCompiler->smarty->autoload_filters[ 'pre' ])
|
||||
|| isset($nextCompiler->smarty->registered_filters[ 'pre' ]))
|
||||
) {
|
||||
$_content = $nextCompiler->smarty->ext->_filterHandler->runFilter(
|
||||
'pre', $_content,
|
||||
'pre',
|
||||
$_content,
|
||||
$nextCompiler->template
|
||||
);
|
||||
}
|
||||
|
@@ -49,7 +49,6 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
unset($_attr[ 'nocache' ]);
|
||||
// convert attributes into parameter array string
|
||||
$_paramsArray = array();
|
||||
@@ -65,9 +64,12 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
|
||||
$output = "{$function}({$_params},\$_smarty_tpl)";
|
||||
if (!empty($parameter[ 'modifierlist' ])) {
|
||||
$output = $compiler->compileTag(
|
||||
'private_modifier', array(),
|
||||
array('modifierlist' => $parameter[ 'modifierlist' ],
|
||||
'value' => $output)
|
||||
'private_modifier',
|
||||
array(),
|
||||
array(
|
||||
'modifierlist' => $parameter[ 'modifierlist' ],
|
||||
'value' => $output
|
||||
)
|
||||
);
|
||||
}
|
||||
$output = "<?php echo {$output};?>\n";
|
||||
|
@@ -20,7 +20,7 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
|
||||
* Setup callback and parameter array
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler
|
||||
* @param array $_attr attributes
|
||||
* @param array $_attr attributes
|
||||
* @param string $tag
|
||||
* @param string $method
|
||||
*
|
||||
|
@@ -71,7 +71,8 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
|
||||
}
|
||||
if (!empty($parameter[ 'modifierlist' ])) {
|
||||
$output = $compiler->compileTag(
|
||||
'private_modifier', array(),
|
||||
'private_modifier',
|
||||
array(),
|
||||
array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output)
|
||||
);
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -62,7 +61,8 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
$output =
|
||||
preg_replace_callback(
|
||||
'#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i',
|
||||
array($this, 'quote'), $_attr[ 'code' ]
|
||||
array($this, 'quote'),
|
||||
$_attr[ 'code' ]
|
||||
);
|
||||
$compiler->parser->current_buffer->append_subtree(
|
||||
$compiler->parser,
|
||||
@@ -87,7 +87,8 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
if (!($compiler->smarty instanceof SmartyBC)) {
|
||||
$compiler->trigger_template_error(
|
||||
'$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it',
|
||||
null, true
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
$compiler->has_code = true;
|
||||
@@ -99,7 +100,8 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
$compiler->has_code = true;
|
||||
if (!($compiler->smarty instanceof SmartyBC)) {
|
||||
$compiler->trigger_template_error(
|
||||
'{php}{/php} tags not allowed. Use SmartyBC to enable them', null,
|
||||
'{php}{/php} tags not allowed. Use SmartyBC to enable them',
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
@@ -115,7 +117,8 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
}
|
||||
return preg_replace(
|
||||
array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"),
|
||||
array('<?php ', '?>'), $_attr[ 'code' ]
|
||||
array('<?php ', '?>'),
|
||||
$_attr[ 'code' ]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -170,8 +173,10 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
if ($lex->phpType === 'unmatched') {
|
||||
return;
|
||||
}
|
||||
if (($lex->phpType === 'php' || $lex->phpType === 'asp')
|
||||
&& ($lex->compiler->php_handling === Smarty::PHP_PASSTHRU || $lex->compiler->php_handling === Smarty::PHP_QUOTE)
|
||||
if (($lex->phpType === 'php' || $lex->phpType === 'asp')
|
||||
&&
|
||||
($lex->compiler->php_handling === Smarty::PHP_PASSTHRU ||
|
||||
$lex->compiler->php_handling === Smarty::PHP_QUOTE)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -185,7 +190,10 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
while ($body) {
|
||||
if (preg_match(
|
||||
'~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~',
|
||||
$lex->data, $match, PREG_OFFSET_CAPTURE, $start
|
||||
$lex->data,
|
||||
$match,
|
||||
PREG_OFFSET_CAPTURE,
|
||||
$start
|
||||
)
|
||||
) {
|
||||
$value = $match[ 0 ][ 0 ];
|
||||
@@ -204,7 +212,10 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
}
|
||||
while ($close > $pos && $close < $start) {
|
||||
if (preg_match(
|
||||
'~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE,
|
||||
'~' . preg_quote($closeTag, '~') . '~i',
|
||||
$lex->data,
|
||||
$match,
|
||||
PREG_OFFSET_CAPTURE,
|
||||
$from
|
||||
)
|
||||
) {
|
||||
|
@@ -50,9 +50,12 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
// tag modifier
|
||||
if (!empty($parameter[ 'modifierlist' ])) {
|
||||
$output = $compiler->compileTag(
|
||||
'private_modifier', array(),
|
||||
array('modifierlist' => $parameter[ 'modifierlist' ],
|
||||
'value' => $output)
|
||||
'private_modifier',
|
||||
array(),
|
||||
array(
|
||||
'modifierlist' => $parameter[ 'modifierlist' ],
|
||||
'value' => $output
|
||||
)
|
||||
);
|
||||
}
|
||||
if (isset($_attr[ 'assign' ])) {
|
||||
@@ -68,9 +71,10 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) {
|
||||
preg_match_all(
|
||||
'/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/',
|
||||
$single_default_modifier, $mod_array
|
||||
$single_default_modifier,
|
||||
$mod_array
|
||||
);
|
||||
for ($i = 0, $count = count($mod_array[ 0 ]); $i < $count; $i ++) {
|
||||
for ($i = 0, $count = count($mod_array[ 0 ]); $i < $count; $i++) {
|
||||
if ($mod_array[ 0 ][ $i ] !== ':') {
|
||||
$modifierlist[ $key ][] = $mod_array[ 0 ][ $i ];
|
||||
}
|
||||
@@ -79,9 +83,12 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
$compiler->default_modifier_list = $modifierlist;
|
||||
}
|
||||
$output = $compiler->compileTag(
|
||||
'private_modifier', array(),
|
||||
array('modifierlist' => $compiler->default_modifier_list,
|
||||
'value' => $output)
|
||||
'private_modifier',
|
||||
array(),
|
||||
array(
|
||||
'modifierlist' => $compiler->default_modifier_list,
|
||||
'value' => $output
|
||||
)
|
||||
);
|
||||
}
|
||||
// autoescape html
|
||||
@@ -91,7 +98,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
// loop over registered filters
|
||||
if (!empty($compiler->template->smarty->registered_filters[ Smarty::FILTER_VARIABLE ])) {
|
||||
foreach ($compiler->template->smarty->registered_filters[ Smarty::FILTER_VARIABLE ] as $key =>
|
||||
$function) {
|
||||
$function) {
|
||||
if (!is_array($function)) {
|
||||
$output = "{$function}({$output},\$_smarty_tpl)";
|
||||
} elseif (is_object($function[ 0 ])) {
|
||||
@@ -104,8 +111,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
}
|
||||
// auto loaded filters
|
||||
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_variable_filter($compiler, $name, $output);
|
||||
if ($result !== false) {
|
||||
$output = $result;
|
||||
@@ -116,13 +122,14 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
}
|
||||
}
|
||||
foreach ($compiler->variable_filters as $filter) {
|
||||
if (count($filter) === 1
|
||||
if (count($filter) === 1
|
||||
&& ($result = $this->compile_variable_filter($compiler, $filter[ 0 ], $output)) !== false
|
||||
) {
|
||||
$output = $result;
|
||||
} else {
|
||||
$output = $compiler->compileTag(
|
||||
'private_modifier', array(),
|
||||
'private_modifier',
|
||||
array(),
|
||||
array('modifierlist' => array($filter), 'value' => $output)
|
||||
);
|
||||
}
|
||||
@@ -130,7 +137,6 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
}
|
||||
$output = "<?php echo {$output};?>\n";
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
@@ -144,7 +150,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
*/
|
||||
private function compile_variable_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output)
|
||||
{
|
||||
$function= $compiler->getPlugin($name, 'variablefilter');
|
||||
$function = $compiler->getPlugin($name, 'variablefilter');
|
||||
if ($function) {
|
||||
return "{$function}({$output},\$_smarty_tpl)";
|
||||
} else {
|
||||
|
@@ -20,7 +20,7 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
|
||||
* Setup callback, parameter array and nocache mode
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler
|
||||
* @param array $_attr attributes
|
||||
* @param array $_attr attributes
|
||||
* @param string $tag
|
||||
* @param null $function
|
||||
*
|
||||
|
@@ -45,8 +45,8 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
|
||||
$tag_info = $compiler->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
|
||||
$is_registered = true;
|
||||
} else {
|
||||
$tag_info = $compiler->default_handler_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
|
||||
$is_registered = false;
|
||||
$tag_info = $compiler->default_handler_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
|
||||
$is_registered = false;
|
||||
}
|
||||
// not cacheable?
|
||||
$compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[ 1 ];
|
||||
@@ -77,9 +77,12 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
|
||||
}
|
||||
if (!empty($parameter[ 'modifierlist' ])) {
|
||||
$output = $compiler->compileTag(
|
||||
'private_modifier', array(),
|
||||
array('modifierlist' => $parameter[ 'modifierlist' ],
|
||||
'value' => $output)
|
||||
'private_modifier',
|
||||
array(),
|
||||
array(
|
||||
'modifierlist' => $parameter[ 'modifierlist' ],
|
||||
'value' => $output
|
||||
)
|
||||
);
|
||||
}
|
||||
$output = "<?php echo {$output};?>\n";
|
||||
|
@@ -43,9 +43,11 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
||||
$class = 'Smarty_Internal_Compile_' . ucfirst($variable);
|
||||
Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ] = new $class;
|
||||
}
|
||||
return Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ]->compileSpecialVariable(array(),
|
||||
$compiler,
|
||||
$_index);
|
||||
return Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ]->compileSpecialVariable(
|
||||
array(),
|
||||
$compiler,
|
||||
$_index
|
||||
);
|
||||
case 'capture':
|
||||
if (class_exists('Smarty_Internal_Compile_Capture')) {
|
||||
return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);
|
||||
@@ -96,12 +98,14 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
||||
} else {
|
||||
return "@constant({$_index[1]})";
|
||||
}
|
||||
// no break
|
||||
case 'config':
|
||||
if (isset($_index[ 2 ])) {
|
||||
return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
|
||||
} else {
|
||||
return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])";
|
||||
}
|
||||
// no break
|
||||
case 'ldelim':
|
||||
return "\$_smarty_tpl->smarty->left_delimiter";
|
||||
case 'rdelim':
|
||||
|
@@ -59,8 +59,10 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum', 'index_prev',
|
||||
'index_next', 'loop');
|
||||
public $nameProperties = array(
|
||||
'first', 'last', 'index', 'iteration', 'show', 'total', 'rownum', 'index_prev',
|
||||
'index_next', 'loop'
|
||||
);
|
||||
|
||||
/**
|
||||
* {section} tag has no item properties
|
||||
@@ -108,8 +110,9 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
$initFor = array();
|
||||
$incFor = array();
|
||||
$cmpFor = array();
|
||||
$propValue = array('index' => "{$sectionVar}->value['index']", 'show' => 'true', 'step' => 1,
|
||||
'iteration' => "{$local}iteration",
|
||||
$propValue = array(
|
||||
'index' => "{$sectionVar}->value['index']", 'show' => 'true', 'step' => 1,
|
||||
'iteration' => "{$local}iteration",
|
||||
);
|
||||
$propType = array('index' => 2, 'iteration' => 2, 'show' => 0, 'step' => 0,);
|
||||
// search for used tag attributes
|
||||
@@ -232,12 +235,14 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
$propValue[ 'start' ] = join('', $start_code);
|
||||
} else {
|
||||
$start_code =
|
||||
array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ", 4 => '0',
|
||||
5 => ' : ', 6 => '-1', 7 => ', ', 8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')',
|
||||
11 => ' : ', 12 => 'min(', 13 => $propValue[ 'start' ], 14 => ', ',
|
||||
15 => "{$propValue['step']} > 0 ? ", 16 => $propValue[ 'loop' ], 17 => ' : ',
|
||||
18 => $propType[ 'loop' ] === 0 ? $propValue[ 'loop' ] - 1 : "{$propValue['loop']} - 1",
|
||||
19 => ')');
|
||||
array(
|
||||
1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ", 4 => '0',
|
||||
5 => ' : ', 6 => '-1', 7 => ', ', 8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')',
|
||||
11 => ' : ', 12 => 'min(', 13 => $propValue[ 'start' ], 14 => ', ',
|
||||
15 => "{$propValue['step']} > 0 ? ", 16 => $propValue[ 'loop' ], 17 => ' : ',
|
||||
18 => $propType[ 'loop' ] === 0 ? $propValue[ 'loop' ] - 1 : "{$propValue['loop']} - 1",
|
||||
19 => ')'
|
||||
);
|
||||
if ($propType[ 'step' ] === 0) {
|
||||
$start_code[ 3 ] = $start_code[ 5 ] = $start_code[ 15 ] = $start_code[ 17 ] = '';
|
||||
if ($propValue[ 'step' ] > 0) {
|
||||
@@ -257,10 +262,12 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
$start_code[ $i ] = '';
|
||||
}
|
||||
if ($propType[ 'start' ] === 0) {
|
||||
$start_code = array(max(
|
||||
$propValue[ 'step' ] > 0 ? 0 : -1,
|
||||
$propValue[ 'start' ] + $propValue[ 'loop' ]
|
||||
));
|
||||
$start_code = array(
|
||||
max(
|
||||
$propValue[ 'step' ] > 0 ? 0 : -1,
|
||||
$propValue[ 'start' ] + $propValue[ 'loop' ]
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
for ($i = 1; $i <= 11; $i++) {
|
||||
@@ -268,10 +275,12 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
}
|
||||
if ($propType[ 'start' ] === 0) {
|
||||
$start_code =
|
||||
array(min(
|
||||
$propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1,
|
||||
$propValue[ 'start' ]
|
||||
));
|
||||
array(
|
||||
min(
|
||||
$propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1,
|
||||
$propValue[ 'start' ]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -298,10 +307,12 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
$propValue[ 'max' ]
|
||||
);
|
||||
} else {
|
||||
$total_code = array(1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ",
|
||||
5 => $propValue[ 'loop' ], 6 => ' - ', 7 => $propValue[ 'start' ], 8 => ' : ',
|
||||
9 => $propValue[ 'start' ], 10 => '+ 1', 11 => ')', 12 => '/ ', 13 => 'abs(',
|
||||
14 => $propValue[ 'step' ], 15 => ')', 16 => ')', 17 => ", {$propValue['max']})",);
|
||||
$total_code = array(
|
||||
1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ",
|
||||
5 => $propValue[ 'loop' ], 6 => ' - ', 7 => $propValue[ 'start' ], 8 => ' : ',
|
||||
9 => $propValue[ 'start' ], 10 => '+ 1', 11 => ')', 12 => '/ ', 13 => 'abs(',
|
||||
14 => $propValue[ 'step' ], 15 => ')', 16 => ')', 17 => ", {$propValue['max']})",
|
||||
);
|
||||
if (!isset($propValue[ 'max' ])) {
|
||||
$total_code[ 1 ] = $total_code[ 17 ] = '';
|
||||
}
|
||||
|
@@ -31,7 +31,6 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase
|
||||
$compiler->variable_filters = $parameter[ 'modifier_list' ];
|
||||
// this tag does not return compiled code
|
||||
$compiler->has_code = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -64,7 +63,6 @@ class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase
|
||||
}
|
||||
// this tag does not return compiled code
|
||||
$compiler->has_code = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ class Smarty_Internal_Compile_Shared_Inheritance extends Smarty_Internal_Compile
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler
|
||||
* @param bool|false $initChildSequence if true force child template
|
||||
*/
|
||||
static function postCompile(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
|
||||
public static function postCompile(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
|
||||
{
|
||||
$compiler->prefixCompiledCode .= "<?php \$_smarty_tpl->_loadInheritance();\n\$_smarty_tpl->inheritance->init(\$_smarty_tpl, " .
|
||||
var_export($initChildSequence, true) . ");\n?>\n";
|
||||
@@ -36,15 +36,14 @@ class Smarty_Internal_Compile_Shared_Inheritance extends Smarty_Internal_Compile
|
||||
*/
|
||||
public function registerInit(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
|
||||
{
|
||||
if ($initChildSequence || !isset($compiler->_cache['inheritanceInit'])) {
|
||||
if ($initChildSequence || !isset($compiler->_cache[ 'inheritanceInit' ])) {
|
||||
$compiler->registerPostCompileCallback(
|
||||
array('Smarty_Internal_Compile_Shared_Inheritance', 'postCompile'),
|
||||
array($initChildSequence),
|
||||
'inheritanceInit',
|
||||
$initChildSequence
|
||||
);
|
||||
|
||||
$compiler->_cache['inheritanceInit'] = true;
|
||||
$compiler->_cache[ 'inheritanceInit' ] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -28,15 +28,13 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
$compiler->loopNesting ++;
|
||||
$compiler->loopNesting++;
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$this->openTag($compiler, 'while', $compiler->nocache);
|
||||
|
||||
if (!array_key_exists('if condition', $parameter)) {
|
||||
$compiler->trigger_template_error('missing while condition', null, true);
|
||||
}
|
||||
|
||||
// maybe nocache because of nocache variables
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
if (is_array($parameter[ 'if condition' ])) {
|
||||
@@ -57,7 +55,8 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
|
||||
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||
$_output = "<?php while ({$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]}) {?>";
|
||||
$_output .= $assignCompiler->compile(
|
||||
$assignAttr, $compiler,
|
||||
$assignAttr,
|
||||
$compiler,
|
||||
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
|
||||
);
|
||||
} else {
|
||||
@@ -65,7 +64,6 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
|
||||
$_output = "<?php while ({$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]}) {?>";
|
||||
$_output .= $assignCompiler->compile($assignAttr, $compiler, array());
|
||||
}
|
||||
|
||||
return $_output;
|
||||
} else {
|
||||
return "<?php\n while ({$parameter['if condition']}) {?>";
|
||||
@@ -91,7 +89,7 @@ class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$compiler->loopNesting --;
|
||||
$compiler->loopNesting--;
|
||||
// must endblock be nocache?
|
||||
if ($compiler->nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
|
@@ -105,7 +105,9 @@ abstract class Smarty_Internal_CompileBase
|
||||
} else {
|
||||
$compiler->trigger_template_error(
|
||||
"illegal value '" . var_export($v, true) .
|
||||
"' for option flag '{$k}'", null, true
|
||||
"' for option flag '{$k}'",
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -128,9 +130,11 @@ abstract class Smarty_Internal_CompileBase
|
||||
$this->mapCache[ 'all' ] =
|
||||
array_fill_keys(
|
||||
array_merge(
|
||||
$this->required_attributes, $this->optional_attributes,
|
||||
$this->required_attributes,
|
||||
$this->optional_attributes,
|
||||
$this->option_flags
|
||||
), true
|
||||
),
|
||||
true
|
||||
);
|
||||
}
|
||||
foreach ($_indexed_attr as $key => $dummy) {
|
||||
@@ -179,7 +183,7 @@ abstract class Smarty_Internal_CompileBase
|
||||
// get stacked info
|
||||
list($_openTag, $_data) = array_pop($compiler->_tag_stack);
|
||||
// open tag must match with the expected ones
|
||||
if (in_array($_openTag, (array) $expectedTag)) {
|
||||
if (in_array($_openTag, (array)$expectedTag)) {
|
||||
if (is_null($_data)) {
|
||||
// return opening tag
|
||||
return $_openTag;
|
||||
@@ -190,12 +194,10 @@ abstract class Smarty_Internal_CompileBase
|
||||
}
|
||||
// wrong nesting of tags
|
||||
$compiler->trigger_template_error("unclosed '{$compiler->smarty->left_delimiter}{$_openTag}{$compiler->smarty->right_delimiter}' tag");
|
||||
|
||||
return;
|
||||
}
|
||||
// wrong nesting of tags
|
||||
$compiler->trigger_template_error('unexpected closing tag', null, true);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -103,9 +103,11 @@ class Smarty_Internal_Config_File_Compiler
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->template->compiled->file_dependency[ $this->template->source->uid ] =
|
||||
array($this->template->source->filepath,
|
||||
$this->template->source->getTimeStamp(),
|
||||
$this->template->source->type);
|
||||
array(
|
||||
$this->template->source->filepath,
|
||||
$this->template->source->getTimeStamp(),
|
||||
$this->template->source->type
|
||||
);
|
||||
if ($this->smarty->debugging) {
|
||||
if (!isset($this->smarty->_debug)) {
|
||||
$this->smarty->_debug = new Smarty_Internal_Debug();
|
||||
@@ -116,17 +118,20 @@ class Smarty_Internal_Config_File_Compiler
|
||||
/* @var Smarty_Internal_ConfigFileLexer $this ->lex */
|
||||
$this->lex = new $this->lexer_class(
|
||||
str_replace(
|
||||
array("\r\n",
|
||||
"\r"), "\n", $template->source->getContent()
|
||||
array(
|
||||
"\r\n",
|
||||
"\r"
|
||||
),
|
||||
"\n",
|
||||
$template->source->getContent()
|
||||
) . "\n",
|
||||
$this
|
||||
);
|
||||
/* @var Smarty_Internal_ConfigFileParser $this ->parser */
|
||||
$this->parser = new $this->parser_class($this->lex, $this);
|
||||
|
||||
if (function_exists('mb_internal_encoding')
|
||||
&& function_exists('ini_get')
|
||||
&& ((int) ini_get('mbstring.func_overload')) & 2
|
||||
&& ((int)ini_get('mbstring.func_overload')) & 2
|
||||
) {
|
||||
$mbEncoding = mb_internal_encoding();
|
||||
mb_internal_encoding('ASCII');
|
||||
@@ -145,7 +150,6 @@ class Smarty_Internal_Config_File_Compiler
|
||||
}
|
||||
// finish parsing process
|
||||
$this->parser->doParse(0, 0);
|
||||
|
||||
if ($mbEncoding) {
|
||||
mb_internal_encoding($mbEncoding);
|
||||
}
|
||||
@@ -157,7 +161,6 @@ class Smarty_Internal_Config_File_Compiler
|
||||
"<?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";
|
||||
|
||||
$code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
|
||||
var_export($this->config_data, true) . '); ?>';
|
||||
return $template_header . $this->template->smarty->ext->_codeFrame->create($this->template, $code);
|
||||
|
@@ -189,27 +189,43 @@ class Smarty_Internal_Configfilelexer
|
||||
public function yypushstate($state)
|
||||
{
|
||||
if ($this->yyTraceFILE) {
|
||||
fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt,
|
||||
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
|
||||
fprintf(
|
||||
$this->yyTraceFILE,
|
||||
"%sState push %s\n",
|
||||
$this->yyTracePrompt,
|
||||
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state
|
||||
);
|
||||
}
|
||||
array_push($this->_yy_stack, $this->_yy_state);
|
||||
$this->_yy_state = $state;
|
||||
if ($this->yyTraceFILE) {
|
||||
fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt,
|
||||
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
|
||||
fprintf(
|
||||
$this->yyTraceFILE,
|
||||
"%snew State %s\n",
|
||||
$this->yyTracePrompt,
|
||||
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function yypopstate()
|
||||
{
|
||||
if ($this->yyTraceFILE) {
|
||||
fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt,
|
||||
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
|
||||
fprintf(
|
||||
$this->yyTraceFILE,
|
||||
"%sState pop %s\n",
|
||||
$this->yyTracePrompt,
|
||||
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state
|
||||
);
|
||||
}
|
||||
$this->_yy_state = array_pop($this->_yy_stack);
|
||||
if ($this->yyTraceFILE) {
|
||||
fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt,
|
||||
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
|
||||
fprintf(
|
||||
$this->yyTraceFILE,
|
||||
"%snew State %s\n",
|
||||
$this->yyTracePrompt,
|
||||
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,8 +233,12 @@ class Smarty_Internal_Configfilelexer
|
||||
{
|
||||
$this->_yy_state = $state;
|
||||
if ($this->yyTraceFILE) {
|
||||
fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt,
|
||||
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
|
||||
fprintf(
|
||||
$this->yyTraceFILE,
|
||||
"%sState set %s\n",
|
||||
$this->yyTracePrompt,
|
||||
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,8 +263,11 @@ class Smarty_Internal_Configfilelexer
|
||||
}
|
||||
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');
|
||||
' an empty string. Input "' . substr(
|
||||
$this->data,
|
||||
$this->counter,
|
||||
5
|
||||
) . '... state START');
|
||||
}
|
||||
next($yymatches); // skip global match
|
||||
$this->token = key($yymatches); // token number
|
||||
@@ -340,8 +363,11 @@ class Smarty_Internal_Configfilelexer
|
||||
}
|
||||
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');
|
||||
' an empty string. Input "' . substr(
|
||||
$this->data,
|
||||
$this->counter,
|
||||
5
|
||||
) . '... state VALUE');
|
||||
}
|
||||
next($yymatches); // skip global match
|
||||
$this->token = key($yymatches); // token number
|
||||
@@ -454,8 +480,11 @@ class Smarty_Internal_Configfilelexer
|
||||
}
|
||||
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');
|
||||
' an empty string. Input "' . substr(
|
||||
$this->data,
|
||||
$this->counter,
|
||||
5
|
||||
) . '... state NAKED_STRING_VALUE');
|
||||
}
|
||||
next($yymatches); // skip global match
|
||||
$this->token = key($yymatches); // token number
|
||||
@@ -513,8 +542,11 @@ class Smarty_Internal_Configfilelexer
|
||||
}
|
||||
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');
|
||||
' an empty string. Input "' . substr(
|
||||
$this->data,
|
||||
$this->counter,
|
||||
5
|
||||
) . '... state COMMENT');
|
||||
}
|
||||
next($yymatches); // skip global match
|
||||
$this->token = key($yymatches); // token number
|
||||
@@ -582,8 +614,11 @@ class Smarty_Internal_Configfilelexer
|
||||
}
|
||||
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');
|
||||
' an empty string. Input "' . substr(
|
||||
$this->data,
|
||||
$this->counter,
|
||||
5
|
||||
) . '... state SECTION');
|
||||
}
|
||||
next($yymatches); // skip global match
|
||||
$this->token = key($yymatches); // token number
|
||||
@@ -646,8 +681,11 @@ class Smarty_Internal_Configfilelexer
|
||||
}
|
||||
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');
|
||||
' an empty string. Input "' . substr(
|
||||
$this->data,
|
||||
$this->counter,
|
||||
5
|
||||
) . '... state TRIPPLE');
|
||||
}
|
||||
next($yymatches); // skip global match
|
||||
$this->token = key($yymatches); // token number
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user