aboutsummaryrefslogtreecommitdiffstats
path: root/include/smarty/libs/plugins/modifiercompiler.escape.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2015-12-10 14:02:22 +0100
committerplegall <plg@piwigo.org>2015-12-10 14:02:22 +0100
commitfa10e0945ecd45bfe78a2c8fb015a43092b4944b (patch)
tree19cf59c08877e43325efbe9a2584114011a25522 /include/smarty/libs/plugins/modifiercompiler.escape.php
parent16f6a54fa719cc79ff942e4bb8139d7ca09ed997 (diff)
bug #385 update to smarty-3.1.28-dev (from Github)
Diffstat (limited to 'include/smarty/libs/plugins/modifiercompiler.escape.php')
-rw-r--r--include/smarty/libs/plugins/modifiercompiler.escape.php75
1 files changed, 38 insertions, 37 deletions
diff --git a/include/smarty/libs/plugins/modifiercompiler.escape.php b/include/smarty/libs/plugins/modifiercompiler.escape.php
index d38d12975..0b29220ef 100644
--- a/include/smarty/libs/plugins/modifiercompiler.escape.php
+++ b/include/smarty/libs/plugins/modifiercompiler.escape.php
@@ -2,25 +2,27 @@
/**
* Smarty plugin
*
- * @package Smarty
+ * @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* @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
- *
* Type: modifier<br>
* Name: escape<br>
* 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
+ *
* @param array $params parameters
+ * @param $compiler
+ *
* @return string with compiled code
*/
function smarty_modifiercompiler_escape($params, $compiler)
@@ -29,7 +31,7 @@ function smarty_modifiercompiler_escape($params, $compiler)
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);
@@ -43,13 +45,13 @@ function smarty_modifiercompiler_escape($params, $compiler)
case 'html':
if ($_double_encode) {
return 'htmlspecialchars('
- . $params[0] .', ENT_QUOTES, '
- . var_export($char_set, true) . ', '
- . var_export($double_encode, true) . ')';
- } else if ($double_encode) {
+ . $params[0] . ', ENT_QUOTES, '
+ . var_export($char_set, true) . ', '
+ . var_export($double_encode, true) . ')';
+ } elseif ($double_encode) {
return 'htmlspecialchars('
- . $params[0] .', ENT_QUOTES, '
- . var_export($char_set, true) . ')';
+ . $params[0] . ', ENT_QUOTES, '
+ . var_export($char_set, true) . ')';
} else {
// fall back to modifier.escape.php
}
@@ -59,18 +61,18 @@ function smarty_modifiercompiler_escape($params, $compiler)
if ($_double_encode) {
// php >=5.2.3 - go native
return 'mb_convert_encoding(htmlspecialchars('
- . $params[0] .', ENT_QUOTES, '
- . var_export($char_set, true) . ', '
- . var_export($double_encode, true)
- . '), "HTML-ENTITIES", '
- . var_export($char_set, true) . ')';
- } else if ($double_encode) {
+ . $params[0] . ', ENT_QUOTES, '
+ . var_export($char_set, true) . ', '
+ . var_export($double_encode, true)
+ . '), "HTML-ENTITIES", '
+ . var_export($char_set, true) . ')';
+ } elseif ($double_encode) {
// php <5.2.3 - only handle double encoding
return 'mb_convert_encoding(htmlspecialchars('
- . $params[0] .', ENT_QUOTES, '
- . var_export($char_set, true)
- . '), "HTML-ENTITIES", '
- . var_export($char_set, true) . ')';
+ . $params[0] . ', ENT_QUOTES, '
+ . var_export($char_set, true)
+ . '), "HTML-ENTITIES", '
+ . var_export($char_set, true) . ')';
} else {
// fall back to modifier.escape.php
}
@@ -80,14 +82,14 @@ function smarty_modifiercompiler_escape($params, $compiler)
if ($_double_encode) {
// php >=5.2.3 - go native
return 'htmlentities('
- . $params[0] .', ENT_QUOTES, '
- . var_export($char_set, true) . ', '
- . var_export($double_encode, true) . ')';
- } else if ($double_encode) {
+ . $params[0] . ', ENT_QUOTES, '
+ . var_export($char_set, true) . ', '
+ . var_export($double_encode, true) . ')';
+ } elseif ($double_encode) {
// php <5.2.3 - only handle double encoding
return 'htmlentities('
- . $params[0] .', ENT_QUOTES, '
- . var_export($char_set, true) . ')';
+ . $params[0] . ', ENT_QUOTES, '
+ . var_export($char_set, true) . ')';
} else {
// fall back to modifier.escape.php
}
@@ -105,21 +107,20 @@ function smarty_modifiercompiler_escape($params, $compiler)
case 'javascript':
// escape quotes and backslashes, newlines, etc.
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->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']['function'] = 'smarty_modifier_escape';
+ if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
+ $compiler->parent_compiler->template->compiled->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
+ $compiler->parent_compiler->template->compiled->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape';
} else {
- $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->parent_compiler->template->compiled->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
+ $compiler->parent_compiler->template->compiled->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape';
}
- return 'smarty_modifier_escape(' . join( ', ', $params ) . ')';
-}
-?> \ No newline at end of file
+ return 'smarty_modifier_escape(' . join(', ', $params) . ')';
+}