Document Gallery - Version 4.1.9

Version Description

  • Bug Fix: Addresses issues with the IMagick thumbnail generation.
  • Enhancement: Handling thumbnail generation for image attachments better (should be faster & more reliable).
Download this release

Release Info

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

Code changes from version 4.1.8 to 4.1.9

CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
  # Changelog
2
 
 
 
 
 
3
  ## 4.1.8
4
  * **Bug Fix:** There was a minor bug in how thumbnails for image attachments were being generated. It has been addressed.
5
 
1
  # Changelog
2
 
3
+ ## 4.1.9
4
+ * **Bug Fix:** Addresses issues with the IMagick thumbnail generation.
5
+ * **Enhancement:** Handling thumbnail generation for image attachments better (should be faster & more reliable).
6
+
7
  ## 4.1.8
8
  * **Bug Fix:** There was a minor bug in how thumbnails for image attachments were being generated. It has been addressed.
9
 
README.txt CHANGED
@@ -4,7 +4,7 @@ Tags: attachments, library, thumbnail, documents, gallery, word, 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: 4.1
6
  Tested up to: 4.4
7
- Stable tag: 4.1.8
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -422,6 +422,10 @@ To see a list of features planned for the future as well as to propose your own
422
  ideas for future Document Gallery development, take a look at our
423
  [issue tracker](https://github.com/thenadz/document-gallery/issues).
424
 
 
 
 
 
425
  = 4.1.8 =
426
  * **Bug Fix:** There was a minor bug in how thumbnails for image attachments were being generated. It has been addressed.
427
 
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: 4.1
6
  Tested up to: 4.4
7
+ Stable tag: 4.1.9
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
422
  ideas for future Document Gallery development, take a look at our
423
  [issue tracker](https://github.com/thenadz/document-gallery/issues).
424
 
425
+ = 4.1.9 =
426
+ * **Bug Fix:** Addresses issues with the IMagick thumbnail generation.
427
+ * **Enhancement:** Handling thumbnail generation for image attachments better (should be faster & more reliable).
428
+
429
  = 4.1.8 =
430
  * **Bug Fix:** There was a minor bug in how thumbnails for image attachments were being generated. It has been addressed.
431
 
document-gallery.php CHANGED
@@ -5,14 +5,14 @@ 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: 4.1.8
9
  Author: Dan Rossiter
10
  Author URI: http://danrossiter.org/
11
  License: GPLv3
12
  Text Domain: document-gallery
13
  */
14
 
15
- define( 'DG_VERSION', '4.1.8' );
16
 
17
  if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
18
  add_action( 'admin_notices', 'dg_php_lt_three' );
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: 4.1.9
9
  Author: Dan Rossiter
10
  Author URI: http://danrossiter.org/
11
  License: GPLv3
12
  Text Domain: document-gallery
13
  */
14
 
15
+ define( 'DG_VERSION', '4.1.9' );
16
 
17
  if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
18
  add_action( 'admin_notices', 'dg_php_lt_three' );
inc/thumbers/class-abstract-thumber.php CHANGED
@@ -45,7 +45,7 @@ abstract class DG_AbstractThumber {
45
  }
46
 
47
  /**
48
- * @return string[] The extensions supported by this thumber.
49
  */
50
  protected abstract function getThumberExtensions();
51
 
@@ -66,7 +66,7 @@ abstract class DG_AbstractThumber {
66
  * @return bool Whether the attachment is supported by this thumber.
67
  */
68
  public function supportsAttachment( $ID ) {
69
- return in_array( self::getAttachmentExt( $ID ), $this->getThumberExtensions() );
70
  }
71
 
72
  /**
45
  }
46
 
47
  /**
48
+ * @return string[] The extensions supported by this thumber in lowercase.
49
  */
50
  protected abstract function getThumberExtensions();
51
 
66
  * @return bool Whether the attachment is supported by this thumber.
67
  */
68
  public function supportsAttachment( $ID ) {
69
+ return in_array( strtolower( self::getAttachmentExt( $ID ) ), $this->getThumberExtensions() );
70
  }
71
 
72
  /**
inc/thumbers/class-default-thumber.php CHANGED
@@ -16,7 +16,7 @@ class DG_DefaultThumber extends DG_AbstractThumber {
16
  }
17
 
18
  /**
19
- * Get thumbnail for document with given ID from default images.
20
  *
21
  * @param string $ID The attachment ID to retrieve thumbnail from.
22
  * @param int $pg Unused.
@@ -24,13 +24,18 @@ class DG_DefaultThumber extends DG_AbstractThumber {
24
  * @return string URL to thumbnail.
25
  */
26
  public function getThumbnail( $ID, $pg = 1 ) {
 
27
  $icon_url = DG_URL . 'assets/icons/';
 
28
 
29
  // handle images
30
- if ( $name = self::getDefaultIcon( self::getExt( wp_get_attachment_url( $ID ) ) ) ) {
 
 
 
31
  $icon = $icon_url . $name;
32
- } // fallback to standard WP icons
33
- elseif ( ! $icon = wp_mime_type_icon( $ID ) ) {
34
  // everything failed. This is bad...
35
  $icon = $icon_url . 'missing.png';
36
  }
@@ -38,6 +43,22 @@ class DG_DefaultThumber extends DG_AbstractThumber {
38
  return $icon;
39
  }
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  /**
42
  * @return string[] The extensions supported by this thumber.
43
  */
16
  }
17
 
18
  /**
19
+ * Get thumbnail URL for document with given ID from default images.
20
  *
21
  * @param string $ID The attachment ID to retrieve thumbnail from.
22
  * @param int $pg Unused.
24
  * @return string URL to thumbnail.
25
  */
26
  public function getThumbnail( $ID, $pg = 1 ) {
27
+ static $image_exts = array( 'jpg', 'jpeg', 'gif', 'png' );
28
  $icon_url = DG_URL . 'assets/icons/';
29
+ $ext = self::getExt( wp_get_attachment_url( $ID ) );
30
 
31
  // handle images
32
+ if ( in_array( $ext, $image_exts ) && ( $icon = self::getImageThumbnail( $ID ) ) ) {
33
+ // Nothing to do
34
+ } elseif ( $name = self::getDefaultIcon( $ext ) ) {
35
+ // try DG custom default icons first
36
  $icon = $icon_url . $name;
37
+ // then fall back to standard WP default icons
38
+ } elseif ( ! $icon = wp_mime_type_icon( $ID ) ) {
39
  // everything failed. This is bad...
40
  $icon = $icon_url . 'missing.png';
41
  }
43
  return $icon;
44
  }
45
 
46
+ /**
47
+ * @param string $ID The attachment ID to retrieve thumbnail from.
48
+ *
49
+ * @return bool|string False on failure, URL to thumb on success.
50
+ */
51
+ private static function getImageThumbnail( $ID ) {
52
+ $options = DG_Thumber::getOptions();
53
+ $ret = false;
54
+
55
+ if ( $icon = image_downsize( $ID, array( $options['width'], $options['height'] ) ) ) {
56
+ $ret = $icon[0];
57
+ }
58
+
59
+ return $ret;
60
+ }
61
+
62
  /**
63
  * @return string[] The extensions supported by this thumber.
64
  */
inc/thumbers/class-image-thumber.php DELETED
@@ -1,33 +0,0 @@
1
- <?php
2
- defined( 'WPINC' ) OR exit;
3
-
4
- class DG_ImageThumber extends DG_AbstractThumber {
5
-
6
- /**
7
- * @return string[] The extensions supported by this thumber.
8
- */
9
- protected function getThumberExtensions() {
10
- return array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
11
- }
12
-
13
- /**
14
- * @param string $ID The attachment ID to retrieve thumbnail from.
15
- * @param int $pg Unused.
16
- *
17
- * @return bool|string False on failure, URL to thumb on success.
18
- */
19
- public function getThumbnail( $ID, $pg = 1 ) {
20
- $img = get_attached_file( $ID );
21
- $tmp = DG_Util::getTempFile( self::getExt( $img ) );
22
- return @link( $img, $tmp ) ? $tmp : false;
23
- }
24
-
25
- /**
26
- * @return int An integer from 0 to 100. Higher priorities will be attempted before lower priority thumbers.
27
- */
28
- public function getPriority() {
29
- return 100;
30
- }
31
- }
32
-
33
- DG_ImageThumber::init();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/thumbers/class-imagick-thumber.php CHANGED
@@ -5,6 +5,11 @@ include_once DG_PATH . 'inc/class-image-editor-imagick.php';
5
 
6
  class DG_ImagickThumber extends DG_AbstractThumber {
7
 
 
 
 
 
 
8
  /**
9
  * Initialize the thumber class for use in thumbnail generation.
10
  */
@@ -13,6 +18,12 @@ class DG_ImagickThumber extends DG_AbstractThumber {
13
  $active = $options['active'];
14
  if ( $active['imagick'] && self::isImagickAvailable() ) {
15
  parent::init();
 
 
 
 
 
 
16
  }
17
  }
18
 
@@ -20,11 +31,7 @@ class DG_ImagickThumber extends DG_AbstractThumber {
20
  * @return string[] The extensions supported by this thumber.
21
  */
22
  protected function getThumberExtensions() {
23
- if ( ! ($ret = DG_Image_Editor_Imagick::query_formats()) ) {
24
- $ret = array();
25
- }
26
-
27
- return $ret;
28
  }
29
 
30
  /**
5
 
6
  class DG_ImagickThumber extends DG_AbstractThumber {
7
 
8
+ /**
9
+ * @var string[] Supported file formats.
10
+ */
11
+ private static $file_formats;
12
+
13
  /**
14
  * Initialize the thumber class for use in thumbnail generation.
15
  */
18
  $active = $options['active'];
19
  if ( $active['imagick'] && self::isImagickAvailable() ) {
20
  parent::init();
21
+
22
+ if ( !(self::$file_formats = DG_Image_Editor_Imagick::query_formats()) ) {
23
+ self::$file_formats = array();
24
+ }
25
+ $image_exts = array( 'jpg', 'jpeg', 'gif', 'png' );
26
+ self::$file_formats = array_map( 'strtolower', array_diff( self::$file_formats, $image_exts ) );
27
  }
28
  }
29
 
31
  * @return string[] The extensions supported by this thumber.
32
  */
33
  protected function getThumberExtensions() {
34
+ return self::$file_formats;
 
 
 
 
35
  }
36
 
37
  /**