PluginProbe
Document Gallery / 1.0
Document Gallery v1.0
trunk 0.8 0.8.5 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 2.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 94 releases
document-gallery / document-gallery.php

document-gallery.php in Document Gallery 1.0, at document-gallery.php

258 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 ?>
258