registerEvent('onPrepareContent', 'plgContentEmailCloak');
/**
* Plugin that cloaks all emails in content from spambots via Javascript.
*
* @param object|string An object with a "text" property or the string to be
* cloaked.
* @param array Additional parameters. See {@see plgEmailCloak()}.
* @param int Optional page number. Unused. Defaults to zero.
* @return boolean True on success.
*/
function plgContentEmailCloak(&$row, &$params, $page=0)
{
if (is_object($row)) {
return plgEmailCloak($row->text, $params);
}
return plgEmailCloak($row, $params);
}
/**
* Genarate a search pattern based on link and text.
*
* @param string The target of an e-mail link.
* @param string The text enclosed by the link.
* @return string A regular expression that matches a link containing the
* parameters.
*/
function plgContentEmailCloak_searchPattern ($link, $text) {
// anyText
$pattern = '~(?:' . $text . '~i';
return $pattern;
}
/**
* Cloak all emails in text from spambots via Javascript.
*
* @param string The string to be cloaked.
* @param array Additional parameters. Parameter "mode" (integer, default 1)
* replaces addresses with "mailto:" links if nonzero.
* @return boolean True on success.
*/
function plgEmailCloak(&$text, &$params)
{
/*
* Check for presence of {emailcloak=off} which is explicits disables this
* bot for the item.
*/
if (JString::strpos($text, '{emailcloak=off}') !== false) {
$text = JString::str_ireplace('{emailcloak=off}', '', $text);
return true;
}
// Simple performance check to determine whether bot should process further.
if (JString::strpos($text, '@') === false) {
return true;
}
$plugin = & JPluginHelper::getPlugin('content', 'emailcloak');
// Load plugin params info
$pluginParams = new JParameter($plugin->params);
$mode = $pluginParams->def('mode', 1);
// split the string into parts to exclude strcipt tags from being handled
$text = explode( '', $str );
foreach ( $str_split as $j => $str_split_part ) {
if ( ( $j % 2 ) == 1 ) {
plgEmailCloakString( $str_split[$i], $mode );
}
}
$text[$i] = implode( '', $str_split );
}
}
$text = implode( '