Document Gallery - Version 1.4

Version Description

  • New Feature: This release features the addition of category/taxonomy support, as suggested by Pyo.
  • Under The Hood: The plugin was completely rewritten for this release. Logic was cleaned up to make maintenance easier and facilitate some big changes planned for version 2.0 of Document Gallery.
Download this release

Release Info

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

Code changes from version 1.3.1 to 1.4

bootstrap.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Borrowed from Google Doc Embedder
3
+ // http://wordpress.org/plugins/google-document-embedder/
4
+
5
+ // define custom path to wp-load.php (usually not necessary)
6
+ $path = '';
7
+
8
+ // bootstrap for getting ABSPATH constant to wp-load.php outside the admin screen
9
+ if ( ! defined('WP_LOAD_PATH') ) {
10
+ $classic_root = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) . '/';
11
+ if ( file_exists( $classic_root . 'wp-load.php' ) ) {
12
+ define('WP_LOAD_PATH', $classic_root);
13
+ } else {
14
+ if ( file_exists( $path . 'wp-load.php' ) ) {
15
+ define('WP_LOAD_PATH', $path);
16
+ } else {
17
+ exit( 'Could not find wp-load.php' );
18
+ }
19
+ }
20
+ }
21
+
22
+ // load wp-load.php
23
+ require_once( WP_LOAD_PATH . 'wp-load.php' );
24
+
25
+ define( 'DG_PERM_ERROR', '<p>'.__('You do not have sufficient permissions to access this page.').'</p>' );
26
+
27
+ ?>
dgembedder.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // access WP functions externally
4
+ require_once('bootstrap.php');
5
+
6
+ $type = $url = null;
7
+
8
+ // no access if parent plugin is disabled
9
+ if ( ! function_exists('dg_get_attachment_icons') ) {
10
+ wp_die(DG_PERM_ERROR);
11
+ }
12
+
13
+ if(isset($_GET['type'])) {
14
+ if($_GET['type'] === 'not_supported') {
15
+ wp_die('<p>'.__('This attachment type is not yet supported. Sorry for the inconvenience!').'</p>');
16
+ }
17
+ $type = $_GET['type'];
18
+ }
19
+ else {
20
+ wp_die(DG_PERM_ERROR);
21
+ }
22
+
23
+ if(isset($_GET['id'])) {
24
+ $url = wp_get_attachment_url($_GET['id']);
25
+
26
+ if($url === false) {
27
+ wp_die('<p>'.__('The ID provided is invalid.').'</p>');
28
+ }
29
+ }
30
+ else {
31
+ wp_die(DG_PERM_ERROR);
32
+ }
33
+
34
+ switch($type) {
35
+ case 'google' :
36
+ break;
37
+ case 'video' :
38
+ break;
39
+ case 'audio' :
40
+ break;
41
+ default :
42
+ wp_die(DG_PERM_ERROR);
43
+ }
document-gallery.php CHANGED
@@ -1,318 +1,39 @@
1
  <?php
2
- /*
3
- Plugin Name: Document Gallery
4
- Description: Display non-images (and images) in gallery format on a page or post with the [dg] shortcode.
5
- Version: 1.3.1
6
- Author: Dan Rossiter
7
- Author URI: http://danrossiter.org/
8
- License: GPL2
9
- */
10
-
11
- define( 'DG_URL', plugin_dir_url( __FILE__ ) );
12
- define( 'DG_IMG_STRING', '<img src="%s" title="%s" alt="%s" />' );
13
- define( 'DG_DOC_ICON',
14
- ' <div class="document-icon">'.PHP_EOL.
15
- ' <a href="%s">%s<br>%s</a>'.PHP_EOL.
16
- ' </div>'.PHP_EOL );
17
 
18
- // CREATE GALLERY STRING //
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  function dg_get_attachment_icons($atts) {
20
- extract( shortcode_atts( array(
21
- 'descriptions' => FALSE,
22
- 'orderby' => 'menu_order',
23
- 'order' => 'ASC',
24
- 'attachment_pg' => FALSE, // default: link directly to file (true to link to attachment pg)
25
- 'images' => FALSE, // if enabled, all images attached to current page will be included also
26
- 'ids' => FALSE // comma-separated list of attachment ids
27
- ), $atts) );
28
-
29
- // INIT
30
- $attachments = array();
31
- $count = 0;
32
- $errs = array();
33
-
34
-
35
- // ATTRIBUTE VALIDATION
36
- $order = strtoupper( $order );
37
- if($order != 'ASC' && $order != 'DEC')
38
- $errs[] = "The order attribute must be either ASC or DEC. You entered $order.";
39
-
40
- if( strtolower($ids) == "false" ) $ids = FALSE;
41
-
42
- $descriptions = !$descriptions || strtolower($descriptions) == "false" ? FALSE : TRUE;
43
- $attachment_pg = !$attachment_pg || strtolower($attachment_pg) == "false" ? FALSE : TRUE;
44
- $images = !$images || strtolower($images) == "false" ? FALSE : TRUE;
45
-
46
- // http://www.youtube.com/watch?v=ClnSMCdw6E8
47
- if( $errs ) return implode(' ', $errs);
48
- // END VALIDATION (WE MADE IT!)
49
-
50
-
51
- // LET'S GET SOME DOCUMENTS!
52
- if( $ids && ( $ids = explode( ',', $ids ) ) )
53
- $attachments = dg_get_attachments_by_ids( $ids );
54
-
55
- // if 'ids' was used, skip this
56
- if( !$attachments ){
57
- $args = array(
58
- 'numberposts' => -1,
59
- 'orderby' => $orderby,
60
- 'order' => $order,
61
- 'post_type' => 'attachment',
62
- 'post_mime_type' => 'application,video,text,audio',
63
- 'post_parent' => get_the_ID() );
64
- if( $images ) $args['post_mime_type'] .= ',image';
65
-
66
- $attachments = get_posts($args);
67
- }
68
-
69
- if ( $attachments ) {
70
- $attachment_str = PHP_EOL.'<!-- Generated using Document Gallery. Get yours here: '.
71
- 'http://wordpress.org/extend/plugins/document-gallery -->'.PHP_EOL;
72
-
73
- // DOCUMENT LOOP
74
- foreach( $attachments as $attachment ) {
75
- // INIT ATTACHMENT-SPECIFIC VARS
76
- $url = $attachment->guid;
77
- $filename = basename( $url );
78
-
79
- if( $attachment_pg ) // link to attachment page
80
- $url = get_attachment_link( $attachment->ID );
81
-
82
- $title = get_the_title( $attachment->ID );
83
- $icon = dg_get_attachment_image( $attachment->ID, $title, $filename );
84
-
85
- // GENERATE OUTPUT
86
- if($descriptions) { // start description wrapper
87
- $attachment_str .= '<div class="document-icon-wrapper descriptions">'.PHP_EOL;
88
-
89
- } elseif( $count % 4 == 0 ) { // no description
90
- $attachment_str .= '<div id="document-icon-wrapper">'.PHP_EOL;
91
- }
92
-
93
- // insert filtered document-icon
94
- $attachment_str .= apply_filters( 'dg_doc_icon',
95
- sprintf( DG_DOC_ICON, $url, $icon, $title ), $attachment->ID );
96
-
97
- if($descriptions) { // add description
98
- $attachment_str .= " <p>$attachment->post_content</p>".
99
- PHP_EOL.'</div>'.PHP_EOL;
100
-
101
- } elseif( ++$count % 4 == 0 ) { // end wrapper
102
- $attachment_str .= '</div>'.PHP_EOL;
103
- }
104
- } // END DOCUMENT LOOP
105
-
106
- // for galleries w/ number of docs != mult of 4
107
- if( $count % 4 != 0 && !$descriptions ) // end wrapper
108
- $attachment_str .= '</div>'.PHP_EOL;
109
-
110
- return $attachment_str;
111
- } // END IF
112
-
113
- // NO DOCUMENTS
114
- return PHP_EOL.'<!-- Document Gallery: No attachments to display. How boring... -->'.PHP_EOL;
115
- }
116
- add_shortcode('dg', 'dg_get_attachment_icons');
117
-
118
- // 'document gallery' shortcode depreciated as of v1.0. left for backward compatibility
119
- add_shortcode('document gallery', 'dg_get_attachment_icons');
120
-
121
-
122
- // HELPERS //
123
- function dg_get_attachments_by_ids( $ids ){
124
- $attachments = array();
125
- foreach( $ids as $id ){
126
- $attachment = get_post( $id );
127
- if( $attachment->post_type == 'attachment' )
128
- $attachments[] = $attachment;
129
- // else: not an attachment so skip
130
- }
131
- return $attachments;
132
  }
133
 
134
- // pass in $title & $filename to avoid mult function calls
135
- function dg_get_attachment_image( $id, $title, $filename ) {
136
- $filetype = wp_check_filetype( $filename );
137
-
138
- // identify extension
139
- switch( $filetype['ext'] ) {
140
- // Most Common First
141
- case 'pdf':
142
- $icon = DG_URL.'icons/pdf.png';
143
- break;
144
- // MS Office
145
- case 'doc':
146
- case 'docx':
147
- case 'docm':
148
- case 'dotx':
149
- case 'dotm':
150
- $icon = DG_URL.'icons/msdoc.png';
151
- break;
152
- case 'ppt':
153
- case 'pot':
154
- case 'pps':
155
- case 'pptx':
156
- case 'pptm':
157
- case 'ppsx':
158
- case 'ppsm':
159
- case 'potx':
160
- case 'potm':
161
- case 'ppam':
162
- case 'sldx':
163
- case 'sldm':
164
- $icon = DG_URL.'icons/msppt.png';
165
- break;
166
- case 'xla':
167
- case 'xls':
168
- case 'xlt':
169
- case 'xlw':
170
- case 'xlsx':
171
- case 'xlsm':
172
- case 'xlsb':
173
- case 'xltx':
174
- case 'xltm':
175
- case 'xlam':
176
- $icon = DG_URL.'icons/msxls.png';
177
- break;
178
- case 'mdb':
179
- $icon = DG_URL.'icons/msaccess.png';
180
- break;
181
- // Video formats
182
- case 'avi':
183
- $icon = DG_URL.'icons/avi.png';
184
- break;
185
- case 'divx':
186
- $icon = DG_URL.'icons/divx.png';
187
- break;
188
- case 'flv':
189
- $icon = DG_URL.'icons/flv.png';
190
- break;
191
- case 'qt':
192
- case 'mov':
193
- $icon = DG_URL.'icons/mov.png';
194
- break;
195
- case 'asf':
196
- case 'asx':
197
- case 'wax':
198
- case 'wmv':
199
- case 'wmx':
200
- $icon = DG_URL.'icons/wmv.png';
201
- break;
202
- case 'mkv':
203
- $icon = DG_URL.'icons/mkv.png';
204
- break;
205
- // Audio formats
206
- case 'mp3':
207
- $icon = DG_URL.'icons/mp3.png';
208
- break;
209
- case 'wav':
210
- $icon = DG_URL.'icons/wav.png';
211
- break;
212
- case 'ogg':
213
- case 'oga':
214
- $icon = DG_URL.'icons/ogg.png';
215
- break;
216
- case 'midi':
217
- case 'mid':
218
- $icon = DG_URL.'icons/midi.png';
219
- break;
220
- case 'wma':
221
- $icon = DG_URL.'icons/wma.png';
222
- break;
223
- // Text formats
224
- case 'rtx':
225
- $icon = DG_URL.'icons/rtx.png';
226
- break;
227
- case 'ics':
228
- $icon = DG_URL.'icons/ics.png';
229
- break;
230
- case 'csv':
231
- $icon = DG_URL.'icons/csv.png';
232
- break;
233
- // Msc application formats
234
- case 'html':
235
- case 'htm': // death to all who use this!
236
- $icon = DG_URL.'icons/html.png';
237
- break;
238
- case 'css':
239
- $icon = DG_URL.'icons/css.png';
240
- break;
241
- case 'js':
242
- $icon = DG_URL.'icons/javascript.png';
243
- break;
244
- case 'class':
245
- $icon = DG_URL.'icons/java.png';
246
- break;
247
- case 'zip':
248
- $icon = DG_URL.'icons/zip.png';
249
- break;
250
- case 'tar':
251
- case 'gzip':
252
- case 'gz':
253
- case 'bz2': // not yet WP-supported
254
- case 'tgz': // not yet WP-supported
255
- $icon = DG_URL.'icons/compressed.png';
256
- break;
257
- case 'rar': // RAWR!!!
258
- $icon = DG_URL.'icons/rar.png';
259
- break;
260
- case '7z':
261
- $icon = DG_URL.'icons/7zip.png';
262
- break;
263
- case 'exec':
264
- $icon = DG_URL.'icons/exec.png';
265
- break;
266
- case 'rtf':
267
- $icon = DG_URL.'icons/rtf.png';
268
- break;
269
- case 'swf':
270
- $icon = DG_URL.'icons/shockwave.png';
271
- break;
272
- // OpenOffice formats
273
- case 'odt':
274
- $icon = DG_URL.'icons/opendocument-text.png';
275
- break;
276
- case 'odp':
277
- $icon = DG_URL.'icons/opendocument-presentation.png';
278
- break;
279
- case 'ods':
280
- $icon = DG_URL.'icons/opendocument-spreadsheet.png';
281
- break;
282
- case 'odg':
283
- $icon = DG_URL.'icons/opendocument-graphics.png';
284
- break;
285
- case 'odb':
286
- $icon = DG_URL.'icons/opendocument-database.png';
287
- break;
288
- case 'odf':
289
- $icon = DG_URL.'icons/opendocument-formula.png';
290
- break;
291
- default:
292
- // handle images
293
- if( strpos( $filetype['type'], 'image' ) === 0 &&
294
- ( $icon = wp_get_attachment_image_src( $id, 'thumbnail', false ) ) ){
295
- $icon = $icon[0];
296
- break;
297
- }
298
-
299
- // fallback to default icons if not recognized
300
- if( $icon = wp_get_attachment_image_src( $id, null, true ) ){
301
- $icon = $icon[0];
302
- break;
303
- }
304
-
305
- // everything failed. This is bad...
306
- return "<!-- Failed to retrive icon for attachment #$id -->";
307
- }
308
-
309
- return sprintf( DG_IMG_STRING, $icon, $title, $title );
310
- }
311
 
312
- // ADD SOME STYLING
 
 
313
  function dg_add_header_css() {
314
- wp_enqueue_style( 'document-gallery-css', plugins_url('style.css', __FILE__) );
315
  }
316
- add_action( 'wp_print_styles', 'dg_add_header_css');
317
-
318
- ?>
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ /*
4
+ Plugin Name: Document Gallery
5
+ Description: Display non-images (and images) in gallery format on a page or post with the [dg] shortcode.
6
+ Version: 1.4
7
+ Author: Dan Rossiter
8
+ Author URI: http://danrossiter.org/
9
+ License: GPL2
10
+ */
11
+
12
+ define('DG_URL', plugin_dir_url(__FILE__));
13
+ define('DG_PATH', dirname(__FILE__).'/');
14
+
15
+ /**
16
+ * Takes values passed from attributes and returns sutable HTML to represent
17
+ * all valid attachments requested.
18
+ *
19
+ * @param array $atts Arguments from the user.
20
+ * @return string HTML for the Document Gallery.
21
+ */
22
  function dg_get_attachment_icons($atts) {
23
+ include_once(DG_PATH . 'models/class-gallery.php');
24
+ return (string)(new DG_Gallery($atts));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  }
26
 
27
+ /**
28
+ * 'document gallery' shortcode depreciated as of v1.0. left for backward compatibility
29
+ */
30
+ add_shortcode('document gallery', 'dg_get_attachment_icons');
31
+ add_shortcode('dg', 'dg_get_attachment_icons');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ /**
34
+ * Include stylesheet for some basic design.
35
+ */
36
  function dg_add_header_css() {
37
+ wp_enqueue_style('document-gallery-css', DG_URL . 'style.css');
38
  }
39
+ add_action('wp_print_styles', 'dg_add_header_css');
 
 
icons/missing.png ADDED
Binary file
license.txt ADDED
@@ -0,0 +1,339 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
models/class-document.php ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Description of Document
5
+ *
6
+ * @author drossiter
7
+ */
8
+ class DG_Document {
9
+ // templates for HTML output
10
+ private $doc_icon, $icon_url;
11
+ private $img_string = '<img src="%s" title="%s" alt="%s" />';
12
+
13
+ // general document data
14
+ private $description, $gallery, $ID, $link, $title, $title_attribute;
15
+
16
+ // filetype => image mapping
17
+ private static $exts = array(
18
+ // Most Common First
19
+ 'pdf' => 'pdf.png',
20
+
21
+ // MS Office
22
+ 'doc' => 'msdoc.png',
23
+ 'docx' => 'msdoc.png',
24
+ 'docm' => 'msdoc.png',
25
+ 'dotx' => 'msdoc.png',
26
+ 'dotm' => 'msdoc.png',
27
+ 'ppt' => 'msppt.png',
28
+ 'pot' => 'msppt.png',
29
+ 'pps' => 'msppt.png',
30
+ 'pptx' => 'msppt.png',
31
+ 'pptm' => 'msppt.png',
32
+ 'ppsx' => 'msppt.png',
33
+ 'ppsm' => 'msppt.png',
34
+ 'potx' => 'msppt.png',
35
+ 'potm' => 'msppt.png',
36
+ 'ppam' => 'msppt.png',
37
+ 'sldx' => 'msppt.png',
38
+ 'sldm' => 'msppt.png',
39
+ 'xla' => 'msxls.png',
40
+ 'xls' => 'msxls.png',
41
+ 'xlt' => 'msxls.png',
42
+ 'xlw' => 'msxls.png',
43
+ 'xlsx' => 'msxls.png',
44
+ 'xlsm' => 'msxls.png',
45
+ 'xlsb' => 'msxls.png',
46
+ 'xltx' => 'msxls.png',
47
+ 'xltm' => 'msxls.png',
48
+ 'xlam' => 'msxls.png',
49
+ 'mdb' => 'msaccess.png',
50
+
51
+ // Video formats
52
+ 'avi' => 'avi.png',
53
+ 'divx' => 'divx.png',
54
+ 'flv' => 'flv.png',
55
+ 'qt' => 'mov.png',
56
+ 'mov' => 'mov.png',
57
+ 'asf' => 'wmv.png',
58
+ 'asx' => 'wmv.png',
59
+ 'wax' => 'wmv.png',
60
+ 'wmv' => 'wmv.png',
61
+ 'wmx' => 'wmv.png',
62
+ 'mkv' => 'mkv.png',
63
+
64
+ // Audio formats
65
+ 'mp3' => 'mp3.png',
66
+ 'wav' => 'wav.png',
67
+ 'ogg' => 'ogg.png',
68
+ 'oga' => 'ogg.png',
69
+ 'midi' => 'midi.png',
70
+ 'mid' => 'midi.png',
71
+ 'wma' => 'wma.png',
72
+
73
+ // Text formats
74
+ 'rtx' => 'rtx.png',
75
+ 'ics' => 'ics.png',
76
+ 'csv' => 'csv.png',
77
+
78
+ // Msc application formats
79
+ 'html' => 'html.png',
80
+ 'htm' => 'html.png', // death to all who use this!
81
+ 'css' => 'css.png',
82
+ 'js' => 'javascript.png',
83
+ 'class'=> 'java.png',
84
+ 'zip' => 'zip.png',
85
+ 'tar' => 'compressed.png',
86
+ 'gzip' => 'compressed.png',
87
+ 'gz' => 'compressed.png',
88
+ 'bz2' => 'compressed.png', // not yet WP-supported
89
+ 'tgz' => 'compressed.png', // not yet WP-supported
90
+ 'rar' => 'rar.png', // RAWR!!!
91
+ '7z' => '7zip.png',
92
+ 'exec' => 'exec.png',
93
+ 'rtf' => 'rtf.png',
94
+ 'swf' => 'shockwave.png',
95
+
96
+ // OpenDocument formats
97
+ 'odt' => 'opendocument-text.png',
98
+ 'odp' => 'opendocument-presentation.png',
99
+ 'ods' => 'opendocument-spreadsheet.png',
100
+ 'odg' => 'opendocument-graphics.png',
101
+ 'odb' => 'opendocument-database.png',
102
+ 'odf' => 'opendocument-formula.png'
103
+ );
104
+
105
+ /**
106
+ * Constructs instance of Document.
107
+ * @param type $attachment Attachment object used to initalize fields.
108
+ * @param type $gallery Instance of Gallery class.
109
+ */
110
+ public function __construct($attachment, $gallery) {
111
+ // init templates for HTML output
112
+ $this->doc_icon =
113
+ ' <div class="document-icon">' . PHP_EOL .
114
+ ' <a href="%s">%s<br>%s</a>' . PHP_EOL .
115
+ ' </div>' . PHP_EOL;
116
+ $this->icon_url = DG_URL . 'icons/';
117
+
118
+ // init general document data
119
+ $this->gallery = $gallery;
120
+ $this->description = $attachment->post_content;
121
+ $this->ID = $attachment->ID;
122
+ $this->link = $gallery->linkToAttachmentPg()
123
+ ? get_attachment_link($attachment->ID)
124
+ : wp_get_attachment_url($attachment->ID);
125
+ $this->title = get_the_title($attachment->ID);
126
+ $this->title_attribute = esc_attr(strip_tags($this->title));
127
+ }
128
+
129
+ /**
130
+ * Determines the filetype of the attachment and returns an HTML value to
131
+ * appropriately represent the attachment.
132
+ * @param attachment object representing the attachment
133
+ * @return string HTML for the specified attachment's display
134
+ */
135
+ private function getIcon() {
136
+ $url = wp_get_attachment_url($this->ID);
137
+ $filetype = wp_check_filetype(basename($url));
138
+
139
+ // identify extension
140
+ if(array_key_exists($filetype['ext'], self::$exts)) {
141
+ $icon = $this->icon_url . self::$exts[$filetype['ext']];
142
+ }
143
+ // handle images
144
+ elseif (strpos($filetype['type'], 'image') === 0 &&
145
+ ($icon = wp_get_attachment_image_src($this->ID, 'thumbnail', false))) {
146
+ $icon = $icon[0];
147
+ }
148
+ // fallback to default icons if not recognized
149
+ elseif (($icon = wp_get_attachment_image_src($this->ID, null, true))) {
150
+ $icon = $icon[0];
151
+ }
152
+ // everything failed. This is bad...
153
+ else {
154
+ $icon = $this->icon_url . 'missing.png';
155
+ }
156
+
157
+ return sprintf($this->img_string, $icon,
158
+ $this->title_attribute, $this->title_attribute);
159
+ }
160
+
161
+ /**
162
+ * Returns associative array of filetype to icon mapping.
163
+ * @return array
164
+ */
165
+ public static function getFiletypeMapping() {
166
+ return self::$exts;
167
+ }
168
+
169
+ /**
170
+ * Takes associative array of filetype to icon mapping.
171
+ *
172
+ * NOTE: This is foundation work for allowing users to add their own
173
+ * filetypes in the future.
174
+ * @param array $new
175
+ */
176
+ public static function setFiletypeMapping($new) {
177
+ self::$exts = $new;
178
+ }
179
+
180
+ /**
181
+ * Returns HTML representing this Document.
182
+ * @return string
183
+ */
184
+ public function __toString() {
185
+ $core = sprintf($this->doc_icon, $this->link, $this->getIcon(), $this->title);
186
+
187
+ if($this->gallery->useDescriptions()) {
188
+ $core .= " <p>$this->description</p>" . PHP_EOL;
189
+ }
190
+
191
+ // users may filter icon here
192
+ return apply_filters('dg_doc_icon', $core, $this->ID);
193
+ }
194
+ }
195
+
196
+ ?>
models/class-gallery.php ADDED
@@ -0,0 +1,400 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Description of Gallery
5
+ *
6
+ * @author drossiter
7
+ */
8
+ class DG_Gallery {
9
+ private $atts, $taxa, $comment;
10
+ private $docs = array();
11
+ private $errs = array();
12
+
13
+ private static $defaults = array(
14
+ // default: link directly to file (true to link to attachment pg)
15
+ 'attachment_pg' => FALSE,
16
+ 'descriptions' => FALSE,
17
+ // include thumbnail of actual document in gallery display
18
+ //'fancy_thumbs' => FALSE,
19
+ // comma-separated list of attachment ids
20
+ 'ids' => FALSE,
21
+ // if true, all images attached to current page will be included also
22
+ 'images' => FALSE,
23
+ 'localpost' => TRUE,
24
+ 'order' => 'ASC',
25
+ 'orderby' => 'menu_order',
26
+ // only relevant if tax_query used (WP >= 3.1)
27
+ 'relation' => 'AND'
28
+ );
29
+
30
+ // templates for HTML output
31
+ private $no_docs = '<!-- No attachments to display. How boring! :( -->';
32
+ private $icon_wrapper;
33
+
34
+ /**
35
+ * Builds a gallery object with attributes passed.
36
+ * @param type $atts Array of attributes used in shortcode.
37
+ */
38
+ public function __construct($atts) {
39
+ // init templates for HTML output
40
+ $this->comment =
41
+ PHP_EOL . '<!-- Generated using Document Gallery. Get yours here: ' .
42
+ 'http://wordpress.org/extend/plugins/document-gallery -->' . PHP_EOL;
43
+ $this->icon_wrapper = '<div class="%s">'. PHP_EOL . '%s</div>' . PHP_EOL;
44
+
45
+ // values used to construct tax query (may be empty)
46
+ $this->taxa = array_diff_key($atts, self::$defaults);
47
+
48
+ // all recognized attributes go here
49
+ $this->atts = shortcode_atts(self::$defaults, $atts);
50
+
51
+ // goes through all values in $this->atts, setting $this->errs as needed
52
+ $this->sanitizeDefaults();
53
+
54
+ // query DB for all documents requested
55
+ try {
56
+ $docs = $this->getDocuments();
57
+ include_once(DG_PATH . 'models/class-document.php');
58
+ foreach($docs as $doc) {
59
+ $this->docs[] = new DG_Document($doc, $this);
60
+ }
61
+ } catch(InvalidArgumentException $e) {
62
+ // errors will be printed in __toString()
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Gets all valid Documents based on the attributes passed by the user.
68
+ * @return array Contains all documents matching the query.
69
+ * @throws InvalidArgumentException Thrown when $this->errs is not empty.
70
+ */
71
+ private function getDocuments() {
72
+ $mime_types = array('application', 'video', 'text', 'audio');
73
+ if ($this->atts['images']) {
74
+ $mime_types[] = 'image';
75
+ }
76
+
77
+ $query = array(
78
+ 'numberposts' => -1,
79
+ 'orderby' => $this->atts['orderby'],
80
+ 'order' => $this->atts['order'],
81
+ 'post_status' => 'any',
82
+ 'post_type' => 'attachment',
83
+ 'post_mime_type' => implode(',', $mime_types));
84
+
85
+ $query['post_parent'] =
86
+ $this->atts['localpost']
87
+ && ($post = get_post()) ? $post->ID : '';
88
+
89
+ $this->setTaxa($query);
90
+
91
+ if(!empty($this->errs)) {
92
+ throw new InvalidArgumentException();
93
+ }
94
+
95
+ return ($this->atts['ids'] !== FALSE)
96
+ ? $this->getAttachmentsByIds()
97
+ : get_posts($query);
98
+ }
99
+
100
+ /**
101
+ * Cleans up user input, making sure we don't pass crap on to WP core.
102
+ * @global string $wp_version
103
+ */
104
+ private function sanitizeDefaults() {
105
+ global $wp_version;
106
+
107
+ if($this->atts['attachment_pg'] !== self::$defaults['attachment_pg']) {
108
+ $attachment_pg =
109
+ filter_var($this->atts['attachment_pg'],
110
+ FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
111
+
112
+ if($attachment_pg === null) {
113
+ $this->errs[] =
114
+ 'The attachment_pg parameter may only be \'true\' or \'false.\' ' .
115
+ "You entered {$this->atts['attachment_pg']}.";
116
+ } else {
117
+ $this->atts['attachment_pg'] = $attachment_pg;
118
+ }
119
+ }
120
+
121
+ if($this->atts['descriptions'] !== self::$defaults['descriptions']) {
122
+ $descriptions =
123
+ filter_var($this->atts['descriptions'],
124
+ FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
125
+
126
+ if($descriptions === null) {
127
+ $this->errs[] =
128
+ 'The descriptions parameter may only be \'true\' or \'false.\' ' .
129
+ "You entered {$this->atts['descriptions']}.";
130
+ } else {
131
+ $this->atts['descriptions'] = $descriptions;
132
+ }
133
+ }
134
+
135
+ if($this->atts['ids'] !== self::$defaults['ids']) {
136
+ if(strcasecmp('false', $this->atts['ids']) == 0) {
137
+ $this->atts['ids'] = FALSE;
138
+ } else {
139
+ $ids = explode(',', $this->atts['ids']);
140
+ $bad = array_filter($ids, array(__CLASS__, 'negativeInt'));
141
+
142
+ if(!empty($bad)) {
143
+ $this->errs[] =
144
+ 'The following ID(s) are not valid: ' .
145
+ implode(', ', $bad) . '.';
146
+ } else {
147
+ $this->atts['ids'] = $ids;
148
+ }
149
+ }
150
+ }
151
+
152
+ if($this->atts['images'] !== self::$defaults['images']) {
153
+ $images =
154
+ filter_var($this->atts['images'],
155
+ FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
156
+
157
+ if($images === null) {
158
+ $this->errs[] =
159
+ 'The images parameter may only be \'true\' or \'false.\' ' .
160
+ "You entered {$this->atts['images']}.";
161
+ } else {
162
+ $this->atts['images'] = $images;
163
+ }
164
+ }
165
+
166
+ if($this->atts['localpost'] !== self::$defaults['localpost']) {
167
+ $localpost =
168
+ filter_var($this->atts['localpost'],
169
+ FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
170
+ if($localpost === null) {
171
+ $this->errs[] =
172
+ 'The localpost parameter may only be \'true\' or \'false.\' ' .
173
+ "You entered {$this->atts['localpost']}.";
174
+ } else {
175
+ $this->atts['localpost'] = $localpost;
176
+ }
177
+ }
178
+
179
+ $order = strtoupper($this->atts['order']);
180
+ if('ASC' !== $order && 'DEC' !== $order) {
181
+ $this->errs[] =
182
+ 'The order parameter must be either \'ASC\' or \'DEC.\' '.
183
+ "You entered {$this->atts['order']}.";
184
+ }
185
+
186
+ $orderby = strtoupper($this->atts['orderby']) === 'ID'
187
+ ? 'ID' : strtolower($this->atts['orderby']);
188
+ if ($orderby !== 'ID' && $orderby !== 'menu_order'
189
+ && $orderby !== 'author' && $orderby !== 'title'
190
+ && $orderby !== 'name' && $orderby !== 'date'
191
+ && $orderby !== 'modified' && $orderby !== 'parent'
192
+ && $orderby !== 'rand' /* && $orderby !== 'meta_value' */
193
+ // check version-specific parameters
194
+ && version_compare($wp_version, '2.8', '>=') && $orderby !== 'none' /* && $orderby !== 'meta_value_num' */
195
+ && version_compare($wp_version, '2.9', '>=') && $orderby !== 'comment_count'
196
+ && version_compare($wp_version, '3.5', '>=') && $orderby !== 'post__in') {
197
+ $this->errs[] =
198
+ "The orderby parameter value entered, {$this->atts['orderby']}, " .
199
+ "is not valid in WP $wp_version.";
200
+ } else {
201
+ $this->atts['orderby'] = $orderby;
202
+ }
203
+
204
+ $relation = strtoupper($this->atts['relation']);
205
+ if ('AND' !== $relation && 'OR' !== $relation) {
206
+ $this->errs[] =
207
+ 'The relation parameter must be either \'AND\' or \'OR.\' ' .
208
+ "You entered {$this->atts['relation']}.";
209
+ } else {
210
+ $this->atts['relation'] = $relation;
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Returns whether to link to attachment pg.
216
+ * @return bool
217
+ */
218
+ public function linkToAttachmentPg() {
219
+ return $this->atts['attachment_pg'];
220
+ }
221
+
222
+ /**
223
+ * Returns whether descriptions should be included in output.
224
+ * @return bool
225
+ */
226
+ public function useDescriptions() {
227
+ return $this->atts['descriptions'];
228
+ }
229
+
230
+ /**
231
+ * Function loops through all attributes passed that did not match
232
+ * self::$defaults. If they are the name of a taxonomy, they are plugged
233
+ * into the query, otherwise $this->errs is appended with an error string.
234
+ * @global string $wp_version Determines which tax query to use.
235
+ * @param array $query Query to insert tax query into.
236
+ */
237
+ private function setTaxa(&$query) {
238
+ if(!empty($this->taxa)) {
239
+ global $wp_version;
240
+ $taxa = array();
241
+
242
+ // use preferred tax_query if supported
243
+ if (version_compare($wp_version, '3.1', '>=')) {
244
+ // only include relation if we have multiple taxa
245
+ if(count($this->taxa) > 1) {
246
+ $taxa['relation'] = $this->atts['relation'];
247
+ }
248
+
249
+ foreach ($this->taxa as $taxon => $terms) {
250
+ $terms = $this->getTermIdsByNames($taxon, explode(',', $terms));
251
+
252
+ $taxa[] = array(
253
+ 'taxonomy' => $taxon,
254
+ 'field' => 'id',
255
+ 'terms' => $terms
256
+ );
257
+ }
258
+
259
+ // create nested structure
260
+ $query['tax_query'] = $taxa;
261
+ } // fallback to deprecated {tax_name} => {term_slug} construct
262
+ elseif (version_compare($wp_version, '2.3', '>=')) {
263
+ foreach ($this->taxa as $taxon => $terms) {
264
+ $taxa[$taxon] = ($taxon == 'category')
265
+ ? implode(',', $this->getTermIdsByNames($taxon, explode(',', $terms)))
266
+ : implode(',', $this->getTermSlugsByNames($taxon, explode(',', $terms)));
267
+ }
268
+
269
+ $query = array_merge($taxa, $query);
270
+ } // WP < 2.3 not supported for category/custom taxa
271
+ else {
272
+ $this->errs[] = 'The following attributes are invalid: ' .
273
+ implode(', ', array_keys($this->taxa));
274
+ }
275
+ }
276
+ }
277
+
278
+
279
+ /**
280
+ * Returns an array of term ids when provided with a list of term names.
281
+ * Also appends an entry onto $errs if any invalid names are found.
282
+ * @param string $taxon
283
+ * @param array $term_names
284
+ * @param &array $errs
285
+ * @return array
286
+ */
287
+ private function getTermIdsByNames($taxon, $term_names) {
288
+ return $this->getTermXByNames('term_id', $taxon, $term_names);
289
+ }
290
+
291
+ /**
292
+ * Returns an array of term slugs when provided with a list of term names.
293
+ * Also appends an entry onto $errs if any invalid names are found.
294
+ * @param string $taxon
295
+ * @param array $term_names
296
+ * @param &array $errs
297
+ * @return array
298
+ */
299
+ private function getTermSlugsByNames($taxon, $term_names) {
300
+ return $this->getTermXByNames('slug', $taxon, $term_names);
301
+ }
302
+
303
+ /**
304
+ * (WP >= 2.3) Returns a list of x, where x may be any of the fields within a
305
+ * term object, when provided with a list of term names (not slugs).
306
+ * (http://codex.wordpress.org/Function_Reference/get_term_by#Return_Values)
307
+ *
308
+ * Also appends an entry onto $errs if any invalid names are found.
309
+ * @param string $x
310
+ * @param string $taxon
311
+ * @param array $term_names
312
+ * @param &array $errs
313
+ * @return array
314
+ */
315
+ private function getTermXByNames($x, $taxon, $term_names) {
316
+ $ret = array();
317
+
318
+ foreach ($term_names as $name) {
319
+ if (($term = get_term_by('name', $name, $taxon))) {
320
+ $ret[] = $term->{$x};
321
+ }
322
+ else {
323
+ $this->errs[] = "$name is not a valid term name in $taxon.";
324
+ }
325
+ }
326
+
327
+ return $ret;
328
+ }
329
+
330
+ /**
331
+ * Given a list of IDs, all attachments represented by these IDs are returned.
332
+ * @return array post objects
333
+ */
334
+ private function getAttachmentsByIds() {
335
+ $attachments = array();
336
+ foreach ($this->atts['ids'] as $id) {
337
+ $attachment = get_post($id);
338
+ if ($attachment->post_type === 'attachment')
339
+ $attachments[] = $attachment;
340
+ // else: not an attachment so skip
341
+ }
342
+
343
+ return $attachments;
344
+ }
345
+
346
+ /**
347
+ * Function returns false for positive ints, true otherwise.
348
+ * @param var $var could be anything.
349
+ * @return boolean indicating whether $var is not a positive int.
350
+ */
351
+ private static function negativeInt($var) {
352
+ return !is_numeric($var) // isn't numeric
353
+ || (int)$var != $var // isn't int
354
+ || (int)$var < 0; // isn't positive
355
+ }
356
+
357
+
358
+ /**
359
+ * Returns HTML representing this Gallery.
360
+ * @return string
361
+ */
362
+ public function __toString() {
363
+ if(!empty($this->errs)) {
364
+ return '<p>' . implode('</p><p>', $this->errs) . '</p>';
365
+ }
366
+
367
+ if(empty($this->docs)) {
368
+ return $this->no_docs;
369
+ }
370
+
371
+ $core = '';
372
+ $classes = array('document-icon-wrapper');
373
+ if($this->useDescriptions()) {
374
+ $classes[] = 'descriptions';
375
+ }
376
+
377
+ $icon_wrapper = sprintf($this->icon_wrapper, implode(' ', $classes), '%s');
378
+
379
+ if($this->useDescriptions()) {
380
+ foreach($this->docs as $doc) {
381
+ $core .= sprintf($icon_wrapper, (string)$doc);
382
+ }
383
+ } else {
384
+ for($i = 0; $i < count($this->docs); $i+=4) {
385
+ $row = '';
386
+
387
+ $min = min($i+4, count($this->docs));
388
+ for($x = $i; $x < $min; $x++) {
389
+ $row .= (string)$this->docs[$x];
390
+ }
391
+
392
+ $core .= sprintf($icon_wrapper, $row);
393
+ }
394
+ }
395
+
396
+ return $this->comment . $core;
397
+ }
398
+ }
399
+
400
+ ?>
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Document Gallery ===
2
  Contributors: dan.rossiter
3
- Tags: attachments, icons, documents, gallery, ms office, doc, ppt, xls, docx, pptx, xlsx, pdf,openoffice
4
- Requires at least: 2.6
5
- Tested up to: 3.5.1
6
- Stable tag: 1.3.1
7
- License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
  This plugin allows the user to easily create a "gallery" of all non-image
@@ -12,19 +12,21 @@ attachments on a given post/page, making them easy to share.
12
 
13
  == Description ==
14
 
15
- This plugin allows the user to effortlessly include a gallery, much like a
16
- photo gallery, of all your non-image attachments anywhere within your post.
 
17
 
18
  The plugin will, by default, inherit the styling within your active theme, but
19
- with a little CSS knowledge it is easily modified to meet your specific needs.
 
20
 
21
  Read more in the **Installation** tab!
22
 
23
  = Developers =
24
 
25
- Document Gallery includes features intended to make integrating the plugin into
26
- the core of your theme or plugin very convenient. See the bottom of the
27
- **Installation** tab for specific documentation on the various features included.
28
 
29
  *If this plugin has helped you, please take a moment to [rate
30
  it](http://wordpress.org/support/view/plugin-reviews/document-gallery#postform)!*
@@ -33,23 +35,48 @@ it](http://wordpress.org/support/view/plugin-reviews/document-gallery#postform)!
33
 
34
  1. Upload `document-gallery` to the `/wp-content/plugins/` directory
35
  1. Activate the plugin through the 'Plugins' menu in WordPress
36
- 1. Place `[dg]` in any posts or pages you want a document gallery included. See
37
  below for additional display options.
38
 
39
  = Document Gallery Options =
40
 
41
- In order to include all compatible docuements from a given page or post, you
42
- must include the following shortcode in the post:
43
 
44
- `[dg descriptions=[true/false] orderby=[menu_order, title, date, author, rand]
45
- order=[ASC/DEC] attachment_pg=[true/false] images=[true/false]
46
- ids=[false/comma-separated list of id #s]]`
 
 
 
 
 
 
 
 
47
 
48
  **Default Values**
49
 
50
- By default, document gallery will use `descriptions=false`
51
- , `orderby=menu_order`, `order=ASC` , `attachment_pg=false`, `images=false`
52
- , and `ids=false` if you do not specify otherwise.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  **Descriptions Option**
55
 
@@ -59,45 +86,69 @@ alongside it.
59
  *Note: this will use the `description` field, **not** the `caption`. Be
60
  careful when entering your document data.*
61
 
62
- **Orderby Option**
63
-
64
- * `menu_order` - This is probably the one you want to use. Order by the
65
- integer fields in the Insert / Upload Media Gallery dialog. (Note that
66
- these fields may be blank by default. If this is the case, you must
67
- populate the fields before this option will work.
68
- * `title` - Alphabetical order based on title.
69
- * `date` - Order by date of document upload.
70
- * `author` - Order by the owner of the upload (username).
71
- * `rand` - Pseudo-random order.
72
-
73
  **Order Option**
74
 
75
- This option works alongsied the `orderby` option to determine whether the
76
- documents are displayed in ascending or decending order.
77
-
78
- **Attachment Page Option** *(New in Version 1.1)*
79
-
80
- This option determines whether each document icon will link to the actual file
81
- or to its attachment page. If you want the user to be able to click on the
82
- icon and directly rective the option to download then use
83
- `attachment_pg=false` (the default). If you have information on the attachment
84
- page that you want the link to go to, use `attachment_pg=true`.
85
 
86
- **Images** *(New in Version 1.2)*
87
 
88
- This option will tell the plugin to pull all images attached to to a page or
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  post in addition to all documents.
90
 
91
- **Ids** *(New in Version 1.2)*
92
 
93
  This is an advanced option intended for experienced WordPress users. If this
94
  option is used, the plugin will ignore attached documents, instead including
95
- all attachments defined by the ids attribute (e.g.: `ids=10,2,4,42`).
96
 
97
- *Note: If this attribute is used, the `order`, `orderby`, and `images`
98
- attributes will be ignored. Order is defined by the order the ids are
 
99
  provided.*
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  = Customize Appearance =
102
 
103
  By default, the document gallery will use the styles within your active theme
@@ -108,7 +159,7 @@ for an idea of what will select different elements within the gallery display.
108
 
109
  **Example**
110
 
111
- Say I would like to include a border for the right and bottom of thedocument
112
  icon, but only when descriptions are shown (to deliniate the icon from the
113
  description text). To do this, I would need to add the following CSS to my
114
  theme stylesheet:
@@ -129,7 +180,8 @@ be lost when a new version is released.*
129
 
130
  = Developers =
131
 
132
- **Filter document-icon Content**
 
133
  For those unfamiliar with content filters, [here is some
134
  documentation](http://codex.wordpress.org/Plugin_API/Filter_Reference) that you
135
  should read before continuing.
@@ -143,12 +195,12 @@ modify any of this content before it reaches your users.
143
  Any function using this filter will receive two parameters, the content to be
144
  filtered and the ID number of the file represented by the icon in question.
145
  If you are implementing something to override the plugin default functionality,
146
- it may be useful to be able to query various attributes of the attachment with
147
  this value.
148
 
149
  One example use for this filter, which I have personally used in a project I
150
- am working on, will add a query parameter to the end of each attachment url.
151
- This parameter, `rid`, specifies the refering page and allows the page
152
  receiving the URL to dynamically detect which page ID the link came from.
153
 
154
  `function dg_doc_icon( $icon, $id ){
@@ -159,14 +211,14 @@ receiving the URL to dynamically detect which page ID the link came from.
159
 
160
  if( strpos( $matches[2], '?' ) !== false )
161
  return "{$matches[1]}{$matches[2]}&rid=".get_the_ID().$matches[3];
162
-
163
  return "{$matches[1]}{$matches[2]}?rid=".get_the_ID().$matches[3];
164
  }
165
  add_filter( 'dg_doc_icon', 'dg_doc_icon', null, 2 );`
166
 
167
  Obviously this is just one very specific example, but anything that requires
168
  modifying the image tag, the anchor tag, or the title can be handled with this
169
- filter. Note that this function does not use the $id value it receives, which
170
  is perfectly alright.
171
 
172
  == Screenshots ==
@@ -174,11 +226,11 @@ is perfectly alright.
174
  1. This is an example of multiple Document Galleries on a single page (using
175
  the `ids` attribute). It also shows how images will appear in a Document
176
  Gallery. Note that the description field supports HTML markup, so the
177
- possibilites are endless!
178
- 2. This is how the Document Gallery looks with `descriptions=true`. The
179
- descriptions are auto-populated using the description field from when you
180
  upload the document.
181
- 3. This is how the Document Gallery looks with `descriptions=false` (default).
182
  Note that the display inherits styling from your active theme.
183
 
184
  == Changelog ==
@@ -187,14 +239,22 @@ Note that the display inherits styling from your active theme.
187
 
188
  * Full integration with the new [Wordpress 3.5 Media
189
  Manager](http://codex.wordpress.org/Version_3.5#Highlights).
190
- * Option to include player for any music or video attachments uploaded to page.
191
- * Option to open documents directly within your browser (&#224; la [Google Drive
192
  Viewer](https://drive.google.com/viewer)).
193
  * Support for adding your own filetypes/icons.
194
  * Whatever else **you** would like (post on the [support
195
  forum](http://wordpress.org/support/plugin/document-gallery) if you have
196
  ideas)!
197
 
 
 
 
 
 
 
 
 
198
  = 1.3.1 =
199
 
200
  * **Bug Fix:** This resolves a bug introduced in version `1.3`. (Thanks to JKChad
@@ -204,14 +264,14 @@ Note that the display inherits styling from your active theme.
204
 
205
  * **New Feature:** It is now possible to filter the HTML produced to represent
206
  each individual icon, making it possible to add extra attributes and other
207
- modifications on the fly as document icons are generated. This will probably
208
- only be of use to developers and people who don't mind getting their hands
209
  dirty. *(See bottom **Installation** tab for more details.)*
210
  * **Enhancement:** There have been a lot of optimizations to the underlying
211
  plugin code to make it run more efficiently and be easier to read, if you
212
  are so inclined.
213
- * **Enhancement:** Changed how images, when included within the gallery, are
214
- generated so that the format of the icon returned now matches the rest of
215
  the icons.
216
 
217
  = 1.2.1 =
@@ -225,7 +285,7 @@ Note that the display inherits styling from your active theme.
225
  document gallery (using `images=true` attribute).
226
  (Thanks for the suggestion, Luca!)
227
  * **New Feature:** Attachment ids can now be explicitly listed, allowing for
228
- documents not attached to a post or page to be included in a document
229
  gallery (e.g.: `ids=2,42,57,1`). Note that no spaces should be included.
230
  * **Enhancement:** The CSS stylesheet has been enhanced for more flexibility
231
  in sizing icons.
@@ -235,7 +295,7 @@ Note that the display inherits styling from your active theme.
235
  * **New Feature:** Included option to link to the attachment page as well as
236
  to the actual document.
237
  * **Enhancement:** Added documentation for customizing the appearance of the plugin.
238
- * **Enhancement:** Many improvements to the backend, including pretty HTML output
239
  and best practice implementation in calls to WordPress core functions.
240
 
241
  = 1.0.4 =
@@ -265,9 +325,9 @@ Note that the display inherits styling from your active theme.
265
 
266
  * **New Feature:** Plugin now has **36 icons** representing **72 filetypes**!
267
  * **Enhancement:** Optimized gallery generation (faster!)
268
- * **Enhancement:** Added fallback to WordPress default icons if you happen to
269
  include one of the few filetypes not yet supported.
270
- * **Enhancement:** Changed shortcode to `[dg]` (`[document gallery]` will still
271
  work for backward compatibility).
272
  * **Enhancement:** Gave documentation some **much needed** revisions.
273
 
@@ -279,6 +339,6 @@ Note that the display inherits styling from your active theme.
279
  = 0.8 =
280
 
281
  * **Release:** First public release of Document Gallery.
282
- * **Feature:** Displays PDF, Word, PowerPoint, Excel, and ZIP documents from a
283
- given page or post. **Feature:** Documents can be ordered by a number of
284
- different factors.
1
  === Document Gallery ===
2
  Contributors: dan.rossiter
3
+ Tags: attachments, icons, documents, gallery, MS office, pdf
4
+ Requires at least: 2.8
5
+ Tested up to: 3.6
6
+ Stable tag: 1.4
7
+ License: GPL2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
  This plugin allows the user to easily create a "gallery" of all non-image
12
 
13
  == Description ==
14
 
15
+ This plugin allows the user to effortlessly create a gallery of documents and
16
+ other attached media, much like the gallery option already available for image
17
+ attachments.
18
 
19
  The plugin will, by default, inherit the styling within your active theme, but
20
+ with a little CSS knowledge it is possible to customize the appearance to meet
21
+ your specific needs.
22
 
23
  Read more in the **Installation** tab!
24
 
25
  = Developers =
26
 
27
+ Document Gallery includes features intended to make integration with other plugins
28
+ simple. See the bottom of the **Installation** tab for specific documentation on
29
+ the various features provided.
30
 
31
  *If this plugin has helped you, please take a moment to [rate
32
  it](http://wordpress.org/support/view/plugin-reviews/document-gallery#postform)!*
35
 
36
  1. Upload `document-gallery` to the `/wp-content/plugins/` directory
37
  1. Activate the plugin through the 'Plugins' menu in WordPress
38
+ 1. Place `[dg]` in any posts or pages you want a document gallery included. See
39
  below for additional display options.
40
 
41
  = Document Gallery Options =
42
 
43
+ In order to include all compatible documents from a given page or post, you
44
+ must include the following shortcode in the post: `[dg]`.
45
 
46
+ In addition to the default behavior, the plugin provides many options to
47
+ customize behavior with various attributes, seen below:
48
+
49
+ `[dg [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/DEC>] [orderby=<**see below**>]]`
53
+
54
+ Though the shortcode above may seem far from "short," none of the attributes are
55
+ required and most users will find that the plugin meets your needs "out of the box"
56
+ without any added attributes.
57
 
58
  **Default Values**
59
 
60
+ By default, document gallery will use `no descriptions`, `orderby menu_order`
61
+ , `ASC order`, `no attachment_pg links`, and `no images` from the `local post`
62
+ if you do not specify otherwise.
63
+
64
+ **Attachment Page Option** *(New in Version 1.1)*
65
+
66
+ This option determines whether each document icon will link to the actual file
67
+ or to its attachment page. If you want the user to be able to click on the
68
+ icon and directly rective the option to download then use `attachment_pg=false`
69
+ (the default). If you have information on the attachment page that you want the
70
+ link to go to, use `attachment_pg=true`.
71
+
72
+ **Categories/Custom Taxonomy Option** *(New in Version 1.4)*
73
+
74
+ With the `categories` option you are able to select attachments based on
75
+ their assigned category or any other
76
+ [custom taxon](http://codex.wordpress.org/Taxonomies). Categories
77
+ or any custom taxon can be referenced simply by including `category=category_value`
78
+ or `taxon_name=taxon_value`. Multiple values for a single taxon may be separated
79
+ by commas.
80
 
81
  **Descriptions Option**
82
 
86
  *Note: this will use the `description` field, **not** the `caption`. Be
87
  careful when entering your document data.*
88
 
 
 
 
 
 
 
 
 
 
 
 
89
  **Order Option**
90
 
91
+ This option works alongside the `orderby` option to determine whether the
92
+ documents are displayed in ascending or descending order.
 
 
 
 
 
 
 
 
93
 
94
+ **Orderby Option**
95
 
96
+ * `menu_order` - This is probably the one you want to use. Menu order is
97
+ the order that icons appear when seen in the Insert / Upload Media Gallery
98
+ dialog. To change this order, you simply drag the icons around until they
99
+ are where you want them. In earlier versions of WordPress, menu_order was
100
+ modified by the integer fields in the Insert / Upload Media Gallery dialog.
101
+ These fields no longer exist in recent releases.
102
+ * `title` - Order by title.
103
+ * `date` - Order by upload date.
104
+ * `modified` - Order by last modified date.
105
+ * `rand` - Random order.
106
+ * `ID` - Order by post id.
107
+ * `author` - Order by author.
108
+ * `name` - Order by attachment slug.
109
+ * `parent` - Order by post/page parent id.
110
+ (Only useful in conjunction with `localpost=false` option.)
111
+ * `comment_count` - Order by number of comments (available with WP >= 2.9).
112
+ * `none` - No order (available with Version 2.8).
113
+ * `post__in` - Preserve post ID order given in the post__in array (available
114
+ with WP >= 3.5).
115
+
116
+ **Images Option** *(New in Version 1.2)*
117
+
118
+ This option will tell the plugin to include all images attached to to a page or
119
  post in addition to all documents.
120
 
121
+ **IDs Option** *(New in Version 1.2)*
122
 
123
  This is an advanced option intended for experienced WordPress users. If this
124
  option is used, the plugin will ignore attached documents, instead including
125
+ all attachments defined by the `ids` attribute (e.g.: `ids=10,2,4,42`).
126
 
127
+ *Note: If this attribute is used, the `order`, `orderby`, `images` and other
128
+ attributes which generally determine which attachments to include or how to
129
+ order them will be ignored. Order is defined by the order the ids are
130
  provided.*
131
 
132
+ **Localpost Option** *(New in Version 1.4)*
133
+
134
+ By default a document gallery only looks at attachments of the page/post where
135
+ the `[dg]` shortcode is used. If you would like to search beyond that local scope,
136
+ you must set `localpost=false`.
137
+
138
+ This option would probably be useful especially when querying with the *category
139
+ or taxonomy* option, though it can be used with any options you chose.
140
+
141
+ **Relation Option** *(New in Version 1.4)*
142
+
143
+ The relation option should only be used when also using the *category or custom
144
+ taxonomy* option (see above). Additionally, this option is only effective in
145
+ WordPress installs version 3.1 or higher. Older versions cannot use this value
146
+ and will ignore it.
147
+
148
+ When using multiple taxa, this option allows you to decide whether the attachments
149
+ returned must meet all of the taxa_names specified (AND) or a minimum of one
150
+ match (OR).
151
+
152
  = Customize Appearance =
153
 
154
  By default, the document gallery will use the styles within your active theme
159
 
160
  **Example**
161
 
162
+ Say I would like to include a border for the right and bottom of the document
163
  icon, but only when descriptions are shown (to deliniate the icon from the
164
  description text). To do this, I would need to add the following CSS to my
165
  theme stylesheet:
180
 
181
  = Developers =
182
 
183
+ **Filter .document-icon Content**
184
+
185
  For those unfamiliar with content filters, [here is some
186
  documentation](http://codex.wordpress.org/Plugin_API/Filter_Reference) that you
187
  should read before continuing.
195
  Any function using this filter will receive two parameters, the content to be
196
  filtered and the ID number of the file represented by the icon in question.
197
  If you are implementing something to override the plugin default functionality,
198
+ it may be useful to be able to query various attributes of the attachment with
199
  this value.
200
 
201
  One example use for this filter, which I have personally used in a project I
202
+ am working on, will add a query parameter to the end of each attachment URL.
203
+ This parameter, `rid`, specifies the referring page and allows the page
204
  receiving the URL to dynamically detect which page ID the link came from.
205
 
206
  `function dg_doc_icon( $icon, $id ){
211
 
212
  if( strpos( $matches[2], '?' ) !== false )
213
  return "{$matches[1]}{$matches[2]}&rid=".get_the_ID().$matches[3];
214
+
215
  return "{$matches[1]}{$matches[2]}?rid=".get_the_ID().$matches[3];
216
  }
217
  add_filter( 'dg_doc_icon', 'dg_doc_icon', null, 2 );`
218
 
219
  Obviously this is just one very specific example, but anything that requires
220
  modifying the image tag, the anchor tag, or the title can be handled with this
221
+ filter. Note that this function does not use the $id value it receives, which
222
  is perfectly alright.
223
 
224
  == Screenshots ==
226
  1. This is an example of multiple Document Galleries on a single page (using
227
  the `ids` attribute). It also shows how images will appear in a Document
228
  Gallery. Note that the description field supports HTML markup, so the
229
+ possibilities are endless!
230
+ 2. This is how the Document Gallery looks with `descriptions=true`. The
231
+ descriptions are auto-populated using the description field from when you
232
  upload the document.
233
+ 3. This is how the Document Gallery looks with `descriptions=false` (default).
234
  Note that the display inherits styling from your active theme.
235
 
236
  == Changelog ==
239
 
240
  * Full integration with the new [Wordpress 3.5 Media
241
  Manager](http://codex.wordpress.org/Version_3.5#Highlights).
242
+ * Option to open music or video files directly from your gallery.
243
+ * Option to open documents directly from your gallery (&#224; la [Google Drive
244
  Viewer](https://drive.google.com/viewer)).
245
  * Support for adding your own filetypes/icons.
246
  * Whatever else **you** would like (post on the [support
247
  forum](http://wordpress.org/support/plugin/document-gallery) if you have
248
  ideas)!
249
 
250
+ = 1.4 =
251
+
252
+ * **New Feature:** This release features the addition of *category/taxonomy* support,
253
+ [as suggested by Pyo](http://wordpress.org/support/topic/sorting-documents-by-categorytag-or-other-taxonomy).
254
+ * **Under The Hood:** The plugin was completely rewritten for this release. Logic
255
+ was cleaned up to make maintenance easier and facilitate some *big* changes
256
+ planned for version 2.0 of Document Gallery.
257
+
258
  = 1.3.1 =
259
 
260
  * **Bug Fix:** This resolves a bug introduced in version `1.3`. (Thanks to JKChad
264
 
265
  * **New Feature:** It is now possible to filter the HTML produced to represent
266
  each individual icon, making it possible to add extra attributes and other
267
+ modifications on the fly as document icons are generated. This will probably
268
+ only be of use to developers and people who don't mind getting their hands
269
  dirty. *(See bottom **Installation** tab for more details.)*
270
  * **Enhancement:** There have been a lot of optimizations to the underlying
271
  plugin code to make it run more efficiently and be easier to read, if you
272
  are so inclined.
273
+ * **Enhancement:** Changed how images, when included within the gallery, are
274
+ generated so that the format of the icon returned now matches the rest of
275
  the icons.
276
 
277
  = 1.2.1 =
285
  document gallery (using `images=true` attribute).
286
  (Thanks for the suggestion, Luca!)
287
  * **New Feature:** Attachment ids can now be explicitly listed, allowing for
288
+ documents not attached to a post or page to be included in a document
289
  gallery (e.g.: `ids=2,42,57,1`). Note that no spaces should be included.
290
  * **Enhancement:** The CSS stylesheet has been enhanced for more flexibility
291
  in sizing icons.
295
  * **New Feature:** Included option to link to the attachment page as well as
296
  to the actual document.
297
  * **Enhancement:** Added documentation for customizing the appearance of the plugin.
298
+ * **Enhancement:** Many improvements to the backend, including pretty HTML output
299
  and best practice implementation in calls to WordPress core functions.
300
 
301
  = 1.0.4 =
325
 
326
  * **New Feature:** Plugin now has **36 icons** representing **72 filetypes**!
327
  * **Enhancement:** Optimized gallery generation (faster!)
328
+ * **Enhancement:** Added fallback to WordPress default icons if you happen to
329
  include one of the few filetypes not yet supported.
330
+ * **Enhancement:** Changed shortcode to `[dg]` (`[document gallery]` will still
331
  work for backward compatibility).
332
  * **Enhancement:** Gave documentation some **much needed** revisions.
333
 
339
  = 0.8 =
340
 
341
  * **Release:** First public release of Document Gallery.
342
+ * **Feature:** Displays PDF, Word, PowerPoint, Excel, and ZIP documents from a
343
+ given page or post. **Feature:** Documents can be ordered by a number of
344
+ different factors.