parser = xml_parser_create(); $startfunc = array (&$this, 'start_element'); $endfunc = array (&$this, 'end_element'); $charfunc = array (&$this, 'character_data'); xml_set_element_handler ($this->parser, $startfunc, $endfunc); xml_set_character_data_handler ($this->parser, $charfunc); } function parse ($arguments) { xml_parse($this->parser, $arguments, true); xml_parser_free($parser); return $this->pattrs; } function start_element ($parser, $element_name, $element_attrs) { if ($element_name == 'PRE') $pattrs = $element_attrs; } function end_element ($parser, $element_name) { return; } function character_data ($parser, $data) { return; } } $_MAMBOTS->registerFunction( 'onPrepareContent', 'botGeshi' ); /** * Code Highlighting Mambot * * Replaces
...
tags with highlighted text */ function botGeshi( $published, &$row, &$params, $page=0 ) { // define the regular expression for the bot $regex = "#(.*?)#s"; if (!$published) { $row->text = preg_replace( $regex, '', $row->text ); return; } $GLOBALS['_MAMBOT_GESHI_PARAMS'] =& $params; // perform the replacement $row->text = preg_replace_callback( $regex, 'botGeshi_replacer', $row->text ); return true; } /** * Replaces the matched tags an image * @param array An array of matches (see preg_match_all) * @return string */ function botGeshi_replacer( &$matches ) { $params =& $GLOBALS['_MAMBOT_GESHI_PARAMS']; include_once( dirname( __FILE__ ) . '/geshi/geshi.php' ); $parser =& new geshiXML(); $args = $parser->parse($matches[1]); $text = $matches[2]; $lang = mosGetParam( $args, 'lang', 'php' ); $lines = mosGetParam( $args, 'lines', 'false' ); $html_entities_match = array( "|\
|", "#<#", "#>#", "|'|", '#"#', '# #' ); $html_entities_replace = array( "\n", '<', '>', "'", '"', ' ' ); $text = preg_replace( $html_entities_match, $html_entities_replace, $text ); $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); /* // Replace 2 spaces with "  " so non-tabbed code indents without making huge long lines. $text = str_replace(" ", "  ", $text); // now Replace 2 spaces with "  " to catch odd #s of spaces. $text = str_replace(" ", "  ", $text); */ // Replace tabs with "   " so tabbed code indents sorta right without making huge long lines. //$text = str_replace("\t", "   ", $text); $text = str_replace( "\t", ' ', $text ); $geshi = new GeSHi( $text, $lang, dirname( __FILE__ ) . '/geshi/geshi' ); if ($lines == 'true') { $geshi->enable_line_numbers( GESHI_NORMAL_LINE_NUMBERS ); } $text = $geshi->parse_code(); return $text; } ?>