00001 <?php 00022 function smarty_modifier_escape($string, $esc_type = 'html', $char_set = 'ISO-8859-1') 00023 { 00024 switch ($esc_type) { 00025 case 'html': 00026 return htmlspecialchars($string, ENT_QUOTES, $char_set); 00027 00028 case 'htmlall': 00029 return htmlentities($string, ENT_QUOTES, $char_set); 00030 00031 case 'url': 00032 return rawurlencode($string); 00033 00034 case 'urlpathinfo': 00035 return str_replace('%2F','/',rawurlencode($string)); 00036 00037 case 'quotes': 00038 // escape unescaped single quotes 00039 return preg_replace("%(?<!\\\\)'%", "\\'", $string); 00040 00041 case 'hex': 00042 // escape every character into hex 00043 $return = ''; 00044 for ($x=0; $x < strlen($string); $x++) { 00045 $return .= '%' . bin2hex($string[$x]); 00046 } 00047 return $return; 00048 00049 case 'hexentity': 00050 $return = ''; 00051 for ($x=0; $x < strlen($string); $x++) { 00052 $return .= '&#x' . bin2hex($string[$x]) . ';'; 00053 } 00054 return $return; 00055 00056 case 'decentity': 00057 $return = ''; 00058 for ($x=0; $x < strlen($string); $x++) { 00059 $return .= '&#' . ord($string[$x]) . ';'; 00060 } 00061 return $return; 00062 00063 case 'javascript': 00064 // escape quotes and backslashes, newlines, etc. 00065 return strtr($string, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/')); 00066 00067 case 'mail': 00068 // safe way to display e-mail address on a web page 00069 return str_replace(array('@', '.'),array(' [AT] ', ' [DOT] '), $string); 00070 00071 case 'nonstd': 00072 // escape non-standard chars, such as ms document quotes 00073 $_res = ''; 00074 for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) { 00075 $_ord = ord(substr($string, $_i, 1)); 00076 // non-standard char, escape it 00077 if($_ord >= 126){ 00078 $_res .= '&#' . $_ord . ';'; 00079 } 00080 else { 00081 $_res .= substr($string, $_i, 1); 00082 } 00083 } 00084 return $_res; 00085 00086 default: 00087 return $string; 00088 } 00089 } 00090 00091 /* vim: set expandtab: */ 00092 00093 ?>
| Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|
