Document Gallery - Version 4.3.1

Version Description

  • Enhancement: WordPress 4.7 includes native support for PDF thumbnails. Document Gallery was already using some of this, but this update ensures that DG takes full advantage of the new core functionality, including some new logic to allow older WordPress installs running Document Gallery to take advantage of some of the new goodies.
  • Tested Up To: Document Gallery has been tested in WP 4.7. Big thanks to Bjarne for help with testing.
  • Reminder: Don't forget that Thumber.co can integrate with Document Gallery to greatly expand supported file types (eg: Word, PowerPoint, Publisher, and Photoshop). Thumber.co offers a free 1-week trial if you want to try it before you buy it!
Download this release

Release Info

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

Code changes from version 4.2.6 to 4.3.1

CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
  # Changelog
2
 
 
 
 
 
 
 
 
 
 
 
3
  ## 4.2.6
4
  * **Bug Fix:** Document Gallery was impossible to uninstall on some WordPress systems. This is addressed now.
5
 
1
  # Changelog
2
 
3
+ ## 4.3.1
4
+ * **Enhancement:** WordPress 4.7 includes native support for PDF thumbnails. Document Gallery was already using some
5
+ of this, but this update ensures that DG takes full advantage of the new core functionality, including some new
6
+ logic to allow older WordPress installs running Document Gallery to take advantage of some of the new goodies.
7
+ * **Tested Up To:** Document Gallery has been tested in WP 4.7. Big thanks to
8
+ [Bjarne](https://wordpress.org/support/users/oldrup/) for help with testing.
9
+ * **Reminder:** Don't forget that [Thumber.co](https://thumber.co) can integrate with Document Gallery to greatly
10
+ expand supported file types (eg: Word, PowerPoint, Publisher, and Photoshop). Thumber.co offers a free 1-week trial
11
+ if you want to try it before you buy it!
12
+
13
  ## 4.2.6
14
  * **Bug Fix:** Document Gallery was impossible to uninstall on some WordPress systems. This is addressed now.
15
 
README.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: dan.rossiter, demur
3
  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.6
7
- Stable tag: 4.2.6
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -422,6 +422,16 @@ 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.2.6 =
426
  * **Bug Fix:** Document Gallery was impossible to uninstall on some WordPress systems. This is addressed now.
427
 
3
  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.7
7
+ Stable tag: 4.3.1
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.3.1 =
426
+ * **Enhancement:** WordPress 4.7 includes native support for PDF thumbnails. Document Gallery was already using some
427
+ of this, but this update ensures that DG takes full advantage of the new core functionality, including some new
428
+ logic to allow older WordPress installs running Document Gallery to take advantage of some of the new goodies.
429
+ * **Tested Up To:** Document Gallery has been tested in WP 4.7. Big thanks to
430
+ [Bjarne](https://wordpress.org/support/users/oldrup/) for help with testing.
431
+ * **Reminder:** Don't forget that [Thumber.co](https://thumber.co) can integrate with Document Gallery to greatly
432
+ expand supported file types (eg: Word, PowerPoint, Publisher, and Photoshop). Thumber.co offers a free 1-week trial
433
+ if you want to try it before you buy it!
434
+
435
  = 4.2.6 =
436
  * **Bug Fix:** Document Gallery was impossible to uninstall on some WordPress systems. This is addressed now.
437
 
document-gallery.php CHANGED
@@ -5,14 +5,14 @@ defined( 'WPINC' ) OR exit;
5
  Plugin Name: Document Gallery
6
  Plugin URI: https://wordpress.org/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.2.6
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.2.6' );
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: https://wordpress.org/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.3.1
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.3.1' );
16
 
17
  if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
18
  add_action( 'admin_notices', 'dg_php_lt_three' );
inc/class-image-editor-imagick.php CHANGED
@@ -26,10 +26,106 @@ class DG_Image_Editor_Imagick extends WP_Image_Editor_Imagick {
26
  }
27
 
28
  /**
29
- * Loads the filepath into Imagick object.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  */
31
  public function load() {
32
- $ret = parent::load();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  // set correct page number
35
  if ( ! is_null( $this->pg ) && ! is_wp_error( $ret )
@@ -53,13 +149,40 @@ class DG_Image_Editor_Imagick extends WP_Image_Editor_Imagick {
53
  }
54
 
55
  /**
56
- * @return string[]|bool The formats supported by Imagick, or false
 
 
 
 
 
 
57
  */
58
- public static function query_formats() {
59
- try {
60
- return @Imagick::queryFormats();
61
- } catch ( Exception $ex ) {
62
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  }
 
 
64
  }
65
  }
26
  }
27
 
28
  /**
29
+ * @return string[]|bool The formats supported by Imagick, or false
30
+ */
31
+ public static function query_formats() {
32
+ try {
33
+ return @Imagick::queryFormats();
34
+ } catch ( Exception $ex ) {
35
+ return false;
36
+ }
37
+ }
38
+
39
+ /**
40
+ * TODO: Can be removed once WP < 4.7 is no longer supported
41
+ *
42
+ * Checks to see if current environment supports Imagick.
43
+ *
44
+ * We require Imagick 2.2.0 or greater, based on whether the queryFormats()
45
+ * method can be called statically.
46
+ *
47
+ * @since 3.5.0
48
+ *
49
+ * @static
50
+ * @access public
51
+ *
52
+ * @param array $args
53
+ * @return bool
54
+ */
55
+ public static function test( $args = array() ) {
56
+ global $wp_version;
57
+ if ( version_compare( $wp_version, '4.7.0', '>=' ) ) {
58
+ return parent::test( $args );
59
+ } else {
60
+ return parent::test( $args ) && in_array( 'readimage', array_map( 'strtolower', get_class_methods( 'Imagick' ) ) );
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Loads image from $this->file into new Imagick Object.
66
+ *
67
+ * @since 3.5.0
68
+ * @access protected
69
+ *
70
+ * @return true|WP_Error True if loaded; WP_Error on failure.
71
  */
72
  public function load() {
73
+ if ( $this->image instanceof Imagick ) {
74
+ return true;
75
+ }
76
+
77
+ global $wp_version;
78
+ if ( version_compare( $wp_version, '4.7.0', '>=' ) ) {
79
+ $ret = parent::load();
80
+ } else {
81
+ // TODO: Can be removed once WP < 4.7 is no longer supported
82
+
83
+ if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) )
84
+ $ret = new WP_Error( 'error_loading_image', __('File doesn&#8217;t exist?'), $this->file );
85
+
86
+ /*
87
+ * Even though Imagick uses less PHP memory than GD, set higher limit
88
+ * for users that have low PHP.ini limits.
89
+ */
90
+ if ( version_compare( $wp_version, '4.6.0', '>=' ) ) {
91
+ wp_raise_memory_limit( 'image' );
92
+ } else {
93
+ // TODO: Can be removed once WP < 4.6 is no longer supported
94
+ @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) );
95
+ }
96
+
97
+ try {
98
+ $this->image = new Imagick();
99
+ $file_parts = pathinfo( $this->file );
100
+ $filename = $this->file;
101
+
102
+ if ( 'pdf' == strtolower( $file_parts['extension'] ) ) {
103
+ $filename = $this->pdf_setup();
104
+ }
105
+
106
+ // Reading image after Imagick instantiation because `setResolution`
107
+ // only applies correctly before the image is read.
108
+ $this->image->readImage( $filename );
109
+
110
+ if ( ! $this->image->valid() ) {
111
+ $ret = new WP_Error( 'invalid_image', __( 'File is not an image.' ), $this->file );
112
+ } else {
113
+ $this->mime_type = $this->get_mime_type( $this->image->getImageFormat() );
114
+ }
115
+ }
116
+ catch ( Exception $e ) {
117
+ $ret = new WP_Error( 'invalid_image', $e->getMessage(), $this->file );
118
+ }
119
+
120
+ if ( ! isset( $ret ) ) {
121
+ $updated_size = $this->update_size();
122
+ if ( is_wp_error( $updated_size ) ) {
123
+ $ret = $updated_size;
124
+ } else {
125
+ $ret = $this->set_quality();
126
+ }
127
+ }
128
+ }
129
 
130
  // set correct page number
131
  if ( ! is_null( $this->pg ) && ! is_wp_error( $ret )
149
  }
150
 
151
  /**
152
+ * Sets up Imagick for PDF processing.
153
+ * Increases rendering DPI and only loads first page.
154
+ *
155
+ * @since 4.7.0
156
+ * @access protected
157
+ *
158
+ * @return string|WP_Error File to load or WP_Error on failure.
159
  */
160
+ protected function pdf_setup() {
161
+ $page = !is_null($this->pg) ? "[{$this->pg}]" : '[0]';
162
+
163
+ global $wp_version;
164
+ if ( version_compare( $wp_version, '4.7.0', '>=' ) ) {
165
+ $ret = rtrim( parent::pdf_setup(), '[0]' ) . $page;
166
+ } else {
167
+ // TODO: Can be removed once WP < 4.7 is no longer supported
168
+
169
+ try {
170
+ // By default, PDFs are rendered in a very low resolution.
171
+ // We want the thumbnail to be readable, so increase the rendering DPI.
172
+ $this->image->setResolution( 128, 128 );
173
+
174
+ // Only load the first page.
175
+ $ret = $this->file . $page;
176
+ }
177
+ catch ( Exception $e ) {
178
+ $ret = new WP_Error( 'pdf_setup_failed', $e->getMessage(), $this->file );
179
+ }
180
+ }
181
+
182
+ if ( is_wp_error( $ret ) ) {
183
+ DG_Logger::writeLog( DG_LogLevel::Error, $ret->get_error_code() . ': ' . $ret->get_error_message() );
184
  }
185
+
186
+ return $ret;
187
  }
188
  }
inc/thumbers/class-imagick-thumber.php CHANGED
@@ -86,7 +86,7 @@ class DG_ImagickThumber extends DG_AbstractThumber {
86
  static $ret = null;
87
 
88
  if ( is_null( $ret ) ) {
89
- $ret = WP_Image_Editor_Imagick::test();
90
  }
91
 
92
  return $ret;
86
  static $ret = null;
87
 
88
  if ( is_null( $ret ) ) {
89
+ $ret = DG_Image_Editor_Imagick::test();
90
  }
91
 
92
  return $ret;