1: <?php
2: 3: 4: 5: 6: 7:
8:
9: 10: 11:
12: require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php');
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: function smarty_modifiercompiler_escape($params, $compiler)
29: {
30: static $_double_encode = null;
31: if ($_double_encode === null) {
32: $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
33: }
34:
35: try {
36: $esc_type = smarty_literal_compiler_param($params, 1, 'html');
37: $char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET);
38: $double_encode = smarty_literal_compiler_param($params, 3, true);
39:
40: if (!$char_set) {
41: $char_set = Smarty::$_CHARSET;
42: }
43:
44: switch ($esc_type) {
45: case 'html':
46: if ($_double_encode) {
47: return 'htmlspecialchars('
48: . $params[0] . ', ENT_QUOTES, '
49: . var_export($char_set, true) . ', '
50: . var_export($double_encode, true) . ')';
51: } elseif ($double_encode) {
52: return 'htmlspecialchars('
53: . $params[0] . ', ENT_QUOTES, '
54: . var_export($char_set, true) . ')';
55: } else {
56:
57: }
58:
59: case 'htmlall':
60: if (Smarty::$_MBSTRING) {
61: if ($_double_encode) {
62:
63: return 'mb_convert_encoding(htmlspecialchars('
64: . $params[0] . ', ENT_QUOTES, '
65: . var_export($char_set, true) . ', '
66: . var_export($double_encode, true)
67: . '), "HTML-ENTITIES", '
68: . var_export($char_set, true) . ')';
69: } elseif ($double_encode) {
70:
71: return 'mb_convert_encoding(htmlspecialchars('
72: . $params[0] . ', ENT_QUOTES, '
73: . var_export($char_set, true)
74: . '), "HTML-ENTITIES", '
75: . var_export($char_set, true) . ')';
76: } else {
77:
78: }
79: }
80:
81:
82: if ($_double_encode) {
83:
84: return 'htmlentities('
85: . $params[0] . ', ENT_QUOTES, '
86: . var_export($char_set, true) . ', '
87: . var_export($double_encode, true) . ')';
88: } elseif ($double_encode) {
89:
90: return 'htmlentities('
91: . $params[0] . ', ENT_QUOTES, '
92: . var_export($char_set, true) . ')';
93: } else {
94:
95: }
96:
97: case 'url':
98: return 'rawurlencode(' . $params[0] . ')';
99:
100: case 'urlpathinfo':
101: return 'str_replace("%2F", "/", rawurlencode(' . $params[0] . '))';
102:
103: case 'quotes':
104:
105: return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[0] . ')';
106:
107: case 'javascript':
108:
109: return 'strtr(' . $params[0] . ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))';
110: }
111: }
112: catch (SmartyException $e) {
113:
114: }
115:
116:
117: if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
118: $compiler->template->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
119: $compiler->template->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape';
120: } else {
121: $compiler->template->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
122: $compiler->template->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape';
123: }
124:
125: return 'smarty_modifier_escape(' . join(', ', $params) . ')';
126: }
127: