...
 
Commits (4)
...@@ -2,7 +2,14 @@ ...@@ -2,7 +2,14 @@
This file contains a brief description of new features which have been added to Smarty 3.1 This file contains a brief description of new features which have been added to Smarty 3.1
Smarty 3.1.32 New tags for inheritance parent and child Smarty 3.1.33-dev
Variable capture name in Smarty special variable
================================================
{$smarty.capture.$foo} can now be used to access the content of a named
capture block
Smarty 3.1.32
New tags for inheritance parent and child
========================================= =========================================
{parent} == {$smarty.block.parent} {parent} == {$smarty.block.parent}
{child} == {$smarty.block.child} {child} == {$smarty.block.child}
......
===== 3.1.32 ===== (24.04.2018) ===== 3.1.33-dev-7 =====
26.08.2018
- bugfix/enhancement {capture} allow variable as capture block name in Smarty special variable
like $smarty.capture.$foo https://github.com/smarty-php/smarty/issues/478 https://github.com/smarty-php/smarty/pull/481
===== 3.1.33-dev-6 =====
19.08.2018
- fix PSR-2 coding standards and PHPDoc blocks https://github.com/smarty-php/smarty/pull/452
https://github.com/smarty-php/smarty/pull/475
https://github.com/smarty-php/smarty/pull/473
- bugfix PHP5.2 compatibility https://github.com/smarty-php/smarty/pull/472
===== 3.1.33-dev-4 =====
17.05.2018
- bugfix strip-block produces different output in Smarty v3.1.32 https://github.com/smarty-php/smarty/issues/436
- bugfix Smarty::compileAllTemplates ignores `$extension` parameter https://github.com/smarty-php/smarty/issues/437
https://github.com/smarty-php/smarty/pull/438
- improvement do not compute total property in {foreach} if not needed https://github.com/smarty-php/smarty/issues/443
- bugfix plugins may not be loaded when setMergeCompiledIncludes is true https://github.com/smarty-php/smarty/issues/435
26.04.2018
- bugfix regarding Security Vulnerability did not solve the problem under Linux.
===== 3.1.32 ===== (24.04.2018)
24.04.2018 24.04.2018
- bugfix possible Security Vulnerability in Smarty_Security class. - bugfix possible Security Vulnerability in Smarty_Security class.
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
"name": "smarty/smarty", "name": "smarty/smarty",
"type": "library", "type": "library",
"description": "Smarty - the compiling PHP template engine", "description": "Smarty - the compiling PHP template engine",
"keywords": ["templating"], "keywords": [
"templating"
],
"homepage": "http://www.smarty.net", "homepage": "http://www.smarty.net",
"license": "LGPL-3.0", "license": "LGPL-3.0",
"authors": [ "authors": [
...@@ -28,12 +30,13 @@ ...@@ -28,12 +30,13 @@
"php": ">=5.2" "php": ">=5.2"
}, },
"autoload": { "autoload": {
"files": ["libs/bootstrap.php"] "files": [
"libs/bootstrap.php"
]
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "3.1.x-dev" "dev-master": "3.1.x-dev"
} }
} }
}
} \ No newline at end of file
smarty3 (3.1.33+20180830.1.3a78a21f+selfpack1-1) unstable; urgency=medium
* New upstream release.
- CVE-2018-16831: Don't bypass trusted directories with "../". (Closes:
#908698).
* debian/control:
+ Bump Standards-Version: to 4.2.1. No changes needed.
-- Mike Gabriel <sunweaver@debian.org> Mon, 17 Sep 2018 13:04:18 +0200
smarty3 (3.1.32+20180424.1.ac9d4b58+selfpack1-1) unstable; urgency=medium smarty3 (3.1.32+20180424.1.ac9d4b58+selfpack1-1) unstable; urgency=medium
* New upstream release. * New upstream release.
......
...@@ -8,7 +8,7 @@ Build-Depends: ...@@ -8,7 +8,7 @@ Build-Depends:
debhelper (>= 11~), debhelper (>= 11~),
pkg-php-tools (>= 1.7~), pkg-php-tools (>= 1.7~),
smarty-lexer (>= 3.1.30+dfsg1-1.1~), smarty-lexer (>= 3.1.30+dfsg1-1.1~),
Standards-Version: 4.1.4 Standards-Version: 4.2.1
Vcs-Git: https://salsa.debian.org/debian/smarty3.git Vcs-Git: https://salsa.debian.org/debian/smarty3.git
Vcs-Browser: https://salsa.debian.org/debian/smarty3 Vcs-Browser: https://salsa.debian.org/debian/smarty3
Homepage: http://www.smarty.net/ Homepage: http://www.smarty.net/
......
...@@ -17,11 +17,15 @@ $smarty->cache_lifetime = 120; ...@@ -17,11 +17,15 @@ $smarty->cache_lifetime = 120;
$smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true); $smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true);
$smarty->assign("FirstName", array("John", "Mary", "James", "Henry")); $smarty->assign("FirstName", array("John", "Mary", "James", "Henry"));
$smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case")); $smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case"));
$smarty->assign("Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"), array("I", "J", "K", "L"), $smarty->assign(
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"), $smarty->assign(
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_values", array("NY", "NE", "KS", "IA", "OK", "TX"));
$smarty->assign("option_output", array("New York", "Nebraska", "Kansas", "Iowa", "Oklahoma", "Texas")); $smarty->assign("option_output", array("New York", "Nebraska", "Kansas", "Iowa", "Oklahoma", "Texas"));
......
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
*/ */
class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
{ {
/**
* Smarty_CacheResource_Apc constructor.
*
* @throws \Exception
*/
public function __construct() public function __construct()
{ {
// test if APC is present // test if APC is present
...@@ -22,7 +27,7 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore ...@@ -22,7 +27,7 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
/** /**
* Read values for a set of keys from cache * Read values for a set of keys from cache
* *
* @param array $keys list of keys to fetch * @param array $keys list of keys to fetch
* *
* @return array list of values with the given keys used as indexes * @return array list of values with the given keys used as indexes
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
...@@ -41,8 +46,8 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore ...@@ -41,8 +46,8 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
/** /**
* Save values for a set of keys to cache * Save values for a set of keys to cache
* *
* @param array $keys list of values to save * @param array $keys list of values to save
* @param int $expire expiration time * @param int $expire expiration time
* *
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
*/ */
...@@ -58,7 +63,7 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore ...@@ -58,7 +63,7 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
/** /**
* Remove values from cache * Remove values from cache
* *
* @param array $keys list of keys to delete * @param array $keys list of keys to delete
* *
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
*/ */
......
...@@ -32,7 +32,7 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore ...@@ -32,7 +32,7 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
/** /**
* Read values for a set of keys from cache * Read values for a set of keys from cache
* *
* @param array $keys list of keys to fetch * @param array $keys list of keys to fetch
* *
* @return array list of values with the given keys used as indexes * @return array list of values with the given keys used as indexes
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
...@@ -57,8 +57,8 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore ...@@ -57,8 +57,8 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
/** /**
* Save values for a set of keys to cache * Save values for a set of keys to cache
* *
* @param array $keys list of values to save * @param array $keys list of values to save
* @param int $expire expiration time * @param int $expire expiration time
* *
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
*/ */
...@@ -75,7 +75,7 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore ...@@ -75,7 +75,7 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
/** /**
* Remove values from cache * Remove values from cache
* *
* @param array $keys list of keys to delete * @param array $keys list of keys to delete
* *
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
*/ */
...@@ -96,6 +96,6 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore ...@@ -96,6 +96,6 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
*/ */
protected function purge() protected function purge()
{ {
$this->memcache->flush(); return $this->memcache->flush();
} }
} }
...@@ -33,6 +33,11 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom ...@@ -33,6 +33,11 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
protected $save; protected $save;
/**
* Smarty_CacheResource_Mysql constructor.
*
* @throws \SmartyException
*/
public function __construct() public function __construct()
{ {
try { try {
...@@ -43,19 +48,21 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom ...@@ -43,19 +48,21 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
} }
$this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id'); $this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id');
$this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id'); $this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id');
$this->save = $this->db->prepare('REPLACE INTO output_cache (id, name, cache_id, compile_id, content) $this->save = $this->db->prepare(
VALUES (:id, :name, :cache_id, :compile_id, :content)'); 'REPLACE INTO output_cache (id, name, cache_id, compile_id, content)
VALUES (:id, :name, :cache_id, :compile_id, :content)'
);
} }
/** /**
* fetch cached content and its modification time from data source * fetch cached content and its modification time from data source
* *
* @param string $id unique cache content identifier * @param string $id unique cache content identifier
* @param string $name template name * @param string $name template name
* @param string $cache_id cache id * @param string $cache_id cache id
* @param string $compile_id compile id * @param string $compile_id compile id
* @param string $content cached content * @param string $content cached content
* @param integer $mtime cache modification timestamp (epoch) * @param integer $mtime cache modification timestamp (epoch)
* *
* @return void * @return void
*/ */
...@@ -78,10 +85,10 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom ...@@ -78,10 +85,10 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
* *
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the complete cached content. * @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 $id unique cache content identifier
* @param string $name template name * @param string $name template name
* @param string $cache_id cache id * @param string $cache_id cache id
* @param string $compile_id compile id * @param string $compile_id compile id
* *
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found * @return integer|boolean timestamp (epoch) the template was modified, or false if not found
*/ */
...@@ -97,19 +104,21 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom ...@@ -97,19 +104,21 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
/** /**
* Save content to cache * Save content to cache
* *
* @param string $id unique cache content identifier * @param string $id unique cache content identifier
* @param string $name template name * @param string $name template name
* @param string $cache_id cache id * @param string $cache_id cache id
* @param string $compile_id compile id * @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration time in seconds or null * @param integer|null $exp_time seconds till expiration time in seconds or null
* @param string $content content to cache * @param string $content content to cache
* *
* @return boolean success * @return boolean success
*/ */
protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content) protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content)
{ {
$this->save->execute(array('id' => $id, 'name' => $name, 'cache_id' => $cache_id, 'compile_id' => $compile_id, $this->save->execute(
'content' => $content,)); array('id' => $id, 'name' => $name, 'cache_id' => $cache_id, 'compile_id' => $compile_id,
'content' => $content,)
);
return !!$this->save->rowCount(); return !!$this->save->rowCount();
} }
...@@ -117,10 +126,10 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom ...@@ -117,10 +126,10 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
/** /**
* Delete content from cache * Delete content from cache
* *
* @param string $name template name * @param string $name template name
* @param string $cache_id cache id * @param string $cache_id cache id
* @param string $compile_id compile id * @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration or null * @param integer|null $exp_time seconds till expiration or null
* *
* @return integer number of deleted caches * @return integer number of deleted caches
*/ */
......
...@@ -29,35 +29,30 @@ ...@@ -29,35 +29,30 @@
*/ */
class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
{ {
protected $fetchStatements = Array('default' => 'SELECT %2$s protected $fetchStatements = Array('default' => 'SELECT %2$s
FROM %1$s FROM %1$s
WHERE 1 WHERE 1
AND id = :id AND id = :id
AND cache_id IS NULL AND cache_id IS NULL
AND compile_id IS NULL', AND compile_id IS NULL',
'withCacheId' => 'SELECT %2$s 'withCacheId' => 'SELECT %2$s
FROM %1$s FROM %1$s
WHERE 1 WHERE 1
AND id = :id AND id = :id
AND cache_id = :cache_id AND cache_id = :cache_id
AND compile_id IS NULL', AND compile_id IS NULL',
'withCompileId' => 'SELECT %2$s 'withCompileId' => 'SELECT %2$s
FROM %1$s FROM %1$s
WHERE 1 WHERE 1
AND id = :id AND id = :id
AND compile_id = :compile_id AND compile_id = :compile_id
AND cache_id IS NULL', AND cache_id IS NULL',
'withCacheIdAndCompileId' => 'SELECT %2$s 'withCacheIdAndCompileId' => 'SELECT %2$s
FROM %1$s FROM %1$s
WHERE 1 WHERE 1
AND id = :id AND id = :id
AND cache_id = :cache_id AND cache_id = :cache_id
AND compile_id = :compile_id'); AND compile_id = :compile_id');
protected $insertStatement = 'INSERT INTO %s protected $insertStatement = 'INSERT INTO %s
SET id = :id, SET id = :id,
...@@ -75,15 +70,10 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom ...@@ -75,15 +70,10 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
modified = CURRENT_TIMESTAMP, modified = CURRENT_TIMESTAMP,
expire = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :expire SECOND), expire = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL :expire SECOND),
content = :content'; content = :content';
protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s'; protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s';
protected $truncateStatement = 'TRUNCATE TABLE %s'; protected $truncateStatement = 'TRUNCATE TABLE %s';
protected $fetchColumns = 'modified, content'; protected $fetchColumns = 'modified, content';
protected $fetchTimestampColumns = 'modified'; protected $fetchTimestampColumns = 'modified';
protected $pdo, $table, $database; protected $pdo, $table, $database;
/* /*
...@@ -93,17 +83,23 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom ...@@ -93,17 +83,23 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
* @param string $table : table (or view) name * @param string $table : table (or view) name
* @param string $database : optional - if table is located in another db * @param string $database : optional - if table is located in another db
*/ */
/**
* Smarty_CacheResource_Pdo constructor.
*
* @param \PDO $pdo
* @param $table
* @param null $database
*
* @throws \SmartyException
*/
public function __construct(PDO $pdo, $table, $database = null) public function __construct(PDO $pdo, $table, $database = null)
{ {
if (is_null($table)) { if (is_null($table)) {
throw new SmartyException("Table name for caching can't be null"); throw new SmartyException("Table name for caching can't be null");
} }
$this->pdo = $pdo; $this->pdo = $pdo;
$this->table = $table; $this->table = $table;
$this->database = $database; $this->database = $database;
$this->fillStatementsWithTableName(); $this->fillStatementsWithTableName();
} }
...@@ -115,15 +111,12 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom ...@@ -115,15 +111,12 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
*/ */
protected function fillStatementsWithTableName() protected function fillStatementsWithTableName()
{ {
foreach ($this->fetchStatements AS &$statement) { foreach ($this->fetchStatements AS &$statement) {
$statement = sprintf($statement, $this->getTableName(), '%s'); $statement = sprintf($statement, $this->getTableName(), '%s');
} }
$this->insertStatement = sprintf($this->insertStatement, $this->getTableName()); $this->insertStatement = sprintf($this->insertStatement, $this->getTableName());
$this->deleteStatement = sprintf($this->deleteStatement, $this->getTableName(), '%s'); $this->deleteStatement = sprintf($this->deleteStatement, $this->getTableName(), '%s');
$this->truncateStatement = sprintf($this->truncateStatement, $this->getTableName()); $this->truncateStatement = sprintf($this->truncateStatement, $this->getTableName());
return $this; return $this;
} }
...@@ -138,7 +131,6 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom ...@@ -138,7 +131,6 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
*/ */
protected function getFetchStatement($columns, $id, $cache_id = null, $compile_id = null) protected function getFetchStatement($columns, $id, $cache_id = null, $compile_id = null)
{ {
if (!is_null($cache_id) && !is_null($compile_id)) { if (!is_null($cache_id) && !is_null($compile_id)) {
$query = $this->fetchStatements[ 'withCacheIdAndCompileId' ] AND $query = $this->fetchStatements[ 'withCacheIdAndCompileId' ] AND
$args = Array('id' => $id, 'cache_id' => $cache_id, 'compile_id' => $compile_id); $args = Array('id' => $id, 'cache_id' => $cache_id, 'compile_id' => $compile_id);
...@@ -150,39 +142,33 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom ...@@ -150,39 +142,33 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
} else { } else {
$query = $this->fetchStatements[ 'default' ] AND $args = Array('id' => $id); $query = $this->fetchStatements[ 'default' ] AND $args = Array('id' => $id);
} }
$query = sprintf($query, $columns); $query = sprintf($query, $columns);
$stmt = $this->pdo->prepare($query); $stmt = $this->pdo->prepare($query);
foreach ($args AS $key => $value) { foreach ($args AS $key => $value) {
$stmt->bindValue($key, $value); $stmt->bindValue($key, $value);
} }
return $stmt; return $stmt;
} }
/** /**
* fetch cached content and its modification time from data source * fetch cached content and its modification time from data source
* *
* @param string $id unique cache content identifier * @param string $id unique cache content identifier
* @param string $name template name * @param string $name template name
* @param string|null $cache_id cache id * @param string|null $cache_id cache id
* @param string|null $compile_id compile id * @param string|null $compile_id compile id
* @param string $content cached content * @param string $content cached content
* @param integer $mtime cache modification timestamp (epoch) * @param integer $mtime cache modification timestamp (epoch)
* *
* @return void * @return void
* @access protected * @access protected
*/ */
protected function fetch($id, $name, $cache_id = null, $compile_id = null, &$content, &$mtime) protected function fetch($id, $name, $cache_id = null, $compile_id = null, &$content, &$mtime)
{ {
$stmt = $this->getFetchStatement($this->fetchColumns, $id, $cache_id, $compile_id); $stmt = $this->getFetchStatement($this->fetchColumns, $id, $cache_id, $compile_id);
$stmt->execute(); $stmt->execute();
$row = $stmt->fetch(); $row = $stmt->fetch();
$stmt->closeCursor(); $stmt->closeCursor();
if ($row) { if ($row) {
$content = $this->outputContent($row[ 'content' ]); $content = $this->outputContent($row[ 'content' ]);
$mtime = strtotime($row[ 'modified' ]); $mtime = strtotime($row[ 'modified' ]);
...@@ -197,10 +183,10 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom ...@@ -197,10 +183,10 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
* {@internal implementing this method is optional. * {@internal implementing this method is optional.
* Only implement it if modification times can be accessed faster than loading the complete cached content.}} * 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 $id unique cache content identifier
* @param string $name template name * @param string $name template name
* @param string|null $cache_id cache id * @param string|null $cache_id cache id
* @param string|null $compile_id compile id * @param string|null $compile_id compile id
* *
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found * @return integer|boolean timestamp (epoch) the template was modified, or false if not found
* @access protected * @access protected
...@@ -212,7 +198,6 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom ...@@ -212,7 +198,6 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
// $stmt -> closeCursor(); // $stmt -> closeCursor();
// return $mtime; // return $mtime;
// } // }
/** /**
* Save content to cache * Save content to cache
* *
...@@ -228,17 +213,14 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom ...@@ -228,17 +213,14 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
*/ */
protected function save($id, $name, $cache_id = null, $compile_id = null, $exp_time, $content) protected function save($id, $name, $cache_id = null, $compile_id = null, $exp_time, $content)
{ {
$stmt = $this->pdo->prepare($this->insertStatement); $stmt = $this->pdo->prepare($this->insertStatement);
$stmt->bindValue('id', $id); $stmt->bindValue('id', $id);
$stmt->bindValue('name', $name); $stmt->bindValue('name', $name);
$stmt->bindValue('cache_id', $cache_id, (is_null($cache_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR); $stmt->bindValue('cache_id', $cache_id, (is_null($cache_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
$stmt->bindValue('compile_id', $compile_id, (is_null($compile_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR); $stmt->bindValue('compile_id', $compile_id, (is_null($compile_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
$stmt->bindValue('expire', (int) $exp_time, PDO::PARAM_INT); $stmt->bindValue('expire', (int)$exp_time, PDO::PARAM_INT);
$stmt->bindValue('content', $this->inputContent($content)); $stmt->bindValue('content', $this->inputContent($content));
$stmt->execute(); $stmt->execute();
return !!$stmt->rowCount(); return !!$stmt->rowCount();
} }
...@@ -272,19 +254,18 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom ...@@ -272,19 +254,18 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
* @param string|null $name template name * @param string|null $name template name
* @param string|null $cache_id cache id * @param string|null $cache_id cache id
* @param string|null $compile_id compile 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 * @return integer number of deleted caches
* @access protected * @access protected
*/ */
protected function delete($name = null, $cache_id = null, $compile_id = null, $exp_time = null) protected function delete($name = null, $cache_id = null, $compile_id = null, $exp_time = null)
{ {
// delete the whole cache
// delete the whole cache
if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) { 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); $this->pdo->query($this->truncateStatement);
return - 1; return -1;
} }
// build the filter // build the filter
$where = array(); $where = array();
...@@ -324,4 +305,4 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom ...@@ -324,4 +305,4 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
return (is_null($this->database)) ? "`{$this->table}`" : "`{$this->database}`.`{$this->table}`"; return (is_null($this->database)) ? "`{$this->table}`" : "`{$this->database}`.`{$this->table}`";
} }
} }
\ No newline at end of file
...@@ -40,4 +40,4 @@ class Smarty_CacheResource_Pdo_Gzip extends Smarty_CacheResource_Pdo ...@@ -40,4 +40,4 @@ class Smarty_CacheResource_Pdo_Gzip extends Smarty_CacheResource_Pdo
return gzinflate($content); return gzinflate($content);
} }
} }
\ No newline at end of file
...@@ -13,8 +13,8 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends ...@@ -13,8 +13,8 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
/** /**
* populate Source Object with meta data from Resource * populate Source Object with meta data from Resource
* *
* @param Smarty_Template_Source $source source object * @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object * @param Smarty_Internal_Template $_template template object
* *
* @return void * @return void
*/ */
......
...@@ -28,6 +28,11 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom ...@@ -28,6 +28,11 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
// prepared fetchTimestamp() statement // prepared fetchTimestamp() statement
protected $mtime; protected $mtime;
/**
* Smarty_Resource_Mysql constructor.
*
* @throws \SmartyException
*/
public function __construct() public function __construct()
{ {
try { try {
...@@ -43,9 +48,9 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom ...@@ -43,9 +48,9 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
/** /**
* Fetch a template and its modification time from database * Fetch a template and its modification time from database
* *
* @param string $name template name * @param string $name template name
* @param string $source template source * @param string $source template source
* @param integer $mtime template modification timestamp (epoch) * @param integer $mtime template modification timestamp (epoch)
* *
* @return void * @return void
*/ */
...@@ -68,7 +73,7 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom ...@@ -68,7 +73,7 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
* *
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source. * @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source.
* *
* @param string $name template name * @param string $name template name
* *
* @return integer timestamp (epoch) the template was modified * @return integer timestamp (epoch) the template was modified
*/ */
......
...@@ -27,6 +27,11 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom ...@@ -27,6 +27,11 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
// prepared fetch() statement // prepared fetch() statement
protected $fetch; protected $fetch;
/**
* Smarty_Resource_Mysqls constructor.
*
* @throws \SmartyException
*/
public function __construct() public function __construct()
{ {
try { try {
...@@ -41,9 +46,9 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom ...@@ -41,9 +46,9 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
/** /**
* Fetch a template and its modification time from database * Fetch a template and its modification time from database
* *
* @param string $name template name * @param string $name template name
* @param string $source template source * @param string $source template source
* @param integer $mtime template modification timestamp (epoch) * @param integer $mtime template modification timestamp (epoch)
* *
* @return void * @return void
*/ */
......
...@@ -124,7 +124,7 @@ class Smarty_Internal_Configfilelexer ...@@ -124,7 +124,7 @@ class Smarty_Internal_Configfilelexer
* @param string $data template source * @param string $data template source
* @param Smarty_Internal_Config_File_Compiler $compiler * @param Smarty_Internal_Config_File_Compiler $compiler
*/ */
function __construct($data, Smarty_Internal_Config_File_Compiler $compiler) public function __construct($data, Smarty_Internal_Config_File_Compiler $compiler)
{ {
$this->data = $data . "\n"; //now all lines are \n-terminated $this->data = $data . "\n"; //now all lines are \n-terminated
$this->dataLength = strlen($data); $this->dataLength = strlen($data);
......
...@@ -89,7 +89,7 @@ class Smarty_Internal_Configfileparser ...@@ -89,7 +89,7 @@ class Smarty_Internal_Configfileparser
* @param Smarty_Internal_Configfilelexer $lex * @param Smarty_Internal_Configfilelexer $lex
* @param Smarty_Internal_Config_File_Compiler $compiler * @param Smarty_Internal_Config_File_Compiler $compiler
*/ */
function __construct(Smarty_Internal_Configfilelexer $lex, Smarty_Internal_Config_File_Compiler $compiler) public function __construct(Smarty_Internal_Configfilelexer $lex, Smarty_Internal_Config_File_Compiler $compiler)
{ {
$this->lex = $lex; $this->lex = $lex;
$this->smarty = $compiler->smarty; $this->smarty = $compiler->smarty;
......
...@@ -215,7 +215,7 @@ class Smarty_Internal_Templatelexer ...@@ -215,7 +215,7 @@ class Smarty_Internal_Templatelexer
* @param string $source template source * @param string $source template source
* @param Smarty_Internal_TemplateCompilerBase $compiler * @param Smarty_Internal_TemplateCompilerBase $compiler
*/ */
function __construct($source, Smarty_Internal_TemplateCompilerBase $compiler) public function __construct($source, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$this->data = $source; $this->data = $source;
$this->dataLength = strlen($this->data); $this->dataLength = strlen($this->data);
......
...@@ -147,7 +147,7 @@ class Smarty_Internal_Templateparser ...@@ -147,7 +147,7 @@ class Smarty_Internal_Templateparser
* @param Smarty_Internal_Templatelexer $lex * @param Smarty_Internal_Templatelexer $lex
* @param Smarty_Internal_TemplateCompilerBase $compiler * @param Smarty_Internal_TemplateCompilerBase $compiler
*/ */
function __construct(Smarty_Internal_Templatelexer $lex, Smarty_Internal_TemplateCompilerBase $compiler) public function __construct(Smarty_Internal_Templatelexer $lex, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$this->lex = $lex; $this->lex = $lex;
$this->compiler = $compiler; $this->compiler = $compiler;
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
/** /**
* Smarty Autoloader * Smarty Autoloader
* *
* @package Smarty * @package Smarty
*/ */
/** /**
* Smarty Autoloader * Smarty Autoloader
* *
* @package Smarty * @package Smarty
* @author Uwe Tews * @author Uwe Tews
* Usage: * Usage:
* require_once '...path/Autoloader.php'; * require_once '...path/Autoloader.php';
* Smarty_Autoloader::register(); * Smarty_Autoloader::register();
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
class Smarty_Autoloader class Smarty_Autoloader
{ {
/** /**
* Filepath to Smarty root * Filepath to Smarty root
* *
* @var string * @var string
...@@ -54,8 +54,8 @@ class Smarty_Autoloader ...@@ -54,8 +54,8 @@ class Smarty_Autoloader
if (!defined('SMARTY_SPL_AUTOLOAD')) { if (!defined('SMARTY_SPL_AUTOLOAD')) {
define('SMARTY_SPL_AUTOLOAD', 0); 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 && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
) { ) {
$registeredAutoLoadFunctions = spl_autoload_functions(); $registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) { if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {
......
This diff is collapsed.
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
/** /**
* @ignore * @ignore
*/ */
require_once(dirname(__FILE__) . '/Smarty.class.php'); require_once dirname(__FILE__) . '/Smarty.class.php';
/** /**
* Smarty Backward Compatibility Wrapper Class * Smarty Backward Compatibility Wrapper Class
...@@ -53,7 +53,6 @@ class SmartyBC extends Smarty ...@@ -53,7 +53,6 @@ class SmartyBC extends Smarty
/** /**
* Initialize new SmartyBC object * Initialize new SmartyBC object
*
*/ */
public function __construct() public function __construct()
{ {
...@@ -127,12 +126,12 @@ class SmartyBC extends Smarty ...@@ -127,12 +126,12 @@ class SmartyBC extends Smarty
* @param boolean $smarty_args smarty argument format, else traditional * @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_methods list of methods that are block format * @param array $block_methods list of methods that are block format
* *
* @throws SmartyException * @throws SmartyException
* @internal param array $block_functs list of methods that are block format * @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()) $block_methods = array()
{ ) {
settype($allowed, 'array'); settype($allowed, 'array');
settype($smarty_args, 'boolean'); settype($smarty_args, 'boolean');
$this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods); $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
...@@ -151,8 +150,8 @@ class SmartyBC extends Smarty ...@@ -151,8 +150,8 @@ class SmartyBC extends Smarty
/** /**
* Registers block function to be used in templates * Registers block function to be used in templates
* *
* @param string $block name of template block * @param string $block name of template block
* @param string $block_impl PHP function to register * @param string $block_impl PHP function to register
* @param bool $cacheable * @param bool $cacheable
* @param mixed $cache_attrs * @param mixed $cache_attrs
* *
...@@ -326,10 +325,10 @@ class SmartyBC extends Smarty ...@@ -326,10 +325,10 @@ class SmartyBC extends Smarty
/** /**
* clear cached content for the given template and cache id * clear cached content for the given template and cache id
* *
* @param string $tpl_file name of template file * @param string $tpl_file name of template file
* @param string $cache_id name of cache_id * @param string $cache_id name of cache_id
* @param string $compile_id name of compile_id * @param string $compile_id name of compile_id
* @param string $exp_time expiration time * @param string $exp_time expiration time
* *
* @return boolean * @return boolean
*/ */
...@@ -341,7 +340,7 @@ class SmartyBC extends Smarty ...@@ -341,7 +340,7 @@ class SmartyBC extends Smarty
/** /**
* clear the entire contents of cache (all templates) * clear the entire contents of cache (all templates)
* *
* @param string $exp_time expire time * @param string $exp_time expire time
* *
* @return boolean * @return boolean
*/ */
...@@ -353,9 +352,9 @@ class SmartyBC extends Smarty ...@@ -353,9 +352,9 @@ class SmartyBC extends Smarty
/** /**
* test to see if valid cache exists for this template * 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 $cache_id
* @param string $compile_id * @param string $compile_id
* *
* @return bool * @return bool
* @throws \Exception * @throws \Exception
...@@ -379,9 +378,9 @@ class SmartyBC extends Smarty ...@@ -379,9 +378,9 @@ class SmartyBC extends Smarty
* or all compiled template files if one is not specified. * or all compiled template files if one is not specified.
* This function is for advanced use only, not normally needed. * This function is for advanced use only, not normally needed.
* *
* @param string $tpl_file * @param string $tpl_file
* @param string $compile_id * @param string $compile_id
* @param string $exp_time * @param string $exp_time
* *
* @return boolean results of {@link smarty_core_rm_auto()} * @return boolean results of {@link smarty_core_rm_auto()}
*/ */
...@@ -393,7 +392,7 @@ class SmartyBC extends Smarty ...@@ -393,7 +392,7 @@ class SmartyBC extends Smarty
/** /**
* Checks whether requested template exists. * Checks whether requested template exists.
* *
* @param string $tpl_file * @param string $tpl_file
* *
* @return bool * @return bool
* @throws \SmartyException * @throws \SmartyException
...@@ -406,7 +405,7 @@ class SmartyBC extends Smarty ...@@ -406,7 +405,7 @@ class SmartyBC extends Smarty
/** /**
* Returns an array containing template variables * Returns an array containing template variables
* *
* @param string $name * @param string $name
* *
* @return array * @return array
*/ */
...@@ -418,7 +417,7 @@ class SmartyBC extends Smarty ...@@ -418,7 +417,7 @@ class SmartyBC extends Smarty
/** /**
* Returns an array containing config variables * Returns an array containing config variables
* *
* @param string $name * @param string $name
* *
* @return array * @return array
*/ */
...@@ -442,7 +441,7 @@ class SmartyBC extends Smarty ...@@ -442,7 +441,7 @@ class SmartyBC extends Smarty
/** /**
* return a reference to a registered object * return a reference to a registered object
* *
* @param string $name * @param string $name
* *
* @return object * @return object
*/ */
......
...@@ -12,6 +12,6 @@ ...@@ -12,6 +12,6 @@
* Load and register Smarty Autoloader * Load and register Smarty Autoloader
*/ */
if (!class_exists('Smarty_Autoloader')) { if (!class_exists('Smarty_Autoloader')) {
require dirname(__FILE__) . '/Autoloader.php'; include dirname(__FILE__) . '/Autoloader.php';
} }
Smarty_Autoloader::register(true); Smarty_Autoloader::register(true);
...@@ -127,7 +127,7 @@ ...@@ -127,7 +127,7 @@
{foreach $assigned_vars as $vars} {foreach $assigned_vars as $vars}
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}"> <tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
<td><h3><font color=blue>${$vars@key}</font></h3> <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} {if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if}
</td> </td>
<td><h3>Value</h3>{$vars['value']|debug_print_var:10:80 nofilter}</td> <td><h3>Value</h3>{$vars['value']|debug_print_var:10:80 nofilter}</td>
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
* - indent_char - string (" ") * - indent_char - string (" ")
* - wrap_boundary - boolean (true) * - wrap_boundary - boolean (true)
* *
*
* @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat} * @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat}
* (Smarty online manual) * (Smarty online manual)
* *
...@@ -39,10 +38,11 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te ...@@ -39,10 +38,11 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
return; return;
} }
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
$template->_checkPlugins(array(array('function' => 'smarty_modifier_mb_wordwrap', $template->_checkPlugins(
'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; $style = null;
$indent = 0; $indent = 0;
$indent_first = 0; $indent_first = 0;
...@@ -51,47 +51,44 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te ...@@ -51,47 +51,44 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
$wrap_char = "\n"; $wrap_char = "\n";
$wrap_cut = false; $wrap_cut = false;
$assign = null; $assign = null;
foreach ($params as $_key => $_val) { foreach ($params as $_key => $_val) {
switch ($_key) { switch ($_key) {
case 'style': case 'style':
case 'indent_char': case 'indent_char':
case 'wrap_char': case 'wrap_char':
case 'assign': case 'assign':
$$_key = (string) $_val; $$_key = (string)$_val;
break; break;
case 'indent': case 'indent':
case 'indent_first': case 'indent_first':
case 'wrap': case 'wrap':
$$_key = (int) $_val; $$_key = (int)$_val;
break; break;
case 'wrap_cut': case 'wrap_cut':
$$_key = (bool) $_val; $$_key = (bool)$_val;
break; break;
default: default:
trigger_error("textformat: unknown attribute '{$_key}'"); trigger_error("textformat: unknown attribute '{$_key}'");
} }
} }
if ($style === 'email') { if ($style === 'email') {
$wrap = 72; $wrap = 72;
} }
// split into paragraphs // split into paragraphs
$_paragraphs = preg_split('![\r\n]{2}!', $content); $_paragraphs = preg_split('![\r\n]{2}!', $content);
foreach ($_paragraphs as &$_paragraph) { foreach ($_paragraphs as &$_paragraph) {
if (!$_paragraph) { if (!$_paragraph) {
continue; continue;
} }
// convert mult. spaces & special chars to single space // convert mult. spaces & special chars to single space
$_paragraph = $_paragraph =
preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, preg_replace(
'!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), array('!\s+!' . Smarty::$_UTF8_MODIFIER,
array(' ', '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER),
''), $_paragraph); array(' ',
''),
$_paragraph
);
// indent first line // indent first line
if ($indent_first > 0) { if ($indent_first > 0) {
$_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph; $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;
...@@ -108,7 +105,6 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te ...@@ -108,7 +105,6 @@ function smarty_block_textformat($params, $content, Smarty_Internal_Template $te
} }
} }
$_output = implode($wrap_char . $wrap_char, $_paragraphs); $_output = implode($wrap_char . $wrap_char, $_paragraphs);
if ($assign) { if ($assign) {
$template->assign($assign, $_output); $template->assign($assign, $_output);
} else { } else {
......
...@@ -29,14 +29,13 @@ ...@@ -29,14 +29,13 @@
* {cycle name=row values="one,two,three" reset=true} * {cycle name=row values="one,two,three" reset=true}
* {cycle name=row} * {cycle name=row}
* *
* * @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle}
* @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle}
* (Smarty online manual) * (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Mark Priatel <mpriatel@rogers.com> * @author credit to Mark Priatel <mpriatel@rogers.com>
* @author credit to Gerard <gerard@interfold.com> * @author credit to Gerard <gerard@interfold.com>
* @author credit to Jason Sweat <jsweat_php@yahoo.com> * @author credit to Jason Sweat <jsweat_php@yahoo.com>
* @version 1.3 * @version 1.3
* *
* @param array $params parameters * @param array $params parameters
* @param Smarty_Internal_Template $template template object * @param Smarty_Internal_Template $template template object
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {fetch} plugin * Smarty {fetch} plugin
* Type: function * Type: function
...@@ -26,20 +25,16 @@ function smarty_function_fetch($params, $template) ...@@ -26,20 +25,16 @@ function smarty_function_fetch($params, $template)
{ {
if (empty($params[ 'file' ])) { if (empty($params[ 'file' ])) {
trigger_error('[plugin] fetch parameter \'file\' cannot be empty', E_USER_NOTICE); trigger_error('[plugin] fetch parameter \'file\' cannot be empty', E_USER_NOTICE);
return; return;
} }
// strip file protocol // strip file protocol
if (stripos($params[ 'file' ], 'file://') === 0) { if (stripos($params[ 'file' ], 'file://') === 0) {
$params[ 'file' ] = substr($params[ 'file' ], 7); $params[ 'file' ] = substr($params[ 'file' ], 7);
} }
$protocol = strpos($params[ 'file' ], '://'); $protocol = strpos($params[ 'file' ], '://');
if ($protocol !== false) { if ($protocol !== false) {
$protocol = strtolower(substr($params[ 'file' ], 0, $protocol)); $protocol = strtolower(substr($params[ 'file' ], 0, $protocol));
} }
if (isset($template->smarty->security_policy)) { if (isset($template->smarty->security_policy)) {
if ($protocol) { if ($protocol) {
// remote resource (or php stream, …) // remote resource (or php stream, …)
...@@ -53,7 +48,6 @@ function smarty_function_fetch($params, $template) ...@@ -53,7 +48,6 @@ function smarty_function_fetch($params, $template)
} }
} }
} }
$content = ''; $content = '';
if ($protocol === 'http') { if ($protocol === 'http') {
// http fetch // http fetch
...@@ -104,7 +98,6 @@ function smarty_function_fetch($params, $template) ...@@ -104,7 +98,6 @@ function smarty_function_fetch($params, $template)
if (!empty($param_value)) { if (!empty($param_value)) {
if (!preg_match('![\w\d-]+: .+!', $param_value)) { if (!preg_match('![\w\d-]+: .+!', $param_value)) {
trigger_error("[plugin] invalid header format '{$param_value}'", E_USER_NOTICE); trigger_error("[plugin] invalid header format '{$param_value}'", E_USER_NOTICE);
return; return;
} else { } else {
$extra_headers[] = $param_value; $extra_headers[] = $param_value;
...@@ -118,10 +111,9 @@ function smarty_function_fetch($params, $template) ...@@ -118,10 +111,9 @@ function smarty_function_fetch($params, $template)
break; break;
case 'proxy_port': case 'proxy_port':
if (!preg_match('!\D!', $param_value)) { if (!preg_match('!\D!', $param_value)) {
$proxy_port = (int) $param_value; $proxy_port = (int)$param_value;
} else { } else {
trigger_error("[plugin] invalid value for attribute '{$param_key }'", E_USER_NOTICE); trigger_error("[plugin] invalid value for attribute '{$param_key }'", E_USER_NOTICE);
return; return;
} }
break; break;
...@@ -137,16 +129,14 @@ function smarty_function_fetch($params, $template) ...@@ -137,16 +129,14 @@ function smarty_function_fetch($params, $template)
break; break;
case 'timeout': case 'timeout':
if (!preg_match('!\D!', $param_value)) { if (!preg_match('!\D!', $param_value)) {
$timeout = (int) $param_value; $timeout = (int)$param_value;
} else { } else {
trigger_error("[plugin] invalid value for attribute '{$param_key}'", E_USER_NOTICE); trigger_error("[plugin] invalid value for attribute '{$param_key}'", E_USER_NOTICE);
return; return;
} }
break; break;
default: default:
trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE); trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE);
return; return;
} }
} }
...@@ -156,10 +146,8 @@ function smarty_function_fetch($params, $template) ...@@ -156,10 +146,8 @@ function smarty_function_fetch($params, $template)
} else { } else {
$fp = fsockopen($server_name, $port, $errno, $errstr, $timeout); $fp = fsockopen($server_name, $port, $errno, $errstr, $timeout);
} }
if (!$fp) { if (!$fp) {
trigger_error("[plugin] unable to fetch: $errstr ($errno)", E_USER_NOTICE); trigger_error("[plugin] unable to fetch: $errstr ($errno)", E_USER_NOTICE);
return; return;
} else { } else {
if ($_is_proxy) { if ($_is_proxy) {
...@@ -187,23 +175,19 @@ function smarty_function_fetch($params, $template) ...@@ -187,23 +175,19 @@ function smarty_function_fetch($params, $template)
if (!empty($user) && !empty($pass)) { if (!empty($user) && !empty($pass)) {
fputs($fp, 'Authorization: BASIC ' . base64_encode("$user:$pass") . "\r\n"); fputs($fp, 'Authorization: BASIC ' . base64_encode("$user:$pass") . "\r\n");
} }
fputs($fp, "\r\n"); fputs($fp, "\r\n");
while (!feof($fp)) { while (!feof($fp)) {
$content .= fgets($fp, 4096); $content .= fgets($fp, 4096);
} }
fclose($fp); fclose($fp);
$csplit = preg_split("!\r\n\r\n!", $content, 2); $csplit = preg_split("!\r\n\r\n!", $content, 2);
$content = $csplit[ 1 ]; $content = $csplit[ 1 ];
if (!empty($params[ 'assign_headers' ])) { if (!empty($params[ 'assign_headers' ])) {
$template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ])); $template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ]));
} }
} }
} else { } else {
trigger_error("[plugin fetch] unable to parse URL, check syntax", E_USER_NOTICE); trigger_error("[plugin fetch] unable to parse URL, check syntax", E_USER_NOTICE);
return; return;
} }
} else { } else {
...@@ -212,7 +196,6 @@ function smarty_function_fetch($params, $template) ...@@ -212,7 +196,6 @@ function smarty_function_fetch($params, $template)
throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'"); throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'");
} }
} }
if (!empty($params[ 'assign' ])) { if (!empty($params[ 'assign' ])) {
$template->assign($params[ 'assign' ], $content); $template->assign($params[ 'assign' ], $content);
} else { } else {
......
This diff is collapsed.
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_image} function plugin * Smarty {html_image} function plugin
* Type: function * Type: function
...@@ -22,7 +21,6 @@ ...@@ -22,7 +21,6 @@
* - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT * - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT
* - path_prefix - prefix for path output (optional, default empty) * - path_prefix - prefix for path output (optional, default empty)
* *
*
* @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image} * @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image}
* (Smarty online manual) * (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
...@@ -38,9 +36,10 @@ ...@@ -38,9 +36,10 @@
*/ */
function smarty_function_html_image($params, Smarty_Internal_Template $template) function smarty_function_html_image($params, Smarty_Internal_Template $template)
{ {
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', $template->_checkPlugins(
'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 = ''; $alt = '';
$file = ''; $file = '';
$height = ''; $height = '';
...@@ -60,53 +59,46 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template) ...@@ -60,53 +59,46 @@ function smarty_function_html_image($params, Smarty_Internal_Template $template)
case 'basedir': case 'basedir':
$$_key = $_val; $$_key = $_val;
break; break;
case 'alt': case 'alt':
if (!is_array($_val)) { if (!is_array($_val)) {
$$_key = smarty_function_escape_special_chars($_val); $$_key = smarty_function_escape_special_chars($_val);
} else { } 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; break;
case 'link': case 'link':
case 'href': case 'href':
$prefix = '<a href="' . $_val . '">'; $prefix = '<a href="' . $_val . '">';
$suffix = '</a>'; $suffix = '</a>';
break; break;
default: default:
if (!is_array($_val)) { if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
} else { } 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; break;
} }
} }
if (empty($file)) { if (empty($file)) {
trigger_error('html_image: missing \'file\' parameter', E_USER_NOTICE); trigger_error('html_image: missing \'file\' parameter', E_USER_NOTICE);
return; return;
} }
if ($file[ 0 ] === '/') { if ($file[ 0 ] === '/') {
$_image_path = $basedir . $file; $_image_path = $basedir . $file;
} else { } else {
$_image_path = $file; $_image_path = $file;
} }