SyntaxHighlighter Evolved - Version 3.2.1

Version Description

Download this release

Release Info

Developer Viper007Bond
Plugin Icon wp plugin SyntaxHighlighter Evolved
Version 3.2.1
Comparing to
See all releases

Code changes from version 3.2.0 to 3.2.1

Files changed (3) hide show
  1. readme.md +0 -7
  2. readme.txt +4 -0
  3. syntaxhighlighter.php +1328 -1299
readme.md DELETED
@@ -1,7 +0,0 @@
1
- ## SyntaxHighlighter Evolved
2
-
3
- Easily post syntax-highlighted code to your WordPress site without having to modify the code at all. As seen on WordPress.com.
4
-
5
- ## Development On The Next Version
6
-
7
- A major rewrite is currently occurring in the [4.0 branch](https://github.com/Viper007Bond/syntaxhighlighter/tree/4.0). Go there if you want to see the current work in progress code.
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -55,6 +55,10 @@ Make sure your theme's `footer.php` file has `<?php wp_footer(); ?>` somewhere i
55
 
56
  == ChangeLog ==
57
 
 
 
 
 
58
  = Version 3.2.0 =
59
 
60
  * Don't parse shortcodes inside of HTML entities, which could result in broken HTML.
55
 
56
  == ChangeLog ==
57
 
58
+ = Version 3.2.1 =
59
+
60
+ * Fix shortcode issues that would occur during post editing if the code contained what looked like opening HTML tags such as `<?php`. See [this forum thread](https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks) for details.
61
+
62
  = Version 3.2.0 =
63
 
64
  * Don't parse shortcodes inside of HTML entities, which could result in broken HTML.
syntaxhighlighter.php CHANGED
@@ -1,1300 +1,1329 @@
1
- <?php /*
2
-
3
- **************************************************************************
4
-
5
- Plugin Name: SyntaxHighlighter Evolved
6
- Plugin URI: http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/
7
- Version: 3.2.0
8
- Description: Easily post syntax-highlighted code to your site without having to modify the code at all. Uses Alex Gorbatchev's <a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter">SyntaxHighlighter</a>. <strong>TIP:</strong> Don't use the Visual editor if you don't want your code mangled. TinyMCE will "clean up" your HTML.
9
- Author: Alex Mills (Viper007Bond)
10
- Author URI: http://www.viper007bond.com/
11
-
12
- **************************************************************************
13
-
14
- Thanks to:
15
-
16
- * Alex Gorbatchev for writing the Javascript-powered syntax highlighter script
17
-
18
- * Andrew Ozz for writing the TinyMCE plugin
19
-
20
- **************************************************************************/
21
-
22
- class SyntaxHighlighter {
23
- // All of these variables are private. Filters are provided for things that can be modified.
24
- var $pluginver = '3.2.0'; // Plugin version
25
- var $agshver = false; // Alex Gorbatchev's SyntaxHighlighter version (dynamically set below due to v2 vs v3)
26
- var $shfolder = false; // Controls what subfolder to load SyntaxHighlighter from (v2 or v3)
27
- var $settings = array(); // Contains the user's settings
28
- var $defaultsettings = array(); // Contains the default settings
29
- var $brushes = array(); // Array of aliases => brushes
30
- var $shortcodes = array(); // Array of shortcodes to use
31
- var $themes = array(); // Array of themes
32
- var $usedbrushes = array(); // Stores used brushes so we know what to output
33
- var $encoded = false; // Used to mark that a character encode took place
34
- var $codeformat = false; // If set, SyntaxHighlighter::get_code_format() will return this value
35
- var $content_save_pre_ran = false; // It's possible for the "content_save_pre" filter to run multiple times, so keep track
36
-
37
- // Initalize the plugin by registering the hooks
38
- function __construct() {
39
- if ( ! function_exists( 'do_shortcodes_in_html_tags' ) )
40
- return;
41
-
42
- // Load localization domain
43
- load_plugin_textdomain( 'syntaxhighlighter', false, '/syntaxhighlighter/localization' );
44
-
45
- // Display hooks
46
- add_filter( 'the_content', array( $this, 'parse_shortcodes' ), 7 ); // Posts
47
- add_filter( 'comment_text', array( $this, 'parse_shortcodes_comment' ), 7 ); // Comments
48
- add_filter( 'bp_get_the_topic_post_content', array( $this, 'parse_shortcodes' ), 7 ); // BuddyPress
49
-
50
- // Into the database
51
- add_filter( 'content_save_pre', array( $this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // Posts
52
- add_filter( 'pre_comment_content', array( $this, 'encode_shortcode_contents_slashed' ), 1 ); // Comments
53
- add_filter( 'group_forum_post_text_before_save', array( $this, 'encode_shortcode_contents_slashed' ), 1 ); // BuddyPress
54
- add_filter( 'group_forum_topic_text_before_save', array( $this, 'encode_shortcode_contents_slashed' ), 1 ); // BuddyPress
55
-
56
- // Out of the database for editing
57
- add_filter( 'the_editor_content', array( $this, 'the_editor_content' ), 1 ); // Posts
58
- add_filter( 'comment_edit_pre', array( $this, 'decode_shortcode_contents' ), 1 ); // Comments
59
- add_filter( 'bp_get_the_topic_text', array( $this, 'decode_shortcode_contents' ), 1 ); // BuddyPress
60
- add_filter( 'bp_get_the_topic_post_edit_text', array( $this, 'decode_shortcode_contents' ), 1 ); // BuddyPress
61
-
62
- // Outputting SyntaxHighlighter's JS and CSS
63
- add_action( 'wp_head', array( $this, 'output_header_placeholder' ), 15 );
64
- add_action( 'admin_head', array( $this, 'output_header_placeholder' ), 15 ); // For comments
65
- add_action( 'wp_footer', array( $this, 'maybe_output_scripts' ), 15 );
66
- add_action( 'admin_footer', array( $this, 'maybe_output_scripts' ), 15 ); // For comments
67
-
68
- // Admin hooks
69
- add_action( 'admin_init', array( $this, 'register_setting' ) );
70
- add_action( 'admin_menu', array( $this, 'register_settings_page' ) );
71
- add_filter( 'mce_external_plugins', array( $this, 'add_tinymce_plugin' ) );
72
- add_filter( 'save_post', array( $this, 'mark_as_encoded' ), 10, 2 );
73
- add_filter( 'plugin_action_links', array( $this, 'settings_link' ), 10, 2 );
74
-
75
- // Register widget hooks
76
- add_filter( 'widget_text', array( $this, 'widget_text_output' ), 7, 2 );
77
- add_filter( 'widget_update_callback', array( $this, 'widget_text_save' ), 1, 4 );
78
- add_filter( 'widget_form_callback', array( $this, 'widget_text_form' ), 1, 2 );
79
-
80
-
81
- // Create array of default settings (you can use the filter to modify these)
82
- $this->defaultsettings = (array) apply_filters( 'syntaxhighlighter_defaultsettings', array(
83
- 'theme' => 'default',
84
- 'loadallbrushes' => 0,
85
- 'shversion' => 3,
86
- 'title' => '',
87
- 'autolinks' => 1,
88
- 'classname' => '',
89
- 'collapse' => 0,
90
- 'firstline' => 1,
91
- 'gutter' => 1,
92
- 'htmlscript' => 0,
93
- 'light' => 0,
94
- 'padlinenumbers' => 'false',
95
- 'smarttabs' => 1,
96
- 'tabsize' => 4,
97
- 'toolbar' => 0,
98
- 'wraplines' => 1, // 2.x only
99
- ) );
100
-
101
- // Create the settings array by merging the user's settings and the defaults
102
- $usersettings = (array) get_option('syntaxhighlighter_settings');
103
- $this->settings = wp_parse_args( $usersettings, $this->defaultsettings );
104
-
105
- // Dynamically set folder and version names for SynaxHighlighter
106
- if ( 2 == $this->settings['shversion'] ) {
107
- $this->shfolder = 'syntaxhighlighter2';
108
- $this->agshver = '2.1.364';
109
- } else {
110
- $this->shfolder = 'syntaxhighlighter3';
111
- $this->agshver = '3.0.9b';
112
- }
113
-
114
- // Register brush scripts
115
- wp_register_script( 'syntaxhighlighter-core', plugins_url( $this->shfolder . '/scripts/shCore.js', __FILE__ ), array(), $this->agshver );
116
- wp_register_script( 'syntaxhighlighter-brush-as3', plugins_url( $this->shfolder . '/scripts/shBrushAS3.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
117
- wp_register_script( 'syntaxhighlighter-brush-bash', plugins_url( $this->shfolder . '/scripts/shBrushBash.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
118
- wp_register_script( 'syntaxhighlighter-brush-coldfusion', plugins_url( $this->shfolder . '/scripts/shBrushColdFusion.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
119
- wp_register_script( 'syntaxhighlighter-brush-cpp', plugins_url( $this->shfolder . '/scripts/shBrushCpp.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
120
- wp_register_script( 'syntaxhighlighter-brush-csharp', plugins_url( $this->shfolder . '/scripts/shBrushCSharp.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
121
- wp_register_script( 'syntaxhighlighter-brush-css', plugins_url( $this->shfolder . '/scripts/shBrushCss.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
122
- wp_register_script( 'syntaxhighlighter-brush-delphi', plugins_url( $this->shfolder . '/scripts/shBrushDelphi.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
123
- wp_register_script( 'syntaxhighlighter-brush-diff', plugins_url( $this->shfolder . '/scripts/shBrushDiff.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
124
- wp_register_script( 'syntaxhighlighter-brush-erlang', plugins_url( $this->shfolder . '/scripts/shBrushErlang.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
125
- wp_register_script( 'syntaxhighlighter-brush-groovy', plugins_url( $this->shfolder . '/scripts/shBrushGroovy.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
126
- wp_register_script( 'syntaxhighlighter-brush-java', plugins_url( $this->shfolder . '/scripts/shBrushJava.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
127
- wp_register_script( 'syntaxhighlighter-brush-javafx', plugins_url( $this->shfolder . '/scripts/shBrushJavaFX.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
128
- wp_register_script( 'syntaxhighlighter-brush-jscript', plugins_url( $this->shfolder . '/scripts/shBrushJScript.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
129
- wp_register_script( 'syntaxhighlighter-brush-perl', plugins_url( $this->shfolder . '/scripts/shBrushPerl.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
130
- wp_register_script( 'syntaxhighlighter-brush-php', plugins_url( $this->shfolder . '/scripts/shBrushPhp.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
131
- wp_register_script( 'syntaxhighlighter-brush-plain', plugins_url( $this->shfolder . '/scripts/shBrushPlain.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
132
- wp_register_script( 'syntaxhighlighter-brush-powershell', plugins_url( $this->shfolder . '/scripts/shBrushPowerShell.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
133
- wp_register_script( 'syntaxhighlighter-brush-python', plugins_url( $this->shfolder . '/scripts/shBrushPython.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
134
- wp_register_script( 'syntaxhighlighter-brush-ruby', plugins_url( $this->shfolder . '/scripts/shBrushRuby.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
135
- wp_register_script( 'syntaxhighlighter-brush-scala', plugins_url( $this->shfolder . '/scripts/shBrushScala.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
136
- wp_register_script( 'syntaxhighlighter-brush-sql', plugins_url( $this->shfolder . '/scripts/shBrushSql.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
137
- wp_register_script( 'syntaxhighlighter-brush-vb', plugins_url( $this->shfolder . '/scripts/shBrushVb.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
138
- wp_register_script( 'syntaxhighlighter-brush-xml', plugins_url( $this->shfolder . '/scripts/shBrushXml.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
139
-
140
- // Register some popular third-party brushes
141
- wp_register_script( 'syntaxhighlighter-brush-clojure', plugins_url( 'third-party-brushes/shBrushClojure.js', __FILE__ ), array('syntaxhighlighter-core'), '20090602' );
142
- wp_register_script( 'syntaxhighlighter-brush-fsharp', plugins_url( 'third-party-brushes/shBrushFSharp.js', __FILE__ ), array('syntaxhighlighter-core'), '20091003' );
143
- wp_register_script( 'syntaxhighlighter-brush-latex', plugins_url( 'third-party-brushes/shBrushLatex.js', __FILE__ ), array('syntaxhighlighter-core'), '20090613' );
144
- wp_register_script( 'syntaxhighlighter-brush-matlabkey', plugins_url( 'third-party-brushes/shBrushMatlabKey.js', __FILE__ ), array('syntaxhighlighter-core'), '20091209' );
145
- wp_register_script( 'syntaxhighlighter-brush-objc', plugins_url( 'third-party-brushes/shBrushObjC.js', __FILE__ ), array('syntaxhighlighter-core'), '20091207' );
146
- wp_register_script( 'syntaxhighlighter-brush-r', plugins_url( 'third-party-brushes/shBrushR.js', __FILE__ ), array('syntaxhighlighter-core'), '20100919' );
147
-
148
- // Register theme stylesheets
149
- wp_register_style( 'syntaxhighlighter-core', plugins_url( $this->shfolder . '/styles/shCore.css', __FILE__ ), array(), $this->agshver );
150
- wp_register_style( 'syntaxhighlighter-theme-default', plugins_url( $this->shfolder . '/styles/shThemeDefault.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
151
- wp_register_style( 'syntaxhighlighter-theme-django', plugins_url( $this->shfolder . '/styles/shThemeDjango.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
152
- wp_register_style( 'syntaxhighlighter-theme-eclipse', plugins_url( $this->shfolder . '/styles/shThemeEclipse.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
153
- wp_register_style( 'syntaxhighlighter-theme-emacs', plugins_url( $this->shfolder . '/styles/shThemeEmacs.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
154
- wp_register_style( 'syntaxhighlighter-theme-fadetogrey', plugins_url( $this->shfolder . '/styles/shThemeFadeToGrey.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
155
- wp_register_style( 'syntaxhighlighter-theme-midnight', plugins_url( $this->shfolder . '/styles/shThemeMidnight.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
156
- wp_register_style( 'syntaxhighlighter-theme-rdark', plugins_url( $this->shfolder . '/styles/shThemeRDark.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
157
-
158
-
159
- // Create list of brush aliases and map them to their real brushes
160
- // The key is the language alias
161
- // The value is the script handle suffix: syntaxhighlighter-brush-ThisBitHere (your plugin needs to register the script itself)
162
- $this->brushes = (array) apply_filters( 'syntaxhighlighter_brushes', array(
163
- 'as3' => 'as3',
164
- 'actionscript3' => 'as3',
165
- 'bash' => 'bash',
166
- 'shell' => 'bash',
167
- 'coldfusion' => 'coldfusion',
168
- 'cf' => 'coldfusion',
169
- 'clojure' => 'clojure',
170
- 'clj' => 'clojure',
171
- 'cpp' => 'cpp',
172
- 'c' => 'cpp',
173
- 'c-sharp' => 'csharp',
174
- 'csharp' => 'csharp',
175
- 'css' => 'css',
176
- 'delphi' => 'delphi',
177
- 'pas' => 'delphi',
178
- 'pascal' => 'delphi',
179
- 'diff' => 'diff',
180
- 'patch' => 'diff',
181
- 'erl' => 'erlang',
182
- 'erlang' => 'erlang',
183
- 'fsharp' => 'fsharp',
184
- 'groovy' => 'groovy',
185
- 'java' => 'java',
186
- 'jfx' => 'javafx',
187
- 'javafx' => 'javafx',
188
- 'js' => 'jscript',
189
- 'jscript' => 'jscript',
190
- 'javascript' => 'jscript',
191
- 'latex' => 'latex', // Not used as a shortcode
192
- 'tex' => 'latex',
193
- 'matlab' => 'matlabkey',
194
- 'objc' => 'objc',
195
- 'obj-c' => 'objc',
196
- 'perl' => 'perl',
197
- 'pl' => 'perl',
198
- 'php' => 'php',
199
- 'plain' => 'plain',
200
- 'text' => 'plain',
201
- 'ps' => 'powershell',
202
- 'powershell' => 'powershell',
203
- 'py' => 'python',
204
- 'python' => 'python',
205
- 'r' => 'r', // Not used as a shortcode
206
- 'splus' => 'r',
207
- 'rails' => 'ruby',
208
- 'rb' => 'ruby',
209
- 'ror' => 'ruby',
210
- 'ruby' => 'ruby',
211
- 'scala' => 'scala',
212
- 'sql' => 'sql',
213
- 'vb' => 'vb',
214
- 'vbnet' => 'vb',
215
- 'xml' => 'xml',
216
- 'xhtml' => 'xml',
217
- 'xslt' => 'xml',
218
- 'html' => 'xml',
219
- ) );
220
-
221
-
222
- // Create a list of shortcodes to use. You can use the filter to add/remove ones.
223
- // If the language/lang parameter is left out, it's assumed the shortcode name is the language.
224
- // If that's invalid, then "plain" is used.
225
- $this->shortcodes = array( 'sourcecode', 'source', 'code' );
226
- $this->shortcodes = array_merge( $this->shortcodes, array_keys( $this->brushes ) );
227
-
228
- // Remove some shortcodes we don't want while still supporting them as language values
229
- unset( $this->shortcodes[array_search( 'latex', $this->shortcodes )] ); // Remove "latex" shortcode (it'll collide)
230
- unset( $this->shortcodes[array_search( 'r', $this->shortcodes )] ); // Remove "r" shortcode (too short)
231
-
232
- $this->shortcodes = (array) apply_filters( 'syntaxhighlighter_shortcodes', $this->shortcodes );
233
-
234
-
235
- // Register each shortcode with a placeholder callback so that strip_shortcodes() will work
236
- // The proper callback and such is done in SyntaxHighlighter::shortcode_hack()
237
- foreach ( $this->shortcodes as $shortcode )
238
- add_shortcode( $shortcode, '__return_empty_string' );
239
-
240
-
241
- // Create list of themes and their human readable names
242
- // Plugins can add to this list: http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/adding-a-new-theme/
243
- $this->themes = (array) apply_filters( 'syntaxhighlighter_themes', array(
244
- 'default' => __( 'Default', 'syntaxhighlighter' ),
245
- 'django' => __( 'Django', 'syntaxhighlighter' ),
246
- 'eclipse' => __( 'Eclipse', 'syntaxhighlighter' ),
247
- 'emacs' => __( 'Emacs', 'syntaxhighlighter' ),
248
- 'fadetogrey' => __( 'Fade to Grey', 'syntaxhighlighter' ),
249
- 'midnight' => __( 'Midnight', 'syntaxhighlighter' ),
250
- 'rdark' => __( 'RDark', 'syntaxhighlighter' ),
251
- 'none' => __( '[None]', 'syntaxhighlighter' ),
252
- ) );
253
-
254
- // Other special characters that need to be encoded before going into the database (namely to work around kses)
255
- $this->specialchars = (array) apply_filters( 'syntaxhighlighter_specialchars', array(
256
- '\0' => '&#92;&#48;',
257
- ) );
258
- }
259
-
260
-
261
- // Register the settings page
262
- function register_settings_page() {
263
- add_options_page( __( 'SyntaxHighlighter Settings', 'syntaxhighlighter' ), __( 'SyntaxHighlighter', 'syntaxhighlighter' ), 'manage_options', 'syntaxhighlighter', array( $this, 'settings_page' ) );
264
- }
265
-
266
-
267
- // Register the plugin's setting
268
- function register_setting() {
269
- register_setting( 'syntaxhighlighter_settings', 'syntaxhighlighter_settings', array( $this, 'validate_settings' ) );
270
- }
271
-
272
-
273
- // Add the custom TinyMCE plugin which wraps plugin shortcodes in <pre> in TinyMCE
274
- function add_tinymce_plugin( $plugins ) {
275
- global $tinymce_version;
276
-
277
- add_action( 'admin_print_footer_scripts', array( $this, 'output_shortcodes_for_tinymce' ), 9 );
278
-
279
- if ( substr( $tinymce_version, 0, 1 ) < 4 ) {
280
- $plugins['syntaxhighlighter'] = plugins_url( 'syntaxhighlighter_mce.js', __FILE__ );
281
- } else {
282
- $plugins['syntaxhighlighter'] = add_query_arg( 'ver', $this->pluginver, plugins_url( 'syntaxhighlighter_mce-4.js', __FILE__ ) );
283
- wp_enqueue_script( 'syntaxhighlighter', plugins_url( 'syntaxhighlighter.js', __FILE__ ), array(), false, true );
284
- }
285
-
286
- return $plugins;
287
- }
288
-
289
-
290
- // Break the TinyMCE cache
291
- function break_tinymce_cache( $version ) {
292
- return $version . '-sh' . $this->pluginver;
293
- }
294
-
295
-
296
- // Add a "Settings" link to the plugins page
297
- function settings_link( $links, $file ) {
298
- static $this_plugin;
299
-
300
- if( empty($this_plugin) )
301
- $this_plugin = plugin_basename(__FILE__);
302
-
303
- if ( $file == $this_plugin )
304
- $links[] = '<a href="' . admin_url( 'options-general.php?page=syntaxhighlighter' ) . '">' . __( 'Settings', 'syntaxhighlighter' ) . '</a>';
305
-
306
- return $links;
307
- }
308
-
309
-
310
- // Output list of shortcode tags for the TinyMCE plugin
311
- function output_shortcodes_for_tinymce() {
312
- $shortcodes = array();
313
-
314
- foreach ( $this->shortcodes as $shortcode )
315
- $shortcodes[] = preg_quote( $shortcode );
316
-
317
- echo "<script type='text/javascript'>\n";
318
- echo " var syntaxHLcodes = '" . implode( '|', $shortcodes ) . "';\n";
319
- echo "</script>\n";
320
- }
321
-
322
-
323
- /**
324
- * Process only this plugin's shortcodes.
325
- *
326
- * If we waited for the normal do_shortcode() call at priority 11,
327
- * then wpautop() and maybe others would mangle all of the code.
328
- *
329
- * So instead we hook in earlier with this function and process
330
- * just this plugins's shortcodes. To do this requires some trickery.
331
- *
332
- * First we need to clear out all existing shortcodes, then register
333
- * just this plugin's ones, process them, and then restore the original
334
- * list of shortcodes.
335
- *
336
- * To make matters more complicated, if someone has done [[code]foo[/code]]
337
- * in order to display the shortcode (not render it), then do_shortcode()
338
- * will strip the outside brackets and when do_shortcode() runs a second
339
- * time later on, it will render it.
340
- *
341
- * So instead before do_shortcode() runs for the first time, we add
342
- * even more brackets escaped shortcodes in order to result in
343
- * the shortcodes actually being displayed instead rendered.
344
- *
345
- * We only need to do this for this plugin's shortcodes however
346
- * as all other shortcodes such as [[gallery]] will be untouched
347
- * by this pass of do_shortcode.
348
- *
349
- * Phew!
350
- *
351
- * @param string $content The post content.
352
- * @param string $callback The callback function that should be used for add_shortcode()
353
- *
354
- * @return string The filtered content, with this plugin's shortcodes parsed.
355
- */
356
- function shortcode_hack( $content, $callback ) {
357
- global $shortcode_tags;
358
-
359
- // Regex is slow. Let's do some strpos() checks first.
360
- if ( ! $this->string_has_shortcodes( $content, $this->shortcodes ) ) {
361
- return $content;
362
- }
363
-
364
- // Backup current registered shortcodes and clear them all out
365
- $orig_shortcode_tags = $shortcode_tags;
366
- remove_all_shortcodes();
367
-
368
- // Register all of this plugin's shortcodes
369
- foreach ( $this->shortcodes as $shortcode ) {
370
- add_shortcode( $shortcode, $callback );
371
- }
372
-
373
- // Extra escape escaped shortcodes because do_shortcode() is going to strip a pair of square brackets when it runs
374
- $content = preg_replace_callback(
375
- '/' . get_shortcode_regex( $this->shortcodes ) . '/',
376
- array( $this, 'shortcode_hack_extra_escape_escaped_shortcodes' ),
377
- $content
378
- );
379
-
380
- // Do the shortcodes (only this plugins's are registered)
381
- $content = do_shortcode( $content, true );
382
-
383
- // Put the original shortcodes back
384
- $shortcode_tags = $orig_shortcode_tags;
385
-
386
- return $content;
387
- }
388
-
389
-
390
- /**
391
- * A quick checker to see if any of this plugin's shortcodes are in use in a string.
392
- * Since all of the tags can't be self-closing, we look for the closing tag.
393
- *
394
- * @param string $string The string to look through. This is a post's contents usually.
395
- * @param array $shortcodes The array of shortcodes to look for.
396
- *
397
- * @return bool Whether any shortcode usage was found.
398
- */
399
- function string_has_shortcodes( $string, $shortcodes ) {
400
- foreach ( $shortcodes as $shortcode ) {
401
- if ( false !== strpos( $string, "[/{$shortcode}]" ) ) {
402
- return true;
403
- }
404
- }
405
-
406
- return false;
407
- }
408
-
409
-
410
- /**
411
- * Add extra square brackets around escaped shortcodes.
412
- * This is to counteract the beginning of the do_shortcode_tag() function.
413
- *
414
- * @param array $match The array of matches generated by get_shortcode_regex()
415
- *
416
- * @return string What should be placed into the post content. In this case it's the raw match, or an extra-wrapped raw match.
417
- */
418
- function shortcode_hack_extra_escape_escaped_shortcodes( $match ) {
419
- if ( $match[1] == '[' && $match[6] == ']' ) {
420
- return '[' . $match[0] . ']';
421
- }
422
-
423
- return $match[0];
424
- }
425
-
426
-
427
- // The main filter for the post contents. The regular shortcode filter can't be used as it's post-wpautop().
428
- function parse_shortcodes( $content ) {
429
- return $this->shortcode_hack( $content, array( $this, 'shortcode_callback' ) );
430
- }
431
-
432
-
433
- // HTML entity encode the contents of shortcodes
434
- function encode_shortcode_contents( $content ) {
435
- return $this->shortcode_hack( $content, array( $this, 'encode_shortcode_contents_callback' ) );
436
- }
437
-
438
-
439
- // HTML entity encode the contents of shortcodes. Expects slashed content.
440
- function encode_shortcode_contents_slashed( $content ) {
441
- return addslashes( $this->encode_shortcode_contents( stripslashes( $content ) ) );
442
- }
443
-
444
-
445
- // HTML entity encode the contents of shortcodes. Expects slashed content. Aborts if AJAX.
446
- function encode_shortcode_contents_slashed_noquickedit( $content ) {
447
-
448
- // In certain weird circumstances, the content gets run through "content_save_pre" twice
449
- // Keep track and don't allow this filter to be run twice
450
- // I couldn't easily figure out why this happens and didn't bother looking into it further as this works fine
451
- if ( true == $this->content_save_pre_ran ) {
452
- return $content;
453
- }
454
- $this->content_save_pre_ran = true;
455
-
456
- // Post quick edits aren't decoded for display, so we don't need to encode them (again)
457
- // This also aborts for (un)trashing to avoid extra encoding.
458
- if ( empty( $_POST ) || ( ! empty( $_POST['action'] ) && 'inline-save' == $_POST['action'] ) ) {
459
- return $content;
460
- }
461
-
462
- return $this->encode_shortcode_contents_slashed( $content );
463
- }
464
-
465
-
466
- // HTML entity decode the contents of shortcodes
467
- function decode_shortcode_contents( $content ) {
468
- return $this->shortcode_hack( $content, array( $this, 'decode_shortcode_contents_callback' ) );
469
- }
470
-
471
-
472
- // The callback function for SyntaxHighlighter::encode_shortcode_contents()
473
- function encode_shortcode_contents_callback( $atts, $code = '', $tag = false ) {
474
- $this->encoded = true;
475
- $code = str_replace( array_keys($this->specialchars), array_values($this->specialchars), htmlspecialchars( $code ) );
476
- return '[' . $tag . $this->atts2string( $atts ) . "]{$code}[/$tag]";
477
- }
478
-
479
-
480
- // The callback function for SyntaxHighlighter::decode_shortcode_contents()
481
- // Shortcode attribute values need to not be quoted with TinyMCE disabled for some reason (weird bug)
482
- function decode_shortcode_contents_callback( $atts, $code = '', $tag = false ) {
483
- $quotes = ( user_can_richedit() ) ? true : false;
484
- $code = str_replace( array_values($this->specialchars), array_keys($this->specialchars), htmlspecialchars_decode( $code ) );
485
- return '[' . $tag . $this->atts2string( $atts, $quotes ) . "]{$code}[/$tag]";
486
- }
487
-
488
-
489
- // Dynamically format the post content for the edit form
490
- function the_editor_content( $content ) {
491
- global $post;
492
-
493
- // New code format (stored encoded in database)
494
- if ( 2 == $this->get_code_format( $post ) ) {
495
- // If TinyMCE is disabled or the HTML tab is set to be displayed first, we need to decode the HTML
496
- if ( !user_can_richedit() || 'html' == wp_default_editor() )
497
- $content = $this->decode_shortcode_contents( $content );
498
- }
499
-
500
- // Old code format (stored raw in database)
501
- else {
502
- // If TinyMCE is enabled and is set to be displayed first, we need to encode the HTML
503
- if ( user_can_richedit() && 'html' != wp_default_editor() )
504
- $content = $this->encode_shortcode_contents( $content );
505
- }
506
-
507
- return $content;
508
- }
509
-
510
-
511
- // Run SyntaxHighlighter::encode_shortcode_contents() on the contents of the text widget
512
- function widget_text_save( $instance, $new_instance, $old_instance, $widgetclass ) {
513
- if ( 'text' == $widgetclass->id_base ) {
514
- // Re-save the widget settings but this time with the shortcode contents encoded
515
- $new_instance['text'] = $this->encode_shortcode_contents( $new_instance['text'] );
516
- $instance = $widgetclass->update( $new_instance, $old_instance );
517
-
518
- // And flag it as encoded
519
- $instance['syntaxhighlighter_encoded'] = true;
520
- }
521
-
522
- return $instance;
523
- }
524
-
525
-
526
- // Run SyntaxHighlighter::decode_shortcode_contents_callback() on the contents of the text widget form
527
- function widget_text_form( $instance, $widgetclass ) {
528
- if ( 'text' == $widgetclass->id_base && !empty($instance['syntaxhighlighter_encoded']) ) {
529
- $instance['text'] = $this->shortcode_hack( $instance['text'], array( $this, 'decode_shortcode_contents_callback' ) );
530
- }
531
-
532
- return $instance;
533
- }
534
-
535
-
536
- // Run SyntaxHighlighter::parse_shortcodes() on the contents of a text widget
537
- function widget_text_output( $content, $instance = false ) {
538
- $this->codeformat = ( false === $instance || empty($instance['syntaxhighlighter_encoded']) ) ? 1 : 2;
539
- $content = $this->parse_shortcodes( $content );
540
- $this->codeformat = false;
541
-
542
- return $content;
543
- }
544
-
545
-
546
- // Run SyntaxHighlighter::parse_shortcodes() on the contents of a comment
547
- function parse_shortcodes_comment( $content ) {
548
- $this->codeformat = 2;
549
- $content = $this->parse_shortcodes( $content );
550
- $this->codeformat = false;
551
-
552
- return $content;
553
- }
554
-
555
-
556
- // This function determines what version of SyntaxHighlighter was used when the post was written
557
- // This is because the code was stored differently for different versions of SyntaxHighlighter
558
- function get_code_format( $post ) {
559
- if ( false !== $this->codeformat )
560
- return $this->codeformat;
561
-
562
- if ( empty($post) )
563
- $post = new stdClass();
564
-
565
- if ( null !== $version = apply_filters( 'syntaxhighlighter_pre_getcodeformat', null, $post ) )
566
- return $version;
567
-
568
- $version = ( empty($post->ID) || get_post_meta( $post->ID, '_syntaxhighlighter_encoded', true ) || get_post_meta( $post->ID, 'syntaxhighlighter_encoded', true ) ) ? 2 : 1;
569
-
570
- return apply_filters( 'syntaxhighlighter_getcodeformat', $version, $post );
571
- }
572
-
573
-
574
- // Adds a post meta saying that HTML entities are encoded (for backwards compatibility)
575
- function mark_as_encoded( $post_ID, $post ) {
576
- if ( false == $this->encoded || 'revision' == $post->post_type )
577
- return;
578
-
579
- delete_post_meta( $post_ID, 'syntaxhighlighter_encoded' ); // Previously used
580
- add_post_meta( $post_ID, '_syntaxhighlighter_encoded', true, true );
581
- }
582
-
583
-
584
- // Transforms an attributes array into a 'key="value"' format (i.e. reverses the process)
585
- function atts2string( $atts, $quotes = true ) {
586
- if ( empty($atts) )
587
- return '';
588
-
589
- $atts = $this->attributefix( $atts );
590
-
591
- // Re-map [code="php"] style tags
592
- if ( isset($atts[0]) ) {
593
- if ( empty($atts['language']) )
594
- $atts['language'] = $atts[0];
595
-
596
- unset($atts[0]);
597
- }
598
-
599
- $strings = array();
600
- foreach ( $atts as $key => $value )
601
- $strings[] = ( $quotes ) ? $key . '="' . esc_attr( $value ) . '"' : $key . '=' . esc_attr( $value );
602
-
603
- return ' ' . implode( ' ', $strings );
604
- }
605
-
606
-
607
- // Simple function for escaping just single quotes (the original js_escape() escapes more than we need)
608
- function js_escape_singlequotes( $string ) {
609
- return str_replace( "'", "\'", $string );
610
- }
611
-
612
-
613
- // Output an anchor in the header for the Javascript to use.
614
- // In the <head>, we don't know if we'll need this plugin's CSS and JavaScript yet but we will in the footer.
615
- function output_header_placeholder() {
616
- echo '<style type="text/css" id="syntaxhighlighteranchor"></style>' . "\n";
617
- }
618
-
619
-
620
- // Output any needed scripts. This is meant for the footer.
621
- function maybe_output_scripts() {
622
- global $wp_styles;
623
-
624
- if ( 1 == $this->settings['loadallbrushes'] )
625
- $this->usedbrushes = array_flip( array_values( $this->brushes ) );
626
-
627
- if ( empty($this->usedbrushes) )
628
- return;
629
-
630
- $scripts = array();
631
- foreach ( $this->usedbrushes as $brush => $unused )
632
- $scripts[] = 'syntaxhighlighter-brush-' . strtolower( $brush );
633
-
634
- wp_print_scripts( $scripts );
635
-
636
- // Stylesheets can't be in the footer, so inject them via Javascript
637
- echo "<script type='text/javascript'>\n";
638
- echo " (function(){\n";
639
- echo " var corecss = document.createElement('link');\n";
640
- echo " var themecss = document.createElement('link');\n";
641
-
642
- if ( !is_a($wp_styles, 'WP_Styles') )
643
- $wp_styles = new WP_Styles();
644
-
645
- $needcore = false;
646
- if ( 'none' == $this->settings['theme'] ) {
647
- $needcore = true;
648
- } else {
649
- $theme = ( !empty($this->themes[$this->settings['theme']]) ) ? strtolower($this->settings['theme']) : $this->defaultsettings['theme'];
650
- $theme = 'syntaxhighlighter-theme-' . $theme;
651
-
652
- // See if the requested theme has been registered
653
- if ( !empty($wp_styles) && !empty($wp_styles->registered) && !empty($wp_styles->registered[$theme]) && !empty($wp_styles->registered[$theme]->src) ) {
654
-
655
- // Users can register their own stylesheet and may opt to not load the core stylesheet if they wish for some reason
656
- if ( is_array($wp_styles->registered[$theme]->deps) && in_array( 'syntaxhighlighter-core', $wp_styles->registered[$theme]->deps ) )
657
- $needcore = true;
658
- }
659
-
660
- // Otherwise use the default theme
661
- else {
662
- $theme = 'syntaxhighlighter-theme-' . $this->defaultsettings['theme'];
663
- $needcore = true;
664
- }
665
- }
666
-
667
- if ( $needcore && !empty($wp_styles) && !empty($wp_styles->registered) && !empty($wp_styles->registered['syntaxhighlighter-core']) && !empty($wp_styles->registered['syntaxhighlighter-core']->src) ) :
668
- $corecssurl = add_query_arg( 'ver', $this->agshver, $wp_styles->registered['syntaxhighlighter-core']->src );
669
- $corecssurl = apply_filters( 'syntaxhighlighter_csscoreurl', $corecssurl );
670
- ?>
671
- var corecssurl = "<?php echo esc_js( $corecssurl ); ?>";
672
- if ( corecss.setAttribute ) {
673
- corecss.setAttribute( "rel", "stylesheet" );
674
- corecss.setAttribute( "type", "text/css" );
675
- corecss.setAttribute( "href", corecssurl );
676
- } else {
677
- corecss.rel = "stylesheet";
678
- corecss.href = corecssurl;
679
- }
680
- document.getElementsByTagName("head")[0].insertBefore( corecss, document.getElementById("syntaxhighlighteranchor") );
681
- <?php
682
- endif; // Endif $needcore
683
-
684
- if ( 'none' != $this->settings['theme'] ) : ?>
685
- var themecssurl = "<?php echo esc_js( apply_filters( 'syntaxhighlighter_cssthemeurl', add_query_arg( 'ver', $this->agshver, $wp_styles->registered[$theme]->src ) ) ); ?>";
686
- if ( themecss.setAttribute ) {
687
- themecss.setAttribute( "rel", "stylesheet" );
688
- themecss.setAttribute( "type", "text/css" );
689
- themecss.setAttribute( "href", themecssurl );
690
- } else {
691
- themecss.rel = "stylesheet";
692
- themecss.href = themecssurl;
693
- }
694
- //document.getElementById("syntaxhighlighteranchor").appendChild(themecss);
695
- document.getElementsByTagName("head")[0].insertBefore( themecss, document.getElementById("syntaxhighlighteranchor") );
696
- <?php
697
- endif; // Endif none != theme
698
-
699
- echo " })();\n";
700
-
701
- switch ( $this->settings['shversion'] ) {
702
- case 2:
703
- echo " SyntaxHighlighter.config.clipboardSwf = '" . esc_js( apply_filters( 'syntaxhighlighter_clipboardurl', plugins_url( 'syntaxhighlighter2/scripts/clipboard.swf', __FILE__ ) ) ) . "';\n";
704
- echo " SyntaxHighlighter.config.strings.expandSource = '" . $this->js_escape_singlequotes( __( 'show source', 'syntaxhighlighter' ) ) . "';\n";
705
- echo " SyntaxHighlighter.config.strings.viewSource = '" . $this->js_escape_singlequotes( __( 'view source', 'syntaxhighlighter' ) ) . "';\n";
706
- echo " SyntaxHighlighter.config.strings.copyToClipboard = '" . $this->js_escape_singlequotes( __( 'copy to clipboard', 'syntaxhighlighter' ) ) . "';\n";
707
- echo " SyntaxHighlighter.config.strings.copyToClipboardConfirmation = '" . $this->js_escape_singlequotes( __( 'The code is in your clipboard now', 'syntaxhighlighter' ) ) . "';\n";
708
- echo " SyntaxHighlighter.config.strings.print = '" . $this->js_escape_singlequotes( __( 'print', 'syntaxhighlighter' ) ) . "';\n";
709
- echo " SyntaxHighlighter.config.strings.help = '" . $this->js_escape_singlequotes( __( '?', 'syntaxhighlighter' ) ) . "';\n";
710
- echo " SyntaxHighlighter.config.strings.alert = '" . $this->js_escape_singlequotes( __( 'SyntaxHighlighter\n\n', 'syntaxhighlighter' ) ) . "';\n";
711
- echo " SyntaxHighlighter.config.strings.noBrush = '" . $this->js_escape_singlequotes( __( "Can't find brush for: ", 'syntaxhighlighter' ) ) . "';\n";
712
- echo " SyntaxHighlighter.config.strings.brushNotHtmlScript = '" . $this->js_escape_singlequotes( __( "Brush wasn't configured for html-script option: ", 'syntaxhighlighter' ) ) . "';\n";
713
- break;
714
- case 3:
715
- echo " SyntaxHighlighter.config.strings.expandSource = '" . $this->js_escape_singlequotes( __( '+ expand source', 'syntaxhighlighter' ) ) . "';\n";
716
- echo " SyntaxHighlighter.config.strings.help = '" . $this->js_escape_singlequotes( __( '?', 'syntaxhighlighter' ) ) . "';\n";
717
- echo " SyntaxHighlighter.config.strings.alert = '" . $this->js_escape_singlequotes( __( 'SyntaxHighlighter\n\n', 'syntaxhighlighter' ) ) . "';\n";
718
- echo " SyntaxHighlighter.config.strings.noBrush = '" . $this->js_escape_singlequotes( __( "Can't find brush for: ", 'syntaxhighlighter' ) ) . "';\n";
719
- echo " SyntaxHighlighter.config.strings.brushNotHtmlScript = '" . $this->js_escape_singlequotes( __( "Brush wasn't configured for html-script option: ", 'syntaxhighlighter' ) ) . "';\n";
720
- break;
721
- }
722
-
723
- if ( 1 != $this->settings['autolinks'] )
724
- echo " SyntaxHighlighter.defaults['auto-links'] = false;\n";
725
-
726
- if ( !empty($this->settings['classname']) )
727
- echo " SyntaxHighlighter.defaults['class-name'] = '" . $this->js_escape_singlequotes( $this->settings['classname'] ) . "';\n";
728
-
729
- if ( 1 == $this->settings['collapse'] )
730
- echo " SyntaxHighlighter.defaults['collapse'] = true;\n";
731
-
732
- if ( 1 != $this->settings['firstline'] )
733
- echo " SyntaxHighlighter.defaults['first-line'] = " . $this->settings['firstline'] . ";\n";
734
-
735
- if ( 1 != $this->settings['gutter'] )
736
- echo " SyntaxHighlighter.defaults['gutter'] = false;\n";
737
-
738
- /*
739
- if ( 1 == $this->settings['htmlscript'] )
740
- echo " SyntaxHighlighter.defaults['html-script'] = true;\n";
741
- */
742
-
743
- if ( 1 == $this->settings['light'] )
744
- echo " SyntaxHighlighter.defaults['light'] = true;\n";
745
-
746
- echo " SyntaxHighlighter.defaults['pad-line-numbers'] = ";
747
- switch ( $this->settings['padlinenumbers'] ) {
748
- case 'true':
749
- echo 'true';
750
- break;
751
- case 'false';
752
- echo 'false';
753
- break;
754
- default;
755
- echo (int) $this->settings['padlinenumbers'];
756
- }
757
- echo ";\n";
758
-
759
- if ( 1 != $this->settings['smarttabs'] )
760
- echo " SyntaxHighlighter.defaults['smart-tabs'] = false;\n";
761
-
762
- if ( 4 != $this->settings['tabsize'] )
763
- echo " SyntaxHighlighter.defaults['tab-size'] = " . $this->settings['tabsize'] . ";\n";
764
-
765
- if ( 1 != $this->settings['toolbar'] )
766
- echo " SyntaxHighlighter.defaults['toolbar'] = false;\n";
767
-
768
- // 2.x only for now
769
- if ( 1 != $this->settings['wraplines'] )
770
- echo " SyntaxHighlighter.defaults['wrap-lines'] = false;\n";
771
-
772
- ?> SyntaxHighlighter.all();
773
- </script>
774
- <?php
775
- }
776
-
777
-
778
- // No-name attribute fixing
779
- function attributefix( $atts = array() ) {
780
- if ( empty($atts[0]) )
781
- return $atts;
782
-
783
- // Quoted value
784
- if ( 0 !== preg_match( '#=("|\')(.*?)\1#', $atts[0], $match ) )
785
- $atts[0] = $match[2];
786
-
787
- // Unquoted value
788
- elseif ( '=' == substr( $atts[0], 0, 1 ) )
789
- $atts[0] = substr( $atts[0], 1 );
790
-
791
- return $atts;
792
- }
793
-
794
-
795
- // Shortcode handler for transforming the shortcodes to their final <pre>'s
796
- function shortcode_callback( $atts, $code = '', $tag = false ) {
797
- global $post;
798
-
799
- if ( false === $tag || empty($code) )
800
- return $code;
801
-
802
- // Avoid PHP notices
803
- if ( !isset($post) )
804
- $post = null;
805
-
806
- $code = apply_filters( 'syntaxhighlighter_precode', $code, $atts, $tag );
807
-
808
- // Error fixing for [tag="language"]
809
- if ( isset($atts[0]) ) {
810
- $atts = $this->attributefix( $atts );
811
- $atts['language'] = $atts[0];
812
- unset($atts[0]);
813
- }
814
-
815
- // Default out all of the available parameters to "false" (easy way to check if they're set or not)
816
- // Note this isn't the same as if the user passes the string "false" to the shortcode
817
- $atts = (array) apply_filters( 'syntaxhighlighter_shortcodeatts', shortcode_atts( array(
818
- 'language' => false,
819
- 'lang' => false,
820
- 'type' => false, // language alias
821
- 'autolinks' => false,
822
- 'classname' => false,
823
- 'collapse' => false,
824
- 'firstline' => false,
825
- 'fontsize' => false,
826
- 'gutter' => false,
827
- 'highlight' => false,
828
- 'htmlscript' => false,
829
- 'light' => false,
830
- 'padlinenumbers' => false,
831
- 'smarttabs' => false,
832
- 'tabsize' => false,
833
- 'title' => $this->settings['title'],
834
- 'toolbar' => false,
835
- 'wraplines' => false,
836
- ), $atts ) );
837
-
838
- // Check for language shortcode tag such as [php]code[/php]
839
- if ( isset($this->brushes[$tag]) ) {
840
- $lang = $tag;
841
- }
842
-
843
- // If a valid tag is not used, it must be sourcecode/source/code
844
- else {
845
- $atts = $this->attributefix( $atts );
846
-
847
- // Check for the "language" attribute
848
- if ( false !== $atts['language'] )
849
- $lang = $atts['language'];
850
-
851
- // Check for the "lang" attribute
852
- elseif ( false !== $atts['lang'] )
853
- $lang = $atts['lang'];
854
-
855
- // Default to plain text
856
- else
857
- $lang = 'text';
858
-
859
- // All language aliases are lowercase
860
- $lang = strtolower( $lang );
861
-
862
- // Validate passed attribute
863
- if ( !isset($this->brushes[$lang]) )
864
- return $code;
865
- }
866
-
867
- // Switch from the alias to the real brush name (so custom aliases can be used)
868
- $lang = $this->brushes[$lang];
869
-
870
- // Register this brush as used so it's script will be outputted
871
- $this->usedbrushes[$lang] = true;
872
-
873
- $params = array();
874
- $params[] = "brush: $lang;";
875
-
876
- // Fix bug that prevents collapse from working if the toolbar is off or light mode is on
877
- if ( 'true' == $atts['collapse'] || '1' === $atts['collapse'] || 1 == $this->settings['collapse'] ) {
878
- $atts['toolbar'] = 'true';
879
- $atts['light'] = 'false';
880
- }
881
-
882
- // Parameter renaming (the shortcode API doesn't like parameter names with dashes)
883
- $rename_map = array(
884
- 'autolinks' => 'auto-links',
885
- 'classname' => 'class-name',
886
- 'firstline' => 'first-line',
887
- 'fontsize' => 'font-size',
888
- 'htmlscript' => 'html-script',
889
- 'padlinenumbers' => 'pad-line-numbers',
890
- 'smarttabs' => 'smart-tabs',
891
- 'tabsize' => 'tab-size',
892
- 'wraplines' => 'wrap-lines',
893
- );
894
-
895
- // Allowed configuration parameters and their type
896
- // Use the proper names (see above)
897
- $allowed_atts = (array) apply_filters( 'syntaxhighlighter_allowedatts', array(
898
- 'auto-links' => 'boolean',
899
- 'class-name' => 'other',
900
- 'collapse' => 'boolean',
901
- 'first-line' => 'integer',
902
- 'font-size' => 'integer',
903
- 'gutter' => 'boolean',
904
- 'highlight' => 'other',
905
- 'html-script' => 'boolean',
906
- 'light' => 'boolean',
907
- 'pad-line-numbers' => 'other',
908
- 'smart-tabs' => 'boolean',
909
- 'tab-size' => 'integer',
910
- 'title' => 'other',
911
- 'toolbar' => 'boolean',
912
- 'wrap-lines' => 'boolean',
913
- ) );
914
-
915
- $title = '';
916
-
917
- // Sanitize configuration parameters and such
918
- foreach ( $atts as $key => $value ) {
919
- $key = strtolower( $key );
920
-
921
- // Put back parameter names that have been renamed for shortcode use
922
- if ( !empty($rename_map[$key]) )
923
- $key = $rename_map[$key];
924
-
925
- // This this parameter if it's unknown, not set, or the language which was already handled
926
- if ( empty($allowed_atts[$key]) || false === $value || in_array( $key, array( 'language', 'lang' ) ) )
927
- continue;
928
-
929
- // Sanitize values
930
- switch ( $allowed_atts[$key] ) {
931
- case 'boolean':
932
- $value = strtolower( $value );
933
- if ( 'true' === $value || '1' === $value || 'on' == $value )
934
- $value = 'true';
935
- elseif ( 'false' === $value || '0' === $value || 'off' == $value )
936
- $value = 'false';
937
- else
938
- continue 2; // Invalid value, ditch parameter
939
- break;
940
-
941
- // integer
942
- case 'integer':
943
- $value = (int) $value;
944
- break;
945
- }
946
-
947
- // Sanitize the "classname" parameter
948
- if ( 'class-name' == $key )
949
- $value = trim( preg_replace( '/[^a-zA-Z0-9 _-]/i', '', $value ) );
950
-
951
- // Special sanitization for "pad-line-numbers"
952
- if ( 'pad-line-numbers' == $key ) {
953
- $value = strtolower( $value );
954
- if ( 'true' === $value || '1' === $value )
955
- $value = 'true';
956
- elseif ( 'false' === $value || '0' === $value )
957
- $value = 'false';
958
- else
959
- $value = (int) $value;
960
- }
961
-
962
- // Add % sign to "font-size"
963
- if ( 'font-size' == $key )
964
- $value = $value . '%';
965
-
966
- // If "html-script", then include the XML brush as it's needed
967
- if ( 'html-script' == $key && 'true' == $value )
968
- $this->usedbrushes['xml'] = true;
969
-
970
- // Sanitize row highlights
971
- if ( 'highlight' == $key ) {
972
- if ( false === strpos( $value, ',' ) && false === strpos( $value, '-' ) ) {
973
- $value = (int) $value;
974
- } else {
975
- $lines = explode( ',', $value );
976
- $highlights = array();
977
-
978
- foreach ( $lines as $line ) {
979
- // Line range
980
- if ( false !== strpos( $line, '-' ) ) {
981
- list( $range_start, $range_end ) = array_map( 'intval', explode( '-', $line ) );
982
- if ( ! $range_start || ! $range_end || $range_end <= $range_start )
983
- continue;
984
-
985
- for ( $i = $range_start; $i <= $range_end; $i++ )
986
- $highlights[] = $i;
987
- } else {
988
- $highlights[] = (int) $line;
989
- }
990
- }
991
-
992
- natsort( $highlights );
993
-
994
- $value = implode( ',', $highlights );
995
- }
996
-
997
- if ( empty( $value ) )
998
- continue;
999
-
1000
- // Wrap highlight in [ ]
1001
- $params[] = "$key: [$value];";
1002
- continue;
1003
- }
1004
-
1005
- // Don't allow HTML in the title parameter
1006
- if ( 'title' == $key ) {
1007
- $value = strip_tags( html_entity_decode( strip_tags( $value ) ) );
1008
- }
1009
-
1010
- $params[] = "$key: $value;";
1011
-
1012
- // Set the title variable if the title parameter is set (but not for feeds)
1013
- if ( 'title' == $key && ! is_feed() )
1014
- $title = ' title="' . esc_attr( $value ) . '"';
1015
- }
1016
-
1017
- $code = ( false === strpos( $code, '<' ) && false === strpos( $code, '>' ) && 2 == $this->get_code_format($post) ) ? strip_tags( $code ) : htmlspecialchars( $code );
1018
-
1019
- $params[] = 'notranslate'; // For Google, see http://otto42.com/9k
1020
-
1021
- $params = apply_filters( 'syntaxhighlighter_cssclasses', $params ); // Use this to add additional CSS classes / SH parameters
1022
-
1023
- return apply_filters( 'syntaxhighlighter_htmlresult', '<pre class="' . esc_attr( implode( ' ', $params ) ) . '"' . $title . '>' . $code . '</pre>' );;
1024
- }
1025
-
1026
-
1027
- // Settings page
1028
- function settings_page() { ?>
1029
-
1030
- <script type="text/javascript">
1031
- // <![CDATA[
1032
- jQuery(document).ready(function($) {
1033
- // Confirm pressing of the "Reset to Defaults" button
1034
- $("#syntaxhighlighter-defaults").click(function(){
1035
- var areyousure = confirm("<?php echo esc_js( __( 'Are you sure you want to reset your settings to the defaults?', 'syntaxhighlighter' ) ); ?>");
1036
- if ( true != areyousure ) return false;
1037
- });
1038
- <?php if ( !empty( $_GET['defaults'] ) ) : ?>
1039
- $("#message p strong").text("<?php echo esc_js( __( 'Settings reset to defaults.', 'syntaxhighlighter' ) ); ?>");
1040
- <?php endif; ?>
1041
- });
1042
- // ]]>
1043
- </script>
1044
-
1045
- <div class="wrap">
1046
- <?php if ( function_exists('screen_icon') ) screen_icon(); ?>
1047
- <h2><?php _e( 'SyntaxHighlighter Settings', 'syntaxhighlighter' ); ?></h2>
1048
-
1049
- <form method="post" action="options.php">
1050
-
1051
- <?php settings_fields('syntaxhighlighter_settings'); ?>
1052
-
1053
-
1054
- <table class="form-table">
1055
- <tr valign="top">
1056
- <th scope="row"><label for="syntaxhighlighter-shversion"><?php _e( 'Highlighter Version', 'syntaxhighlighter' ); ?></label></th>
1057
- <td>
1058
- <select name="syntaxhighlighter_settings[shversion]" id="syntaxhighlighter-shversion" class="postform">
1059
- <?php
1060
- $versions = array(
1061
- 3 => __( 'Version 3.x', 'syntaxhighlighter' ),
1062
- 2 => __( 'Version 2.x', 'syntaxhighlighter' ),
1063
- );
1064
-
1065
- foreach ( $versions as $version => $name ) {
1066
- echo ' <option value="' . esc_attr( $version ) . '"' . selected( $this->settings['shversion'], $version, false ) . '>' . esc_html( $name ) . "&nbsp;</option>\n";
1067
- }
1068
- ?>
1069
- </select><br />
1070
- <?php _e( 'Version 3 allows visitors to easily highlight portions of your code with their mouse (either by dragging or double-clicking) and copy it to their clipboard. No toolbar containing a Flash-based button is required.', 'syntaxhighlighter' ); ?><br />
1071
- <?php _e( 'Version 2 allows for line wrapping, something that version 3 does not do at this time.', 'syntaxhighlighter' ); ?>
1072
- </td>
1073
- </tr>
1074
- <tr valign="top">
1075
- <th scope="row"><label for="syntaxhighlighter-theme"><?php _e( 'Color Theme', 'syntaxhighlighter' ); ?></label></th>
1076
- <td>
1077
- <select name="syntaxhighlighter_settings[theme]" id="syntaxhighlighter-theme" class="postform">
1078
- <?php
1079
- foreach ( $this->themes as $theme => $name ) {
1080
- echo ' <option value="' . esc_attr( $theme ) . '"' . selected( $this->settings['theme'], $theme, false ) . '>' . esc_html( $name ) . "&nbsp;</option>\n";
1081
- }
1082
- ?>
1083
- </select>
1084
- </td>
1085
- </tr>
1086
- <tr valign="top">
1087
- <th scope="row"><?php _e( 'Load All Brushes', 'syntaxhighlighter' ); ?></th>
1088
- <td>
1089
- <fieldset>
1090
- <legend class="hidden"><?php _e( 'Load All Brushes', 'syntaxhighlighter' ); ?></legend>
1091
- <label for="syntaxhighlighter-loadallbrushes"><input name="syntaxhighlighter_settings[loadallbrushes]" type="checkbox" id="syntaxhighlighter-loadallbrushes" value="1" <?php checked( $this->settings['loadallbrushes'], 1 ); ?> /> <?php _e( 'Always load all language files (for directly using <code>&lt;pre&gt;</code> tags rather than shortcodes)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If left unchecked (default), then language files will only be loaded when needed<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If unsure, leave this box unchecked', 'syntaxhighlighter' ); ?></label>
1092
- </fieldset>
1093
- </td>
1094
- </tr>
1095
- </table>
1096
-
1097
- <h3><?php _e( 'Defaults', 'syntaxhighlighter' ); ?></h3>
1098
-
1099
- <p><?php _e( 'All of the settings below can be configured on a per-code block basis, but you can control the defaults of all code blocks here.', 'syntaxhighlighter' ); ?></p>
1100
-
1101
- <table class="form-table">
1102
- <tr valign="top">
1103
- <th scope="row"><?php _e( 'Miscellaneous', 'syntaxhighlighter' ); ?></th>
1104
- <td>
1105
- <fieldset>
1106
- <legend class="hidden"><?php _e( 'Miscellaneous', 'syntaxhighlighter' ); ?></legend>
1107
-
1108
- <label for="syntaxhighlighter-gutter"><input name="syntaxhighlighter_settings[gutter]" type="checkbox" id="syntaxhighlighter-gutter" value="1" <?php checked( $this->settings['gutter'], 1 ); ?> /> <?php _e( 'Display line numbers', 'syntaxhighlighter' ); ?></label><br />
1109
- <label for="syntaxhighlighter-toolbar"><input name="syntaxhighlighter_settings[toolbar]" type="checkbox" id="syntaxhighlighter-toolbar" value="1" <?php checked( $this->settings['toolbar'], 1 ); ?> /> <?php _e( 'Display the toolbar', 'syntaxhighlighter' ); ?></label><br />
1110
- <label for="syntaxhighlighter-autolinks"><input name="syntaxhighlighter_settings[autolinks]" type="checkbox" id="syntaxhighlighter-autolinks" value="1" <?php checked( $this->settings['autolinks'], 1 ); ?> /> <?php _e( 'Automatically make URLs clickable', 'syntaxhighlighter' ); ?></label><br />
1111
- <label for="syntaxhighlighter-collapse"><input name="syntaxhighlighter_settings[collapse]" type="checkbox" id="syntaxhighlighter-collapse" value="1" <?php checked( $this->settings['collapse'], 1 ); ?> /> <?php _e( 'Collapse code boxes', 'syntaxhighlighter' ); ?></label><br />
1112
- <label for="syntaxhighlighter-light"><input name="syntaxhighlighter_settings[light]" type="checkbox" id="syntaxhighlighter-light" value="1" <?php checked( $this->settings['light'], 1 ); ?> /> <?php _e( 'Use the light display mode, best for single lines of code', 'syntaxhighlighter' ); ?></label><br />
1113
- <label for="syntaxhighlighter-smarttabs"><input name="syntaxhighlighter_settings[smarttabs]" type="checkbox" id="syntaxhighlighter-smarttabs" value="1" <?php checked( $this->settings['smarttabs'], 1 ); ?> /> <?php _e( 'Use smart tabs allowing tabs being used for alignment', 'syntaxhighlighter' ); ?></label><br />
1114
- <label for="syntaxhighlighter-wraplines"><input name="syntaxhighlighter_settings[wraplines]" type="checkbox" id="syntaxhighlighter-wraplines" value="1" <?php checked( $this->settings['wraplines'], 1 ); ?> /> <?php _e( 'Wrap long lines (v2.x only, disabling this will make a scrollbar show instead)', 'syntaxhighlighter' ); ?></label><br />
1115
- <!--<label for="syntaxhighlighter-htmlscript"><input name="syntaxhighlighter_settings[htmlscript]" type="checkbox" id="syntaxhighlighter-htmlscript" value="1" <?php checked( $this->settings['htmlscript'], 1 ); ?> /> <?php _e( 'Enable &quot;HTML script&quot; mode by default (see the bottom of this page for details). Checking this box is not recommended as this mode only works with certain languages.', 'syntaxhighlighter' ); ?></label>-->
1116
- </fieldset>
1117
- </td>
1118
- </tr>
1119
- <tr valign="top">
1120
- <th scope="row"><label for="syntaxhighlighter-classname"><?php _e( 'Additional CSS Class(es)', 'syntaxhighlighter' ); ?></label></th>
1121
- <td><input name="syntaxhighlighter_settings[classname]" type="text" id="syntaxhighlighter-classname" value="<?php echo esc_attr( $this->settings['classname'] ); ?>" class="regular-text" /></td>
1122
- </tr>
1123
- <tr valign="top">
1124
- <th scope="row"><label for="syntaxhighlighter-firstline"><?php _e( 'Starting Line Number', 'syntaxhighlighter' ); ?></label></th>
1125
- <td><input name="syntaxhighlighter_settings[firstline]" type="text" id="syntaxhighlighter-firstline" value="<?php echo esc_attr( $this->settings['firstline'] ); ?>" class="small-text" /></td>
1126
- </tr>
1127
- <tr valign="top">
1128
- <th scope="row"><label for="syntaxhighlighter-padlinenumbers"><?php _e( 'Line Number Padding', 'syntaxhighlighter' ); ?></label></th>
1129
- <td>
1130
- <select name="syntaxhighlighter_settings[padlinenumbers]" id="syntaxhighlighter-padlinenumbers" class="postform">
1131
- <?php
1132
- $linepaddings = array(
1133
- 'false' => __( 'Off', 'syntaxhighlighter' ),
1134
- 'true' => __( 'Automatic', 'syntaxhighlighter' ),
1135
- 1 => 1,
1136
- 2 => 2,
1137
- 3 => 3,
1138
- 4 => 4,
1139
- 5 => 5,
1140
- );
1141
-
1142
- foreach ( $linepaddings as $value => $name ) {
1143
- echo ' <option value="' . esc_attr( $value ) . '"' . selected( $this->settings['padlinenumbers'], $value, false ) . '>' . esc_html( $name ) . "&nbsp;</option>\n";
1144
- }
1145
- ?>
1146
- </select>
1147
- </td>
1148
- </tr>
1149
- <tr valign="top">
1150
- <th scope="row"><label for="syntaxhighlighter-tabsize"><?php _e( 'Tab Size', 'syntaxhighlighter' ); ?></label></th>
1151
- <td><input name="syntaxhighlighter_settings[tabsize]" type="text" id="syntaxhighlighter-tabsize" value="<?php echo esc_attr( $this->settings['tabsize'] ); ?>" class="small-text" /></td>
1152
- </tr>
1153
- <tr valign="top">
1154
- <th scope="row"><label for="syntaxhighlighter-title"><?php _e( 'Title', 'syntaxhighlighter' ); ?></label></th>
1155
- <td>
1156
- <input name="syntaxhighlighter_settings[title]" type="text" id="syntaxhighlighter-title" value="<?php echo esc_attr( $this->settings['title'] ); ?>" class="regular-text" /><br />
1157
- <?php _e( 'Some optional default text to display above each code block or as the clickable text for collapsed code blocks.', 'syntaxhighlighter' ); ?>
1158
- </td>
1159
- </tr>
1160
- </table>
1161
-
1162
- <p class="submit">
1163
- <?php
1164
- if ( function_exists( 'submit_button' ) ) {
1165
- submit_button( null, 'primary', 'syntaxhighlighter-submit', false );
1166
- echo ' ';
1167
- submit_button( __( 'Reset to Defaults', 'syntaxhighlighter' ), 'primary', 'syntaxhighlighter-defaults', false );
1168
- } else {
1169
- echo '<input type="submit" name="syntaxhighlighter-submit" class="button-primary" value="' . __( 'Save Changes') . '" />' . "\n";
1170
- echo '<input type="submit" name="syntaxhighlighter-defaults" id="syntaxhighlighter-defaults" class="button-primary" value="' . __( 'Reset to Defaults', 'syntaxhighlighter' ) . '" />' . "\n";
1171
- }
1172
- ?>
1173
- </p>
1174
-
1175
- </form>
1176
-
1177
- <h3><?php _e( 'Preview', 'syntaxhighlighter' ); ?></h3>
1178
-
1179
- <p><?php _e( 'Click &quot;Save Changes&quot; to update this preview.', 'syntaxhighlighter' ); ?>
1180
-
1181
- <?php
1182
-
1183
- echo '<div';
1184
- if ( ! empty( $GLOBALS['content_width'] ) )
1185
- echo ' style="max-width:' . intval( $GLOBALS['content_width'] ) . 'px"';
1186
- echo '>';
1187
-
1188
- $title = ( empty( $this->settings['title'] ) && 1 != $this->settings['collapse'] ) ? ' title="Code example: (this example was added using the title parameter)"' : '';
1189
-
1190
- // Site owners may opt to disable the short tags, i.e. [php]
1191
- $democode = apply_filters( 'syntaxhighlighter_democode', '[sourcecode language="php" htmlscript="true" highlight="12"' . $title . ']<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1192
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
1193
- <head>
1194
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
1195
- <title>PHP Code Example</title>
1196
- </head>
1197
- <body>
1198
- <h1>' . __( 'PHP Code Example', 'syntaxhighlighter' ) . '</h1>
1199
-
1200
- <p><?php echo \'' . __( 'Hello World!', 'syntaxhighlighter' ) . '\'; ?></p>
1201
-
1202
- <p>' . __( 'This line is highlighted.', 'syntaxhighlighter' ) . '</p>
1203
-
1204
- <div class="foobar">
1205
- ' . __( ' This is an
1206
- example of smart
1207
- tabs.', 'syntaxhighlighter' ) . '
1208
- </div>
1209
-
1210
- <p><a href="http://wordpress.org/">' . __( 'WordPress' ) . '</a></p>
1211
- </body>
1212
- </html>[/sourcecode]' );
1213
-
1214
- $this->codeformat = 1;
1215
- echo $this->parse_shortcodes( $democode );
1216
- $this->codeformat = false;
1217
-
1218
- echo '</div>';
1219
- ?>
1220
-
1221
- <h3 style="margin-top:30px"><?php _e( 'Shortcode Parameters', 'syntaxhighlighter' ); ?></h3>
1222
-
1223
- <p><?php printf( __( 'These are the parameters you can pass to the shortcode and what they do. For the booleans (i.e. on/off), pass %1$s/%2$s or %3$s/%4$s.', 'syntaxhighlighter' ), '<code>true</code>', '<code>1</code>', '<code>false</code>', '<code>0</code>' ); ?></p>
1224
-
1225
- <ul class="ul-disc">
1226
- <li><?php printf( _x( '%1$s or %2$s &#8212; The language syntax to highlight with. You can alternately just use that as the tag, such as <code>[php]code[/php]</code>. <a href="%3$s">Click here</a> for a list of valid tags (under &quot;aliases&quot;).', 'language parameter', 'syntaxhighlighter' ), '<code>lang</code>', '<code>language</code>', 'http://alexgorbatchev.com/wiki/SyntaxHighlighter:Brushes' ); ?></li>
1227
- <li><?php printf( _x( '%s &#8212; Toggle automatic URL linking.', 'autolinks parameter', 'syntaxhighlighter' ), '<code>autolinks</code>' ); ?></li>
1228
- <li><?php printf( _x( '%s &#8212; Add an additional CSS class to the code box.', 'classname parameter', 'syntaxhighlighter' ), '<code>classname</code>' ); ?></li>
1229
- <li><?php printf( _x( '%s &#8212; Toggle collapsing the code box by default, requiring a click to expand it. Good for large code posts.', 'collapse parameter', 'syntaxhighlighter' ), '<code>collapse</code>' ); ?></li>
1230
- <li><?php printf( _x( '%s &#8212; An interger specifying what number the first line should be (for the line numbering).', 'firstline parameter', 'syntaxhighlighter' ), '<code>firstline</code>' ); ?></li>
1231
- <li><?php printf( _x( '%s &#8212; Toggle the left-side line numbering.', 'gutter parameter', 'syntaxhighlighter' ), '<code>gutter</code>' ); ?></li>
1232
- <li><?php printf( _x( '%1$s &#8212; A comma-separated list of line numbers to highlight. You can also specify a range. Example: %2$s', 'highlight parameter', 'syntaxhighlighter' ), '<code>highlight</code>', '<code>2,5-10,12</code>' ); ?></li>
1233
- <li><?php printf( _x( "%s &#8212; Toggle highlighting any extra HTML/XML. Good for when you're mixing HTML/XML with another language, such as having PHP inside an HTML web page. The above preview has it enabled for example. This only works with certain languages.", 'htmlscript parameter', 'syntaxhighlighter' ), '<code>htmlscript</code>' ); ?></li>
1234
- <li><?php printf( _x( '%s &#8212; Toggle light mode which disables the gutter and toolbar all at once.', 'light parameter', 'syntaxhighlighter' ), '<code>light</code>' ); ?></li>
1235
- <li><?php printf( _x( '%s &#8212; Controls line number padding. Valid values are <code>false</code> (no padding), <code>true</code> (automatic padding), or an integer (forced padding).', 'padlinenumbers parameter', 'syntaxhighlighter' ), '<code>padlinenumbers</code>' ); ?></li>
1236
- <li><?php printf( _x( '%1$s (v3 only) &#8212; Sets some text to show up before the code. Very useful when combined with the %2$s parameter.', 'title parameter', 'syntaxhighlighter' ), '<code>title</code>', '<code>collapse</code>' ); ?></li>
1237
- <li><?php printf( _x( '%s &#8212; Toggle the toolbar (buttons in v2, the about question mark in v3)', 'toolbar parameter', 'syntaxhighlighter' ), '<code>toolbar</code>' ); ?></li>
1238
- <li><?php printf( _x( '%s (v2 only) &#8212; Toggle line wrapping.', 'wraplines parameter', 'syntaxhighlighter'), '<code>wraplines</code>' ); ?></li>
1239
- </ul>
1240
-
1241
- <p><?php _e( 'Some example shortcodes:', 'syntaxhighlighter' ); ?></p>
1242
-
1243
- <ul class="ul-disc">
1244
- <li><code>[php]<?php _e( 'your code here', 'syntaxhighlighter' ); ?>[/php]</code></li>
1245
- <li><code>[css autolinks=&quot;false&quot; classname=&quot;myclass&quot; collapse=&quot;false&quot; firstline=&quot;1&quot; gutter=&quot;true&quot; highlight=&quot;1-3,6,9&quot; htmlscript=&quot;false&quot; light=&quot;false&quot; padlinenumbers=&quot;false&quot; smarttabs=&quot;true&quot; tabsize=&quot;4&quot; toolbar=&quot;true&quot; title=&quot;<?php _e( 'example-filename.php', 'syntaxhighlighter' ); ?>&quot;]<?php _e( 'your code here', 'syntaxhighlighter' ); ?>[/css]</code></li>
1246
- <li><code>[code lang=&quot;js&quot;]<?php _e( 'your code here', 'syntaxhighlighter' ); ?>[/code]</code></li>
1247
- <li><code>[sourcecode language=&quot;plain&quot;]<?php _e( 'your code here', 'syntaxhighlighter' ); ?>[/sourcecode]</code></li>
1248
- </ul>
1249
-
1250
- <?php $this->maybe_output_scripts(); ?>
1251
-
1252
- </div>
1253
-
1254
- <?php
1255
- }
1256
-
1257
-
1258
- // Validate the settings sent from the settings page
1259
- function validate_settings( $settings ) {
1260
- if ( !empty($_POST['syntaxhighlighter-defaults']) ) {
1261
- $settings = $this->defaultsettings;
1262
- $_REQUEST['_wp_http_referer'] = add_query_arg( 'defaults', 'true', $_REQUEST['_wp_http_referer'] );
1263
- } else {
1264
- $settings['shversion'] = ( ! empty($settings['shversion']) && 2 == $settings['shversion'] ) ? 2 : 3;
1265
-
1266
- $settings['theme'] = ( ! empty($settings['theme']) && isset($this->themes[$settings['theme']]) ) ? strtolower($settings['theme']) : $this->defaultsettings['theme'];
1267
-
1268
- $settings['loadallbrushes'] = ( ! empty($settings['loadallbrushes']) ) ? 1 : 0;
1269
- $settings['autolinks'] = ( ! empty($settings['autolinks']) ) ? 1 : 0;
1270
- $settings['collapse'] = ( ! empty($settings['collapse']) ) ? 1 : 0;
1271
- $settings['gutter'] = ( ! empty($settings['gutter']) ) ? 1 : 0;
1272
- $settings['light'] = ( ! empty($settings['light']) ) ? 1 : 0;
1273
- $settings['smarttabs'] = ( ! empty($settings['smarttabs']) ) ? 1 : 0;
1274
- $settings['toolbar'] = ( ! empty($settings['toolbar']) ) ? 1 : 0; // May be overridden below
1275
- $settings['wraplines'] = ( ! empty($settings['wraplines']) ) ? 1 : 0; // 2.x only for now
1276
-
1277
- // If the version changed, then force change the toolbar version setting
1278
- if ( $settings['shversion'] != $this->settings['shversion'] ) {
1279
- $settings['toolbar'] = ( 2 == $settings['shversion'] ) ? 1 : 0;
1280
- }
1281
-
1282
- if ( 'true' != $settings['padlinenumbers'] && 'false' != $settings['padlinenumbers'] )
1283
- $settings['padlinenumbers'] = (int) $settings['padlinenumbers'];
1284
-
1285
- $settings['classname'] = ( !empty($settings['classname']) ) ? preg_replace( '/[^ A-Za-z0-9_-]*/', '', $settings['classname'] ) : '';
1286
- $settings['firstline'] = (int) ( ( !empty($settings['firstline']) ) ? $settings['firstline'] : $this->defaultsettings['firstline'] );
1287
- $settings['tabsize'] = (int) ( ( !empty($settings['tabsize']) ) ? $settings['tabsize'] : $this->defaultsettings['tabsize'] );
1288
- }
1289
-
1290
- return $settings;
1291
- }
1292
- }
1293
-
1294
-
1295
- // Start this plugin once all other plugins are fully loaded
1296
- add_action( 'init', 'SyntaxHighlighter', 5 );
1297
- function SyntaxHighlighter() {
1298
- global $SyntaxHighlighter;
1299
- $SyntaxHighlighter = new SyntaxHighlighter();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1300
  }
1
+ <?php /*
2
+
3
+ **************************************************************************
4
+
5
+ Plugin Name: SyntaxHighlighter Evolved
6
+ Plugin URI: http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/
7
+ Version: 3.2.1
8
+ Description: Easily post syntax-highlighted code to your site without having to modify the code at all. Uses Alex Gorbatchev's <a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter">SyntaxHighlighter</a>. <strong>TIP:</strong> Don't use the Visual editor if you don't want your code mangled. TinyMCE will "clean up" your HTML.
9
+ Author: Alex Mills (Viper007Bond)
10
+ Author URI: http://www.viper007bond.com/
11
+
12
+ **************************************************************************
13
+
14
+ Thanks to:
15
+
16
+ * Alex Gorbatchev for writing the Javascript-powered syntax highlighter script
17
+
18
+ * Andrew Ozz for writing the TinyMCE plugin
19
+
20
+ **************************************************************************/
21
+
22
+ class SyntaxHighlighter {
23
+ // All of these variables are private. Filters are provided for things that can be modified.
24
+ var $pluginver = '3.2.1'; // Plugin version
25
+ var $agshver = false; // Alex Gorbatchev's SyntaxHighlighter version (dynamically set below due to v2 vs v3)
26
+ var $shfolder = false; // Controls what subfolder to load SyntaxHighlighter from (v2 or v3)
27
+ var $settings = array(); // Contains the user's settings
28
+ var $defaultsettings = array(); // Contains the default settings
29
+ var $brushes = array(); // Array of aliases => brushes
30
+ var $shortcodes = array(); // Array of shortcodes to use
31
+ var $themes = array(); // Array of themes
32
+ var $usedbrushes = array(); // Stores used brushes so we know what to output
33
+ var $encoded = false; // Used to mark that a character encode took place
34
+ var $codeformat = false; // If set, SyntaxHighlighter::get_code_format() will return this value
35
+ var $content_save_pre_ran = false; // It's possible for the "content_save_pre" filter to run multiple times, so keep track
36
+
37
+ // Initalize the plugin by registering the hooks
38
+ function __construct() {
39
+ if ( ! function_exists( 'do_shortcodes_in_html_tags' ) )
40
+ return;
41
+
42
+ // Load localization domain
43
+ load_plugin_textdomain( 'syntaxhighlighter', false, '/syntaxhighlighter/localization' );
44
+
45
+ // Display hooks
46
+ add_filter( 'the_content', array( $this, 'parse_shortcodes' ), 7 ); // Posts
47
+ add_filter( 'comment_text', array( $this, 'parse_shortcodes_comment' ), 7 ); // Comments
48
+ add_filter( 'bp_get_the_topic_post_content', array( $this, 'parse_shortcodes' ), 7 ); // BuddyPress
49
+
50
+ // Into the database
51
+ add_filter( 'content_save_pre', array( $this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // Posts
52
+ add_filter( 'pre_comment_content', array( $this, 'encode_shortcode_contents_slashed' ), 1 ); // Comments
53
+ add_filter( 'group_forum_post_text_before_save', array( $this, 'encode_shortcode_contents_slashed' ), 1 ); // BuddyPress
54
+ add_filter( 'group_forum_topic_text_before_save', array( $this, 'encode_shortcode_contents_slashed' ), 1 ); // BuddyPress
55
+
56
+ // Out of the database for editing
57
+ add_filter( 'the_editor_content', array( $this, 'the_editor_content' ), 1 ); // Posts
58
+ add_filter( 'comment_edit_pre', array( $this, 'decode_shortcode_contents' ), 1 ); // Comments
59
+ add_filter( 'bp_get_the_topic_text', array( $this, 'decode_shortcode_contents' ), 1 ); // BuddyPress
60
+ add_filter( 'bp_get_the_topic_post_edit_text', array( $this, 'decode_shortcode_contents' ), 1 ); // BuddyPress
61
+
62
+ // Outputting SyntaxHighlighter's JS and CSS
63
+ add_action( 'wp_head', array( $this, 'output_header_placeholder' ), 15 );
64
+ add_action( 'admin_head', array( $this, 'output_header_placeholder' ), 15 ); // For comments
65
+ add_action( 'wp_footer', array( $this, 'maybe_output_scripts' ), 15 );
66
+ add_action( 'admin_footer', array( $this, 'maybe_output_scripts' ), 15 ); // For comments
67
+
68
+ // Admin hooks
69
+ add_action( 'admin_init', array( $this, 'register_setting' ) );
70
+ add_action( 'admin_menu', array( $this, 'register_settings_page' ) );
71
+ add_filter( 'mce_external_plugins', array( $this, 'add_tinymce_plugin' ) );
72
+ add_filter( 'save_post', array( $this, 'mark_as_encoded' ), 10, 2 );
73
+ add_filter( 'plugin_action_links', array( $this, 'settings_link' ), 10, 2 );
74
+
75
+ // Register widget hooks
76
+ add_filter( 'widget_text', array( $this, 'widget_text_output' ), 7, 2 );
77
+ add_filter( 'widget_update_callback', array( $this, 'widget_text_save' ), 1, 4 );
78
+ add_filter( 'widget_form_callback', array( $this, 'widget_text_form' ), 1, 2 );
79
+
80
+
81
+ // Create array of default settings (you can use the filter to modify these)
82
+ $this->defaultsettings = (array) apply_filters( 'syntaxhighlighter_defaultsettings', array(
83
+ 'theme' => 'default',
84
+ 'loadallbrushes' => 0,
85
+ 'shversion' => 3,
86
+ 'title' => '',
87
+ 'autolinks' => 1,
88
+ 'classname' => '',
89
+ 'collapse' => 0,
90
+ 'firstline' => 1,
91
+ 'gutter' => 1,
92
+ 'htmlscript' => 0,
93
+ 'light' => 0,
94
+ 'padlinenumbers' => 'false',
95
+ 'smarttabs' => 1,
96
+ 'tabsize' => 4,
97
+ 'toolbar' => 0,
98
+ 'wraplines' => 1, // 2.x only
99
+ ) );
100
+
101
+ // Create the settings array by merging the user's settings and the defaults
102
+ $usersettings = (array) get_option('syntaxhighlighter_settings');
103
+ $this->settings = wp_parse_args( $usersettings, $this->defaultsettings );
104
+
105
+ // Dynamically set folder and version names for SynaxHighlighter
106
+ if ( 2 == $this->settings['shversion'] ) {
107
+ $this->shfolder = 'syntaxhighlighter2';
108
+ $this->agshver = '2.1.364';
109
+ } else {
110
+ $this->shfolder = 'syntaxhighlighter3';
111
+ $this->agshver = '3.0.9b';
112
+ }
113
+
114
+ // Register brush scripts
115
+ wp_register_script( 'syntaxhighlighter-core', plugins_url( $this->shfolder . '/scripts/shCore.js', __FILE__ ), array(), $this->agshver );
116
+ wp_register_script( 'syntaxhighlighter-brush-as3', plugins_url( $this->shfolder . '/scripts/shBrushAS3.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
117
+ wp_register_script( 'syntaxhighlighter-brush-bash', plugins_url( $this->shfolder . '/scripts/shBrushBash.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
118
+ wp_register_script( 'syntaxhighlighter-brush-coldfusion', plugins_url( $this->shfolder . '/scripts/shBrushColdFusion.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
119
+ wp_register_script( 'syntaxhighlighter-brush-cpp', plugins_url( $this->shfolder . '/scripts/shBrushCpp.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
120
+ wp_register_script( 'syntaxhighlighter-brush-csharp', plugins_url( $this->shfolder . '/scripts/shBrushCSharp.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
121
+ wp_register_script( 'syntaxhighlighter-brush-css', plugins_url( $this->shfolder . '/scripts/shBrushCss.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
122
+ wp_register_script( 'syntaxhighlighter-brush-delphi', plugins_url( $this->shfolder . '/scripts/shBrushDelphi.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
123
+ wp_register_script( 'syntaxhighlighter-brush-diff', plugins_url( $this->shfolder . '/scripts/shBrushDiff.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
124
+ wp_register_script( 'syntaxhighlighter-brush-erlang', plugins_url( $this->shfolder . '/scripts/shBrushErlang.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
125
+ wp_register_script( 'syntaxhighlighter-brush-groovy', plugins_url( $this->shfolder . '/scripts/shBrushGroovy.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
126
+ wp_register_script( 'syntaxhighlighter-brush-java', plugins_url( $this->shfolder . '/scripts/shBrushJava.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
127
+ wp_register_script( 'syntaxhighlighter-brush-javafx', plugins_url( $this->shfolder . '/scripts/shBrushJavaFX.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
128
+ wp_register_script( 'syntaxhighlighter-brush-jscript', plugins_url( $this->shfolder . '/scripts/shBrushJScript.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
129
+ wp_register_script( 'syntaxhighlighter-brush-perl', plugins_url( $this->shfolder . '/scripts/shBrushPerl.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
130
+ wp_register_script( 'syntaxhighlighter-brush-php', plugins_url( $this->shfolder . '/scripts/shBrushPhp.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
131
+ wp_register_script( 'syntaxhighlighter-brush-plain', plugins_url( $this->shfolder . '/scripts/shBrushPlain.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
132
+ wp_register_script( 'syntaxhighlighter-brush-powershell', plugins_url( $this->shfolder . '/scripts/shBrushPowerShell.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
133
+ wp_register_script( 'syntaxhighlighter-brush-python', plugins_url( $this->shfolder . '/scripts/shBrushPython.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
134
+ wp_register_script( 'syntaxhighlighter-brush-ruby', plugins_url( $this->shfolder . '/scripts/shBrushRuby.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
135
+ wp_register_script( 'syntaxhighlighter-brush-scala', plugins_url( $this->shfolder . '/scripts/shBrushScala.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
136
+ wp_register_script( 'syntaxhighlighter-brush-sql', plugins_url( $this->shfolder . '/scripts/shBrushSql.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
137
+ wp_register_script( 'syntaxhighlighter-brush-vb', plugins_url( $this->shfolder . '/scripts/shBrushVb.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
138
+ wp_register_script( 'syntaxhighlighter-brush-xml', plugins_url( $this->shfolder . '/scripts/shBrushXml.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
139
+
140
+ // Register some popular third-party brushes
141
+ wp_register_script( 'syntaxhighlighter-brush-clojure', plugins_url( 'third-party-brushes/shBrushClojure.js', __FILE__ ), array('syntaxhighlighter-core'), '20090602' );
142
+ wp_register_script( 'syntaxhighlighter-brush-fsharp', plugins_url( 'third-party-brushes/shBrushFSharp.js', __FILE__ ), array('syntaxhighlighter-core'), '20091003' );
143
+ wp_register_script( 'syntaxhighlighter-brush-latex', plugins_url( 'third-party-brushes/shBrushLatex.js', __FILE__ ), array('syntaxhighlighter-core'), '20090613' );
144
+ wp_register_script( 'syntaxhighlighter-brush-matlabkey', plugins_url( 'third-party-brushes/shBrushMatlabKey.js', __FILE__ ), array('syntaxhighlighter-core'), '20091209' );
145
+ wp_register_script( 'syntaxhighlighter-brush-objc', plugins_url( 'third-party-brushes/shBrushObjC.js', __FILE__ ), array('syntaxhighlighter-core'), '20091207' );
146
+ wp_register_script( 'syntaxhighlighter-brush-r', plugins_url( 'third-party-brushes/shBrushR.js', __FILE__ ), array('syntaxhighlighter-core'), '20100919' );
147
+
148
+ // Register theme stylesheets
149
+ wp_register_style( 'syntaxhighlighter-core', plugins_url( $this->shfolder . '/styles/shCore.css', __FILE__ ), array(), $this->agshver );
150
+ wp_register_style( 'syntaxhighlighter-theme-default', plugins_url( $this->shfolder . '/styles/shThemeDefault.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
151
+ wp_register_style( 'syntaxhighlighter-theme-django', plugins_url( $this->shfolder . '/styles/shThemeDjango.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
152
+ wp_register_style( 'syntaxhighlighter-theme-eclipse', plugins_url( $this->shfolder . '/styles/shThemeEclipse.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
153
+ wp_register_style( 'syntaxhighlighter-theme-emacs', plugins_url( $this->shfolder . '/styles/shThemeEmacs.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
154
+ wp_register_style( 'syntaxhighlighter-theme-fadetogrey', plugins_url( $this->shfolder . '/styles/shThemeFadeToGrey.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
155
+ wp_register_style( 'syntaxhighlighter-theme-midnight', plugins_url( $this->shfolder . '/styles/shThemeMidnight.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
156
+ wp_register_style( 'syntaxhighlighter-theme-rdark', plugins_url( $this->shfolder . '/styles/shThemeRDark.css', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
157
+
158
+
159
+ // Create list of brush aliases and map them to their real brushes
160
+ // The key is the language alias
161
+ // The value is the script handle suffix: syntaxhighlighter-brush-ThisBitHere (your plugin needs to register the script itself)
162
+ $this->brushes = (array) apply_filters( 'syntaxhighlighter_brushes', array(
163
+ 'as3' => 'as3',
164
+ 'actionscript3' => 'as3',
165
+ 'bash' => 'bash',
166
+ 'shell' => 'bash',
167
+ 'coldfusion' => 'coldfusion',
168
+ 'cf' => 'coldfusion',
169
+ 'clojure' => 'clojure',
170
+ 'clj' => 'clojure',
171
+ 'cpp' => 'cpp',
172
+ 'c' => 'cpp',
173
+ 'c-sharp' => 'csharp',
174
+ 'csharp' => 'csharp',
175
+ 'css' => 'css',
176
+ 'delphi' => 'delphi',
177
+ 'pas' => 'delphi',
178
+ 'pascal' => 'delphi',
179
+ 'diff' => 'diff',
180
+ 'patch' => 'diff',
181
+ 'erl' => 'erlang',
182
+ 'erlang' => 'erlang',
183
+ 'fsharp' => 'fsharp',
184
+ 'groovy' => 'groovy',
185
+ 'java' => 'java',
186
+ 'jfx' => 'javafx',
187
+ 'javafx' => 'javafx',
188
+ 'js' => 'jscript',
189
+ 'jscript' => 'jscript',
190
+ 'javascript' => 'jscript',
191
+ 'latex' => 'latex', // Not used as a shortcode
192
+ 'tex' => 'latex',
193
+ 'matlab' => 'matlabkey',
194
+ 'objc' => 'objc',
195
+ 'obj-c' => 'objc',
196
+ 'perl' => 'perl',
197
+ 'pl' => 'perl',
198
+ 'php' => 'php',
199
+ 'plain' => 'plain',
200
+ 'text' => 'plain',
201
+ 'ps' => 'powershell',
202
+ 'powershell' => 'powershell',
203
+ 'py' => 'python',
204
+ 'python' => 'python',
205
+ 'r' => 'r', // Not used as a shortcode
206
+ 'splus' => 'r',
207
+ 'rails' => 'ruby',
208
+ 'rb' => 'ruby',
209
+ 'ror' => 'ruby',
210
+ 'ruby' => 'ruby',
211
+ 'scala' => 'scala',
212
+ 'sql' => 'sql',
213
+ 'vb' => 'vb',
214
+ 'vbnet' => 'vb',
215
+ 'xml' => 'xml',
216
+ 'xhtml' => 'xml',
217
+ 'xslt' => 'xml',
218
+ 'html' => 'xml',
219
+ ) );
220
+
221
+
222
+ // Create a list of shortcodes to use. You can use the filter to add/remove ones.
223
+ // If the language/lang parameter is left out, it's assumed the shortcode name is the language.
224
+ // If that's invalid, then "plain" is used.
225
+ $this->shortcodes = array( 'sourcecode', 'source', 'code' );
226
+ $this->shortcodes = array_merge( $this->shortcodes, array_keys( $this->brushes ) );
227
+
228
+ // Remove some shortcodes we don't want while still supporting them as language values
229
+ unset( $this->shortcodes[array_search( 'latex', $this->shortcodes )] ); // Remove "latex" shortcode (it'll collide)
230
+ unset( $this->shortcodes[array_search( 'r', $this->shortcodes )] ); // Remove "r" shortcode (too short)
231
+
232
+ $this->shortcodes = (array) apply_filters( 'syntaxhighlighter_shortcodes', $this->shortcodes );
233
+
234
+
235
+ // Register each shortcode with a placeholder callback so that strip_shortcodes() will work
236
+ // The proper callback and such is done in SyntaxHighlighter::shortcode_hack()
237
+ foreach ( $this->shortcodes as $shortcode )
238
+ add_shortcode( $shortcode, '__return_empty_string' );
239
+
240
+
241
+ // Create list of themes and their human readable names
242
+ // Plugins can add to this list: http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/adding-a-new-theme/
243
+ $this->themes = (array) apply_filters( 'syntaxhighlighter_themes', array(
244
+ 'default' => __( 'Default', 'syntaxhighlighter' ),
245
+ 'django' => __( 'Django', 'syntaxhighlighter' ),
246
+ 'eclipse' => __( 'Eclipse', 'syntaxhighlighter' ),
247
+ 'emacs' => __( 'Emacs', 'syntaxhighlighter' ),
248
+ 'fadetogrey' => __( 'Fade to Grey', 'syntaxhighlighter' ),
249
+ 'midnight' => __( 'Midnight', 'syntaxhighlighter' ),
250
+ 'rdark' => __( 'RDark', 'syntaxhighlighter' ),
251
+ 'none' => __( '[None]', 'syntaxhighlighter' ),
252
+ ) );
253
+
254
+ // Other special characters that need to be encoded before going into the database (namely to work around kses)
255
+ $this->specialchars = (array) apply_filters( 'syntaxhighlighter_specialchars', array(
256
+ '\0' => '&#92;&#48;',
257
+ ) );
258
+ }
259
+
260
+
261
+ // Register the settings page
262
+ function register_settings_page() {
263
+ add_options_page( __( 'SyntaxHighlighter Settings', 'syntaxhighlighter' ), __( 'SyntaxHighlighter', 'syntaxhighlighter' ), 'manage_options', 'syntaxhighlighter', array( $this, 'settings_page' ) );
264
+ }
265
+
266
+
267
+ // Register the plugin's setting
268
+ function register_setting() {
269
+ register_setting( 'syntaxhighlighter_settings', 'syntaxhighlighter_settings', array( $this, 'validate_settings' ) );
270
+ }
271
+
272
+
273
+ // Add the custom TinyMCE plugin which wraps plugin shortcodes in <pre> in TinyMCE
274
+ function add_tinymce_plugin( $plugins ) {
275
+ global $tinymce_version;
276
+
277
+ add_action( 'admin_print_footer_scripts', array( $this, 'output_shortcodes_for_tinymce' ), 9 );
278
+
279
+ if ( substr( $tinymce_version, 0, 1 ) < 4 ) {
280
+ $plugins['syntaxhighlighter'] = plugins_url( 'syntaxhighlighter_mce.js', __FILE__ );
281
+ } else {
282
+ $plugins['syntaxhighlighter'] = add_query_arg( 'ver', $this->pluginver, plugins_url( 'syntaxhighlighter_mce-4.js', __FILE__ ) );
283
+ wp_enqueue_script( 'syntaxhighlighter', plugins_url( 'syntaxhighlighter.js', __FILE__ ), array(), false, true );
284
+ }
285
+
286
+ return $plugins;
287
+ }
288
+
289
+
290
+ // Break the TinyMCE cache
291
+ function break_tinymce_cache( $version ) {
292
+ return $version . '-sh' . $this->pluginver;
293
+ }
294
+
295
+
296
+ // Add a "Settings" link to the plugins page
297
+ function settings_link( $links, $file ) {
298
+ static $this_plugin;
299
+
300
+ if( empty($this_plugin) )
301
+ $this_plugin = plugin_basename(__FILE__);
302
+
303
+ if ( $file == $this_plugin )
304
+ $links[] = '<a href="' . admin_url( 'options-general.php?page=syntaxhighlighter' ) . '">' . __( 'Settings', 'syntaxhighlighter' ) . '</a>';
305
+
306
+ return $links;
307
+ }
308
+
309
+
310
+ // Output list of shortcode tags for the TinyMCE plugin
311
+ function output_shortcodes_for_tinymce() {
312
+ $shortcodes = array();
313
+
314
+ foreach ( $this->shortcodes as $shortcode )
315
+ $shortcodes[] = preg_quote( $shortcode );
316
+
317
+ echo "<script type='text/javascript'>\n";
318
+ echo " var syntaxHLcodes = '" . implode( '|', $shortcodes ) . "';\n";
319
+ echo "</script>\n";
320
+ }
321
+
322
+
323
+ /**
324
+ * Process only this plugin's shortcodes.
325
+ *
326
+ * If we waited for the normal do_shortcode() call at priority 11,
327
+ * then wpautop() and maybe others would mangle all of the code.
328
+ *
329
+ * So instead we hook in earlier with this function and process
330
+ * just this plugins's shortcodes. To do this requires some trickery.
331
+ *
332
+ * First we need to clear out all existing shortcodes, then register
333
+ * just this plugin's ones, process them, and then restore the original
334
+ * list of shortcodes.
335
+ *
336
+ * To make matters more complicated, if someone has done [[code]foo[/code]]
337
+ * in order to display the shortcode (not render it), then do_shortcode()
338
+ * will strip the outside brackets and when do_shortcode() runs a second
339
+ * time later on, it will render it.
340
+ *
341
+ * So instead before do_shortcode() runs for the first time, we add
342
+ * even more brackets escaped shortcodes in order to result in
343
+ * the shortcodes actually being displayed instead rendered.
344
+ *
345
+ * We only need to do this for this plugin's shortcodes however
346
+ * as all other shortcodes such as [[gallery]] will be untouched
347
+ * by this pass of do_shortcode.
348
+ *
349
+ * Phew!
350
+ *
351
+ * @param string $content The post content.
352
+ * @param string $callback The callback function that should be used for add_shortcode()
353
+ * @param bool $ignore_html When true, shortcodes inside HTML elements will be skipped.
354
+ *
355
+ * @return string The filtered content, with this plugin's shortcodes parsed.
356
+ */
357
+ function shortcode_hack( $content, $callback, $ignore_html = true ) {
358
+ global $shortcode_tags;
359
+
360
+ // Regex is slow. Let's do some strpos() checks first.
361
+ if ( ! $this->string_has_shortcodes( $content, $this->shortcodes ) ) {
362
+ return $content;
363
+ }
364
+
365
+ // Backup current registered shortcodes and clear them all out
366
+ $orig_shortcode_tags = $shortcode_tags;
367
+ remove_all_shortcodes();
368
+
369
+ // Register all of this plugin's shortcodes
370
+ foreach ( $this->shortcodes as $shortcode ) {
371
+ add_shortcode( $shortcode, $callback );
372
+ }
373
+
374
+ $regex = '/' . get_shortcode_regex( $this->shortcodes ) . '/';
375
+
376
+ // Parse the shortcodes (only this plugins's are registered)
377
+ if ( $ignore_html ) {
378
+ // Extra escape escaped shortcodes because do_shortcode_tag() called by do_shortcode() is going to strip a pair of square brackets when it runs
379
+ $content = preg_replace_callback(
380
+ $regex,
381
+ array( $this, 'shortcode_hack_extra_escape_escaped_shortcodes' ),
382
+ $content
383
+ );
384
+
385
+ // Normal, safe parsing
386
+ $content = do_shortcode( $content, true );
387
+ } else {
388
+ // Extra escape escaped shortcodes because do_shortcode_tag() called by do_shortcode() is going to strip a pair of square brackets when it runs.
389
+ // Then call do_shortcode_tag(). This is basically do_shortcode() without calling do_shortcodes_in_html_tags() which breaks things.
390
+ // For context, see https://wordpress.org/support/topic/php-opening-closing-tags-break-code-blocks
391
+ $content = preg_replace_callback(
392
+ $regex,
393
+ array( $this, 'shortcode_hack_extra_escape_escaped_shortcodes_and_parse' ),
394
+ $content
395
+ );
396
+ }
397
+
398
+ // Put the original shortcodes back
399
+ $shortcode_tags = $orig_shortcode_tags;
400
+
401
+ return $content;
402
+ }
403
+
404
+
405
+ /**
406
+ * A quick checker to see if any of this plugin's shortcodes are in use in a string.
407
+ * Since all of the tags can't be self-closing, we look for the closing tag.
408
+ *
409
+ * @param string $string The string to look through. This is a post's contents usually.
410
+ * @param array $shortcodes The array of shortcodes to look for.
411
+ *
412
+ * @return bool Whether any shortcode usage was found.
413
+ */
414
+ function string_has_shortcodes( $string, $shortcodes ) {
415
+ foreach ( $shortcodes as $shortcode ) {
416
+ if ( false !== strpos( $string, "[/{$shortcode}]" ) ) {
417
+ return true;
418
+ }
419
+ }
420
+
421
+ return false;
422
+ }
423
+
424
+
425
+ /**
426
+ * Add extra square brackets around escaped shortcodes.
427
+ * This is to counteract the beginning of the do_shortcode_tag() function.
428
+ *
429
+ * @param array $match The array of matches generated by get_shortcode_regex()
430
+ *
431
+ * @return string What should be placed into the post content. In this case it's the raw match, or an extra-wrapped raw match.
432
+ */
433
+ function shortcode_hack_extra_escape_escaped_shortcodes( $match ) {
434
+ if ( $match[1] == '[' && $match[6] == ']' ) {
435
+ return '[' . $match[0] . ']';
436
+ }
437
+
438
+ return $match[0];
439
+ }
440
+
441
+ /**
442
+ * This is a combination of this class's shortcode_hack_extra_escape_escaped_shortcodes()
443
+ * and do_shortcode_tag() for performance reasons so that we don't have to run some regex twice.
444
+ *
445
+ * @param array $match Regular expression match array.
446
+ *
447
+ * @return string|false False on failure, otherwise a parse shortcode tag.
448
+ */
449
+ function shortcode_hack_extra_escape_escaped_shortcodes_and_parse( $match ) {
450
+ $match[0] = $this->shortcode_hack_extra_escape_escaped_shortcodes( $match );
451
+
452
+ return do_shortcode_tag( $match );
453
+ }
454
+
455
+
456
+ // The main filter for the post contents. The regular shortcode filter can't be used as it's post-wpautop().
457
+ function parse_shortcodes( $content ) {
458
+ return $this->shortcode_hack( $content, array( $this, 'shortcode_callback' ) );
459
+ }
460
+
461
+
462
+ // HTML entity encode the contents of shortcodes
463
+ function encode_shortcode_contents( $content ) {
464
+ return $this->shortcode_hack( $content, array( $this, 'encode_shortcode_contents_callback' ), false );
465
+ }
466
+
467
+
468
+ // HTML entity encode the contents of shortcodes. Expects slashed content.
469
+ function encode_shortcode_contents_slashed( $content ) {
470
+ return addslashes( $this->encode_shortcode_contents( stripslashes( $content ) ) );
471
+ }
472
+
473
+
474
+ // HTML entity encode the contents of shortcodes. Expects slashed content. Aborts if AJAX.
475
+ function encode_shortcode_contents_slashed_noquickedit( $content ) {
476
+
477
+ // In certain weird circumstances, the content gets run through "content_save_pre" twice
478
+ // Keep track and don't allow this filter to be run twice
479
+ // I couldn't easily figure out why this happens and didn't bother looking into it further as this works fine
480
+ if ( true == $this->content_save_pre_ran ) {
481
+ return $content;
482
+ }
483
+ $this->content_save_pre_ran = true;
484
+
485
+ // Post quick edits aren't decoded for display, so we don't need to encode them (again)
486
+ // This also aborts for (un)trashing to avoid extra encoding.
487
+ if ( empty( $_POST ) || ( ! empty( $_POST['action'] ) && 'inline-save' == $_POST['action'] ) ) {
488
+ return $content;
489
+ }
490
+
491
+ return $this->encode_shortcode_contents_slashed( $content );
492
+ }
493
+
494
+
495
+ // HTML entity decode the contents of shortcodes
496
+ function decode_shortcode_contents( $content ) {
497
+ return $this->shortcode_hack( $content, array( $this, 'decode_shortcode_contents_callback' ), false );
498
+ }
499
+
500
+
501
+ // The callback function for SyntaxHighlighter::encode_shortcode_contents()
502
+ function encode_shortcode_contents_callback( $atts, $code = '', $tag = false ) {
503
+ $this->encoded = true;
504
+ $code = str_replace( array_keys($this->specialchars), array_values($this->specialchars), htmlspecialchars( $code ) );
505
+ return '[' . $tag . $this->atts2string( $atts ) . "]{$code}[/$tag]";
506
+ }
507
+
508
+
509
+ // The callback function for SyntaxHighlighter::decode_shortcode_contents()
510
+ // Shortcode attribute values need to not be quoted with TinyMCE disabled for some reason (weird bug)
511
+ function decode_shortcode_contents_callback( $atts, $code = '', $tag = false ) {
512
+ $quotes = ( user_can_richedit() ) ? true : false;
513
+ $code = str_replace( array_values($this->specialchars), array_keys($this->specialchars), htmlspecialchars_decode( $code ) );
514
+ return '[' . $tag . $this->atts2string( $atts, $quotes ) . "]{$code}[/$tag]";
515
+ }
516
+
517
+
518
+ // Dynamically format the post content for the edit form
519
+ function the_editor_content( $content ) {
520
+ global $post;
521
+
522
+ // New code format (stored encoded in database)
523
+ if ( 2 == $this->get_code_format( $post ) ) {
524
+ // If TinyMCE is disabled or the HTML tab is set to be displayed first, we need to decode the HTML
525
+ if ( !user_can_richedit() || 'html' == wp_default_editor() )
526
+ $content = $this->decode_shortcode_contents( $content );
527
+ }
528
+
529
+ // Old code format (stored raw in database)
530
+ else {
531
+ // If TinyMCE is enabled and is set to be displayed first, we need to encode the HTML
532
+ if ( user_can_richedit() && 'html' != wp_default_editor() )
533
+ $content = $this->encode_shortcode_contents( $content );
534
+ }
535
+
536
+ return $content;
537
+ }
538
+
539
+
540
+ // Run SyntaxHighlighter::encode_shortcode_contents() on the contents of the text widget
541
+ function widget_text_save( $instance, $new_instance, $old_instance, $widgetclass ) {
542
+ if ( 'text' == $widgetclass->id_base ) {
543
+ // Re-save the widget settings but this time with the shortcode contents encoded
544
+ $new_instance['text'] = $this->encode_shortcode_contents( $new_instance['text'] );
545
+ $instance = $widgetclass->update( $new_instance, $old_instance );
546
+
547
+ // And flag it as encoded
548
+ $instance['syntaxhighlighter_encoded'] = true;
549
+ }
550
+
551
+ return $instance;
552
+ }
553
+
554
+
555
+ // Run SyntaxHighlighter::decode_shortcode_contents_callback() on the contents of the text widget form
556
+ function widget_text_form( $instance, $widgetclass ) {
557
+ if ( 'text' == $widgetclass->id_base && !empty($instance['syntaxhighlighter_encoded']) ) {
558
+ $instance['text'] = $this->shortcode_hack( $instance['text'], array( $this, 'decode_shortcode_contents_callback' ) );
559
+ }
560
+
561
+ return $instance;
562
+ }
563
+
564
+
565
+ // Run SyntaxHighlighter::parse_shortcodes() on the contents of a text widget
566
+ function widget_text_output( $content, $instance = false ) {
567
+ $this->codeformat = ( false === $instance || empty($instance['syntaxhighlighter_encoded']) ) ? 1 : 2;
568
+ $content = $this->parse_shortcodes( $content );
569
+ $this->codeformat = false;
570
+
571
+ return $content;
572
+ }
573
+
574
+
575
+ // Run SyntaxHighlighter::parse_shortcodes() on the contents of a comment
576
+ function parse_shortcodes_comment( $content ) {
577
+ $this->codeformat = 2;
578
+ $content = $this->parse_shortcodes( $content );
579
+ $this->codeformat = false;
580
+
581
+ return $content;
582
+ }
583
+
584
+
585
+ // This function determines what version of SyntaxHighlighter was used when the post was written
586
+ // This is because the code was stored differently for different versions of SyntaxHighlighter
587
+ function get_code_format( $post ) {
588
+ if ( false !== $this->codeformat )
589
+ return $this->codeformat;
590
+
591
+ if ( empty($post) )
592
+ $post = new stdClass();
593
+
594
+ if ( null !== $version = apply_filters( 'syntaxhighlighter_pre_getcodeformat', null, $post ) )
595
+ return $version;
596
+
597
+ $version = ( empty($post->ID) || get_post_meta( $post->ID, '_syntaxhighlighter_encoded', true ) || get_post_meta( $post->ID, 'syntaxhighlighter_encoded', true ) ) ? 2 : 1;
598
+
599
+ return apply_filters( 'syntaxhighlighter_getcodeformat', $version, $post );
600
+ }
601
+
602
+
603
+ // Adds a post meta saying that HTML entities are encoded (for backwards compatibility)
604
+ function mark_as_encoded( $post_ID, $post ) {
605
+ if ( false == $this->encoded || 'revision' == $post->post_type )
606
+ return;
607
+
608
+ delete_post_meta( $post_ID, 'syntaxhighlighter_encoded' ); // Previously used
609
+ add_post_meta( $post_ID, '_syntaxhighlighter_encoded', true, true );
610
+ }
611
+
612
+
613
+ // Transforms an attributes array into a 'key="value"' format (i.e. reverses the process)
614
+ function atts2string( $atts, $quotes = true ) {
615
+ if ( empty($atts) )
616
+ return '';
617
+
618
+ $atts = $this->attributefix( $atts );
619
+
620
+ // Re-map [code="php"] style tags
621
+ if ( isset($atts[0]) ) {
622
+ if ( empty($atts['language']) )
623
+ $atts['language'] = $atts[0];
624
+
625
+ unset($atts[0]);
626
+ }
627
+
628
+ $strings = array();
629
+ foreach ( $atts as $key => $value )
630
+ $strings[] = ( $quotes ) ? $key . '="' . esc_attr( $value ) . '"' : $key . '=' . esc_attr( $value );
631
+
632
+ return ' ' . implode( ' ', $strings );
633
+ }
634
+
635
+
636
+ // Simple function for escaping just single quotes (the original js_escape() escapes more than we need)
637
+ function js_escape_singlequotes( $string ) {
638
+ return str_replace( "'", "\'", $string );
639
+ }
640
+
641
+
642
+ // Output an anchor in the header for the Javascript to use.
643
+ // In the <head>, we don't know if we'll need this plugin's CSS and JavaScript yet but we will in the footer.
644
+ function output_header_placeholder() {
645
+ echo '<style type="text/css" id="syntaxhighlighteranchor"></style>' . "\n";
646
+ }
647
+
648
+
649
+ // Output any needed scripts. This is meant for the footer.
650
+ function maybe_output_scripts() {
651
+ global $wp_styles;
652
+
653
+ if ( 1 == $this->settings['loadallbrushes'] )
654
+ $this->usedbrushes = array_flip( array_values( $this->brushes ) );
655
+
656
+ if ( empty($this->usedbrushes) )
657
+ return;
658
+
659
+ $scripts = array();
660
+ foreach ( $this->usedbrushes as $brush => $unused )
661
+ $scripts[] = 'syntaxhighlighter-brush-' . strtolower( $brush );
662
+
663
+ wp_print_scripts( $scripts );
664
+
665
+ // Stylesheets can't be in the footer, so inject them via Javascript
666
+ echo "<script type='text/javascript'>\n";
667
+ echo " (function(){\n";
668
+ echo " var corecss = document.createElement('link');\n";
669
+ echo " var themecss = document.createElement('link');\n";
670
+
671
+ if ( !is_a($wp_styles, 'WP_Styles') )
672
+ $wp_styles = new WP_Styles();
673
+
674
+ $needcore = false;
675
+ if ( 'none' == $this->settings['theme'] ) {
676
+ $needcore = true;
677
+ } else {
678
+ $theme = ( !empty($this->themes[$this->settings['theme']]) ) ? strtolower($this->settings['theme']) : $this->defaultsettings['theme'];
679
+ $theme = 'syntaxhighlighter-theme-' . $theme;
680
+
681
+ // See if the requested theme has been registered
682
+ if ( !empty($wp_styles) && !empty($wp_styles->registered) && !empty($wp_styles->registered[$theme]) && !empty($wp_styles->registered[$theme]->src) ) {
683
+
684
+ // Users can register their own stylesheet and may opt to not load the core stylesheet if they wish for some reason
685
+ if ( is_array($wp_styles->registered[$theme]->deps) && in_array( 'syntaxhighlighter-core', $wp_styles->registered[$theme]->deps ) )
686
+ $needcore = true;
687
+ }
688
+
689
+ // Otherwise use the default theme
690
+ else {
691
+ $theme = 'syntaxhighlighter-theme-' . $this->defaultsettings['theme'];
692
+ $needcore = true;
693
+ }
694
+ }
695
+
696
+ if ( $needcore && !empty($wp_styles) && !empty($wp_styles->registered) && !empty($wp_styles->registered['syntaxhighlighter-core']) && !empty($wp_styles->registered['syntaxhighlighter-core']->src) ) :
697
+ $corecssurl = add_query_arg( 'ver', $this->agshver, $wp_styles->registered['syntaxhighlighter-core']->src );
698
+ $corecssurl = apply_filters( 'syntaxhighlighter_csscoreurl', $corecssurl );
699
+ ?>
700
+ var corecssurl = "<?php echo esc_js( $corecssurl ); ?>";
701
+ if ( corecss.setAttribute ) {
702
+ corecss.setAttribute( "rel", "stylesheet" );
703
+ corecss.setAttribute( "type", "text/css" );
704
+ corecss.setAttribute( "href", corecssurl );
705
+ } else {
706
+ corecss.rel = "stylesheet";
707
+ corecss.href = corecssurl;
708
+ }
709
+ document.getElementsByTagName("head")[0].insertBefore( corecss, document.getElementById("syntaxhighlighteranchor") );
710
+ <?php
711
+ endif; // Endif $needcore
712
+
713
+ if ( 'none' != $this->settings['theme'] ) : ?>
714
+ var themecssurl = "<?php echo esc_js( apply_filters( 'syntaxhighlighter_cssthemeurl', add_query_arg( 'ver', $this->agshver, $wp_styles->registered[$theme]->src ) ) ); ?>";
715
+ if ( themecss.setAttribute ) {
716
+ themecss.setAttribute( "rel", "stylesheet" );
717
+ themecss.setAttribute( "type", "text/css" );
718
+ themecss.setAttribute( "href", themecssurl );
719
+ } else {
720
+ themecss.rel = "stylesheet";
721
+ themecss.href = themecssurl;
722
+ }
723
+ //document.getElementById("syntaxhighlighteranchor").appendChild(themecss);
724
+ document.getElementsByTagName("head")[0].insertBefore( themecss, document.getElementById("syntaxhighlighteranchor") );
725
+ <?php
726
+ endif; // Endif none != theme
727
+
728
+ echo " })();\n";
729
+
730
+ switch ( $this->settings['shversion'] ) {
731
+ case 2:
732
+ echo " SyntaxHighlighter.config.clipboardSwf = '" . esc_js( apply_filters( 'syntaxhighlighter_clipboardurl', plugins_url( 'syntaxhighlighter2/scripts/clipboard.swf', __FILE__ ) ) ) . "';\n";
733
+ echo " SyntaxHighlighter.config.strings.expandSource = '" . $this->js_escape_singlequotes( __( 'show source', 'syntaxhighlighter' ) ) . "';\n";
734
+ echo " SyntaxHighlighter.config.strings.viewSource = '" . $this->js_escape_singlequotes( __( 'view source', 'syntaxhighlighter' ) ) . "';\n";
735
+ echo " SyntaxHighlighter.config.strings.copyToClipboard = '" . $this->js_escape_singlequotes( __( 'copy to clipboard', 'syntaxhighlighter' ) ) . "';\n";
736
+ echo " SyntaxHighlighter.config.strings.copyToClipboardConfirmation = '" . $this->js_escape_singlequotes( __( 'The code is in your clipboard now', 'syntaxhighlighter' ) ) . "';\n";
737
+ echo " SyntaxHighlighter.config.strings.print = '" . $this->js_escape_singlequotes( __( 'print', 'syntaxhighlighter' ) ) . "';\n";
738
+ echo " SyntaxHighlighter.config.strings.help = '" . $this->js_escape_singlequotes( __( '?', 'syntaxhighlighter' ) ) . "';\n";
739
+ echo " SyntaxHighlighter.config.strings.alert = '" . $this->js_escape_singlequotes( __( 'SyntaxHighlighter\n\n', 'syntaxhighlighter' ) ) . "';\n";
740
+ echo " SyntaxHighlighter.config.strings.noBrush = '" . $this->js_escape_singlequotes( __( "Can't find brush for: ", 'syntaxhighlighter' ) ) . "';\n";
741
+ echo " SyntaxHighlighter.config.strings.brushNotHtmlScript = '" . $this->js_escape_singlequotes( __( "Brush wasn't configured for html-script option: ", 'syntaxhighlighter' ) ) . "';\n";
742
+ break;
743
+ case 3:
744
+ echo " SyntaxHighlighter.config.strings.expandSource = '" . $this->js_escape_singlequotes( __( '+ expand source', 'syntaxhighlighter' ) ) . "';\n";
745
+ echo " SyntaxHighlighter.config.strings.help = '" . $this->js_escape_singlequotes( __( '?', 'syntaxhighlighter' ) ) . "';\n";
746
+ echo " SyntaxHighlighter.config.strings.alert = '" . $this->js_escape_singlequotes( __( 'SyntaxHighlighter\n\n', 'syntaxhighlighter' ) ) . "';\n";
747
+ echo " SyntaxHighlighter.config.strings.noBrush = '" . $this->js_escape_singlequotes( __( "Can't find brush for: ", 'syntaxhighlighter' ) ) . "';\n";
748
+ echo " SyntaxHighlighter.config.strings.brushNotHtmlScript = '" . $this->js_escape_singlequotes( __( "Brush wasn't configured for html-script option: ", 'syntaxhighlighter' ) ) . "';\n";
749
+ break;
750
+ }
751
+
752
+ if ( 1 != $this->settings['autolinks'] )
753
+ echo " SyntaxHighlighter.defaults['auto-links'] = false;\n";
754
+
755
+ if ( !empty($this->settings['classname']) )
756
+ echo " SyntaxHighlighter.defaults['class-name'] = '" . $this->js_escape_singlequotes( $this->settings['classname'] ) . "';\n";
757
+
758
+ if ( 1 == $this->settings['collapse'] )
759
+ echo " SyntaxHighlighter.defaults['collapse'] = true;\n";
760
+
761
+ if ( 1 != $this->settings['firstline'] )
762
+ echo " SyntaxHighlighter.defaults['first-line'] = " . $this->settings['firstline'] . ";\n";
763
+
764
+ if ( 1 != $this->settings['gutter'] )
765
+ echo " SyntaxHighlighter.defaults['gutter'] = false;\n";
766
+
767
+ /*
768
+ if ( 1 == $this->settings['htmlscript'] )
769
+ echo " SyntaxHighlighter.defaults['html-script'] = true;\n";
770
+ */
771
+
772
+ if ( 1 == $this->settings['light'] )
773
+ echo " SyntaxHighlighter.defaults['light'] = true;\n";
774
+
775
+ echo " SyntaxHighlighter.defaults['pad-line-numbers'] = ";
776
+ switch ( $this->settings['padlinenumbers'] ) {
777
+ case 'true':
778
+ echo 'true';
779
+ break;
780
+ case 'false';
781
+ echo 'false';
782
+ break;
783
+ default;
784
+ echo (int) $this->settings['padlinenumbers'];
785
+ }
786
+ echo ";\n";
787
+
788
+ if ( 1 != $this->settings['smarttabs'] )
789
+ echo " SyntaxHighlighter.defaults['smart-tabs'] = false;\n";
790
+
791
+ if ( 4 != $this->settings['tabsize'] )
792
+ echo " SyntaxHighlighter.defaults['tab-size'] = " . $this->settings['tabsize'] . ";\n";
793
+
794
+ if ( 1 != $this->settings['toolbar'] )
795
+ echo " SyntaxHighlighter.defaults['toolbar'] = false;\n";
796
+
797
+ // 2.x only for now
798
+ if ( 1 != $this->settings['wraplines'] )
799
+ echo " SyntaxHighlighter.defaults['wrap-lines'] = false;\n";
800
+
801
+ ?> SyntaxHighlighter.all();
802
+ </script>
803
+ <?php
804
+ }
805
+
806
+
807
+ // No-name attribute fixing
808
+ function attributefix( $atts = array() ) {
809
+ if ( empty($atts[0]) )
810
+ return $atts;
811
+
812
+ // Quoted value
813
+ if ( 0 !== preg_match( '#=("|\')(.*?)\1#', $atts[0], $match ) )
814
+ $atts[0] = $match[2];
815
+
816
+ // Unquoted value
817
+ elseif ( '=' == substr( $atts[0], 0, 1 ) )
818
+ $atts[0] = substr( $atts[0], 1 );
819
+
820
+ return $atts;
821
+ }
822
+
823
+
824
+ // Shortcode handler for transforming the shortcodes to their final <pre>'s
825
+ function shortcode_callback( $atts, $code = '', $tag = false ) {
826
+ global $post;
827
+
828
+ if ( false === $tag || empty($code) )
829
+ return $code;
830
+
831
+ // Avoid PHP notices
832
+ if ( !isset($post) )
833
+ $post = null;
834
+
835
+ $code = apply_filters( 'syntaxhighlighter_precode', $code, $atts, $tag );
836
+
837
+ // Error fixing for [tag="language"]
838
+ if ( isset($atts[0]) ) {
839
+ $atts = $this->attributefix( $atts );
840
+ $atts['language'] = $atts[0];
841
+ unset($atts[0]);
842
+ }
843
+
844
+ // Default out all of the available parameters to "false" (easy way to check if they're set or not)
845
+ // Note this isn't the same as if the user passes the string "false" to the shortcode
846
+ $atts = (array) apply_filters( 'syntaxhighlighter_shortcodeatts', shortcode_atts( array(
847
+ 'language' => false,
848
+ 'lang' => false,
849
+ 'type' => false, // language alias
850
+ 'autolinks' => false,
851
+ 'classname' => false,
852
+ 'collapse' => false,
853
+ 'firstline' => false,
854
+ 'fontsize' => false,
855
+ 'gutter' => false,
856
+ 'highlight' => false,
857
+ 'htmlscript' => false,
858
+ 'light' => false,
859
+ 'padlinenumbers' => false,
860
+ 'smarttabs' => false,
861
+ 'tabsize' => false,
862
+ 'title' => $this->settings['title'],
863
+ 'toolbar' => false,
864
+ 'wraplines' => false,
865
+ ), $atts ) );
866
+
867
+ // Check for language shortcode tag such as [php]code[/php]
868
+ if ( isset($this->brushes[$tag]) ) {
869
+ $lang = $tag;
870
+ }
871
+
872
+ // If a valid tag is not used, it must be sourcecode/source/code
873
+ else {
874
+ $atts = $this->attributefix( $atts );
875
+
876
+ // Check for the "language" attribute
877
+ if ( false !== $atts['language'] )
878
+ $lang = $atts['language'];
879
+
880
+ // Check for the "lang" attribute
881
+ elseif ( false !== $atts['lang'] )
882
+ $lang = $atts['lang'];
883
+
884
+ // Default to plain text
885
+ else
886
+ $lang = 'text';
887
+
888
+ // All language aliases are lowercase
889
+ $lang = strtolower( $lang );
890
+
891
+ // Validate passed attribute
892
+ if ( !isset($this->brushes[$lang]) )
893
+ return $code;
894
+ }
895
+
896
+ // Switch from the alias to the real brush name (so custom aliases can be used)
897
+ $lang = $this->brushes[$lang];
898
+
899
+ // Register this brush as used so it's script will be outputted
900
+ $this->usedbrushes[$lang] = true;
901
+
902
+ $params = array();
903
+ $params[] = "brush: $lang;";
904
+
905
+ // Fix bug that prevents collapse from working if the toolbar is off or light mode is on
906
+ if ( 'true' == $atts['collapse'] || '1' === $atts['collapse'] || 1 == $this->settings['collapse'] ) {
907
+ $atts['toolbar'] = 'true';
908
+ $atts['light'] = 'false';
909
+ }
910
+
911
+ // Parameter renaming (the shortcode API doesn't like parameter names with dashes)
912
+ $rename_map = array(
913
+ 'autolinks' => 'auto-links',
914
+ 'classname' => 'class-name',
915
+ 'firstline' => 'first-line',
916
+ 'fontsize' => 'font-size',
917
+ 'htmlscript' => 'html-script',
918
+ 'padlinenumbers' => 'pad-line-numbers',
919
+ 'smarttabs' => 'smart-tabs',
920
+ 'tabsize' => 'tab-size',
921
+ 'wraplines' => 'wrap-lines',
922
+ );
923
+
924
+ // Allowed configuration parameters and their type
925
+ // Use the proper names (see above)
926
+ $allowed_atts = (array) apply_filters( 'syntaxhighlighter_allowedatts', array(
927
+ 'auto-links' => 'boolean',
928
+ 'class-name' => 'other',
929
+ 'collapse' => 'boolean',
930
+ 'first-line' => 'integer',
931
+ 'font-size' => 'integer',
932
+ 'gutter' => 'boolean',
933
+ 'highlight' => 'other',
934
+ 'html-script' => 'boolean',
935
+ 'light' => 'boolean',
936
+ 'pad-line-numbers' => 'other',
937
+ 'smart-tabs' => 'boolean',
938
+ 'tab-size' => 'integer',
939
+ 'title' => 'other',
940
+ 'toolbar' => 'boolean',
941
+ 'wrap-lines' => 'boolean',
942
+ ) );
943
+
944
+ $title = '';
945
+
946
+ // Sanitize configuration parameters and such
947
+ foreach ( $atts as $key => $value ) {
948
+ $key = strtolower( $key );
949
+
950
+ // Put back parameter names that have been renamed for shortcode use
951
+ if ( !empty($rename_map[$key]) )
952
+ $key = $rename_map[$key];
953
+
954
+ // This this parameter if it's unknown, not set, or the language which was already handled
955
+ if ( empty($allowed_atts[$key]) || false === $value || in_array( $key, array( 'language', 'lang' ) ) )
956
+ continue;
957
+
958
+ // Sanitize values
959
+ switch ( $allowed_atts[$key] ) {
960
+ case 'boolean':
961
+ $value = strtolower( $value );
962
+ if ( 'true' === $value || '1' === $value || 'on' == $value )
963
+ $value = 'true';
964
+ elseif ( 'false' === $value || '0' === $value || 'off' == $value )
965
+ $value = 'false';
966
+ else
967
+ continue 2; // Invalid value, ditch parameter
968
+ break;
969
+
970
+ // integer
971
+ case 'integer':
972
+ $value = (int) $value;
973
+ break;
974
+ }
975
+
976
+ // Sanitize the "classname" parameter
977
+ if ( 'class-name' == $key )
978
+ $value = trim( preg_replace( '/[^a-zA-Z0-9 _-]/i', '', $value ) );
979
+
980
+ // Special sanitization for "pad-line-numbers"
981
+ if ( 'pad-line-numbers' == $key ) {
982
+ $value = strtolower( $value );
983
+ if ( 'true' === $value || '1' === $value )
984
+ $value = 'true';
985
+ elseif ( 'false' === $value || '0' === $value )
986
+ $value = 'false';
987
+ else
988
+ $value = (int) $value;
989
+ }
990
+
991
+ // Add % sign to "font-size"
992
+ if ( 'font-size' == $key )
993
+ $value = $value . '%';
994
+
995
+ // If "html-script", then include the XML brush as it's needed
996
+ if ( 'html-script' == $key && 'true' == $value )
997
+ $this->usedbrushes['xml'] = true;
998
+
999
+ // Sanitize row highlights
1000
+ if ( 'highlight' == $key ) {
1001
+ if ( false === strpos( $value, ',' ) && false === strpos( $value, '-' ) ) {
1002
+ $value = (int) $value;
1003
+ } else {
1004
+ $lines = explode( ',', $value );
1005
+ $highlights = array();
1006
+
1007
+ foreach ( $lines as $line ) {
1008
+ // Line range
1009
+ if ( false !== strpos( $line, '-' ) ) {
1010
+ list( $range_start, $range_end ) = array_map( 'intval', explode( '-', $line ) );
1011
+ if ( ! $range_start || ! $range_end || $range_end <= $range_start )
1012
+ continue;
1013
+
1014
+ for ( $i = $range_start; $i <= $range_end; $i++ )
1015
+ $highlights[] = $i;
1016
+ } else {
1017
+ $highlights[] = (int) $line;
1018
+ }
1019
+ }
1020
+
1021
+ natsort( $highlights );
1022
+
1023
+ $value = implode( ',', $highlights );
1024
+ }
1025
+
1026
+ if ( empty( $value ) )
1027
+ continue;
1028
+
1029
+ // Wrap highlight in [ ]
1030
+ $params[] = "$key: [$value];";
1031
+ continue;
1032
+ }
1033
+
1034
+ // Don't allow HTML in the title parameter
1035
+ if ( 'title' == $key ) {
1036
+ $value = strip_tags( html_entity_decode( strip_tags( $value ) ) );
1037
+ }
1038
+
1039
+ $params[] = "$key: $value;";
1040
+
1041
+ // Set the title variable if the title parameter is set (but not for feeds)
1042
+ if ( 'title' == $key && ! is_feed() )
1043
+ $title = ' title="' . esc_attr( $value ) . '"';
1044
+ }
1045
+
1046
+ $code = ( false === strpos( $code, '<' ) && false === strpos( $code, '>' ) && 2 == $this->get_code_format($post) ) ? strip_tags( $code ) : htmlspecialchars( $code );
1047
+
1048
+ $params[] = 'notranslate'; // For Google, see http://otto42.com/9k
1049
+
1050
+ $params = apply_filters( 'syntaxhighlighter_cssclasses', $params ); // Use this to add additional CSS classes / SH parameters
1051
+
1052
+ return apply_filters( 'syntaxhighlighter_htmlresult', '<pre class="' . esc_attr( implode( ' ', $params ) ) . '"' . $title . '>' . $code . '</pre>' );;
1053
+ }
1054
+
1055
+
1056
+ // Settings page
1057
+ function settings_page() { ?>
1058
+
1059
+ <script type="text/javascript">
1060
+ // <![CDATA[
1061
+ jQuery(document).ready(function($) {
1062
+ // Confirm pressing of the "Reset to Defaults" button
1063
+ $("#syntaxhighlighter-defaults").click(function(){
1064
+ var areyousure = confirm("<?php echo esc_js( __( 'Are you sure you want to reset your settings to the defaults?', 'syntaxhighlighter' ) ); ?>");
1065
+ if ( true != areyousure ) return false;
1066
+ });
1067
+ <?php if ( !empty( $_GET['defaults'] ) ) : ?>
1068
+ $("#message p strong").text("<?php echo esc_js( __( 'Settings reset to defaults.', 'syntaxhighlighter' ) ); ?>");
1069
+ <?php endif; ?>
1070
+ });
1071
+ // ]]>
1072
+ </script>
1073
+
1074
+ <div class="wrap">
1075
+ <?php if ( function_exists('screen_icon') ) screen_icon(); ?>
1076
+ <h2><?php _e( 'SyntaxHighlighter Settings', 'syntaxhighlighter' ); ?></h2>
1077
+
1078
+ <form method="post" action="options.php">
1079
+
1080
+ <?php settings_fields('syntaxhighlighter_settings'); ?>
1081
+
1082
+
1083
+ <table class="form-table">
1084
+ <tr valign="top">
1085
+ <th scope="row"><label for="syntaxhighlighter-shversion"><?php _e( 'Highlighter Version', 'syntaxhighlighter' ); ?></label></th>
1086
+ <td>
1087
+ <select name="syntaxhighlighter_settings[shversion]" id="syntaxhighlighter-shversion" class="postform">
1088
+ <?php
1089
+ $versions = array(
1090
+ 3 => __( 'Version 3.x', 'syntaxhighlighter' ),
1091
+ 2 => __( 'Version 2.x', 'syntaxhighlighter' ),
1092
+ );
1093
+
1094
+ foreach ( $versions as $version => $name ) {
1095
+ echo ' <option value="' . esc_attr( $version ) . '"' . selected( $this->settings['shversion'], $version, false ) . '>' . esc_html( $name ) . "&nbsp;</option>\n";
1096
+ }
1097
+ ?>
1098
+ </select><br />
1099
+ <?php _e( 'Version 3 allows visitors to easily highlight portions of your code with their mouse (either by dragging or double-clicking) and copy it to their clipboard. No toolbar containing a Flash-based button is required.', 'syntaxhighlighter' ); ?><br />
1100
+ <?php _e( 'Version 2 allows for line wrapping, something that version 3 does not do at this time.', 'syntaxhighlighter' ); ?>
1101
+ </td>
1102
+ </tr>
1103
+ <tr valign="top">
1104
+ <th scope="row"><label for="syntaxhighlighter-theme"><?php _e( 'Color Theme', 'syntaxhighlighter' ); ?></label></th>
1105
+ <td>
1106
+ <select name="syntaxhighlighter_settings[theme]" id="syntaxhighlighter-theme" class="postform">
1107
+ <?php
1108
+ foreach ( $this->themes as $theme => $name ) {
1109
+ echo ' <option value="' . esc_attr( $theme ) . '"' . selected( $this->settings['theme'], $theme, false ) . '>' . esc_html( $name ) . "&nbsp;</option>\n";
1110
+ }
1111
+ ?>
1112
+ </select>
1113
+ </td>
1114
+ </tr>
1115
+ <tr valign="top">
1116
+ <th scope="row"><?php _e( 'Load All Brushes', 'syntaxhighlighter' ); ?></th>
1117
+ <td>
1118
+ <fieldset>
1119
+ <legend class="hidden"><?php _e( 'Load All Brushes', 'syntaxhighlighter' ); ?></legend>
1120
+ <label for="syntaxhighlighter-loadallbrushes"><input name="syntaxhighlighter_settings[loadallbrushes]" type="checkbox" id="syntaxhighlighter-loadallbrushes" value="1" <?php checked( $this->settings['loadallbrushes'], 1 ); ?> /> <?php _e( 'Always load all language files (for directly using <code>&lt;pre&gt;</code> tags rather than shortcodes)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If left unchecked (default), then language files will only be loaded when needed<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If unsure, leave this box unchecked', 'syntaxhighlighter' ); ?></label>
1121
+ </fieldset>
1122
+ </td>
1123
+ </tr>
1124
+ </table>
1125
+
1126
+ <h3><?php _e( 'Defaults', 'syntaxhighlighter' ); ?></h3>
1127
+
1128
+ <p><?php _e( 'All of the settings below can be configured on a per-code block basis, but you can control the defaults of all code blocks here.', 'syntaxhighlighter' ); ?></p>
1129
+
1130
+ <table class="form-table">
1131
+ <tr valign="top">
1132
+ <th scope="row"><?php _e( 'Miscellaneous', 'syntaxhighlighter' ); ?></th>
1133
+ <td>
1134
+ <fieldset>
1135
+ <legend class="hidden"><?php _e( 'Miscellaneous', 'syntaxhighlighter' ); ?></legend>
1136
+
1137
+ <label for="syntaxhighlighter-gutter"><input name="syntaxhighlighter_settings[gutter]" type="checkbox" id="syntaxhighlighter-gutter" value="1" <?php checked( $this->settings['gutter'], 1 ); ?> /> <?php _e( 'Display line numbers', 'syntaxhighlighter' ); ?></label><br />
1138
+ <label for="syntaxhighlighter-toolbar"><input name="syntaxhighlighter_settings[toolbar]" type="checkbox" id="syntaxhighlighter-toolbar" value="1" <?php checked( $this->settings['toolbar'], 1 ); ?> /> <?php _e( 'Display the toolbar', 'syntaxhighlighter' ); ?></label><br />
1139
+ <label for="syntaxhighlighter-autolinks"><input name="syntaxhighlighter_settings[autolinks]" type="checkbox" id="syntaxhighlighter-autolinks" value="1" <?php checked( $this->settings['autolinks'], 1 ); ?> /> <?php _e( 'Automatically make URLs clickable', 'syntaxhighlighter' ); ?></label><br />
1140
+ <label for="syntaxhighlighter-collapse"><input name="syntaxhighlighter_settings[collapse]" type="checkbox" id="syntaxhighlighter-collapse" value="1" <?php checked( $this->settings['collapse'], 1 ); ?> /> <?php _e( 'Collapse code boxes', 'syntaxhighlighter' ); ?></label><br />
1141
+ <label for="syntaxhighlighter-light"><input name="syntaxhighlighter_settings[light]" type="checkbox" id="syntaxhighlighter-light" value="1" <?php checked( $this->settings['light'], 1 ); ?> /> <?php _e( 'Use the light display mode, best for single lines of code', 'syntaxhighlighter' ); ?></label><br />
1142
+ <label for="syntaxhighlighter-smarttabs"><input name="syntaxhighlighter_settings[smarttabs]" type="checkbox" id="syntaxhighlighter-smarttabs" value="1" <?php checked( $this->settings['smarttabs'], 1 ); ?> /> <?php _e( 'Use smart tabs allowing tabs being used for alignment', 'syntaxhighlighter' ); ?></label><br />
1143
+ <label for="syntaxhighlighter-wraplines"><input name="syntaxhighlighter_settings[wraplines]" type="checkbox" id="syntaxhighlighter-wraplines" value="1" <?php checked( $this->settings['wraplines'], 1 ); ?> /> <?php _e( 'Wrap long lines (v2.x only, disabling this will make a scrollbar show instead)', 'syntaxhighlighter' ); ?></label><br />
1144
+ <!--<label for="syntaxhighlighter-htmlscript"><input name="syntaxhighlighter_settings[htmlscript]" type="checkbox" id="syntaxhighlighter-htmlscript" value="1" <?php checked( $this->settings['htmlscript'], 1 ); ?> /> <?php _e( 'Enable &quot;HTML script&quot; mode by default (see the bottom of this page for details). Checking this box is not recommended as this mode only works with certain languages.', 'syntaxhighlighter' ); ?></label>-->
1145
+ </fieldset>
1146
+ </td>
1147
+ </tr>
1148
+ <tr valign="top">
1149
+ <th scope="row"><label for="syntaxhighlighter-classname"><?php _e( 'Additional CSS Class(es)', 'syntaxhighlighter' ); ?></label></th>
1150
+ <td><input name="syntaxhighlighter_settings[classname]" type="text" id="syntaxhighlighter-classname" value="<?php echo esc_attr( $this->settings['classname'] ); ?>" class="regular-text" /></td>
1151
+ </tr>
1152
+ <tr valign="top">
1153
+ <th scope="row"><label for="syntaxhighlighter-firstline"><?php _e( 'Starting Line Number', 'syntaxhighlighter' ); ?></label></th>
1154
+ <td><input name="syntaxhighlighter_settings[firstline]" type="text" id="syntaxhighlighter-firstline" value="<?php echo esc_attr( $this->settings['firstline'] ); ?>" class="small-text" /></td>
1155
+ </tr>
1156
+ <tr valign="top">
1157
+ <th scope="row"><label for="syntaxhighlighter-padlinenumbers"><?php _e( 'Line Number Padding', 'syntaxhighlighter' ); ?></label></th>
1158
+ <td>
1159
+ <select name="syntaxhighlighter_settings[padlinenumbers]" id="syntaxhighlighter-padlinenumbers" class="postform">
1160
+ <?php
1161
+ $linepaddings = array(
1162
+ 'false' => __( 'Off', 'syntaxhighlighter' ),
1163
+ 'true' => __( 'Automatic', 'syntaxhighlighter' ),
1164
+ 1 => 1,
1165
+ 2 => 2,
1166
+ 3 => 3,
1167
+ 4 => 4,
1168
+ 5 => 5,
1169
+ );
1170
+
1171
+ foreach ( $linepaddings as $value => $name ) {
1172
+ echo ' <option value="' . esc_attr( $value ) . '"' . selected( $this->settings['padlinenumbers'], $value, false ) . '>' . esc_html( $name ) . "&nbsp;</option>\n";
1173
+ }
1174
+ ?>
1175
+ </select>
1176
+ </td>
1177
+ </tr>
1178
+ <tr valign="top">
1179
+ <th scope="row"><label for="syntaxhighlighter-tabsize"><?php _e( 'Tab Size', 'syntaxhighlighter' ); ?></label></th>
1180
+ <td><input name="syntaxhighlighter_settings[tabsize]" type="text" id="syntaxhighlighter-tabsize" value="<?php echo esc_attr( $this->settings['tabsize'] ); ?>" class="small-text" /></td>
1181
+ </tr>
1182
+ <tr valign="top">
1183
+ <th scope="row"><label for="syntaxhighlighter-title"><?php _e( 'Title', 'syntaxhighlighter' ); ?></label></th>
1184
+ <td>
1185
+ <input name="syntaxhighlighter_settings[title]" type="text" id="syntaxhighlighter-title" value="<?php echo esc_attr( $this->settings['title'] ); ?>" class="regular-text" /><br />
1186
+ <?php _e( 'Some optional default text to display above each code block or as the clickable text for collapsed code blocks.', 'syntaxhighlighter' ); ?>
1187
+ </td>
1188
+ </tr>
1189
+ </table>
1190
+
1191
+ <p class="submit">
1192
+ <?php
1193
+ if ( function_exists( 'submit_button' ) ) {
1194
+ submit_button( null, 'primary', 'syntaxhighlighter-submit', false );
1195
+ echo ' ';
1196
+ submit_button( __( 'Reset to Defaults', 'syntaxhighlighter' ), 'primary', 'syntaxhighlighter-defaults', false );
1197
+ } else {
1198
+ echo '<input type="submit" name="syntaxhighlighter-submit" class="button-primary" value="' . __( 'Save Changes') . '" />' . "\n";
1199
+ echo '<input type="submit" name="syntaxhighlighter-defaults" id="syntaxhighlighter-defaults" class="button-primary" value="' . __( 'Reset to Defaults', 'syntaxhighlighter' ) . '" />' . "\n";
1200
+ }
1201
+ ?>
1202
+ </p>
1203
+
1204
+ </form>
1205
+
1206
+ <h3><?php _e( 'Preview', 'syntaxhighlighter' ); ?></h3>
1207
+
1208
+ <p><?php _e( 'Click &quot;Save Changes&quot; to update this preview.', 'syntaxhighlighter' ); ?>
1209
+
1210
+ <?php
1211
+
1212
+ echo '<div';
1213
+ if ( ! empty( $GLOBALS['content_width'] ) )
1214
+ echo ' style="max-width:' . intval( $GLOBALS['content_width'] ) . 'px"';
1215
+ echo '>';
1216
+
1217
+ $title = ( empty( $this->settings['title'] ) && 1 != $this->settings['collapse'] ) ? ' title="Code example: (this example was added using the title parameter)"' : '';
1218
+
1219
+ // Site owners may opt to disable the short tags, i.e. [php]
1220
+ $democode = apply_filters( 'syntaxhighlighter_democode', '[sourcecode language="php" htmlscript="true" highlight="12"' . $title . ']<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1221
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
1222
+ <head>
1223
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
1224
+ <title>PHP Code Example</title>
1225
+ </head>
1226
+ <body>
1227
+ <h1>' . __( 'PHP Code Example', 'syntaxhighlighter' ) . '</h1>
1228
+
1229
+ <p><?php echo \'' . __( 'Hello World!', 'syntaxhighlighter' ) . '\'; ?></p>
1230
+
1231
+ <p>' . __( 'This line is highlighted.', 'syntaxhighlighter' ) . '</p>
1232
+
1233
+ <div class="foobar">
1234
+ ' . __( ' This is an
1235
+ example of smart
1236
+ tabs.', 'syntaxhighlighter' ) . '
1237
+ </div>
1238
+
1239
+ <p><a href="http://wordpress.org/">' . __( 'WordPress' ) . '</a></p>
1240
+ </body>
1241
+ </html>[/sourcecode]' );
1242
+
1243
+ $this->codeformat = 1;
1244
+ echo $this->parse_shortcodes( $democode );
1245
+ $this->codeformat = false;
1246
+
1247
+ echo '</div>';
1248
+ ?>
1249
+
1250
+ <h3 style="margin-top:30px"><?php _e( 'Shortcode Parameters', 'syntaxhighlighter' ); ?></h3>
1251
+
1252
+ <p><?php printf( __( 'These are the parameters you can pass to the shortcode and what they do. For the booleans (i.e. on/off), pass %1$s/%2$s or %3$s/%4$s.', 'syntaxhighlighter' ), '<code>true</code>', '<code>1</code>', '<code>false</code>', '<code>0</code>' ); ?></p>
1253
+
1254
+ <ul class="ul-disc">
1255
+ <li><?php printf( _x( '%1$s or %2$s &#8212; The language syntax to highlight with. You can alternately just use that as the tag, such as <code>[php]code[/php]</code>. <a href="%3$s">Click here</a> for a list of valid tags (under &quot;aliases&quot;).', 'language parameter', 'syntaxhighlighter' ), '<code>lang</code>', '<code>language</code>', 'http://alexgorbatchev.com/wiki/SyntaxHighlighter:Brushes' ); ?></li>
1256
+ <li><?php printf( _x( '%s &#8212; Toggle automatic URL linking.', 'autolinks parameter', 'syntaxhighlighter' ), '<code>autolinks</code>' ); ?></li>
1257
+ <li><?php printf( _x( '%s &#8212; Add an additional CSS class to the code box.', 'classname parameter', 'syntaxhighlighter' ), '<code>classname</code>' ); ?></li>
1258
+ <li><?php printf( _x( '%s &#8212; Toggle collapsing the code box by default, requiring a click to expand it. Good for large code posts.', 'collapse parameter', 'syntaxhighlighter' ), '<code>collapse</code>' ); ?></li>
1259
+ <li><?php printf( _x( '%s &#8212; An interger specifying what number the first line should be (for the line numbering).', 'firstline parameter', 'syntaxhighlighter' ), '<code>firstline</code>' ); ?></li>
1260
+ <li><?php printf( _x( '%s &#8212; Toggle the left-side line numbering.', 'gutter parameter', 'syntaxhighlighter' ), '<code>gutter</code>' ); ?></li>
1261
+ <li><?php printf( _x( '%1$s &#8212; A comma-separated list of line numbers to highlight. You can also specify a range. Example: %2$s', 'highlight parameter', 'syntaxhighlighter' ), '<code>highlight</code>', '<code>2,5-10,12</code>' ); ?></li>
1262
+ <li><?php printf( _x( "%s &#8212; Toggle highlighting any extra HTML/XML. Good for when you're mixing HTML/XML with another language, such as having PHP inside an HTML web page. The above preview has it enabled for example. This only works with certain languages.", 'htmlscript parameter', 'syntaxhighlighter' ), '<code>htmlscript</code>' ); ?></li>
1263
+ <li><?php printf( _x( '%s &#8212; Toggle light mode which disables the gutter and toolbar all at once.', 'light parameter', 'syntaxhighlighter' ), '<code>light</code>' ); ?></li>
1264
+ <li><?php printf( _x( '%s &#8212; Controls line number padding. Valid values are <code>false</code> (no padding), <code>true</code> (automatic padding), or an integer (forced padding).', 'padlinenumbers parameter', 'syntaxhighlighter' ), '<code>padlinenumbers</code>' ); ?></li>
1265
+ <li><?php printf( _x( '%1$s (v3 only) &#8212; Sets some text to show up before the code. Very useful when combined with the %2$s parameter.', 'title parameter', 'syntaxhighlighter' ), '<code>title</code>', '<code>collapse</code>' ); ?></li>
1266
+ <li><?php printf( _x( '%s &#8212; Toggle the toolbar (buttons in v2, the about question mark in v3)', 'toolbar parameter', 'syntaxhighlighter' ), '<code>toolbar</code>' ); ?></li>
1267
+ <li><?php printf( _x( '%s (v2 only) &#8212; Toggle line wrapping.', 'wraplines parameter', 'syntaxhighlighter'), '<code>wraplines</code>' ); ?></li>
1268
+ </ul>
1269
+
1270
+ <p><?php _e( 'Some example shortcodes:', 'syntaxhighlighter' ); ?></p>
1271
+
1272
+ <ul class="ul-disc">
1273
+ <li><code>[php]<?php _e( 'your code here', 'syntaxhighlighter' ); ?>[/php]</code></li>
1274
+ <li><code>[css autolinks=&quot;false&quot; classname=&quot;myclass&quot; collapse=&quot;false&quot; firstline=&quot;1&quot; gutter=&quot;true&quot; highlight=&quot;1-3,6,9&quot; htmlscript=&quot;false&quot; light=&quot;false&quot; padlinenumbers=&quot;false&quot; smarttabs=&quot;true&quot; tabsize=&quot;4&quot; toolbar=&quot;true&quot; title=&quot;<?php _e( 'example-filename.php', 'syntaxhighlighter' ); ?>&quot;]<?php _e( 'your code here', 'syntaxhighlighter' ); ?>[/css]</code></li>
1275
+ <li><code>[code lang=&quot;js&quot;]<?php _e( 'your code here', 'syntaxhighlighter' ); ?>[/code]</code></li>
1276
+ <li><code>[sourcecode language=&quot;plain&quot;]<?php _e( 'your code here', 'syntaxhighlighter' ); ?>[/sourcecode]</code></li>
1277
+ </ul>
1278
+
1279
+ <?php $this->maybe_output_scripts(); ?>
1280
+
1281
+ </div>
1282
+
1283
+ <?php
1284
+ }
1285
+
1286
+
1287
+ // Validate the settings sent from the settings page
1288
+ function validate_settings( $settings ) {
1289
+ if ( !empty($_POST['syntaxhighlighter-defaults']) ) {
1290
+ $settings = $this->defaultsettings;
1291
+ $_REQUEST['_wp_http_referer'] = add_query_arg( 'defaults', 'true', $_REQUEST['_wp_http_referer'] );
1292
+ } else {
1293
+ $settings['shversion'] = ( ! empty($settings['shversion']) && 2 == $settings['shversion'] ) ? 2 : 3;
1294
+
1295
+ $settings['theme'] = ( ! empty($settings['theme']) && isset($this->themes[$settings['theme']]) ) ? strtolower($settings['theme']) : $this->defaultsettings['theme'];
1296
+
1297
+ $settings['loadallbrushes'] = ( ! empty($settings['loadallbrushes']) ) ? 1 : 0;
1298
+ $settings['autolinks'] = ( ! empty($settings['autolinks']) ) ? 1 : 0;
1299
+ $settings['collapse'] = ( ! empty($settings['collapse']) ) ? 1 : 0;
1300
+ $settings['gutter'] = ( ! empty($settings['gutter']) ) ? 1 : 0;
1301
+ $settings['light'] = ( ! empty($settings['light']) ) ? 1 : 0;
1302
+ $settings['smarttabs'] = ( ! empty($settings['smarttabs']) ) ? 1 : 0;
1303
+ $settings['toolbar'] = ( ! empty($settings['toolbar']) ) ? 1 : 0; // May be overridden below
1304
+ $settings['wraplines'] = ( ! empty($settings['wraplines']) ) ? 1 : 0; // 2.x only for now
1305
+
1306
+ // If the version changed, then force change the toolbar version setting
1307
+ if ( $settings['shversion'] != $this->settings['shversion'] ) {
1308
+ $settings['toolbar'] = ( 2 == $settings['shversion'] ) ? 1 : 0;
1309
+ }
1310
+
1311
+ if ( 'true' != $settings['padlinenumbers'] && 'false' != $settings['padlinenumbers'] )
1312
+ $settings['padlinenumbers'] = (int) $settings['padlinenumbers'];
1313
+
1314
+ $settings['classname'] = ( !empty($settings['classname']) ) ? preg_replace( '/[^ A-Za-z0-9_-]*/', '', $settings['classname'] ) : '';
1315
+ $settings['firstline'] = (int) ( ( !empty($settings['firstline']) ) ? $settings['firstline'] : $this->defaultsettings['firstline'] );
1316
+ $settings['tabsize'] = (int) ( ( !empty($settings['tabsize']) ) ? $settings['tabsize'] : $this->defaultsettings['tabsize'] );
1317
+ }
1318
+
1319
+ return $settings;
1320
+ }
1321
+ }
1322
+
1323
+
1324
+ // Start this plugin once all other plugins are fully loaded
1325
+ add_action( 'init', 'SyntaxHighlighter', 5 );
1326
+ function SyntaxHighlighter() {
1327
+ global $SyntaxHighlighter;
1328
+ $SyntaxHighlighter = new SyntaxHighlighter();
1329
  }