PluginProbe
WP Attachments – Smarter File Management & Download Lists / 3.1.2
WP Attachments – Smarter File Management & Download Lists v3.1.2
6.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 All 53 releases
wp-attachments / wp-attachments.php

wp-attachments.php in WP Attachments – Smarter File Management & Download Lists 3.1.2, at wp-attachments.php

278 lines 8.7 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.2
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 }
113 return $content;
114 }
115
116
117
118 /* Enable Backend? */
119 dd_action( 'init', 'WPATT_FUNCTIONSLOAD');
120
121 function WPATT_FUNCTIONSLOAD () {
122 $get_wpatt_disable_backend = get_option('wpatt_disable_backend');
123 if ($get_wpatt_disable_backend == '1') {
124 include(plugin_dir_path(__FILE__) . 'backend.php');
125 }
126 }
127 /* Register Settings */
128
129 add_action('admin_init', 'wpatt_reg_settings');
130
131 function wpatt_reg_settings()
132 {
133
134 register_setting('wpatt_options_group', 'wpatt_option_showdate', 'intval');
135
136 register_setting('wpatt_options_group', 'wpatt_option_includeimages', 'intval');
137
138 register_setting('wpatt_options_group', 'wpatt_option_localization');
139
140 register_setting('wpatt_options_group', 'wpatt_disable_backend');
141
142 /* Preopulate 'Attachments' */
143
144 $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
145
146 if (get_option('wpatt_option_localization') == '')
147 {
148 update_option('wpatt_option_localization', 'Attachments');
149 }
150 }
151
152
153
154 /* Here starts the code for the option panel */
155
156
157
158 add_action('admin_menu', 'wpatt_plugin_menu');
159
160
161
162 function wpatt_plugin_menu()
163 {
164
165 add_options_page('WP Attachments - Settings', 'WP Attachments', 'manage_options', 'wpatt-option-page', 'wpatt_plugin_options');
166
167 }
168
169
170
171 function wpatt_plugin_options()
172 {
173
174 if (!current_user_can('manage_options'))
175 {
176
177 wp_die(__('You do not have sufficient permissions to access this page.'));
178
179 }
180
181
182
183 if (isset($_POST['Submit'])) {
184
185 $wpatt_option_localization_get = $_POST["wpatt_option_localization_n"];
186
187 update_option('wpatt_option_localization', $wpatt_option_localization_get);
188
189 if (isset($_POST['wpatt_option_showdate_n'])) {
190 update_option('wpatt_option_showdate', '1');
191 } else {
192 update_option('wpatt_option_showdate', '0');
193 }
194
195 if (isset($_POST['wpatt_option_includeimages_n'])) {
196 update_option('wpatt_option_includeimages', '1');
197 } else {
198 update_option('wpatt_option_includeimages', '0');
199 }
200
201 if (isset($_POST['wpatt_disable_backend_n'])) {
202 update_option('wpatt_disable_backend', '0');
203 } else {
204 update_option('wpatt_disable_backend', '1');
205 }
206 }
207
208
209
210 echo '<div class="wrap">';
211
212 screen_icon();
213
214 echo '<h2>WP Attachments</h2>';
215 echo '<h3>OPTIONS</h3>';
216
217 echo '<div id="welcome-panel" class="welcome-panel">';
218
219 echo '<form method="post" name="options" target="_self">';
220
221 settings_fields('wpatt_option_group');
222
223 echo '
224
225 <table class="form-table">
226
227
228
229 <tr valign="top">
230
231 <th scope="row">Label for list header</th>
232
233 <td><input type="text" name="wpatt_option_localization_n" value="';
234
235 echo get_option('wpatt_option_localization');
236
237 echo '" />&nbsp;Insert here the label you want to use for the title of the attachments list. Default "<b>Attachments</b>"</td></tr>';
238
239 echo '<tr><th scope="row">Include Images?</th>
240 <td><input type="checkbox" name="wpatt_option_includeimages_n" ';
241 $wpatt_option_includeimages_get = get_option('wpatt_option_includeimages');
242 if ($wpatt_option_includeimages_get == '1') {
243 echo 'checked=\'checked\'';
244 }
245 echo '/>&nbsp;Check this if you want to include images (.jpg, .jpeg, .gif, .png) from being listed.</td>';
246 echo '</tr>';
247
248 echo '<tr><th scope="row">Enable Back-End?</th>
249 <td><input type="checkbox" name="wpatt_disable_backends_n" ';
250 $wpatt_disable_backend_get = get_option('wpatt_disable_backend');
251 if ($wpatt_disable_backend_get == '0') {
252 echo 'checked=\'checked\'';
253 }
254 echo '/>&nbsp;Check this if you want to enable the integrated back-end functions.</td>';
255 echo '</tr>';
256
257 echo '<tr><th scope="row">Show date?</th>
258 <td><input type="checkbox" name="wpatt_option_showdate_n" ';
259 $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
260 if ($wpatt_option_showdate_get == '1') {
261 echo 'checked=\'checked\'';
262 }
263 echo '/>&nbsp;Check this if you want to show when the file has been uploaded.</td>';
264 echo '</tr></table>';
265
266
267
268 echo '</table><p class="submit"><input type="submit" class="button-primary" name="Submit" value="Update" /></p>';
269
270 echo '</form></div>
271 <h3>HELP, SUPPORT & FEEDBACK</h3>
272 <a href="http://wordpress.org/plugins/wp-attachments/" title "WP Attachments Wordpress Plugin>http://wordpress.org/plugins/wp-attachments/</a><br/>
273 This plugin is continuously developed by Marco Milesi focusing on simplicity, intuitiveness and cleanness. Keep updated :)<br/>
274 Thank You for using this plugin.</div>';
275
276 }
277
278 ?>