PluginProbe
CodeColorer / 0.9.3
CodeColorer v0.9.3
trunk 0.10.0 0.10.1 0.10.2 0.11.0 0.12.0 0.5.1 0.6.0 0.7.0 0.7.2 0.7.3 0.8.0 0.8.1 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.10 0.9.11 0.9.12 0.9.13 All 36 releases
codecolorer / codecolorer.php

codecolorer.php in CodeColorer 0.9.3, at codecolorer.php

244 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: CodeColorer
4 Plugin URI: http://kpumuk.info/projects/wordpress-plugins/codecolorer/
5 Description: This plugin allows you to insert code snippets to your posts with nice syntax highlighting powered by <a href="http://qbnz.com/highlighter/">GeSHi</a> library. After enabling this plugin visit <a href="options-general.php?page=codecolorer.php">the options page</a> to configure code style.
6 Version: 0.9.3
7 Author: Dmytro Shteflyuk
8 Author URI: http://kpumuk.info/
9 Text Domain: codecolorer
10 Domain Path: /languages/
11 */
12 /*
13 Copyright 2006 - 2009 Dmytro Shteflyuk <kpumuk@kpumuk.info>
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 */
29
30 /**
31 * Doesn't work if PHP version is not 4.0.6 or higher
32 */
33 if (version_compare(phpversion(), '4.0.6', '<')) {
34 return;
35 }
36
37 define('CODECOLORER_VERSION', '0.9.3');
38
39 /**
40 * Loader class for the CodeColorer plugin
41 */
42 class CodeColorerLoader {
43 /**
44 * Enables the CodeColorer plugin with registering all required hooks.
45 */
46 function Enable() {
47 $path = dirname(__FILE__);
48 if (!file_exists("$path/codecolorer-core.php")) return false;
49 require_once("$path/codecolorer-core.php");
50
51 // Add some default options if they don't exist
52 add_option('codecolorer_css_style', '');
53 add_option('codecolorer_lines_to_scroll', 20);
54 add_option('codecolorer_width', 435);
55 add_option('codecolorer_height', 300);
56 add_option('codecolorer_rss_width', 435);
57 add_option('codecolorer_line_numbers', false);
58 add_option('codecolorer_disable_keyword_linking', false);
59 add_option('codecolorer_tab_size', 4);
60 add_option('codecolorer_theme', '');
61 add_option('codecolorer_inline_theme', '');
62
63 // Two more options to disable notifications
64 add_option('codecolorer_language_notification', true);
65 add_option('codecolorer_concurrent_notification', true);
66
67 // Admin panel initialization
68 add_action('admin_init', array('CodeColorerLoader', 'AdminInit'));
69
70 // Add plugin options page
71 add_action('admin_menu', array('CodeColorerLoader', 'AddPluginOptionsPage'));
72
73 // Load CodeColorer styles on admin pages
74 add_action('admin_head', array('CodeColorerLoader', 'LoadStyles'));
75
76 // Show notice when another GeSHi library found
77 if (get_option('codecolorer_concurrent_notification')) {
78 add_action('admin_notices', array('CodeColorerLoader', 'CallShowGeshiWarning'));
79 }
80
81 // Load CodeColorer styles on regular pages
82 add_action('wp_head', array('CodeColorerLoader', 'LoadStyles'));
83
84 // Add action links
85 add_action('plugin_action_links_' . plugin_basename(__FILE__), array('CodeColorerLoader', 'AddPluginActions'));
86
87 // Add meta links
88 add_filter('plugin_row_meta', array('CodeColorerLoader', 'AddPluginLinks'), 10, 2);
89
90 // Code highlighting filters
91 add_filter('the_content', array('CodeColorerLoader', 'CallBeforeHighlightCodeBlock'), -1000);
92 add_filter('the_content', array('CodeColorerLoader', 'CallAfterHighlightCodeBlock'), 1000);
93 add_filter('the_excerpt', array('CodeColorerLoader', 'CallBeforeHighlightCodeBlock'), -1000);
94 add_filter('the_excerpt', array('CodeColorerLoader', 'CallAfterHighlightCodeBlock'), 1000);
95 add_filter('comment_text', array('CodeColorerLoader', 'CallBeforeHighlightCodeBlock'), -1000);
96 add_filter('comment_text', array('CodeColorerLoader', 'CallAfterHighlightCodeBlock'), 1000);
97
98 // Code protection filters
99 add_filter('pre_comment_content', array('CodeColorerLoader', 'CallBeforeProtectComment'), -1000);
100 add_filter('pre_comment_content', array('CodeColorerLoader', 'CallAfterProtectComment'), 1000);
101
102 return true;
103 }
104
105 function AdminInit() {
106 $plugin_dir = basename(dirname(__FILE__));
107 load_plugin_textdomain('codecolorer', false, "$plugin_dir/languages");
108
109 if (!class_exists('CodeColorerOptions')) {
110 $path = dirname(__FILE__);
111 if (!file_exists("$path/codecolorer-options.php")) return false;
112 require_once("$path/codecolorer-options.php");
113 }
114
115 // Register out options so WordPress knows about them
116 register_setting('codecolorer', 'codecolorer_css_style', '');
117 register_setting('codecolorer', 'codecolorer_lines_to_scroll', 'intval');
118 register_setting('codecolorer', 'codecolorer_width', '');
119 register_setting('codecolorer', 'codecolorer_height', '');
120 register_setting('codecolorer', 'codecolorer_rss_width', '');
121 register_setting('codecolorer', 'codecolorer_line_numbers', '');
122 register_setting('codecolorer', 'codecolorer_disable_keyword_linking', array('CodeColorerOptions', 'SanitizeBoolean'));
123 register_setting('codecolorer', 'codecolorer_tab_size', 'intval');
124 register_setting('codecolorer', 'codecolorer_theme', '');
125 register_setting('codecolorer', 'codecolorer_inline_theme', '');
126
127 // Scripts
128 if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
129 // Quick tags
130 add_action('wp_print_scripts', array('CodeColorerLoader', 'RegisterQuicktag'));
131
132 // TinyMCE
133 // temporarily disabled
134 // if (get_user_option('rich_editing') == 'true') {
135 // add_filter('mce_external_plugins', array('CodeColorerLoader', 'AddTinyMCEPlugin'));
136 // add_filter('mce_buttons', array('CodeColorerLoader', 'RegisterTinyMCEButton'));
137 // }
138 }
139 }
140
141 function LoadStyles() {
142 $css_url = plugins_url(basename(dirname(__FILE__)) . '/codecolorer.css');
143 echo "<link rel=\"stylesheet\" href=\"$css_url\" type=\"text/css\" />\n";
144 $styles = trim(get_option('codecolorer_css_style'));
145 if (!empty($styles)) {
146 echo "<style type=\"text/css\">$styles</style>\n";
147 }
148 }
149
150 function AddPluginOptionsPage() {
151 if (function_exists('add_options_page')) {
152 add_options_page('CodeColorer', 'CodeColorer', 8, 'codecolorer.php', array('CodeColorerLoader', 'CallShowOptionsPage'));
153 }
154 }
155
156 function AddPluginActions($links) {
157 $new_links = array();
158
159 $new_links[] = '<a href="options-general.php?page=codecolorer.php">' . __('Settings', 'codecolorer') . '</a>';
160
161 return array_merge($new_links, $links);
162 }
163
164 function AddPluginLinks($links, $file) {
165 if ($file == basename(dirname(__FILE__)) . '/' . basename(__FILE__)) {
166 $links[] = '<a href="http://kpumuk.info/projects/wordpress-plugins/codecolorer/#faq">' . __('FAQ', 'codecolorer') . '</a>';
167 $links[] = '<a href="http://kpumuk.info/projects/wordpress-plugins/codecolorer/#support">' . __('Support', 'codecolorer') . '</a>';
168 }
169 return $links;
170 }
171
172 function RegisterQuicktag() {
173 if (is_admin()) {
174 wp_enqueue_script('jquery');
175 $url = plugins_url(basename(dirname(__FILE__)) . '/js/quicktags.js');
176 wp_enqueue_script('codecolorer', $url, array('jquery'), CODECOLORER_VERSION, true);
177 wp_localize_script('codecolorer', 'codeColorerL10n', array(
178 'enterLanguage' => __('Enter Language')
179 ));
180 }
181 }
182
183 function RegisterTinyMCEButton($buttons) {
184 array_push($buttons, 'separator', 'codecolorer');
185 return $buttons;
186 }
187
188 function AddTinyMCEPlugin($plugins) {
189 $url = plugins_url(basename(dirname(__FILE__)) . '/js/tinymce_plugin.js');
190 $plugins['codecolorer'] = $url;
191 return $plugins;
192 }
193
194 function CallShowOptionsPage() {
195 $cc = &CodeColorer::GetInstance();
196 if (null !== $cc) {
197 $cc->ShowOptionsPage();
198 }
199 }
200
201 function CallShowGeshiWarning() {
202 $cc = &CodeColorer::GetInstance();
203 if (null !== $cc) {
204 $cc->ShowGeshiWarning();
205 }
206 }
207
208 function CallBeforeHighlightCodeBlock($content) {
209 $cc = &CodeColorer::GetInstance();
210 if (null !== $cc) {
211 return $cc->BeforeHighlightCodeBlock($content);
212 }
213 return $content;
214 }
215
216 function CallAfterHighlightCodeBlock($content) {
217 $cc = &CodeColorer::GetInstance();
218 if (null !== $cc) {
219 return $cc->AfterHighlightCodeBlock($content);
220 }
221 return $content;
222 }
223
224 function CallBeforeProtectComment($content) {
225 $cc = &CodeColorer::GetInstance();
226 if (null !== $cc) {
227 return $cc->BeforeProtectComment($content);
228 }
229 return $content;
230 }
231
232 function CallAfterProtectComment($content) {
233 $cc = &CodeColorer::GetInstance();
234 if (null !== $cc) {
235 return $cc->AfterProtectComment($content);
236 }
237 return $content;
238 }
239 }
240
241 CodeColorerLoader::Enable();
242
243 ?>
244