Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Smarty library #247

Merged
merged 5 commits into from
Oct 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?php
/*
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* 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
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* 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
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2017 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* 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
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* 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
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2017 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

require_once(_PS_TOOL_DIR_.'smarty/Smarty.class.php');

48 changes: 24 additions & 24 deletions classes/SmartyCustom.php → classes/Smarty/SmartyCustom.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?php
/*
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* 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
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* 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
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2017 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* 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
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* 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
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2017 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

class SmartyCustomCore extends Smarty
{
63 changes: 63 additions & 0 deletions classes/Smarty/SmartyDev.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* 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
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* 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
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2016 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

class SmartyDev extends Smarty
{
public function __construct()
{
parent::__construct();
$this->template_class = 'Smarty_Dev_Template';
}

/**
* {@inheritDoc}
*/
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
{
return "\n<!-- begin $template -->\n"
.parent::fetch($template, $cache_id, $compile_id, $parent, $display, $merge_tpl_vars, $no_output_filter)
."\n<!-- end $template -->\n";
}
}

class Smarty_Dev_Template extends Smarty_Internal_Template
{
/** @var SmartyCustom|null */
public $smarty = null;

public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
{
if (!is_null($template)) {
$tpl = $template->template_resource;
} else {
$tpl = $this->template_resource;
}

return "\n<!-- begin $tpl -->\n"
.parent::fetch($template, $cache_id, $compile_id, $parent, $display, $merge_tpl_vars, $no_output_filter)
."\n<!-- end $tpl -->\n";
}
}
95 changes: 95 additions & 0 deletions classes/Smarty/SmartyLazyRegister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/*
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* 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
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* 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
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2015 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Used to delay loading of external classes with smarty->register_plugin.
*/
class SmartyLazyRegister
{
protected $registry = array();
protected static $instance;

/**
* Register a function or method to be dynamically called later.
*
* @param string|array $params function name or array(object name, method name)
*/
public function register($params)
{
if (is_array($params)) {
$this->registry[$params[1]] = $params;
} else {
$this->registry[$params] = $params;
}
}

public function isRegistered($params)
{
if (is_array($params)) {
$params = $params[1];
}

return isset($this->registry[$params]);
}

/**
* Dynamically call static function or method.
*
* @param string $name function name
* @param mixed $arguments function argument
*
* @return mixed function return
*/
public function __call($name, $arguments)
{
$item = $this->registry[$name];

// case 1: call to static method - case 2 : call to static function
if (is_array($item[1])) {
return call_user_func_array($item[1].'::'.$item[0], array($arguments[0], &$arguments[1]));
} else {
$args = array();

foreach ($arguments as $a => $argument) {
if ($a == 0) {
$args[] = $arguments[0];
} else {
$args[] = &$arguments[$a];
}
}

return call_user_func_array($item, $args);
}
}

public static function getInstance()
{
if (!self::$instance) {
self::$instance = new self();
}

return self::$instance;
}
}
68 changes: 68 additions & 0 deletions classes/Smarty/SmartyResourceModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* 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
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* 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
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2015 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

/**
* Override module templates easily
*
* @since 1.7.0.0
*/
class SmartyResourceModuleCore extends Smarty_Resource_Custom
{
private $shop;

public function __construct(array $paths)
{
$this->paths = $paths;
}

/**
* Fetch a template
*
* @param string $name template name
* @param string $source template source
* @param integer $mtime template modification timestamp (epoch)
* @return void
*/
protected function fetch($name, &$source, &$mtime)
{
foreach ($this->paths as $path) {
if (Tools::file_exists_cache($file = $path.$name)) {
if (_PS_MODE_DEV_) {
$source = implode('', [
'<!-- begin '.$file.' -->',
file_get_contents($file),
'<!-- end '.$file.' -->'
]);
} else {
$source = file_get_contents($file);
}
$mtime = filemtime($file);

return;
}
}
}
}
5 changes: 5 additions & 0 deletions classes/Tools.php
Original file line number Diff line number Diff line change
@@ -868,6 +868,11 @@ public static function htmlentitiesDecodeUTF8($string)
return html_entity_decode((string)$string, ENT_QUOTES, 'utf-8');
}

public static function removeHtmlComments($html)
{
return preg_replace('/<!--(.|\s)*?-->/', '', $html);
}

public static function safePostVars()
{
if (!isset($_POST) || !is_array($_POST)) {
Loading