Document Gallery - Version 2.1

Version Description

  • Enhancement: Document Gallery now supports multisite networks.
Download this release

Release Info

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

Code changes from version 2.0.10 to 2.1

README.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: dan.rossiter
3
  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.9
7
- Stable tag: 2.0.10
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -17,9 +17,8 @@ This plugin allows the user to effortlessly create a gallery of documents and
17
  other attached media, much like the gallery option already available for image
18
  attachments.
19
 
20
- The plugin will, by default, inherit the styling within your active theme, but
21
- with a little CSS knowledge it is possible to customize the appearance to meet
22
- your specific needs.
23
 
24
  Read more in the **Installation** tab!
25
 
@@ -47,7 +46,7 @@ must include the following shortcode in the post: `[dg]`.
47
  In addition to the default behavior, the plugin provides many options to
48
  customize behavior with various attributes, seen below:
49
 
50
- `[dg [fancy=true] [attachment_pg=<true/false>]
51
  [category/custom_taxon_name=<**comma-separated list of taxon values**> [relation=<AND/OR>]]
52
  [descriptions=<true/false>] [ids=<**comma-separated list of ID #s**>]
53
  [images=<true/false>] [localpost=<true/false>] [order=<ASC/DESC>] [orderby=<**see below**>]]`
@@ -239,10 +238,10 @@ Document Gallery provides the `dg_thumbers` filter, which allows developers to
239
  add, remove, or even re-order which methods are used to generate a thumbnail
240
  for a given attachment.
241
 
242
- The value being filtered is an associative array with keys equal to a string
243
- containing all supported file extensions, separated by a vertical bar (|) and values
244
  equal to [callables](http://www.php.net/manual/en/language.types.callable.php)
245
- which take an attachment ID and a page number as arguments.
246
 
247
  The callable given should return false if thumbnail generation fails or
248
  a system path to a **temporary** copy of the generated image if generation
@@ -292,7 +291,7 @@ function dg_get_audio_video_thumbnail($ID, $pg) {
292
  }
293
 
294
  $tmp_dir = untrailingslashit(get_temp_dir());
295
- $temp_file = $tmp_dir . DIRECTORY_SEPARATOR . wp_unique_filename($tmp_dir, md5(time()) + ".$ext");
296
 
297
  if (!$fp = @fopen($temp_file, 'wb')) {
298
  return false;
@@ -365,11 +364,14 @@ Note that the display inherits styling from your active theme.
365
  * Option to open music or video files directly from your gallery.
366
  * Option to open documents directly from your gallery (&#224; la [Google Drive
367
  Viewer](https://drive.google.com/viewer)).
368
- * Support for adding your own filetypes/icons.
369
  * Whatever else **you** would like (post on the [support
370
  forum](http://wordpress.org/support/plugin/document-gallery) if you have
371
  ideas)!
372
 
 
 
 
 
373
  = 2.0.10 =
374
  * **Enhancement:** Ghostscript detection should now work correctly on GoDaddy
375
  and some other hosts that don't properly setup their executables.
3
  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.9.1
7
+ Stable tag: 2.1
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
17
  other attached media, much like the gallery option already available for image
18
  attachments.
19
 
20
+ Watch the following video for a brief demonstration of Document Gallery in action:
21
+ [youtube https://www.youtube.com/watch?v=pCQsx5z-uOU]
 
22
 
23
  Read more in the **Installation** tab!
24
 
46
  In addition to the default behavior, the plugin provides many options to
47
  customize behavior with various attributes, seen below:
48
 
49
+ `[dg [fancy=<true/false>] [attachment_pg=<true/false>]
50
  [category/custom_taxon_name=<**comma-separated list of taxon values**> [relation=<AND/OR>]]
51
  [descriptions=<true/false>] [ids=<**comma-separated list of ID #s**>]
52
  [images=<true/false>] [localpost=<true/false>] [order=<ASC/DESC>] [orderby=<**see below**>]]`
238
  add, remove, or even re-order which methods are used to generate a thumbnail
239
  for a given attachment.
240
 
241
+ The value being filtered is an associative array with keys equal to a regular
242
+ expression matching all file extensions supported by the generator and values
243
  equal to [callables](http://www.php.net/manual/en/language.types.callable.php)
244
+ which take an **attachment ID** and a **file page number** as arguments.
245
 
246
  The callable given should return false if thumbnail generation fails or
247
  a system path to a **temporary** copy of the generated image if generation
291
  }
292
 
293
  $tmp_dir = untrailingslashit(get_temp_dir());
294
+ $temp_file = $tmp_dir . DIRECTORY_SEPARATOR . wp_unique_filename($tmp_dir, md5(time()) . ".$ext");
295
 
296
  if (!$fp = @fopen($temp_file, 'wb')) {
297
  return false;
364
  * Option to open music or video files directly from your gallery.
365
  * Option to open documents directly from your gallery (&#224; la [Google Drive
366
  Viewer](https://drive.google.com/viewer)).
 
367
  * Whatever else **you** would like (post on the [support
368
  forum](http://wordpress.org/support/plugin/document-gallery) if you have
369
  ideas)!
370
 
371
+ = 2.1 =
372
+ * **Enhancement:** Document Gallery now supports
373
+ [multisite networks](http://codex.wordpress.org/Create_A_Network).
374
+
375
  = 2.0.10 =
376
  * **Enhancement:** Ghostscript detection should now work correctly on GoDaddy
377
  and some other hosts that don't properly setup their executables.
admin/class-admin.php CHANGED
@@ -33,7 +33,7 @@ class DG_Admin {
33
  * Adds Document Gallery settings page to admin navigation.
34
  */
35
  public static function addAdminPage() {
36
- $page = add_options_page(
37
  __('Document Gallery Settings', 'document-gallery'),
38
  __('Document Gallery', 'document-gallery'),
39
  'manage_options', 'document_gallery', array(__CLASS__, 'renderOptions'));
@@ -240,6 +240,20 @@ class DG_Admin {
240
  : __('Failed to auto-detect the location of Ghostscript.', 'document-gallery')
241
  ));
242
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
 
244
  /**
245
  * Render the Default Settings section.
@@ -371,11 +385,16 @@ 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']['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']);
 
 
 
 
 
 
 
379
  }
380
 
381
  // handle setting the Ghostscript path
33
  * Adds Document Gallery settings page to admin navigation.
34
  */
35
  public static function addAdminPage() {
36
+ add_options_page(
37
  __('Document Gallery Settings', 'document-gallery'),
38
  __('Document Gallery', 'document-gallery'),
39
  'manage_options', 'document_gallery', array(__CLASS__, 'renderOptions'));
240
  : __('Failed to auto-detect the location of Ghostscript.', 'document-gallery')
241
  ));
242
  }
243
+
244
+ /**
245
+ * @return bool Whether to register settings.
246
+ */
247
+ public static function doRegisterSettings() {
248
+ if (!is_multisite()) {
249
+ $script = !empty($GLOBALS['pagenow']) ? $GLOBALS['pagenow'] : null;
250
+ } else {
251
+ $script = parse_url($_SERVER['REQUEST_URI']);
252
+ $script = basename($script['path']);
253
+ }
254
+
255
+ return !empty($script) && ('options-general.php' === $script || 'options.php' === $script);
256
+ }
257
 
258
  /**
259
  * Render the Default Settings section.
385
  // handle modified CSS
386
  if (trim($ret['css']['text']) !== trim($values['css'])) {
387
  $ret['css']['text'] = trim($values['css']);
 
 
388
  $ret['css']['version']++;
389
  $ret['css']['last-modified'] = gmdate('D, d M Y H:i:s');
390
  $ret['css']['etag'] = md5($ret['css']['last-modified']);
391
+
392
+ if (empty($ret['css']['text'])) {
393
+ unset($ret['css']['minified']);
394
+ } else {
395
+ $ret['css']['minified'] =
396
+ DocumentGallery::compileCustomCss($ret['css']['text']);
397
+ }
398
  }
399
 
400
  // handle setting the Ghostscript path
document-gallery.php CHANGED
@@ -5,15 +5,17 @@ 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.10
9
  Author: Dan Rossiter
10
  Author URI: http://danrossiter.org/
11
  License: GPLv2
12
  Text Domain: document-gallery
13
  */
14
 
 
 
15
  // define helper paths & URLs
16
- define('DG_VERSION', '2.0.10');
17
  define('DG_URL', plugin_dir_url(__FILE__));
18
  define('DG_PATH', plugin_dir_path(__FILE__));
19
  define('DG_WPINC_PATH', ABSPATH . WPINC . '/');
@@ -24,10 +26,12 @@ global $dg_options;
24
  define('DG_OPTION_NAME', 'document_gallery');
25
  $dg_options = get_option(DG_OPTION_NAME, null);
26
 
27
- // handle activation and uninstallation
28
  include_once DG_PATH . 'inc/class-setup.php';
29
- DG_Setup::maybeUpdate();
 
30
  register_uninstall_hook(__FILE__, array('DG_Setup', 'uninstall'));
 
31
 
32
  // I18n
33
  add_action('plugins_loaded', array('DocumentGallery', 'loadTextDomain'));
@@ -41,15 +45,13 @@ if (is_admin()) {
41
  include_once DG_PATH . 'admin/class-admin.php';
42
 
43
  // add settings link
44
- add_filter('plugin_action_links_' . plugin_basename(__FILE__),
45
  array('DG_Admin', 'addSettingsLink'));
46
-
47
  // build options page
48
  add_action('admin_menu', array('DG_Admin', 'addAdminPage'));
49
- if (!empty($GLOBALS['pagenow'])
50
- && ('options-general.php' === $GLOBALS['pagenow'] // output
51
- || 'options.php' === $GLOBALS['pagenow'])) { // validation
52
- add_action('admin_init', array('DG_Admin', 'registerSettings'));
53
  }
54
  } else {
55
  // styling for gallery
@@ -141,7 +143,7 @@ class DocumentGallery {
141
  header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
142
  header('Last-Modified: ' . $dg_options['css']['last-modified']);
143
  header('ETag: ' . $dg_options['css']['etag']);
144
-
145
  echo $dg_options['css']['minified'];
146
  exit;
147
  }
@@ -157,8 +159,17 @@ class DocumentGallery {
157
  * @param str $entry
158
  */
159
  public static function writeLog($entry) {
160
- if (defined('WP_DEBUG') && WP_DEBUG) {
161
- $err = 'DG: ' . print_r($entry, true) . PHP_EOL;
 
 
 
 
 
 
 
 
 
162
  if (defined('ERRORLOGFILE')) {
163
  error_log($err, 3, ERRORLOGFILE);
164
  } else {
@@ -166,19 +177,55 @@ class DocumentGallery {
166
  }
167
  }
168
  }
 
 
 
 
 
 
 
169
 
170
  /*==========================================================================
171
  * I18n
172
  *=========================================================================*/
173
 
174
  public static function loadTextDomain() {
175
- load_plugin_textdomain('document-gallery', false, dirname(plugin_basename(__FILE__ )) . '/languages/');
176
  }
177
 
178
  /*==========================================================================
179
  * HELPER FUNCTIONS
180
  *=========================================================================*/
181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  /**
183
  * Compiles any custom CSS plus the default CSS together,
184
  * minifying in the process.
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.1
9
  Author: Dan Rossiter
10
  Author URI: http://danrossiter.org/
11
  License: GPLv2
12
  Text Domain: document-gallery
13
  */
14
 
15
+ define('DG_VERSION', '2.1');
16
+
17
  // define helper paths & URLs
18
+ define('DG_BASENAME', plugin_basename(__FILE__));
19
  define('DG_URL', plugin_dir_url(__FILE__));
20
  define('DG_PATH', plugin_dir_path(__FILE__));
21
  define('DG_WPINC_PATH', ABSPATH . WPINC . '/');
26
  define('DG_OPTION_NAME', 'document_gallery');
27
  $dg_options = get_option(DG_OPTION_NAME, null);
28
 
29
+ // handle activation, updates, and uninstallation
30
  include_once DG_PATH . 'inc/class-setup.php';
31
+ register_activation_hook(__FILE__, array('DG_Setup', 'activate'));
32
+ add_action('wpmu_new_blog', array('DG_Setup','activateNewBlog'));
33
  register_uninstall_hook(__FILE__, array('DG_Setup', 'uninstall'));
34
+ DG_Setup::maybeUpdate();
35
 
36
  // I18n
37
  add_action('plugins_loaded', array('DocumentGallery', 'loadTextDomain'));
45
  include_once DG_PATH . 'admin/class-admin.php';
46
 
47
  // add settings link
48
+ add_filter('plugin_action_links_' . DG_BASENAME,
49
  array('DG_Admin', 'addSettingsLink'));
50
+
51
  // build options page
52
  add_action('admin_menu', array('DG_Admin', 'addAdminPage'));
53
+ if (DG_Admin::doRegisterSettings()) {
54
+ add_action('admin_init', array('DG_Admin', 'registerSettings'));
 
 
55
  }
56
  } else {
57
  // styling for gallery
143
  header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
144
  header('Last-Modified: ' . $dg_options['css']['last-modified']);
145
  header('ETag: ' . $dg_options['css']['etag']);
146
+
147
  echo $dg_options['css']['minified'];
148
  exit;
149
  }
159
  * @param str $entry
160
  */
161
  public static function writeLog($entry) {
162
+ if (self::logEnabled()) {
163
+ // NOTE: First entry in stack trace is this method -- need to get second
164
+ $callers = debug_backtrace();
165
+ $caller = $callers[1];
166
+ $caller = (isset($caller['class']) ? $caller['class'] : '') . $caller['type'] . $caller['function'];
167
+
168
+ // build log entry, removing any extra spaces
169
+ $err = preg_replace('/\s+/', ' ', trim(print_r($entry, true)));
170
+ $err = 'DG (' . $caller . '): ' . $err . PHP_EOL;
171
+
172
+ // insert log entry
173
  if (defined('ERRORLOGFILE')) {
174
  error_log($err, 3, ERRORLOGFILE);
175
  } else {
177
  }
178
  }
179
  }
180
+
181
+ /**
182
+ * @return bool Whether debug logging is currently enabled.
183
+ */
184
+ public static function logEnabled() {
185
+ return defined('WP_DEBUG') && WP_DEBUG;
186
+ }
187
 
188
  /*==========================================================================
189
  * I18n
190
  *=========================================================================*/
191
 
192
  public static function loadTextDomain() {
193
+ load_plugin_textdomain('document-gallery', false, dirname(DG_BASENAME) . '/languages/');
194
  }
195
 
196
  /*==========================================================================
197
  * HELPER FUNCTIONS
198
  *=========================================================================*/
199
 
200
+ /**
201
+ * @param int $blog ID of the blog to be retrieved in multisite env.
202
+ * @return array Options for the blog.
203
+ */
204
+ public static function getOptions($blog = null) {
205
+ global $dg_options;
206
+ return is_null($blog)
207
+ ? $dg_options
208
+ : get_blog_option($blog, DG_OPTION_NAME, null);
209
+ }
210
+
211
+ public static function setOptions($options, $blog = null) {
212
+ if (is_null($blog)) {
213
+ global $dg_options;
214
+ update_option(DG_OPTION_NAME, $options);
215
+ $dg_options = $options;
216
+ } else {
217
+ update_blog_option($blog, DG_OPTION_NAME, $options);
218
+ }
219
+ }
220
+
221
+ public static function deleteOptions($blog = null) {
222
+ if (is_null($blog)) {
223
+ delete_option(DG_OPTION_NAME);
224
+ } else {
225
+ delete_blog_option($blog, DG_OPTION_NAME);
226
+ }
227
+ }
228
+
229
  /**
230
  * Compiles any custom CSS plus the default CSS together,
231
  * minifying in the process.
inc/class-setup.php CHANGED
@@ -37,7 +37,6 @@ class DG_Setup {
37
  'localpost' => true,
38
  'order' => 'ASC',
39
  'orderby' => 'menu_order',
40
- // only relevant if tax_query used (WP >= 3.1)
41
  'relation' => 'AND'
42
  )
43
  ),
@@ -52,39 +51,100 @@ class DG_Setup {
52
  }
53
 
54
  /**
55
- * Runs every page load, updates when needed.
56
  */
57
  public static function maybeUpdate() {
58
  global $dg_options;
59
 
60
- // first installation
61
- if (empty($dg_options)) {
62
- $dg_options = self::getDefaultOptions();
63
- add_option(DG_OPTION_NAME, $dg_options);
64
- }
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
 
74
- // used in dynamic CSS HTTP headers
75
- $dg_options['css']['last-modified'] = gmdate('D, d M Y H:i:s');
76
- $dg_options['css']['etag'] = md5($dg_options['css']['last-modified']);
 
 
 
 
 
 
 
 
 
 
 
77
 
78
- // remove previously-failed thumbs
79
- $thumbs = $dg_options['thumber']['thumbs'];
80
- foreach ($thumbs as $k => $v) {
81
- if (false === $v) {
82
- unset($dg_options['thumber']['thumbs'][$k]);
83
- }
 
 
 
 
 
 
 
 
 
 
 
84
  }
 
85
 
86
- // commit DB changes
87
- update_option(DG_OPTION_NAME, $dg_options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
89
  }
90
 
@@ -94,8 +154,24 @@ class DG_Setup {
94
  public static function uninstall() {
95
  if (!current_user_can('activate_plugins')) return;
96
  check_admin_referer('bulk-plugins');
97
-
98
- $options = DG_Thumber::getOptions();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
  foreach ($options['thumbs'] as $val) {
101
  if (false !== $val) {
@@ -103,7 +179,7 @@ class DG_Setup {
103
  }
104
  }
105
 
106
- delete_option(DG_OPTION_NAME);
107
  }
108
 
109
  /**
37
  'localpost' => true,
38
  'order' => 'ASC',
39
  'orderby' => 'menu_order',
 
40
  'relation' => 'AND'
41
  )
42
  ),
51
  }
52
 
53
  /**
54
+ * Runs every page load, updates as needed.
55
  */
56
  public static function maybeUpdate() {
57
  global $dg_options;
58
 
 
 
 
 
 
 
59
  // do update
60
+ if (null != $dg_options && DG_VERSION !== $dg_options['version']) {
61
+ $blogs = array(null);
 
62
 
63
+ if (is_multisite()) {
64
+ global $wpdb;
65
+ $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
66
+ }
67
 
68
+ foreach ($blogs as $blog) {
69
+ self::_update($blog);
70
+ }
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Runs when update is needed, updating the given blog. If blog is null,
76
+ * active blog is updated.
77
+ * @param int $blog Blog to update or null if updating current blog.
78
+ */
79
+ private static function _update($blog) {
80
+ $options = DocumentGallery::getOptions($blog);
81
+ if (is_null($options)) return;
82
 
83
+ // update plugin version
84
+ $options['version'] = DG_VERSION;
85
+
86
+ // setup CSS
87
+ if (!empty($options['css']['text'])) {
88
+ // Only populate minified if it will be used
89
+ $options['css']['minified'] =
90
+ DocumentGallery::compileCustomCss($options['css']['text']);
91
+ }
92
+ $options['css']['last-modified'] = gmdate('D, d M Y H:i:s');
93
+ $options['css']['etag'] = md5($options['css']['last-modified']);
94
+
95
+ // remove previously-failed thumbs
96
+ $thumbs = $options['thumber']['thumbs'];
97
+ foreach ($thumbs as $k => $v) {
98
+ if (false === $v) {
99
+ unset($options['thumber']['thumbs'][$k]);
100
  }
101
+ }
102
 
103
+ DocumentGallery::setOptions($options, $blog);
104
+ }
105
+
106
+ /**
107
+ * Sets up Document Gallery on all blog(s) activated.
108
+ * @param bool $networkwide Whether this is a network-wide update (multisite only).
109
+ */
110
+ public static function activate($networkwide) {
111
+ $blogs = array(null);
112
+
113
+ if (is_multisite()) {
114
+ // check if it is a network activation
115
+ if ($networkwide) {
116
+ global $wpdb;
117
+ $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
118
+ }
119
+ }
120
+
121
+ foreach ($blogs as $blog) {
122
+ self::_activate($blog);
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Hooked into wpmu_new_blog to handle activating a new blog when plugin
128
+ * is already network activated.
129
+ * See discussion: https://core.trac.wordpress.org/ticket/14170
130
+ * @param int $blog Blog ID.
131
+ */
132
+ public static function activateNewBlog($blog) {
133
+ if (is_plugin_active_for_network(DG_BASENAME)) {
134
+ self::_activate($blog);
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Runs activation setup for Document Gallery on all blog(s) it is activated on.
140
+ * @param int $blog Blog to update or null if updating current blog.
141
+ */
142
+ private static function _activate($blog) {
143
+ $options = DocumentGallery::getOptions($blog);
144
+
145
+ // first activation
146
+ if (is_null($options)) {
147
+ DocumentGallery::setOptions(self::getDefaultOptions(), $blog);
148
  }
149
  }
150
 
154
  public static function uninstall() {
155
  if (!current_user_can('activate_plugins')) return;
156
  check_admin_referer('bulk-plugins');
157
+
158
+ $blogs = array(null);
159
+
160
+ if (is_multisite()) {
161
+ global $wpdb;
162
+ $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
163
+ }
164
+
165
+ foreach ($blogs as $blog) {
166
+ self::_uninstall($blog);
167
+ }
168
+ }
169
+ /**
170
+ * Runs when DG is uninstalled for an individual blog.
171
+ */
172
+ private static function _uninstall($blog) {
173
+ $options = DG_Thumber::getOptions($blog);
174
+ if (is_null($options)) return;
175
 
176
  foreach ($options['thumbs'] as $val) {
177
  if (false !== $val) {
179
  }
180
  }
181
 
182
+ DocumentGallery::deleteOptions($blog);
183
  }
184
 
185
  /**
inc/class-thumber.php CHANGED
@@ -29,8 +29,8 @@ class DG_Thumber {
29
  * @return str URL to the thumbnail.
30
  */
31
  public static function getThumbnail($ID, $pg = 1) {
32
- static $timeout = false;
33
- if (false === $timeout) {
34
  $timeout = time();
35
  }
36
 
@@ -294,8 +294,7 @@ class DG_Thumber {
294
  // GoDaddy and others aren't setup in such a way that
295
  // the above works so we need to fallback to a direct
296
  // filesystem check
297
- $executable = file_exists('/usr/bin/gs')
298
- ? '/usr/bin/gs' : false;
299
 
300
  return $executable;
301
  }
@@ -330,13 +329,13 @@ class DG_Thumber {
330
  * @param int $pg The page number to make thumbnail of -- index starts at 1.
331
  * @return bool|str False on failure, URL to thumb on success.
332
  */
333
- public static function getGoogleDriveThumbnail($ID_URL, $pg = 1) {
334
  // User agent for Lynx 2.8.7rel.2 -- Why? Because I can.
335
  static $user_agent = 'Lynx/2.8.7rel.2 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/1.0.0a';
336
  static $timeout = 60;
337
 
338
  $google_viewer = 'https://docs.google.com/viewer?url=%s&a=bi&pagenumber=%d&w=%d';
339
- $doc_url = wp_get_attachment_url($ID_URL);
340
  if (!$doc_url) {
341
  return false;
342
  }
@@ -540,11 +539,9 @@ class DG_Thumber {
540
  * + thumber - Generator used to create thumb OR false if failed to gen.
541
  * @return array|null Thumber options from DB or null if options not initialized.
542
  */
543
- public static function getOptions() {
544
- global $dg_options;
545
- return !empty($dg_options) && isset($dg_options['thumber'])
546
- ? $dg_options['thumber']
547
- : null;
548
  }
549
 
550
  /**
@@ -556,10 +553,10 @@ class DG_Thumber {
556
  * + thumber - Generator used to create thumb OR false if failed to gen.
557
  * @param array $options Thumber options to store in DB
558
  */
559
- private static function setOptions($options) {
560
- global $dg_options;
561
  $dg_options['thumber'] = $options;
562
- update_option(DG_OPTION_NAME, $dg_options);
563
  }
564
 
565
  /**
@@ -573,9 +570,9 @@ class DG_Thumber {
573
  * @return array
574
  */
575
  private static function getThumbers() {
576
- static $thumbers = false;
577
 
578
- if (false === $thumbers) {
579
  $options = self::getOptions();
580
  $active = $options['active'];
581
  $thumbers = array();
@@ -609,9 +606,22 @@ class DG_Thumber {
609
 
610
  // allow users to filter thumbers used
611
  $thumbers = apply_filters('dg_thumbers', $thumbers);
612
-
613
  // strip out anything that can't be called
614
  $thumbers = array_filter($thumbers, 'is_callable');
 
 
 
 
 
 
 
 
 
 
 
 
 
615
  }
616
 
617
  return $thumbers;
@@ -678,7 +688,6 @@ class DG_Thumber {
678
  /**
679
  * Caller should handle removal of the temp file when finished.
680
  *
681
- * @staticvar int $count
682
  * @param str $ext
683
  */
684
  private static function getTempFile($ext = 'png') {
@@ -760,7 +769,7 @@ class DG_Thumber {
760
  * @return str|bool Returns the file extension on success, false on failure.
761
  */
762
  private static function getExt($filename) {
763
- foreach (wp_get_mime_types() as $ext_preg => $unused) {
764
  $ext_preg = '!\.(' . $ext_preg . ')$!i';
765
  if (preg_match($ext_preg, $filename, $ext_matches)) {
766
  return $ext_matches[1];
29
  * @return str URL to the thumbnail.
30
  */
31
  public static function getThumbnail($ID, $pg = 1) {
32
+ static $timeout = null;
33
+ if (is_null($timeout)) {
34
  $timeout = time();
35
  }
36
 
294
  // GoDaddy and others aren't setup in such a way that
295
  // the above works so we need to fallback to a direct
296
  // filesystem check
297
+ $executable = file_exists('/usr/bin/gs') ? '/usr/bin/gs' : false;
 
298
 
299
  return $executable;
300
  }
329
  * @param int $pg The page number to make thumbnail of -- index starts at 1.
330
  * @return bool|str False on failure, URL to thumb on success.
331
  */
332
+ public static function getGoogleDriveThumbnail($ID, $pg = 1) {
333
  // User agent for Lynx 2.8.7rel.2 -- Why? Because I can.
334
  static $user_agent = 'Lynx/2.8.7rel.2 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/1.0.0a';
335
  static $timeout = 60;
336
 
337
  $google_viewer = 'https://docs.google.com/viewer?url=%s&a=bi&pagenumber=%d&w=%d';
338
+ $doc_url = wp_get_attachment_url($ID);
339
  if (!$doc_url) {
340
  return false;
341
  }
539
  * + thumber - Generator used to create thumb OR false if failed to gen.
540
  * @return array|null Thumber options from DB or null if options not initialized.
541
  */
542
+ public static function getOptions($blog = null) {
543
+ $options = DocumentGallery::getOptions($blog);
544
+ return $options['thumber'];
 
 
545
  }
546
 
547
  /**
553
  * + thumber - Generator used to create thumb OR false if failed to gen.
554
  * @param array $options Thumber options to store in DB
555
  */
556
+ private static function setOptions($options, $blog = null) {
557
+ $dg_options = DocumentGallery::getOptions($blog);
558
  $dg_options['thumber'] = $options;
559
+ DocumentGallery::setOptions($dg_options, $blog);
560
  }
561
 
562
  /**
570
  * @return array
571
  */
572
  private static function getThumbers() {
573
+ static $thumbers = null;
574
 
575
+ if (is_null($thumbers)) {
576
  $options = self::getOptions();
577
  $active = $options['active'];
578
  $thumbers = array();
606
 
607
  // allow users to filter thumbers used
608
  $thumbers = apply_filters('dg_thumbers', $thumbers);
609
+
610
  // strip out anything that can't be called
611
  $thumbers = array_filter($thumbers, 'is_callable');
612
+
613
+ // log which thumbers are being used
614
+ if (DocumentGallery::logEnabled()) {
615
+ if (count($thumbers) > 0) {
616
+ $entry = __('Thumbnail Generators: ', 'document-gallery');
617
+ foreach ($thumbers as $k => $v) {
618
+ $entry .= '{' . $k . ' => ' . print_r($v, true) . '} ';
619
+ }
620
+ } else {
621
+ $entry = __('No thumbnail generators enabled.', 'document-gallery');
622
+ }
623
+ DocumentGallery::writeLog($entry);
624
+ }
625
  }
626
 
627
  return $thumbers;
688
  /**
689
  * Caller should handle removal of the temp file when finished.
690
  *
 
691
  * @param str $ext
692
  */
693
  private static function getTempFile($ext = 'png') {
769
  * @return str|bool Returns the file extension on success, false on failure.
770
  */
771
  private static function getExt($filename) {
772
+ foreach (array_keys(wp_get_mime_types()) as $ext_preg) {
773
  $ext_preg = '!\.(' . $ext_preg . ')$!i';
774
  if (preg_match($ext_preg, $filename, $ext_matches)) {
775
  return $ext_matches[1];
languages/document-gallery.pot CHANGED
@@ -2,9 +2,9 @@
2
  # This file is distributed under the same license as the Document Gallery package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Document Gallery 2.0.9\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/document-gallery\n"
7
- "POT-Creation-Date: 2014-04-21 02:57:10+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -20,7 +20,7 @@ msgstr ""
20
  msgid "Document Gallery Settings"
21
  msgstr ""
22
 
23
- #. #-#-#-#-# plugin.pot (Document Gallery 2.0.9) #-#-#-#-#
24
  #. Plugin Name of the plugin/theme
25
  #: admin/class-admin.php:38
26
  msgid "Document Gallery"
@@ -122,35 +122,35 @@ msgstr ""
122
  msgid "Failed to auto-detect the location of Ghostscript."
123
  msgstr ""
124
 
125
- #: admin/class-admin.php:248
126
  msgid ""
127
  "The following values will be used by default in the shortcode. You can still "
128
  "manually set each of these values in each individual shortcode."
129
  msgstr ""
130
 
131
- #: admin/class-admin.php:255
132
  msgid "Select which tools to use when generating thumbnails."
133
  msgstr ""
134
 
135
- #: admin/class-admin.php:261
136
  msgid ""
137
  "Enter custom CSS styling for use with document galleries. To see which ids "
138
  "and classes you can style, take a look at <a href=\"%s\" target=\"_blank"
139
  "\">style.css</a>."
140
  msgstr ""
141
 
142
- #: admin/class-admin.php:279
143
  msgid ""
144
  "Unless you <em>really</em> know what you're doing, you should not touch "
145
  "these values."
146
  msgstr ""
147
 
148
- #: admin/class-admin.php:281
149
  msgid ""
150
  "NOTE: <code>exec()</code> is not accessible. Ghostscript will not function."
151
  msgstr ""
152
 
153
- #: admin/class-admin.php:388
154
  msgid "Invalid Ghostscript path given: "
155
  msgstr ""
156
 
@@ -204,15 +204,23 @@ msgstr ""
204
  msgid "Ghostscript failed: "
205
  msgstr ""
206
 
207
- #: inc/class-thumber.php:364
208
  msgid "Failed to retrieve thumbnail from Google: "
209
  msgstr ""
210
 
211
- #: inc/class-thumber.php:644
 
 
 
 
 
 
 
 
212
  msgid "Failed to get image editor: "
213
  msgstr ""
214
 
215
- #: inc/class-thumber.php:655
216
  msgid "Failed to save image: "
217
  msgstr ""
218
 
2
  # This file is distributed under the same license as the Document Gallery package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Document Gallery 2.1\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/document-gallery\n"
7
+ "POT-Creation-Date: 2014-05-26 15:34:24+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
20
  msgid "Document Gallery Settings"
21
  msgstr ""
22
 
23
+ #. #-#-#-#-# plugin.pot (Document Gallery 2.1) #-#-#-#-#
24
  #. Plugin Name of the plugin/theme
25
  #: admin/class-admin.php:38
26
  msgid "Document Gallery"
122
  msgid "Failed to auto-detect the location of Ghostscript."
123
  msgstr ""
124
 
125
+ #: admin/class-admin.php:262
126
  msgid ""
127
  "The following values will be used by default in the shortcode. You can still "
128
  "manually set each of these values in each individual shortcode."
129
  msgstr ""
130
 
131
+ #: admin/class-admin.php:269
132
  msgid "Select which tools to use when generating thumbnails."
133
  msgstr ""
134
 
135
+ #: admin/class-admin.php:275
136
  msgid ""
137
  "Enter custom CSS styling for use with document galleries. To see which ids "
138
  "and classes you can style, take a look at <a href=\"%s\" target=\"_blank"
139
  "\">style.css</a>."
140
  msgstr ""
141
 
142
+ #: admin/class-admin.php:293
143
  msgid ""
144
  "Unless you <em>really</em> know what you're doing, you should not touch "
145
  "these values."
146
  msgstr ""
147
 
148
+ #: admin/class-admin.php:295
149
  msgid ""
150
  "NOTE: <code>exec()</code> is not accessible. Ghostscript will not function."
151
  msgstr ""
152
 
153
+ #: admin/class-admin.php:407
154
  msgid "Invalid Ghostscript path given: "
155
  msgstr ""
156
 
204
  msgid "Ghostscript failed: "
205
  msgstr ""
206
 
207
+ #: inc/class-thumber.php:372
208
  msgid "Failed to retrieve thumbnail from Google: "
209
  msgstr ""
210
 
211
+ #: inc/class-thumber.php:616
212
+ msgid "Thumbnail Generators: "
213
+ msgstr ""
214
+
215
+ #: inc/class-thumber.php:621
216
+ msgid "No thumbnail generators enabled."
217
+ msgstr ""
218
+
219
+ #: inc/class-thumber.php:663
220
  msgid "Failed to get image editor: "
221
  msgstr ""
222
 
223
+ #: inc/class-thumber.php:674
224
  msgid "Failed to save image: "
225
  msgstr ""
226