3 * Template Lite plugin converted from Smarty
11 * Smarty escape modifier plugin
15 * Purpose: Escape the string according to escapement type
16 * @link http://smarty.php.net/manual/en/language.modifier.escape.php
17 * escape (Smarty online manual)
18 * @author Monte Ohrt <monte at ohrt dot com>
20 * @param html|htmlall|url|quotes|hex|hexentity|javascript
23 function tpl_modifier_escape($string, $esc_type = 'html', $char_set = 'ISO-8859-1', $double_encode = true)
28 if (version_compare(PHP_VERSION
, '5.2.3') === 1)
29 return htmlspecialchars($string, ENT_QUOTES
, $char_set, $double_encode);
31 return htmlspecialchars($string, ENT_QUOTES
, $char_set);
34 if (version_compare(PHP_VERSION
, '5.2.3') === 1)
35 return htmlentities($string, ENT_QUOTES
, $char_set, $double_encode);
37 return htmlentities($string, ENT_QUOTES
, $char_set);
40 return rawurlencode($string);
43 return str_replace('%2F','/',rawurlencode($string));
46 // escape unescaped single quotes
47 return preg_replace("%(?<!\\\\)'%", "\\'", $string);
50 // escape every character into hex
52 for ($x=0; $x < strlen($string); $x++
) {
53 $return .= '%' . bin2hex($string[$x]);
59 for ($x=0; $x < strlen($string); $x++
) {
60 $return .= '&#x' . bin2hex($string[$x]) . ';';
66 for ($x=0; $x < strlen($string); $x++
) {
67 $return .= '&#' . ord($string[$x]) . ';';
72 // escape quotes and backslashes, newlines, etc.
73 return strtr($string, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/'));
76 // safe way to display e-mail address on a web page
77 return str_replace(array('@', '.'),array(' [AT] ', ' [DOT] '), $string);
80 // escape non-standard chars, such as ms document quotes
82 for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++
)
84 $_ord = ord(substr($string, $_i, 1));
85 // non-standard char, escape it
88 $_res .= '&#' . $_ord . ';';
92 $_res .= substr($string, $_i, 1);