diff options
author | emkael <emkael@tlen.pl> | 2018-10-18 02:40:38 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2018-10-18 02:40:38 +0200 |
commit | eab8a101e7a3fcbb41e01a574985e06c5a3775de (patch) | |
tree | 60f201da5984b0c3638d10da02bba42b61aa3177 /lib/smarty3/plugins/modifiercompiler.escape.php | |
parent | 7f38be342c1495aeca418286c15c25c18ac9e142 (diff) |
Updating Smarty
Diffstat (limited to 'lib/smarty3/plugins/modifiercompiler.escape.php')
-rw-r--r-- | lib/smarty3/plugins/modifiercompiler.escape.php | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/lib/smarty3/plugins/modifiercompiler.escape.php b/lib/smarty3/plugins/modifiercompiler.escape.php index 4816106..e0763ad 100644 --- a/lib/smarty3/plugins/modifiercompiler.escape.php +++ b/lib/smarty3/plugins/modifiercompiler.escape.php @@ -5,42 +5,43 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - -/** - * @ignore - */ -require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'); - /** * Smarty escape modifier plugin - * Type: modifier<br> - * Name: escape<br> + * Type: modifier + * Name: escape * Purpose: escape string for output * * @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual) * @author Rodney Rehm * - * @param array $params parameters - * @param $compiler + * @param array $params parameters + * @param Smarty_Internal_TemplateCompilerBase $compiler * * @return string with compiled code + * @throws \SmartyException */ -function smarty_modifiercompiler_escape($params, $compiler) +function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompilerBase $compiler) { static $_double_encode = null; + static $is_loaded = false; + $compiler->template->_checkPlugins( + array( + array( + 'function' => 'smarty_literal_compiler_param', + 'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php' + ) + ) + ); if ($_double_encode === null) { $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); } - try { $esc_type = smarty_literal_compiler_param($params, 1, 'html'); $char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET); $double_encode = smarty_literal_compiler_param($params, 3, true); - if (!$char_set) { $char_set = Smarty::$_CHARSET; } - switch ($esc_type) { case 'html': if ($_double_encode) { @@ -51,7 +52,7 @@ function smarty_modifiercompiler_escape($params, $compiler) } else { // fall back to modifier.escape.php } - + // no break case 'htmlall': if (Smarty::$_MBSTRING) { if ($_double_encode) { @@ -67,7 +68,6 @@ function smarty_modifiercompiler_escape($params, $compiler) // fall back to modifier.escape.php } } - // no MBString fallback if ($_double_encode) { // php >=5.2.3 - go native @@ -79,39 +79,34 @@ function smarty_modifiercompiler_escape($params, $compiler) } else { // fall back to modifier.escape.php } - + // no break case 'url': return 'rawurlencode(' . $params[ 0 ] . ')'; - case 'urlpathinfo': return 'str_replace("%2F", "/", rawurlencode(' . $params[ 0 ] . '))'; - case 'quotes': // escape unescaped single quotes return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[ 0 ] . ')'; - case 'javascript': // escape quotes and backslashes, newlines, etc. - return 'strtr(' . $params[ 0 ] . + return 'strtr(' . + $params[ 0 ] . ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))'; } - } - catch (SmartyException $e) { + } catch (SmartyException $e) { // pass through to regular plugin fallback } - // could not optimize |escape call, so fallback to regular plugin if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) { - $compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] = + $compiler->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] = SMARTY_PLUGINS_DIR . 'modifier.escape.php'; - $compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'function' ] = + $compiler->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'function' ] = 'smarty_modifier_escape'; } else { - $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'file' ] = + $compiler->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'file' ] = SMARTY_PLUGINS_DIR . 'modifier.escape.php'; - $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] = + $compiler->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] = 'smarty_modifier_escape'; } - return 'smarty_modifier_escape(' . join(', ', $params) . ')'; } |