CoreFiles by mySites.guru
emailcloak.php127 lines, 4,967 bytes, from Joomla_1.5.1-Stable-Full_Package.zip
Raw History Compare with 1.5.0
md5
80f50f26b937472c84db2188c6bc0422
sha1
70df89984a127f53eb6f270ba508c34f8682fa12
sha256
84562215fb9781f869f1b176b00a000964176a312e90c4020d73c7ce8be7f280
<?php
/**
* @version		$Id: emailcloak.php 9764 2007-12-30 07:48:11Z ircmaxell $
* @package		Joomla
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

$mainframe->registerEvent( 'onPrepareContent', 'plgContentEmailCloak' );

/**
* Plugin that Cloaks all emails in content from spambots via javascript
*/
function plgContentEmailCloak( &$row, &$params, $page=0 )
{
	// simple performance check to determine whether bot should process further
	if ( JString::strpos( $row->text, '@' ) === false ) {
		return true;
	}

 	$plugin =& JPluginHelper::getPlugin('content', 'emailcloak');

	// check for presence of {emailcloak=off} which is explicits disables this bot for the item
	if ( !JString::strpos( $row->text, '{emailcloak=off}' ) === false ) {
		$row->text = JString::str_ireplace( '{emailcloak=off}', '', $row->text );
		return true;
	}

	// load plugin params info
 	$pluginParams 	= new JParameter( $plugin->params );
 	$mode			= $pluginParams->def( 'mode', 1 );

	// [email protected]
	$search_email		= "([[:alnum:]_\.\-]+)(\@[[:alnum:]\.\-]+\.+)([[:alnum:]\.\-]+)";
	// [email protected]?subject=anyText
	$search_email_msg	= "([[:alnum:]_\.\-]+)(\@[[:alnum:]\.\-]+\.+)([[:alnum:]\.\-]+)([[:alnum:][:space:][:punct:]][^\"<>]+)";
	// anyText
	$search_text 		= "([[:alnum:][:space:][:punct:]][^<>]+)";

	// search for derivativs of link code <a href="mailto:[email protected]">[email protected]</a>
	$pattern = plgContentEmailCloak_searchPattern( $search_email, $search_email );
	while( eregi( $pattern, $row->text, $regs ) ) {
		$mail 		= $regs[2] . $regs[3] . $regs[4];
		$mail_text 	= $regs[5] . $regs[6] . $regs[7];

		// check to see if mail text is different from mail addy
		if ( $mail_text ) {
			$replacement = JHTML::_('email.cloak', $mail, $mode, $mail_text );
		} else {
			$replacement = JHTML::_('email.cloak', $mail, $mode );
		}

		// replace the found address with the js cloacked email
		$row->text 	= str_replace( $regs[0], $replacement, $row->text );
	}

	// search for derivativs of link code <a href="mailto:[email protected]">anytext</a>
	$pattern = plgContentEmailCloak_searchPattern( $search_email, $search_text );
	while( eregi( $pattern, $row->text, $regs ) ) {
		$mail 		= $regs[2] . $regs[3] . $regs[4];
		$mail_text 	= $regs[5];

		$replacement = JHTML::_('email.cloak', $mail, $mode, $mail_text, 0 );

		// replace the found address with the js cloacked email
		$row->text 	= str_replace( $regs[0], $replacement, $row->text );
	}

	// search for derivativs of link code <a href="mailto:[email protected]?subject=Text">[email protected]</a>
	$pattern = plgContentEmailCloak_searchPattern( $search_email_msg, $search_email );
	while( eregi( $pattern, $row->text, $regs ) ) {
		$mail		= $regs[2] . $regs[3] . $regs[4] . $regs[5];
		$mail_text	= $regs[6] . $regs[7]. $regs[8];
		//needed for handling of Body parameter
		$mail 		= str_replace( '&amp;', '&', $mail );

		// check to see if mail text is different from mail addy
		if ( $mail_text ) {
			$replacement = JHTML::_('email.cloak', $mail, $mode, $mail_text );
		} else {
			$replacement = JHTML::_('email.cloak', $mail, $mode );
		}


		// replace the found address with the js cloacked email
		$row->text	 = str_replace( $regs[0], $replacement, $row->text );
	}

	// search for derivativs of link code <a href="mailto:[email protected]?subject=Text">anytext</a>
	$pattern = plgContentEmailCloak_searchPattern( $search_email_msg, $search_text );
	while( eregi( $pattern, $row->text, $regs ) ) {
		$mail		= $regs[2] . $regs[3] . $regs[4] . $regs[5];
		$mail_text	= $regs[6];
		//needed for handling of Body parameter
		$mail 		= str_replace( '&amp;', '&', $mail );

		$replacement = JHTML::_('email.cloak', $mail);

		// replace the found address with the js cloacked email
		$row->text	 = str_replace( $regs[0], $replacement, $row->text );
	}

	// search for plain text [email protected]
	while( eregi( $search_email, $row->text, $regs ) ) {
		$mail = $regs[0];

		$replacement = JHTML::_('email.cloak', $mail, $mode );

		// replace the found address with the js cloacked email
		$row->text = str_replace( $regs[0], $replacement, $row->text );
	}
}

function plgContentEmailCloak_searchPattern ( $link, $text ) {
	// <a href="mailto:anyLink">anyText</a>
	$pattern = "(<a [[:alnum:] _\"\'=\@\.\-]*href=[\"\']mailto:". $link	."[\"\'][[:alnum:] _\"\'=\@\.\-]*)>". $text ."</a>";

	return $pattern;
}

The same content is in 2 releases, Joomla 1.5.0 to 1.5.1. See them all, or every version of this file.