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( "|\