| 1 | <?php | 
| 2 |  | 
| 3 | /* | 
| 4 | * Smarty plugin | 
| 5 | * ------------------------------------------------------------ | 
| 6 | * Type:     modifier | 
| 7 | * Name:     escape | 
| 8 | * Purpose:  Escape the string according to escapement type | 
| 9 | * ------------------------------------------------------------ | 
| 10 | */ | 
| 11 | function smarty_modifier_escape($string, $esc_type = 'html') | 
| 12 | { | 
| 13 | switch ($esc_type) { | 
| 14 | case 'html': | 
| 15 | return htmlspecialchars($string, ENT_QUOTES); | 
| 16 |  | 
| 17 | case 'htmlall': | 
| 18 | return htmlentities($string, ENT_QUOTES); | 
| 19 |  | 
| 20 | case 'url': | 
| 21 | return urlencode($string); | 
| 22 |  | 
| 23 | case 'quotes': | 
| 24 | // escape unescaped single quotes | 
| 25 | return preg_replace("%(?<!\\\\)'%", "\\'", $string); | 
| 26 |  | 
| 27 | case 'hex': | 
| 28 | // escape every character into hex | 
| 29 | for ($x=0; $x < strlen($string); $x++) { | 
| 30 | $return .= '%' . bin2hex($string[$x]); | 
| 31 | } | 
| 32 | return $return; | 
| 33 |  | 
| 34 | case 'hexentity': | 
| 35 | for ($x=0; $x < strlen($string); $x++) { | 
| 36 | $return .= '&#x' . bin2hex($string[$x]) . ';'; | 
| 37 | } | 
| 38 | return $return; | 
| 39 |  | 
| 40 | default: | 
| 41 | return $string; | 
| 42 | } | 
| 43 | } | 
| 44 |  | 
| 45 | /* vim: set expandtab: */ | 
| 46 |  | 
| 47 | ?> |