SyntaxHighlighter from Alex Gorbatchev for easy use in your WordPress. Simplifications by Mick West */ // Should contain all shBrush*.js-files in ./Scripts function syntaxBrushes() { return array( "Cpp" => "C++", "CSharp" => "C#", "Css" => "CSS", "Delphi" => "Delphi, Pascal", "Java" => "Java", "JScript" => "JavaScript", "Php" => "PHP", "Python" => "Python", "Ruby" => "Ruby", "Sql" => "SQL", "Vb" => "VisualBasic, VB.NET", "Xml" => "XML, XHTML, XSLT, HTML", ); } function syntaxUsage() { return array( "Cpp" => false, "CSharp" => false, "Css" => false, "Delphi" => false, "Java" => false, "JScript" => false, "Php" => false, "Python" => false, "Ruby" => false, "Sql" => false, "Vb" => false, "Xml" => false, ); } // Returns the script path function syntaxPath() { return get_settings( 'home' )."/wp-content/plugins/syntax/"; } // Options Menu function syntaxMenu() { if (function_exists('add_options_page')) add_options_page( __('Syntax'), __('Syntax'), 'manage_options', 'syntaxOptions.php', 'syntaxOptions' ) ; } // Options Administration function syntaxOptions() { // Submitted Form? if( $_POST['Submit'] ) { // Load Brushes // $syntaxBrushes = syntaxBrushes(); // // // Set all Brushes to Zilch first // foreach( $syntaxBrushes as $brushID => $brushName ) // $setOptions['syntaxBrush'.$brushID] = 0; // Now, snatch the new configs foreach( $_POST as $postVar => $postVal ) if( strpos( $postVar, "syntax" ) !== false ) $setOptions[$postVar] = $postVal; // Save new options update_option( 'syntaxOptions', $setOptions ); // Message to the user $msgSaved = "New Options saved."; } // Load settings $syntaxOptions = get_settings( 'syntaxOptions' ); $syntaxBrushes = syntaxBrushes(); // Defaults for textarea if( !$syntaxOptions['syntaxCols'] ) $syntaxOptions['syntaxCols'] = 60; if( !$syntaxOptions['syntaxRows'] ) $syntaxOptions['syntaxRows'] = 10; // Display options page if( $msgSaved ) echo '

'.$msgSaved.'

'; ?>

:

$brushName ) { $checkbox = ( $syntaxOptions['syntaxBrush'.$brushID] == 1 ) ? 'checked="checked" ' : ''; // echo "\t\t\t\t\t

" // ." " // ."{$brushName}

\n"; echo "\t\t\t\t\t

" ."{$brushID} : {$brushName}

\n"; } ?>

:



:

/> Make the Textbox Collapsible?

/> Hide Controls on top?

/> Hide Gutter?

/> Hide Columns?

  
post_content, '[source:' ) !== false ) { $is_syntaxPost = true; } } return $is_syntaxPost; } // Add CSS to header function syntaxHeader() { if (hasSyntaxPost()) { $syntaxPath = syntaxPath(); echo "\n\t\n"; } } // Parse the posting thx to that damn autoformatting function syntaxPost( $thePost ) { global $userdata; // v1.5: No more '; // Re-insert source as (formatted) textarea foreach( $theSources[2] as $sourceID => $sourceBlock ) { $theBrush = $theSources[1][$sourceID].$optionString; $thePost = str_replace( "

{sourceID:{$sourceID}}

", sprintf( $textArea, $theBrush, $syntaxOptions['syntaxCols'], $syntaxOptions['syntaxRows'], $sourceBlock ), $thePost ); } return $thePost; } else // No code, no business! return wpautop( wptexturize( $thePost ) ); } // Add Scripts to footer function syntaxFooter() { // Load Usage table $syntaxUse = syntaxUsage(); global $posts; for($i=0;$i<=(count($posts)-1);$i++) { // Grab all source-tags preg_match_all ( '!\[source:(.*)\](.*)\[\/source\]!isU', $posts[$i]->post_content, $theSources ); // Flag which are used foreach( $theSources[1] as $sourceID => $sourceType ) { // sourceType here will be the arbitary case version // need to convert it to the specific case version used by the JS filename foreach( $syntaxUse as $syntaxID => $use ) { if (strcasecmp($sourceType,$syntaxID) == 0) $syntaxUse[$syntaxID] = true; } } } if (hasSyntaxPost()) { $syntaxOptions = get_settings( 'syntaxOptions' ); $syntaxPath = syntaxPath(); echo "\n\n" ."\n\t"; foreach( $syntaxUse as $syntaxID => $use ) if( $syntaxUse[$syntaxID]) { echo "\n\t"; } echo "\n\t" ."\n\n"; } } // Modify Filters remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_content', 'wptexturize' ); // Modify Actions add_action( 'admin_menu', 'syntaxMenu' ); add_action( 'wp_head', 'syntaxHeader' ); add_action( 'the_content', 'syntaxPost' ); add_action( 'wp_footer', 'syntaxFooter' ); ?>