Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email cloak resets body content when loaded with AJAX #151

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 46 additions & 60 deletions libraries/joomla/html/html/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,72 +34,58 @@ abstract class JHtmlEmail
*/
public static function cloak($mail, $mailto = 1, $text = '', $email = 1)
{
/**
* Original approach breaks site content when combined with
* AJAX calls, i.e. JomSocial
*
* Current implementation relies on jQuery, please extend for
* other JS libraries
*/
// 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 type='text/javascript'>";
$replacement .= "\n <!--";
$replacement .= "\n var prefix = '&#109;a' + 'i&#108;' + '&#116;o';";
$replacement .= "\n var path = 'hr' + 'ef' + '=';";
$replacement .= "\n var addy" . $rand . " = '" . @$mail[0] . "' + '&#64;';";
$replacement .= "\n addy" . $rand . " = addy" . $rand . " + '" . implode("' + '&#46;' + '", $mail_parts) . "';";

if ($mailto)
{
// Special handling when mail text is different from mail address
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] . "' + '&#64;' + '" . implode("' + '&#46;' + '", @$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 type='text/javascript'>";
$replacement .= "\n <!--";
$replacement .= "\n document.write('<span style=\'display: none;\'>');";
$replacement .= "\n //-->";
$replacement .= "\n </script>";
$replacement .= JText::_('JLIB_HTML_CLOAKING');
$replacement .= "\n <script type='text/javascript'>";
$replacement .= "\n <!--";
$replacement .= "\n document.write('</');";
$replacement .= "\n document.write('span>');";
$replacement .= "\n //-->";
$replacement .= "\n </script>";

$__mail = '__' + rand(1, 100000);


// Convert text
$text = JHtmlEmail::_convertEncoding($text);
// Split email by @ symbol
$text = explode('@', $text);
$text_parts = explode('.', $text[1]);
// Random number
$__text = '__' + rand(1, 100000);

ob_start();
?>
<span id="span<?php echo $__mail ?>"><?php echo JText::_('JLIB_HTML_CLOAKING') ?></span>
<script type="text/javascript">
jQuery(document).load(function($){
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jQuery(document).ready

$('#span<?php echo $__mail ?>').each(function(){
var $this = $(this),
prefix = '&#109;a' + 'i&#108;' + '&#116;o',
<?php echo $__mail ?> = "<?php echo @$mail[0] ?>" + "&#64;",
<?php echo $__text ?> = "<?php echo @$text[0] ?>" + "&#64;";

<?php echo $__mail ?> += "<?php echo implode('" + "&#46;" + "',(array)$mail_parts) ?>";
<?php echo $__text ?> += "<?php echo implode('" + "&#46;" + "',(array)$text_parts) ?>";

<?php if ($mailto) { ?>
$this.html('<a href="mailto:' + <?php echo $__mail ?> + '">' + <?php echo $__mail ?> + '</a>');
<?php if ($email) { ?>
$this.find('a').html(<?php echo $__text ?>);
<?php } ?>
<?php } else { ?>
$this.html(<?php echo $__mail ?>);
<?php } ?>
});
});
</script>
<?php

$replacement = ob_get_clean();
return $replacement;
}

Expand Down