Non so se conoscete JosObfuscator. Secondo me è l'unica vera difesa contro gli spambot che recuperano indirizzi e-mail dalle pagine web. Costruito come mambot per la versione 1.0, ho tentato la conversione per la versione 1.5
Devo dire che per le mie esigenze (visto che non ho alcuna intenzione di disabilitarlo) funziona a meraviglia, ma avrei avuto il piacere di condividerlo, visto che non è ancora stato convertito dall'autore (nè pare ne abbia intenzione). Il punto è che se si disabilita, i segnaposto {joso}{/joso}
diventano visibili.
Questo il codice originale:
<?php
// no direct access
//Copyright http://www.josxp.com
//ChangeLoge Winword Bug Fix
defined( '_VALID_MOS' ) or die( 'Restricted access' );
$_MAMBOTS->registerFunction( 'onPrepareContent', 'botJosObfuscator' );
function botJosObfuscator( $published, &$row, &$params, $page=0 ) {
$regex = '%\{joso\}(.*?)\{/joso\}%si';
* if ($published==0) {
* $row->text = preg_replace( $regex, "", $row->text );
* return true;
* }
$josStyle = "<style media=\"screen\">\n";
$josStyle .= "span.joshide { display:none; }\n";
$josStyle .= "</style>";
$row->text = $josStyle . preg_replace_callback( $regex, 'JosObfuscator_Replacer', $row->text );
}
function JosObfuscator_Replacer( $matches ) {
$regex = '/\>(.*?)\</si';
return '<span class="joshide">[JosObfuscator] </span>' . str_replace('<jos>', '', preg_replace_callback( $regex, 'JosObfuscator_Replacer_TAG', '<jos>' . $matches[1] . '<jos>')) ;
}
function JosObfuscator_Replacer_TAG( $matches ) {
$regex = '/\;(.*?)\&/si';
$raw = preg_replace_callback( $regex, 'JosObfuscator_Replacer_AMP', ';' . $matches[1] . '&');
$raw = substr($raw, 1, strlen($raw)-2);
$txt = '>' . $raw . '<';
return $txt;
}
function JosObfuscator_Replacer_AMP( $matches ) {
return ';' . JosObfuscator_Hash($matches[1]) . '&';
}
function JosObfuscator_Hash($word) {
$rtnVal = '';
for ($i=0; $i < strlen($word); $i++) {
$rtnVal .= JosRandChars() . $word{$i};
}
return $rtnVal;
}
function JosRandChars() {
$rndNumber = rand(1, 5);
$rtnVal = '';
for ($i=1; $i<= $rndNumber; $i++) {
$rtnVal .= JosRandChar();
}
return '<span class="joshide">' . $rtnVal . '</span>';
}
function JosRandChar() {
$rnd = 38;
while ( ($rnd == 38) || ($rnd == 39) || ($rnd == 60) || ($rnd == 32) || ($rnd == 92) ) {
$rnd = rand(35, 126);
}
return chr($rnd);
}
?>
Questo il codice come da me modificato:
<?php
// no direct access
//Copyright http://www.josxp.com
//ChangeLoge Winword Bug Fix
defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );
$mainframe->registerEvent( 'onPrepareContent', 'botJosObfuscator' );
function botJosObfuscator( &$row, &$params, $page=0 ) {
//Access the database
$db =& JFactory::getDBO();
//Check whether the bot should process or not
if ( JString::strpos( $row->text, 'joso' ) === false ) {
return true;
}
//Get plugin info
$plugin =& JPluginHelper::getPlugin( 'content', 'josobfuscator' );
//Search for this tag in the content
$regex = '%\{joso\}(.*?)\{/joso\}%is';
//Access the parameters
$pluginParams = new JParameter( $plugin->params );
//Check whether plugin has been unpublished
* if ( !$pluginParams->get( 'enabled', 1 ) ) {
* $row->text = preg_replace( $regex, "", $row->text );
* return true;
* }
$josStyle = "<style media=\"screen\">\n";
$josStyle .= "span.joshide { display:none; }\n";
$josStyle .= "</style>";
$row->text = $josStyle . preg_replace_callback( $regex, 'JosObfuscator_Replacer', $row->text );
}
function JosObfuscator_Replacer( $matches ) {
$regex = '/\>(.*?)\</si';
return '<span class="joshide">[JosObfuscator] </span>' . str_replace('<jos>', '', preg_replace_callback( $regex, 'JosObfuscator_Replacer_TAG', '<jos>' . $matches[1] . '<jos>')) ;
}
function JosObfuscator_Replacer_TAG( $matches ) {
$regex = '/\;(.*?)\&/is';
$raw = preg_replace_callback( $regex, 'JosObfuscator_Replacer_AMP', ';' . $matches[1] . '&');
$raw = substr($raw, 1, strlen($raw)-2);
$txt = '>' . $raw . '<';
return $txt;
}
function JosObfuscator_Replacer_AMP( $matches ) {
return ';' . JosObfuscator_Hash($matches[1]) . '&';
}
function JosObfuscator_Hash($word) {
$rtnVal = '';
for ($i=0; $i < strlen($word); $i++) {
$rtnVal .= JosRandChars() . $word{$i};
}
return $rtnVal;
}
function JosRandChars() {
$rndNumber = rand(1, 5);
$rtnVal = '';
for ($i=1; $i<= $rndNumber; $i++) {
$rtnVal .= JosRandChar();
}
return '<span class="joshide">' . $rtnVal . '</span>';
}
function JosRandChar() {
$rnd = 38;
while ( ($rnd == 38) || ($rnd == 39) || ($rnd == 60) || ($rnd == 32) || ($rnd == 92) ) {
$rnd = rand(35, 126);
}
return chr($rnd);
}
?>
ovviamente ho modificato l'xml.
Il plugin assume il nome 'josobfuscator'
Qualcuno può dirmi dove ho commesso l'errore? Con '*' ho segnato la parte della funzione che dovrebbe "stripare" i segnaposto nel caso di disabilitazione del plugin.