[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/plugins/content/ -> geshi.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: geshi.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla
   5  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   6  * @license        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( '_JEXEC' ) or die( 'Restricted access' );
  16  
  17  $mainframe->registerEvent( 'onPrepareContent', 'plgContentGeshi' );
  18  
  19  /**
  20  * Code Highlighting Plugin
  21  *
  22  * Replaces <pre>...</pre> tags with highlighted text
  23  */
  24  function plgContentGeshi( &$row, &$params, $page=0 )
  25  {
  26      // simple performance check to determine whether bot should process further
  27      if ( JString::strpos( $row->text, 'pre>' ) === false ) {
  28          return true;
  29      }
  30  
  31      // Get Plugin info
  32       $plugin =& JPluginHelper::getPlugin('content', 'geshi');
  33  
  34      // define the regular expression for the bot
  35      $regex = "#<pre xml:\s*(.*?)>(.*?)</pre>#s";
  36  
  37      $GLOBALS['_MAMBOT_GESHI_PARAMS'] =& $params;
  38  
  39      // perform the replacement
  40      $row->text = preg_replace_callback( $regex, 'plgContentGeshi_replacer', $row->text );
  41  
  42      return true;
  43  }
  44  /**
  45  * Replaces the matched tags an image
  46  * @param array An array of matches (see preg_match_all)
  47  * @return string
  48  */
  49  function plgContentGeshi_replacer( &$matches )
  50  {
  51      $params =& $GLOBALS['_MAMBOT_GESHI_PARAMS'];
  52  
  53      jimport('geshi.geshi');
  54      jimport('domit.xml_saxy_shared');
  55  
  56      $args = SAXY_Parser_Base::parseAttributes( $matches[1] );
  57      $text = $matches[2];
  58  
  59      $lang    = JArrayHelper::getValue( $args, 'lang', 'php' );
  60      $lines    = JArrayHelper::getValue( $args, 'lines', 'false' );
  61  
  62  
  63      $html_entities_match = array( "|\<br \/\>|", "#<#", "#>#", "|&#39;|", '#&quot;#', '#&nbsp;#' );
  64      $html_entities_replace = array( "\n", '&lt;', '&gt;', "'", '"', ' ' );
  65  
  66      $text = preg_replace( $html_entities_match, $html_entities_replace, $text );
  67  
  68      $text = str_replace('&lt;', '<', $text);
  69      $text = str_replace('&gt;', '>', $text);
  70  
  71  /*
  72      // Replace 2 spaces with "&nbsp; " so non-tabbed code indents without making huge long lines.
  73      $text = str_replace("  ", "&nbsp; ", $text);
  74      // now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
  75      $text = str_replace("  ", " &nbsp;", $text);
  76  */
  77      // Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines.
  78      //$text = str_replace("\t", "&nbsp; &nbsp;", $text);
  79      $text = str_replace( "\t", '  ', $text );
  80  
  81      $geshi = new GeSHi( $text, $lang );
  82      if ($lines == 'true') {
  83          $geshi->enable_line_numbers( GESHI_NORMAL_LINE_NUMBERS );
  84      }
  85      $text = $geshi->parse_code();
  86  
  87      return $text;
  88  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1