| version 1.27, 2004/12/13 10:23:54 |
version 1.28, 2004/12/27 21:17:22 |
|
|
| * @access public |
* @access public |
| */ |
*/ |
| |
|
| /* $Platon: phpPlatonLib/Platon/Platon.php,v 1.26 2004/12/12 21:50:18 nepto Exp $ */ |
/* $Platon: phpPlatonLib/Platon/Platon.php,v 1.27 2004/12/13 10:23:54 nepto Exp $ */ |
| |
|
| class Platon |
class Platon |
| { |
{ |
|
|
| * @param string $email e-mail address |
* @param string $email e-mail address |
| * @param string $mode url - does URL escaping |
* @param string $mode url - does URL escaping |
| * html - does HTML escaping |
* html - does HTML escaping |
| |
* url_and_html - does URL & HTML escaping |
| |
* mailto - prepends "mailto:" and escapes |
| * hypertext_link - creates hypertext link |
* hypertext_link - creates hypertext link |
| * @param string $attr when creating hypertext link, additional |
* @param string $attr when creating hypertext link, additional |
| * attributes may be added |
* attributes may be added |
|
|
| */ |
*/ |
| function escape_email($email, $mode = 'hypertext_link', $attr = '')/* {{{ */ |
function escape_email($email, $mode = 'hypertext_link', $attr = '')/* {{{ */ |
| { |
{ |
| /* Code borrowed from Smarty template engine; |
|
| Smarty-2.1.0/plugins/modifier.escape.php file */ |
|
| |
|
| $ret = ''; |
$ret = ''; |
| switch ($mode) { |
switch ($mode) { |
| |
case 'url_and_html': |
| |
case 'url_html': |
| case 'url': |
case 'url': |
| // escape every character into hex |
// escape every character into hex |
| for ($x = 0; $x < strlen($email); $x++) { |
for ($x = 0; $x < strlen($email); $x++) { |
| $ret .= '%' . bin2hex($email[$x]); |
$ret .= '%' . bin2hex($email[$x]); |
| } |
} |
| break; |
if ($mode == 'url') { |
| |
break; |
| |
} |
| |
$email = $ret; |
| |
$ret = ''; |
| |
// ... and continue with HTML escaping |
| case 'html': |
case 'html': |
| for ($x = 0; $x < strlen($email); $x++) { |
for ($x = 0; $x < strlen($email); $x++) { |
| $ret .= (ord($email[$x]) > 127 |
$ret .= (ord($email[$x]) > 127 |
| ? $email[$x] : '&#x'.bin2hex($email[$x]).';'); |
? $email[$x] : '&#x'.bin2hex($email[$x]).';'); |
| } |
} |
| break; |
break; |
| |
case 'mailto': |
| |
$ret = 'mailto:';// mailto: |
| |
$ret .= Platon::escape_email($email, 'url_and_html'); |
| |
break; |
| default: |
default: |
| case 'hypertext_link': |
case 'hypertext_link': |
| is_array($attr) && $attr = join(' ', $attr); |
is_array($attr) && $attr = join(' ', $attr); |
| $attr != '' && $attr .= ' '; |
$attr != '' && $attr .= ' '; |
| $ret = '<a '.$attr.'href="mailto:' |
$ret = sprintf('<a %shref="%s">%s</a>', $attr, |
| . Platon::escape_email($email, 'url') . '">' |
Platon::escape_email($email, 'mailto'), |
| . Platon::escape_email($email, 'html') . '</a>'; |
Platon::escape_email($email, 'html')); |
| break; |
break; |
| } |
} |
| return $ret; |
return $ret; |