")) { return $text; } // Check if the user don't want to see any of our nice colours... if($_GET['highlight'] == 'no') { return $text; } // Grab memory for a new class $hh_highlight = new Highlight; // Let's do'it return $hh_highlight->initialise($text); } class Highlight { // Extracts only the bits and pieces that we need, i.e. what's // in the code-element. The extracted code is then sent to match() function initialise($text) { define('hh_highlight', true); return preg_replace_callback("/(.*?)<\/code>/si", array(&$this, "match"), $text); } // Sends the code that needs to be highlighted to the // appropriate function and wraps the result in a code-block function match($matches) { $text = str_replace(array('<code>', '</code>'), array('', ''), $this->highlight($matches[1])); return $text; } // We'll have to search to see wether or not there is a preprocess($code)) : // It wasn't PHP so let's return it with wrapped // in its code-element, shall we. $code = '' . $code . ''; else : // Need to clean up the code a bit (can this be done neater?) $code = str_replace( // Search (Needle) array( '<?php', '< ?php', '< ?php', '< ? php', '[php]', '[/php]', '?>', '
', "" ), // Replace (New Needle) array( '', '?>', '', '' ), // Haystack $code); // From php.net user notes - this is the work horse ob_start(); // Start output buffering highlight_string($code); // Highlight the code $code = ob_get_contents(); // Capture output ob_end_clean(); // Clear buffer if(1 == get_option('hh_highlight_use_classes')) : // From PHP.net ( http://www.php.net/source.php?url=/include/layout.inc ) // Fix output to use CSS classes and wrap well $code = str_replace( // Search (Needle) array( ' ', '
', '', "\n ", ' ' ), // Replace (New needle) array( ' ', "
\n", '', "\n ", '  ' ), // Haystack $code); endif; endif; return $code; } } // Class dismissed function hh_highlight_after($text) { $text = str_replace('
', '', $text); return $text; } // Highlight options page function hh_highlight_options() { // Get all the class names so that we can populate the // fields with some values - This is an array $class = unserialize(get_option('hh_highlight_classes')); ?>




code-element:', 'hh_highlight') ?>

$_POST['highlight_comment'], 'default' => $_POST['highlight_default'], 'keyword' => $_POST['highlight_keyword'], 'string' => $_POST['highlight_string'], 'html' => $_POST['highlight_html'], 'code' => $_POST['code_class']))); // Go back to the options-page without the POST information in the headers // ToDo: Not hard-code file name header('Location: options-general.php?page=hh-highlight.php&updated=true'); /* print '
';
		print_r($_POST);
		print '
'; */ } // Highlight comments? // Must be activated from admin-page if(1 == get_option('hh_highlight_comments')) { add_filter('comment_text', 'hh_highlight'); add_filter('comment_text', 'hh_highlight_after'); } // Let's set up some classes (if needed) if(1 == get_option('hh_highlight_use_classes')) { $class = unserialize(get_option('hh_highlight_classes')); ini_set('highlight.comment', $class['comment']); ini_set('highlight.default', $class['default']); ini_set('highlight.keyword', $class['keyword']); ini_set('highlight.string', $class['string']); ini_set('highlight.html', $class['html']); } } // Just for adding a options page function hh_highlight_add_pages() { add_options_page('Code Highlighter', 'Code Highlighter', 8, __FILE__, 'hh_highlight_options'); } // Add to the WordPress hook's add_action('init', 'hh_init'); add_action('admin_menu', 'hh_highlight_add_pages'); add_filter('the_content', 'hh_highlight'); ?>