From e7fac954e7932db9a62c717ba0acf078401fbe96 Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Wed, 27 Oct 2010 11:13:08 +0300 Subject: Add the following plugins: - aksimet - clean archives reloaded - google intergration toolkit - openid - smart youtube - wp stats - wp-syntax - wp-security scan --- plugins/wp-syntax/wp-syntax.php | 173 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 plugins/wp-syntax/wp-syntax.php (limited to 'plugins/wp-syntax/wp-syntax.php') diff --git a/plugins/wp-syntax/wp-syntax.php b/plugins/wp-syntax/wp-syntax.php new file mode 100644 index 00000000..dc98528c --- /dev/null +++ b/plugins/wp-syntax/wp-syntax.php @@ -0,0 +1,173 @@ +GeSHi supporting a wide range of popular languages. Wrap code blocks with <pre lang="LANGUAGE" line="1"> and </pre> where LANGUAGE is a geshi supported language syntax. The line attribute is optional. +Author: Ryan McGeary +Version: 0.9.8 +Author URI: http://ryan.mcgeary.org/ +*/ + +# +# Copyright (c) 2007-2009 Ryan McGeary +# +# This file is part of WP-Syntax. +# +# WP-Syntax is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# WP-Syntax is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along +# with WP-Syntax; if not, write to the Free Software Foundation, Inc., 59 +# Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +// Override allowed attributes for pre tags in order to use
 in
+// comments. For more info see wp-includes/kses.php
+if (!CUSTOM_TAGS) {
+  $allowedposttags['pre'] = array(
+    'lang' => array(),
+    'line' => array(),
+    'escaped' => array(),
+    'style' => array(),
+    'width' => array(),
+  );
+  //Allow plugin use in comments
+  $allowedtags['pre'] = array(
+    'lang' => array(),
+    'line' => array(),
+    'escaped' => array(),
+  );
+}
+
+include_once("geshi/geshi.php");
+
+if (!defined("WP_CONTENT_URL")) define("WP_CONTENT_URL", get_option("siteurl") . "/wp-content");
+if (!defined("WP_PLUGIN_URL"))  define("WP_PLUGIN_URL",  WP_CONTENT_URL        . "/plugins");
+
+function wp_syntax_head()
+{
+  $css_url = WP_PLUGIN_URL . "/wp-syntax/wp-syntax.css";
+  if (file_exists(TEMPLATEPATH . "/wp-syntax.css"))
+  {
+    $css_url = get_bloginfo("template_url") . "/wp-syntax.css";
+  }
+  echo "\n".''."\n";
+}
+
+function wp_syntax_code_trim($code)
+{
+    // special ltrim b/c leading whitespace matters on 1st line of content
+    $code = preg_replace("/^\s*\n/siU", "", $code);
+    $code = rtrim($code);
+    return $code;
+}
+
+function wp_syntax_substitute(&$match)
+{
+    global $wp_syntax_token, $wp_syntax_matches;
+
+    $i = count($wp_syntax_matches);
+    $wp_syntax_matches[$i] = $match;
+
+    return "\n\n

" . $wp_syntax_token . sprintf("%03d", $i) . "

\n\n"; +} + +function wp_syntax_line_numbers($code, $start) +{ + $line_count = count(explode("\n", $code)); + $output = "
";
+    for ($i = 0; $i < $line_count; $i++)
+    {
+        $output .= ($start + $i) . "\n";
+    }
+    $output .= "
"; + return $output; +} + +function wp_syntax_highlight($match) +{ + global $wp_syntax_matches; + + $i = intval($match[1]); + $match = $wp_syntax_matches[$i]; + + $language = strtolower(trim($match[1])); + $line = trim($match[2]); + $escaped = trim($match[3]); + $code = wp_syntax_code_trim($match[4]); + if ($escaped == "true") $code = htmlspecialchars_decode($code); + + $geshi = new GeSHi($code, $language); + $geshi->enable_keyword_links(false); + do_action_ref_array('wp_syntax_init_geshi', array(&$geshi)); + + $output = "\n
"; + + if ($line) + { + $output .= "
"; + $output .= wp_syntax_line_numbers($code, $line); + $output .= ""; + $output .= $geshi->parse_code(); + $output .= "
"; + } + else + { + $output .= "
"; + $output .= $geshi->parse_code(); + $output .= "
"; + } + return + + $output .= "
\n"; + + return $output; +} + +function wp_syntax_before_filter($content) +{ + return preg_replace_callback( + "/\s*(.*)<\/pre>\s*/siU", + "wp_syntax_substitute", + $content + ); +} + +function wp_syntax_after_filter($content) +{ + global $wp_syntax_token; + + $content = preg_replace_callback( + "/

\s*".$wp_syntax_token."(\d{3})\s*<\/p>/si", + "wp_syntax_highlight", + $content + ); + + return $content; +} + +$wp_syntax_token = md5(uniqid(rand())); + +// Add styling +add_action('wp_head', 'wp_syntax_head'); + +// We want to run before other filters; hence, a priority of 0 was chosen. +// The lower the number, the higher the priority. 10 is the default and +// several formatting filters run at or around 6. +add_filter('the_content', 'wp_syntax_before_filter', 0); +add_filter('the_excerpt', 'wp_syntax_before_filter', 0); +add_filter('comment_text', 'wp_syntax_before_filter', 0); + +// We want to run after other filters; hence, a priority of 99. +add_filter('the_content', 'wp_syntax_after_filter', 99); +add_filter('the_excerpt', 'wp_syntax_after_filter', 99); +add_filter('comment_text', 'wp_syntax_after_filter', 99); + +?> -- cgit v1.2.3-65-gdbad