diff --git a/config/smartyadmin.config.inc.php b/config/smartyadmin.config.inc.php index ec1e9a1ea..212f3ebc4 100644 --- a/config/smartyadmin.config.inc.php +++ b/config/smartyadmin.config.inc.php @@ -24,46 +24,8 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ -define('_PS_SMARTY_DIR_', _PS_TOOL_DIR_.'smarty/'); - -require_once(_PS_SMARTY_DIR_.'Smarty.class.php'); - global $smarty; -$smarty = new Smarty(); $smarty->template_dir = _PS_ADMIN_DIR_.'/themes/template'; -$smarty->compile_dir = _PS_CACHE_DIR_.'smarty/compile'; -$smarty->cache_dir = _PS_CACHE_DIR_.'smarty/cache'; -$smarty->caching = false; -$smarty->force_compile = (Configuration::get('PS_SMARTY_FORCE_COMPILE') == _PS_SMARTY_FORCE_COMPILE_) ? true : false; -$smarty->compile_check = (Configuration::get('PS_SMARTY_FORCE_COMPILE') == _PS_SMARTY_CHECK_COMPILE_) ? true : false; -$smarty->debugging = false; -$smarty->debugging_ctrl = 'URL'; // 'NONE' on production - - -if (Configuration::get('PS_HTML_THEME_COMPRESSION')) - $smarty->registerFilter('output', 'smartyMinifyHTML'); -if (Configuration::get('PS_JS_HTML_THEME_COMPRESSION')) - $smarty->registerFilter('output', 'smartyPackJSinHTML'); - -smartyRegisterFunction($smarty, 'modifier', 'truncate', 'smarty_modifier_truncate'); -smartyRegisterFunction($smarty, 'modifier', 'htmlentitiesUTF8', 'smarty_modifier_htmlentitiesUTF8'); -smartyRegisterFunction($smarty, 'modifier', 'secureReferrer', array('Tools', 'secureReferrer')); - -smartyRegisterFunction($smarty, 'function', 't', 'smartyTruncate'); // unused -smartyRegisterFunction($smarty, 'function', 'm', 'smartyMaxWords'); // unused -smartyRegisterFunction($smarty, 'function', 'p', 'smartyShowObject'); // Debug only -smartyRegisterFunction($smarty, 'function', 'd', 'smartyDieObject'); // Debug only -smartyRegisterFunction($smarty, 'function', 'l', 'smartyTranslate'); - -smartyRegisterFunction($smarty, 'function', 'dateFormat', array('Tools', 'dateFormat')); -smartyRegisterFunction($smarty, 'function', 'convertPrice', array('Product', 'convertPrice')); -smartyRegisterFunction($smarty, 'function', 'convertPriceWithCurrency', array('Product', 'convertPriceWithCurrency')); -smartyRegisterFunction($smarty, 'function', 'displayWtPrice', array('Product', 'displayWtPrice')); -smartyRegisterFunction($smarty, 'function', 'displayWtPriceWithCurrency', array('Product', 'displayWtPriceWithCurrency')); -smartyRegisterFunction($smarty, 'function', 'displayPrice', array('Tools', 'displayPriceSmarty')); -smartyRegisterFunction($smarty, 'modifier', 'convertAndFormatPrice', array('Product', 'convertAndFormatPrice')); // used twice -smartyRegisterFunction($smarty, 'function', 'getAdminToken', array('Tools', 'getAdminTokenLiteSmarty')); -smartyRegisterFunction($smarty, 'function', 'displayAddressDetail', array('AddressFormat', 'generateAddressSmarty')); function smartyTranslate($params, &$smarty) { @@ -80,78 +42,3 @@ function smartyTranslate($params, &$smarty) return AdminController::translate($string, $class, $addslashes, $htmlentities); } - -function smartyDieObject($params, &$smarty) -{ - return Tools::d($params['var']); -} - -function smartyShowObject($params, &$smarty) -{ - return Tools::p($params['var']); -} - -function smartyMaxWords($params, &$smarty) -{ - Tools::displayAsDeprecated(); - $params['s'] = str_replace('...', ' ...', html_entity_decode($params['s'], ENT_QUOTES, 'UTF-8')); - $words = explode(' ', $params['s']); - - foreach($words AS &$word) - if(Tools::strlen($word) > $params['n']) - $word = Tools::substr(trim(chunk_split($word, $params['n']-1, '- ')), 0, -1); - - return implode(' ', Tools::htmlentitiesUTF8($words)); -} - -function smartyTruncate($params, &$smarty) -{ - Tools::displayAsDeprecated(); - $text = isset($params['strip']) ? strip_tags($params['text']) : $params['text']; - $length = $params['length']; - $sep = isset($params['sep']) ? $params['sep'] : '...'; - - if (Tools::strlen($text) > $length + Tools::strlen($sep)) - $text = Tools::substr($text, 0, $length).$sep; - - return (isset($params['encode']) ? Tools::htmlentitiesUTF8($text, ENT_NOQUOTES) : $text); -} - -function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false, $charset = 'UTF-8') -{ - if (!$length) - return ''; - - if (Tools::strlen($string) > $length) - { - $length -= min($length, Tools::strlen($etc)); - if (!$break_words && !$middle) - $string = preg_replace('/\s+?(\S+)?$/u', '', Tools::substr($string, 0, $length+1, $charset)); - return !$middle ? Tools::substr($string, 0, $length, $charset).$etc : Tools::substr($string, 0, $length/2, $charset).$etc.Tools::substr($string, -$length/2, $charset); - } - else - return $string; -} - -function smarty_modifier_htmlentitiesUTF8($string) -{ - return Tools::htmlentitiesUTF8($string); -} -function smartyMinifyHTML($tpl_output, &$smarty) -{ - $tpl_output = Media::minifyHTML($tpl_output); - return $tpl_output; -} - -function smartyPackJSinHTML($tpl_output, &$smarty) -{ - $tpl_output = Media::packJSinHTML($tpl_output); - return $tpl_output; -} - -function smartyRegisterFunction($smarty, $type, $function, $params) -{ - if (!in_array($type, array('function', 'modifier'))) - return false; - $smarty->registerPlugin($type, $function, $params); -}