PluginProbe
Document Gallery / 0.8
Document Gallery v0.8
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 0.8, at document-gallery.php

142 lines 5.1 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: 0.8
6 Author: Dan Rossiter
7 Author URI: http://danrossiter.org/
8 License: GPL2
9 */
10
11 /* much credit to: tgrayimages.com/automate-file-attachments-on-your-wordpress-posts/ */
12 add_action( 'wp_print_styles', 'add_header_css');
13
14 function add_header_css() {
15 wp_enqueue_style('document-gallery-css', plugins_url('style.css', __FILE__));
16 }
17
18 function get_attachment_icons($atts){
19 extract(shortcode_atts(array(
20 'descriptions' => FALSE,
21 'echo' => FALSE,
22 'orderby' => 'menu_order',
23 'order' => 'ASC'
24 ), $atts));
25
26 if($descriptions){
27 $sAttachmentString = "<table id='documentIconsWrapper'> \n";
28 } else{
29 $sAttachmentString = "<div id='documentIconsWrapper'> \n";
30 }
31 $args = array(
32 'numberposts' => -1,
33 'orderby' => $orderby,
34 'order' => $order,
35 'post_type' => 'attachment',
36 'post_mime_type' => 'application',
37 'post_parent' => get_the_ID() );
38
39 if ( $attachments = get_posts($args) ){
40 $count = 0;
41 foreach( $attachments as $attachment ){ //setup array for more than one file attachment
42 $attachment_url = wp_get_attachment_url($attachment->ID);
43 $attachment_name_array = explode("/",$attachment_url);
44 $attachment_title = wp_get_attachment_link($attachment->ID);
45
46 if($descriptions){
47 $sAttachmentString .= "<tr><td class='documentIcons'><a href='$attachment_url'>";
48 } else{
49 $sAttachmentString .= "<div class='documentIcons'><a href='$attachment_url'>";
50 }
51
52 switch(get_post_mime_type( $attachment->ID )){
53 case 'application/pdf': // pdf files
54 $sAttachmentString .= "<img src='".plugins_url('images/pdf.png', __FILE__)."'/>";
55 break;
56 case 'application/msword': // word files
57 $sAttachmentString .= "<img src='".plugins_url('images/word.png' , __FILE__)."'/>";
58 break;
59 case 'application/vnd.ms-powerpoint': // powerpoint files
60 $sAttachmentString .= "<img src='".plugins_url('images/PowerPoint.png' , __FILE__)."'/>";
61 break;
62 case 'application/vnd.ms-excel': // excel files
63 $sAttachmentString .= "<img src='".plugins_url( 'images/XLS8.png' , __FILE__)."'/>";
64 break;
65 case 'application/zip': // zip files
66 $sAttachmentString .= "<img src='".plugins_url( 'images/zip.png' , __FILE__)."'/>";
67 break;
68 default:
69 continue;
70 }
71
72 $sAttachmentString .= "</a><br><a href='$attachment_url'>$attachment_title</a>";
73 if($descriptions){
74 $sAttachmentString .= "</td><td valign='top'><p>$attachment->post_content</p></td></tr>";
75 }else{
76 $sAttachmentString .= "</div>";
77 if(++$count % 4 == 0)
78 $sAttachmentString .= "<hr>";
79 }
80 }
81 }
82
83 //Audio Files
84 /*$mp3s = get_children(array( //do only if there are attachments of these qualifications
85 'post_parent' => get_the_ID(),
86 'post_type' => 'attachment',
87 'numberposts' => -1,
88 'post_mime_type' => 'audio', //MIME Type condition
89 ) );
90
91 if (!empty($mp3s)) :
92 $sAttachmentString .= "<ul class='audiofiles'>";
93 foreach($mp3s as $mp3) :
94 $sAttachmentString .= "<li>";
95 if(!empty($mp3->post_title)) : //checking to make sure the post title isn't empty
96 $sAttachmentString .= "<h4 class='title'>".$mp3->post_title."</h4>";
97 endif;
98
99 if(!empty($mp3->post_content)) : //checking to make sure something exists in post_content (description)
100 $sAttachmentString .= "<p class='description'>".$mp3->post_content."</p>";
101 endif;
102
103 $sAttachmentString .= "<object width='470' height='24' id='single".$mp3->ID."' name='single".$mp3->ID."'>";
104 $sAttachmentString .= "<param name='movie' value='player.swf'>";
105 $sAttachmentString .= "<param name='allowfullscreen' value='true'>";
106 $sAttachmentString .= "<param name='allowscriptaccess' value='always'>";
107 $sAttachmentString .= "<param name='wmode' value='transparent'>";
108 $sAttachmentString .= "<param name='flashvars' value='file=".$mp3->guid."'>";
109 $sAttachmentString .= "<embed ";
110 $sAttachmentString .= "id='single".$mp3->ID."' ";
111 $sAttachmentString .= "name='single".$mp3->ID."' ";
112 $sAttachmentString .= "src='".get_bloginfo('template_directory')."/jw/player.swf' ";
113 $sAttachmentString .= "width='470' ";
114 $sAttachmentString .= "height='24' ";
115 $sAttachmentString .= "bgcolor='#ffffff' ";
116 $sAttachmentString .= "allowscriptaccess='always' ";
117 $sAttachmentString .= "allowfullscreen='true' ";
118 $sAttachmentString .= "flashvars='file=".$mp3->guid."' ";
119
120 $sAttachmentString .= "/>";
121 $sAttachmentString .= "</object>";
122 $sAttachmentString .= "<a href='".$mp3->guid."'>Download</a>";
123 $sAttachmentString .= "</li>";
124 endforeach;
125 $sAttachmentString .= "</ul>";
126 endif;*/
127
128 if($descriptions){
129 $sAttachmentString .= "</table>";
130 }else{
131 $sAttachmentString .= "</div>";
132 }
133 /*$finalString = implode('', $sAttachmentString);*/
134 if($echo){
135 /*echo $finalString;*/
136 echo $sAttachmentString;
137 }
138 return $sAttachmentString; /*$finalString;*/
139 }
140 add_shortcode('document gallery', 'get_attachment_icons');
141 ?>
142