PluginProbe
CodeColorer / 0.9.6
CodeColorer v0.9.6
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.6, at codecolorer.php

246 lines 8.9 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.6
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.6');
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_css_class', '');
54 add_option('codecolorer_lines_to_scroll', 20);
55 add_option('codecolorer_width', 435);
56 add_option('codecolorer_height', 300);
57 add_option('codecolorer_rss_width', 435);
58 add_option('codecolorer_line_numbers', false);
59 add_option('codecolorer_disable_keyword_linking', false);
60 add_option('codecolorer_tab_size', 4);
61 add_option('codecolorer_theme', '');
62 add_option('codecolorer_inline_theme', '');
63
64 // Two more options to disable notifications
65 add_option('codecolorer_language_notification', true);
66 add_option('codecolorer_concurrent_notification', true);
67
68 // Admin panel initialization
69 add_action('admin_init', array('CodeColorerLoader', 'AdminInit'));
70
71 // Add plugin options page
72 add_action('admin_menu', array('CodeColorerLoader', 'AddPluginOptionsPage'));
73
74 // Load CodeColorer styles on admin pages
75 add_action('admin_head', array('CodeColorerLoader', 'LoadStyles'));
76
77 // Show notice when another GeSHi library found
78 if (get_option('codecolorer_concurrent_notification')) {
79 add_action('admin_notices', array('CodeColorerLoader', 'CallShowGeshiWarning'));
80 }
81
82 // Load CodeColorer styles on regular pages
83 add_action('wp_head', array('CodeColorerLoader', 'LoadStyles'));
84
85 // Add action links
86 add_action('plugin_action_links_' . plugin_basename(__FILE__), array('CodeColorerLoader', 'AddPluginActions'));
87
88 // Add meta links
89 add_filter('plugin_row_meta', array('CodeColorerLoader', 'AddPluginLinks'), 10, 2);
90
91 // Code highlighting filters
92 add_filter('the_content', array('CodeColorerLoader', 'CallBeforeHighlightCodeBlock'), -1000);
93 add_filter('the_content', array('CodeColorerLoader', 'CallAfterHighlightCodeBlock'), 1000);
94 add_filter('the_excerpt', array('CodeColorerLoader', 'CallBeforeHighlightCodeBlock'), -1000);
95 add_filter('the_excerpt', array('CodeColorerLoader', 'CallAfterHighlightCodeBlock'), 1000);
96 add_filter('comment_text', array('CodeColorerLoader', 'CallBeforeHighlightCodeBlock'), -1000);
97 add_filter('comment_text', array('CodeColorerLoader', 'CallAfterHighlightCodeBlock'), 1000);
98
99 // Code protection filters
100 add_filter('pre_comment_content', array('CodeColorerLoader', 'CallBeforeProtectComment'), -1000);
101 add_filter('pre_comment_content', array('CodeColorerLoader', 'CallAfterProtectComment'), 1000);
102
103 return true;
104 }
105
106 function AdminInit() {
107 $plugin_dir = basename(dirname(__FILE__));
108 load_plugin_textdomain('codecolorer', false, "$plugin_dir/languages");
109
110 if (!class_exists('CodeColorerOptions')) {
111 $path = dirname(__FILE__);
112 if (!file_exists("$path/codecolorer-options.php")) return false;
113 require_once("$path/codecolorer-options.php");
114 }
115
116 // Register out options so WordPress knows about them
117 register_setting('codecolorer', 'codecolorer_css_style', '');
118 register_setting('codecolorer', 'codecolorer_css_class', '');
119 register_setting('codecolorer', 'codecolorer_lines_to_scroll', 'intval');
120 register_setting('codecolorer', 'codecolorer_width', '');
121 register_setting('codecolorer', 'codecolorer_height', '');
122 register_setting('codecolorer', 'codecolorer_rss_width', '');
123 register_setting('codecolorer', 'codecolorer_line_numbers', '');
124 register_setting('codecolorer', 'codecolorer_disable_keyword_linking', array('CodeColorerOptions', 'SanitizeBoolean'));
125 register_setting('codecolorer', 'codecolorer_tab_size', 'intval');
126 register_setting('codecolorer', 'codecolorer_theme', '');
127 register_setting('codecolorer', 'codecolorer_inline_theme', '');
128
129 // Scripts
130 if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
131 // Quick tags
132 add_action('wp_print_scripts', array('CodeColorerLoader', 'RegisterQuicktag'));
133
134 // TinyMCE
135 // temporarily disabled
136 // if (get_user_option('rich_editing') == 'true') {
137 // add_filter('mce_external_plugins', array('CodeColorerLoader', 'AddTinyMCEPlugin'));
138 // add_filter('mce_buttons', array('CodeColorerLoader', 'RegisterTinyMCEButton'));
139 // }
140 }
141 }
142
143 function LoadStyles() {
144 $css_url = plugins_url(basename(dirname(__FILE__)) . '/codecolorer.css');
145 echo "<link rel=\"stylesheet\" href=\"$css_url\" type=\"text/css\" />\n";
146 $styles = trim(get_option('codecolorer_css_style'));
147 if (!empty($styles)) {
148 echo "<style type=\"text/css\">$styles</style>\n";
149 }
150 }
151
152 function AddPluginOptionsPage() {
153 if (function_exists('add_options_page')) {
154 add_options_page('CodeColorer', 'CodeColorer', 8, 'codecolorer.php', array('CodeColorerLoader', 'CallShowOptionsPage'));
155 }
156 }
157
158 function AddPluginActions($links) {
159 $new_links = array();
160
161 $new_links[] = '<a href="options-general.php?page=codecolorer.php">' . __('Settings', 'codecolorer') . '</a>';
162
163 return array_merge($new_links, $links);
164 }
165
166 function AddPluginLinks($links, $file) {
167 if ($file == basename(dirname(__FILE__)) . '/' . basename(__FILE__)) {
168 $links[] = '<a href="http://kpumuk.info/projects/wordpress-plugins/codecolorer/#faq">' . __('FAQ', 'codecolorer') . '</a>';
169 $links[] = '<a href="http://kpumuk.info/projects/wordpress-plugins/codecolorer/#support">' . __('Support', 'codecolorer') . '</a>';
170 }
171 return $links;
172 }
173
174 function RegisterQuicktag() {
175 if (is_admin()) {
176 wp_enqueue_script('jquery');
177 $url = plugins_url(basename(dirname(__FILE__)) . '/js/quicktags.js');
178 wp_enqueue_script('codecolorer', $url, array('jquery'), CODECOLORER_VERSION, true);
179 wp_localize_script('codecolorer', 'codeColorerL10n', array(
180 'enterLanguage' => __('Enter Language')
181 ));
182 }
183 }
184
185 function RegisterTinyMCEButton($buttons) {
186 array_push($buttons, 'separator', 'codecolorer');
187 return $buttons;
188 }
189
190 function AddTinyMCEPlugin($plugins) {
191 $url = plugins_url(basename(dirname(__FILE__)) . '/js/tinymce_plugin.js');
192 $plugins['codecolorer'] = $url;
193 return $plugins;
194 }
195
196 function CallShowOptionsPage() {
197 $cc = &CodeColorer::GetInstance();
198 if (null !== $cc) {
199 $cc->ShowOptionsPage();
200 }
201 }
202
203 function CallShowGeshiWarning() {
204 $cc = &CodeColorer::GetInstance();
205 if (null !== $cc) {
206 $cc->ShowGeshiWarning();
207 }
208 }
209
210 function CallBeforeHighlightCodeBlock($content) {
211 $cc = &CodeColorer::GetInstance();
212 if (null !== $cc) {
213 return $cc->BeforeHighlightCodeBlock($content);
214 }
215 return $content;
216 }
217
218 function CallAfterHighlightCodeBlock($content) {
219 $cc = &CodeColorer::GetInstance();
220 if (null !== $cc) {
221 return $cc->AfterHighlightCodeBlock($content);
222 }
223 return $content;
224 }
225
226 function CallBeforeProtectComment($content) {
227 $cc = &CodeColorer::GetInstance();
228 if (null !== $cc) {
229 return $cc->BeforeProtectComment($content);
230 }
231 return $content;
232 }
233
234 function CallAfterProtectComment($content) {
235 $cc = &CodeColorer::GetInstance();
236 if (null !== $cc) {
237 return $cc->AfterProtectComment($content);
238 }
239 return $content;
240 }
241 }
242
243 CodeColorerLoader::Enable();
244
245 ?>
246