Crayon Syntax Highlighter - Version 1.5.2

Version Description

  • Proper enquing of themes via wordpress, should cause no more issues with any themes
  • Cached images for toolbar items, no delay on mouseover
  • Fixed a minor regex bug in js preventing styles from being removed when in popup
Download this release

Release Info

Developer akarmenia
Plugin Icon wp plugin Crayon Syntax Highlighter
Version 1.5.2
Comparing to
See all releases

Code changes from version 1.5.1 to 1.5.2

crayon_formatter.class.php CHANGED
@@ -204,9 +204,13 @@ class CrayonFormatter {
204
  is not enabled or fails, the toolbar won't work so there is no point to display it. */
205
 
206
  $buttons = $print_nums_button.$print_copy_button.$print_popup_button.$print_plain_button.$print_lang;
 
 
 
 
207
  $toolbar = '
208
  <div class="crayon-toolbar" settings="'.$toolbar_settings.'">'.$print_title.'
209
- <div class="crayon-tools">'.$buttons.'</div>
210
  </div><div>'.$print_plain.'</div>'.'<div class="crayon-info"></div>';
211
 
212
  } else {
@@ -234,15 +238,15 @@ class CrayonFormatter {
234
  $theme_id_dashed = CrayonUtil::clean_css_name($theme_id);
235
 
236
  // Only load css once for each theme
237
- if (!empty($theme_id) && $theme != NULL /*&& !$theme->used()*/) {
238
- // Record usage
239
  $theme->used(TRUE);
240
  if ($print) {
241
  // Add style
242
  $url = CrayonGlobalSettings::plugin_path() . CrayonUtil::pathf(CRAYON_THEME_DIR) . $theme_id . '/' . $theme_id . '.css?ver' . $CRAYON_VERSION;
243
  $output .= '<link rel="stylesheet" type="text/css" href="' . $url . '" />' . CRAYON_NL;
244
  }
245
- }
246
 
247
  // Load font css if not default
248
  $font_id = $hl->setting_val(CrayonSettings::FONT);
204
  is not enabled or fails, the toolbar won't work so there is no point to display it. */
205
 
206
  $buttons = $print_nums_button.$print_copy_button.$print_popup_button.$print_plain_button.$print_lang;
207
+ $button_preload = '';
208
+ foreach (array('nums', 'copy', 'popup', 'plain') as $name) {
209
+ $button_preload .= '<a href="#" class="crayon-'.$name.'-button crayon-button crayon-pressed crayon-invisible"></a>';
210
+ }
211
  $toolbar = '
212
  <div class="crayon-toolbar" settings="'.$toolbar_settings.'">'.$print_title.'
213
+ <div class="crayon-tools">'.$buttons.$button_preload.'</div>
214
  </div><div>'.$print_plain.'</div>'.'<div class="crayon-info"></div>';
215
 
216
  } else {
238
  $theme_id_dashed = CrayonUtil::clean_css_name($theme_id);
239
 
240
  // Only load css once for each theme
241
+ //if (!empty($theme_id) && $theme != NULL /*&& !$theme->used()*/) {
242
+ /* // Record usage
243
  $theme->used(TRUE);
244
  if ($print) {
245
  // Add style
246
  $url = CrayonGlobalSettings::plugin_path() . CrayonUtil::pathf(CRAYON_THEME_DIR) . $theme_id . '/' . $theme_id . '.css?ver' . $CRAYON_VERSION;
247
  $output .= '<link rel="stylesheet" type="text/css" href="' . $url . '" />' . CRAYON_NL;
248
  }
249
+ }*/
250
 
251
  // Load font css if not default
252
  $font_id = $hl->setting_val(CrayonSettings::FONT);
crayon_themes.class.php CHANGED
@@ -25,16 +25,30 @@ class CrayonThemes extends CrayonUsedResourceCollection {
25
  }
26
 
27
  // Prints out CSS for all the used themes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  public function get_used_theme_css() {
29
- global $CRAYON_VERSION;
30
  $used = $this->get_used();
31
- $css = '';
32
  foreach ($used as $theme) {
33
- if (!in_array($theme, $this->printed_themes)) {
34
- $url = CrayonGlobalSettings::plugin_path() . CrayonUtil::pathf(CRAYON_THEME_DIR) . $theme->id() . '/' . $theme->id() . '.css?ver' . $CRAYON_VERSION;
35
- $css .= '<link rel="stylesheet" type="text/css" href="' . $url . '" />' . CRAYON_NL;
36
- $this->printed_themes[] = $theme;
37
- }
38
  }
39
  return $css;
40
  }
25
  }
26
 
27
  // Prints out CSS for all the used themes
28
+ public function get_used_theme_css_str() {
29
+ $css_str = '';
30
+ $css = self::get_used_theme_css();
31
+ foreach ($css as $theme=>$url) {
32
+ $css_str .= '<link rel="stylesheet" type="text/css" href="' . $css[$url] . '" />' . CRAYON_NL;
33
+ }
34
+ return $css_str;
35
+ }
36
+
37
+ public function get_theme_url($theme) {
38
+ return CrayonGlobalSettings::plugin_path() . CrayonUtil::pathf(CRAYON_THEME_DIR) . $theme->id() . '/' . $theme->id() . '.css';
39
+ }
40
+
41
+ public function get_theme_as_css($theme) {
42
+ $css_str = '<link rel="stylesheet" type="text/css" href="' . self::get_theme_url($theme) . '" />' . CRAYON_NL;
43
+ return $css_str;
44
+ }
45
+
46
  public function get_used_theme_css() {
 
47
  $used = $this->get_used();
48
+ $css = array();
49
  foreach ($used as $theme) {
50
+ $url = self::get_theme_url($theme);
51
+ $css[$theme->id()] = $url;
 
 
 
52
  }
53
  return $css;
54
  }
crayon_wp.class.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Crayon Syntax Highlighter
4
  Plugin URI: http://ak.net84.net/
5
  Description: Supports multiple languages, themes, highlighting from a URL, local file or post text. <a href="options-general.php?page=crayon_settings">View Settings.</a>
6
- Version: 1.5.1
7
  Author: Aram Kocharyan
8
  Author URI: http://ak.net84.net/
9
  License: GPL2
@@ -74,8 +74,6 @@ class CrayonWP {
74
  * Adds the actual Crayon instance, should only be called by add_shortcode()
75
  */
76
  private static function shortcode($atts, $content = NULL, $id = NULL) {
77
- CrayonSettingsWP::load_settings(); // Run first to ensure global settings loaded
78
-
79
  // Lowercase attributes
80
  $lower_atts = array();
81
  foreach ($atts as $att=>$value) {
@@ -166,6 +164,8 @@ class CrayonWP {
166
 
167
  if ( count($matches[0]) != 0 ) {
168
  // Crayons found!
 
 
169
  $full_matches = $matches[0];
170
  $closed_ids = $matches[1];
171
  $closed_atts = $matches[2];
@@ -176,6 +176,10 @@ class CrayonWP {
176
  // Make sure we enqueue the styles/scripts
177
  $enqueue = TRUE;
178
 
 
 
 
 
179
  for ($i = 0; $i < count($full_matches); $i++) {
180
  // Get attributes
181
  if ( !empty($closed_atts[$i]) ) {
@@ -195,12 +199,18 @@ class CrayonWP {
195
  }
196
  }
197
 
 
 
 
 
 
 
 
198
  // Add array of atts and content to post queue with key as post ID
199
  $id = !empty($open_ids[$i]) ? $open_ids[$i] : $closed_ids[$i];
200
  self::$post_queue[strval($post->ID)][$id] = array('post_id'=>$post->ID, 'atts'=>$atts_array, 'code'=>$contents[$i]);
201
  }
202
  }
203
-
204
  }
205
 
206
  if (!is_admin() && $enqueue && !self::$included) {
@@ -221,6 +231,12 @@ class CrayonWP {
221
  private static function enqueue_resources() {
222
  global $CRAYON_VERSION;
223
  wp_enqueue_style('crayon-style', plugins_url(CRAYON_STYLE, __FILE__), array(), $CRAYON_VERSION);
 
 
 
 
 
 
224
  wp_enqueue_script('crayon-jquery', plugins_url(CRAYON_JQUERY, __FILE__), array(), $CRAYON_VERSION);
225
  wp_enqueue_script('crayon-js', plugins_url(CRAYON_JS, __FILE__), array('crayon-jquery'), $CRAYON_VERSION);
226
  wp_enqueue_script('crayon-jquery-popup', plugins_url(CRAYON_JQUERY_POPUP, __FILE__), array('crayon-jquery'), $CRAYON_VERSION);
@@ -285,7 +301,11 @@ class CrayonWP {
285
  }
286
 
287
  public static function crayon_theme_css() {
288
- echo CrayonResources::themes()->get_used_theme_css();
 
 
 
 
289
  }
290
  }
291
 
@@ -298,7 +318,7 @@ if (defined('ABSPATH')) {
298
  add_filter('the_posts', 'CrayonWP::the_posts');
299
  add_filter('the_content', 'CrayonWP::the_content');
300
  add_filter('the_excerpt', 'CrayonWP::the_excerpt');
301
- add_action('loop_end', 'CrayonWP::crayon_theme_css');
302
  //add_action('get_footer', 'CrayonWP::crayon_theme_css');
303
  }
304
  ?>
3
  Plugin Name: Crayon Syntax Highlighter
4
  Plugin URI: http://ak.net84.net/
5
  Description: Supports multiple languages, themes, highlighting from a URL, local file or post text. <a href="options-general.php?page=crayon_settings">View Settings.</a>
6
+ Version: 1.5.2
7
  Author: Aram Kocharyan
8
  Author URI: http://ak.net84.net/
9
  License: GPL2
74
  * Adds the actual Crayon instance, should only be called by add_shortcode()
75
  */
76
  private static function shortcode($atts, $content = NULL, $id = NULL) {
 
 
77
  // Lowercase attributes
78
  $lower_atts = array();
79
  foreach ($atts as $att=>$value) {
164
 
165
  if ( count($matches[0]) != 0 ) {
166
  // Crayons found!
167
+ CrayonSettingsWP::load_settings(); // Run first to ensure global settings loaded
168
+
169
  $full_matches = $matches[0];
170
  $closed_ids = $matches[1];
171
  $closed_atts = $matches[2];
176
  // Make sure we enqueue the styles/scripts
177
  $enqueue = TRUE;
178
 
179
+ // Mark the default theme as being used
180
+ $default_theme = CrayonResources::themes()->get_default();
181
+ $default_theme->used(TRUE);
182
+
183
  for ($i = 0; $i < count($full_matches); $i++) {
184
  // Get attributes
185
  if ( !empty($closed_atts[$i]) ) {
199
  }
200
  }
201
 
202
+ // Detect if a theme is used
203
+ if (array_key_exists('theme', $atts_array)) {
204
+ $theme_id = $atts_array['theme'];
205
+ $theme = CrayonResources::themes()->get($theme_id);
206
+ $theme->used(TRUE);
207
+ }
208
+
209
  // Add array of atts and content to post queue with key as post ID
210
  $id = !empty($open_ids[$i]) ? $open_ids[$i] : $closed_ids[$i];
211
  self::$post_queue[strval($post->ID)][$id] = array('post_id'=>$post->ID, 'atts'=>$atts_array, 'code'=>$contents[$i]);
212
  }
213
  }
 
214
  }
215
 
216
  if (!is_admin() && $enqueue && !self::$included) {
231
  private static function enqueue_resources() {
232
  global $CRAYON_VERSION;
233
  wp_enqueue_style('crayon-style', plugins_url(CRAYON_STYLE, __FILE__), array(), $CRAYON_VERSION);
234
+
235
+ $css = CrayonResources::themes()->get_used_theme_css();
236
+ foreach ($css as $theme=>$url) {
237
+ wp_enqueue_style('crayon-theme-'.$theme, $url, array(), $CRAYON_VERSION);
238
+ }
239
+
240
  wp_enqueue_script('crayon-jquery', plugins_url(CRAYON_JQUERY, __FILE__), array(), $CRAYON_VERSION);
241
  wp_enqueue_script('crayon-js', plugins_url(CRAYON_JS, __FILE__), array('crayon-jquery'), $CRAYON_VERSION);
242
  wp_enqueue_script('crayon-jquery-popup', plugins_url(CRAYON_JQUERY_POPUP, __FILE__), array('crayon-jquery'), $CRAYON_VERSION);
301
  }
302
 
303
  public static function crayon_theme_css() {
304
+ global $CRAYON_VERSION;
305
+ $css = CrayonResources::themes()->get_used_theme_css();
306
+ foreach ($css as $theme=>$url) {
307
+ wp_enqueue_style('crayon-theme-'.$theme, $url, array(), $CRAYON_VERSION);
308
+ }
309
  }
310
  }
311
 
318
  add_filter('the_posts', 'CrayonWP::the_posts');
319
  add_filter('the_content', 'CrayonWP::the_content');
320
  add_filter('the_excerpt', 'CrayonWP::the_excerpt');
321
+ //add_action('loop_end', 'CrayonWP::crayon_theme_css');
322
  //add_action('get_footer', 'CrayonWP::crayon_theme_css');
323
  }
324
  ?>
css/style.css CHANGED
@@ -135,7 +135,7 @@ coloring etc.
135
  }
136
 
137
  .crayon-syntax .crayon-toolbar a.crayon-button {
138
- display: inline !important;
139
  float: left !important;
140
  min-width: 20px;
141
 
135
  }
136
 
137
  .crayon-syntax .crayon-toolbar a.crayon-button {
138
+ display: inline;
139
  float: left !important;
140
  min-width: 20px;
141
 
js/crayon.js CHANGED
@@ -231,7 +231,7 @@ function get_jquery_str(object) {
231
  }
232
 
233
  function remove_css_inline(string) {
234
- return string.replace(/style="[^"]+"/mi, '');
235
  }
236
 
237
  // Get all CSS on the page as a string
231
  }
232
 
233
  function remove_css_inline(string) {
234
+ return string.replace(/style\s*=\s*"[^"]+"/mi, '');
235
  }
236
 
237
  // Get all CSS on the page as a string
log.txt CHANGED
@@ -1,18 +0,0 @@
1
- ==============================================================================
2
- Crayon Syntax Highlighter Log Entry
3
- ==============================================================================
4
- 4:23:40 AM - 08 Nov 2011
5
- string(55) "The specified URL is empty, please provide a valid URL."
6
- ------------------------------------------------------------------------------
7
- ==============================================================================
8
- Crayon Syntax Highlighter Log Entry
9
- ==============================================================================
10
- 4:24:23 AM - 08 Nov 2011
11
- string(55) "The specified URL is empty, please provide a valid URL."
12
- ------------------------------------------------------------------------------
13
- ==============================================================================
14
- Crayon Syntax Highlighter Log Entry
15
- ==============================================================================
16
- 4:24:41 AM - 08 Nov 2011
17
- string(55) "The specified URL is empty, please provide a valid URL."
18
- ------------------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://ak.net84.net/
4
  Tags: syntax highlighter, syntax, highlighter, highlighting, crayon, code highlighter
5
  Requires at least: 3.0
6
  Tested up to: 3.3
7
- Stable tag: 1.5.1
8
 
9
  Syntax Highlighter supporting multiple languages, themes, fonts, highlighting from a URL, local file or post text.
10
 
@@ -90,6 +90,11 @@ Contact me at http://twitter.com/crayonsyntax or crayon.syntax@gmail.com.
90
 
91
  == Changelog ==
92
 
 
 
 
 
 
93
  = 1.5.1 =
94
  * Fixed plain code toggle button update
95
 
4
  Tags: syntax highlighter, syntax, highlighter, highlighting, crayon, code highlighter
5
  Requires at least: 3.0
6
  Tested up to: 3.3
7
+ Stable tag: 1.5.2
8
 
9
  Syntax Highlighter supporting multiple languages, themes, fonts, highlighting from a URL, local file or post text.
10
 
90
 
91
  == Changelog ==
92
 
93
+ = 1.5.2 =
94
+ * Proper enquing of themes via wordpress, should cause no more issues with any themes
95
+ * Cached images for toolbar items, no delay on mouseover
96
+ * Fixed a minor regex bug in js preventing styles from being removed when in popup
97
+
98
  = 1.5.1 =
99
  * Fixed plain code toggle button update
100
 
util/preview.php CHANGED
@@ -23,8 +23,13 @@ $settings = array(CrayonSettings::TOP_SET => TRUE, CrayonSettings::TOP_MARGIN =>
23
  CrayonSettings::BOTTOM_SET => FALSE, CrayonSettings::BOTTOM_MARGIN => 0);
24
  $crayon->settings($settings);
25
 
26
- $lang = $crayon->setting_val(CrayonSettings::FALLBACK_LANG);
 
 
 
27
 
 
 
28
  $path = crayon_pf( dirname(__FILE__) . '/sample/' . $lang . '.txt', FALSE );
29
 
30
  if ($lang && @file_exists($path)) {
23
  CrayonSettings::BOTTOM_SET => FALSE, CrayonSettings::BOTTOM_MARGIN => 0);
24
  $crayon->settings($settings);
25
 
26
+ // Print the theme CSS
27
+ $theme_id = $crayon->setting_val(CrayonSettings::THEME);
28
+ $theme = CrayonResources::themes()->get($theme_id);
29
+ echo CrayonThemes::get_theme_as_css($theme);
30
 
31
+ // Load custom code based on language
32
+ $lang = $crayon->setting_val(CrayonSettings::FALLBACK_LANG);
33
  $path = crayon_pf( dirname(__FILE__) . '/sample/' . $lang . '.txt', FALSE );
34
 
35
  if ($lang && @file_exists($path)) {