registerFunction( 'onPrepareContent', 'botMosCode' ); /** * Code Highlighting Mambot * * Usage: * {moscode}...some code...{/moscode} */ function botMosCode( $published, &$row, &$params, $page=0 ) { // simple performance check to determine whether bot should process further if ( strpos( $row->text, 'moscode' ) === false ) { return true; } // define the regular expression for the bot $regex = "#{moscode}(.*?){/moscode}#s"; // check whether mambot has been unpublished if ( !$published ) { $row->text = preg_replace( $regex, '', $row->text ); return true; } // perform the replacement $row->text = preg_replace_callback( $regex, 'botMosCode_replacer', $row->text ); return true; } /** * Replaces the matched tags an image * @param array An array of matches (see preg_match_all) * @return string */ function botMosCode_replacer( &$matches ) { $html_entities_match = array("#<#", "#>#"); $html_entities_replace = array("<", ">"); $text = $matches[1]; $text = preg_replace($html_entities_match, $html_entities_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('<', '<', $text); $text = str_replace('>', '>', $text); $text = highlight_string( $text, 1 ); $text = str_replace('&nbsp;', ' ', $text); $text = str_replace('<br/>', '
', $text); $text = str_replace('<br/>','
', $text); $text = str_replace('&
nbsp;', ' ', $text); $text = str_replace('&nbsp;', ' ', $text); $text = str_replace(';<br/>','
', $text); return $text; } ?>