JHtmlEmail/cloak
From Joomla! Documentation
< API16:JHtmlEmail
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Simple Javascript email Cloaker
<! removed transcluded page call, red link never existed >
Syntax[edit]
static cloak($mail, $mailto=1, $text='', $email=1)
Parameter Name | Default Value | Description |
---|---|---|
$mailto | 1 | |
$text | ||
1 |
Defined in[edit]
libraries/joomla/html/html/email.php
Importing[edit]
jimport( 'joomla.html.html.email' );
Source Body[edit]
public static function cloak($mail, $mailto=1, $text='', $email=1)
{
// convert text
$mail = JHtmlEmail::_convertEncoding($mail);
// split email by @ symbol
$mail = explode('@', $mail);
$mail_parts = explode('.', $mail[1]);
// random number
$rand = rand(1, 100000);
$replacement = "\n <script language='JavaScript' type='text/javascript'>";
$replacement .= "\n <!--";
$replacement .= "\n var prefix = 'ma' + 'il' + 'to';";
$replacement .= "\n var path = 'hr' + 'ef' + '=';";
$replacement .= "\n var addy". $rand ." = '". @$mail[0] ."' + '@';";
$replacement .= "\n addy". $rand ." = addy". $rand ." + '". implode("' + '.' + '", $mail_parts) ."';";
if ($mailto) {
// special handling when mail text is different from mail addy
if ($text) {
if ($email) {
// convert text
$text = JHtmlEmail::_convertEncoding($text);
// split email by @ symbol
$text = explode('@', $text);
$text_parts = explode('.', $text[1]);
$replacement .= "\n var addy_text". $rand ." = '". @$text[0] ."' + '@' + '". implode("' + '.' + '", @$text_parts) ."';";
} else {
$replacement .= "\n var addy_text". $rand ." = '". $text ."';";
}
$replacement .= "\n document.write('<a ' + path + '\'' + prefix + ':' + addy". $rand ." + '\'>');";
$replacement .= "\n document.write(addy_text". $rand .");";
$replacement .= "\n document.write('<\/a>');";
} else {
$replacement .= "\n document.write('<a ' + path + '\'' + prefix + ':' + addy". $rand ." + '\'>');";
$replacement .= "\n document.write(addy". $rand .");";
$replacement .= "\n document.write('<\/a>');";
}
} else {
$replacement .= "\n document.write(addy". $rand .");";
}
$replacement .= "\n //-->";
$replacement .= '\n </script>';
// XHTML compliance `No Javascript` text handling
$replacement .= "<script language='JavaScript' type='text/javascript'>";
$replacement .= "\n <!--";
$replacement .= "\n document.write('<span style=\'display: none;\'>');";
$replacement .= "\n //-->";
$replacement .= "\n </script>";
$replacement .= JText::_('CLOAKING');
$replacement .= "\n <script language='JavaScript' type='text/javascript'>";
$replacement .= "\n <!--";
$replacement .= "\n document.write('</');";
$replacement .= "\n document.write('span>');";
$replacement .= "\n //-->";
$replacement .= "\n </script>";
return $replacement;
}
<! removed transcluded page call, red link never existed >
Examples[edit]
Code Examples[edit]