[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/mambots/content/ -> mosemailcloak.php (source)

   1  <?php
   2  /**
   3  * @version $Id: mosemailcloak.php 4564 2006-08-18 23:26:32Z stingrey $
   4  * @package Joomla
   5  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
   6  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  */
  13  
  14  // no direct access
  15  defined( '_VALID_MOS' ) or die( 'Restricted access' );
  16  
  17  $_MAMBOTS->registerFunction( 'onPrepareContent', 'botMosEmailCloak' );
  18  
  19  /**
  20  * Mambot that Cloaks all emails in content from spambots via javascript
  21  */
  22  function botMosEmailCloak( $published, &$row, &$params, $page=0 ) {
  23      global $database, $_MAMBOTS;
  24  
  25      // check whether mambot has been unpublished
  26      if ( !$published ) {
  27          return true;
  28      }
  29      
  30      // simple performance check to determine whether bot should process further
  31      if ( strpos( $row->text, '@' ) === false ) {
  32          return true;
  33      }
  34          
  35      // simple check to allow disabling of bot
  36      $regex = '{emailcloak=off}';
  37      if ( strpos( $row->text, $regex ) !== false ) {
  38          $row->text = str_replace( $regex, '', $row->text );
  39          return true;
  40      }
  41      
  42      // check if param query has previously been processed
  43      if ( !isset($_MAMBOTS->_content_mambot_params['mosemailcloak']) ) {
  44          // load mambot params info
  45          $query = "SELECT params"
  46          . "\n FROM #__mambots"
  47          . "\n WHERE element = 'mosemailcloak'"
  48          . "\n AND folder = 'content'"
  49          ;
  50          $database->setQuery( $query );
  51          $database->loadObject($mambot);    
  52              
  53          // save query to class variable
  54          $_MAMBOTS->_content_mambot_params['mosemailcloak'] = $mambot;
  55      }
  56      
  57      // pull query data from class variable
  58      $mambot = $_MAMBOTS->_content_mambot_params['mosemailcloak'];
  59      
  60       $botParams     = new mosParameters( $mambot->params );
  61       $mode        = $botParams->def( 'mode', 1 );
  62  
  63      // any@email.address.com
  64       $search_email        = "([[:alnum:]_\.\-]+)(\@[[:alnum:]\.\-]+\.+)([[:alnum:]\.\-]+)";
  65      // any@email.address.com?subject=anyText
  66      $search_email_msg   = "([[:alnum:]_\.\-]+)(\@[[:alnum:]\.\-]+\.+)([[:alnum:]\.\-]+)([[:alnum:][:space:][:punct:]][^\"<>]+)";
  67      // anyText
  68       $search_text         = "([[:alnum:][:space:][:punct:]][^<>]+)";
  69  
  70      // search for derivativs of link code <a href="mailto:email@amail.com">email@amail.com</a>
  71      $pattern = botMosEmailCloak_searchPattern( $search_email, $search_email );
  72      while( eregi( $pattern, $row->text, $regs ) ) {        
  73          $mail         = $regs[2] . $regs[3] . $regs[4];
  74          $mail_text     = $regs[5] . $regs[6] . $regs[7];
  75  
  76          // check to see if mail text is different from mail addy
  77          if ( $mail_text ) {
  78              $replacement = mosHTML::emailCloaking( $mail, $mode, $mail_text );
  79          } else {
  80              $replacement = mosHTML::emailCloaking( $mail, $mode );
  81          }
  82  
  83          // replace the found address with the js cloacked email
  84          $row->text     = str_replace( $regs[0], $replacement, $row->text );
  85      }
  86  
  87      // search for derivativs of link code <a href="mailto:email@amail.com">anytext</a>
  88      $pattern = botMosEmailCloak_searchPattern( $search_email, $search_text );
  89      while( eregi( $pattern, $row->text, $regs ) ) {        
  90          $mail         = $regs[2] . $regs[3] . $regs[4];
  91          $mail_text     = $regs[5];
  92  
  93          $replacement = mosHTML::emailCloaking( $mail, $mode, $mail_text, 0 );
  94  
  95          // replace the found address with the js cloacked email
  96          $row->text     = str_replace( $regs[0], $replacement, $row->text );
  97      }
  98  
  99      // search for derivativs of link code <a href="mailto:email@amail.com?subject=Text&body=Text">email@amail.com</a>
 100      $pattern = botMosEmailCloak_searchPattern( $search_email_msg, $search_email );
 101      while( eregi( $pattern, $row->text, $regs ) ) {        
 102          $mail        = $regs[2] . $regs[3] . $regs[4] . $regs[5];
 103          $mail_text    = $regs[6] . $regs[7]. $regs[8];
 104          //needed for handling of Body parameter
 105          $mail         = str_replace( '&amp;', '&', $mail );
 106  
 107          // check to see if mail text is different from mail addy
 108          if ( $mail_text ) {
 109              $replacement = mosHTML::emailCloaking( $mail, $mode, $mail_text );
 110          } else {
 111              $replacement = mosHTML::emailCloaking( $mail, $mode );
 112          }
 113  
 114          // replace the found address with the js cloacked email
 115          $row->text     = str_replace( $regs[0], $replacement, $row->text );
 116      }
 117      
 118      // search for derivativs of link code <a href="mailto:email@amail.com?subject=Text&body=Text">anytext</a>
 119      $pattern = botMosEmailCloak_searchPattern( $search_email_msg, $search_text );
 120      while( eregi( $pattern, $row->text, $regs ) ) {        
 121          $mail        = $regs[2] . $regs[3] . $regs[4] . $regs[5];
 122          $mail_text    = $regs[6];
 123          //needed for handling of Body parameter
 124          $mail         = str_replace( '&amp;', '&', $mail );
 125  
 126          $replacement = mosHTML::emailCloaking( $mail, $mode, $mail_text, 0 );
 127  
 128          // replace the found address with the js cloacked email
 129          $row->text     = str_replace( $regs[0], $replacement, $row->text );
 130      }
 131      
 132      // search for plain text email@amail.com
 133      while( eregi( $search_email, $row->text, $regs ) ) {
 134          $mail = $regs[0];
 135  
 136          $replacement = mosHTML::emailCloaking( $mail, $mode );
 137  
 138          // replace the found address with the js cloacked email
 139          $row->text = str_replace( $regs[0], $replacement, $row->text );
 140      }
 141  }
 142  
 143  function botMosEmailCloak_searchPattern ( $link, $text ) {    
 144      // <a href="mailto:anyLink">anyText</a>
 145      $pattern = "(<a [[:alnum:] _\"\'=\@\.\-]*href=[\"\']mailto:". $link    ."[\"\'][[:alnum:] _\"\'=\@\.\-]*)>". $text ."</a>";
 146      
 147      return $pattern;
 148  }
 149  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics