Crayon Syntax Highlighter - Version 1.2.0

Version Description

  • Recommended upgrade for everyone.
  • Fixed crucial filesystem errors for Windows regarding filepaths and resource loading
  • Said Windows bug was causing Live Preview to fail, nevermore.
  • Fixed loading based on URL structure that caused wp_remote errors and local paths not being recognised
  • Removed redundant dependency on filesystem path slashes
  • PHP now fades surrounding HTML

=

Download this release

Release Info

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

Code changes from version 1.1.1 to 1.2.0

crayon_formatter.class.php CHANGED
@@ -28,6 +28,7 @@ class CrayonFormatter {
28
  // Match language regex
29
  $elements = $language->elements();
30
  $regex = $language->regex();
 
31
  if (!empty($regex) && !empty($elements)) {
32
  // Get array of CrayonElements
33
  self::$elements = array_values($elements);
@@ -232,7 +233,7 @@ EOT;
232
  // Record usage
233
  $theme->used(TRUE);
234
  // Add style
235
- $url = CrayonGlobalSettings::plugin_path() . CrayonUtil::path_f_slash(CRAYON_THEME_DIR) . $theme_id . '/' . $theme_id . '.css?ver' . $CRAYON_VERSION;
236
  $output .= '<link rel="stylesheet" type="text/css" href="' . $url . '" />' . CRAYON_NL;
237
  }
238
 
@@ -241,7 +242,7 @@ EOT;
241
  $font_id_dashed = '';
242
  $font = CrayonResources::fonts()->get($font_id);
243
  if ($hl->setting_val(CrayonSettings::FONT) != CrayonFonts::DEFAULT_FONT && !empty($font_id) && $font != NULL && !$font->used()) {
244
- $url = CrayonGlobalSettings::plugin_path() . CrayonUtil::path_f_slash(CRAYON_FONT_DIR) . $font_id . '.css?ver' . $CRAYON_VERSION;
245
  $output .= '<link rel="stylesheet" type="text/css" href="' . $url . '" />' . CRAYON_NL;
246
  $font_id_dashed = ' crayon-font-' . CrayonUtil::clean_css_name($font_id);
247
  }
@@ -348,7 +349,7 @@ EOT;
348
  </td>
349
  EOT;
350
  }
351
-
352
  $output .= <<<EOT
353
  <td class="crayon-code"><div class="crayon-pre">{$print_code}</div></td>
354
  </tr>
28
  // Match language regex
29
  $elements = $language->elements();
30
  $regex = $language->regex();
31
+
32
  if (!empty($regex) && !empty($elements)) {
33
  // Get array of CrayonElements
34
  self::$elements = array_values($elements);
233
  // Record usage
234
  $theme->used(TRUE);
235
  // Add style
236
+ $url = CrayonGlobalSettings::plugin_path() . CrayonUtil::pathf(CRAYON_THEME_DIR) . $theme_id . '/' . $theme_id . '.css?ver' . $CRAYON_VERSION;
237
  $output .= '<link rel="stylesheet" type="text/css" href="' . $url . '" />' . CRAYON_NL;
238
  }
239
 
242
  $font_id_dashed = '';
243
  $font = CrayonResources::fonts()->get($font_id);
244
  if ($hl->setting_val(CrayonSettings::FONT) != CrayonFonts::DEFAULT_FONT && !empty($font_id) && $font != NULL && !$font->used()) {
245
+ $url = CrayonGlobalSettings::plugin_path() . CrayonUtil::pathf(CRAYON_FONT_DIR) . $font_id . '.css?ver' . $CRAYON_VERSION;
246
  $output .= '<link rel="stylesheet" type="text/css" href="' . $url . '" />' . CRAYON_NL;
247
  $font_id_dashed = ' crayon-font-' . CrayonUtil::clean_css_name($font_id);
248
  }
349
  </td>
350
  EOT;
351
  }
352
+
353
  $output .= <<<EOT
354
  <td class="crayon-code"><div class="crayon-pre">{$print_code}</div></td>
355
  </tr>
crayon_highlighter.class.php CHANGED
@@ -38,7 +38,7 @@ class CrayonHighlighter {
38
  $this->language($language);
39
  }
40
  }
41
-
42
  /* Tries to load the code locally, then attempts to load it remotely */
43
  private function load() {
44
  if (empty($this->url)) {
@@ -48,33 +48,37 @@ class CrayonHighlighter {
48
  /* Try to replace the URL with an absolute path if it is local, used to prevent scripts
49
  from executing when they are loaded. */
50
  $url = $this->url;
 
51
  $local = FALSE; // Whether to read locally
52
  $site_http = CrayonGlobalSettings::site_http();
53
  $site_path = CrayonGlobalSettings::site_path();
54
-
 
55
  // Try to replace the site URL with a path to force local loading
56
  if (strpos($url, $site_http) !== FALSE || strpos($url, $site_path) !== FALSE ) {
57
  $url = str_replace($site_http, $site_path, $url);
58
  // Attempt to load locally
59
  $local = TRUE;
60
- } else {
61
- $scheme = parse_url($url, PHP_URL_SCHEME);
62
- if (empty($scheme)) {
63
- // No url scheme is given - path may be given as relative
64
- $url = preg_replace('#^(\\/*)?#', $site_path . $this->setting_val(CrayonSettings::LOCAL_PATH), $url);
65
- $local = TRUE;
66
- }
67
  }
68
  // Try to find the file locally
69
- if ($local == TRUE || strpos($url, $site_path) !== FALSE) {
70
- if ( ($contents = CrayonUtil::file($url)) !== FALSE ) {
71
  $this->code($contents);
72
  } else {
73
  $local = FALSE;
 
74
  }
75
  }
76
  // If reading the url locally produced an error or failed, attempt remote request
77
- if ($local == FALSE/* || $this->code == FALSE*/) {
 
 
 
78
  $http_code = 0;
79
  if (function_exists('wp_remote_get')) {
80
  // If available, use the built in wp remote http get function, we don't need SSL
@@ -101,7 +105,7 @@ class CrayonHighlighter {
101
  } else {
102
  if (empty($this->code)) {
103
  // If code is also given, just use that
104
- $this->error("The provided URL ('$url') could not be accessed locally or remotely.");
105
  }
106
  }
107
  }
@@ -193,7 +197,7 @@ class CrayonHighlighter {
193
  $this->log("The language '$id' could not be loaded.");
194
  }
195
  $this->language = CrayonResources::langs()->detect($this->url, $this->setting_val(CrayonSettings::FALLBACK_LANG));
196
- }
197
  }
198
 
199
  function url($url = NULL) {
38
  $this->language($language);
39
  }
40
  }
41
+
42
  /* Tries to load the code locally, then attempts to load it remotely */
43
  private function load() {
44
  if (empty($this->url)) {
48
  /* Try to replace the URL with an absolute path if it is local, used to prevent scripts
49
  from executing when they are loaded. */
50
  $url = $this->url;
51
+ $url = CrayonUtil::pathf($url);
52
  $local = FALSE; // Whether to read locally
53
  $site_http = CrayonGlobalSettings::site_http();
54
  $site_path = CrayonGlobalSettings::site_path();
55
+ $scheme = parse_url($url, PHP_URL_SCHEME);
56
+
57
  // Try to replace the site URL with a path to force local loading
58
  if (strpos($url, $site_http) !== FALSE || strpos($url, $site_path) !== FALSE ) {
59
  $url = str_replace($site_http, $site_path, $url);
60
  // Attempt to load locally
61
  $local = TRUE;
62
+ $local_url = $url;
63
+ } else if (empty($scheme)) {
64
+ // No url scheme is given - path may be given as relative
65
+ $local_url = preg_replace('#^((\/|\\\\)*)?#', $site_path . $this->setting_val(CrayonSettings::LOCAL_PATH), $url);
66
+ $local = TRUE;
 
 
67
  }
68
  // Try to find the file locally
69
+ if ($local == TRUE) {
70
+ if ( ($contents = CrayonUtil::file($local_url)) !== FALSE ) {
71
  $this->code($contents);
72
  } else {
73
  $local = FALSE;
74
+ CrayonLog::log("Local url ($local_url) could not be loaded", '', FALSE);
75
  }
76
  }
77
  // If reading the url locally produced an error or failed, attempt remote request
78
+ if ($local == FALSE) {
79
+ if (empty($scheme)) {
80
+ $url = 'http://' . $url;
81
+ }
82
  $http_code = 0;
83
  if (function_exists('wp_remote_get')) {
84
  // If available, use the built in wp remote http get function, we don't need SSL
105
  } else {
106
  if (empty($this->code)) {
107
  // If code is also given, just use that
108
+ $this->error("The provided URL ('$this->url') could not be accessed locally or remotely.");
109
  }
110
  }
111
  }
197
  $this->log("The language '$id' could not be loaded.");
198
  }
199
  $this->language = CrayonResources::langs()->detect($this->url, $this->setting_val(CrayonSettings::FALLBACK_LANG));
200
+ }
201
  }
202
 
203
  function url($url = NULL) {
crayon_langs.class.php CHANGED
@@ -21,7 +21,7 @@ class CrayonLangs extends CrayonResourceCollection {
21
 
22
  // XXX Override
23
  public function path($id) {
24
- return CRAYON_LANG_PATH . $id . crayon_slash() . "$id.txt";
25
  }
26
 
27
  // XXX Override
21
 
22
  // XXX Override
23
  public function path($id) {
24
+ return CRAYON_LANG_PATH . $id . "/$id.txt";
25
  }
26
 
27
  // XXX Override
crayon_parser.class.php CHANGED
@@ -153,7 +153,7 @@ class CrayonParser {
153
  if ( count($file) == 2 ) {
154
  // Element 0 has full match, 1 has captured groups
155
  for ($i = 0; $i < count($file[1]); $i++) {
156
- $file_lines = CrayonUtil::lines(dirname($element->path()) . crayon_slash() . $file[1][$i], 'rcwh');
157
  if ($file_lines !== FALSE) {
158
  $file_lines = implode('|', $file_lines);
159
  $regex = str_replace($file[0][$i], "(?:$file_lines)", $regex);
153
  if ( count($file) == 2 ) {
154
  // Element 0 has full match, 1 has captured groups
155
  for ($i = 0; $i < count($file[1]); $i++) {
156
+ $file_lines = CrayonUtil::lines(dirname($element->path()) . crayon_s() . $file[1][$i], 'rcwh');
157
  if ($file_lines !== FALSE) {
158
  $file_lines = implode('|', $file_lines);
159
  $regex = str_replace($file[0][$i], "(?:$file_lines)", $regex);
crayon_settings.class.php CHANGED
@@ -160,7 +160,16 @@ class CrayonSettings {
160
  $this->set($setting, NULL, $replace);
161
  }
162
  }
163
- } else if ( get_class($name) == CRAYON_SETTING_CLASS ) {
 
 
 
 
 
 
 
 
 
164
  $setting = $name; // Semantics
165
  if ( $replace || !$this->is_setting($setting->name()) ) {
166
  // Replace/Create
@@ -173,15 +182,6 @@ class CrayonSettings {
173
  $this->settings[$setting->name()]->value($setting->value());
174
  }
175
  }
176
- } else if (is_string($name) && !empty($name) && $value !== NULL) {
177
- $value = CrayonSettings::validate($name, $value);
178
- if ($replace || !$this->is_setting($name)) {
179
- // Replace/Create
180
- $this->settings[$name] = new CrayonSetting($name, $value);
181
- } else {
182
- // Update
183
- $this->settings[$name]->value($value);
184
- }
185
  }
186
  }
187
 
@@ -435,8 +435,10 @@ class CrayonGlobalSettings {
435
  }
436
 
437
  public static function site_http($site_http = NULL) {
438
- if (!CrayonUtil::str(self::$site_http, CrayonUtil::url_slash($site_http))) {
439
  return self::$site_http;
 
 
440
  }
441
  }
442
 
@@ -444,7 +446,7 @@ class CrayonGlobalSettings {
444
  if ($site_path === NULL) {
445
  return self::$site_path;
446
  } else {
447
- self::$site_path = CrayonUtil::url_slash($site_path);
448
  }
449
  }
450
 
@@ -452,7 +454,7 @@ class CrayonGlobalSettings {
452
  if ($plugin_path === NULL) {
453
  return self::$plugin_path;
454
  } else {
455
- self::$plugin_path = CrayonUtil::url_slash($plugin_path);
456
  }
457
  }
458
  }
160
  $this->set($setting, NULL, $replace);
161
  }
162
  }
163
+ } else if (is_string($name) && !empty($name) && $value !== NULL) {
164
+ $value = CrayonSettings::validate($name, $value);
165
+ if ($replace || !$this->is_setting($name)) {
166
+ // Replace/Create
167
+ $this->settings[$name] = new CrayonSetting($name, $value);
168
+ } else {
169
+ // Update
170
+ $this->settings[$name]->value($value);
171
+ }
172
+ } else if ( is_object($name) && get_class($name) == CRAYON_SETTING_CLASS ) {
173
  $setting = $name; // Semantics
174
  if ( $replace || !$this->is_setting($setting->name()) ) {
175
  // Replace/Create
182
  $this->settings[$setting->name()]->value($setting->value());
183
  }
184
  }
 
 
 
 
 
 
 
 
 
185
  }
186
  }
187
 
435
  }
436
 
437
  public static function site_http($site_http = NULL) {
438
+ if ($site_http === NULL) {
439
  return self::$site_http;
440
+ } else {
441
+ self::$site_http = CrayonUtil::url_slash($site_http);
442
  }
443
  }
444
 
446
  if ($site_path === NULL) {
447
  return self::$site_path;
448
  } else {
449
+ self::$site_path = CrayonUtil::path_slash($site_path);
450
  }
451
  }
452
 
454
  if ($plugin_path === NULL) {
455
  return self::$plugin_path;
456
  } else {
457
+ self::$plugin_path = CrayonUtil::path_slash($plugin_path);
458
  }
459
  }
460
  }
crayon_settings_wp.class.php CHANGED
@@ -111,7 +111,7 @@ class CrayonSettingsWP {
111
  // For local file loading
112
  // This is used to decouple WP functions from internal Crayon classes
113
  CrayonGlobalSettings::site_http(home_url());
114
- CrayonGlobalSettings::site_path(ABSPATH);
115
  CrayonGlobalSettings::plugin_path(plugins_url('', __FILE__));
116
 
117
  // Ensure all missing settings in db are replaced by default values
@@ -306,7 +306,7 @@ class CrayonSettingsWP {
306
  $web = $CRAYON_WEBSITE;
307
  echo <<<EOT
308
  <div id="crayon-help" class="updated settings-error crayon-help">
309
- <span><strong>Howdy, coder!</strong> Thanks for using Crayon. Use <strong>help</strong> on the top-right to learn how to use the shortcode and basic features, or check out my <a href="#info">Twitter & Email</a>. For online help and info, visit <a target="_blank" href="{$web}">here</a>.</span>
310
  <a class="crayon-help-close" href="#" url="{$url}">X</a>
311
  </div>
312
  EOT;
111
  // For local file loading
112
  // This is used to decouple WP functions from internal Crayon classes
113
  CrayonGlobalSettings::site_http(home_url());
114
+ CrayonGlobalSettings::site_path(ABSPATH);
115
  CrayonGlobalSettings::plugin_path(plugins_url('', __FILE__));
116
 
117
  // Ensure all missing settings in db are replaced by default values
306
  $web = $CRAYON_WEBSITE;
307
  echo <<<EOT
308
  <div id="crayon-help" class="updated settings-error crayon-help">
309
+ <span><strong>Howdy, coder!</strong> Thanks for using Crayon. Use <strong>help</strong> on the top of this page to learn how to use the shortcode and basic features, or check out my <a href="#info">Twitter & Email</a>. For online help and info, visit <a target="_blank" href="{$web}">here</a>.</span>
310
  <a class="crayon-help-close" href="#" url="{$url}">X</a>
311
  </div>
312
  EOT;
crayon_themes.class.php CHANGED
@@ -19,7 +19,7 @@ class CrayonThemes extends CrayonUsedResourceCollection {
19
  // XXX Override
20
 
21
  public function path($id) {
22
- return CRAYON_THEME_PATH . $id . crayon_slash () . "$id.css";
23
  }
24
  }
25
  ?>
19
  // XXX Override
20
 
21
  public function path($id) {
22
+ return CRAYON_THEME_PATH . $id . "/$id.css";
23
  }
24
  }
25
  ?>
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.1.1
7
  Author: Aram Kocharyan
8
  Author URI: http://ak.net84.net/
9
  License: GPL2
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.2
7
  Author: Aram Kocharyan
8
  Author URI: http://ak.net84.net/
9
  License: GPL2
global.php CHANGED
@@ -25,17 +25,17 @@ define('CRAYON_SETTING_CLASS', 'CrayonSetting');
25
 
26
  // Directories
27
 
28
- define('CRAYON_DIR', basename(dirname(__FILE__)) . crayon_slash());
29
- define('CRAYON_LANG_DIR', crayon_slash('langs'));
30
- define('CRAYON_THEME_DIR', crayon_slash('themes'));
31
- define('CRAYON_FONT_DIR', crayon_slash('fonts'));
32
- define('CRAYON_UTIL_DIR', crayon_slash('util'));
33
- define('CRAYON_CSS_DIR', crayon_slash('css'));
34
- define('CRAYON_JS_DIR', crayon_slash('js'));
35
 
36
  // Paths
37
 
38
- define('CRAYON_ROOT_PATH', dirname(__FILE__) . crayon_slash());
39
  define('CRAYON_LANG_PATH', CRAYON_ROOT_PATH . CRAYON_LANG_DIR);
40
  define('CRAYON_THEME_PATH', CRAYON_ROOT_PATH . CRAYON_THEME_DIR);
41
  define('CRAYON_FONT_PATH', CRAYON_ROOT_PATH . CRAYON_FONT_DIR);
@@ -98,6 +98,30 @@ require_once (CRAYON_LOG_PHP);
98
  // Turn on the error & exception handlers
99
  crayon_handler_on();
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  // Get/Set plugin information
102
  function set_crayon_info($info_array) {
103
  global $CRAYON_VERSION, $CRAYON_DATE, $CRAYON_AUTHOR, $CRAYON_WEBSITE, $uid;
@@ -121,18 +145,4 @@ function set_info($key, $array, &$info) {
121
  }
122
  }
123
 
124
- // Check for forwardslash/backslash in folder path to structure paths
125
- $crayon_slash = NULL;
126
- function crayon_slash($url = '') {
127
- global $crayon_slash;
128
- if ($crayon_slash == NULL) {
129
- if (strpos(dirname(__FILE__), '\\')) {
130
- $crayon_slash = '\\';
131
- } else {
132
- $crayon_slash = '/';
133
- }
134
- }
135
- return $url . $crayon_slash;
136
- }
137
-
138
  ?>
25
 
26
  // Directories
27
 
28
+ define('CRAYON_DIR', crayon_pf(basename(dirname(__FILE__))));
29
+ define('CRAYON_LANG_DIR', crayon_s('langs'));
30
+ define('CRAYON_THEME_DIR', crayon_s('themes'));
31
+ define('CRAYON_FONT_DIR', crayon_s('fonts'));
32
+ define('CRAYON_UTIL_DIR', crayon_s('util'));
33
+ define('CRAYON_CSS_DIR', crayon_s('css'));
34
+ define('CRAYON_JS_DIR', crayon_s('js'));
35
 
36
  // Paths
37
 
38
+ define('CRAYON_ROOT_PATH', crayon_pf(dirname(__FILE__)));
39
  define('CRAYON_LANG_PATH', CRAYON_ROOT_PATH . CRAYON_LANG_DIR);
40
  define('CRAYON_THEME_PATH', CRAYON_ROOT_PATH . CRAYON_THEME_DIR);
41
  define('CRAYON_FONT_PATH', CRAYON_ROOT_PATH . CRAYON_FONT_DIR);
98
  // Turn on the error & exception handlers
99
  crayon_handler_on();
100
 
101
+ // GLOBAL FUNCTIONS
102
+
103
+ // Check for forwardslash/backslash in folder path to structure paths
104
+ function crayon_s($url = '') {
105
+ $url = strval($url);
106
+ if (!empty($url) && !preg_match('#(\\\\|/)$#', $url)) {
107
+ return $url . '/';
108
+ } else if ( empty($url) ) {
109
+ return '/';
110
+ } else {
111
+ return $url;
112
+ }
113
+ }
114
+
115
+ // Returns path using forward slashes
116
+ function crayon_pf($url) {
117
+ return str_replace('\\', '/', crayon_s(trim(strval($url))));
118
+ }
119
+
120
+ // Returns path using back slashes
121
+ function crayon_pb($url) {
122
+ return str_replace('/', '\\', crayon_s(trim(strval($url))));
123
+ }
124
+
125
  // Get/Set plugin information
126
  function set_crayon_info($info_array) {
127
  global $CRAYON_VERSION, $CRAYON_DATE, $CRAYON_AUTHOR, $CRAYON_WEBSITE, $uid;
145
  }
146
  }
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  ?>
langs/html/html.txt CHANGED
@@ -3,14 +3,14 @@
3
  # ELEMENT_NAME [optional-css-class] REGULAR_EXPRESSION
4
 
5
  NAME HTML
6
- VERSION 1.0
7
 
8
  COMMENT \<!--.*?--\>
9
- ATT_STR:STRING (((?<!\\)".*?(?<!\\)")|((?<!\\)'.*?(?<!\\)'))(?=[^\<]*\>)
10
  NOTATION <!.*?>
11
 
12
- TAG_OPEN:KEYWORD </?\s*\w+(?=[^\>\<]*\>)
13
- TAG_CLOSE:KEYWORD /?>
14
  ATTR:ENTITY \w+(?=\s*=)(?=[^\<]*\>)
15
  TEXT:IDENTIFIER (?<=\>)[^\<\>]*(?=\<)
16
  SYMBOL (?default)
3
  # ELEMENT_NAME [optional-css-class] REGULAR_EXPRESSION
4
 
5
  NAME HTML
6
+ VERSION 1.1
7
 
8
  COMMENT \<!--.*?--\>
9
+ ATT_STR:STRING (((?<!\\)".*?(?<!\\)")|((?<!\\)'.*?(?<!\\)'))
10
  NOTATION <!.*?>
11
 
12
+ TAG:KEYWORD </?\s*[^<\s>]+\s*>?
13
+
14
  ATTR:ENTITY \w+(?=\s*=)(?=[^\<]*\>)
15
  TEXT:IDENTIFIER (?<=\>)[^\<\>]*(?=\<)
16
  SYMBOL (?default)
langs/php/php.txt CHANGED
@@ -3,10 +3,10 @@
3
  # ELEMENT_NAME [optional-css-class] REGULAR_EXPRESSION
4
 
5
  NAME PHP
6
- VERSION 1.0
7
 
8
- FADED (.+(?=<\?php|<\?))|((?<=\?>).+)
9
-
10
  COMMENT (?default)|(\#.*?$)
11
  STRING (?default)|(<<<EOT.*?^EOT)
12
 
@@ -16,7 +16,7 @@
16
  RESERVED (?default)
17
  TYPE (?default)
18
  MODIFIER (?default)
19
- COMPILE:KEYWORD \b(?alt:compile.txt)\b
20
 
21
  RES_CONST:ENTITY \b(?alt:reserved.txt)\b
22
  ENTITY (?default)|\b[a-z_]\w*::
3
  # ELEMENT_NAME [optional-css-class] REGULAR_EXPRESSION
4
 
5
  NAME PHP
6
+ VERSION 1.1
7
 
8
+ HTML:FADED ((?<=\?>).*?(?=<\?(?:php)?))|(\A.*?(?=<\?(?:php)?))|((?<=\?>).*\Z)
9
+
10
  COMMENT (?default)|(\#.*?$)
11
  STRING (?default)|(<<<EOT.*?^EOT)
12
 
16
  RESERVED (?default)
17
  TYPE (?default)
18
  MODIFIER (?default)
19
+ COMPILE:KEYWORD \b(?alt:compile.txt)\b
20
 
21
  RES_CONST:ENTITY \b(?alt:reserved.txt)\b
22
  ENTITY (?default)|\b[a-z_]\w*::
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.1.1
8
 
9
  Syntax Highlighter supporting multiple languages, themes, highlighting from a URL, local file or post text.
10
 
@@ -44,7 +44,7 @@ Contact me at http://twitter.com/crayonsyntax or crayon.syntax@gmail.com.
44
 
45
  == Changelog ==
46
 
47
- = 1.0 =
48
  * Initial Release. Huzzah!
49
 
50
  = 1.0.1 =
@@ -57,7 +57,7 @@ Contact me at http://twitter.com/crayonsyntax or crayon.syntax@gmail.com.
57
  * Added highlight="false" attribute to temporarily disable highlighting.
58
  * Fixed default color of font for twilight font.
59
 
60
- = 1.1 =
61
  * Recommended upgrade for everyone running 1.0.3.
62
  * Fixes a bug that causes code become unhighlighted
63
  * Attribute names can be given in any case in shortcodes
@@ -67,6 +67,14 @@ Contact me at http://twitter.com/crayonsyntax or crayon.syntax@gmail.com.
67
  = 1.1.1 =
68
  * Plugin version information is updated automatically
69
 
 
 
 
 
 
 
 
 
70
  == Upgrade Notice ==
71
 
72
  No issues upgrading.
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.2.0
8
 
9
  Syntax Highlighter supporting multiple languages, themes, highlighting from a URL, local file or post text.
10
 
44
 
45
  == Changelog ==
46
 
47
+ = 1.0.0 =
48
  * Initial Release. Huzzah!
49
 
50
  = 1.0.1 =
57
  * Added highlight="false" attribute to temporarily disable highlighting.
58
  * Fixed default color of font for twilight font.
59
 
60
+ = 1.1.0 =
61
  * Recommended upgrade for everyone running 1.0.3.
62
  * Fixes a bug that causes code become unhighlighted
63
  * Attribute names can be given in any case in shortcodes
67
  = 1.1.1 =
68
  * Plugin version information is updated automatically
69
 
70
+ = 1.2.0 =
71
+ * Recommended upgrade for everyone.
72
+ * Fixed crucial filesystem errors for Windows regarding filepaths and resource loading
73
+ * Said Windows bug was causing Live Preview to fail, nevermore.
74
+ * Fixed loading based on URL structure that caused wp_remote errors and local paths not being recognised
75
+ * Removed redundant dependency on filesystem path slashes
76
+ * PHP now fades surrounding HTML
77
+
78
  == Upgrade Notice ==
79
 
80
  No issues upgrading.
util/crayon_log.class.php CHANGED
@@ -7,7 +7,7 @@ class CrayonLog {
7
 
8
  // Logs a variable value to a log file
9
 
10
- public static function log($var = NULL, $title = '') {
11
  if ($var === NULL) {
12
  // Return log
13
 
@@ -30,20 +30,21 @@ class CrayonLog {
30
  }
31
  }
32
  // Capture variable dump
33
-
34
  ob_start();
35
  var_dump($var);
36
  $buffer = trim(strip_tags(ob_get_clean()));
 
37
  // Remove stupid formatting from wampserver
38
-
39
  $buffer = str_replace('&apos;', '"', $buffer);
40
  $title = (!empty($title) && is_string($title) ? "[$title] " : '');
41
- // Remove absolute path to plugin directory from buffer
42
 
43
- $buffer = CrayonUtil::path_rel($buffer);
 
 
 
44
  $write = $title . date('g:i:s A - d M Y') . CRAYON_NL . $buffer . CRAYON_NL . CRAYON_LINE . CRAYON_NL;
 
45
  // If we exceed max file size, truncate file first
46
-
47
  if (filesize(CRAYON_LOG_FILE) + strlen($write) > CRAYON_LOG_MAX_SIZE) {
48
  ftruncate(self::$file, 0);
49
  fwrite(self::$file, 'The log has been truncated since it exceeded ' . CRAYON_LOG_MAX_SIZE .
@@ -60,10 +61,10 @@ class CrayonLog {
60
 
61
  // Logs system-wide only if global settings permit
62
 
63
- public static function syslog($var = NULL, $title = '') {
64
  if (CrayonGlobalSettings::val(CrayonSettings::ERROR_LOG_SYS)) {
65
  $title = (empty($title)) ? 'SYSTEM ERROR' : $title;
66
- self::log($var, $title);
67
  }
68
  }
69
 
7
 
8
  // Logs a variable value to a log file
9
 
10
+ public static function log($var = NULL, $title = '', $trim_url = TRUE) {
11
  if ($var === NULL) {
12
  // Return log
13
 
30
  }
31
  }
32
  // Capture variable dump
 
33
  ob_start();
34
  var_dump($var);
35
  $buffer = trim(strip_tags(ob_get_clean()));
36
+
37
  // Remove stupid formatting from wampserver
 
38
  $buffer = str_replace('&apos;', '"', $buffer);
39
  $title = (!empty($title) && is_string($title) ? "[$title] " : '');
 
40
 
41
+ // Remove absolute path to plugin directory from buffer
42
+ if ($trim_url) {
43
+ $buffer = CrayonUtil::path_rel($buffer);
44
+ }
45
  $write = $title . date('g:i:s A - d M Y') . CRAYON_NL . $buffer . CRAYON_NL . CRAYON_LINE . CRAYON_NL;
46
+
47
  // If we exceed max file size, truncate file first
 
48
  if (filesize(CRAYON_LOG_FILE) + strlen($write) > CRAYON_LOG_MAX_SIZE) {
49
  ftruncate(self::$file, 0);
50
  fwrite(self::$file, 'The log has been truncated since it exceeded ' . CRAYON_LOG_MAX_SIZE .
61
 
62
  // Logs system-wide only if global settings permit
63
 
64
+ public static function syslog($var = NULL, $title = '', $trim_url = TRUE) {
65
  if (CrayonGlobalSettings::val(CrayonSettings::ERROR_LOG_SYS)) {
66
  $title = (empty($title)) ? 'SYSTEM ERROR' : $title;
67
+ self::log($var, $title, $trim_url);
68
  }
69
  }
70
 
util/crayon_util.class.php CHANGED
@@ -12,6 +12,7 @@ class CrayonUtil {
12
  c - remove comments
13
  s - return as string */
14
  public static function lines($path, $opts = NULL) {
 
15
  if ( ($str = self::file($path)) === FALSE ) {
16
  // Log failure, n = no log
17
  if ( strpos($opts, 'n') === FALSE ) {
@@ -88,10 +89,10 @@ class CrayonUtil {
88
  if (self::$touchscreen !== NULL) {
89
  return self::$touchscreen;
90
  }
91
- if ( ($devices = CrayonUtil::lines(CRAYON_TOUCH_FILE, 'lw')) !== FALSE ) {
92
  // Create array of device strings from file
93
  $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
94
- self::$touchscreen = (CrayonUtil::strposa($user_agent, $devices) !== FALSE);
95
  return self::$touchscreen;
96
  } else {
97
  CrayonLog::syslog('Error occurred when trying to identify touchscreen devices');
@@ -224,41 +225,52 @@ class CrayonUtil {
224
  // Removes crayon plugin path from absolute path
225
  public static function path_rel($url) {
226
  if (is_string($url)) {
227
- return str_replace(CRAYON_ROOT_PATH, crayon_slash(), $url);
228
  }
229
  return $url;
230
  }
231
 
232
  // Returns path according to detected use of forwardslash/backslash
 
233
  public static function path($path, $detect) {
234
- if (strpos($detect, '\\')) {
 
 
 
 
 
 
235
  // Windows
236
- $slash = '\\';
237
  } else {
238
  // UNIX
239
- $slash = '/';
240
  }
241
- return str_replace(array('\\', '/'), $slash, $path);
242
  }
243
-
244
  // Returns path using forward slashes
245
- public static function path_f_slash($url) {
246
- return str_replace('\\', '/', $url);
 
 
 
 
 
247
  }
248
 
249
  // Append either forward slash or backslash based on environment to paths
250
  public static function path_slash($path) {
251
- $path = strval($path);
252
- if (!empty($path) && !preg_match('#\\\\|/$#', $path)) {
253
- $path .= crayon_slash();
254
  }
255
  return $path;
256
  }
257
 
258
  // Append a forward slash to a path if needed
259
  public static function url_slash($url) {
260
- $url = trim(strval($url));
261
- if (!empty($url) && !preg_match('#(/|\\\\)$#', $url)) {
262
  $url .= '/';
263
  }
264
  return $url;
@@ -266,7 +278,7 @@ class CrayonUtil {
266
 
267
  // Removes extension from file path
268
  public static function path_rem_ext($path) {
269
- $path = strval($path);
270
  return preg_replace('#\.\w+$#m', '', $path);
271
  }
272
 
@@ -275,7 +287,7 @@ class CrayonUtil {
275
  if (is_array($needles)) {
276
  foreach ($needles as $str) {
277
  if (is_array($str)) {
278
- $pos = CrayonUtil::strposa($haystack, $str);
279
  } else {
280
  $pos = strpos($haystack, $str);
281
  }
12
  c - remove comments
13
  s - return as string */
14
  public static function lines($path, $opts = NULL) {
15
+ $path = self::pathf($path);
16
  if ( ($str = self::file($path)) === FALSE ) {
17
  // Log failure, n = no log
18
  if ( strpos($opts, 'n') === FALSE ) {
89
  if (self::$touchscreen !== NULL) {
90
  return self::$touchscreen;
91
  }
92
+ if ( ($devices = self::lines(CRAYON_TOUCH_FILE, 'lw')) !== FALSE ) {
93
  // Create array of device strings from file
94
  $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
95
+ self::$touchscreen = (self::strposa($user_agent, $devices) !== FALSE);
96
  return self::$touchscreen;
97
  } else {
98
  CrayonLog::syslog('Error occurred when trying to identify touchscreen devices');
225
  // Removes crayon plugin path from absolute path
226
  public static function path_rel($url) {
227
  if (is_string($url)) {
228
+ return str_replace(CRAYON_ROOT_PATH, '/', $url);
229
  }
230
  return $url;
231
  }
232
 
233
  // Returns path according to detected use of forwardslash/backslash
234
+ // Depreciated from regular use after v.1.1.1
235
  public static function path($path, $detect) {
236
+ $slash = self::detect_slash($detect);
237
+ return str_replace(array('\\', '/'), $slash, $path);
238
+ }
239
+
240
+ // Detect which kind of slash is being used in a path
241
+ public static function detect_slash($path) {
242
+ if (strpos($path, '\\')) {
243
  // Windows
244
+ return $slash = '\\';
245
  } else {
246
  // UNIX
247
+ return $slash = '/';
248
  }
 
249
  }
250
+
251
  // Returns path using forward slashes
252
+ public static function pathf($url) {
253
+ return str_replace('\\', '/', trim(strval($url)));
254
+ }
255
+
256
+ // Returns path using back slashes
257
+ public static function pathb($url) {
258
+ return str_replace('/', '\\', trim(strval($url)));
259
  }
260
 
261
  // Append either forward slash or backslash based on environment to paths
262
  public static function path_slash($path) {
263
+ $path = self::pathf($path);
264
+ if (!empty($path) && !preg_match('#\/$#', $path)) {
265
+ $path .= '/';
266
  }
267
  return $path;
268
  }
269
 
270
  // Append a forward slash to a path if needed
271
  public static function url_slash($url) {
272
+ $url = self::pathf($url);
273
+ if (!empty($url) && !preg_match('#\/$#', $url)) {
274
  $url .= '/';
275
  }
276
  return $url;
278
 
279
  // Removes extension from file path
280
  public static function path_rem_ext($path) {
281
+ $path = self::pathf($path);
282
  return preg_replace('#\.\w+$#m', '', $path);
283
  }
284
 
287
  if (is_array($needles)) {
288
  foreach ($needles as $str) {
289
  if (is_array($str)) {
290
+ $pos = self::strposa($haystack, $str);
291
  } else {
292
  $pos = strpos($haystack, $str);
293
  }
util/preview.php CHANGED
@@ -1,9 +1,10 @@
1
  <?php
2
 
3
  require_once (dirname(dirname(__FILE__)) . '/crayon_wp.class.php');
4
- $remove = CrayonUtil::path('wp-content/plugins/' . CRAYON_DIR, CRAYON_DIR);
5
- $wp_root_path = str_replace($remove, '', CRAYON_ROOT_PATH);
6
  require_once ($wp_root_path . 'wp-load.php');
 
7
  echo '<link rel="stylesheet" href="', plugins_url(CRAYON_STYLE, dirname(__FILE__)),
8
  '?ver=', $CRAYON_VERSION, '" type="text/css" media="all" />';
9
  echo '<script type="text/javascript">init();</script>';
@@ -23,7 +24,8 @@ $crayon->settings($settings);
23
 
24
  $lang = $crayon->setting_val(CrayonSettings::FALLBACK_LANG);
25
 
26
- $path = dirname(__FILE__) . crayon_slash() . 'sample' . crayon_slash() . $lang . '.txt';
 
27
  if ($lang && @file_exists($path)) {
28
  $crayon->url($path);
29
  } else {
@@ -40,8 +42,6 @@ EOT;
40
  $crayon->code($code);
41
  }
42
  $crayon->title('Sample Code');
43
-
44
- //$crayon->language('php');
45
  $crayon->marked('5-7');
46
  $crayon->output($highlight = true, $nums = true, $print = true);
47
  echo '</div>';
1
  <?php
2
 
3
  require_once (dirname(dirname(__FILE__)) . '/crayon_wp.class.php');
4
+
5
+ $wp_root_path = str_replace('wp-content/plugins/' . CRAYON_DIR, '', CrayonUtil::pathf(CRAYON_ROOT_PATH));
6
  require_once ($wp_root_path . 'wp-load.php');
7
+
8
  echo '<link rel="stylesheet" href="', plugins_url(CRAYON_STYLE, dirname(__FILE__)),
9
  '?ver=', $CRAYON_VERSION, '" type="text/css" media="all" />';
10
  echo '<script type="text/javascript">init();</script>';
24
 
25
  $lang = $crayon->setting_val(CrayonSettings::FALLBACK_LANG);
26
 
27
+ $path = crayon_pf( dirname(__FILE__) . '/sample/' . $lang . '.txt' );
28
+
29
  if ($lang && @file_exists($path)) {
30
  $crayon->url($path);
31
  } else {
42
  $crayon->code($code);
43
  }
44
  $crayon->title('Sample Code');
 
 
45
  $crayon->marked('5-7');
46
  $crayon->output($highlight = true, $nums = true, $print = true);
47
  echo '</div>';