| version 1.28, 2004/12/27 21:17:22 |
version 1.29, 2004/12/31 16:03:27 |
|
|
| * @access public |
* @access public |
| */ |
*/ |
| |
|
| /* $Platon: phpPlatonLib/Platon/Platon.php,v 1.27 2004/12/13 10:23:54 nepto Exp $ */ |
/* $Platon: phpPlatonLib/Platon/Platon.php,v 1.28 2004/12/27 21:17:22 nepto Exp $ */ |
| |
|
| class Platon |
class Platon |
| { |
{ |
|
|
| * Escapes e-mail address. |
* Escapes e-mail address. |
| * |
* |
| * @param string $email e-mail address |
* @param string $email e-mail address |
| * @param string $mode url - does URL escaping |
* @param string $mode plain - no escaping |
| |
* url - does URL escaping |
| * html - does HTML escaping |
* html - does HTML escaping |
| * url_and_html - does URL & HTML escaping |
* url_and_html - does URL & HTML escaping |
| * mailto - prepends "mailto:" and escapes |
* mailto - prepends "mailto:" and escapes |
| * hypertext_link - creates hypertext link |
* hypertext_link - creates hypertext link |
| |
* javascript - using JS for escaping |
| |
* (JS method was inpired by Wouter Brok -- http://www.stack.nl/~wjmb) |
| * @param string $attr when creating hypertext link, additional |
* @param string $attr when creating hypertext link, additional |
| * attributes may be added |
* attributes may be added |
| * @return string escaped e-mail added |
* @return string escaped e-mail added |
|
|
| { |
{ |
| $ret = ''; |
$ret = ''; |
| switch ($mode) { |
switch ($mode) { |
| |
case 'plain': |
| |
$ret = $email; |
| |
break; |
| case 'url_and_html': |
case 'url_and_html': |
| case 'url_html': |
case 'url_html': |
| case 'url': |
case 'url': |
|
|
| $ret = 'mailto:';// mailto: |
$ret = 'mailto:';// mailto: |
| $ret .= Platon::escape_email($email, 'url_and_html'); |
$ret .= Platon::escape_email($email, 'url_and_html'); |
| break; |
break; |
| |
case 'js': |
| |
case 'javascript': |
| |
$no_js_dot_subst = '<!-- jane@example.org -->·<!-- alice@example.com -->'; |
| |
$no_js_at_subst = '<!-- peter@example.com -->@<!-- andrew@example.org -->'; |
| |
$no_js_email = Platon::escape_email($email, 'html'); |
| |
$no_js_email = str_replace('.', $no_js_dot_subst, $no_js_email); |
| |
$no_js_email = str_replace('@', $no_js_at_subst, $no_js_email); |
| |
$js_email = str_replace('@', '(', str_replace('.', ')', $email)); |
| |
$js_email = htmlspecialchars($js_email); |
| |
$ret .= '<script language="JavaScript"><!--'."\n"; |
| |
$ret .= ' var e = String("'.$js_email.'").replace(/\(/g,"@").replace(/\)/g,"."); '."\n"; |
| |
$ret .= ' document.write(\'<a href="mailto:\'+e+\'">\'+e+\'</a>\');'."\n"; |
| |
$ret .= '// --></script>'."\n"; |
| |
$ret .= '<noscript>'.$no_js_email.'</noscript>'; |
| |
break; |
| default: |
default: |
| case 'hypertext_link': |
case 'hypertext_link': |
| is_array($attr) && $attr = join(' ', $attr); |
is_array($attr) && $attr = join(' ', $attr); |