Version Description
Download this release
Release Info
Developer | Viper007Bond |
Plugin | SyntaxHighlighter Evolved |
Version | 3.2.1 |
Comparing to | |
See all releases |
Code changes from version 3.2.0 to 3.2.1
- readme.md +0 -7
- readme.txt +4 -0
- 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.
|
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.
|
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' => '\0',
|
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
|
352 |
-
* @param string $callback
|
353 |
-
*
|
354 |
-
*
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
$
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
*
|
412 |
-
*
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
$
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
}
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
$
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
function
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
$
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
}
|
611 |
-
|
612 |
-
|
613 |
-
//
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
if (
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
//
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
$
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
//
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
//
|
897 |
-
$
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
'
|
908 |
-
'
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
?>
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
<
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
<
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
);
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
<
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
<
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
echo
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
<
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
</
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
</
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
}
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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' => '\0',
|
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 ) . " </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 ) . " </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><pre></code> tags rather than shortcodes)<br /> If left unchecked (default), then language files will only be loaded when needed<br /> 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 "HTML script" 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 ) . " </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 "Save Changes" 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 — 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 "aliases").', 'language parameter', 'syntaxhighlighter' ), '<code>lang</code>', '<code>language</code>', 'http://alexgorbatchev.com/wiki/SyntaxHighlighter:Brushes' ); ?></li>
|
1256 |
+
<li><?php printf( _x( '%s — Toggle automatic URL linking.', 'autolinks parameter', 'syntaxhighlighter' ), '<code>autolinks</code>' ); ?></li>
|
1257 |
+
<li><?php printf( _x( '%s — Add an additional CSS class to the code box.', 'classname parameter', 'syntaxhighlighter' ), '<code>classname</code>' ); ?></li>
|
1258 |
+
<li><?php printf( _x( '%s — 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 — 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 — Toggle the left-side line numbering.', 'gutter parameter', 'syntaxhighlighter' ), '<code>gutter</code>' ); ?></li>
|
1261 |
+
<li><?php printf( _x( '%1$s — 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 — 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 — 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 — 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) — 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 — 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) — 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="false" classname="myclass" collapse="false" firstline="1" gutter="true" highlight="1-3,6,9" htmlscript="false" light="false" padlinenumbers="false" smarttabs="true" tabsize="4" toolbar="true" title="<?php _e( 'example-filename.php', 'syntaxhighlighter' ); ?>"]<?php _e( 'your code here', 'syntaxhighlighter' ); ?>[/css]</code></li>
|
1275 |
+
<li><code>[code lang="js"]<?php _e( 'your code here', 'syntaxhighlighter' ); ?>[/code]</code></li>
|
1276 |
+
<li><code>[sourcecode language="plain"]<?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 |
}
|