Crayon Syntax Highlighter - Version 1.1.0

Version Description

Download this release

Release Info

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

Code changes from version 1.0.3 to 1.1.0

crayon_formatter.class.php CHANGED
@@ -38,8 +38,11 @@ class CrayonFormatter {
38
  $error = 'An error occured when formatting: ' . $e->message();
39
  $hl ? $hl->log($error) : CrayonLog::syslog($error);
40
  }
 
 
 
 
41
  }
42
- return $code;
43
  }
44
 
45
  /* Performs a replace to format each match based on the captured element. */
38
  $error = 'An error occured when formatting: ' . $e->message();
39
  $hl ? $hl->log($error) : CrayonLog::syslog($error);
40
  }
41
+
42
+ return $code;
43
+ } else {
44
+ return self::clean_code($code);
45
  }
 
46
  }
47
 
48
  /* Performs a replace to format each match based on the captured element. */
crayon_highlighter.class.php CHANGED
@@ -151,10 +151,6 @@ class CrayonHighlighter {
151
  /* Sends the code to the formatter for printing. Apart from the getters and setters, this is
152
  the only other function accessible outside this class. $show_lines can also be a string. */
153
  function output($highlight = TRUE, $show_lines = TRUE, $print = TRUE) {
154
- if ( !$this->settings->val(CrayonSettings::HIGHLIGHT) ) {
155
- // Disable highlight
156
- $highlight = FALSE;
157
- }
158
  $this->process($highlight);
159
  if (empty($this->error)) {
160
  // If no errors have occured, print the formatted code
@@ -279,6 +275,7 @@ class CrayonHighlighter {
279
  return $this->settings->get($mixed);
280
  } else if (is_array($mixed)) {
281
  $this->settings->set($mixed);
 
282
  return TRUE;
283
  }
284
  return FALSE;
151
  /* Sends the code to the formatter for printing. Apart from the getters and setters, this is
152
  the only other function accessible outside this class. $show_lines can also be a string. */
153
  function output($highlight = TRUE, $show_lines = TRUE, $print = TRUE) {
 
 
 
 
154
  $this->process($highlight);
155
  if (empty($this->error)) {
156
  // If no errors have occured, print the formatted code
275
  return $this->settings->get($mixed);
276
  } else if (is_array($mixed)) {
277
  $this->settings->set($mixed);
278
+
279
  return TRUE;
280
  }
281
  return FALSE;
crayon_settings.class.php CHANGED
@@ -63,7 +63,6 @@ class CrayonSettings {
63
  const ERROR_MSG_SHOW = 'error-msg-show';
64
  const ERROR_MSG = 'error-msg';
65
  const HIDE_HELP = 'hide-help';
66
- const HIGHLIGHT = 'highlight';
67
 
68
  // The current settings, should be loaded with default if none exists
69
  private $settings = array();
@@ -138,9 +137,9 @@ class CrayonSettings {
138
  new CrayonSetting(self::ERROR_LOG_SYS, TRUE),
139
  new CrayonSetting(self::ERROR_MSG_SHOW, TRUE),
140
  new CrayonSetting(self::ERROR_MSG, 'An error has occurred. Please try again later.'),
141
- new CrayonSetting(self::HIDE_HELP, FALSE),
142
- new CrayonSetting(self::HIGHLIGHT, TRUE)
143
  );
 
144
  $this->set($settings);
145
  }
146
 
@@ -267,6 +266,7 @@ class CrayonSettings {
267
  if (!is_string($name)) {
268
  return '';
269
  }
 
270
  // Type-cast to correct value for known settings
271
  if (($setting = CrayonGlobalSettings::get($name)) != FALSE) {
272
  // Booleans settings that are sent as string are allowed to have "false" == false
@@ -425,12 +425,6 @@ class CrayonGlobalSettings {
425
  }
426
 
427
  public static function val($name = NULL) {
428
- /*self::init();
429
- if (($setting = self::get($name)) != FALSE) {
430
- return $setting->value();
431
- } else {
432
- return NULL;
433
- }*/
434
  return self::$global->val($name);
435
  }
436
 
@@ -498,7 +492,7 @@ class CrayonSetting {
498
  }
499
 
500
  function copy() {
501
- return new CrayonSetting($this->name, $this->default, $this->value);
502
  }
503
 
504
  function name($name = NULL) {
@@ -540,7 +534,7 @@ class CrayonSetting {
540
  } else {
541
  return $this->default;
542
  }
543
- } else {
544
  if ($this->is_array) {
545
  $this->index($value); // $value is index
546
  } else {
63
  const ERROR_MSG_SHOW = 'error-msg-show';
64
  const ERROR_MSG = 'error-msg';
65
  const HIDE_HELP = 'hide-help';
 
66
 
67
  // The current settings, should be loaded with default if none exists
68
  private $settings = array();
137
  new CrayonSetting(self::ERROR_LOG_SYS, TRUE),
138
  new CrayonSetting(self::ERROR_MSG_SHOW, TRUE),
139
  new CrayonSetting(self::ERROR_MSG, 'An error has occurred. Please try again later.'),
140
+ new CrayonSetting(self::HIDE_HELP, FALSE)
 
141
  );
142
+
143
  $this->set($settings);
144
  }
145
 
266
  if (!is_string($name)) {
267
  return '';
268
  }
269
+
270
  // Type-cast to correct value for known settings
271
  if (($setting = CrayonGlobalSettings::get($name)) != FALSE) {
272
  // Booleans settings that are sent as string are allowed to have "false" == false
425
  }
426
 
427
  public static function val($name = NULL) {
 
 
 
 
 
 
428
  return self::$global->val($name);
429
  }
430
 
492
  }
493
 
494
  function copy() {
495
+ return new CrayonSetting($this->name, $this->default, $this->value, $this->locked);
496
  }
497
 
498
  function name($name = NULL) {
534
  } else {
535
  return $this->default;
536
  }
537
+ } else if ($this->locked === FALSE) {
538
  if ($this->is_array) {
539
  $this->index($value); // $value is index
540
  } else {
crayon_settings_wp.class.php CHANGED
@@ -101,7 +101,7 @@ class CrayonSettingsWP {
101
 
102
  // Initialise default global settings and update them from db
103
  CrayonGlobalSettings::set(self::$options);
104
-
105
  // Load all available languages and themes
106
  CrayonResources::langs()->load();
107
  CrayonResources::themes()->load();
101
 
102
  // Initialise default global settings and update them from db
103
  CrayonGlobalSettings::set(self::$options);
104
+
105
  // Load all available languages and themes
106
  CrayonResources::langs()->load();
107
  CrayonResources::themes()->load();
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.0.3
7
  Author: Aram Kocharyan
8
  Author URI: http://ak.net84.net/
9
  License: GPL2
@@ -63,6 +63,15 @@ class CrayonWP {
63
  private static function shortcode($atts, $content = NULL) {
64
  CrayonSettingsWP::load_settings(); // Run first to ensure global settings loaded
65
 
 
 
 
 
 
 
 
 
 
66
  // Load attributes from shortcode
67
  $allowed_atts = array('url' => NULL, 'lang' => NULL, 'title' => NULL, 'mark' => NULL);
68
  $filtered_atts = shortcode_atts($allowed_atts, $atts);
@@ -97,13 +106,18 @@ class CrayonWP {
97
  $crayon->language($lang);
98
  $crayon->title($title);
99
  $crayon->marked($mark);
100
- return $crayon->output($highlight = true, $nums = true, $print = false);
 
 
 
 
101
  }
102
 
103
  /* Returns Crayon instance */
104
  public static function instance($extra_attr = array()) {
105
  // Create Crayon
106
  $crayon = new CrayonHighlighter();
 
107
  /* Load settings and merge shortcode attributes which will override any existing.
108
  * Stores the other shortcode attributes as settings in the crayon. */
109
  if (!empty($extra_attr)) {
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.1
7
  Author: Aram Kocharyan
8
  Author URI: http://ak.net84.net/
9
  License: GPL2
63
  private static function shortcode($atts, $content = NULL) {
64
  CrayonSettingsWP::load_settings(); // Run first to ensure global settings loaded
65
 
66
+ // Lowercase attributes
67
+ $lower_atts = array();
68
+ foreach ($atts as $att=>$value) {
69
+ $lower_atts[trim(strip_tags(strtolower($att)))] = $value;
70
+ }
71
+ $atts = $lower_atts;
72
+
73
+ //echo count($atts);
74
+
75
  // Load attributes from shortcode
76
  $allowed_atts = array('url' => NULL, 'lang' => NULL, 'title' => NULL, 'mark' => NULL);
77
  $filtered_atts = shortcode_atts($allowed_atts, $atts);
106
  $crayon->language($lang);
107
  $crayon->title($title);
108
  $crayon->marked($mark);
109
+
110
+ // Determine if we should highlight
111
+ $highlight = array_key_exists('highlight', $atts) ? CrayonUtil::str_to_bool($atts['highlight'], FALSE) : TRUE;
112
+
113
+ return $crayon->output($highlight, $nums = true, $print = false);
114
  }
115
 
116
  /* Returns Crayon instance */
117
  public static function instance($extra_attr = array()) {
118
  // Create Crayon
119
  $crayon = new CrayonHighlighter();
120
+
121
  /* Load settings and merge shortcode attributes which will override any existing.
122
  * Stores the other shortcode attributes as settings in the crayon. */
123
  if (!empty($extra_attr)) {
global.php CHANGED
@@ -8,8 +8,8 @@ define('CRAYON_DEBUG', FALSE); // Enable to show exceptions on screen
8
 
9
  $uid = CRAYON_DEBUG ? uniqid() : ''; // Prevent caching in debug mode
10
 
11
- define('CRAYON_VERSION', '1.0.3' . $uid);
12
- define('CRAYON_DATE', '23rd September, 2011');
13
  define('CRAYON_AUTHOR', 'Aram Kocharyan');
14
  // TODO These will be changed once I set up a site for docs
15
  define('CRAYON_WEBSITE', 'http://ak.net84.net/?go=crayon');
8
 
9
  $uid = CRAYON_DEBUG ? uniqid() : ''; // Prevent caching in debug mode
10
 
11
+ define('CRAYON_VERSION', '1.1.0' . $uid);
12
+ define('CRAYON_DATE', '27rd September, 2011');
13
  define('CRAYON_AUTHOR', 'Aram Kocharyan');
14
  // TODO These will be changed once I set up a site for docs
15
  define('CRAYON_WEBSITE', 'http://ak.net84.net/?go=crayon');
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: akarmenia
3
  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.2.1
7
- Stable tag: 1.0.3
8
 
9
  Syntax Highlighter supporting multiple languages, themes, highlighting from a URL, local file or post text.
10
 
@@ -53,7 +53,14 @@ Contact me at http://twitter.com/crayonsyntax or crayon.syntax@gmail.com.
53
 
54
  = 1.0.3 =
55
  * Added highlight="false" attribute to temporarily disable highlighting.
56
- * Fixed default color of font for twilight font.
 
 
 
 
 
 
 
57
 
58
  == Upgrade Notice ==
59
 
3
  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.1.0
8
 
9
  Syntax Highlighter supporting multiple languages, themes, highlighting from a URL, local file or post text.
10
 
53
 
54
  = 1.0.3 =
55
  * Added highlight="false" attribute to temporarily disable highlighting.
56
+ * Fixed default color of font for twilight font.
57
+
58
+ = 1.1 =
59
+ * Recommended upgrade for everyone running 1.0.3.
60
+ * Fixes a bug that causes code become unhighlighted
61
+ * Attribute names can be given in any case in shortcodes
62
+ * Fixes settings bug regarding copy constructor for locked settings
63
+ * Minor bug fixes and cleanups
64
 
65
  == Upgrade Notice ==
66
 
util/crayon_util.class.php CHANGED
@@ -327,6 +327,25 @@ class CrayonUtil {
327
  public static function bool_yn($bool) {
328
  return $bool ? 'Yes' : 'No';
329
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
 
331
  // Decodes WP html entities
332
  public static function html_entity_decode_wp($str) {
327
  public static function bool_yn($bool) {
328
  return $bool ? 'Yes' : 'No';
329
  }
330
+
331
+ // String to boolean, default decides what boolean value to look for
332
+ public static function str_to_bool($str, $default = TRUE) {
333
+ $str = trim(strtolower($str));
334
+ if ($default) {
335
+ if ($str == 'true' || $str == 'yes' || $str == '1') {
336
+ return TRUE;
337
+ } else {
338
+ return FALSE;
339
+ }
340
+ } else {
341
+ if ($str == 'false' || $str == 'no' || $str == '0') {
342
+ return FALSE;
343
+ } else {
344
+ return TRUE;
345
+ }
346
+ }
347
+
348
+ }
349
 
350
  // Decodes WP html entities
351
  public static function html_entity_decode_wp($str) {