Document Gallery - Version 1.0

Version Description

  • Optimized gallery generation (faster!)
  • Plugin now has 36 icons representing 72 filetypes!
  • Added fallback to WordPress default icons if you happen to include one of the few filetypes not yet supported.
  • Changed shortcode to [dg] ([document gallery] will still work for backward compatibility).
  • Gave documentation some much needed revisions.
Download this release

Release Info

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

Version 1.0

document-gallery.php ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Document Gallery
4
+ Description: Display non-images in gallery format on page.
5
+ Version: 1.0
6
+ Author: Dan Rossiter
7
+ Author URI: http://danrossiter.org/
8
+ License: GPL2
9
+ */
10
+
11
+ define( 'DG_URL', plugin_dir_url().'document-gallery/' );
12
+
13
+ // CREATE GALLERY STRING //
14
+ function dg_get_attachment_icons($atts) {
15
+ extract( shortcode_atts( array(
16
+ 'descriptions' => FALSE,
17
+ 'echo' => FALSE,
18
+ 'orderby' => 'menu_order',
19
+ 'order' => 'ASC'
20
+ ), $atts) );
21
+
22
+ $args = array(
23
+ 'numberposts' => -1,
24
+ 'orderby' => $orderby,
25
+ 'order' => $order,
26
+ 'post_type' => 'attachment',
27
+ 'post_mime_type' => 'application,video,text,audio',
28
+ 'post_parent' => get_the_ID() );
29
+
30
+ if ( $attachments = get_posts($args) ) {
31
+ $attachment_str = array( '<!-- GENERATED USING DOCUMENT GALLERY'.PHP_EOL.
32
+ ' http://wordpress.org/extend/plugins/document-gallery -->'.PHP_EOL );
33
+
34
+ if($descriptions) {
35
+ $attachment_str[] = '<table id="document-icon-wrapper">';
36
+ } else {
37
+ $attachment_str[] = '<div id="document-icon-wrapper">';
38
+ }
39
+
40
+ $count = 0;
41
+ foreach( $attachments as $attachment ) { //setup array for more than one file attachment
42
+ $url = wp_get_attachment_url( $attachment->ID );
43
+ $title = wp_get_attachment_link( $attachment->ID );
44
+ $icon = dg_get_attachment_icon( $attachment->ID, $tile, $url );
45
+
46
+ if($descriptions) {
47
+ $attachment_str[] = '<tr><td class="document-icon">';
48
+ } else {
49
+ $attachment_str[] = '<div class="document-icon">';
50
+ }
51
+
52
+ $attachment_str[] = "<a href=\"$url\">$icon</a><br><a href=\"$url\">$title</a>";
53
+
54
+ if($descriptions) {
55
+ $attachment_str[] = "</td><td valign=\"top\"><p>$attachment->post_content</p></td></tr>";
56
+ } else {
57
+ $attachment_str[] = '</div>';
58
+ if( ++$count % 4 == 0 ) {
59
+ $attachment_str[] = '<hr>';
60
+ }
61
+ }
62
+ } // end looping attachments
63
+
64
+ // close #document-icon-wrapper
65
+ if($descriptions) {
66
+ $attachment_str[] = '</table>';
67
+ } else {
68
+ $attachment_str[] = '</div>';
69
+ }
70
+
71
+ // join array & return
72
+ $attachment_str = implode( '', $attachment_str );
73
+ return $attachment_str;
74
+ } // end if attachments
75
+
76
+ return '<!-- Document Gallery: No attachments to display. -->'.PHP_EOL;
77
+ }
78
+ add_shortcode('document gallery', 'dg_get_attachment_icons');
79
+ add_shortcode('dg', 'dg_get_attachment_icons');
80
+
81
+
82
+ // ADD SOME STYLING //
83
+ function dg_add_header_css() {
84
+ wp_enqueue_style( 'document-gallery-css', plugins_url('style.css', __FILE__) );
85
+ }
86
+ add_action( 'wp_print_styles', 'dg_add_header_css');
87
+
88
+
89
+ // HELPERS //
90
+
91
+ // pass in $title & $url to avoid mult function calls
92
+ function dg_get_attachment_icon( $id, $title, $url ) {
93
+ $filename = basename( $url );
94
+ $filetype = wp_check_filetype( $filename );
95
+
96
+ // identify extension
97
+ switch( $filetype['ext'] ) {
98
+ // Most Common First
99
+ case 'pdf':
100
+ $icon = 'pdf.png';
101
+ break;
102
+ // MS Office
103
+ case 'doc':
104
+ case 'docx':
105
+ case 'docm':
106
+ case 'dotx':
107
+ case 'dotm':
108
+ $icon = 'msdoc.png';
109
+ break;
110
+ case 'ppt':
111
+ case 'pot':
112
+ case 'pps':
113
+ case 'pptx':
114
+ case 'pptm':
115
+ case 'ppsx':
116
+ case 'ppsm':
117
+ case 'potx':
118
+ case 'potm':
119
+ case 'ppam':
120
+ case 'sldx':
121
+ case 'sldm':
122
+ $icon = 'msppt.png';
123
+ break;
124
+ case 'xla':
125
+ case 'xls':
126
+ case 'xlt':
127
+ case 'xlw':
128
+ case 'xlsx':
129
+ case 'xlsm':
130
+ case 'xlsb':
131
+ case 'xltx':
132
+ case 'xltm':
133
+ case 'xlam':
134
+ $icon = 'msxls.png';
135
+ break;
136
+ case 'mdb':
137
+ $icon = 'msaccess.png';
138
+ break;
139
+ // Video formats
140
+ case 'avi':
141
+ $icon = 'avi.png';
142
+ break;
143
+ case 'divx':
144
+ $icon = 'divx.png';
145
+ break;
146
+ case 'flv':
147
+ $icon = 'flv.png';
148
+ break;
149
+ case 'qt':
150
+ case 'mov':
151
+ $icon = 'mov.png';
152
+ break;
153
+ case 'asf':
154
+ case 'asx':
155
+ case 'wax':
156
+ case 'wmv':
157
+ case 'wmx':
158
+ $icon = 'wmv.png';
159
+ break;
160
+ case 'mkv':
161
+ $icon = 'mkv.png';
162
+ break;
163
+ // Audio formats
164
+ case 'mp3':
165
+ $icon = 'mp3.png';
166
+ break;
167
+ case 'wav':
168
+ $icon = 'wav.png';
169
+ break;
170
+ case 'ogg':
171
+ case 'oga':
172
+ $icon = 'ogg.png';
173
+ break;
174
+ case 'midi':
175
+ case 'mid':
176
+ $icon = 'midi.png';
177
+ break;
178
+ case 'wma':
179
+ $icon = 'wma.png';
180
+ break;
181
+ // Text formats
182
+ case 'rtx':
183
+ $icon = 'rtx.png';
184
+ break;
185
+ case 'ics':
186
+ $icon = 'ics.png';
187
+ break;
188
+ case 'csv':
189
+ $icon = 'csv.png';
190
+ break;
191
+ // Msc application formats
192
+ case 'html':
193
+ case 'htm': // death to all who use this!
194
+ $icon = 'html.png';
195
+ break;
196
+ case 'css':
197
+ $icon = 'css.png';
198
+ break;
199
+ case 'js':
200
+ $icon = 'javascript.png';
201
+ break;
202
+ case 'class':
203
+ $icon = 'java.png';
204
+ break;
205
+ case 'zip':
206
+ $icon = 'zip.png';
207
+ break;
208
+ case 'tar':
209
+ case 'gzip':
210
+ case 'gz':
211
+ case 'bz2': // not yet WP-supported
212
+ case 'tgz': // not yet WP-supported
213
+ $icon = 'compressed.png';
214
+ break;
215
+ case 'rar': // RAWR!!!
216
+ $icon = 'rar.png';
217
+ break;
218
+ case '7z':
219
+ $icon = '7zip.png';
220
+ break;
221
+ case 'exec':
222
+ $icon = 'exec.png';
223
+ break;
224
+ case 'rtf':
225
+ $icon = 'rtf.png';
226
+ break;
227
+ case 'swf':
228
+ $icon = 'shockwave.png';
229
+ break;
230
+ // OpenOffice formats
231
+ case 'odt':
232
+ $icon = 'opendocument-text.png';
233
+ break;
234
+ case 'odp':
235
+ $icon = 'opendocument-presentation.png';
236
+ break;
237
+ case 'ods':
238
+ $icon = 'opendocument-spreadsheet.png';
239
+ break;
240
+ case 'odg':
241
+ $icon = 'opendocument-graphics.png';
242
+ break;
243
+ case 'odb':
244
+ $icon = 'opendocument-database.png';
245
+ break;
246
+ case 'odf':
247
+ $icon = 'opendocument-formula.png';
248
+ break;
249
+ // fallback to default icons if not recognized
250
+ default:
251
+ return get_attachment_icon( $id );
252
+ }
253
+
254
+ $icon = '<img src="'.DG_URL.'icons/'.$icon."\" title=\"$title\" alt=\"$title\"/>";
255
+ return $icon;
256
+ }
257
+ ?>
icons/7zip.png ADDED
Binary file
icons/avi.png ADDED
Binary file
icons/compressed.png ADDED
Binary file
icons/css.png ADDED
Binary file
icons/csv.png ADDED
Binary file
icons/divx.png ADDED
Binary file
icons/exec.png ADDED
Binary file
icons/flv.png ADDED
Binary file
icons/html.png ADDED
Binary file
icons/ics.png ADDED
Binary file
icons/java.png ADDED
Binary file
icons/javascript.png ADDED
Binary file
icons/midi.png ADDED
Binary file
icons/mkv.png ADDED
Binary file
icons/mov.png ADDED
Binary file
icons/mp3.png ADDED
Binary file
icons/msaccess.png ADDED
Binary file
icons/msdoc.png ADDED
Binary file
icons/msppt.png ADDED
Binary file
icons/msxls.png ADDED
Binary file
icons/ogg.png ADDED
Binary file
icons/opendocument-database.png ADDED
Binary file
icons/opendocument-formula.png ADDED
Binary file
icons/opendocument-graphics.png ADDED
Binary file
icons/opendocument-presentation.png ADDED
Binary file
icons/opendocument-spreadsheet.png ADDED
Binary file
icons/opendocument-text.png ADDED
Binary file
icons/pdf.png ADDED
Binary file
icons/rar.png ADDED
Binary file
icons/rtf.png ADDED
Binary file
icons/rtx.png ADDED
Binary file
icons/shockwave.png ADDED
Binary file
icons/wav.png ADDED
Binary file
icons/wma.png ADDED
Binary file
icons/wmv.png ADDED
Binary file
icons/zip.png ADDED
Binary file
readme.txt ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Document Gallery ===
2
+ Contributors: dan.rossiter
3
+ Tags: attachments, icons, documents, gallery
4
+ Requires at least: 2.6
5
+ Tested up to: 3.5
6
+ Stable tag: 1.0
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 attachments on a given post/page,
11
+ making them easy to share.
12
+
13
+ == Description ==
14
+
15
+ This plugin allows the user to effortlessly include a gallery, much like a photo gallery,
16
+ of all your non-image attachments anywhere within your post.
17
+
18
+ *NOTE: If you find this plugin useful, please take 10 seconds to rate it so others can find it also. Thanks so
19
+ much for your support!*
20
+
21
+ == Installation ==
22
+
23
+ 1. Upload `document-gallery` to the `/wp-content/plugins/` directory
24
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
25
+ 1. Place `[dg]` in any posts or pages you want a document gallery included. See below for additional display options.
26
+
27
+ = Document Gallery Options =
28
+
29
+ In order to include all compatible docuements from a given page or post, you must include
30
+ the following shortcode in the post:
31
+
32
+ `[dg <descriptions=[true or false]> <orderby=[menu_order, title, date, author, rand]> <order=[ASC or DEC]>]`
33
+
34
+ **Orderby Options**
35
+ * `menu_order` - This is probably the one you want to use. Order by the integer fields in the Insert /
36
+ Upload Media Gallery dialog. Note that these fields may be blank by default. If this is the case,
37
+ you must populate the fields before this option will work.
38
+ * `title` - Alphabetical order based on title.
39
+ * `date` - Order by date of document upload.
40
+ * `author` - Order by the owner of the upload (username).
41
+ * `rand` - Pseudo-random order.
42
+
43
+ By default, document gallery will use `descriptions=false`, `orderby=menu_order`, and `order=ASC` if you
44
+ do not specify otherwise.
45
+
46
+ = Theme Developers =
47
+
48
+ If you would like to include Document Gallery functionality in your theme, you simply need to include the following
49
+ code wherever you would like it to appear: `<?php echo do_shortcode('[dg]'); ?>`. You can include additional options
50
+ (listed above) as needed.
51
+
52
+ == Screenshots ==
53
+
54
+ 1. This is how the Document Gallery looks with `descriptions=false` (default). Note that the display inherits styling from your active theme.
55
+ 2. This is how the Document Gallery looks with `descriptions=true`. The descriptions are auto-populated using the description field from when you upload the document.
56
+
57
+ == Changelog ==
58
+
59
+ = Coming Soon! =
60
+
61
+ * Option to include player for any music files uploaded to page.
62
+ * Option to open documents directly within your browser (a la [Google Drive Viewer](https://drive.google.com/viewer)).
63
+ * Support for adding your own filetypes/icons.
64
+ * Whatever else **you** would like (post on the [support forum](http://wordpress.org/support/plugin/document-gallery) if you have ideas)!
65
+
66
+ = 1.0 =
67
+
68
+ * Optimized gallery generation (faster!)
69
+ * Plugin now has **36 icons** representing **72 filetypes**!
70
+ * Added fallback to WordPress default icons if you happen to include one of the few filetypes not yet supported.
71
+ * Changed shortcode to `[dg]` (`[document gallery]` will still work for backward compatibility).
72
+ * Gave documentation some **much needed** revisions.
73
+
74
+ = 0.8.5 =
75
+
76
+ * Added support for [OpenDocuments](http://en.wikipedia.org/wiki/OpenDocument).
77
+
78
+ = 0.8 =
79
+
80
+ * First public release of Document Gallery.
81
+ * Displays PDF, Word, PowerPoint, Excel, and ZIP documents from a given page or post.
82
+ * Documents can be ordered by a number of different factors.
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
style.css ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .document-icon{ text-align: center; }
2
+
3
+ .document-icon img{
4
+ border: none;
5
+ }
6
+
7
+ .document-icon a{
8
+ font-size: 10px;
9
+ line-height: 12px;
10
+ }
11
+
12
+ /* WITHOUT DESCRIPTION */
13
+ div.document-icon{
14
+ float: left;
15
+ min-height: 125px;
16
+ max-height: 145px;
17
+ overflow: hidden;
18
+ padding: 10px 0;
19
+ width: 25%;
20
+ }
21
+ div#document-icon-wrapper hr{
22
+ border: none;
23
+ width: 100%;
24
+ height: 0;
25
+ padding: 0;
26
+ margin: 0;
27
+ }
28
+ /* END WITHOUT DESCRIPTION */
29
+
30
+ /* WITH DESCRIPTION */
31
+ td.document-icon{ width: 115px; }
32
+ table#document-icon-wrapper{ border-collapse: collapse; }
33
+
34
+ table#document-icon-wrapper,
35
+ table#document-icon-wrapper tbody,
36
+ table#document-icon-wrapper tr,
37
+ table#document-icon-wrapper p{
38
+ width: 100%;
39
+ padding: 0;
40
+ margin: 0;
41
+ border: none;
42
+ }
43
+
44
+ table#document-icon-wrapper td{
45
+ padding: 5px 4px 3px;
46
+ vertical-align: middle;
47
+ }
48
+
49
+ table .document-icon img{
50
+ width: 65px;
51
+ height: 65px;
52
+ }
53
+ /* END WITH DESCRIPTION */