Document Gallery - Version 3.4.2

Version Description

  • Bug Fix: Resolves issues in handling manual thumbnail uploads that were introduced in 3.4.
Download this release

Release Info

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

Code changes from version 3.4.1 to 3.4.2

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: 4.1
6
  Tested up to: 4.3
7
- Stable tag: 3.4.1
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -438,6 +438,9 @@ To see a list of features planned for the future as well as to propose your own
438
  ideas for future Document Gallery development, take a look at our
439
  [issue tracker](https://github.com/thenadz/document-gallery/issues).
440
 
 
 
 
441
  = 3.4 =
442
  * **Enhancement:** To address recent issues resulting from corrupt plugin options, we're making option validation no longer
443
  optional. This was an advanced feature that most users were likely not aware of, but it allows us to provide more
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.3
7
+ Stable tag: 3.4.2
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
438
  ideas for future Document Gallery development, take a look at our
439
  [issue tracker](https://github.com/thenadz/document-gallery/issues).
440
 
441
+ = 3.4.2 =
442
+ * **Bug Fix:** Resolves issues in handling manual thumbnail uploads that were introduced in `3.4`.
443
+
444
  = 3.4 =
445
  * **Enhancement:** To address recent issues resulting from corrupt plugin options, we're making option validation no longer
446
  optional. This was an advanced feature that most users were likely not aware of, but it allows us to provide more
admin/class-admin.php CHANGED
@@ -515,14 +515,20 @@ class DG_Admin {
515
  // per page load, re-returning the previous result on any
516
  // subsequent calls.
517
  static $ret = null;
518
- if ( is_null( $values ) ) {
519
- $ret = $values;
520
- }
 
 
 
 
 
 
521
 
522
- if ( array_key_exists( 'tab', $values ) && array_key_exists( $values['tab'], self::getTabs() ) ) {
523
- $funct = 'validate' . $values['tab'] . 'Settings';
524
- unset( $values['tab'] );
525
- $ret = DG_Admin::$funct( $values );
526
  }
527
 
528
  return $ret;
@@ -680,10 +686,10 @@ class DG_Admin {
680
  // Thumbnail file manual refresh (one at a time)
681
  // upload value is a marker
682
  elseif ( isset( $values['upload'] ) && isset( $_FILES['file'] ) && isset( $ret['thumber']['thumbs'][ $ID ] ) ) {
683
- $old_path = $ret['thumber']['thumbs'][ $ID ]['thumb_path'];
684
  $uploaded_filename = self::validateUploadedFile();
685
  if ( $uploaded_filename && DG_Thumber::setThumbnail( $ID, $uploaded_filename ) ) {
686
- if ( $dg_options['thumber']['thumbs'][ $ID ]['thumb_path'] !== $old_path ) {
687
  @unlink( $old_path );
688
  }
689
  $responseArr['result'] = true;
@@ -692,8 +698,10 @@ class DG_Admin {
692
  }
693
  }
694
 
695
- if ( isset( $values['ajax'] ) ) {
696
- wp_send_json( $responseArr );
 
 
697
  }
698
 
699
  return $ret;
@@ -1169,19 +1177,21 @@ class DG_Admin {
1169
  } else {
1170
  $ID = - 1;
1171
  }
 
1172
  if ( isset( $_POST[ DG_OPTION_NAME ]['upload'] ) && isset( $_FILES['file'] ) && isset( $dg_options['thumber']['thumbs'][ $ID ] ) ) {
1173
- $old_path = $dg_options['thumber']['thumbs'][ $ID ]['thumb_path'];
1174
  $uploaded_filename = self::validateUploadedFile();
1175
  if ( $uploaded_filename && DG_Thumber::setThumbnail( $ID, $uploaded_filename ) ) {
1176
- if ( $dg_options['thumber']['thumbs'][ $ID ]['thumb_path'] !== $old_path ) {
1177
  @unlink( $old_path );
1178
  }
1179
  $responseArr['result'] = true;
1180
  $responseArr['url'] = $dg_options['thumber']['thumbs'][ $ID ]['thumb_url'];
1181
  }
1182
  }
 
1183
  if ( isset( $_POST[ DG_OPTION_NAME ]['ajax'] ) ) {
1184
- wp_send_json($responseArr);
1185
  }
1186
  }
1187
 
@@ -1375,6 +1385,13 @@ class DG_Admin {
1375
  return 'asc' === self::$URL_params['order'] ? $ret : -$ret;
1376
  }
1377
 
 
 
 
 
 
 
 
1378
  /**
1379
  * Blocks instantiation. All functions are static.
1380
  */
515
  // per page load, re-returning the previous result on any
516
  // subsequent calls.
517
  static $ret = null;
518
+ if ( is_null( $ret ) ) {
519
+ if ( empty( $values['tab'] ) || ! array_key_exists( $values['tab'], self::getTabs() ) ) {
520
+ global $dg_options;
521
+ return $dg_options;
522
+ } else {
523
+ if ( array_key_exists( 'ajax', $values ) ) {
524
+ unset( $values['ajax'] );
525
+ define( 'DOING_AJAX', true );
526
+ }
527
 
528
+ $funct = 'validate' . $values['tab'] . 'Settings';
529
+ unset( $values['tab'] );
530
+ $ret = DG_Admin::$funct( $values );
531
+ }
532
  }
533
 
534
  return $ret;
686
  // Thumbnail file manual refresh (one at a time)
687
  // upload value is a marker
688
  elseif ( isset( $values['upload'] ) && isset( $_FILES['file'] ) && isset( $ret['thumber']['thumbs'][ $ID ] ) ) {
689
+ $old_path = DG_Util::hasThumb( $ID ) ? $ret['thumber']['thumbs'][ $ID ]['thumb_path'] : null;
690
  $uploaded_filename = self::validateUploadedFile();
691
  if ( $uploaded_filename && DG_Thumber::setThumbnail( $ID, $uploaded_filename ) ) {
692
+ if ( ! is_null( $old_path ) && $dg_options['thumber']['thumbs'][ $ID ]['thumb_path'] !== $old_path ) {
693
  @unlink( $old_path );
694
  }
695
  $responseArr['result'] = true;
698
  }
699
  }
700
 
701
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
702
+ @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
703
+ echo wp_json_encode( $responseArr );
704
+ add_filter( 'wp_redirect', array( __CLASS__, '_exit' ), 1, 0 );
705
  }
706
 
707
  return $ret;
1177
  } else {
1178
  $ID = - 1;
1179
  }
1180
+
1181
  if ( isset( $_POST[ DG_OPTION_NAME ]['upload'] ) && isset( $_FILES['file'] ) && isset( $dg_options['thumber']['thumbs'][ $ID ] ) ) {
1182
+ $old_path = DG_Util::hasThumb($ID) ? $dg_options['thumber']['thumbs'][ $ID ]['thumb_path'] : null;
1183
  $uploaded_filename = self::validateUploadedFile();
1184
  if ( $uploaded_filename && DG_Thumber::setThumbnail( $ID, $uploaded_filename ) ) {
1185
+ if ( ! is_null($old_path) && $dg_options['thumber']['thumbs'][ $ID ]['thumb_path'] !== $old_path ) {
1186
  @unlink( $old_path );
1187
  }
1188
  $responseArr['result'] = true;
1189
  $responseArr['url'] = $dg_options['thumber']['thumbs'][ $ID ]['thumb_url'];
1190
  }
1191
  }
1192
+
1193
  if ( isset( $_POST[ DG_OPTION_NAME ]['ajax'] ) ) {
1194
+ wp_send_json( $responseArr );
1195
  }
1196
  }
1197
 
1385
  return 'asc' === self::$URL_params['order'] ? $ret : -$ret;
1386
  }
1387
 
1388
+ /**
1389
+ * Wraps the PHP exit language construct.
1390
+ */
1391
+ public static function _exit() {
1392
+ exit;
1393
+ }
1394
+
1395
  /**
1396
  * Blocks instantiation. All functions are static.
1397
  */
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: 3.4.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', '3.4.1' );
16
 
17
  // define helper paths & URLs
18
  define( 'DG_BASENAME', plugin_basename( __FILE__ ) );
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: 3.4.2
9
  Author: Dan Rossiter
10
  Author URI: http://danrossiter.org/
11
  License: GPLv2
12
  Text Domain: document-gallery
13
  */
14
 
15
+ define( 'DG_VERSION', '3.4.2' );
16
 
17
  // define helper paths & URLs
18
  define( 'DG_BASENAME', plugin_basename( __FILE__ ) );
inc/class-thumber.php CHANGED
@@ -771,14 +771,16 @@ class DG_Thumber {
771
  if ( $ext = pathinfo( $filename, PATHINFO_EXTENSION ) ) {
772
  $res = preg_grep( '/^(?:.*\|)?' . $ext . '(?:\|.*)?$/i', self::getAllExts() );
773
  $res = reset( $res );
774
- if ( $res !== false ) {
775
- return $ext;
776
  }
777
- } elseif ( ( $info = getimagesize( $filename ) ) && ( $ext = image_type_to_extension( $info[2], false ) ) ) {
 
 
778
  return $ext;
779
  }
780
 
781
- return false;
782
  }
783
 
784
  /**
771
  if ( $ext = pathinfo( $filename, PATHINFO_EXTENSION ) ) {
772
  $res = preg_grep( '/^(?:.*\|)?' . $ext . '(?:\|.*)?$/i', self::getAllExts() );
773
  $res = reset( $res );
774
+ if ( $res === false ) {
775
+ $ext = false;
776
  }
777
+ }
778
+
779
+ if ( ! $ext && ( $info = getimagesize( $filename ) ) && ( $ext = image_type_to_extension( $info[2], false ) ) ) {
780
  return $ext;
781
  }
782
 
783
+ return $ext;
784
  }
785
 
786
  /**
inc/class-util.php CHANGED
@@ -35,6 +35,18 @@ class DG_Util {
35
  return $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
36
  }
37
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  /**
39
  * @param mixed $maybeint Data you wish to have converted to a positive integer.
40
  *
35
  return $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
36
  }
37
 
38
+ /**
39
+ * Whether the given attachment has a thumbanil graphic.
40
+ *
41
+ * @param $ID int The id of the attachment to be checked.
42
+ * @return bool Whether the given attachment has a thumbnail image.
43
+ */
44
+ public static function hasThumb($ID) {
45
+ $options = DocumentGallery::getOptions();
46
+ $thumbs = $options['thumber']['thumbs'];
47
+ return array_key_exists($ID, $thumbs) && ! empty( $thumbs[ $ID ]['thumber'] );
48
+ }
49
+
50
  /**
51
  * @param mixed $maybeint Data you wish to have converted to a positive integer.
52
  *