[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: geshi.php 2972 2006-03-30 08:01: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', 'botGeshi' ); 18 19 /** 20 * Code Highlighting Mambot 21 * 22 * Replaces <pre>...</pre> tags with highlighted text 23 */ 24 function botGeshi( $published, &$row, &$params, $page=0 ) { 25 require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/domit/xml_saxy_shared.php' ); 26 27 // simple performance check to determine whether bot should process further 28 if ( strpos( $row->text, 'pre>' ) === false ) { 29 return true; 30 } 31 32 // define the regular expression for the bot 33 $regex = "#<pre\s*(.*?)>(.*?)</pre>#s"; 34 35 // check whether mambot has been unpublished 36 if ( !$published ) { 37 return true; 38 } 39 40 $GLOBALS['_MAMBOT_GESHI_PARAMS'] =& $params; 41 42 // perform the replacement 43 $row->text = preg_replace_callback( $regex, 'botGeshi_replacer', $row->text ); 44 45 return true; 46 } 47 /** 48 * Replaces the matched tags an image 49 * @param array An array of matches (see preg_match_all) 50 * @return string 51 */ 52 function botGeshi_replacer( &$matches ) { 53 $params =& $GLOBALS['_MAMBOT_GESHI_PARAMS']; 54 include_once( dirname( __FILE__ ) . '/geshi/geshi.php' ); 55 56 $args = SAXY_Parser_Base::parseAttributes( $matches[1] ); 57 $text = $matches[2]; 58 59 $lang = mosGetParam( $args, 'lang', 'php' ); 60 $lines = mosGetParam( $args, 'lines', 'false' ); 61 62 63 $html_entities_match = array( "|\<br \/\>|", "#<#", "#>#", "|'|", '#"#', '# #' ); 64 $html_entities_replace = array( "\n", '<', '>', "'", '"', ' ' ); 65 66 $text = preg_replace( $html_entities_match, $html_entities_replace, $text ); 67 68 $text = str_replace('<', '<', $text); 69 $text = str_replace('>', '>', $text); 70 71 // Replace tabs with " " so tabbed code indents sorta right without making huge long lines. 72 //$text = str_replace("\t", " ", $text); 73 $text = str_replace( "\t", ' ', $text ); 74 75 $geshi = new GeSHi( $text, $lang, dirname( __FILE__ ) . '/geshi/geshi' ); 76 if ($lines == 'true') { 77 $geshi->enable_line_numbers( GESHI_NORMAL_LINE_NUMBERS ); 78 } 79 $text = $geshi->parse_code(); 80 81 return $text; 82 } 83 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |