PluginProbe
WP Attachments / 3.1.1
WP Attachments v3.1.1
6.0.2 6.0.3 trunk 2.0 3 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.2 3.1.3 3.1.4 3.2 3.2.1 3.2.2 3.2.3 3.2.4 3.3 3.4 3.5 3.5.1 3.5.2 3.5.3 3.5.4 All 52 releases
wp-attachments / wp-attachments.php

wp-attachments.php in WP Attachments 3.1.1, at wp-attachments.php

259 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP Attachments
4 Plugin URI: http://marcomilesi.ml
5 Description: Automatically shows your attachments under every post and page content. Simple. Automatic. Easy. As it has to be!
6 Author: Marco Milesi
7 Version: 3.1.1
8 Author URI: http://marcomilesi.ml
9 */
10
11
12
13 function wpatt_format_bytes($a_bytes)
14 {
15
16 if ($a_bytes < 1024)
17 {
18
19 return $a_bytes . ' B';
20
21 }
22 elseif ($a_bytes < 1048576)
23 {
24
25 return round($a_bytes / 1024, 2) . ' KB';
26
27 }
28 elseif ($a_bytes < 1073741824)
29 {
30
31 return round($a_bytes / 1048576, 2) . ' MB';
32
33 }
34 elseif ($a_bytes < 1099511627776)
35 {
36
37 return round($a_bytes / 1073741824, 2) . ' GB';
38
39 }
40 else
41 {
42
43 return round($a_bytes / 1208925819614629174706176, 2) . ' ERROR';
44
45 }
46
47 }
48
49
50 add_filter('the_content', 'wpatt_job_cpt_template_filter');
51
52 function wpatt_job_cpt_template_filter($content)
53 {
54 global $post;
55 $somethingtoshow = 0;
56
57 $attachments = get_posts(array(
58 'post_type' => 'attachment',
59 'orderby' => 'menu_order',
60 'posts_per_page' => 100,
61 'post_parent' => $post->ID
62 ));
63
64 if ($attachments)
65 {
66 $content_l .= '<div style="width:100%;float:left;margin:10px 0 10px 0;"><h3>' . get_option('wpatt_option_localization') . '</h3>
67 <style>
68 ul.post-attachments{list-style:none;margin:0;}
69 li.post-attachment{background:url(' . plugin_dir_url(__FILE__) . 'icons/document.png) 0 4px no-repeat;padding-left:24px} .post-attachment.mime-imagejpeg,.post-attachment.mime-imagepng,.post-attachment.mime-imagejpeg,.post-attachment.mime-imagegif{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-image.png)}
70 .post-attachment.mime-applicationzip{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-zipper.png)}
71 .post-attachment.mime-applicationpdf{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-pdf.png)}
72 .post-attachment.mime-applicationvnd-ms-excel{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-excel.png)}
73 .post-attachment.mime-applicationvnd-openxmlformats-officedocument-spreadsheetml-sheet{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-excel.png)}
74 .post-attachment.mime-applicationmsword{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-word.png)}
75 .post-attachment.mime-applicationvnd-openxmlformats-officedocument-wordprocessingml-document{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-word.png)}
76 </style><ul class="post-attachments">';
77
78 foreach ($attachments as $attachment)
79 {
80
81 $wpatt_option_includeimages_get = get_option('wpatt_option_includeimages');
82 if ($wpatt_option_includeimages_get == '1') {
83 } else if ( wp_attachment_is_image( $attachment->ID ) ) {
84 continue;
85 }
86 $somethingtoshow = 1;
87
88 $class = "post-attachment mime-" . sanitize_title($attachment->post_mime_type);
89
90 $content_l .= '<li class="' . $class . '"><a href="' . wp_get_attachment_url($attachment->ID) . '">' . $attachment->post_title . '</a> (' . wpatt_format_bytes(filesize(get_attached_file($attachment->ID)));
91
92
93 $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
94
95 if ($wpatt_option_showdate_get == '1')
96 {
97
98 $wpatt_date = new DateTime($attachment->post_date);
99
100 $content_l .= '<div style="float:right;">' . $wpatt_date->format('d.m.Y') . '</div>';
101
102 }
103
104 $content_l .= ')</li>';
105
106 }
107 $content_l .= '</ul></div>';
108
109 }
110 if ($somethingtoshow == 1) {
111 $content .= $content_l;
112 return $content_l;
113 } else {
114 return $content;
115 }
116
117 }
118
119
120
121 /* Register Settings */
122
123 add_action('admin_init', 'wpatt_reg_settings');
124
125 function wpatt_reg_settings()
126 {
127
128 register_setting('wpatt_options_group', 'wpatt_option_showdate', 'intval');
129
130 register_setting('wpatt_options_group', 'wpatt_option_includeimages', 'intval');
131
132 register_setting('wpatt_options_group', 'wpatt_option_localization');
133
134 /* Preopulate 'Attachments' */
135
136 $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
137
138 if (get_option('wpatt_option_localization') == '')
139 {
140
141 update_option('wpatt_option_localization', 'Attachments');
142
143 }
144
145 }
146
147
148
149 /* Here starts the code for the option panel */
150
151
152
153 add_action('admin_menu', 'wpatt_plugin_menu');
154
155
156
157 function wpatt_plugin_menu()
158 {
159
160 add_options_page('WP Attachments - Settings', 'WP Attachments', 'manage_options', 'wpatt-option-page', 'wpatt_plugin_options');
161
162 }
163
164
165
166 function wpatt_plugin_options()
167 {
168
169 if (!current_user_can('manage_options'))
170 {
171
172 wp_die(__('You do not have sufficient permissions to access this page.'));
173
174 }
175
176
177
178 if (isset($_POST['Submit'])) {
179
180 $wpatt_option_localization_get = $_POST["wpatt_option_localization_n"];
181
182 update_option('wpatt_option_localization', $wpatt_option_localization_get);
183
184 if (isset($_POST['wpatt_option_showdate_n'])) {
185 update_option('wpatt_option_showdate', '1');
186 } else {
187 update_option('wpatt_option_showdate', '0');
188 }
189
190 if (isset($_POST['wpatt_option_includeimages_n'])) {
191 update_option('wpatt_option_includeimages', '1');
192 } else {
193 update_option('wpatt_option_includeimages', '0');
194 }
195 }
196
197
198
199 echo '<div class="wrap">';
200
201 screen_icon();
202
203 echo '<h2>WP Attachments</h2>';
204 echo '<h3>OPTIONS</h3>';
205
206 echo '<div id="welcome-panel" class="welcome-panel">';
207
208 echo '<form method="post" name="options" target="_self">';
209
210 settings_fields('wpatt_option_group');
211
212 echo '
213
214 <table class="form-table">
215
216
217
218 <tr valign="top">
219
220 <th scope="row">Label for list header</th>
221
222 <td><input type="text" name="wpatt_option_localization_n" value="';
223
224 echo get_option('wpatt_option_localization');
225
226 echo '" />&nbsp;Insert here the label you want to use for the title of the attachments list. Default "<b>Attachments</b>"</td></tr>';
227
228 echo '<tr><th scope="row">Include Images?</th>
229 <td><input type="checkbox" name="wpatt_option_includeimages_n" ';
230 $wpatt_option_includeimages_get = get_option('wpatt_option_includeimages');
231 if ($wpatt_option_includeimages_get == '1') {
232 echo 'checked=\'checked\'';
233 }
234 echo '/>&nbsp;Check this if you want to include images (.jpg, .jpeg, .gif, .png) from being listed.</td>';
235 echo '</tr>';
236
237
238 echo '<tr><th scope="row">Show date?</th>
239 <td><input type="checkbox" name="wpatt_option_showdate_n" ';
240 $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
241 if ($wpatt_option_showdate_get == '1') {
242 echo 'checked=\'checked\'';
243 }
244 echo '/>&nbsp;Check this if you want to show when the file has been uploaded.</td>';
245 echo '</tr></table>';
246
247
248
249 echo '</table><p class="submit"><input type="submit" class="button-primary" name="Submit" value="Update" /></p>';
250
251 echo '</form></div>
252 <h3>HELP, SUPPORT & FEEDBACK</h3>
253 <a href="http://wordpress.org/plugins/wp-attachments/" title "WP Attachments Wordpress Plugin>http://wordpress.org/plugins/wp-attachments/</a><br/>
254 This plugin is continuously developed by Marco Milesi focusing on semplicity, intuitiveness and cleanness. Keep updated :)<br/>
255 Thank You for using this plugin.</div>';
256
257 }
258
259 ?>