PluginProbe
WP Attachments / 3.1.4
WP Attachments v3.1.4
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.4, at wp-attachments.php

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