Document Gallery - Version 4.2.5

Version Description

  • Bug Fix: Resolves issue where visual editor gallery preview got stuck loading.
Download this release

Release Info

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

Code changes from version 4.2.4 to 4.2.5

CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
  # Changelog
2
 
 
 
3
 
4
  ## 4.2.4
5
  * **Tested Up To:** Document Gallery has been tested in WP 4.6.
1
  # Changelog
2
 
3
+ ## 4.2.5
4
+ * **Bug Fix:** Resolves issue where visual editor gallery preview got stuck loading.
5
 
6
  ## 4.2.4
7
  * **Tested Up To:** Document Gallery has been tested in WP 4.6.
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.6
7
- Stable tag: 4.2.4
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -422,6 +422,9 @@ 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.4 =
426
  * **Tested Up To:** Document Gallery has been tested in WP 4.6.
427
  * **Bug Fix:** Resolves bug in visual editor that would result in the gallery preview never loading in some circumstances.
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.5
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.2.5 =
426
+ * **Bug Fix:** Resolves issue where visual editor gallery preview got stuck loading.
427
+
428
  = 4.2.4 =
429
  * **Tested Up To:** Document Gallery has been tested in WP 4.6.
430
  * **Bug Fix:** Resolves bug in visual editor that would result in the gallery preview never loading in some circumstances.
admin/class-feature-pointers.php CHANGED
@@ -56,6 +56,19 @@ class DG_FeaturePointers {
56
  self::printFeaturePointer( '#thumber-co-tab-header', array( 'content' => $title . $body, 'position' => 'top' ) );
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  /**
60
  * Print the pointer JavaScript data.
61
  * NOTE: Taken from WP_Internal_Pointers.
@@ -67,10 +80,50 @@ class DG_FeaturePointers {
67
  if ( empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
68
  return;
69
 
70
- $trace = debug_backtrace();
 
 
 
71
  $pointer_id = self::getFeaturePointerIdFromMethodName( $trace[1]['function'] );
 
 
72
  ?>
73
- <script>(function(b){var a=<?php echo wp_json_encode( $args ); ?>,c;a&&(a=b.extend(a,{close:function(){b.post(ajaxurl,{pointer:"<?php echo $pointer_id; ?>",action:"dismiss-wp-pointer"})}}),c=function(){b("<?php echo $selector; ?>").first().pointer(a).pointer("open")},a.position&&a.position.defer_loading?b(window).bind("load.wp-pointers",c):b(document).ready(c))})(jQuery);</script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  <?php
75
  }
76
 
@@ -79,7 +132,7 @@ class DG_FeaturePointers {
79
  * @return string The feature pointer ID.
80
  */
81
  private static function getFeaturePointerIdFromMethodName( $method ) {
82
- return substr( $method, 0, strlen( $method ) - strlen( self::$feature_pointer_method_suffix ) );
83
  }
84
 
85
  /**
56
  self::printFeaturePointer( '#thumber-co-tab-header', array( 'content' => $title . $body, 'position' => 'top' ) );
57
  }
58
 
59
+ /**
60
+ * Feature pointer for visual editor when post contains MS Office files.
61
+ */
62
+ public static function dg424_FeaturePointer() {
63
+ $title = '<h3>' . __( 'More Thumbnails!', 'document-gallery' ) . '</h3>';
64
+ $body = '<p>' . sprintf( __( 'It looks like your gallery includes Word, PowerPoint, or some other Microsoft Office ' .
65
+ 'files. Did you know that Document Gallery can generate thumbanils for these too? ' .
66
+ '<a href="%s">Learn more.</a>', 'document-gallery' ),
67
+ 'options-general.php?page=' . DG_OPTION_NAME . '&tab=thumber-co-tab' ) . '</p>';
68
+ $position = array( 'edge' => 'top', 'align' => 'left', 'defer_loading' => true );
69
+ self::printFeaturePointer( '#insert-media-button', array( 'content' => $title . $body, 'position' => $position ) );
70
+ }
71
+
72
  /**
73
  * Print the pointer JavaScript data.
74
  * NOTE: Taken from WP_Internal_Pointers.
80
  if ( empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
81
  return;
82
 
83
+ // optimize version_compare as much as possible based on PHP version
84
+ $trace = version_compare( PHP_VERSION, '5.4', '>=' )
85
+ ? debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 )
86
+ : debug_backtrace( false );
87
  $pointer_id = self::getFeaturePointerIdFromMethodName( $trace[1]['function'] );
88
+
89
+ // NOTE: If below JS is modified, *ensure* that minified is also updated
90
  ?>
91
+ <script>
92
+ <?php if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ): ?>
93
+ (function($){
94
+ var options = <?php echo wp_json_encode( $args ); ?>, setup;
95
+
96
+ if ( ! options )
97
+ return;
98
+
99
+ options = $.extend( options, {
100
+ close: function() {
101
+ $.post( ajaxurl, {
102
+ pointer: '<?php echo $pointer_id; ?>',
103
+ action: 'dismiss-wp-pointer'
104
+ });
105
+ }
106
+ });
107
+
108
+ setup = function() {
109
+ $('<?php echo $selector; ?>').first().pointer( options ).pointer('open');
110
+ };
111
+
112
+ if ( options.position && options.position.defer_loading ) {
113
+ var hdlr = function () {
114
+ setup();
115
+ $('<?php echo $selector; ?>').off('ready.dg', hdlr);
116
+ };
117
+ $('<?php echo $selector; ?>').on('ready.dg', hdlr);
118
+ } else {
119
+ $(document).ready(setup);
120
+ }
121
+
122
+ })( jQuery );
123
+ <?php else: ?>
124
+ (function(a){var b=<?php echo wp_json_encode( $args ); ?>,c;if(b)if(b=a.extend(b,{close:function(){a.post(ajaxurl,{pointer:"<?php echo $pointer_id; ?>",action:"dismiss-wp-pointer"})}}),c=function(){a("<?php echo $selector; ?>").first().pointer(b).pointer("open")},b.position&&b.position.defer_loading){var d=function(){c();a("<?php echo $selector; ?>").off("ready.dg",d)};a("<?php echo $selector; ?>").on("ready.dg",d)}else a(document).ready(c)})(jQuery);
125
+ <?php endif; ?>
126
+ </script>
127
  <?php
128
  }
129
 
132
  * @return string The feature pointer ID.
133
  */
134
  private static function getFeaturePointerIdFromMethodName( $method ) {
135
+ return rtrim( substr( $method, 0, strlen( $method ) - strlen( self::$feature_pointer_method_suffix ) ), '_' );
136
  }
137
 
138
  /**
assets/js/gallery.js CHANGED
@@ -5,8 +5,19 @@
5
  // current index in ids array
6
  var i;
7
 
 
 
 
 
 
 
 
 
 
 
8
  // find all document-icons without icons generated and start processing
9
  $(document).ready(function() {
 
10
  sizeGalleryIcons();
11
  resetPendingIcons();
12
  handleVisualEditor();
@@ -30,10 +41,10 @@
30
  * Handles necessary logic for when we're rendering gallery preview within visual editor.
31
  */
32
  function handleVisualEditor() {
33
- if (typeof tinymce !== 'undefined') {
34
  tinymce.PluginManager.add('dg', function (editor, url) {
35
- editor.on('LoadContent dgUpdate undo', function (e) {
36
- $(e.target.contentDocument).find('.wpview-type-dg > [data-shortcode]').each(function () {
37
  retrieveGallery($.parseJSON(decodeURIComponent($(this).data('shortcode'))), $(this));
38
  });
39
  });
@@ -91,9 +102,14 @@
91
  atts['id'] = wp.media.dgDefaults.id;
92
  }
93
  $.post(ajaxurl, { action: 'dg_generate_gallery', atts: atts }, function(html) {
94
- var jobj = $($.parseHTML(html));
95
- target.replaceWith(jobj);
96
- sizeGalleryIcons(jobj);
 
 
 
 
 
97
  resetPendingIcons();
98
  });
99
  }
5
  // current index in ids array
6
  var i;
7
 
8
+ // whether we're in the visual editor
9
+ var is_editor;
10
+
11
+ // CSS selector to match documents requiring Thumber
12
+ var thumber_exts = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'pub', 'vsd', 'vsdx'];
13
+ var thumber_exts_sel = '.document-gallery [data-ext="' + thumber_exts.join('"],[data-ext="') + '"]';
14
+
15
+ // whether pointer has already been shown
16
+ var thumber_pointer_shown = false;
17
+
18
  // find all document-icons without icons generated and start processing
19
  $(document).ready(function() {
20
+ is_editor = typeof tinymce !== 'undefined';
21
  sizeGalleryIcons();
22
  resetPendingIcons();
23
  handleVisualEditor();
41
  * Handles necessary logic for when we're rendering gallery preview within visual editor.
42
  */
43
  function handleVisualEditor() {
44
+ if (is_editor) {
45
  tinymce.PluginManager.add('dg', function (editor, url) {
46
+ editor.on('LoadContent update.dg undo', function (e) {
47
+ $(e.target.contentDocument).find('[data-wpview-type="dg"] [data-shortcode]').each(function () {
48
  retrieveGallery($.parseJSON(decodeURIComponent($(this).data('shortcode'))), $(this));
49
  });
50
  });
102
  atts['id'] = wp.media.dgDefaults.id;
103
  }
104
  $.post(ajaxurl, { action: 'dg_generate_gallery', atts: atts }, function(html) {
105
+ var parsedHtml = $($.parseHTML(html));
106
+ if ( is_editor && !thumber_pointer_shown && parsedHtml.find(thumber_exts_sel).length ) {
107
+ thumber_pointer_shown = true;
108
+ $('#insert-media-button').trigger('ready.dg');
109
+ }
110
+
111
+ target.replaceWith(parsedHtml);
112
+ sizeGalleryIcons(parsedHtml);
113
  resetPendingIcons();
114
  });
115
  }
assets/js/gallery.min.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(b){function g(a){(a||b(".document-gallery[data-icon-width]")).each(function(){var a=b(this).data("icon-width");"undefined"!==typeof a&&b(this).find(".document-icon").width(a+"%")})}function m(){"undefined"!==typeof tinymce&&tinymce.PluginManager.add("dg",function(a,d){a.on("LoadContent dgUpdate undo",function(a){b(a.target.contentDocument).find(".wpview-type-dg > [data-shortcode]").each(function(){h(b.parseJSON(decodeURIComponent(b(this).data("shortcode"))),b(this))})})})}function n(){b("body").delegate(".dg-paginate-wrapper .paginate a",
2
- "click",function(a){var d=b(this).closest(".dg-paginate-wrapper"),e=d.data("shortcode");e.skip=0;var c=b(this).attr("href").split("#")[1].split("=");2<=c.length&&(e.skip=e.limit*(c.pop()-1));h(e,d);a.preventDefault()})}function k(){c=[];f=0;b(".document-gallery img[data-id]").each(function(){var a=b(this).data("id");-1===b.inArray(a,c)&&c.push(a)});l()}function h(a,d){"undefined"===typeof a.id&&(a.id=wp.media.dgDefaults.id);b.post(ajaxurl,{action:"dg_generate_gallery",atts:a},function(a){a=b(b.parseHTML(a));
3
- d.replaceWith(a);g(a);k()})}function l(){for(var a=[];f<c.length&&4!==a.length;f++)a.push(c[f]);0!=a.length&&b.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"dg_generate_icons",ids:a},success:p,error:function(a){console.error(a.responseText)}})}function p(a){for(var d in a)if(a.hasOwnProperty(d)){var c=b('.document-gallery img[data-id="'+d+'"]');c.removeAttr("data-id");(function(c,d){d.fadeOut("fast",function(){b(this).attr("src",a[c]);b(this).fadeIn("fast")})})(d,c)}l()}var c,f;b(document).ready(function(){g();
4
- k();m();n()})})(jQuery);
1
+ (function(b){function h(a){(a||b(".document-gallery[data-icon-width]")).each(function(){var a=b(this).data("icon-width");"undefined"!==typeof a&&b(this).find(".document-icon").width(a+"%")})}function p(){g&&tinymce.PluginManager.add("dg",function(a,d){a.on("LoadContent update.dg undo",function(a){b(a.target.contentDocument).find('[data-wpview-type="dg"] [data-shortcode]').each(function(){k(b.parseJSON(decodeURIComponent(b(this).data("shortcode"))),b(this))})})})}function q(){b("body").delegate(".dg-paginate-wrapper .paginate a",
2
+ "click",function(a){var d=b(this).closest(".dg-paginate-wrapper"),e=d.data("shortcode");e.skip=0;var c=b(this).attr("href").split("#")[1].split("=");2<=c.length&&(e.skip=e.limit*(c.pop()-1));k(e,d);a.preventDefault()})}function l(){c=[];f=0;b(".document-gallery img[data-id]").each(function(){var a=b(this).data("id");-1===b.inArray(a,c)&&c.push(a)});m()}function k(a,d){"undefined"===typeof a.id&&(a.id=wp.media.dgDefaults.id);b.post(ajaxurl,{action:"dg_generate_gallery",atts:a},function(a){a=b(b.parseHTML(a));
3
+ g&&!n&&a.find(r).length&&(n=!0,b("#insert-media-button").trigger("ready.dg"));d.replaceWith(a);h(a);l()})}function m(){for(var a=[];f<c.length&&4!==a.length;f++)a.push(c[f]);0!=a.length&&b.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"dg_generate_icons",ids:a},success:t,error:function(a){console.error(a.responseText)}})}function t(a){for(var d in a)if(a.hasOwnProperty(d)){var c=b('.document-gallery img[data-id="'+d+'"]');c.removeAttr("data-id");(function(c,d){d.fadeOut("fast",function(){b(this).attr("src",
4
+ a[c]);b(this).fadeIn("fast")})})(d,c)}m()}var c,f,g,r='.document-gallery [data-ext="'+"doc docx ppt pptx xls xlsx pub vsd vsdx".split(" ").join('"],[data-ext="')+'"]',n=!1;b(document).ready(function(){g="undefined"!==typeof tinymce;h();l();p();q()})})(jQuery);
assets/js/media_manager.js CHANGED
@@ -410,7 +410,7 @@
410
  controller.setState(controller.options.state);
411
  controller.reset();
412
  if (typeof tinyMCE != 'undefined') {
413
- tinyMCE.activeEditor.fire('dgUpdate');
414
  }
415
  }
416
  }
410
  controller.setState(controller.options.state);
411
  controller.reset();
412
  if (typeof tinyMCE != 'undefined') {
413
+ tinyMCE.activeEditor.fire('update.dg');
414
  }
415
  }
416
  }
assets/js/media_manager.min.js CHANGED
@@ -7,7 +7,7 @@ b.filter('[value="'+c+'"]').addClass("active")):a.is('input[type="text"], input[
7
  toolbar:"main-dg",filterable:"all",multiple:"add",editable:!1,library:a.query(this.options.library)}),new a.controller.dgEdit({library:this.options.selection,editing:this.options.editing,menu:"dg"}),new a.controller.dgAdd]);this.on("menu:create:dg",this.createMenu,this);this.on("toolbar:create:main-dg",this.createToolbar,this);this.on("menu:render:dg",this.dgMenu,this);this.on("toolbar:render:main-dg",this.maindgToolbar,this);this.on("toolbar:render:dg-edit",this.dgEditToolbar,this);this.on("toolbar:render:dg-add",
8
  this.dgAddToolbar,this)},dgMenu:function(b){var c=this.lastState(),f=c&&c.id,e=this;b.set({cancel:{text:d.canceldgTitle,priority:20,click:function(){f?e.setState(f):e.close();this.controller.modal.focusManager.focus()}},separateCancel:new a.View({className:"separator",priority:40})})},maindgToolbar:function(b){var c=this;this.selectionStatusToolbar(b);b.set("dg",{style:"primary",text:d.dgButton,priority:60,requires:{selection:!0},click:function(){var b=c.state().get("selection");c.state("dg-edit").set("library",
9
  new a.model.Selection(b.models,{props:b.props.toJSON(),multiple:!0}));this.controller.setState("dg-edit");this.controller.modal.focusManager.focus()}})},dgEditToolbar:function(){var b=this.state().get("editing");this.toolbar.set(new a.view.Toolbar({controller:this,items:{insert:{style:"primary",text:b?d.updatedg:d.insertdg,priority:80,requires:{library:!0},click:function(){var c=this.controller,b=c.state();c.close();wp.media.editor.insert(wp.media.dg.shortcode(b.get("library")).string().replace(/\sdgorder=/ig,
10
- " order=").replace(/\sdgorderby=/ig," orderby="));c.setState(c.options.state);c.reset();"undefined"!=typeof tinyMCE&&tinyMCE.activeEditor.fire("dgUpdate")}}}}))},dgAddToolbar:function(){this.toolbar.set(new a.view.Toolbar({controller:this,items:{insert:{style:"primary",text:d.addTodg,priority:80,requires:{selection:!0},click:function(){var b=this.controller,c=b.state();b.state("dg-edit").get("library").add(c.get("selection").models);c.trigger("reset");b.setState("dg-edit")}}}}))}});wp.media._dgDefaults=
11
  {id:wp.media.view.settings.post&&wp.media.view.settings.post.id,columns:dgDefaults.columns,fancy:dgDefaults.fancy,relation:dgDefaults.relation,limit:dgDefaults.limit,mime_types:dgDefaults.mime_types,post_status:dgDefaults.post_status,post_type:dgDefaults.post_type,attachment_pg:dgDefaults.attachment_pg,descriptions:dgDefaults.descriptions,new_window:dgDefaults.new_window,paginate:dgDefaults.paginate,dgorder:dgDefaults.order,dgorderby:dgDefaults.orderby};wp.media.dgDefaults=wp.media.view.settings.dgDefaults?
12
  g.extend({},wp.media._dgDefaults,wp.media.view.settings.dgDefaults):wp.media._dgDefaults;wp.media.dg=new wp.media.collection({tag:"dg",editTitle:wp.media.view.l10n.editdgTitle,defaults:wp.media.dgDefaults,setDefaults:function(b){var c=this,a=!g.isEqual(wp.media.dgDefaults,wp.media._dgDefaults);g.each(this.defaults,function(d,e){b[e]=c.coerce(b,e);d!==b[e]||a&&d!==wp.media._dgDefaults[e]||delete b[e]});return b}})}})(jQuery,_);
13
  "undefined"!==typeof window.wp.mce&&"undefined"!==typeof window.wp.mce.views&&function(h,g,d,a){base={state:[],edit:function(a,b){if(-1==a.search(/\sids\s*=/gi)||-1<a.search(/\s(?!(?:ids|attachment_pg|columns|new_window|descriptions|fancy|orderby|order|paginate|limit)\s*=)[\w\-]+\s*=/gi))tinyMCE.activeEditor.windowManager.alert(DGl10n.unfitSCalert);else{var c=this.type,f=d[c].edit(a.replace(/\sorder\s*=/ig," dgorder=").replace(/\sorderby\s*=/ig," dgorderby="));this.pausePlayers&&this.pausePlayers();
7
  toolbar:"main-dg",filterable:"all",multiple:"add",editable:!1,library:a.query(this.options.library)}),new a.controller.dgEdit({library:this.options.selection,editing:this.options.editing,menu:"dg"}),new a.controller.dgAdd]);this.on("menu:create:dg",this.createMenu,this);this.on("toolbar:create:main-dg",this.createToolbar,this);this.on("menu:render:dg",this.dgMenu,this);this.on("toolbar:render:main-dg",this.maindgToolbar,this);this.on("toolbar:render:dg-edit",this.dgEditToolbar,this);this.on("toolbar:render:dg-add",
8
  this.dgAddToolbar,this)},dgMenu:function(b){var c=this.lastState(),f=c&&c.id,e=this;b.set({cancel:{text:d.canceldgTitle,priority:20,click:function(){f?e.setState(f):e.close();this.controller.modal.focusManager.focus()}},separateCancel:new a.View({className:"separator",priority:40})})},maindgToolbar:function(b){var c=this;this.selectionStatusToolbar(b);b.set("dg",{style:"primary",text:d.dgButton,priority:60,requires:{selection:!0},click:function(){var b=c.state().get("selection");c.state("dg-edit").set("library",
9
  new a.model.Selection(b.models,{props:b.props.toJSON(),multiple:!0}));this.controller.setState("dg-edit");this.controller.modal.focusManager.focus()}})},dgEditToolbar:function(){var b=this.state().get("editing");this.toolbar.set(new a.view.Toolbar({controller:this,items:{insert:{style:"primary",text:b?d.updatedg:d.insertdg,priority:80,requires:{library:!0},click:function(){var c=this.controller,b=c.state();c.close();wp.media.editor.insert(wp.media.dg.shortcode(b.get("library")).string().replace(/\sdgorder=/ig,
10
+ " order=").replace(/\sdgorderby=/ig," orderby="));c.setState(c.options.state);c.reset();"undefined"!=typeof tinyMCE&&tinyMCE.activeEditor.fire("update.dg")}}}}))},dgAddToolbar:function(){this.toolbar.set(new a.view.Toolbar({controller:this,items:{insert:{style:"primary",text:d.addTodg,priority:80,requires:{selection:!0},click:function(){var b=this.controller,c=b.state();b.state("dg-edit").get("library").add(c.get("selection").models);c.trigger("reset");b.setState("dg-edit")}}}}))}});wp.media._dgDefaults=
11
  {id:wp.media.view.settings.post&&wp.media.view.settings.post.id,columns:dgDefaults.columns,fancy:dgDefaults.fancy,relation:dgDefaults.relation,limit:dgDefaults.limit,mime_types:dgDefaults.mime_types,post_status:dgDefaults.post_status,post_type:dgDefaults.post_type,attachment_pg:dgDefaults.attachment_pg,descriptions:dgDefaults.descriptions,new_window:dgDefaults.new_window,paginate:dgDefaults.paginate,dgorder:dgDefaults.order,dgorderby:dgDefaults.orderby};wp.media.dgDefaults=wp.media.view.settings.dgDefaults?
12
  g.extend({},wp.media._dgDefaults,wp.media.view.settings.dgDefaults):wp.media._dgDefaults;wp.media.dg=new wp.media.collection({tag:"dg",editTitle:wp.media.view.l10n.editdgTitle,defaults:wp.media.dgDefaults,setDefaults:function(b){var c=this,a=!g.isEqual(wp.media.dgDefaults,wp.media._dgDefaults);g.each(this.defaults,function(d,e){b[e]=c.coerce(b,e);d!==b[e]||a&&d!==wp.media._dgDefaults[e]||delete b[e]});return b}})}})(jQuery,_);
13
  "undefined"!==typeof window.wp.mce&&"undefined"!==typeof window.wp.mce.views&&function(h,g,d,a){base={state:[],edit:function(a,b){if(-1==a.search(/\sids\s*=/gi)||-1<a.search(/\s(?!(?:ids|attachment_pg|columns|new_window|descriptions|fancy|orderby|order|paginate|limit)\s*=)[\w\-]+\s*=/gi))tinyMCE.activeEditor.windowManager.alert(DGl10n.unfitSCalert);else{var c=this.type,f=d[c].edit(a.replace(/\sorder\s*=/ig," dgorder=").replace(/\sorderby\s*=/ig," dgorderby="));this.pausePlayers&&this.pausePlayers();
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.4
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.4' );
16
 
17
  if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
18
  add_action( 'admin_notices', 'dg_php_lt_three' );
@@ -59,6 +59,15 @@ add_action( 'init', array( 'DocumentGallery', 'addValidation' ) );
59
  // I18n
60
  add_action( 'plugins_loaded', array( 'DocumentGallery', 'loadTextDomain' ) );
61
 
 
 
 
 
 
 
 
 
 
62
  // cleanup cached data when thumbed attachment deleted
63
  include_once DG_PATH . 'inc/class-thumber.php';
64
  add_action( 'delete_attachment', array( 'DG_Thumb', 'cleanupAttachmentMeta' ) );
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.5
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.5' );
16
 
17
  if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
18
  add_action( 'admin_notices', 'dg_php_lt_three' );
59
  // I18n
60
  add_action( 'plugins_loaded', array( 'DocumentGallery', 'loadTextDomain' ) );
61
 
62
+ if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
63
+ add_action( ( is_admin() ? 'admin' : 'wp' ) . '_footer', 'dg_debug_data' );
64
+ function dg_debug_data() {
65
+ echo '<!-- ' . PHP_EOL;
66
+ echo 'Document Gallery Count: ' . ( class_exists( 'DG_Gallery' ) ? count( DG_Gallery::getGalleries() ) : 0 ) . PHP_EOL;
67
+ echo ' -->' . PHP_EOL;
68
+ }
69
+ }
70
+
71
  // cleanup cached data when thumbed attachment deleted
72
  include_once DG_PATH . 'inc/class-thumber.php';
73
  add_action( 'delete_attachment', array( 'DG_Thumb', 'cleanupAttachmentMeta' ) );
inc/class-document.php CHANGED
@@ -15,6 +15,74 @@ class DG_Document {
15
  // general document data
16
  private $description, $gallery, $ID, $link, $title, $title_attribute, $path, $extension, $size;
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  /*==========================================================================
19
  * INIT GALLERY
20
  *=========================================================================*/
@@ -40,14 +108,7 @@ class DG_Document {
40
  $wp_filetype = wp_check_filetype_and_ext( $this->path, basename( $this->path ) );
41
  $this->extension = $wp_filetype['ext'];
42
  $size = @filesize( $this->path );
43
- $this->size = ($size !== false) ? size_format( $size ) : 0;
44
- }
45
-
46
- /**
47
- * @return int The attachment ID.
48
- */
49
- public function getId() {
50
- return $this->ID;
51
  }
52
 
53
  /*==========================================================================
@@ -63,7 +124,7 @@ class DG_Document {
63
  public function __toString() {
64
  include_once DG_PATH . 'inc/class-thumber.php';
65
 
66
- $data = '';
67
  $description = '';
68
  $target = $this->gallery->openLinkInNewWindow() ? '_blank' : '_self';
69
 
@@ -76,7 +137,7 @@ class DG_Document {
76
  }
77
  } else {
78
  // include a data-* attribute for client side to asynchronously request icon after gallery load
79
- $data = 'data-id="' . $this->ID . '"';
80
  }
81
  }
82
 
15
  // general document data
16
  private $description, $gallery, $ID, $link, $title, $title_attribute, $path, $extension, $size;
17
 
18
+ /*==========================================================================
19
+ * GETTERS
20
+ *=========================================================================*/
21
+
22
+ /**
23
+ * @return int The attachment ID.
24
+ */
25
+ public function getId() {
26
+ return $this->ID;
27
+ }
28
+
29
+ /**
30
+ * @return string This document's description.
31
+ */
32
+ public function getDescription() {
33
+ return $this->description;
34
+ }
35
+
36
+ /**
37
+ * @return DG_Gallery The gallery which this document is a member.
38
+ */
39
+ public function getGallery() {
40
+ return $this->gallery;
41
+ }
42
+
43
+ /**
44
+ * @return string The link to be followed when clicking this document.
45
+ */
46
+ public function getLink() {
47
+ return $this->link;
48
+ }
49
+
50
+ /**
51
+ * @return string The title of this document.
52
+ */
53
+ public function getTitle() {
54
+ return $this->title;
55
+ }
56
+
57
+ /**
58
+ * @return string The title attribute string.
59
+ */
60
+ public function getTitleAttribute() {
61
+ return $this->title_attribute;
62
+ }
63
+
64
+ /**
65
+ * @return string The path to this document.
66
+ */
67
+ public function getPath() {
68
+ return $this->path;
69
+ }
70
+
71
+ /**
72
+ * @return string The extension of this document's file.
73
+ */
74
+ public function getExtension() {
75
+ return $this->extension;
76
+ }
77
+
78
+ /**
79
+ * @return string The size of this document human-readable formatted.
80
+ */
81
+ public function getSize() {
82
+ return $this->size;
83
+ }
84
+
85
+
86
  /*==========================================================================
87
  * INIT GALLERY
88
  *=========================================================================*/
108
  $wp_filetype = wp_check_filetype_and_ext( $this->path, basename( $this->path ) );
109
  $this->extension = $wp_filetype['ext'];
110
  $size = @filesize( $this->path );
111
+ $this->size = ($size !== false) ? size_format( $size ) : '0';
 
 
 
 
 
 
 
112
  }
113
 
114
  /*==========================================================================
124
  public function __toString() {
125
  include_once DG_PATH . 'inc/class-thumber.php';
126
 
127
+ $data = 'data-ext="' . $this->extension . '"';
128
  $description = '';
129
  $target = $this->gallery->openLinkInNewWindow() ? '_blank' : '_self';
130
 
137
  }
138
  } else {
139
  // include a data-* attribute for client side to asynchronously request icon after gallery load
140
+ $data .= ' data-id="' . $this->ID . '"';
141
  }
142
  }
143
 
inc/class-gallery.php CHANGED
@@ -17,13 +17,29 @@ class DG_Gallery {
17
  *=========================================================================*/
18
 
19
  private $atts, $taxa;
 
 
 
 
20
  private $docs = array();
 
 
 
 
21
  private $errs = array();
22
 
 
 
 
23
  private $instance;
24
 
25
  private $pg_count = 1, $cur_pg = 1;
26
 
 
 
 
 
 
27
  // templates for HTML output
28
  private static $no_docs, $comment, $defaults;
29
 
@@ -59,8 +75,15 @@ class DG_Gallery {
59
  return $this->atts['descriptions'];
60
  }
61
 
 
 
 
 
 
 
 
62
  /*==========================================================================
63
- * GET AND SET OPTIONS
64
  *=========================================================================*/
65
 
66
  /**
@@ -84,6 +107,51 @@ class DG_Gallery {
84
  DocumentGallery::setOptions( $dg_options, $blog );
85
  }
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  /*==========================================================================
88
  * INIT GALLERY
89
  *=========================================================================*/
@@ -107,6 +175,7 @@ class DG_Gallery {
107
  * @param mixed[] $atts Array of attributes used in shortcode.
108
  */
109
  public function __construct( $atts ) {
 
110
  static $instance = 0;
111
  $this->instance = ++$instance;
112
 
@@ -168,7 +237,7 @@ class DG_Gallery {
168
 
169
  // query DB for all documents requested
170
  try {
171
- foreach ( $this->getDocuments() as $doc ) {
172
  $this->docs[] = new DG_Document( $doc, $this );
173
  }
174
  } catch ( InvalidArgumentException $e ) {
@@ -176,51 +245,13 @@ class DG_Gallery {
176
  }
177
  }
178
 
179
- /**
180
- * Cleans up user input, making sure we don't pass crap on to WP core.
181
- *
182
- * @param mixed[] $old_defaults The previous set of defaults.
183
- * @param mixed[] $defaults The defaults array to sanitize.
184
- * @param string[] &$errs The array of errors, which will be appended with any errors found.
185
- *
186
- * @return mixed[] The sanitized defaults.
187
- */
188
- public static function sanitizeDefaults( $old_defaults, $defaults, &$errs ) {
189
- if ( is_null( $old_defaults ) ) {
190
- $old_defaults = self::getOptions();
191
- }
192
-
193
- // remove invalid keys
194
- $sanitized = is_array( $defaults )
195
- ? array_intersect_key( $defaults, $old_defaults )
196
- : array();
197
-
198
- // add any missing keys & sanitize each new value
199
- foreach ( $old_defaults as $k => $v ) {
200
- if ( ! isset( $sanitized[ $k ] ) ) {
201
- if ( is_bool( $v ) ) {
202
- // checkbox
203
- $sanitized[ $k ] = false;
204
- } else {
205
- // missing value
206
- $sanitized[ $k ] = $v;
207
- }
208
- } else if ( $sanitized[ $k ] !== $v ) { //Sometimes we get boolean in the string form for checkboxes
209
- // sanitize value if different from old value
210
- $sanitized[ $k ] = DG_GallerySanitization::sanitizeParameter( $k, $sanitized[ $k ], $errs );
211
- }
212
- }
213
-
214
- return $sanitized;
215
- }
216
-
217
  /**
218
  * Gets all valid Documents based on the attributes passed by the user.
219
  * NOTE: Keys in returned array are arbitrary and will vary. They should be ignored.
220
  * @return WP_Post[] Contains all documents matching the query.
221
  * @throws InvalidArgumentException Thrown when $this->errs is not empty.
222
  */
223
- private function getDocuments() {
224
  $query = array(
225
  'posts_per_page' => $this->atts['limit'],
226
  'offset' => $this->atts['skip'],
17
  *=========================================================================*/
18
 
19
  private $atts, $taxa;
20
+
21
+ /**
22
+ * @var DG_Document[] The documents in this gallery.
23
+ */
24
  private $docs = array();
25
+
26
+ /**
27
+ * @var string[] The errors in this gallery.
28
+ */
29
  private $errs = array();
30
 
31
+ /**
32
+ * @var int The instance number across all galleries on this page.
33
+ */
34
  private $instance;
35
 
36
  private $pg_count = 1, $cur_pg = 1;
37
 
38
+ /**
39
+ * @var DG_Gallery[] All gallery instances on this page.
40
+ */
41
+ private static $galleries = array();
42
+
43
  // templates for HTML output
44
  private static $no_docs, $comment, $defaults;
45
 
75
  return $this->atts['descriptions'];
76
  }
77
 
78
+ /**
79
+ * @return DG_Document[] The documents in this gallery.
80
+ */
81
+ public function getDocuments() {
82
+ return $this->docs;
83
+ }
84
+
85
  /*==========================================================================
86
+ * PUBLIC CLASS METHODS
87
  *=========================================================================*/
88
 
89
  /**
107
  DocumentGallery::setOptions( $dg_options, $blog );
108
  }
109
 
110
+ /**
111
+ * Cleans up user input, making sure we don't pass crap on to WP core.
112
+ *
113
+ * @param mixed[] $old_defaults The previous set of defaults.
114
+ * @param mixed[] $defaults The defaults array to sanitize.
115
+ * @param string[] &$errs The array of errors, which will be appended with any errors found.
116
+ *
117
+ * @return mixed[] The sanitized defaults.
118
+ */
119
+ public static function sanitizeDefaults( $old_defaults, $defaults, &$errs ) {
120
+ if ( is_null( $old_defaults ) ) {
121
+ $old_defaults = self::getOptions();
122
+ }
123
+
124
+ // remove invalid keys
125
+ $sanitized = is_array( $defaults )
126
+ ? array_intersect_key( $defaults, $old_defaults )
127
+ : array();
128
+
129
+ // add any missing keys & sanitize each new value
130
+ foreach ( $old_defaults as $k => $v ) {
131
+ if ( ! isset( $sanitized[ $k ] ) ) {
132
+ if ( is_bool( $v ) ) {
133
+ // checkbox
134
+ $sanitized[ $k ] = false;
135
+ } else {
136
+ // missing value
137
+ $sanitized[ $k ] = $v;
138
+ }
139
+ } else if ( $sanitized[ $k ] !== $v ) { //Sometimes we get boolean in the string form for checkboxes
140
+ // sanitize value if different from old value
141
+ $sanitized[ $k ] = DG_GallerySanitization::sanitizeParameter( $k, $sanitized[ $k ], $errs );
142
+ }
143
+ }
144
+
145
+ return $sanitized;
146
+ }
147
+
148
+ /**
149
+ * @return DG_Gallery[] The gallery instances on this page.
150
+ */
151
+ public static function getGalleries() {
152
+ return self::$galleries;
153
+ }
154
+
155
  /*==========================================================================
156
  * INIT GALLERY
157
  *=========================================================================*/
175
  * @param mixed[] $atts Array of attributes used in shortcode.
176
  */
177
  public function __construct( $atts ) {
178
+ self::$galleries[] = $this;
179
  static $instance = 0;
180
  $this->instance = ++$instance;
181
 
237
 
238
  // query DB for all documents requested
239
  try {
240
+ foreach ( $this->getAttachments() as $doc ) {
241
  $this->docs[] = new DG_Document( $doc, $this );
242
  }
243
  } catch ( InvalidArgumentException $e ) {
245
  }
246
  }
247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  /**
249
  * Gets all valid Documents based on the attributes passed by the user.
250
  * NOTE: Keys in returned array are arbitrary and will vary. They should be ignored.
251
  * @return WP_Post[] Contains all documents matching the query.
252
  * @throws InvalidArgumentException Thrown when $this->errs is not empty.
253
  */
254
+ private function getAttachments() {
255
  $query = array(
256
  'posts_per_page' => $this->atts['limit'],
257
  'offset' => $this->atts['skip'],
inc/thumbers/class-thumber-co-thumber.php CHANGED
@@ -29,12 +29,19 @@ class DG_ThumberCoThumber extends DG_AbstractThumber {
29
  */
30
  private static $client;
31
 
 
 
 
 
 
 
 
 
32
  /**
33
  * Initializes the static values for this class.
34
  */
35
  public static function init() {
36
- $options = DG_Thumber::getOptions();
37
- if ( $options['active']['thumber-co'] ) {
38
  parent::init();
39
  self::$webhook = admin_url( 'admin-post.php?action=' . self::ThumberAction );
40
  self::$client = DG_ThumberClient::getInstance();
29
  */
30
  private static $client;
31
 
32
+ /**
33
+ * @return bool Whether Thumber.co is enabled.
34
+ */
35
+ public static function thumberEnabled() {
36
+ $options = DG_Thumber::getOptions();
37
+ return $options['active']['thumber-co'];
38
+ }
39
+
40
  /**
41
  * Initializes the static values for this class.
42
  */
43
  public static function init() {
44
+ if ( self::thumberEnabled() ) {
 
45
  parent::init();
46
  self::$webhook = admin_url( 'admin-post.php?action=' . self::ThumberAction );
47
  self::$client = DG_ThumberClient::getInstance();