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); if ($parser) { 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 (is_callable(array($row, 'getText'))) $localtext = $row->getText(); else $localtext = $row->text; if (!$published) { $localtext = preg_replace( $regex, '', $localtext ); if (is_callable(array($row, 'saveText'))) $row->saveText($localtext); else $row->text = $localtext; return; } $GLOBALS['_MAMBOT_GESHI_PARAMS'] =& $params; // perform the replacement $localtext = preg_replace_callback( $regex, 'botGeshi_replacer', $localtext ); if (is_callable(array($row, 'saveText'))) $row->saveText($localtext); else $row->text = $localtext; 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( "|\