1. registerFunction( 'onPrepareContent', 'botGeshi' ); 18. 19. /** 20. * Code Highlighting Mambot 21. * 22. * Replaces
...
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 = "#(.*?)#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( "|\
|", "#<#", "#>#", "|'|", '#"#', '# #' ); 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. ?>