Merge branch 'development' of https://github.com/PrestaShop/PrestaShop into development

This commit is contained in:
gRoussac committed 2013-07-03 15:06:05 +02:00
commit 36e3956267
57 files changed
+4548 -4434

No files matched your search

+35 -18
View File
@@ -101,7 +101,7 @@ class LinkCore
if (!is_object($product)) if (!is_object($product))
{ {
if (is_array($product) && isset($product['id_product'])) if (is_array($product) && isset($product['id_product']))
$product = new Product($product['id_product'], false, $id_lang); $product = new Product($product['id_product'], false, $id_lang);
else if (is_numeric($product) || !$product) else if (is_numeric($product) || !$product)
$product = new Product($product, false, $id_lang); $product = new Product($product, false, $id_lang);
else else
@@ -195,24 +195,28 @@ class LinkCore
* @param int $id_lang * @param int $id_lang
* @return string * @return string
*/ */
public function getCMSCategoryLink($category, $alias = null, $id_lang = null) public function getCMSCategoryLink($cms_category, $alias = null, $id_lang = null)
{ {
if (!$id_lang) if (!$id_lang)
$id_lang = Context::getContext()->language->id; $id_lang = Context::getContext()->language->id;
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (!is_object($category)) $dispatcher = Dispatcher::getInstance();
$category = new CMSCategory($category, $id_lang); if (!is_object($cms_category))
{
if ($alias !== null && !$dispatcher->hasKeyword('cms_category_rule', $id_lang, 'meta_keywords') && !$dispatcher->hasKeyword('cms_category_rule', $id_lang, 'meta_title'))
return $url.$dispatcher->createUrl('cms_category_rule', $id_lang, array('id' => (int)$cms_category, 'rewrite' => (string)$alias), $this->allow);
$cms_category = new CMSCategory($cms_category, $id_lang);
}
// Set available keywords // Set available keywords
$params = array(); $params = array();
$params['id'] = $category->id; $params['id'] = $cms_category->id;
$params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias; $params['rewrite'] = (!$alias) ? $cms_category->link_rewrite : $alias;
$params['meta_keywords'] = Tools::str2url($category->meta_keywords); $params['meta_keywords'] = Tools::str2url($cms_category->meta_keywords);
$params['meta_title'] = Tools::str2url($category->meta_title); $params['meta_title'] = Tools::str2url($cms_category->meta_title);
return $url.Dispatcher::getInstance()->createUrl('cms_category_rule', $id_lang, $params, $this->allow); return $url.$dispatcher->createUrl('cms_category_rule', $id_lang, $params, $this->allow);
} }
/** /**
@@ -232,25 +236,28 @@ class LinkCore
$id_lang = Context::getContext()->language->id; $id_lang = Context::getContext()->language->id;
$url = $base.__PS_BASE_URI__.$this->getLangLink($id_lang); $url = $base.__PS_BASE_URI__.$this->getLangLink($id_lang);
$dispatcher = Dispatcher::getInstance();
if (!is_object($cms)) if (!is_object($cms))
{
if ($alias !== null && !$dispatcher->hasKeyword('cms_rule', $id_lang, 'meta_keywords') && !$dispatcher->hasKeyword('cms_rule', $id_lang, 'meta_title'))
return $url.$dispatcher->createUrl('cms_rule', $id_lang, array('id' => (int)$cms, 'rewrite' => (string)$alias), $this->allow);
$cms = new CMS($cms, $id_lang); $cms = new CMS($cms, $id_lang);
}
// Set available keywords // Set available keywords
$params = array(); $params = array();
$params['id'] = $cms->id; $params['id'] = $cms->id;
$params['rewrite'] = (!$alias) ? (is_array($cms->link_rewrite) ? $cms->link_rewrite[(int)$id_lang] : $cms->link_rewrite) : $alias; $params['rewrite'] = (!$alias) ? (is_array($cms->link_rewrite) ? $cms->link_rewrite[(int)$id_lang] : $cms->link_rewrite) : $alias;
$params['meta_keywords'] = '';
if (isset($cms->meta_keywords) && !empty($cms->meta_keywords)) if (isset($cms->meta_keywords) && !empty($cms->meta_keywords))
$params['meta_keywords'] = is_array($cms->meta_keywords) ? Tools::str2url($cms->meta_keywords[(int)$id_lang]) : Tools::str2url($cms->meta_keywords); $params['meta_keywords'] = is_array($cms->meta_keywords) ? Tools::str2url($cms->meta_keywords[(int)$id_lang]) : Tools::str2url($cms->meta_keywords);
else
$params['meta_keywords'] = '';
$params['meta_title'] = '';
if (isset($cms->meta_title) && !empty($cms->meta_title)) if (isset($cms->meta_title) && !empty($cms->meta_title))
$params['meta_title'] = is_array($cms->meta_title) ? Tools::str2url($cms->meta_title[(int)$id_lang]) : Tools::str2url($cms->meta_title); $params['meta_title'] = is_array($cms->meta_title) ? Tools::str2url($cms->meta_title[(int)$id_lang]) : Tools::str2url($cms->meta_title);
else
$params['meta_title'] = '';
return $url.Dispatcher::getInstance()->createUrl('cms_rule', $id_lang, $params, $this->allow); return $url.$dispatcher->createUrl('cms_rule', $id_lang, $params, $this->allow);
} }
/** /**
@@ -266,9 +273,14 @@ class LinkCore
if (!$id_lang) if (!$id_lang)
$id_lang = Context::getContext()->language->id; $id_lang = Context::getContext()->language->id;
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
$dispatcher = Dispatcher::getInstance();
if (!is_object($supplier)) if (!is_object($supplier))
{
if ($alias !== null && !$dispatcher->hasKeyword('supplier_rule', $id_lang, 'meta_keywords') && !$dispatcher->hasKeyword('supplier_rule', $id_lang, 'meta_title'))
return $url.$dispatcher->createUrl('supplier_rule', $id_lang, array('id' => (int)$supplier, 'rewrite' => (string)$alias), $this->allow);
$supplier = new Supplier($supplier, $id_lang); $supplier = new Supplier($supplier, $id_lang);
}
// Set available keywords // Set available keywords
$params = array(); $params = array();
@@ -277,7 +289,7 @@ class LinkCore
$params['meta_keywords'] = Tools::str2url($supplier->meta_keywords); $params['meta_keywords'] = Tools::str2url($supplier->meta_keywords);
$params['meta_title'] = Tools::str2url($supplier->meta_title); $params['meta_title'] = Tools::str2url($supplier->meta_title);
return $url.Dispatcher::getInstance()->createUrl('supplier_rule', $id_lang, $params, $this->allow); return $url.$dispatcher->createUrl('supplier_rule', $id_lang, $params, $this->allow);
} }
/** /**
@@ -294,8 +306,13 @@ class LinkCore
$id_lang = Context::getContext()->language->id; $id_lang = Context::getContext()->language->id;
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
$dispatcher = Dispatcher::getInstance();
if (!is_object($manufacturer)) if (!is_object($manufacturer))
{
if ($alias !== null && !$dispatcher->hasKeyword('manufacturer_rule', $id_lang, 'meta_keywords') && !$dispatcher->hasKeyword('manufacturer_rule', $id_lang, 'meta_title'))
return $url.$dispatcher->createUrl('manufacturer_rule', $id_lang, array('id' => (int)$manufacturer, 'rewrite' => (string)$alias), $this->allow);
$manufacturer = new Manufacturer($manufacturer, $id_lang); $manufacturer = new Manufacturer($manufacturer, $id_lang);
}
// Set available keywords // Set available keywords
$params = array(); $params = array();
@@ -304,7 +321,7 @@ class LinkCore
$params['meta_keywords'] = Tools::str2url($manufacturer->meta_keywords); $params['meta_keywords'] = Tools::str2url($manufacturer->meta_keywords);
$params['meta_title'] = Tools::str2url($manufacturer->meta_title); $params['meta_title'] = Tools::str2url($manufacturer->meta_title);
return $url.Dispatcher::getInstance()->createUrl('manufacturer_rule', $id_lang, $params, $this->allow); return $url.$dispatcher->createUrl('manufacturer_rule', $id_lang, $params, $this->allow);
} }
/** /**
+6 -2
View File
@@ -208,9 +208,10 @@ class ProductSupplierCore extends ObjectModel
* *
* @param int $id_product * @param int $id_product
* @param int $id_product_attribute Optional * @param int $id_product_attribute Optional
* @param bool $converted_price Optional
* @return Array keys: price_te, id_currency * @return Array keys: price_te, id_currency
*/ */
public static function getProductPrice($id_supplier, $id_product, $id_product_attribute = 0) public static function getProductPrice($id_supplier, $id_product, $id_product_attribute = 0, $converted_price = false)
{ {
if (is_null($id_supplier) || is_null($id_product)) if (is_null($id_supplier) || is_null($id_product))
return; return;
@@ -222,6 +223,9 @@ class ProductSupplierCore extends ObjectModel
$query->where('id_supplier = '.(int)$id_supplier); $query->where('id_supplier = '.(int)$id_supplier);
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query); $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query);
if ($converted_price)
return Tools::convertPrice($row['price_te'], $row['id_currency']);
return $row['price_te']; return $row['price_te'];
} }
} }
+17 -1
View File
@@ -52,6 +52,21 @@ class DbMySQLiCore extends Db
return $this->link; return $this->link;
} }
public static function createDatabase($host, $user, $password, $dbname, $dropit = false)
{
if (strpos($host, ':') !== false)
{
list($host, $port) = explode(':', $host);
$link = @new mysqli($host, $this->user, $this->password, null, $port);
}
else
$link = @new mysqli($host, $user, $password);
$success = $link->query('CREATE DATABASE `'.bqSQL($dbname).'`');
if ($dropit && ($link->exec('DROP DATABASE `'.bqSQL($dbname).'`') !== false))
return true;
return $success;
}
/** /**
* @see DbCore::disconnect() * @see DbCore::disconnect()
@@ -169,7 +184,8 @@ class DbMySQLiCore extends Db
if (!$link->options(MYSQLI_OPT_CONNECT_TIMEOUT, $timeout)) if (!$link->options(MYSQLI_OPT_CONNECT_TIMEOUT, $timeout))
return 1; return 1;
if (!$link->real_connect($server, $user, $pwd, $db)) // There is an @ because mysqli throw a warning when the database does not exists
if (!@$link->real_connect($server, $user, $pwd, $db))
return (mysqli_connect_errno() == 1049) ? 2 : 1; return (mysqli_connect_errno() == 1049) ? 2 : 1;
$link->close(); $link->close();
+266 -253
View File
@@ -1,253 +1,266 @@
<?php <?php
/* /*
* 2007-2013 PrestaShop * 2007-2013 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
* This source file is subject to the Open Software License (OSL 3.0) * This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt. * that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL: * It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php * http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to * If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email * obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately. * to license@prestashop.com so we can send you a copy immediately.
* *
* DISCLAIMER * DISCLAIMER
* *
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your * versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information. * needs please refer to http://www.prestashop.com for more information.
* *
* @author PrestaShop SA <contact@prestashop.com> * @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA * @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
/** /**
* This class is currently only here for tests * This class is currently only here for tests
* *
* @since 1.5.0 * @since 1.5.0
*/ */
class DbPDOCore extends Db class DbPDOCore extends Db
{ {
protected static function _getPDO($host, $user, $password, $dbname, $timeout = 5) protected static function _getPDO($host, $user, $password, $dbname, $timeout = 5)
{ {
$dsn = 'mysql:'; $dsn = 'mysql:';
if ($dbname) if ($dbname)
$dsn .= 'dbname='.$dbname.';'; $dsn .= 'dbname='.$dbname.';';
if (preg_match('/^(.*):([0-9]+)$/', $host, $matches)) if (preg_match('/^(.*):([0-9]+)$/', $host, $matches))
$dsn .= 'host='.$matches[1].';port='.$matches[2]; $dsn .= 'host='.$matches[1].';port='.$matches[2];
elseif (preg_match('#^.*:(/.*)$#', $host, $matches)) elseif (preg_match('#^.*:(/.*)$#', $host, $matches))
$dsn .= 'unix_socket='.$matches[1]; $dsn .= 'unix_socket='.$matches[1];
else else
$dsn .= 'host='.$host; $dsn .= 'host='.$host;
return new PDO($dsn, $user, $password, array(PDO::ATTR_TIMEOUT => $timeout, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true)); return new PDO($dsn, $user, $password, array(PDO::ATTR_TIMEOUT => $timeout, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
} }
/** public static function createDatabase($host, $user, $password, $dbname, $dropit = false)
* @see DbCore::connect() {
*/ try {
public function connect() $link = DbPDO::_getPDO($host, $user, $password, false);
{ $success = $link->exec('CREATE DATABASE `'.bqSQL($dbname).'`');
try { if ($dropit && ($link->exec('DROP DATABASE `'.bqSQL($dbname).'`') !== false))
$this->link = $this->_getPDO($this->server, $this->user, $this->password, $this->database, 5); return true;
} catch (PDOException $e) { } catch (PDOException $e) {
die(sprintf(Tools::displayError('Link to database cannot be established: %s'), utf8_encode($e->getMessage()))); return false;
} }
return $success;
// UTF-8 support }
if ($this->link->exec('SET NAMES \'utf8\'') === false)
die(Tools::displayError('PrestaShop Fatal error: no utf-8 support. Please check your server configuration.')); /**
* @see DbCore::connect()
return $this->link; */
} public function connect()
{
/** try {
* @see DbCore::disconnect() $this->link = $this->_getPDO($this->server, $this->user, $this->password, $this->database, 5);
*/ } catch (PDOException $e) {
public function disconnect() die(sprintf(Tools::displayError('Link to database cannot be established: %s'), utf8_encode($e->getMessage())));
{ }
unset($this->link);
} // UTF-8 support
if ($this->link->exec('SET NAMES \'utf8\'') === false)
/** die(Tools::displayError('PrestaShop Fatal error: no utf-8 support. Please check your server configuration.'));
* @see DbCore::_query()
*/ return $this->link;
protected function _query($sql) }
{
return $this->link->query($sql); /**
} * @see DbCore::disconnect()
*/
/** public function disconnect()
* @see DbCore::nextRow() {
*/ unset($this->link);
public function nextRow($result = false) }
{
if (!$result) /**
$result = $this->result; * @see DbCore::_query()
return $result->fetch(PDO::FETCH_ASSOC); */
} protected function _query($sql)
{
/** return $this->link->query($sql);
* @see DbCore::_numRows() }
*/
protected function _numRows($result) /**
{ * @see DbCore::nextRow()
return $result->rowCount(); */
} public function nextRow($result = false)
{
/** if (!$result)
* @see DbCore::Insert_ID() $result = $this->result;
*/ return $result->fetch(PDO::FETCH_ASSOC);
public function Insert_ID() }
{
return $this->link->lastInsertId(); /**
} * @see DbCore::_numRows()
*/
/** protected function _numRows($result)
* @see DbCore::Affected_Rows() {
*/ return $result->rowCount();
public function Affected_Rows() }
{
return $this->result->rowCount(); /**
} * @see DbCore::Insert_ID()
*/
/** public function Insert_ID()
* @see DbCore::getMsgError() {
*/ return $this->link->lastInsertId();
public function getMsgError($query = false) }
{
$error = $this->link->errorInfo(); /**
return ($error[0] == '00000') ? '' : $error[2]; * @see DbCore::Affected_Rows()
} */
public function Affected_Rows()
/** {
* @see DbCore::getNumberError() return $this->result->rowCount();
*/ }
public function getNumberError()
{ /**
$error = $this->link->errorInfo(); * @see DbCore::getMsgError()
return isset($error[1]) ? $error[1] : 0; */
} public function getMsgError($query = false)
{
/** $error = $this->link->errorInfo();
* @see DbCore::getVersion() return ($error[0] == '00000') ? '' : $error[2];
*/ }
public function getVersion()
{ /**
return $this->getValue('SELECT VERSION()'); * @see DbCore::getNumberError()
} */
public function getNumberError()
/** {
* @see DbCore::_escape() $error = $this->link->errorInfo();
*/ return isset($error[1]) ? $error[1] : 0;
public function _escape($str) }
{
$search = array("\\", "\0", "\n", "\r", "\x1a", "'", '"'); /**
$replace = array("\\\\", "\\0", "\\n", "\\r", "\Z", "\'", '\"'); * @see DbCore::getVersion()
return str_replace($search, $replace, $str); */
} public function getVersion()
{
/** return $this->getValue('SELECT VERSION()');
* @see DbCore::set_db() }
*/
public function set_db($db_name) /**
{ * @see DbCore::_escape()
return $this->link->exec('USE '.pSQL($db_name)); */
} public function _escape($str)
{
/** $search = array("\\", "\0", "\n", "\r", "\x1a", "'", '"');
* @see Db::hasTableWithSamePrefix() $replace = array("\\\\", "\\0", "\\n", "\\r", "\Z", "\'", '\"');
*/ return str_replace($search, $replace, $str);
public static function hasTableWithSamePrefix($server, $user, $pwd, $db, $prefix) }
{
try { /**
$link = DbPDO::_getPDO($server, $user, $pwd, $db, 5); * @see DbCore::set_db()
} catch (PDOException $e) { */
return false; public function set_db($db_name)
} {
return $this->link->exec('USE '.pSQL($db_name));
$sql = 'SHOW TABLES LIKE \''.$prefix.'%\''; }
$result = $link->query($sql);
return (bool)$result->fetch(); /**
} * @see Db::hasTableWithSamePrefix()
*/
public static function checkCreatePrivilege($server, $user, $pwd, $db, $prefix, $engine = null) public static function hasTableWithSamePrefix($server, $user, $pwd, $db, $prefix)
{ {
try { try {
$link = DbPDO::_getPDO($server, $user, $pwd, $db, 5); $link = DbPDO::_getPDO($server, $user, $pwd, $db, 5);
} catch (PDOException $e) { } catch (PDOException $e) {
return false; return false;
} }
$sql = ' $sql = 'SHOW TABLES LIKE \''.$prefix.'%\'';
CREATE TABLE `'.$prefix.'test` ( $result = $link->query($sql);
`test` tinyint(1) unsigned NOT NULL return (bool)$result->fetch();
) ENGINE=MyISAM'; }
$result = $link->query($sql);
if (!$result) public static function checkCreatePrivilege($server, $user, $pwd, $db, $prefix, $engine = null)
{ {
$error = $link->errorInfo(); try {
return $error[2]; $link = DbPDO::_getPDO($server, $user, $pwd, $db, 5);
} } catch (PDOException $e) {
$link->query('DROP TABLE `'.$prefix.'test`'); return false;
return true; }
}
$sql = '
/** CREATE TABLE `'.$prefix.'test` (
* @see Db::checkConnection() `test` tinyint(1) unsigned NOT NULL
*/ ) ENGINE=MyISAM';
public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null, $timeout = 5) $result = $link->query($sql);
{ if (!$result)
try { {
$link = DbPDO::_getPDO($server, $user, $pwd, $db, $timeout); $error = $link->errorInfo();
} catch (PDOException $e) { return $error[2];
return ($e->getCode() == 1049) ? 2 : 1; }
} $link->query('DROP TABLE `'.$prefix.'test`');
unset($link); return true;
return 0; }
}
/**
public function getBestEngine() * @see Db::checkConnection()
{ */
$value = 'InnoDB'; public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true, $engine = null, $timeout = 5)
{
$sql = 'SHOW VARIABLES WHERE Variable_name = \'have_innodb\''; try {
$result = $this->link->query($sql); $link = DbPDO::_getPDO($server, $user, $pwd, $db, $timeout);
if (!$result) } catch (PDOException $e) {
$value = 'MyISAM'; return ($e->getCode() == 1049) ? 2 : 1;
$row = $result->fetch(); }
if (!$row || strtolower($row['Value']) != 'yes') unset($link);
$value = 'MyISAM'; return 0;
}
/* MySQL >= 5.6 */
$sql = 'SHOW ENGINES'; public function getBestEngine()
$result = $this->link->query($sql); {
while ($row = $result->fetch()) $value = 'InnoDB';
if ($row['Engine'] == 'InnoDB')
{ $sql = 'SHOW VARIABLES WHERE Variable_name = \'have_innodb\'';
if (in_array($row['Support'], array('DEFAULT', 'YES'))) $result = $this->link->query($sql);
$value = 'InnoDB'; if (!$result)
break; $value = 'MyISAM';
} $row = $result->fetch();
return $value; if (!$row || strtolower($row['Value']) != 'yes')
} $value = 'MyISAM';
/** /* MySQL >= 5.6 */
* @see Db::checkEncoding() $sql = 'SHOW ENGINES';
*/ $result = $this->link->query($sql);
public static function tryUTF8($server, $user, $pwd) while ($row = $result->fetch())
{ if ($row['Engine'] == 'InnoDB')
try { {
$link = DbPDO::_getPDO($server, $user, $pwd, false, 5); if (in_array($row['Support'], array('DEFAULT', 'YES')))
} catch (PDOException $e) { $value = 'InnoDB';
return false; break;
} }
$result = $link->exec('SET NAMES \'utf8\''); return $value;
unset($link); }
return ($result === false) ? false : true; /**
} * @see Db::checkEncoding()
} */
public static function tryUTF8($server, $user, $pwd)
{
try {
$link = DbPDO::_getPDO($server, $user, $pwd, false, 5);
} catch (PDOException $e) {
return false;
}
$result = $link->exec('SET NAMES \'utf8\'');
unset($link);
return ($result === false) ? false : true;
}
}
+9
View File
@@ -46,6 +46,15 @@ class MySQLCore extends Db
return $this->link; return $this->link;
} }
public static function createDatabase($host, $user, $password, $dbname, $dropit = false)
{
$link = mysql_connect($host, $user, $password);
$success = mysql_query('CREATE DATABASE `'.bqSQL($dbname).'`', $link);
if ($dropit && ($link->exec('DROP DATABASE `'.bqSQL($dbname).'`') !== false))
return true;
return $success;
}
/** /**
* @see DbCore::disconnect() * @see DbCore::disconnect()
+1 -1
View File
@@ -508,7 +508,7 @@ class OrderDetailCore extends ObjectModel
$this->purchase_supplier_price = (float)$product['wholesale_price']; $this->purchase_supplier_price = (float)$product['wholesale_price'];
if ($product['id_supplier'] > 0) if ($product['id_supplier'] > 0)
$this->purchase_supplier_price = (float)ProductSupplier::getProductPrice((int)$product['id_supplier'], $product['id_product'], $product['id_product_attribute']); $this->purchase_supplier_price = (float)ProductSupplier::getProductPrice((int)$product['id_supplier'], $product['id_product'], $product['id_product_attribute'], true);
$this->setSpecificPrice($order, $product); $this->setSpecificPrice($order, $product);
@@ -376,7 +376,7 @@ class WebserviceOutputBuilderCore
{ {
if ($key !== 'empty') if ($key !== 'empty')
{ {
if ($this->fieldsToDisplay === 'minimum') if ($this->fieldsToDisplay === 'minimum')
$output .= $this->renderEntityMinimum($object, $depth); $output .= $this->renderEntityMinimum($object, $depth);
else else
$output .= $this->renderEntity($object, $depth); $output .= $this->renderEntity($object, $depth);
+14 -5
View File
@@ -530,9 +530,10 @@ class WebserviceRequestCore
} }
} }
} }
return $this->returnOutput(); $return = $this->returnOutput();
unset($webservice_call); unset($webservice_call);
unset ($display_errors); unset($display_errors);
return $return;
} }
protected function webserviceChecks() protected function webserviceChecks()
@@ -1158,6 +1159,7 @@ class WebserviceRequestCore
$sorts = array($this->urlFragments['sort']); $sorts = array($this->urlFragments['sort']);
$sql_sort .= ' ORDER BY '; $sql_sort .= ' ORDER BY ';
foreach ($sorts as $sort) foreach ($sorts as $sort)
{ {
$delimiterPosition = strrpos($sort, '_'); $delimiterPosition = strrpos($sort, '_');
@@ -1219,8 +1221,6 @@ class WebserviceRequestCore
return $filters; return $filters;
} }
public function getFilteredObjectList() public function getFilteredObjectList()
{ {
$objects = array(); $objects = array();
@@ -1241,7 +1241,16 @@ class WebserviceRequestCore
if ($sqlObjects) if ($sqlObjects)
{ {
foreach ($sqlObjects as $sqlObject) foreach ($sqlObjects as $sqlObject)
$objects[] = new $this->resourceConfiguration['retrieveData']['className']((int)$sqlObject[$this->resourceConfiguration['fields']['id']['sqlId']]); {
if ($this->fieldsToDisplay == 'minimum')
{
$obj = new $this->resourceConfiguration['retrieveData']['className']();
$obj->id = (int)$sqlObject[$this->resourceConfiguration['fields']['id']['sqlId']];
$objects[] = $obj;
}
else
$objects[] = new $this->resourceConfiguration['retrieveData']['className']((int)$sqlObject[$this->resourceConfiguration['fields']['id']['sqlId']]);
}
return $objects; return $objects;
} }
} }
@@ -2717,7 +2717,7 @@ class AdminProductsControllerCore extends AdminController
if (!$product_supplier_id) if (!$product_supplier_id)
{ {
$product->addSupplierReference($supplier->id_supplier, (int)$attribute['id_product_attribute'], $reference, (float)Tools::convertPrice($price, $id_currency), (int)$id_currency); $product->addSupplierReference($supplier->id_supplier, (int)$attribute['id_product_attribute'], $reference, (float)$price, (int)$id_currency);
if ($product->id_supplier == $supplier->id_supplier) if ($product->id_supplier == $supplier->id_supplier)
{ {
if ((int)$attribute['id_product_attribute'] > 0) if ((int)$attribute['id_product_attribute'] > 0)
@@ -2743,7 +2743,7 @@ class AdminProductsControllerCore extends AdminController
{ {
$product_supplier = new ProductSupplier($product_supplier_id); $product_supplier = new ProductSupplier($product_supplier_id);
$product_supplier->id_currency = (int)$id_currency; $product_supplier->id_currency = (int)$id_currency;
$product_supplier->product_supplier_price_te = (float)Tools::convertPrice($price, $id_currency); //converted in the default currency $product_supplier->product_supplier_price_te = (float)$price;
$product_supplier->product_supplier_reference = pSQL($reference); $product_supplier->product_supplier_reference = pSQL($reference);
$product_supplier->update(); $product_supplier->update();
+11 -19
View File
@@ -95,8 +95,8 @@ class InstallControllerHttpDatabase extends InstallControllerHttp
{ {
if (Tools::getValue('checkDb')) if (Tools::getValue('checkDb'))
$this->processCheckDb(); $this->processCheckDb();
else if (Tools::getValue('sendMail')) elseif (Tools::getValue('createDb'))
$this->processSendMail(); $this->processCreateDb();
} }
/** /**
@@ -120,28 +120,20 @@ class InstallControllerHttpDatabase extends InstallControllerHttp
} }
/** /**
* Send a test email * Attempt to create the database
*/ */
public function processSendMail() public function processCreateDb()
{ {
$smtp_checked = (Tools::getValue('smtpChecked') == 'true'); $server = Tools::getValue('dbServer');
$server = Tools::getValue('smtpSrv'); $database = Tools::getValue('dbName');
$encryption = Tools::getValue('smtpEnc'); $login = Tools::getValue('dbLogin');
$port = Tools::getValue('smtpPort'); $password = Tools::getValue('dbPassword');
$login = Tools::getValue('smtpLogin');
$password = Tools::getValue('smtpPassword');
$email = Tools::getValue('testEmail');
require_once _PS_INSTALL_MODELS_PATH_.'mail.php'; $success = $this->model_database->createDatabase($server, $database, $login, $password);
$this->model_mail = new InstallModelMail($smtp_checked, $server, $login, $password, $port, $encryption, $email);
$result = $this->model_mail->send(
$this->l('Test message from PrestaShop'),
$this->l('This is a test message, your server is now available to send email')
);
$this->ajaxJsonAnswer( $this->ajaxJsonAnswer(
$result === false, $success,
($result === false) ? $this->l('A test e-mail has been sent to %s', $email) : $this->l('An error occurred while sending email, please verify your parameters') $success ? $this->l('Database is created') : $this->l('Cannot create the database automatically')
); );
} }
+11 -1
View File
@@ -81,7 +81,11 @@ class InstallModelDatabase extends InstallAbstractModel
break; break;
case 2: case 2:
$errors[] = $this->language->l('Connection to MySQL server succeeded, but database "%s" not found', $database).$dbtype; $error = $this->language->l('Connection to MySQL server succeeded, but database "%s" not found', $database).$dbtype;
if ($this->createDatabase($server, $database, $login, $password, true))
$error .= '<p>'.sprintf('<input type="button" value="%s" class="button" id="btCreateDB">', $this->language->l('Attempt to create the database automatically')).'</p>
<script type="text/javascript">bindCreateDB();</script>';
$errors[] = $error;
break; break;
} }
} }
@@ -89,6 +93,12 @@ class InstallModelDatabase extends InstallAbstractModel
return $errors; return $errors;
} }
public function createDatabase($server, $database, $login, $password, $dropit = false)
{
$class = Db::getClass();
return $class::createDatabase($server, $login, $password, $database, $dropit);
}
public function getBestEngine($server, $database, $login, $password) public function getBestEngine($server, $database, $login, $password)
{ {
$class = Db::getClass(); $class = Db::getClass();
+76 -39
View File
@@ -1,39 +1,76 @@
$(document).ready(function() $(document).ready(function()
{ {
// Check database configuration // Check database configuration
$('#btTestDB').click(function() $('#btTestDB').click(function()
{ {
$("#dbResultCheck").slideUp('slow'); $("#dbResultCheck").slideUp('slow');
$.ajax({ $.ajax({
url: 'index.php', url: 'index.php',
data: { data: {
'checkDb': 'true', 'checkDb': 'true',
'dbServer': $('#dbServer').val(), 'dbServer': $('#dbServer').val(),
'dbName': $('#dbName').val(), 'dbName': $('#dbName').val(),
'dbLogin': $('#dbLogin').val(), 'dbLogin': $('#dbLogin').val(),
'dbPassword': $('#dbPassword').val(), 'dbPassword': $('#dbPassword').val(),
'dbEngine': $('#dbEngine').val(), 'dbEngine': $('#dbEngine').val(),
'db_prefix': $('#db_prefix').val(), 'db_prefix': $('#db_prefix').val(),
'clear': $('#db_clear').prop('checked') ? '1' : '0' 'clear': $('#db_clear').prop('checked') ? '1' : '0'
}, },
dataType: 'json', dataType: 'json',
cache: false, cache: false,
success: function(json) success: function(json)
{ {
$("#dbResultCheck") $("#dbResultCheck")
.addClass((json.success) ? 'okBlock' : 'errorBlock') .addClass((json.success) ? 'okBlock' : 'errorBlock')
.removeClass((json.success) ? 'errorBlock' : 'okBlock') .removeClass((json.success) ? 'errorBlock' : 'okBlock')
.html(json.message) .html(json.message)
.slideDown('slow'); .slideDown('slow');
}, },
error: function(xhr) error: function(xhr)
{ {
$("#dbResultCheck") $("#dbResultCheck")
.addClass('errorBlock') .addClass('errorBlock')
.removeClass('okBlock') .removeClass('okBlock')
.html('An error occurred:<br /><br />'+xhr.responseText) .html('An error occurred:<br /><br />' + xhr.responseText)
.slideDown('slow'); .slideDown('slow');
} }
}); });
}); });
}); });
function bindCreateDB()
{
// Attempt to create the database
$('#btCreateDB').click(function()
{
$("#dbResultCheck").slideUp('fast');
$.ajax({
url: 'index.php',
data: {
'createDb': 'true',
'dbServer': $('#dbServer').val(),
'dbName': $('#dbName').val(),
'dbLogin': $('#dbLogin').val(),
'dbPassword': $('#dbPassword').val()
},
dataType: 'json',
cache: false,
success: function(json)
{
$("#dbResultCheck")
.addClass((json.success) ? 'okBlock' : 'errorBlock')
.removeClass((json.success) ? 'errorBlock' : 'okBlock')
.html(json.message)
.slideDown('slow');
},
error: function(xhr)
{
$("#dbResultCheck")
.addClass('errorBlock')
.removeClass('okBlock')
.html('An error occurred:<br /><br />' + xhr.responseText)
.slideDown('slow');
}
});
});
}
@@ -48,7 +48,7 @@ class BlockManufacturer extends Module
Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT', true); Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT', true);
Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT_NB', 5); Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT_NB', 5);
Configuration::updateValue('MANUFACTURER_DISPLAY_FORM', true); Configuration::updateValue('MANUFACTURER_DISPLAY_FORM', true);
return parent::install() && return parent::install() &&
$this->registerHook('leftColumn') && $this->registerHook('leftColumn') &&
$this->registerHook('header') && $this->registerHook('header') &&
$this->registerHook('actionObjectManufacturerDeleteAfter') && $this->registerHook('actionObjectManufacturerDeleteAfter') &&
+3 -3
View File
@@ -175,9 +175,9 @@ class PSCleaner extends Module
array('delivery', 'id_carrier', 'carrier', 'id_carrier'), array('delivery', 'id_carrier', 'carrier', 'id_carrier'),
array('delivery', 'id_zone', 'zone', 'id_zone'), array('delivery', 'id_zone', 'zone', 'id_zone'),
array('editorial', 'id_shop', 'shop', 'id_shop', 'editorial'), array('editorial', 'id_shop', 'shop', 'id_shop', 'editorial'),
array('favorite_product', 'id_product', 'product', 'id_product'), array('favorite_product', 'id_product', 'product', 'id_product','favoriteproducts'),
array('favorite_product', 'id_customer', 'customer', 'id_customer'), array('favorite_product', 'id_customer', 'customer', 'id_customer','favoriteproducts'),
array('favorite_product', 'id_shop', 'shop', 'id_shop'), array('favorite_product', 'id_shop', 'shop', 'id_shop','favoriteproducts'),
array('feature_product', 'id_feature', 'feature', 'id_feature'), array('feature_product', 'id_feature', 'feature', 'id_feature'),
array('feature_product', 'id_product', 'product', 'id_product'), array('feature_product', 'id_product', 'product', 'id_product'),
array('feature_value', 'id_feature', 'feature', 'id_feature'), array('feature_value', 'id_feature', 'feature', 'id_feature'),
+12 -7
View File
@@ -2,7 +2,7 @@
/** /**
* Project: Smarty: the PHP compiling template engine * Project: Smarty: the PHP compiling template engine
* File: Smarty.class.php * File: Smarty.class.php
* SVN: $Id: Smarty.class.php 4694 2013-01-13 21:13:14Z uwe.tews@googlemail.com $ * SVN: $Id: Smarty.class.php 4742 2013-06-17 13:30:49Z Uwe.Tews@googlemail.com $
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -28,7 +28,7 @@
* @author Uwe Tews * @author Uwe Tews
* @author Rodney Rehm * @author Rodney Rehm
* @package Smarty * @package Smarty
* @version 3.1.13 * @version 3.1-DEV
*/ */
/** /**
@@ -113,7 +113,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = 'Smarty-3.1.13'; const SMARTY_VERSION = 'Smarty-3.1.14';
/** /**
* define variable scopes * define variable scopes
@@ -128,6 +128,11 @@ class Smarty extends Smarty_Internal_TemplateBase {
const CACHING_OFF = 0; const CACHING_OFF = 0;
const CACHING_LIFETIME_CURRENT = 1; const CACHING_LIFETIME_CURRENT = 1;
const CACHING_LIFETIME_SAVED = 2; const CACHING_LIFETIME_SAVED = 2;
/**
* define constant for clearing cache files be saved expiration datees
*/
const CLEAR_EXPIRED = -1;
/** /**
* define compile check modes * define compile check modes
*/ */
@@ -1323,9 +1328,9 @@ class Smarty extends Smarty_Internal_TemplateBase {
* @param int $max_errors * @param int $max_errors
* @return integer number of template files recompiled * @return integer number of template files recompiled
*/ */
public function compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null) public function compileAllTemplates($extension = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
{ {
return Smarty_Internal_Utility::compileAllTemplates($extention, $force_compile, $time_limit, $max_errors, $this); return Smarty_Internal_Utility::compileAllTemplates($extension, $force_compile, $time_limit, $max_errors, $this);
} }
/** /**
@@ -1337,9 +1342,9 @@ class Smarty extends Smarty_Internal_TemplateBase {
* @param int $max_errors * @param int $max_errors
* @return integer number of template files recompiled * @return integer number of template files recompiled
*/ */
public function compileAllConfig($extention = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null) public function compileAllConfig($extension = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null)
{ {
return Smarty_Internal_Utility::compileAllConfig($extention, $force_compile, $time_limit, $max_errors, $this); return Smarty_Internal_Utility::compileAllConfig($extension, $force_compile, $time_limit, $max_errors, $this);
} }
/** /**
+459 -459
View File
@@ -1,460 +1,460 @@
<?php <?php
/** /**
* Project: Smarty: the PHP compiling template engine * Project: Smarty: the PHP compiling template engine
* File: SmartyBC.class.php * File: SmartyBC.class.php
* SVN: $Id: $ * SVN: $Id: $
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * version 2.1 of the License, or (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
* For questions, help, comments, discussion, etc., please join the * For questions, help, comments, discussion, etc., please join the
* Smarty mailing list. Send a blank e-mail to * Smarty mailing list. Send a blank e-mail to
* smarty-discussion-subscribe@googlegroups.com * smarty-discussion-subscribe@googlegroups.com
* *
* @link http://www.smarty.net/ * @link http://www.smarty.net/
* @copyright 2008 New Digital Group, Inc. * @copyright 2008 New Digital Group, Inc.
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews * @author Uwe Tews
* @author Rodney Rehm * @author Rodney Rehm
* @package Smarty * @package Smarty
*/ */
/** /**
* @ignore * @ignore
*/ */
require(dirname(__FILE__) . '/Smarty.class.php'); require(dirname(__FILE__) . '/Smarty.class.php');
/** /**
* Smarty Backward Compatability Wrapper Class * Smarty Backward Compatability Wrapper Class
* *
* @package Smarty * @package Smarty
*/ */
class SmartyBC extends Smarty { class SmartyBC extends Smarty {
/** /**
* Smarty 2 BC * Smarty 2 BC
* @var string * @var string
*/ */
public $_version = self::SMARTY_VERSION; public $_version = self::SMARTY_VERSION;
/** /**
* Initialize new SmartyBC object * Initialize new SmartyBC object
* *
* @param array $options options to set during initialization, e.g. array( 'forceCompile' => false ) * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
*/ */
public function __construct(array $options=array()) public function __construct(array $options=array())
{ {
parent::__construct($options); parent::__construct($options);
// register {php} tag // register {php} tag
$this->registerPlugin('block', 'php', 'smarty_php_tag'); $this->registerPlugin('block', 'php', 'smarty_php_tag');
} }
/** /**
* wrapper for assign_by_ref * wrapper for assign_by_ref
* *
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name
* @param mixed &$value the referenced value to assign * @param mixed &$value the referenced value to assign
*/ */
public function assign_by_ref($tpl_var, &$value) public function assign_by_ref($tpl_var, &$value)
{ {
$this->assignByRef($tpl_var, $value); $this->assignByRef($tpl_var, $value);
} }
/** /**
* wrapper for append_by_ref * wrapper for append_by_ref
* *
* @param string $tpl_var the template variable name * @param string $tpl_var the template variable name
* @param mixed &$value the referenced value to append * @param mixed &$value the referenced value to append
* @param boolean $merge flag if array elements shall be merged * @param boolean $merge flag if array elements shall be merged
*/ */
public function append_by_ref($tpl_var, &$value, $merge = false) public function append_by_ref($tpl_var, &$value, $merge = false)
{ {
$this->appendByRef($tpl_var, $value, $merge); $this->appendByRef($tpl_var, $value, $merge);
} }
/** /**
* clear the given assigned template variable. * clear the given assigned template variable.
* *
* @param string $tpl_var the template variable to clear * @param string $tpl_var the template variable to clear
*/ */
public function clear_assign($tpl_var) public function clear_assign($tpl_var)
{ {
$this->clearAssign($tpl_var); $this->clearAssign($tpl_var);
} }
/** /**
* Registers custom function to be used in templates * Registers custom function to be used in templates
* *
* @param string $function the name of the template function * @param string $function the name of the template function
* @param string $function_impl the name of the PHP function to register * @param string $function_impl the name of the PHP function to register
* @param bool $cacheable * @param bool $cacheable
* @param mixed $cache_attrs * @param mixed $cache_attrs
*/ */
public function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null) public function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null)
{ {
$this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs); $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
} }
/** /**
* Unregisters custom function * Unregisters custom function
* *
* @param string $function name of template function * @param string $function name of template function
*/ */
public function unregister_function($function) public function unregister_function($function)
{ {
$this->unregisterPlugin('function', $function); $this->unregisterPlugin('function', $function);
} }
/** /**
* Registers object to be used in templates * Registers object to be used in templates
* *
* @param string $object name of template object * @param string $object name of template object
* @param object $object_impl the referenced PHP object to register * @param object $object_impl the referenced PHP object to register
* @param array $allowed list of allowed methods (empty = all) * @param array $allowed list of allowed methods (empty = all)
* @param boolean $smarty_args smarty argument format, else traditional * @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_functs list of methods that are block format * @param array $block_functs list of methods that are block format
*/ */
public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
{ {
settype($allowed, 'array'); settype($allowed, 'array');
settype($smarty_args, 'boolean'); settype($smarty_args, 'boolean');
$this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods); $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
} }
/** /**
* Unregisters object * Unregisters object
* *
* @param string $object name of template object * @param string $object name of template object
*/ */
public function unregister_object($object) public function unregister_object($object)
{ {
$this->unregisterObject($object); $this->unregisterObject($object);
} }
/** /**
* 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
*/ */
public function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null) public function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)
{ {
$this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs); $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
} }
/** /**
* Unregisters block function * Unregisters block function
* *
* @param string $block name of template function * @param string $block name of template function
*/ */
public function unregister_block($block) public function unregister_block($block)
{ {
$this->unregisterPlugin('block', $block); $this->unregisterPlugin('block', $block);
} }
/** /**
* Registers compiler function * Registers compiler function
* *
* @param string $function name of template function * @param string $function name of template function
* @param string $function_impl name of PHP function to register * @param string $function_impl name of PHP function to register
* @param bool $cacheable * @param bool $cacheable
*/ */
public function register_compiler_function($function, $function_impl, $cacheable=true) public function register_compiler_function($function, $function_impl, $cacheable=true)
{ {
$this->registerPlugin('compiler', $function, $function_impl, $cacheable); $this->registerPlugin('compiler', $function, $function_impl, $cacheable);
} }
/** /**
* Unregisters compiler function * Unregisters compiler function
* *
* @param string $function name of template function * @param string $function name of template function
*/ */
public function unregister_compiler_function($function) public function unregister_compiler_function($function)
{ {
$this->unregisterPlugin('compiler', $function); $this->unregisterPlugin('compiler', $function);
} }
/** /**
* Registers modifier to be used in templates * Registers modifier to be used in templates
* *
* @param string $modifier name of template modifier * @param string $modifier name of template modifier
* @param string $modifier_impl name of PHP function to register * @param string $modifier_impl name of PHP function to register
*/ */
public function register_modifier($modifier, $modifier_impl) public function register_modifier($modifier, $modifier_impl)
{ {
$this->registerPlugin('modifier', $modifier, $modifier_impl); $this->registerPlugin('modifier', $modifier, $modifier_impl);
} }
/** /**
* Unregisters modifier * Unregisters modifier
* *
* @param string $modifier name of template modifier * @param string $modifier name of template modifier
*/ */
public function unregister_modifier($modifier) public function unregister_modifier($modifier)
{ {
$this->unregisterPlugin('modifier', $modifier); $this->unregisterPlugin('modifier', $modifier);
} }
/** /**
* Registers a resource to fetch a template * Registers a resource to fetch a template
* *
* @param string $type name of resource * @param string $type name of resource
* @param array $functions array of functions to handle resource * @param array $functions array of functions to handle resource
*/ */
public function register_resource($type, $functions) public function register_resource($type, $functions)
{ {
$this->registerResource($type, $functions); $this->registerResource($type, $functions);
} }
/** /**
* Unregisters a resource * Unregisters a resource
* *
* @param string $type name of resource * @param string $type name of resource
*/ */
public function unregister_resource($type) public function unregister_resource($type)
{ {
$this->unregisterResource($type); $this->unregisterResource($type);
} }
/** /**
* Registers a prefilter function to apply * Registers a prefilter function to apply
* to a template before compiling * to a template before compiling
* *
* @param callable $function * @param callable $function
*/ */
public function register_prefilter($function) public function register_prefilter($function)
{ {
$this->registerFilter('pre', $function); $this->registerFilter('pre', $function);
} }
/** /**
* Unregisters a prefilter function * Unregisters a prefilter function
* *
* @param callable $function * @param callable $function
*/ */
public function unregister_prefilter($function) public function unregister_prefilter($function)
{ {
$this->unregisterFilter('pre', $function); $this->unregisterFilter('pre', $function);
} }
/** /**
* Registers a postfilter function to apply * Registers a postfilter function to apply
* to a compiled template after compilation * to a compiled template after compilation
* *
* @param callable $function * @param callable $function
*/ */
public function register_postfilter($function) public function register_postfilter($function)
{ {
$this->registerFilter('post', $function); $this->registerFilter('post', $function);
} }
/** /**
* Unregisters a postfilter function * Unregisters a postfilter function
* *
* @param callable $function * @param callable $function
*/ */
public function unregister_postfilter($function) public function unregister_postfilter($function)
{ {
$this->unregisterFilter('post', $function); $this->unregisterFilter('post', $function);
} }
/** /**
* Registers an output filter function to apply * Registers an output filter function to apply
* to a template output * to a template output
* *
* @param callable $function * @param callable $function
*/ */
public function register_outputfilter($function) public function register_outputfilter($function)
{ {
$this->registerFilter('output', $function); $this->registerFilter('output', $function);
} }
/** /**
* Unregisters an outputfilter function * Unregisters an outputfilter function
* *
* @param callable $function * @param callable $function
*/ */
public function unregister_outputfilter($function) public function unregister_outputfilter($function)
{ {
$this->unregisterFilter('output', $function); $this->unregisterFilter('output', $function);
} }
/** /**
* load a filter of specified type and name * load a filter of specified type and name
* *
* @param string $type filter type * @param string $type filter type
* @param string $name filter name * @param string $name filter name
*/ */
public function load_filter($type, $name) public function load_filter($type, $name)
{ {
$this->loadFilter($type, $name); $this->loadFilter($type, $name);
} }
/** /**
* 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
*/ */
public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
{ {
return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time); return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
} }
/** /**
* 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
*/ */
public function clear_all_cache($exp_time = null) public function clear_all_cache($exp_time = null)
{ {
return $this->clearCache(null, null, null, $exp_time); return $this->clearCache(null, null, null, $exp_time);
} }
/** /**
* 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 boolean * @return boolean
*/ */
public function is_cached($tpl_file, $cache_id = null, $compile_id = null) public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
{ {
return $this->isCached($tpl_file, $cache_id, $compile_id); return $this->isCached($tpl_file, $cache_id, $compile_id);
} }
/** /**
* clear all the assigned template variables. * clear all the assigned template variables.
*/ */
public function clear_all_assign() public function clear_all_assign()
{ {
$this->clearAllAssign(); $this->clearAllAssign();
} }
/** /**
* clears compiled version of specified template resource, * clears compiled version of specified template resource,
* 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()}
*/ */
public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
{ {
return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time); return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
} }
/** /**
* Checks whether requested template exists. * Checks whether requested template exists.
* *
* @param string $tpl_file * @param string $tpl_file
* @return boolean * @return boolean
*/ */
public function template_exists($tpl_file) public function template_exists($tpl_file)
{ {
return $this->templateExists($tpl_file); return $this->templateExists($tpl_file);
} }
/** /**
* Returns an array containing template variables * Returns an array containing template variables
* *
* @param string $name * @param string $name
* @return array * @return array
*/ */
public function get_template_vars($name=null) public function get_template_vars($name=null)
{ {
return $this->getTemplateVars($name); return $this->getTemplateVars($name);
} }
/** /**
* Returns an array containing config variables * Returns an array containing config variables
* *
* @param string $name * @param string $name
* @return array * @return array
*/ */
public function get_config_vars($name=null) public function get_config_vars($name=null)
{ {
return $this->getConfigVars($name); return $this->getConfigVars($name);
} }
/** /**
* load configuration values * load configuration values
* *
* @param string $file * @param string $file
* @param string $section * @param string $section
* @param string $scope * @param string $scope
*/ */
public function config_load($file, $section = null, $scope = 'global') public function config_load($file, $section = null, $scope = 'global')
{ {
$this->ConfigLoad($file, $section, $scope); $this->ConfigLoad($file, $section, $scope);
} }
/** /**
* return a reference to a registered object * return a reference to a registered object
* *
* @param string $name * @param string $name
* @return object * @return object
*/ */
public function get_registered_object($name) public function get_registered_object($name)
{ {
return $this->getRegisteredObject($name); return $this->getRegisteredObject($name);
} }
/** /**
* clear configuration values * clear configuration values
* *
* @param string $var * @param string $var
*/ */
public function clear_config($var = null) public function clear_config($var = null)
{ {
$this->clearConfig($var); $this->clearConfig($var);
} }
/** /**
* trigger Smarty error * trigger Smarty error
* *
* @param string $error_msg * @param string $error_msg
* @param integer $error_type * @param integer $error_type
*/ */
public function trigger_error($error_msg, $error_type = E_USER_WARNING) public function trigger_error($error_msg, $error_type = E_USER_WARNING)
{ {
trigger_error("Smarty error: $error_msg", $error_type); trigger_error("Smarty error: $error_msg", $error_type);
} }
} }
/** /**
* Smarty {php}{/php} block function * Smarty {php}{/php} block function
* *
* @param array $params parameter list * @param array $params parameter list
* @param string $content contents of the block * @param string $content contents of the block
* @param object $template template object * @param object $template template object
* @param boolean &$repeat repeat flag * @param boolean &$repeat repeat flag
* @return string content re-formatted * @return string content re-formatted
*/ */
function smarty_php_tag($params, $content, $template, &$repeat) function smarty_php_tag($params, $content, $template, &$repeat)
{ {
eval($content); eval($content);
return ''; return '';
} }
?> ?>
+4 -4
View File
@@ -30,7 +30,7 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
$upper_string = mb_convert_case( $string, MB_CASE_TITLE, Smarty::$_CHARSET ); $upper_string = mb_convert_case( $string, MB_CASE_TITLE, Smarty::$_CHARSET );
} else { } else {
// uppercase word breaks // uppercase word breaks
$upper_string = preg_replace("!(^|[^\p{L}'])([\p{Ll}])!eS" . Smarty::$_UTF8_MODIFIER, "stripslashes('\\1').mb_convert_case(stripslashes('\\2'),MB_CASE_UPPER, '" . addslashes(Smarty::$_CHARSET) . "')", $string); $upper_string = preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, create_function ('$matches', 'return stripslashes($matches[1]).mb_convert_case(stripslashes($matches[2]),MB_CASE_UPPER, "' . addslashes(Smarty::$_CHARSET) . '");'), $string);
} }
// check uc_digits case // check uc_digits case
if (!$uc_digits) { if (!$uc_digits) {
@@ -40,7 +40,7 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
} }
} }
} }
$upper_string = preg_replace("!((^|\s)['\"])(\w)!e" . Smarty::$_UTF8_MODIFIER, "stripslashes('\\1').mb_convert_case(stripslashes('\\3'),MB_CASE_UPPER, '" . addslashes(Smarty::$_CHARSET) . "')", $upper_string); $upper_string = preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, create_function ('$matches', 'return stripslashes($matches[1]).mb_convert_case(stripslashes($matches[3]),MB_CASE_UPPER, "' . addslashes(Smarty::$_CHARSET) . '");'), $upper_string);
return $upper_string; return $upper_string;
} }
@@ -49,7 +49,7 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
$string = strtolower($string); $string = strtolower($string);
} }
// uppercase (including hyphenated words) // uppercase (including hyphenated words)
$upper_string = preg_replace("!(^|[^\p{L}'])([\p{Ll}])!eS" . Smarty::$_UTF8_MODIFIER, "stripslashes('\\1').ucfirst(stripslashes('\\2'))", $string); $upper_string = preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, create_function ('$matches', 'return stripslashes($matches[1]).ucfirst(stripslashes($matches[2]));'), $string);
// check uc_digits case // check uc_digits case
if (!$uc_digits) { if (!$uc_digits) {
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, PREG_OFFSET_CAPTURE)) { if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, PREG_OFFSET_CAPTURE)) {
@@ -58,7 +58,7 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
} }
} }
} }
$upper_string = preg_replace("!((^|\s)['\"])(\w)!e" . Smarty::$_UTF8_MODIFIER, "stripslashes('\\1').strtoupper(stripslashes('\\3'))", $upper_string); $upper_string = preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, create_function ('$matches', 'return stripslashes($matches[1]).ucfirst(stripslashes($matches[3]));'), $upper_string);
return $upper_string; return $upper_string;
} }
+2 -7
View File
@@ -21,12 +21,7 @@
* @param boolean $double_encode encode already encoded entitites again, used for htmlspecialchars() or htmlentities() * @param boolean $double_encode encode already encoded entitites again, used for htmlspecialchars() or htmlentities()
* @return string escaped input string * @return string escaped input string
*/ */
/* PrestaShop function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true)
change double_encode to false by default
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true)
*/
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = false)
/* END */
{ {
static $_double_encode = null; static $_double_encode = null;
if ($_double_encode === null) { if ($_double_encode === null) {
@@ -190,4 +185,4 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
} }
} }
?> ?>
+29 -29
View File
@@ -1,30 +1,30 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty cat modifier plugin * Smarty cat modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: cat<br> * Name: cat<br>
* Date: Feb 24, 2003<br> * Date: Feb 24, 2003<br>
* Purpose: catenate a value to a variable<br> * Purpose: catenate a value to a variable<br>
* Input: string to catenate<br> * Input: string to catenate<br>
* Example: {$var|cat:"foo"} * Example: {$var|cat:"foo"}
* *
* @link http://smarty.php.net/manual/en/language.modifier.cat.php cat * @link http://smarty.php.net/manual/en/language.modifier.cat.php cat
* (Smarty online manual) * (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_cat($params, $compiler) function smarty_modifiercompiler_cat($params, $compiler)
{ {
return '('.implode(').(', $params).')'; return '('.implode(').(', $params).')';
} }
?> ?>
@@ -1,33 +1,33 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty count_characters modifier plugin * Smarty count_characters modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: count_characteres<br> * Name: count_characteres<br>
* Purpose: count the number of characters in a text * Purpose: count the number of characters in a text
* *
* @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual) * @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_count_characters($params, $compiler) function smarty_modifiercompiler_count_characters($params, $compiler)
{ {
if (!isset($params[1]) || $params[1] != 'true') { if (!isset($params[1]) || $params[1] != 'true') {
return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[0] . ', $tmp)'; return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[0] . ', $tmp)';
} }
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_strlen(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; return 'mb_strlen(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
} }
// no MBString fallback // no MBString fallback
return 'strlen(' . $params[0] . ')'; return 'strlen(' . $params[0] . ')';
} }
?> ?>
@@ -1,28 +1,28 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty count_paragraphs modifier plugin * Smarty count_paragraphs modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: count_paragraphs<br> * Name: count_paragraphs<br>
* Purpose: count the number of paragraphs in a text * Purpose: count the number of paragraphs in a text
* *
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php * @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_paragraphs (Smarty online manual) * count_paragraphs (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_count_paragraphs($params, $compiler) function smarty_modifiercompiler_count_paragraphs($params, $compiler)
{ {
// count \r or \n characters // count \r or \n characters
return '(preg_match_all(\'#[\r\n]+#\', ' . $params[0] . ', $tmp)+1)'; return '(preg_match_all(\'#[\r\n]+#\', ' . $params[0] . ', $tmp)+1)';
} }
?> ?>
@@ -1,28 +1,28 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty count_sentences modifier plugin * Smarty count_sentences modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: count_sentences * Name: count_sentences
* Purpose: count the number of sentences in a text * Purpose: count the number of sentences in a text
* *
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php * @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_sentences (Smarty online manual) * count_sentences (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_count_sentences($params, $compiler) function smarty_modifiercompiler_count_sentences($params, $compiler)
{ {
// find periods, question marks, exclamation marks with a word before but not after. // find periods, question marks, exclamation marks with a word before but not after.
return 'preg_match_all("#\w[\.\?\!](\W|$)#S' . Smarty::$_UTF8_MODIFIER . '", ' . $params[0] . ', $tmp)'; return 'preg_match_all("#\w[\.\?\!](\W|$)#S' . Smarty::$_UTF8_MODIFIER . '", ' . $params[0] . ', $tmp)';
} }
?> ?>
@@ -1,32 +1,32 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty count_words modifier plugin * Smarty count_words modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: count_words<br> * Name: count_words<br>
* Purpose: count the number of words in a text * Purpose: count the number of words in a text
* *
* @link http://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual) * @link http://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_count_words($params, $compiler) function smarty_modifiercompiler_count_words($params, $compiler)
{ {
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
// return 'preg_match_all(\'#[\w\pL]+#' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)'; // return 'preg_match_all(\'#[\w\pL]+#' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)';
// expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592 // expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592
return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)'; return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)';
} }
// no MBString fallback // no MBString fallback
return 'str_word_count(' . $params[0] . ')'; return 'str_word_count(' . $params[0] . ')';
} }
?> ?>
@@ -1,35 +1,35 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty default modifier plugin * Smarty default modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: default<br> * Name: default<br>
* Purpose: designate default value for empty variables * Purpose: designate default value for empty variables
* *
* @link http://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual) * @link http://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_default ($params, $compiler) function smarty_modifiercompiler_default ($params, $compiler)
{ {
$output = $params[0]; $output = $params[0];
if (!isset($params[1])) { if (!isset($params[1])) {
$params[1] = "''"; $params[1] = "''";
} }
array_shift($params); array_shift($params);
foreach ($params as $param) { foreach ($params as $param) {
$output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)'; $output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)';
} }
return $output; return $output;
} }
?> ?>
+124 -124
View File
@@ -1,125 +1,125 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* @ignore * @ignore
*/ */
require_once( SMARTY_PLUGINS_DIR .'shared.literal_compiler_param.php' ); require_once( SMARTY_PLUGINS_DIR .'shared.literal_compiler_param.php' );
/** /**
* Smarty escape modifier plugin * Smarty escape modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: escape<br> * Name: escape<br>
* Purpose: escape string for output * Purpose: escape string for output
* *
* @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual) * @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
* @author Rodney Rehm * @author Rodney Rehm
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_escape($params, $compiler) function smarty_modifiercompiler_escape($params, $compiler)
{ {
static $_double_encode = null; static $_double_encode = null;
if ($_double_encode === null) { if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
} }
try { try {
$esc_type = smarty_literal_compiler_param($params, 1, 'html'); $esc_type = smarty_literal_compiler_param($params, 1, 'html');
$char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET); $char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET);
$double_encode = smarty_literal_compiler_param($params, 3, true); $double_encode = smarty_literal_compiler_param($params, 3, true);
if (!$char_set) { if (!$char_set) {
$char_set = Smarty::$_CHARSET; $char_set = Smarty::$_CHARSET;
} }
switch ($esc_type) { switch ($esc_type) {
case 'html': case 'html':
if ($_double_encode) { if ($_double_encode) {
return 'htmlspecialchars(' return 'htmlspecialchars('
. $params[0] .', ENT_QUOTES, ' . $params[0] .', ENT_QUOTES, '
. var_export($char_set, true) . ', ' . var_export($char_set, true) . ', '
. var_export($double_encode, true) . ')'; . var_export($double_encode, true) . ')';
} else if ($double_encode) { } else if ($double_encode) {
return 'htmlspecialchars(' return 'htmlspecialchars('
. $params[0] .', ENT_QUOTES, ' . $params[0] .', ENT_QUOTES, '
. var_export($char_set, true) . ')'; . var_export($char_set, true) . ')';
} else { } else {
// fall back to modifier.escape.php // fall back to modifier.escape.php
} }
case 'htmlall': case 'htmlall':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if ($_double_encode) { if ($_double_encode) {
// php >=5.2.3 - go native // php >=5.2.3 - go native
return 'mb_convert_encoding(htmlspecialchars(' return 'mb_convert_encoding(htmlspecialchars('
. $params[0] .', ENT_QUOTES, ' . $params[0] .', ENT_QUOTES, '
. var_export($char_set, true) . ', ' . var_export($char_set, true) . ', '
. var_export($double_encode, true) . var_export($double_encode, true)
. '), "HTML-ENTITIES", ' . '), "HTML-ENTITIES", '
. var_export($char_set, true) . ')'; . var_export($char_set, true) . ')';
} else if ($double_encode) { } else if ($double_encode) {
// php <5.2.3 - only handle double encoding // php <5.2.3 - only handle double encoding
return 'mb_convert_encoding(htmlspecialchars(' return 'mb_convert_encoding(htmlspecialchars('
. $params[0] .', ENT_QUOTES, ' . $params[0] .', ENT_QUOTES, '
. var_export($char_set, true) . var_export($char_set, true)
. '), "HTML-ENTITIES", ' . '), "HTML-ENTITIES", '
. var_export($char_set, true) . ')'; . var_export($char_set, true) . ')';
} else { } else {
// fall back to modifier.escape.php // fall back to modifier.escape.php
} }
} }
// no MBString fallback // no MBString fallback
if ($_double_encode) { if ($_double_encode) {
// php >=5.2.3 - go native // php >=5.2.3 - go native
return 'htmlentities(' return 'htmlentities('
. $params[0] .', ENT_QUOTES, ' . $params[0] .', ENT_QUOTES, '
. var_export($char_set, true) . ', ' . var_export($char_set, true) . ', '
. var_export($double_encode, true) . ')'; . var_export($double_encode, true) . ')';
} else if ($double_encode) { } else if ($double_encode) {
// php <5.2.3 - only handle double encoding // php <5.2.3 - only handle double encoding
return 'htmlentities(' return 'htmlentities('
. $params[0] .', ENT_QUOTES, ' . $params[0] .', ENT_QUOTES, '
. var_export($char_set, true) . ')'; . var_export($char_set, true) . ')';
} else { } else {
// fall back to modifier.escape.php // fall back to modifier.escape.php
} }
case 'url': case 'url':
return 'rawurlencode(' . $params[0] . ')'; return 'rawurlencode(' . $params[0] . ')';
case 'urlpathinfo': case 'urlpathinfo':
return 'str_replace("%2F", "/", rawurlencode(' . $params[0] . '))'; return 'str_replace("%2F", "/", rawurlencode(' . $params[0] . '))';
case 'quotes': case 'quotes':
// escape unescaped single quotes // escape unescaped single quotes
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[0] . ')'; return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[0] . ')';
case 'javascript': case 'javascript':
// escape quotes and backslashes, newlines, etc. // escape quotes and backslashes, newlines, etc.
return 'strtr(' . $params[0] . ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))'; return 'strtr(' . $params[0] . ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))';
} }
} catch(SmartyException $e) { } catch(SmartyException $e) {
// pass through to regular plugin fallback // pass through to regular plugin fallback
} }
// could not optimize |escape call, so fallback to regular plugin // could not optimize |escape call, so fallback to regular plugin
if ($compiler->tag_nocache | $compiler->nocache) { if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
$compiler->template->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR .'modifier.escape.php'; $compiler->template->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR .'modifier.escape.php';
$compiler->template->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape'; $compiler->template->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape';
} else { } else {
$compiler->template->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR .'modifier.escape.php'; $compiler->template->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR .'modifier.escape.php';
$compiler->template->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape'; $compiler->template->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape';
} }
return 'smarty_modifier_escape(' . join( ', ', $params ) . ')'; return 'smarty_modifier_escape(' . join( ', ', $params ) . ')';
} }
?> ?>
@@ -1,34 +1,34 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty from_charset modifier plugin * Smarty from_charset modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: from_charset<br> * Name: from_charset<br>
* Purpose: convert character encoding from $charset to internal encoding * Purpose: convert character encoding from $charset to internal encoding
* *
* @author Rodney Rehm * @author Rodney Rehm
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_from_charset($params, $compiler) function smarty_modifiercompiler_from_charset($params, $compiler)
{ {
if (!Smarty::$_MBSTRING) { if (!Smarty::$_MBSTRING) {
// FIXME: (rodneyrehm) shouldn't this throw an error? // FIXME: (rodneyrehm) shouldn't this throw an error?
return $params[0]; return $params[0];
} }
if (!isset($params[1])) { if (!isset($params[1])) {
$params[1] = '"ISO-8859-1"'; $params[1] = '"ISO-8859-1"';
} }
return 'mb_convert_encoding(' . $params[0] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[1] . ')'; return 'mb_convert_encoding(' . $params[0] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[1] . ')';
} }
?> ?>
@@ -1,32 +1,32 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty indent modifier plugin * Smarty indent modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: indent<br> * Name: indent<br>
* Purpose: indent lines of text * Purpose: indent lines of text
* *
* @link http://www.smarty.net/manual/en/language.modifier.indent.php indent (Smarty online manual) * @link http://www.smarty.net/manual/en/language.modifier.indent.php indent (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_indent($params, $compiler) function smarty_modifiercompiler_indent($params, $compiler)
{ {
if (!isset($params[1])) { if (!isset($params[1])) {
$params[1] = 4; $params[1] = 4;
} }
if (!isset($params[2])) { if (!isset($params[2])) {
$params[2] = "' '"; $params[2] = "' '";
} }
return 'preg_replace(\'!^!m\',str_repeat(' . $params[2] . ',' . $params[1] . '),' . $params[0] . ')'; return 'preg_replace(\'!^!m\',str_repeat(' . $params[2] . ',' . $params[1] . '),' . $params[0] . ')';
} }
?> ?>
+30 -30
View File
@@ -1,31 +1,31 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty lower modifier plugin * Smarty lower modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: lower<br> * Name: lower<br>
* Purpose: convert string to lowercase * Purpose: convert string to lowercase
* *
* @link http://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual) * @link http://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_lower($params, $compiler) function smarty_modifiercompiler_lower($params, $compiler)
{ {
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_strtolower(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')' ; return 'mb_strtolower(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')' ;
} }
// no MBString fallback // no MBString fallback
return 'strtolower(' . $params[0] . ')'; return 'strtolower(' . $params[0] . ')';
} }
?> ?>
@@ -1,25 +1,25 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty noprint modifier plugin * Smarty noprint modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: noprint<br> * Name: noprint<br>
* Purpose: return an empty string * Purpose: return an empty string
* *
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_noprint($params, $compiler) function smarty_modifiercompiler_noprint($params, $compiler)
{ {
return "''"; return "''";
} }
?> ?>
@@ -1,26 +1,26 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty string_format modifier plugin * Smarty string_format modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: string_format<br> * Name: string_format<br>
* Purpose: format strings via sprintf * Purpose: format strings via sprintf
* *
* @link http://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual) * @link http://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_string_format($params, $compiler) function smarty_modifiercompiler_string_format($params, $compiler)
{ {
return 'sprintf(' . $params[1] . ',' . $params[0] . ')'; return 'sprintf(' . $params[1] . ',' . $params[0] . ')';
} }
?> ?>
+32 -32
View File
@@ -1,33 +1,33 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty strip modifier plugin * Smarty strip modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: strip<br> * Name: strip<br>
* Purpose: Replace all repeated spaces, newlines, tabs * Purpose: Replace all repeated spaces, newlines, tabs
* with a single space or supplied replacement string.<br> * with a single space or supplied replacement string.<br>
* Example: {$var|strip} {$var|strip:"&nbsp;"}<br> * Example: {$var|strip} {$var|strip:"&nbsp;"}<br>
* Date: September 25th, 2002 * Date: September 25th, 2002
* *
* @link http://www.smarty.net/manual/en/language.modifier.strip.php strip (Smarty online manual) * @link http://www.smarty.net/manual/en/language.modifier.strip.php strip (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_strip($params, $compiler) function smarty_modifiercompiler_strip($params, $compiler)
{ {
if (!isset($params[1])) { if (!isset($params[1])) {
$params[1] = "' '"; $params[1] = "' '";
} }
return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})"; return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})";
} }
?> ?>
@@ -1,33 +1,28 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty strip_tags modifier plugin * Smarty strip_tags modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: strip_tags<br> * Name: strip_tags<br>
* Purpose: strip html tags from text * Purpose: strip html tags from text
* *
* @link http://www.smarty.net/manual/en/language.modifier.strip.tags.php strip_tags (Smarty online manual) * @link http://www.smarty.net/manual/en/language.modifier.strip.tags.php strip_tags (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_strip_tags($params, $compiler) function smarty_modifiercompiler_strip_tags($params, $compiler)
{ {
if (!isset($params[1])) { if (!isset($params[1]) || $params[1] === true || trim($params[1],'"') == 'true') {
$params[1] = true; return "preg_replace('!<[^>]*?>!', ' ', {$params[0]})";
} } else {
if ($params[1] === true) { return 'strip_tags(' . $params[0] . ')';
return "preg_replace('!<[^>]*?>!', ' ', {$params[0]})"; }
} else { }
return 'strip_tags(' . $params[0] . ')';
}
}
?>
@@ -1,34 +1,34 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty to_charset modifier plugin * Smarty to_charset modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: to_charset<br> * Name: to_charset<br>
* Purpose: convert character encoding from internal encoding to $charset * Purpose: convert character encoding from internal encoding to $charset
* *
* @author Rodney Rehm * @author Rodney Rehm
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_to_charset($params, $compiler) function smarty_modifiercompiler_to_charset($params, $compiler)
{ {
if (!Smarty::$_MBSTRING) { if (!Smarty::$_MBSTRING) {
// FIXME: (rodneyrehm) shouldn't this throw an error? // FIXME: (rodneyrehm) shouldn't this throw an error?
return $params[0]; return $params[0];
} }
if (!isset($params[1])) { if (!isset($params[1])) {
$params[1] = '"ISO-8859-1"'; $params[1] = '"ISO-8859-1"';
} }
return 'mb_convert_encoding(' . $params[0] . ', ' . $params[1] . ', "' . addslashes(Smarty::$_CHARSET) . '")'; return 'mb_convert_encoding(' . $params[0] . ', ' . $params[1] . ', "' . addslashes(Smarty::$_CHARSET) . '")';
} }
?> ?>
@@ -1,51 +1,51 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty unescape modifier plugin * Smarty unescape modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: unescape<br> * Name: unescape<br>
* Purpose: unescape html entities * Purpose: unescape html entities
* *
* @author Rodney Rehm * @author Rodney Rehm
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_unescape($params, $compiler) function smarty_modifiercompiler_unescape($params, $compiler)
{ {
if (!isset($params[1])) { if (!isset($params[1])) {
$params[1] = 'html'; $params[1] = 'html';
} }
if (!isset($params[2])) { if (!isset($params[2])) {
$params[2] = '\'' . addslashes(Smarty::$_CHARSET) . '\''; $params[2] = '\'' . addslashes(Smarty::$_CHARSET) . '\'';
} else { } else {
$params[2] = "'" . $params[2] . "'"; $params[2] = "'" . $params[2] . "'";
} }
switch (trim($params[1], '"\'')) { switch (trim($params[1], '"\'')) {
case 'entity': case 'entity':
case 'htmlall': case 'htmlall':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')'; return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')';
} }
return 'html_entity_decode(' . $params[0] . ', ENT_NOQUOTES, ' . $params[2] . ')'; return 'html_entity_decode(' . $params[0] . ', ENT_NOQUOTES, ' . $params[2] . ')';
case 'html': case 'html':
return 'htmlspecialchars_decode(' . $params[0] . ', ENT_QUOTES)'; return 'htmlspecialchars_decode(' . $params[0] . ', ENT_QUOTES)';
case 'url': case 'url':
return 'rawurldecode(' . $params[0] . ')'; return 'rawurldecode(' . $params[0] . ')';
default: default:
return $params[0]; return $params[0];
} }
} }
?> ?>
+29 -29
View File
@@ -1,30 +1,30 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty upper modifier plugin * Smarty upper modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: lower<br> * Name: lower<br>
* Purpose: convert string to uppercase * Purpose: convert string to uppercase
* *
* @link http://smarty.php.net/manual/en/language.modifier.upper.php lower (Smarty online manual) * @link http://smarty.php.net/manual/en/language.modifier.upper.php lower (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_upper($params, $compiler) function smarty_modifiercompiler_upper($params, $compiler)
{ {
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_strtoupper(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')' ; return 'mb_strtoupper(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')' ;
} }
// no MBString fallback // no MBString fallback
return 'strtoupper(' . $params[0] . ')'; return 'strtoupper(' . $params[0] . ')';
} }
?> ?>
@@ -1,46 +1,46 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty wordwrap modifier plugin * Smarty wordwrap modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: wordwrap<br> * Name: wordwrap<br>
* Purpose: wrap a string of text at a given length * Purpose: wrap a string of text at a given length
* *
* @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual) * @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
* @param array $params parameters * @param array $params parameters
* @return string with compiled code * @return string with compiled code
*/ */
function smarty_modifiercompiler_wordwrap($params, $compiler) function smarty_modifiercompiler_wordwrap($params, $compiler)
{ {
if (!isset($params[1])) { if (!isset($params[1])) {
$params[1] = 80; $params[1] = 80;
} }
if (!isset($params[2])) { if (!isset($params[2])) {
$params[2] = '"\n"'; $params[2] = '"\n"';
} }
if (!isset($params[3])) { if (!isset($params[3])) {
$params[3] = 'false'; $params[3] = 'false';
} }
$function = 'wordwrap'; $function = 'wordwrap';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if ($compiler->tag_nocache | $compiler->nocache) { if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
$compiler->template->required_plugins['nocache']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR .'shared.mb_wordwrap.php'; $compiler->template->required_plugins['nocache']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR .'shared.mb_wordwrap.php';
$compiler->template->required_plugins['nocache']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; $compiler->template->required_plugins['nocache']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap';
} else { } else {
$compiler->template->required_plugins['compiled']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR .'shared.mb_wordwrap.php'; $compiler->template->required_plugins['compiled']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR .'shared.mb_wordwrap.php';
$compiler->template->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; $compiler->template->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap';
} }
$function = 'smarty_mb_wordwrap'; $function = 'smarty_mb_wordwrap';
} }
return $function . '(' . $params[0] . ',' . $params[1] . ',' . $params[2] . ',' . $params[3] . ')'; return $function . '(' . $params[0] . ',' . $params[1] . ',' . $params[2] . ',' . $params[3] . ')';
} }
?> ?>
@@ -91,4 +91,4 @@ function smarty_outputfilter_trimwhitespace($source, Smarty_Internal_Template $s
return $source; return $source;
} }
?> ?>
@@ -224,7 +224,7 @@ class Smarty_Template_Cached {
public $timestamp = false; public $timestamp = false;
/** /**
* Source Existance * Source Existence
* @var boolean * @var boolean
*/ */
public $exists = false; public $exists = false;
@@ -1,271 +1,275 @@
<?php <?php
/** /**
* Smarty Internal Plugin CacheResource File * Smarty Internal Plugin CacheResource File
* *
* @package Smarty * @package Smarty
* @subpackage Cacher * @subpackage Cacher
* @author Uwe Tews * @author Uwe Tews
* @author Rodney Rehm * @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.
*
* @package Smarty
* @subpackage Cacher
*/
class Smarty_Internal_CacheResource_File extends Smarty_CacheResource {
/** /**
* populate Cached Object with meta data from Resource * This class does contain all necessary methods for the HTML cache on file system
* *
* @param Smarty_Template_Cached $cached cached object * Implements the file system as resource for the HTML cache Version ussing nocache inserts.
* @param Smarty_Internal_Template $_template template object *
* @return void * @package Smarty
*/ * @subpackage Cacher
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template) */
{ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource {
$_source_file_path = str_replace(':', '.', $_template->source->filepath);
$_cache_id = isset($_template->cache_id) ? preg_replace('![^\w\|]+!', '_', $_template->cache_id) : null; /**
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null; * populate Cached Object with meta data from Resource
$_filepath = $_template->source->uid; *
// if use_sub_dirs, break file into directories * @param Smarty_Template_Cached $cached cached object
if ($_template->smarty->use_sub_dirs) { * @param Smarty_Internal_Template $_template template object
$_filepath = substr($_filepath, 0, 2) . DS * @return void
*/
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
{
$_source_file_path = str_replace(':', '.', $_template->source->filepath);
$_cache_id = isset($_template->cache_id) ? preg_replace('![^\w\|]+!', '_', $_template->cache_id) : null;
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
$_filepath = $_template->source->uid;
// if use_sub_dirs, break file into directories
if ($_template->smarty->use_sub_dirs) {
$_filepath = substr($_filepath, 0, 2) . DS
. substr($_filepath, 2, 2) . DS . substr($_filepath, 2, 2) . DS
. substr($_filepath, 4, 2) . DS . substr($_filepath, 4, 2) . DS
. $_filepath; . $_filepath;
} }
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^'; $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
if (isset($_cache_id)) { if (isset($_cache_id)) {
$_cache_id = str_replace('|', $_compile_dir_sep, $_cache_id) . $_compile_dir_sep; $_cache_id = str_replace('|', $_compile_dir_sep, $_cache_id) . $_compile_dir_sep;
} else {
$_cache_id = '';
}
if (isset($_compile_id)) {
$_compile_id = $_compile_id . $_compile_dir_sep;
} else {
$_compile_id = '';
}
$_cache_dir = $_template->smarty->getCacheDir();
if ($_template->smarty->cache_locking) {
// create locking file name
// relative file name?
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_cache_dir)) {
$_lock_dir = rtrim(getcwd(), '/\\') . DS . $_cache_dir;
} else { } else {
$_lock_dir = $_cache_dir; $_cache_id = '';
} }
$cached->lock_id = $_lock_dir.sha1($_cache_id.$_compile_id.$_template->source->uid).'.lock'; if (isset($_compile_id)) {
} $_compile_id = $_compile_id . $_compile_dir_sep;
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
$cached->timestamp = @filemtime($cached->filepath);
$cached->exists = !!$cached->timestamp;
}
/**
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @return void
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
{
$cached->timestamp = @filemtime($cached->filepath);
$cached->exists = !!$cached->timestamp;
}
/**
* Read the cached template and process its header
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @return booelan true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
{
$_smarty_tpl = $_template;
return @include $_template->cached->filepath;
}
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
* @return boolean success
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
if (Smarty_Internal_Write_File::writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
$_template->cached->timestamp = @filemtime($_template->cached->filepath);
$_template->cached->exists = !!$_template->cached->timestamp;
if ($_template->cached->exists) {
return true;
}
}
return false;
}
/**
* Empty cache
*
* @param Smarty_Internal_Template $_template template object
* @param integer $exp_time expiration time (number of seconds, not timestamp)
* @return integer number of cache files deleted
*/
public function clearAll(Smarty $smarty, $exp_time = null)
{
return $this->clear($smarty, null, null, null, $exp_time);
}
/**
* Empty cache for a specific template
*
* @param Smarty $_template template object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer $exp_time expiration time (number of seconds, not timestamp)
* @return integer number of cache files deleted
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
$_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0;
$_dir = $smarty->getCacheDir();
$_dir_length = strlen($_dir);
if (isset($_cache_id)) {
$_cache_id_parts = explode('|', $_cache_id);
$_cache_id_parts_count = count($_cache_id_parts);
if ($smarty->use_sub_dirs) {
foreach ($_cache_id_parts as $id_part) {
$_dir .= $id_part . DS;
}
}
}
if (isset($resource_name)) {
$_save_stat = $smarty->caching;
$smarty->caching = true;
$tpl = new $smarty->template_class($resource_name, $smarty);
$smarty->caching = $_save_stat;
// remove from template cache
$tpl->source; // have the template registered before unset()
if ($smarty->allow_ambiguous_resources) {
$_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
} else { } else {
$_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id; $_compile_id = '';
} }
if (isset($_templateId[150])) { $_cache_dir = $_template->smarty->getCacheDir();
$_templateId = sha1($_templateId); if ($_template->smarty->cache_locking) {
} // create locking file name
unset($smarty->template_objects[$_templateId]); // relative file name?
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_cache_dir)) {
if ($tpl->source->exists) { $_lock_dir = rtrim(getcwd(), '/\\') . DS . $_cache_dir;
$_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
} else {
return 0;
}
}
$_count = 0;
$_time = time();
if (file_exists($_dir)) {
$_cacheDirs = new RecursiveDirectoryIterator($_dir);
$_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($_cache as $_file) {
/* PrestaShop - Do not delete index.php and .svn files */
if (preg_match('/^(\.|\.\.|\.svn|index\.php)$/', $_file->getFilename()))
continue;
/* End */
// directory ?
if ($_file->isDir()) {
if (!$_cache->isDot()) {
// delete folder if empty
@rmdir($_file->getPathname());
}
} else { } else {
$_parts = explode($_dir_sep, str_replace('\\', '/', substr((string)$_file, $_dir_length))); $_lock_dir = $_cache_dir;
$_parts_count = count($_parts); }
// check name $cached->lock_id = $_lock_dir.sha1($_cache_id.$_compile_id.$_template->source->uid).'.lock';
if (isset($resource_name)) { }
if ($_parts[$_parts_count-1] != $_resourcename_parts) { $cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
continue; $cached->timestamp = @filemtime($cached->filepath);
} $cached->exists = !!$cached->timestamp;
} }
// check compile id
if (isset($_compile_id) && (!isset($_parts[$_parts_count-2 - $_compile_id_offset]) || $_parts[$_parts_count-2 - $_compile_id_offset] != $_compile_id)) { /**
continue; * populate Cached Object with timestamp and exists from Resource
} *
// check cache id * @param Smarty_Template_Cached $cached cached object
if (isset($_cache_id)) { * @return void
// count of cache id parts */
$_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset; public function populateTimestamp(Smarty_Template_Cached $cached)
if ($_parts_count < $_cache_id_parts_count) { {
continue; $cached->timestamp = @filemtime($cached->filepath);
} $cached->exists = !!$cached->timestamp;
for ($i = 0; $i < $_cache_id_parts_count; $i++) { }
if ($_parts[$i] != $_cache_id_parts[$i]) continue 2;
} /**
} * Read the cached template and process its header
// expired ? *
if (isset($exp_time) && $_time - @filemtime($_file) < $exp_time) { * @param Smarty_Internal_Template $_template template object
continue; * @param Smarty_Template_Cached $cached cached object
} * @return booelan true or false if the cached content does not exist
$_count += @unlink((string) $_file) ? 1 : 0; */
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
{
$_smarty_tpl = $_template;
return @include $_template->cached->filepath;
}
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
* @return boolean success
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
if (Smarty_Internal_Write_File::writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
$_template->cached->timestamp = @filemtime($_template->cached->filepath);
$_template->cached->exists = !!$_template->cached->timestamp;
if ($_template->cached->exists) {
return true;
} }
} }
return false;
} }
return $_count;
}
/** /**
* Check is cache is locked for this template * Empty cache
* *
* @param Smarty $smarty Smarty object * @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object * @param integer $exp_time expiration time (number of seconds, not timestamp)
* @return booelan true or false if cache is locked * @return integer number of cache files deleted
*/ */
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached) public function clearAll(Smarty $smarty, $exp_time = null)
{ {
if (version_compare(PHP_VERSION, '5.3.0', '>=')) { return $this->clear($smarty, null, null, null, $exp_time);
clearstatcache(true, $cached->lock_id);
} else {
clearstatcache();
} }
$t = @filemtime($cached->lock_id);
return $t && (time() - $t < $smarty->locking_timeout);
}
/** /**
* Lock cache for this template * Empty cache for a specific template
* *
* @param Smarty $smarty Smarty object * @param Smarty $_template template object
* @param Smarty_Template_Cached $cached cached object * @param string $resource_name template name
*/ * @param string $cache_id cache id
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached) * @param string $compile_id compile id
{ * @param integer $exp_time expiration time (number of seconds, not timestamp)
$cached->is_locked = true; * @return integer number of cache files deleted
touch($cached->lock_id); */
} public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
$_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0;
$_dir = $smarty->getCacheDir();
$_dir_length = strlen($_dir);
if (isset($_cache_id)) {
$_cache_id_parts = explode('|', $_cache_id);
$_cache_id_parts_count = count($_cache_id_parts);
if ($smarty->use_sub_dirs) {
foreach ($_cache_id_parts as $id_part) {
$_dir .= $id_part . DS;
}
}
}
if (isset($resource_name)) {
$_save_stat = $smarty->caching;
$smarty->caching = true;
$tpl = new $smarty->template_class($resource_name, $smarty);
$smarty->caching = $_save_stat;
/** // remove from template cache
* Unlock cache for this template $tpl->source; // have the template registered before unset()
* if ($smarty->allow_ambiguous_resources) {
* @param Smarty $smarty Smarty object $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
* @param Smarty_Template_Cached $cached cached object } else {
*/ $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached) }
{ if (isset($_templateId[150])) {
$cached->is_locked = false; $_templateId = sha1($_templateId);
@unlink($cached->lock_id); }
unset($smarty->template_objects[$_templateId]);
if ($tpl->source->exists) {
$_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
} else {
return 0;
}
}
$_count = 0;
$_time = time();
if (file_exists($_dir)) {
$_cacheDirs = new RecursiveDirectoryIterator($_dir);
$_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($_cache as $_file) {
if (substr(basename($_file->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue;
// directory ?
if ($_file->isDir()) {
if (!$_cache->isDot()) {
// delete folder if empty
@rmdir($_file->getPathname());
}
} else {
$_parts = explode($_dir_sep, str_replace('\\', '/', substr((string)$_file, $_dir_length)));
$_parts_count = count($_parts);
// check name
if (isset($resource_name)) {
if ($_parts[$_parts_count-1] != $_resourcename_parts) {
continue;
}
}
// check compile id
if (isset($_compile_id) && (!isset($_parts[$_parts_count-2 - $_compile_id_offset]) || $_parts[$_parts_count-2 - $_compile_id_offset] != $_compile_id)) {
continue;
}
// check cache id
if (isset($_cache_id)) {
// count of cache id parts
$_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset;
if ($_parts_count < $_cache_id_parts_count) {
continue;
}
for ($i = 0; $i < $_cache_id_parts_count; $i++) {
if ($_parts[$i] != $_cache_id_parts[$i]) continue 2;
}
}
// expired ?
if (isset($exp_time)) {
if ($exp_time < 0) {
preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match);
if ($_time < (@filemtime($_file) + $match[1])) {
continue;
}
} else {
if ($_time - @filemtime($_file) < $exp_time) {
continue;
}
}
}
$_count += @unlink((string) $_file) ? 1 : 0;
}
}
}
return $_count;
}
/**
* Check is cache is locked for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @return booelan true or false if cache is locked
*/
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
clearstatcache(true, $cached->lock_id);
} else {
clearstatcache();
}
$t = @filemtime($cached->lock_id);
return $t && (time() - $t < $smarty->locking_timeout);
}
/**
* Lock cache for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*/
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
$cached->is_locked = true;
touch($cached->lock_id);
}
/**
* Unlock cache for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
*/
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
$cached->is_locked = false;
@unlink($cached->lock_id);
}
} }
}
?> ?>
@@ -84,7 +84,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
$al = ''; $al = '';
} }
if (0 == preg_match("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")(\s*?)?((append|prepend|nocache)?(\s*)?(hide)?)?(\s*{$_rdl})!", $block_tag, $_match)) { if (0 == preg_match("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")(\s*?)?((append|prepend|nocache)?(\s*)?(hide)?)?(\s*{$_rdl})!", $block_tag, $_match)) {
$error_text = 'Syntax Error in template "' . $template->source->filepath . '" "' . htmlspecialchars($block_tag) . '" illegal options'; $error_text = 'Syntax Error in template "' . $template->source->filepath . '" "' . $block_tag . '" illegal options';
throw new SmartyCompilerException($error_text); throw new SmartyCompilerException($error_text);
} else { } else {
$_name = trim($_match[3], '\'"'); $_name = trim($_match[3], '\'"');
@@ -179,7 +179,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
return ''; return '';
} }
$_tpl = new Smarty_Internal_template('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id, $_tpl = new Smarty_Internal_template('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
$compiler->template->compile_id = null, $compiler->template->caching, $compiler->template->cache_lifetime); $compiler->template->compile_id, $compiler->template->caching, $compiler->template->cache_lifetime);
$_tpl->variable_filters = $compiler->template->variable_filters; $_tpl->variable_filters = $compiler->template->variable_filters;
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash']; $_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
$_tpl->source->filepath = $compiler->template->block_data[$_name]['file']; $_tpl->source->filepath = $compiler->template->block_data[$_name]['file'];
@@ -190,6 +190,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
$_tpl->compiler->forceNocache = 1; $_tpl->compiler->forceNocache = 1;
} }
$_tpl->compiler->suppressHeader = true; $_tpl->compiler->suppressHeader = true;
$_tpl->compiler->suppressFilter = true;
$_tpl->compiler->suppressTemplatePropertyHeader = true; $_tpl->compiler->suppressTemplatePropertyHeader = true;
$_tpl->compiler->suppressMergedTemplates = true; $_tpl->compiler->suppressMergedTemplates = true;
if (strpos($compiler->template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) { if (strpos($compiler->template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
@@ -1,77 +1,77 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Break * Smarty Internal Plugin Compile Break
* *
* Compiles the {break} tag * Compiles the {break} tag
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Break Class * Smarty Internal Plugin Compile Break Class
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
*/ */
class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase {
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
* @var array * @var array
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $optional_attributes = array('levels'); public $optional_attributes = array('levels');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
* @var array * @var array
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $shorttag_order = array('levels'); public $shorttag_order = array('levels');
/** /**
* Compiles code for the {break} tag * Compiles code for the {break} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, $compiler, $parameter)
{ {
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
} }
if (isset($_attr['levels'])) { if (isset($_attr['levels'])) {
if (!is_numeric($_attr['levels'])) { if (!is_numeric($_attr['levels'])) {
$compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno); $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno);
} }
$_levels = $_attr['levels']; $_levels = $_attr['levels'];
} else { } else {
$_levels = 1; $_levels = 1;
} }
$level_count = $_levels; $level_count = $_levels;
$stack_count = count($compiler->_tag_stack) - 1; $stack_count = count($compiler->_tag_stack) - 1;
while ($level_count > 0 && $stack_count >= 0) { while ($level_count > 0 && $stack_count >= 0) {
if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) { if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
$level_count--; $level_count--;
} }
$stack_count--; $stack_count--;
} }
if ($level_count != 0) { if ($level_count != 0) {
$compiler->trigger_template_error("cannot break {$_levels} level(s)", $compiler->lex->taglineno); $compiler->trigger_template_error("cannot break {$_levels} level(s)", $compiler->lex->taglineno);
} }
$compiler->has_code = true; $compiler->has_code = true;
return "<?php break {$_levels}?>"; return "<?php break {$_levels}?>";
} }
} }
?> ?>
@@ -1,78 +1,78 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Continue * Smarty Internal Plugin Compile Continue
* *
* Compiles the {continue} tag * Compiles the {continue} tag
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Continue Class * Smarty Internal Plugin Compile Continue Class
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
*/ */
class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase {
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
* @var array * @var array
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $optional_attributes = array('levels'); public $optional_attributes = array('levels');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
* @var array * @var array
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $shorttag_order = array('levels'); public $shorttag_order = array('levels');
/** /**
* Compiles code for the {continue} tag * Compiles code for the {continue} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, $compiler, $parameter)
{ {
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
} }
if (isset($_attr['levels'])) { if (isset($_attr['levels'])) {
if (!is_numeric($_attr['levels'])) { if (!is_numeric($_attr['levels'])) {
$compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno); $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno);
} }
$_levels = $_attr['levels']; $_levels = $_attr['levels'];
} else { } else {
$_levels = 1; $_levels = 1;
} }
$level_count = $_levels; $level_count = $_levels;
$stack_count = count($compiler->_tag_stack) - 1; $stack_count = count($compiler->_tag_stack) - 1;
while ($level_count > 0 && $stack_count >= 0) { while ($level_count > 0 && $stack_count >= 0) {
if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) { if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
$level_count--; $level_count--;
} }
$stack_count--; $stack_count--;
} }
if ($level_count != 0) { if ($level_count != 0) {
$compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno); $compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno);
} }
$compiler->has_code = true; $compiler->has_code = true;
return "<?php continue {$_levels}?>"; return "<?php continue {$_levels}?>";
} }
} }
?> ?>
@@ -1,140 +1,140 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Modifier * Smarty Internal Plugin Compile Modifier
* *
* Compiles code for modifier execution * Compiles code for modifier execution
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Modifier Class * Smarty Internal Plugin Compile Modifier Class
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
*/ */
class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for modifier execution * Compiles code for modifier execution
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter) { public function compile($args, $compiler, $parameter) {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$output = $parameter['value']; $output = $parameter['value'];
// loop over list of modifiers // loop over list of modifiers
foreach ($parameter['modifierlist'] as $single_modifier) { foreach ($parameter['modifierlist'] as $single_modifier) {
$modifier = $single_modifier[0]; $modifier = $single_modifier[0];
$single_modifier[0] = $output; $single_modifier[0] = $output;
$params = implode(',', $single_modifier); $params = implode(',', $single_modifier);
// check if we know already the type of modifier // check if we know already the type of modifier
if (isset($compiler->known_modifier_type[$modifier])) { if (isset($compiler->known_modifier_type[$modifier])) {
$modifier_types = array($compiler->known_modifier_type[$modifier]); $modifier_types = array($compiler->known_modifier_type[$modifier]);
} else { } else {
$modifier_types = array(1, 2, 3, 4, 5, 6); $modifier_types = array(1, 2, 3, 4, 5, 6);
} }
foreach ($modifier_types as $type) { foreach ($modifier_types as $type) {
switch ($type) { switch ($type) {
case 1: case 1:
// registered modifier // registered modifier
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) { if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) {
$function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
if (!is_array($function)) { if (!is_array($function)) {
$output = "{$function}({$params})"; $output = "{$function}({$params})";
} else { } else {
if (is_object($function[0])) { if (is_object($function[0])) {
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
} else { } else {
$output = $function[0] . '::' . $function[1] . '(' . $params . ')'; $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
} }
} }
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[$modifier] = $type;
break 2; break 2;
} }
break; break;
case 2: case 2:
// registered modifier compiler // registered modifier compiler
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) { if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) {
$output = call_user_func($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], $single_modifier, $compiler->smarty); $output = call_user_func($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], $single_modifier, $compiler->smarty);
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[$modifier] = $type;
break 2; break 2;
} }
break; break;
case 3: case 3:
// modifiercompiler plugin // modifiercompiler plugin
if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) { if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
$plugin = 'smarty_modifiercompiler_' . $modifier; $plugin = 'smarty_modifiercompiler_' . $modifier;
$output = $plugin($single_modifier, $compiler); $output = $plugin($single_modifier, $compiler);
} }
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[$modifier] = $type;
break 2; break 2;
} }
break; break;
case 4: case 4:
// modifier plugin // modifier plugin
if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) { if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
$output = "{$function}({$params})"; $output = "{$function}({$params})";
} }
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[$modifier] = $type;
break 2; break 2;
} }
break; break;
case 5: case 5:
// PHP function // PHP function
if (is_callable($modifier)) { if (is_callable($modifier)) {
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) { if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) {
$output = "{$modifier}({$params})"; $output = "{$modifier}({$params})";
} }
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[$modifier] = $type;
break 2; break 2;
} }
break; break;
case 6: case 6:
// default plugin handler // default plugin handler
if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || (is_callable($compiler->smarty->default_plugin_handler_func) && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))) { if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || (is_callable($compiler->smarty->default_plugin_handler_func) && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))) {
$function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
if (!is_array($function)) { if (!is_array($function)) {
$output = "{$function}({$params})"; $output = "{$function}({$params})";
} else { } else {
if (is_object($function[0])) { if (is_object($function[0])) {
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
} else { } else {
$output = $function[0] . '::' . $function[1] . '(' . $params . ')'; $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
} }
} }
} }
if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) { if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) {
// was a plugin // was a plugin
$compiler->known_modifier_type[$modifier] = 4; $compiler->known_modifier_type[$modifier] = 4;
} else { } else {
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[$modifier] = $type;
} }
break 2; break 2;
} }
} }
} }
if (!isset($compiler->known_modifier_type[$modifier])) { if (!isset($compiler->known_modifier_type[$modifier])) {
$compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", $compiler->lex->taglineno); $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", $compiler->lex->taglineno);
} }
} }
return $output; return $output;
} }
} }
?> ?>
@@ -1,113 +1,113 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Registered Block * Smarty Internal Plugin Compile Registered Block
* *
* Compiles code for the execution of a registered block function * Compiles code for the execution of a registered block function
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Registered Block Class * Smarty Internal Plugin Compile Registered Block Class
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
*/ */
class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_CompileBase {
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
* @var array * @var array
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $optional_attributes = array('_any'); public $optional_attributes = array('_any');
/** /**
* Compiles code for the execution of a block function * Compiles code for the execution of a block function
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @param string $tag name of block function * @param string $tag name of block function
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter, $tag) public function compile($args, $compiler, $parameter, $tag)
{ {
if (!isset($tag[5]) || substr($tag,-5) != 'close') { if (!isset($tag[5]) || substr($tag,-5) != 'close') {
// opening tag of block plugin // opening tag of block plugin
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache']) { if ($_attr['nocache']) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
unset($_attr['nocache']); unset($_attr['nocache']);
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag])) { if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag])) {
$tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag]; $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag];
} else { } else {
$tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag]; $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag];
} }
// convert attributes into parameter array string // convert attributes into parameter array string
$_paramsArray = array(); $_paramsArray = array();
foreach ($_attr as $_key => $_value) { foreach ($_attr as $_key => $_value) {
if (is_int($_key)) { if (is_int($_key)) {
$_paramsArray[] = "$_key=>$_value"; $_paramsArray[] = "$_key=>$_value";
} elseif ($compiler->template->caching && in_array($_key,$tag_info[2])) { } elseif ($compiler->template->caching && in_array($_key,$tag_info[2])) {
$_value = str_replace("'","^#^",$_value); $_value = str_replace("'","^#^",$_value);
$_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^"; $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
} else { } else {
$_paramsArray[] = "'$_key'=>$_value"; $_paramsArray[] = "'$_key'=>$_value";
} }
} }
$_params = 'array(' . implode(",", $_paramsArray) . ')'; $_params = 'array(' . implode(",", $_paramsArray) . ')';
$this->openTag($compiler, $tag, array($_params, $compiler->nocache)); $this->openTag($compiler, $tag, array($_params, $compiler->nocache));
// maybe nocache because of nocache variables or nocache plugin // maybe nocache because of nocache variables or nocache plugin
$compiler->nocache = !$tag_info[1] | $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = !$tag_info[1] | $compiler->nocache | $compiler->tag_nocache;
$function = $tag_info[0]; $function = $tag_info[0];
// compile code // compile code
if (!is_array($function)) { if (!is_array($function)) {
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
} else if (is_object($function[0])) { } else if (is_object($function[0])) {
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
} else { } else {
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
} }
} else { } else {
// must endblock be nocache? // must endblock be nocache?
if ($compiler->nocache) { if ($compiler->nocache) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
$base_tag = substr($tag, 0, -5); $base_tag = substr($tag, 0, -5);
// closing tag of block plugin, restore nocache // closing tag of block plugin, restore nocache
list($_params, $compiler->nocache) = $this->closeTag($compiler, $base_tag); list($_params, $compiler->nocache) = $this->closeTag($compiler, $base_tag);
// This tag does create output // This tag does create output
$compiler->has_output = true; $compiler->has_output = true;
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) { if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) {
$function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0]; $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0];
} else { } else {
$function = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0]; $function = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0];
} }
// compile code // compile code
if (!isset($parameter['modifier_list'])) { if (!isset($parameter['modifier_list'])) {
$mod_pre = $mod_post =''; $mod_pre = $mod_post ='';
} else { } else {
$mod_pre = ' ob_start(); '; $mod_pre = ' ob_start(); ';
$mod_post = 'echo '.$compiler->compileTag('private_modifier',array(),array('modifierlist'=>$parameter['modifier_list'],'value'=>'ob_get_clean()')).';'; $mod_post = 'echo '.$compiler->compileTag('private_modifier',array(),array('modifierlist'=>$parameter['modifier_list'],'value'=>'ob_get_clean()')).';';
} }
if (!is_array($function)) { if (!is_array($function)) {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);".$mod_post." } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);".$mod_post." } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
} else if (is_object($function[0])) { } else if (is_object($function[0])) {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); ".$mod_post."} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); ".$mod_post."} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
} else { } else {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); ".$mod_post."} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); ".$mod_post."} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
} }
} }
return $output . "\n"; return $output . "\n";
} }
} }
?> ?>
@@ -1,81 +1,81 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Registered Function * Smarty Internal Plugin Compile Registered Function
* *
* Compiles code for the execution of a registered function * Compiles code for the execution of a registered function
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Registered Function Class * Smarty Internal Plugin Compile Registered Function Class
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
*/ */
class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Internal_CompileBase {
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
* @var array * @var array
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $optional_attributes = array('_any'); public $optional_attributes = array('_any');
/** /**
* Compiles code for the execution of a registered function * Compiles code for the execution of a registered function
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @param string $tag name of function * @param string $tag name of function
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter, $tag) public function compile($args, $compiler, $parameter, $tag)
{ {
// This tag does create output // This tag does create output
$compiler->has_output = true; $compiler->has_output = true;
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache']) { if ($_attr['nocache']) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
unset($_attr['nocache']); unset($_attr['nocache']);
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) { if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) {
$tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag]; $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag];
} else { } else {
$tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_FUNCTION][$tag]; $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_FUNCTION][$tag];
} }
// not cachable? // not cachable?
$compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[1]; $compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[1];
// convert attributes into parameter array string // convert attributes into parameter array string
$_paramsArray = array(); $_paramsArray = array();
foreach ($_attr as $_key => $_value) { foreach ($_attr as $_key => $_value) {
if (is_int($_key)) { if (is_int($_key)) {
$_paramsArray[] = "$_key=>$_value"; $_paramsArray[] = "$_key=>$_value";
} elseif ($compiler->template->caching && in_array($_key,$tag_info[2])) { } elseif ($compiler->template->caching && in_array($_key,$tag_info[2])) {
$_value = str_replace("'","^#^",$_value); $_value = str_replace("'","^#^",$_value);
$_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^"; $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
} else { } else {
$_paramsArray[] = "'$_key'=>$_value"; $_paramsArray[] = "'$_key'=>$_value";
} }
} }
$_params = 'array(' . implode(",", $_paramsArray) . ')'; $_params = 'array(' . implode(",", $_paramsArray) . ')';
$function = $tag_info[0]; $function = $tag_info[0];
// compile code // compile code
if (!is_array($function)) { if (!is_array($function)) {
$output = "<?php echo {$function}({$_params},\$_smarty_tpl);?>\n"; $output = "<?php echo {$function}({$_params},\$_smarty_tpl);?>\n";
} else if (is_object($function[0])) { } else if (is_object($function[0])) {
$output = "<?php echo \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl);?>\n"; $output = "<?php echo \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl);?>\n";
} else { } else {
$output = "<?php echo {$function[0]}::{$function[1]}({$_params},\$_smarty_tpl);?>\n"; $output = "<?php echo {$function[0]}::{$function[1]}({$_params},\$_smarty_tpl);?>\n";
} }
return $output; return $output;
} }
} }
?> ?>
@@ -1,72 +1,72 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Setfilter * Smarty Internal Plugin Compile Setfilter
* *
* Compiles code for setfilter tag * Compiles code for setfilter tag
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Setfilter Class * Smarty Internal Plugin Compile Setfilter Class
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
*/ */
class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for setfilter tag * Compiles code for setfilter tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, $compiler, $parameter)
{ {
$compiler->variable_filter_stack[] = $compiler->template->variable_filters; $compiler->variable_filter_stack[] = $compiler->template->variable_filters;
$compiler->template->variable_filters = $parameter['modifier_list']; $compiler->template->variable_filters = $parameter['modifier_list'];
// this tag does not return compiled code // this tag does not return compiled code
$compiler->has_code = false; $compiler->has_code = false;
return true; return true;
} }
} }
/** /**
* Smarty Internal Plugin Compile Setfilterclose Class * Smarty Internal Plugin Compile Setfilterclose Class
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
*/ */
class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {/setfilter} tag * Compiles code for the {/setfilter} tag
* *
* This tag does not generate compiled output. It resets variable filter. * This tag does not generate compiled output. It resets variable filter.
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler)
{ {
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
// reset variable filter to previous state // reset variable filter to previous state
if (count($compiler->variable_filter_stack)) { if (count($compiler->variable_filter_stack)) {
$compiler->template->variable_filters = array_pop($compiler->variable_filter_stack); $compiler->template->variable_filters = array_pop($compiler->variable_filter_stack);
} else { } else {
$compiler->template->variable_filters = array(); $compiler->template->variable_filters = array();
} }
// this tag does not return compiled code // this tag does not return compiled code
$compiler->has_code = false; $compiler->has_code = false;
return true; return true;
} }
} }
?> ?>
@@ -1,55 +1,55 @@
<?php <?php
/** /**
* Smarty Internal Plugin Function Call Handler * Smarty Internal Plugin Function Call Handler
* *
* @package Smarty * @package Smarty
* @subpackage PluginsInternal * @subpackage PluginsInternal
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* This class does call function defined with the {function} tag * This class does call function defined with the {function} tag
* *
* @package Smarty * @package Smarty
* @subpackage PluginsInternal * @subpackage PluginsInternal
*/ */
class Smarty_Internal_Function_Call_Handler { class Smarty_Internal_Function_Call_Handler {
/** /**
* This function handles calls to template functions defined by {function} * This function handles calls to template functions defined by {function}
* It does create a PHP function at the first call * It does create a PHP function at the first call
* *
* @param string $_name template function name * @param string $_name template function name
* @param Smarty_Internal_Template $_template template object * @param Smarty_Internal_Template $_template template object
* @param array $_params Smarty variables passed as call parameter * @param array $_params Smarty variables passed as call parameter
* @param string $_hash nocache hash value * @param string $_hash nocache hash value
* @param bool $_nocache nocache flag * @param bool $_nocache nocache flag
*/ */
public static function call($_name, Smarty_Internal_Template $_template, $_params, $_hash, $_nocache) public static function call($_name, Smarty_Internal_Template $_template, $_params, $_hash, $_nocache)
{ {
if ($_nocache) { if ($_nocache) {
$_function = "smarty_template_function_{$_name}_nocache"; $_function = "smarty_template_function_{$_name}_nocache";
} else { } else {
$_function = "smarty_template_function_{$_hash}_{$_name}"; $_function = "smarty_template_function_{$_hash}_{$_name}";
} }
if (!is_callable($_function)) { if (!is_callable($_function)) {
$_code = "function {$_function}(\$_smarty_tpl,\$params) { $_code = "function {$_function}(\$_smarty_tpl,\$params) {
\$saved_tpl_vars = \$_smarty_tpl->tpl_vars; \$saved_tpl_vars = \$_smarty_tpl->tpl_vars;
foreach (\$_smarty_tpl->smarty->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}; foreach (\$_smarty_tpl->smarty->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);};
foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>"; foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>";
if ($_nocache) { if ($_nocache) {
$_code .= preg_replace(array("!<\?php echo \\'/\*%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/|/\*/%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/\\';\?>!", $_code .= preg_replace(array("!<\?php echo \\'/\*%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/|/\*/%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/\\';\?>!",
"!\\\'!"), array('', "'"), $_template->smarty->template_functions[$_name]['compiled']); "!\\\'!"), array('', "'"), $_template->smarty->template_functions[$_name]['compiled']);
$_template->smarty->template_functions[$_name]['called_nocache'] = true; $_template->smarty->template_functions[$_name]['called_nocache'] = true;
} else { } else {
$_code .= preg_replace("/{$_template->smarty->template_functions[$_name]['nocache_hash']}/", $_template->properties['nocache_hash'], $_template->smarty->template_functions[$_name]['compiled']); $_code .= preg_replace("/{$_template->smarty->template_functions[$_name]['nocache_hash']}/", $_template->properties['nocache_hash'], $_template->smarty->template_functions[$_name]['compiled']);
} }
$_code .= "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;}"; $_code .= "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;}";
eval($_code); eval($_code);
} }
$_function($_template, $_params); $_function($_template, $_params);
} }
} }
?> ?>
@@ -1,48 +1,48 @@
<?php <?php
/** /**
* Smarty read include path plugin * Smarty read include path plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsInternal * @subpackage PluginsInternal
* @author Monte Ohrt * @author Monte Ohrt
*/ */
/** /**
* Smarty Internal Read Include Path Class * Smarty Internal Read Include Path Class
* *
* @package Smarty * @package Smarty
* @subpackage PluginsInternal * @subpackage PluginsInternal
*/ */
class Smarty_Internal_Get_Include_Path { class Smarty_Internal_Get_Include_Path {
/** /**
* Return full file path from PHP include_path * Return full file path from PHP include_path
* *
* @param string $filepath filepath * @param string $filepath filepath
* @return string|boolean full filepath or false * @return string|boolean full filepath or false
*/ */
public static function getIncludePath($filepath) public static function getIncludePath($filepath)
{ {
static $_include_path = null; static $_include_path = null;
if (function_exists('stream_resolve_include_path')) { if (function_exists('stream_resolve_include_path')) {
// available since PHP 5.3.2 // available since PHP 5.3.2
return stream_resolve_include_path($filepath); return stream_resolve_include_path($filepath);
} }
if ($_include_path === null) { if ($_include_path === null) {
$_include_path = explode(PATH_SEPARATOR, get_include_path()); $_include_path = explode(PATH_SEPARATOR, get_include_path());
} }
foreach ($_include_path as $_path) { foreach ($_include_path as $_path) {
if (file_exists($_path . DS . $filepath)) { if (file_exists($_path . DS . $filepath)) {
return $_path . DS . $filepath; return $_path . DS . $filepath;
} }
} }
return false; return false;
} }
} }
?> ?>
@@ -1,53 +1,53 @@
<?php <?php
/** /**
* Smarty Internal Plugin Nocache Insert * Smarty Internal Plugin Nocache Insert
* *
* Compiles the {insert} tag into the cache file * Compiles the {insert} tag into the cache file
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Smarty Internal Plugin Compile Insert Class * Smarty Internal Plugin Compile Insert Class
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
*/ */
class Smarty_Internal_Nocache_Insert { class Smarty_Internal_Nocache_Insert {
/** /**
* Compiles code for the {insert} tag into cache file * Compiles code for the {insert} tag into cache file
* *
* @param string $_function insert function name * @param string $_function insert function name
* @param array $_attr array with parameter * @param array $_attr array with parameter
* @param Smarty_Internal_Template $_template template object * @param Smarty_Internal_Template $_template template object
* @param string $_script script name to load or 'null' * @param string $_script script name to load or 'null'
* @param string $_assign optional variable name * @param string $_assign optional variable name
* @return string compiled code * @return string compiled code
*/ */
public static function compile($_function, $_attr, $_template, $_script, $_assign = null) public static function compile($_function, $_attr, $_template, $_script, $_assign = null)
{ {
$_output = '<?php '; $_output = '<?php ';
if ($_script != 'null') { if ($_script != 'null') {
// script which must be included // script which must be included
// code for script file loading // code for script file loading
$_output .= "require_once '{$_script}';"; $_output .= "require_once '{$_script}';";
} }
// call insert // call insert
if (isset($_assign)) { if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign('{$_assign}' , {$_function} (" . var_export($_attr, true) . ",\$_smarty_tpl), true);?>"; $_output .= "\$_smarty_tpl->assign('{$_assign}' , {$_function} (" . var_export($_attr, true) . ",\$_smarty_tpl), true);?>";
} else { } else {
$_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl);?>"; $_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl);?>";
} }
$_tpl = $_template; $_tpl = $_template;
while ($_tpl->parent instanceof Smarty_Internal_Template) { while ($_tpl->parent instanceof Smarty_Internal_Template) {
$_tpl = $_tpl->parent; $_tpl = $_tpl->parent;
} }
return "/*%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/" . $_output . "/*/%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/"; return "/*%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/" . $_output . "/*/%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/";
} }
} }
?> ?>
@@ -1,395 +1,395 @@
<?php <?php
/** /**
* Smarty Internal Plugin Templateparser Parsetrees * Smarty Internal Plugin Templateparser Parsetrees
* *
* These are classes to build parsetrees in the template parser * These are classes to build parsetrees in the template parser
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Thue Kristensen * @author Thue Kristensen
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @ignore * @ignore
*/ */
abstract class _smarty_parsetree { abstract class _smarty_parsetree {
/** /**
* Parser object * Parser object
* @var object * @var object
*/ */
public $parser; public $parser;
/** /**
* Buffer content * Buffer content
* @var mixed * @var mixed
*/ */
public $data; public $data;
/** /**
* Return buffer * Return buffer
* *
* @return string buffer content * @return string buffer content
*/ */
abstract public function to_smarty_php(); abstract public function to_smarty_php();
} }
/** /**
* A complete smarty tag. * A complete smarty tag.
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @ignore * @ignore
*/ */
class _smarty_tag extends _smarty_parsetree { class _smarty_tag extends _smarty_parsetree {
/** /**
* Saved block nesting level * Saved block nesting level
* @var int * @var int
*/ */
public $saved_block_nesting; public $saved_block_nesting;
/** /**
* Create parse tree buffer for Smarty tag * Create parse tree buffer for Smarty tag
* *
* @param object $parser parser object * @param object $parser parser object
* @param string $data content * @param string $data content
*/ */
public function __construct($parser, $data) public function __construct($parser, $data)
{ {
$this->parser = $parser; $this->parser = $parser;
$this->data = $data; $this->data = $data;
$this->saved_block_nesting = $parser->block_nesting_level; $this->saved_block_nesting = $parser->block_nesting_level;
} }
/** /**
* Return buffer content * Return buffer content
* *
* @return string content * @return string content
*/ */
public function to_smarty_php() public function to_smarty_php()
{ {
return $this->data; return $this->data;
} }
/** /**
* Return complied code that loads the evaluated outout of buffer content into a temporary variable * Return complied code that loads the evaluated outout of buffer content into a temporary variable
* *
* @return string template code * @return string template code
*/ */
public function assign_to_var() public function assign_to_var()
{ {
$var = sprintf('$_tmp%d', ++$this->parser->prefix_number); $var = sprintf('$_tmp%d', ++$this->parser->prefix_number);
$this->parser->compiler->prefix_code[] = sprintf('<?php ob_start();?>%s<?php %s=ob_get_clean();?>', $this->data, $var); $this->parser->compiler->prefix_code[] = sprintf('<?php ob_start();?>%s<?php %s=ob_get_clean();?>', $this->data, $var);
return $var; return $var;
} }
} }
/** /**
* Code fragment inside a tag. * Code fragment inside a tag.
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @ignore * @ignore
*/ */
class _smarty_code extends _smarty_parsetree { class _smarty_code extends _smarty_parsetree {
/** /**
* Create parse tree buffer for code fragment * Create parse tree buffer for code fragment
* *
* @param object $parser parser object * @param object $parser parser object
* @param string $data content * @param string $data content
*/ */
public function __construct($parser, $data) public function __construct($parser, $data)
{ {
$this->parser = $parser; $this->parser = $parser;
$this->data = $data; $this->data = $data;
} }
/** /**
* Return buffer content in parentheses * Return buffer content in parentheses
* *
* @return string content * @return string content
*/ */
public function to_smarty_php() public function to_smarty_php()
{ {
return sprintf("(%s)", $this->data); return sprintf("(%s)", $this->data);
} }
} }
/** /**
* Double quoted string inside a tag. * Double quoted string inside a tag.
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @ignore * @ignore
*/ */
class _smarty_doublequoted extends _smarty_parsetree { class _smarty_doublequoted extends _smarty_parsetree {
/** /**
* Create parse tree buffer for double quoted string subtrees * Create parse tree buffer for double quoted string subtrees
* *
* @param object $parser parser object * @param object $parser parser object
* @param _smarty_parsetree $subtree parsetree buffer * @param _smarty_parsetree $subtree parsetree buffer
*/ */
public function __construct($parser, _smarty_parsetree $subtree) public function __construct($parser, _smarty_parsetree $subtree)
{ {
$this->parser = $parser; $this->parser = $parser;
$this->subtrees[] = $subtree; $this->subtrees[] = $subtree;
if ($subtree instanceof _smarty_tag) { if ($subtree instanceof _smarty_tag) {
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack); $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
} }
} }
/** /**
* Append buffer to subtree * Append buffer to subtree
* *
* @param _smarty_parsetree $subtree parsetree buffer * @param _smarty_parsetree $subtree parsetree buffer
*/ */
public function append_subtree(_smarty_parsetree $subtree) public function append_subtree(_smarty_parsetree $subtree)
{ {
$last_subtree = count($this->subtrees) - 1; $last_subtree = count($this->subtrees) - 1;
if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof _smarty_tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) { if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof _smarty_tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) {
if ($subtree instanceof _smarty_code) { if ($subtree instanceof _smarty_code) {
$this->subtrees[$last_subtree]->data .= '<?php echo ' . $subtree->data . ';?>'; $this->subtrees[$last_subtree]->data .= '<?php echo ' . $subtree->data . ';?>';
} elseif ($subtree instanceof _smarty_dq_content) { } elseif ($subtree instanceof _smarty_dq_content) {
$this->subtrees[$last_subtree]->data .= '<?php echo "' . $subtree->data . '";?>'; $this->subtrees[$last_subtree]->data .= '<?php echo "' . $subtree->data . '";?>';
} else { } else {
$this->subtrees[$last_subtree]->data .= $subtree->data; $this->subtrees[$last_subtree]->data .= $subtree->data;
} }
} else { } else {
$this->subtrees[] = $subtree; $this->subtrees[] = $subtree;
} }
if ($subtree instanceof _smarty_tag) { if ($subtree instanceof _smarty_tag) {
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack); $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
} }
} }
/** /**
* Merge subtree buffer content together * Merge subtree buffer content together
* *
* @return string compiled template code * @return string compiled template code
*/ */
public function to_smarty_php() public function to_smarty_php()
{ {
$code = ''; $code = '';
foreach ($this->subtrees as $subtree) { foreach ($this->subtrees as $subtree) {
if ($code !== "") { if ($code !== "") {
$code .= "."; $code .= ".";
} }
if ($subtree instanceof _smarty_tag) { if ($subtree instanceof _smarty_tag) {
$more_php = $subtree->assign_to_var(); $more_php = $subtree->assign_to_var();
} else { } else {
$more_php = $subtree->to_smarty_php(); $more_php = $subtree->to_smarty_php();
} }
$code .= $more_php; $code .= $more_php;
if (!$subtree instanceof _smarty_dq_content) { if (!$subtree instanceof _smarty_dq_content) {
$this->parser->compiler->has_variable_string = true; $this->parser->compiler->has_variable_string = true;
} }
} }
return $code; return $code;
} }
} }
/** /**
* Raw chars as part of a double quoted string. * Raw chars as part of a double quoted string.
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @ignore * @ignore
*/ */
class _smarty_dq_content extends _smarty_parsetree { class _smarty_dq_content extends _smarty_parsetree {
/** /**
* Create parse tree buffer with string content * Create parse tree buffer with string content
* *
* @param object $parser parser object * @param object $parser parser object
* @param string $data string section * @param string $data string section
*/ */
public function __construct($parser, $data) public function __construct($parser, $data)
{ {
$this->parser = $parser; $this->parser = $parser;
$this->data = $data; $this->data = $data;
} }
/** /**
* Return content as double quoted string * Return content as double quoted string
* *
* @return string doubled quoted string * @return string doubled quoted string
*/ */
public function to_smarty_php() public function to_smarty_php()
{ {
return '"' . $this->data . '"'; return '"' . $this->data . '"';
} }
} }
/** /**
* Template element * Template element
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @ignore * @ignore
*/ */
class _smarty_template_buffer extends _smarty_parsetree { class _smarty_template_buffer extends _smarty_parsetree {
/** /**
* Array of template elements * Array of template elements
* *
* @var array * @var array
*/ */
public $subtrees = Array(); public $subtrees = Array();
/** /**
* Create root of parse tree for template elements * Create root of parse tree for template elements
* *
* @param object $parser parse object * @param object $parser parse object
*/ */
public function __construct($parser) public function __construct($parser)
{ {
$this->parser = $parser; $this->parser = $parser;
} }
/** /**
* Append buffer to subtree * Append buffer to subtree
* *
* @param _smarty_parsetree $subtree * @param _smarty_parsetree $subtree
*/ */
public function append_subtree(_smarty_parsetree $subtree) public function append_subtree(_smarty_parsetree $subtree)
{ {
$this->subtrees[] = $subtree; $this->subtrees[] = $subtree;
} }
/** /**
* Sanitize and merge subtree buffers together * Sanitize and merge subtree buffers together
* *
* @return string template code content * @return string template code content
*/ */
public function to_smarty_php() public function to_smarty_php()
{ {
$code = ''; $code = '';
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) { for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {
if ($key + 2 < $cnt) { if ($key + 2 < $cnt) {
if ($this->subtrees[$key] instanceof _smarty_linebreak && $this->subtrees[$key + 1] instanceof _smarty_tag && $this->subtrees[$key + 1]->data == '' && $this->subtrees[$key + 2] instanceof _smarty_linebreak) { if ($this->subtrees[$key] instanceof _smarty_linebreak && $this->subtrees[$key + 1] instanceof _smarty_tag && $this->subtrees[$key + 1]->data == '' && $this->subtrees[$key + 2] instanceof _smarty_linebreak) {
$key = $key + 1; $key = $key + 1;
continue; continue;
} }
if (substr($this->subtrees[$key]->data, -1) == '<' && $this->subtrees[$key + 1]->data == '' && substr($this->subtrees[$key + 2]->data, -1) == '?') { if (substr($this->subtrees[$key]->data, -1) == '<' && $this->subtrees[$key + 1]->data == '' && substr($this->subtrees[$key + 2]->data, -1) == '?') {
$key = $key + 2; $key = $key + 2;
continue; continue;
} }
} }
if (substr($code, -1) == '<') { if (substr($code, -1) == '<') {
$subtree = $this->subtrees[$key]->to_smarty_php(); $subtree = $this->subtrees[$key]->to_smarty_php();
if (substr($subtree, 0, 1) == '?') { if (substr($subtree, 0, 1) == '?') {
$code = substr($code, 0, strlen($code) - 1) . '<<?php ?>?' . substr($subtree, 1); $code = substr($code, 0, strlen($code) - 1) . '<<?php ?>?' . substr($subtree, 1);
} elseif ($this->parser->asp_tags && substr($subtree, 0, 1) == '%') { } elseif ($this->parser->asp_tags && substr($subtree, 0, 1) == '%') {
$code = substr($code, 0, strlen($code) - 1) . '<<?php ?>%' . substr($subtree, 1); $code = substr($code, 0, strlen($code) - 1) . '<<?php ?>%' . substr($subtree, 1);
} else { } else {
$code .= $subtree; $code .= $subtree;
} }
continue; continue;
} }
if ($this->parser->asp_tags && substr($code, -1) == '%') { if ($this->parser->asp_tags && substr($code, -1) == '%') {
$subtree = $this->subtrees[$key]->to_smarty_php(); $subtree = $this->subtrees[$key]->to_smarty_php();
if (substr($subtree, 0, 1) == '>') { if (substr($subtree, 0, 1) == '>') {
$code = substr($code, 0, strlen($code) - 1) . '%<?php ?>>' . substr($subtree, 1); $code = substr($code, 0, strlen($code) - 1) . '%<?php ?>>' . substr($subtree, 1);
} else { } else {
$code .= $subtree; $code .= $subtree;
} }
continue; continue;
} }
if (substr($code, -1) == '?') { if (substr($code, -1) == '?') {
$subtree = $this->subtrees[$key]->to_smarty_php(); $subtree = $this->subtrees[$key]->to_smarty_php();
if (substr($subtree, 0, 1) == '>') { if (substr($subtree, 0, 1) == '>') {
$code = substr($code, 0, strlen($code) - 1) . '?<?php ?>>' . substr($subtree, 1); $code = substr($code, 0, strlen($code) - 1) . '?<?php ?>>' . substr($subtree, 1);
} else { } else {
$code .= $subtree; $code .= $subtree;
} }
continue; continue;
} }
$code .= $this->subtrees[$key]->to_smarty_php(); $code .= $this->subtrees[$key]->to_smarty_php();
} }
return $code; return $code;
} }
} }
/** /**
* template text * template text
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @ignore * @ignore
*/ */
class _smarty_text extends _smarty_parsetree { class _smarty_text extends _smarty_parsetree {
/** /**
* Create template text buffer * Create template text buffer
* *
* @param object $parser parser object * @param object $parser parser object
* @param string $data text * @param string $data text
*/ */
public function __construct($parser, $data) public function __construct($parser, $data)
{ {
$this->parser = $parser; $this->parser = $parser;
$this->data = $data; $this->data = $data;
} }
/** /**
* Return buffer content * Return buffer content
* *
* @return strint text * @return strint text
*/ */
public function to_smarty_php() public function to_smarty_php()
{ {
return $this->data; return $this->data;
} }
} }
/** /**
* template linebreaks * template linebreaks
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @ignore * @ignore
*/ */
class _smarty_linebreak extends _smarty_parsetree { class _smarty_linebreak extends _smarty_parsetree {
/** /**
* Create buffer with linebreak content * Create buffer with linebreak content
* *
* @param object $parser parser object * @param object $parser parser object
* @param string $data linebreak string * @param string $data linebreak string
*/ */
public function __construct($parser, $data) public function __construct($parser, $data)
{ {
$this->parser = $parser; $this->parser = $parser;
$this->data = $data; $this->data = $data;
} }
/** /**
* Return linebrak * Return linebrak
* *
* @return string linebreak * @return string linebreak
*/ */
public function to_smarty_php() public function to_smarty_php()
{ {
return $this->data; return $this->data;
} }
} }
?> ?>
@@ -1,94 +1,94 @@
<?php <?php
/** /**
* Smarty Internal Plugin Resource Eval * Smarty Internal Plugin Resource Eval
* *
* @package Smarty * @package Smarty
* @subpackage TemplateResources * @subpackage TemplateResources
* @author Uwe Tews * @author Uwe Tews
* @author Rodney Rehm * @author Rodney Rehm
*/ */
/** /**
* Smarty Internal Plugin Resource Eval * Smarty Internal Plugin Resource Eval
* *
* Implements the strings as resource for Smarty template * Implements the strings as resource for Smarty template
* *
* {@internal unlike string-resources the compiled state of eval-resources is NOT saved for subsequent access}} * {@internal unlike string-resources the compiled state of eval-resources is NOT saved for subsequent access}}
* *
* @package Smarty * @package Smarty
* @subpackage TemplateResources * @subpackage TemplateResources
*/ */
class Smarty_Internal_Resource_Eval extends Smarty_Resource_Recompiled { class Smarty_Internal_Resource_Eval extends Smarty_Resource_Recompiled {
/** /**
* 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
*/ */
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null) public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
{ {
$source->uid = $source->filepath = sha1($source->name); $source->uid = $source->filepath = sha1($source->name);
$source->timestamp = false; $source->timestamp = false;
$source->exists = true; $source->exists = true;
} }
/** /**
* Load template's source from $resource_name into current template object * Load template's source from $resource_name into current template object
* *
* @uses decode() to decode base64 and urlencoded template_resources * @uses decode() to decode base64 and urlencoded template_resources
* @param Smarty_Template_Source $source source object * @param Smarty_Template_Source $source source object
* @return string template source * @return string template source
*/ */
public function getContent(Smarty_Template_Source $source) public function getContent(Smarty_Template_Source $source)
{ {
return $this->decode($source->name); return $this->decode($source->name);
} }
/** /**
* decode base64 and urlencode * decode base64 and urlencode
* *
* @param string $string template_resource to decode * @param string $string template_resource to decode
* @return string decoded template_resource * @return string decoded template_resource
*/ */
protected function decode($string) protected function decode($string)
{ {
// decode if specified // decode if specified
if (($pos = strpos($string, ':')) !== false) { if (($pos = strpos($string, ':')) !== false) {
if (!strncmp($string, 'base64', 6)) { if (!strncmp($string, 'base64', 6)) {
return base64_decode(substr($string, 7)); return base64_decode(substr($string, 7));
} elseif (!strncmp($string, 'urlencode', 9)) { } elseif (!strncmp($string, 'urlencode', 9)) {
return urldecode(substr($string, 10)); return urldecode(substr($string, 10));
} }
} }
return $string; return $string;
} }
/** /**
* modify resource_name according to resource handlers specifications * modify resource_name according to resource handlers specifications
* *
* @param Smarty $smarty Smarty instance * @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique * @param string $resource_name resource_name to make unique
* @return string unique resource name * @return string unique resource name
*/ */
protected function buildUniqueResourceName(Smarty $smarty, $resource_name) protected function buildUniqueResourceName(Smarty $smarty, $resource_name)
{ {
return get_class($this) . '#' .$this->decode($resource_name); return get_class($this) . '#' .$this->decode($resource_name);
} }
/** /**
* Determine basename for compiled filename * Determine basename for compiled filename
* *
* @param Smarty_Template_Source $source source object * @param Smarty_Template_Source $source source object
* @return string resource's basename * @return string resource's basename
*/ */
protected function getBasename(Smarty_Template_Source $source) protected function getBasename(Smarty_Template_Source $source)
{ {
return ''; return '';
} }
} }
?> ?>
@@ -467,10 +467,15 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
} }
} }
if ($cache) { if ($cache) {
// CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
if ($this->caching === Smarty::CACHING_LIFETIME_SAVED &&
$this->properties['cache_lifetime'] >= 0 &&
(time() > ($this->cached->timestamp + $this->properties['cache_lifetime']))) {
$is_valid = false;
}
$this->cached->valid = $is_valid; $this->cached->valid = $is_valid;
} else { } else {
$this->mustCompile = !$is_valid; $this->mustCompile = !$is_valid; }
}
// store data in reusable Smarty_Template_Compiled // store data in reusable Smarty_Template_Compiled
if (!$cache) { if (!$cache) {
$this->compiled->_properties = $properties; $this->compiled->_properties = $properties;
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -58,7 +58,7 @@ class Smarty_Internal_Utility {
* @param Smarty $smarty Smarty instance * @param Smarty $smarty Smarty instance
* @return integer number of template files compiled * @return integer number of template files compiled
*/ */
public static function compileAllTemplates($extention, $force_compile, $time_limit, $max_errors, Smarty $smarty) public static function compileAllTemplates($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty)
{ {
// switch off time limit // switch off time limit
if (function_exists('set_time_limit')) { if (function_exists('set_time_limit')) {
@@ -74,7 +74,7 @@ class Smarty_Internal_Utility {
foreach ($_compile as $_fileinfo) { foreach ($_compile as $_fileinfo) {
$_file = $_fileinfo->getFilename(); $_file = $_fileinfo->getFilename();
if (substr(basename($_fileinfo->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue; if (substr(basename($_fileinfo->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue;
if (!substr_compare($_file, $extention, - strlen($extention)) == 0) continue; if (!substr_compare($_file, $extension, - strlen($extension)) == 0) continue;
if ($_fileinfo->getPath() == substr($_dir, 0, -1)) { if ($_fileinfo->getPath() == substr($_dir, 0, -1)) {
$_template_file = $_file; $_template_file = $_file;
} else { } else {
@@ -122,7 +122,7 @@ class Smarty_Internal_Utility {
* @param Smarty $smarty Smarty instance * @param Smarty $smarty Smarty instance
* @return integer number of config files compiled * @return integer number of config files compiled
*/ */
public static function compileAllConfig($extention, $force_compile, $time_limit, $max_errors, Smarty $smarty) public static function compileAllConfig($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty)
{ {
// switch off time limit // switch off time limit
if (function_exists('set_time_limit')) { if (function_exists('set_time_limit')) {
@@ -138,7 +138,7 @@ class Smarty_Internal_Utility {
foreach ($_compile as $_fileinfo) { foreach ($_compile as $_fileinfo) {
$_file = $_fileinfo->getFilename(); $_file = $_fileinfo->getFilename();
if (substr(basename($_fileinfo->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue; if (substr(basename($_fileinfo->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue;
if (!substr_compare($_file, $extention, - strlen($extention)) == 0) continue; if (!substr_compare($_file, $extension, - strlen($extension)) == 0) continue;
if ($_fileinfo->getPath() == substr($_dir, 0, -1)) { if ($_fileinfo->getPath() == substr($_dir, 0, -1)) {
$_config_file = $_file; $_config_file = $_file;
} else { } else {
@@ -308,7 +308,7 @@ class Smarty_Internal_Utility {
foreach($smarty->getTemplateDir() as $template_dir) { foreach($smarty->getTemplateDir() as $template_dir) {
$_template_dir = $template_dir; $_template_dir = $template_dir;
$template_dir = realpath($template_dir); $template_dir = realpath($template_dir);
// resolve include_path or fail existance // resolve include_path or fail existence
if (!$template_dir) { if (!$template_dir) {
if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_template_dir)) { if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_template_dir)) {
// try PHP include_path // try PHP include_path
@@ -429,7 +429,7 @@ class Smarty_Internal_Utility {
foreach($smarty->getPluginsDir() as $plugin_dir) { foreach($smarty->getPluginsDir() as $plugin_dir) {
$_plugin_dir = $plugin_dir; $_plugin_dir = $plugin_dir;
$plugin_dir = realpath($plugin_dir); $plugin_dir = realpath($plugin_dir);
// resolve include_path or fail existance // resolve include_path or fail existence
if (!$plugin_dir) { if (!$plugin_dir) {
if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) { if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
// try PHP include_path // try PHP include_path
@@ -561,7 +561,7 @@ class Smarty_Internal_Utility {
foreach($smarty->getConfigDir() as $config_dir) { foreach($smarty->getConfigDir() as $config_dir) {
$_config_dir = $config_dir; $_config_dir = $config_dir;
$config_dir = realpath($config_dir); $config_dir = realpath($config_dir);
// resolve include_path or fail existance // resolve include_path or fail existence
if (!$config_dir) { if (!$config_dir) {
if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) { if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) {
// try PHP include_path // try PHP include_path
+2 -2
View File
@@ -584,7 +584,7 @@ abstract class Smarty_Resource {
* @author Rodney Rehm * @author Rodney Rehm
* *
* @property integer $timestamp Source Timestamp * @property integer $timestamp Source Timestamp
* @property boolean $exists Source Existance * @property boolean $exists Source Existence
* @property boolean $template Extended Template reference * @property boolean $template Extended Template reference
* @property string $content Source Content * @property string $content Source Content
*/ */
@@ -811,7 +811,7 @@ class Smarty_Template_Compiled {
public $timestamp = null; public $timestamp = null;
/** /**
* Compiled Existance * Compiled Existence
* @var boolean * @var boolean
*/ */
public $exists = false; public $exists = false;
+1 -1
View File
@@ -77,7 +77,7 @@ class Smarty_Security {
'nl2br', 'nl2br',
); );
/** /**
* This is an array of trusted PHP modifers. * This is an array of trusted PHP modifiers.
* *
* If empty all modifiers are allowed. * If empty all modifiers are allowed.
* To disable all modifier set $modifiers = null. * To disable all modifier set $modifiers = null.