Source for file emailcloak.php
Documentation is available at emailcloak.php
* @subpackage Content.emailcloak
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Email cloack plugin class.
* @subpackage Content.emailcloak
* Plugin that cloaks all emails in content from spambots via Javascript.
* @param string $context The context of the content being passed to the plugin.
* @param mixed &$row An object with a "text" property or the string to be cloaked.
* @param mixed &$params Additional parameters. See {@see PlgContentEmailcloak()}.
* @param integer $page Optional page number. Unused. Defaults to zero.
* @return boolean True on success.
// Don't run this plugin when the content is being indexed
if ($context ==
'com_finder.indexer')
return $this->_cloak($row->text, $params);
return $this->_cloak($row, $params);
* Generate a search pattern based on link and text.
* @param string $link The target of an email link.
* @param string $text The text enclosed by the link.
* @return string A regular expression that matches a link containing the parameters.
$pattern =
'~(?:<a ([\w "\'=\@\.\-:;]*)href\s*=\s*"mailto:'
.
$link .
'"([\w "\'=\@\.\-:;]*))>' .
$text .
'</a>~i';
* Adds an attributes to the js cloaked email.
* @param string $jsEmail Js cloaked email.
* @param string $before Attributes before email.
* @param string $after Attributes after email.
* @return string Js cloaked email with attributes.
$jsEmail =
str_replace("document.write('<a '", "document.write('<a {$before}'", $jsEmail);
$jsEmail =
str_replace("'\'>');", "'\'{$after}>');", $jsEmail);
* Cloak all emails in text from spambots via Javascript.
* @param string &$text The string to be cloaked.
* @param mixed &$params Additional parameters. Parameter "mode" (integer, default 1)
* replaces addresses with "mailto:" links if nonzero.
* @return boolean True on success.
protected function _cloak(&$text, &$params)
* Check for presence of {emailcloak=off} which is explicits disables this
// Simple performance check to determine whether bot should process further.
$mode =
$this->params->def('mode', 1);
$searchEmail =
'([\w\.\-]+\@(?:[a-z0-9\.\-]+\.)+(?:[a-zA-Z0-9\-]{2,10}))';
// any@email.address.com?subject=anyText
$searchEmailLink =
$searchEmail .
'([?&][\x20-\x7f][^"<>]+)';
$searchText =
'([\x20-\x7f][^<>]+)';
$searchImage =
"(<img[^>]+>)";
* Search and fix derivatives of link code <a href="http://mce_host/ourdirectory/email@amail.com"
* >email@email.com</a>. This happens when inserting an email in TinyMCE, cancelling its suggestion to add
$pattern =
$this->_getPattern($searchEmail, $searchEmail);
$pattern =
str_replace('"mailto:', '"http://mce_host([\x20-\x7f][^<>]+/)', $pattern);
while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE))
// Check to see if mail text is different from mail addy
$replacement =
JHtml::_('email.cloak', $mail, $mode, $mailText);
// Ensure that attributes is not stripped out by email cloaking
// Replace the found address with the js cloaked email
* Search and fix derivatives of link code <a href="http://mce_host/ourdirectory/email@amail.com"
* >anytext</a>. This happens when inserting an email in TinyMCE, cancelling its suggestion to add
$pattern =
$this->_getPattern($searchEmail, $searchText);
$pattern =
str_replace('"mailto:', '"http://mce_host([\x20-\x7f][^<>]+/)', $pattern);
while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE))
// Check to see if mail text is different from mail addy
$replacement =
JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
// Ensure that attributes is not stripped out by email cloaking
// Replace the found address with the js cloaked email
* Search for derivatives of link code <a href="mailto:email@amail.com"
$pattern =
$this->_getPattern($searchEmail, $searchEmail);
while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE))
// Check to see if mail text is different from mail addy
$replacement =
JHtml::_('email.cloak', $mail, $mode, $mailText);
// Ensure that attributes is not stripped out by email cloaking
// Replace the found address with the js cloaked email
* Search for derivatives of link code <a href="mailto:email@amail.com">
$pattern =
$this->_getPattern($searchEmail, $searchText);
while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE))
$replacement =
JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
// Ensure that attributes is not stripped out by email cloaking
// Replace the found address with the js cloaked email
* Search for derivatives of link code <a href="mailto:email@amail.com">
$pattern =
$this->_getPattern($searchEmail, $searchImage);
while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE))
$replacement =
JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
// Ensure that attributes is not stripped out by email cloaking
// Replace the found address with the js cloaked email
* Search for derivatives of link code <a href="mailto:email@amail.com?
* subject=Text">email@amail.com</a>
$pattern =
$this->_getPattern($searchEmailLink, $searchEmail);
while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE))
$mail =
$regs[2][0] .
$regs[3][0];
// Needed for handling of Body parameter
// Check to see if mail text is different from mail addy
$replacement =
JHtml::_('email.cloak', $mail, $mode, $mailText);
// Ensure that attributes is not stripped out by email cloaking
// Replace the found address with the js cloaked email
* Search for derivatives of link code <a href="mailto:email@amail.com?
* subject=Text">anytext</a>
$pattern =
$this->_getPattern($searchEmailLink, $searchText);
while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE))
$mail =
$regs[2][0] .
$regs[3][0];
// Needed for handling of Body parameter
$replacement =
JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
// Ensure that attributes is not stripped out by email cloaking
// Replace the found address with the js cloaked email
// Search for plain text email@amail.com
$pattern =
'~' .
$searchEmail .
'([^a-z0-9]|$)~i';
while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE))
$replacement =
JHtml::_('email.cloak', $mail, $mode);
// Replace the found address with the js cloaked email
Documentation generated on Tue, 19 Nov 2013 15:02:28 +0100 by phpDocumentor 1.4.3