PluginProbe
WP Attachments / 3.2
WP Attachments v3.2
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
← All changes | wp-attachments.php +153 -141 33.2 View file →
@@ -3,146 +3,158 @@
3 3 Plugin Name: WP Attachments
4 4 Plugin URI: http://marcomilesi.ml
5 5 Description: Automatically shows your attachments under every post and page content. Simple. Automatic. Easy. As it has to be!
6 6 Author: Marco Milesi
7 -Version: 3.0
7 +Version: 3.2
8 8 Author URI: http://marcomilesi.ml
9 -*/
10 -
11 -function wpatt_format_bytes($a_bytes)
12 -{
13 - if ($a_bytes < 1024) {
14 - return $a_bytes . ' B';
15 - } elseif ($a_bytes < 1048576) {
16 - return round($a_bytes / 1024, 2) . ' KB';
17 - } elseif ($a_bytes < 1073741824) {
18 - return round($a_bytes / 1048576, 2) . ' MB';
19 - } elseif ($a_bytes < 1099511627776) {
20 - return round($a_bytes / 1073741824, 2) . ' GB';
21 - } else {
22 - return round($a_bytes / 1208925819614629174706176, 2) . ' ERROR';
23 - }
24 -}
25 -
26 -add_action('template_redirect', 'wpatt_job_cpt_template');
27 -function wpatt_job_cpt_template()
28 -{
29 - global $wp, $wp_query;
30 - if (have_posts()) {
31 - add_filter('the_content', 'wpatt_job_cpt_template_filter');
32 - } else {
33 - $wp_query->is_404 = true;
34 - }
35 -}
36 -
37 -function wpatt_job_cpt_template_filter($content)
38 -{
39 - global $wp_query;
40 - $jobID = $wp_query->post->ID;
41 - echo get_the_content();
42 - echo '<div style="width:100%;margin:10px 0 10px 0;"><h3>' . get_option('wpatt_option_localization') . '</h3></div>';
43 - $args = array(
44 - 'post_type' => 'attachment',
45 - 'numberposts' => -1,
46 - 'post_status' => null,
47 - 'post_parent' => get_the_ID(),
48 - 'orderby' => 'menu_order',
49 - 'order' => 'desc'
50 - );
51 - $attachments = get_posts($args);
52 - if ($attachments) {
53 - foreach ($attachments as $attachment) {
54 - echo '<style>
55 - ul.post-attachments{list-style:none;margin:0;}
56 - 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{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-image.png)}
57 - .post-attachment.mime-applicationzip{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-zipper.png)}
58 - .post-attachment.mime-applicationpdf{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-pdf.png)}
59 - .post-attachment.mime-applicationvnd-ms-excel{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-excel.png)}
60 - .post-attachment.mime-applicationvnd-openxmlformats-officedocument-spreadsheetml-sheet{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-excel.png)}
61 - .post-attachment.mime-applicationmsword{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-word.png)}
62 - .post-attachment.mime-applicationvnd-openxmlformats-officedocument-wordprocessingml-document{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-word.png)}
63 - </style>';
64 - echo '<ul class="post-attachments">';
65 - $class = "post-attachment mime-" . sanitize_title($attachment->post_mime_type);
66 - echo '<li class="' . $class . '"><a href="' . wp_get_attachment_url($attachment->ID) . '">';
67 - echo $attachment->post_title;
68 - echo '</a> (';
69 - echo wpatt_format_bytes(filesize(get_attached_file($attachment->ID)));
70 - $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
71 - if ($wpatt_option_showdate_get == '1') {
72 - $wpatt_date = new DateTime($attachment->post_date);
73 - echo '<div style="float:right;">' . $wpatt_date->format('d.m.Y') . '</div>';
74 - }
75 - echo ')</li></ul>';
76 - }
77 - }
78 -}
79 -
80 -/* Register Settings */
81 -add_action('admin_init', 'wpatt_reg_settings');
82 -function wpatt_reg_settings()
83 -{
84 - register_setting('wpatt_options_group', 'wpatt_option_showdate', 'intval');
85 - register_setting('wpatt_options_group', 'wpatt_option_localization');
86 - /* Preopulate 'Attachments' */
87 - $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
88 - if (get_option('wpatt_option_localization') == '') {
89 - update_option('wpatt_option_localization', 'Attachments');
90 - }
91 -}
92 -
93 -/* Here starts the code for the option panel */
94 -
95 -add_action('admin_menu', 'wpatt_plugin_menu');
96 -
97 -function wpatt_plugin_menu()
98 -{
99 - add_options_page('WP Attachments - Settings', 'WP Attachments', 'manage_options', 'wpatt-option-page', 'wpatt_plugin_options');
100 -}
101 -
102 -function wpatt_plugin_options()
103 -{
104 - if (!current_user_can('manage_options')) {
105 - wp_die(__('You do not have sufficient permissions to access this page.'));
106 - }
107 -
108 - if (isset($_POST['Submit'])) {
109 - $wpatt_option_localization_get = $_POST["wpatt_option_localization_n"];
110 - update_option('wpatt_option_localization', $wpatt_option_localization_get);
111 -
112 - if (isset($_POST['wpatt_option_showdate_n'])) {
113 - update_option('wpatt_option_showdate', '1');
114 - } else {
115 - update_option('wpatt_option_showdate', '0');
116 - }
117 -
118 - }
119 -
120 - echo '<div class="wrap">';
121 - screen_icon();
122 - echo '<h2>Settings</h2>';
123 - echo '<div id="welcome-panel" class="welcome-panel">';
124 - echo '<form method="post" name="options" target="_self">';
125 - settings_fields('wpatt_option_group');
126 - echo '
127 - <table class="form-table">
128 -
129 - <tr valign="top">
130 - <th scope="row">Label for list header</th>
131 - <td><input type="text" name="wpatt_option_localization_n" value="';
132 - echo get_option('wpatt_option_localization');
133 - echo '" />&nbsp;Insert here the label you want to use for the title of the attachments list. Default "<b>Attachments</b>"</td></tr>';
134 -
135 - echo '<tr><th scope="row">Show date?</th>
136 - <td><input type="checkbox" name="wpatt_option_showdate_n" ';
137 - $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
138 - if ($wpatt_option_showdate_get == '1') {
139 - echo 'checked=\'checked\'';
140 - }
141 - echo '/>&nbsp;Check this if you want to show when the file has been uploaded.</td>';
142 - echo '</tr></table>';
143 -
144 - echo '</table><p class="submit"><input type="submit" name="Submit" value="Update" /></p>';
145 - echo '</form></div></div>';
146 -}
147 -
148 -?>
9 +*/
10 +
11 +function wpa_action_init()
12 +{
13 + load_plugin_textdomain( 'wp-attachments', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
14 + update_option( 'wpa_version_number', '3.2' );
15 +}
16 +
17 +// Add actions
18 +add_action('init', 'wpa_action_init');
19 +require_once(plugin_dir_path(__FILE__) . 'settings.php');
20 +require_once(plugin_dir_path(__FILE__) . 'ij-post-attachments.php');
21 +
22 +function wpatt_format_bytes($a_bytes)
23 + {
24 +
25 + if ($a_bytes < 1024)
26 + {
27 +
28 + return $a_bytes . ' B';
29 +
30 + }
31 + elseif ($a_bytes < 1048576)
32 + {
33 +
34 + return round($a_bytes / 1024, 2) . ' KB';
35 +
36 + }
37 + elseif ($a_bytes < 1073741824)
38 + {
39 +
40 + return round($a_bytes / 1048576, 2) . ' MB';
41 +
42 + }
43 + elseif ($a_bytes < 1099511627776)
44 + {
45 +
46 + return round($a_bytes / 1073741824, 2) . ' GB';
47 +
48 + }
49 + else
50 + {
51 +
52 + return round($a_bytes / 1208925819614629174706176, 2) . ' ERROR';
53 +
54 + }
55 +
56 + }
57 +
58 +
59 +add_filter('the_content', 'wpatt_job_cpt_template_filter');
60 +
61 +function wpatt_job_cpt_template_filter($content)
62 + {
63 + global $post;
64 + $somethingtoshow = 0;
65 +
66 + $attachments = get_posts(array(
67 + 'post_type' => 'attachment',
68 + 'orderby' => 'menu_order',
69 + 'order' => 'ASC',
70 + 'posts_per_page' => 100,
71 + 'post_parent' => $post->ID
72 + ));
73 +
74 + if ($attachments)
75 + {
76 + $content_l .= '<div style="width:100%;float:left;margin:10px 0 10px 0;"><h3>' . get_option('wpatt_option_localization') . '</h3>
77 + <style>
78 + ul.post-attachments{list-style:none;margin:0;}
79 + 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)}
80 + .post-attachment.mime-applicationzip{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-zipper.png)}
81 + .post-attachment.mime-applicationpdf{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-pdf.png)}
82 + .post-attachment.mime-applicationvnd-ms-excel{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-excel.png)}
83 + .post-attachment.mime-applicationvnd-openxmlformats-officedocument-spreadsheetml-sheet{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-excel.png)}
84 + .post-attachment.mime-applicationmsword{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-word.png)}
85 + .post-attachment.mime-applicationvnd-openxmlformats-officedocument-wordprocessingml-document{background-image:url(' . plugin_dir_url(__FILE__) . 'icons/document-word.png)}
86 + </style><ul class="post-attachments">';
87 +
88 + foreach ($attachments as $attachment)
89 + {
90 +
91 + $wpatt_option_includeimages_get = get_option('wpatt_option_includeimages');
92 + if ($wpatt_option_includeimages_get == '1') {
93 + } else if ( wp_attachment_is_image( $attachment->ID ) ) {
94 + continue;
95 + }
96 + $somethingtoshow = 1;
97 +
98 + $class = "post-attachment mime-" . sanitize_title($attachment->post_mime_type);
99 +
100 + $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)));
101 +
102 +
103 + $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
104 +
105 + if ($wpatt_option_showdate_get == '1')
106 + {
107 +
108 + $wpatt_date = new DateTime($attachment->post_date);
109 +
110 + $content_l .= '<div style="float:right;">' . $wpatt_date->format('d.m.Y') . '</div>';
111 +
112 + }
113 +
114 + $content_l .= ')</li>';
115 +
116 + }
117 + $content_l .= '</ul></div>';
118 +
119 + }
120 + if ($somethingtoshow == 1) {
121 + $content .= $content_l;
122 + }
123 + return $content;
124 + }
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 + $value = __('Attachments','wp-attachments');
149 + update_option('wpatt_option_localization', $value);
150 + }
151 + }
152 +
153 +add_action('admin_menu', 'wpatt_plugin_menu');
154 +
155 +function wpatt_plugin_menu(){
156 + add_options_page('WP Attachments - Settings', 'WP Attachments', 'manage_options', 'wpatt-option-page', 'wpatt_plugin_options');
157 +}
158 +
159 +
160 +?>