Document Gallery - Version 2.0.4

Version Description

  • Enhancement: Custom CSS is now loaded faster, meaning faster page loads for your users. Tests are showing a speedup of around 30% over where it was in the last release.
  • Enhancement: All of the default icons were sent through Yahoo! Smush.it, giving a few percentage points decrease in size. Thanks for the suggestion, wm!
Download this release

Release Info

Developer dan.rossiter
Plugin Icon 128x128 Document Gallery
Version 2.0.4
Comparing to
See all releases

Code changes from version 2.0.3 to 2.0.4

README.txt CHANGED
@@ -4,7 +4,7 @@ Tags: attachments, thumbnail, documents, gallery, MS office, pdf
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=EE5LWRLG933EN&lc=US&item_name=Document%20Gallery%20Plugin&item_number=document%2dgallery&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
5
  Requires at least: 3.6
6
  Tested up to: 3.8.1
7
- Stable tag: 2.0.3
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -237,7 +237,7 @@ is perfectly alright.
237
 
238
  == Frequently Asked Questions ==
239
 
240
- = Q: Why is *-insert thumbnail generation method-* enabled on one of my WordPress
241
  installs, but not on another one? =
242
 
243
  A: Document Gallery works very hard behind the scenes to ensure that it enables
@@ -297,6 +297,15 @@ Note that the display inherits styling from your active theme.
297
  forum](http://wordpress.org/support/plugin/document-gallery) if you have
298
  ideas)!
299
 
 
 
 
 
 
 
 
 
 
300
  = 2.0.3 =
301
  * **Enhancement:** Now handles custom user CSS more securely.
302
  * **Enhancement:** Now handles calling Ghostscript executable more securely.
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=EE5LWRLG933EN&lc=US&item_name=Document%20Gallery%20Plugin&item_number=document%2dgallery&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
5
  Requires at least: 3.6
6
  Tested up to: 3.8.1
7
+ Stable tag: 2.0.4
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
237
 
238
  == Frequently Asked Questions ==
239
 
240
+ = Q: Why is -insert thumbnail generation method- enabled on one of my WordPress
241
  installs, but not on another one? =
242
 
243
  A: Document Gallery works very hard behind the scenes to ensure that it enables
297
  forum](http://wordpress.org/support/plugin/document-gallery) if you have
298
  ideas)!
299
 
300
+ = 2.0.4 =
301
+ * **Enhancement:** Custom CSS is now loaded faster, meaning faster page loads
302
+ for your users. Tests are showing a speedup of around 30% over where it was
303
+ in the last release.
304
+ * **Enhancement:** All of the default icons were sent through
305
+ [Yahoo! Smush.it](http://www.smushit.com/ysmush.it/), giving a few percentage
306
+ points decrease in size. Thanks for the suggestion,
307
+ [wm](http://wordpress.org/support/profile/webbmasterpianise)!
308
+
309
  = 2.0.3 =
310
  * **Enhancement:** Now handles custom user CSS more securely.
311
  * **Enhancement:** Now handles calling Ghostscript executable more securely.
admin/class-admin.php CHANGED
@@ -371,6 +371,8 @@ class DG_Admin {
371
  // handle modified CSS
372
  if (trim($ret['css']['text']) !== trim($values['css'])) {
373
  $ret['css']['text'] = trim($values['css']);
 
 
374
  $ret['css']['version']++;
375
  $ret['css']['last-modified'] = gmdate('D, d M Y H:i:s');
376
  $ret['css']['etag'] = md5($ret['css']['last-modified']);
371
  // handle modified CSS
372
  if (trim($ret['css']['text']) !== trim($values['css'])) {
373
  $ret['css']['text'] = trim($values['css']);
374
+ $ret['css']['minified'] =
375
+ DocumentGallery::compileCustomCss($ret['css']['text']);
376
  $ret['css']['version']++;
377
  $ret['css']['last-modified'] = gmdate('D, d M Y H:i:s');
378
  $ret['css']['etag'] = md5($ret['css']['last-modified']);
assets/icons/asc.png CHANGED
Binary file
assets/icons/audio.png CHANGED
Binary file
assets/icons/c.png CHANGED
Binary file
assets/icons/compressed.png CHANGED
Binary file
assets/icons/cpp.png CHANGED
Binary file
assets/icons/css.png CHANGED
Binary file
assets/icons/exec.png CHANGED
Binary file
assets/icons/h.png CHANGED
Binary file
assets/icons/html.png CHANGED
Binary file
assets/icons/ics.png CHANGED
Binary file
assets/icons/image.png CHANGED
Binary file
assets/icons/java.png CHANGED
Binary file
assets/icons/javascript.png CHANGED
Binary file
assets/icons/key.png CHANGED
Binary file
assets/icons/midi.png CHANGED
Binary file
assets/icons/missing.png CHANGED
Binary file
assets/icons/msaccess.png CHANGED
Binary file
assets/icons/msdoc.png CHANGED
Binary file
assets/icons/msppt.png CHANGED
Binary file
assets/icons/msxls.png CHANGED
Binary file
assets/icons/numbers.png CHANGED
Binary file
assets/icons/opendocument-database.png CHANGED
Binary file
assets/icons/opendocument-formula.png CHANGED
Binary file
assets/icons/opendocument-graphics.png CHANGED
Binary file
assets/icons/opendocument-presentation.png CHANGED
Binary file
assets/icons/opendocument-spreadsheet.png CHANGED
Binary file
assets/icons/opendocument-text.png CHANGED
Binary file
assets/icons/pages.png CHANGED
Binary file
assets/icons/pdf.png CHANGED
Binary file
assets/icons/rtf.png CHANGED
Binary file
assets/icons/rtx.png CHANGED
Binary file
assets/icons/shockwave.png CHANGED
Binary file
assets/icons/text.png CHANGED
Binary file
assets/icons/video.png CHANGED
Binary file
assets/icons/wordperfect.png CHANGED
Binary file
document-gallery.php CHANGED
@@ -5,7 +5,7 @@ defined('WPINC') OR exit;
5
  Plugin Name: Document Gallery
6
  Plugin URI: http://wordpress.org/extend/plugins/document-gallery/
7
  Description: Display non-images (and images) in gallery format on a page or post with the [dg] shortcode.
8
- Version: 2.0.3
9
  Author: Dan Rossiter
10
  Author URI: http://danrossiter.org/
11
  License: GPLv2
@@ -13,7 +13,7 @@ defined('WPINC') OR exit;
13
  */
14
 
15
  // define helper paths & URLs
16
- define('DG_VERSION', '2.0.3');
17
  define('DG_URL', plugin_dir_url(__FILE__));
18
  define('DG_PATH', plugin_dir_path(__FILE__));
19
  if(!defined('WP_INCLUDE_DIR')) {
@@ -80,7 +80,7 @@ class DocumentGallery {
80
  * @var str Name of the query var used to check whether we should print custom CSS.
81
  */
82
  private static $query_var = 'document-gallery-css';
83
-
84
  /*==========================================================================
85
  * THE SHORTCODE
86
  *=========================================================================*/
@@ -94,11 +94,11 @@ class DocumentGallery {
94
  */
95
  public static function doShortcode($atts) {
96
  include_once 'inc/class-gallery.php';
97
-
98
  $start = microtime(true);
99
  $gallery = (string)new DG_Gallery($atts);
100
  DocumentGallery::writeLog('Generation Time: ' . (microtime(true) - $start) . ' s');
101
-
102
  return $gallery;
103
  }
104
 
@@ -109,7 +109,7 @@ class DocumentGallery {
109
  wp_register_style('document-gallery', DG_URL . 'assets/css/style.css', null, DG_VERSION);
110
  wp_enqueue_style('document-gallery');
111
  }
112
-
113
  /**
114
  * Enqueue user's custom DG CSS.
115
  */
@@ -119,7 +119,7 @@ class DocumentGallery {
119
  null, DG_VERSION . ':' . $dg_options['css']['version']);
120
  wp_enqueue_style('document-gallery');
121
  }
122
-
123
  /**
124
  * Add query custom CSS query string.
125
  * Taken from here: http://ottopress.com/2010/dont-include-wp-load-please/
@@ -130,7 +130,7 @@ class DocumentGallery {
130
  $vars[] = self::$query_var;
131
  return $vars;
132
  }
133
-
134
  /**
135
  * Constructs user's custom CSS dynamically, then instructs
136
  * browser to cache for a year. Cache is busted by versioning
@@ -139,18 +139,14 @@ class DocumentGallery {
139
  public static function buildCustomCss() {
140
  if (1 == intval(get_query_var(self::$query_var))) {
141
  global $dg_options;
142
-
143
- header('Content-type: text/css; charset=UTF-8');
144
  header('Cache-Control: no-transform,public,maxage=' . 31536000);
145
  header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
146
  header('Last-Modified: ' . $dg_options['css']['last-modified']);
147
  header('ETag: ' . $dg_options['css']['etag']);
148
 
149
- // standard CSS
150
- echo file_get_contents(DG_PATH . 'assets/css/style.css') . PHP_EOL;
151
-
152
- // custom CSS
153
- echo str_replace('>', '>', esc_html($dg_options['css']['text']));
154
  exit;
155
  }
156
  }
@@ -186,6 +182,80 @@ class DocumentGallery {
186
  /*==========================================================================
187
  * HELPER FUNCTIONS
188
  *=========================================================================*/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
 
190
  /**
191
  * Blocks instantiation. All functions are static.
5
  Plugin Name: Document Gallery
6
  Plugin URI: http://wordpress.org/extend/plugins/document-gallery/
7
  Description: Display non-images (and images) in gallery format on a page or post with the [dg] shortcode.
8
+ Version: 2.0.4
9
  Author: Dan Rossiter
10
  Author URI: http://danrossiter.org/
11
  License: GPLv2
13
  */
14
 
15
  // define helper paths & URLs
16
+ define('DG_VERSION', '2.0.4');
17
  define('DG_URL', plugin_dir_url(__FILE__));
18
  define('DG_PATH', plugin_dir_path(__FILE__));
19
  if(!defined('WP_INCLUDE_DIR')) {
80
  * @var str Name of the query var used to check whether we should print custom CSS.
81
  */
82
  private static $query_var = 'document-gallery-css';
83
+
84
  /*==========================================================================
85
  * THE SHORTCODE
86
  *=========================================================================*/
94
  */
95
  public static function doShortcode($atts) {
96
  include_once 'inc/class-gallery.php';
97
+
98
  $start = microtime(true);
99
  $gallery = (string)new DG_Gallery($atts);
100
  DocumentGallery::writeLog('Generation Time: ' . (microtime(true) - $start) . ' s');
101
+
102
  return $gallery;
103
  }
104
 
109
  wp_register_style('document-gallery', DG_URL . 'assets/css/style.css', null, DG_VERSION);
110
  wp_enqueue_style('document-gallery');
111
  }
112
+
113
  /**
114
  * Enqueue user's custom DG CSS.
115
  */
119
  null, DG_VERSION . ':' . $dg_options['css']['version']);
120
  wp_enqueue_style('document-gallery');
121
  }
122
+
123
  /**
124
  * Add query custom CSS query string.
125
  * Taken from here: http://ottopress.com/2010/dont-include-wp-load-please/
130
  $vars[] = self::$query_var;
131
  return $vars;
132
  }
133
+
134
  /**
135
  * Constructs user's custom CSS dynamically, then instructs
136
  * browser to cache for a year. Cache is busted by versioning
139
  public static function buildCustomCss() {
140
  if (1 == intval(get_query_var(self::$query_var))) {
141
  global $dg_options;
142
+
143
+ header('Content-type: text/css');
144
  header('Cache-Control: no-transform,public,maxage=' . 31536000);
145
  header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
146
  header('Last-Modified: ' . $dg_options['css']['last-modified']);
147
  header('ETag: ' . $dg_options['css']['etag']);
148
 
149
+ echo $dg_options['css']['minified'];
 
 
 
 
150
  exit;
151
  }
152
  }
182
  /*==========================================================================
183
  * HELPER FUNCTIONS
184
  *=========================================================================*/
185
+
186
+ /**
187
+ * Compiles any custom CSS plus the default CSS together,
188
+ * minifying in the process.
189
+ * @param str $custom The custom CSS to compile.
190
+ * @return str Compiled CSS, including both standard and any custom.
191
+ */
192
+ public static function compileCustomCss($custom) {
193
+ $css = file_get_contents(DG_PATH . 'assets/css/style.css');
194
+ $css .= str_replace('>', '>', esc_html($custom));
195
+
196
+ return self::minifyCss($css);
197
+ }
198
+
199
+ /**
200
+ * Removes all comments & space from CSS string.
201
+ * Source: http://stackoverflow.com/a/15195752/866618
202
+ */
203
+ private static function minifyCss($css) {
204
+ # remove comments first (simplifies the other regex)
205
+ $re1 = <<<EOS
206
+ (?sx)
207
+ # quotes
208
+ (
209
+ "(?:[^"\\]++|\\.)*+"
210
+ | '(?:[^'\\]++|\\.)*+'
211
+ )
212
+ |
213
+ # comments
214
+ /\* (?> .*? \*/ )
215
+ EOS;
216
+
217
+ $re2 = <<<EOS
218
+ (?six)
219
+ # quotes
220
+ (
221
+ "(?:[^"\\]++|\\.)*+"
222
+ | '(?:[^'\\]++|\\.)*+'
223
+ )
224
+ |
225
+ # ; before } (and the spaces after it while we're here)
226
+ \s*+ ; \s*+ ( } ) \s*+
227
+ |
228
+ # all spaces around meta chars/operators
229
+ \s*+ ( [*$~^|]?+= | [{};,>~+-] | !important\b ) \s*+
230
+ |
231
+ # spaces right of ( [ :
232
+ ( [[(:] ) \s++
233
+ |
234
+ # spaces left of ) ]
235
+ \s++ ( [])] )
236
+ |
237
+ # spaces left (and right) of :
238
+ \s++ ( : ) \s*+
239
+ # but not in selectors: not followed by a {
240
+ (?!
241
+ (?>
242
+ [^{}"']++
243
+ | "(?:[^"\\]++|\\.)*+"
244
+ | '(?:[^'\\]++|\\.)*+'
245
+ )*+
246
+ {
247
+ )
248
+ |
249
+ # spaces at beginning/end of string
250
+ ^ \s++ | \s++ \z
251
+ |
252
+ # double spaces to single
253
+ (\s)\s+
254
+ EOS;
255
+
256
+ $css = preg_replace("%$re1%", '$1', $css);
257
+ return preg_replace("%$re2%", '$1$2$3$4$5$6$7', $css);
258
+ }
259
 
260
  /**
261
  * Blocks instantiation. All functions are static.
inc/class-setup.php CHANGED
@@ -65,6 +65,9 @@ class DG_Setup {
65
 
66
  // do update
67
  elseif (DG_VERSION !== $dg_options['version']) {
 
 
 
68
  // update plugin version
69
  $dg_options['version'] = DG_VERSION;
70
 
65
 
66
  // do update
67
  elseif (DG_VERSION !== $dg_options['version']) {
68
+ $dg_options['css']['minified'] =
69
+ DocumentGallery::compileCustomCss($dg_options['css']['text']);
70
+
71
  // update plugin version
72
  $dg_options['version'] = DG_VERSION;
73