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