[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  /**
   3  * @version $Id: moscode.php 2413 2006-02-16 17:23: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', 'botMosCode' );
  18  
  19  /**
  20  * Code Highlighting Mambot
  21  *
  22  * <b>Usage:</b>
  23  * <code>{moscode}...some code...{/moscode}</code>
  24  */
  25  function botMosCode( $published, &$row, &$params, $page=0 ) {
  26      // simple performance check to determine whether bot should process further
  27      if ( strpos( $row->text, 'moscode' ) === false ) {
  28          return true;
  29      }
  30      
  31      // define the regular expression for the bot
  32      $regex = "#{moscode}(.*?){/moscode}#s";
  33  
  34      // check whether mambot has been unpublished
  35      if ( !$published ) {
  36          $row->text = preg_replace( $regex, '', $row->text );
  37          return true;
  38      }
  39      
  40      // perform the replacement
  41      $row->text = preg_replace_callback( $regex, 'botMosCode_replacer', $row->text );
  42  
  43      return true;
  44  }
  45  /**
  46  * Replaces the matched tags an image
  47  * @param array An array of matches (see preg_match_all)
  48  * @return string
  49  */
  50  function botMosCode_replacer( &$matches ) {
  51      $html_entities_match = array("#<#", "#>#");
  52      $html_entities_replace = array("&lt;", "&gt;");
  53  
  54      $text = $matches[1];
  55  
  56      $text = preg_replace($html_entities_match, $html_entities_replace, $text );
  57  
  58      // Replace 2 spaces with "&nbsp; " so non-tabbed code indents without making huge long lines.
  59      $text = str_replace("  ", "&nbsp; ", $text);
  60      // now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
  61      $text = str_replace("  ", " &nbsp;", $text);
  62  
  63      // Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines.
  64      $text = str_replace("\t", "&nbsp; &nbsp;", $text);
  65  
  66      $text = str_replace('&lt;', '<', $text);
  67      $text = str_replace('&gt;', '>', $text);
  68  
  69      $text = highlight_string( $text, 1 );
  70  
  71      $text = str_replace('&amp;nbsp;', '&nbsp;', $text);
  72      $text = str_replace('&lt;br/&gt;', '<br />', $text);
  73      $text = str_replace('<font color="#007700">&lt;</font><font color="#0000BB">br</font><font color="#007700">/&gt;','<br />', $text);
  74      $text = str_replace('&amp;</font><font color="#0000CC">nbsp</font><font color="#006600">;', '&nbsp;', $text);
  75      $text = str_replace('&amp;</font><font color="#0000BB">nbsp</font><font color="#007700">;', '&nbsp;', $text);
  76      $text = str_replace('<font color="#007700">;&lt;</font><font color="#0000BB">br</font><font color="#007700">/&gt;','<br />', $text);
  77  
  78      return $text;
  79  }
  80  ?>


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