Document Gallery - Version 1.0.1

Version Description

  • Resolved issue with long document titles being cut off in some themes.
Download this release

Release Info

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

Version 1.0.1

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