1 | <?php |
---|
2 | /** |
---|
3 | * WordPress Administration Media API. |
---|
4 | * |
---|
5 | * @package WordPress |
---|
6 | * @subpackage Administration |
---|
7 | */ |
---|
8 | |
---|
9 | /** |
---|
10 | * {@internal Missing Short Description}} |
---|
11 | * |
---|
12 | * @since unknown |
---|
13 | * |
---|
14 | * @return unknown |
---|
15 | */ |
---|
16 | function media_upload_tabs() { |
---|
17 | $_default_tabs = array( |
---|
18 | 'type' => __('From Computer'), // handler action suffix => tab text |
---|
19 | 'type_url' => __('From URL'), |
---|
20 | 'gallery' => __('Gallery'), |
---|
21 | 'library' => __('Media Library') |
---|
22 | ); |
---|
23 | |
---|
24 | return apply_filters('media_upload_tabs', $_default_tabs); |
---|
25 | } |
---|
26 | |
---|
27 | /** |
---|
28 | * {@internal Missing Short Description}} |
---|
29 | * |
---|
30 | * @since unknown |
---|
31 | * |
---|
32 | * @param unknown_type $tabs |
---|
33 | * @return unknown |
---|
34 | */ |
---|
35 | function update_gallery_tab($tabs) { |
---|
36 | global $wpdb; |
---|
37 | |
---|
38 | if ( !isset($_REQUEST['post_id']) ) { |
---|
39 | unset($tabs['gallery']); |
---|
40 | return $tabs; |
---|
41 | } |
---|
42 | |
---|
43 | $post_id = intval($_REQUEST['post_id']); |
---|
44 | |
---|
45 | if ( $post_id ) |
---|
46 | $attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) ); |
---|
47 | |
---|
48 | if ( empty($attachments) ) { |
---|
49 | unset($tabs['gallery']); |
---|
50 | return $tabs; |
---|
51 | } |
---|
52 | |
---|
53 | $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>"); |
---|
54 | |
---|
55 | return $tabs; |
---|
56 | } |
---|
57 | add_filter('media_upload_tabs', 'update_gallery_tab'); |
---|
58 | |
---|
59 | /** |
---|
60 | * {@internal Missing Short Description}} |
---|
61 | * |
---|
62 | * @since unknown |
---|
63 | */ |
---|
64 | function the_media_upload_tabs() { |
---|
65 | global $redir_tab; |
---|
66 | $tabs = media_upload_tabs(); |
---|
67 | |
---|
68 | if ( !empty($tabs) ) { |
---|
69 | echo "<ul id='sidemenu'>\n"; |
---|
70 | if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) ) |
---|
71 | $current = $redir_tab; |
---|
72 | elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) ) |
---|
73 | $current = $_GET['tab']; |
---|
74 | else |
---|
75 | $current = apply_filters('media_upload_default_tab', 'type'); |
---|
76 | |
---|
77 | foreach ( $tabs as $callback => $text ) { |
---|
78 | $class = ''; |
---|
79 | if ( $current == $callback ) |
---|
80 | $class = " class='current'"; |
---|
81 | $href = add_query_arg(array('tab'=>$callback, 's'=>false, 'paged'=>false, 'post_mime_type'=>false, 'm'=>false)); |
---|
82 | $link = "<a href='" . esc_url($href) . "'$class>$text</a>"; |
---|
83 | echo "\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n"; |
---|
84 | } |
---|
85 | echo "</ul>\n"; |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * {@internal Missing Short Description}} |
---|
91 | * |
---|
92 | * @since unknown |
---|
93 | * |
---|
94 | * @param unknown_type $id |
---|
95 | * @param unknown_type $alt |
---|
96 | * @param unknown_type $title |
---|
97 | * @param unknown_type $align |
---|
98 | * @param unknown_type $url |
---|
99 | * @param unknown_type $rel |
---|
100 | * @param unknown_type $size |
---|
101 | * @return unknown |
---|
102 | */ |
---|
103 | function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') { |
---|
104 | |
---|
105 | $html = get_image_tag($id, $alt, $title, $align, $size); |
---|
106 | |
---|
107 | $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : ''; |
---|
108 | |
---|
109 | if ( $url ) |
---|
110 | $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>"; |
---|
111 | |
---|
112 | $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt ); |
---|
113 | |
---|
114 | return $html; |
---|
115 | } |
---|
116 | |
---|
117 | /** |
---|
118 | * {@internal Missing Short Description}} |
---|
119 | * |
---|
120 | * @since unknown |
---|
121 | * |
---|
122 | * @param unknown_type $html |
---|
123 | * @param unknown_type $id |
---|
124 | * @param unknown_type $alt |
---|
125 | * @param unknown_type $title |
---|
126 | * @param unknown_type $align |
---|
127 | * @param unknown_type $url |
---|
128 | * @param unknown_type $size |
---|
129 | * @return unknown |
---|
130 | */ |
---|
131 | function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) { |
---|
132 | |
---|
133 | if ( empty($caption) || apply_filters( 'disable_captions', '' ) ) |
---|
134 | return $html; |
---|
135 | |
---|
136 | $id = ( 0 < (int) $id ) ? 'attachment_' . $id : ''; |
---|
137 | |
---|
138 | if ( ! preg_match( '/width="([0-9]+)/', $html, $matches ) ) |
---|
139 | return $html; |
---|
140 | |
---|
141 | $width = $matches[1]; |
---|
142 | |
---|
143 | $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html ); |
---|
144 | if ( empty($align) ) |
---|
145 | $align = 'none'; |
---|
146 | |
---|
147 | $shcode = '[caption id="' . $id . '" align="align' . $align |
---|
148 | . '" width="' . $width . '" caption="' . addslashes($caption) . '"]' . $html . '[/caption]'; |
---|
149 | |
---|
150 | return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); |
---|
151 | } |
---|
152 | add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 ); |
---|
153 | |
---|
154 | /** |
---|
155 | * {@internal Missing Short Description}} |
---|
156 | * |
---|
157 | * @since unknown |
---|
158 | * |
---|
159 | * @param unknown_type $html |
---|
160 | */ |
---|
161 | function media_send_to_editor($html) { |
---|
162 | ?> |
---|
163 | <script type="text/javascript"> |
---|
164 | /* <![CDATA[ */ |
---|
165 | var win = window.dialogArguments || opener || parent || top; |
---|
166 | win.send_to_editor('<?php echo addslashes($html); ?>'); |
---|
167 | /* ]]> */ |
---|
168 | </script> |
---|
169 | <?php |
---|
170 | exit; |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | * {@internal Missing Short Description}} |
---|
175 | * |
---|
176 | * This handles the file upload POST itself, creating the attachment post. |
---|
177 | * |
---|
178 | * @since unknown |
---|
179 | * |
---|
180 | * @param string $file_id Index into the {@link $_FILES} array of the upload |
---|
181 | * @param int $post_id The post ID the media is associated with |
---|
182 | * @param array $post_data allows you to overwrite some of the attachment |
---|
183 | * @param array $overrides allows you to override the {@link wp_handle_upload()} behavior |
---|
184 | * @return int the ID of the attachment |
---|
185 | */ |
---|
186 | function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) { |
---|
187 | |
---|
188 | $time = current_time('mysql'); |
---|
189 | if ( $post = get_post($post_id) ) { |
---|
190 | if ( substr( $post->post_date, 0, 4 ) > 0 ) |
---|
191 | $time = $post->post_date; |
---|
192 | } |
---|
193 | |
---|
194 | $name = $_FILES[$file_id]['name']; |
---|
195 | $file = wp_handle_upload($_FILES[$file_id], $overrides, $time); |
---|
196 | |
---|
197 | if ( isset($file['error']) ) |
---|
198 | return new WP_Error( 'upload_error', $file['error'] ); |
---|
199 | |
---|
200 | $name_parts = pathinfo($name); |
---|
201 | $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) ); |
---|
202 | |
---|
203 | $url = $file['url']; |
---|
204 | $type = $file['type']; |
---|
205 | $file = $file['file']; |
---|
206 | $title = $name; |
---|
207 | $content = ''; |
---|
208 | |
---|
209 | // use image exif/iptc data for title and caption defaults if possible |
---|
210 | if ( $image_meta = @wp_read_image_metadata($file) ) { |
---|
211 | if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) |
---|
212 | $title = $image_meta['title']; |
---|
213 | if ( trim( $image_meta['caption'] ) ) |
---|
214 | $content = $image_meta['caption']; |
---|
215 | } |
---|
216 | |
---|
217 | // Construct the attachment array |
---|
218 | $attachment = array_merge( array( |
---|
219 | 'post_mime_type' => $type, |
---|
220 | 'guid' => $url, |
---|
221 | 'post_parent' => $post_id, |
---|
222 | 'post_title' => $title, |
---|
223 | 'post_content' => $content, |
---|
224 | ), $post_data ); |
---|
225 | |
---|
226 | // Save the data |
---|
227 | $id = wp_insert_attachment($attachment, $file, $post_id); |
---|
228 | if ( !is_wp_error($id) ) { |
---|
229 | wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
---|
230 | } |
---|
231 | |
---|
232 | return $id; |
---|
233 | |
---|
234 | } |
---|
235 | |
---|
236 | /** |
---|
237 | * {@internal Missing Short Description}} |
---|
238 | * |
---|
239 | * @since unknown |
---|
240 | * |
---|
241 | * @param unknown_type $file_array |
---|
242 | * @param unknown_type $post_id |
---|
243 | * @param unknown_type $desc |
---|
244 | * @param unknown_type $post_data |
---|
245 | * @return unknown |
---|
246 | */ |
---|
247 | function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { |
---|
248 | $overrides = array('test_form'=>false); |
---|
249 | |
---|
250 | $file = wp_handle_sideload($file_array, $overrides); |
---|
251 | if ( isset($file['error']) ) |
---|
252 | return new WP_Error( 'upload_error', $file['error'] ); |
---|
253 | |
---|
254 | $url = $file['url']; |
---|
255 | $type = $file['type']; |
---|
256 | $file = $file['file']; |
---|
257 | $title = preg_replace('/\.[^.]+$/', '', basename($file)); |
---|
258 | $content = ''; |
---|
259 | |
---|
260 | // use image exif/iptc data for title and caption defaults if possible |
---|
261 | if ( $image_meta = @wp_read_image_metadata($file) ) { |
---|
262 | if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) |
---|
263 | $title = $image_meta['title']; |
---|
264 | if ( trim( $image_meta['caption'] ) ) |
---|
265 | $content = $image_meta['caption']; |
---|
266 | } |
---|
267 | |
---|
268 | $title = @$desc; |
---|
269 | |
---|
270 | // Construct the attachment array |
---|
271 | $attachment = array_merge( array( |
---|
272 | 'post_mime_type' => $type, |
---|
273 | 'guid' => $url, |
---|
274 | 'post_parent' => $post_id, |
---|
275 | 'post_title' => $title, |
---|
276 | 'post_content' => $content, |
---|
277 | ), $post_data ); |
---|
278 | |
---|
279 | // Save the attachment metadata |
---|
280 | $id = wp_insert_attachment($attachment, $file, $post_id); |
---|
281 | if ( !is_wp_error($id) ) { |
---|
282 | wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
---|
283 | return $url; |
---|
284 | } |
---|
285 | return $id; |
---|
286 | } |
---|
287 | |
---|
288 | /** |
---|
289 | * {@internal Missing Short Description}} |
---|
290 | * |
---|
291 | * Wrap iframe content (produced by $content_func) in a doctype, html head/body |
---|
292 | * etc any additional function args will be passed to content_func. |
---|
293 | * |
---|
294 | * @since unknown |
---|
295 | * |
---|
296 | * @param unknown_type $content_func |
---|
297 | */ |
---|
298 | function wp_iframe($content_func /* ... */) { |
---|
299 | ?> |
---|
300 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
301 | <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>> |
---|
302 | <head> |
---|
303 | <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> |
---|
304 | <title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?></title> |
---|
305 | <?php |
---|
306 | wp_enqueue_style( 'global' ); |
---|
307 | wp_enqueue_style( 'wp-admin' ); |
---|
308 | wp_enqueue_style( 'colors' ); |
---|
309 | // Check callback name for 'media' |
---|
310 | if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) || 0 === strpos( $content_func, 'media' ) ) |
---|
311 | wp_enqueue_style( 'media' ); |
---|
312 | wp_enqueue_style( 'ie' ); |
---|
313 | ?> |
---|
314 | <script type="text/javascript"> |
---|
315 | //<![CDATA[ |
---|
316 | addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; |
---|
317 | var userSettings = {'url':'<?php echo SITECOOKIEPATH; ?>','uid':'<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>','time':'<?php echo time(); ?>'}; |
---|
318 | var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup'; |
---|
319 | //]]> |
---|
320 | </script> |
---|
321 | <?php |
---|
322 | do_action('admin_enqueue_scripts', 'media-upload-popup'); |
---|
323 | do_action('admin_print_styles-media-upload-popup'); |
---|
324 | do_action('admin_print_styles'); |
---|
325 | do_action('admin_print_scripts-media-upload-popup'); |
---|
326 | do_action('admin_print_scripts'); |
---|
327 | do_action('admin_head-media-upload-popup'); |
---|
328 | do_action('admin_head'); |
---|
329 | |
---|
330 | if ( is_string($content_func) ) |
---|
331 | do_action( "admin_head_{$content_func}" ); |
---|
332 | ?> |
---|
333 | </head> |
---|
334 | <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>> |
---|
335 | <?php |
---|
336 | $args = func_get_args(); |
---|
337 | $args = array_slice($args, 1); |
---|
338 | call_user_func_array($content_func, $args); |
---|
339 | |
---|
340 | do_action('admin_print_footer_scripts'); |
---|
341 | ?> |
---|
342 | <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script> |
---|
343 | </body> |
---|
344 | </html> |
---|
345 | <?php |
---|
346 | } |
---|
347 | |
---|
348 | /** |
---|
349 | * {@internal Missing Short Description}} |
---|
350 | * |
---|
351 | * @since unknown |
---|
352 | */ |
---|
353 | function media_buttons() { |
---|
354 | $do_image = $do_audio = $do_video = true; |
---|
355 | if ( is_multisite() ) { |
---|
356 | $media_buttons = get_site_option( 'mu_media_buttons' ); |
---|
357 | if ( empty($media_buttons['image']) ) |
---|
358 | $do_image = false; |
---|
359 | if ( empty($media_buttons['audio']) ) |
---|
360 | $do_audio = false; |
---|
361 | if ( empty($media_buttons['video']) ) |
---|
362 | $do_video = false; |
---|
363 | } |
---|
364 | $out = ''; |
---|
365 | |
---|
366 | if ( $do_image ) |
---|
367 | $out .= _media_button(__('Add an Image'), 'images/media-button-image.gif?ver=20100531', 'image'); |
---|
368 | if ( $do_video ) |
---|
369 | $out .= _media_button(__('Add Video'), 'images/media-button-video.gif?ver=20100531', 'video'); |
---|
370 | if ( $do_audio ) |
---|
371 | $out .= _media_button(__('Add Audio'), 'images/media-button-music.gif?ver=20100531', 'audio'); |
---|
372 | |
---|
373 | $out .= _media_button(__('Add Media'), 'images/media-button-other.gif?ver=20100531', 'media'); |
---|
374 | |
---|
375 | $context = apply_filters('media_buttons_context', __('Upload/Insert %s')); |
---|
376 | |
---|
377 | printf($context, $out); |
---|
378 | } |
---|
379 | add_action( 'media_buttons', 'media_buttons' ); |
---|
380 | |
---|
381 | function _media_button($title, $icon, $type) { |
---|
382 | return "<a href='" . esc_url( get_upload_iframe_src($type) ) . "' id='add_$type' class='thickbox' title='$title'><img src='" . esc_url( admin_url( $icon ) ) . "' alt='$title' /></a>"; |
---|
383 | } |
---|
384 | |
---|
385 | function get_upload_iframe_src($type) { |
---|
386 | global $post_ID, $temp_ID; |
---|
387 | $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID); |
---|
388 | $upload_iframe_src = add_query_arg('post_id', $uploading_iframe_ID, 'media-upload.php'); |
---|
389 | |
---|
390 | if ( 'media' != $type ) |
---|
391 | $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); |
---|
392 | $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src); |
---|
393 | |
---|
394 | return add_query_arg('TB_iframe', true, $upload_iframe_src); |
---|
395 | } |
---|
396 | |
---|
397 | /** |
---|
398 | * {@internal Missing Short Description}} |
---|
399 | * |
---|
400 | * @since unknown |
---|
401 | * |
---|
402 | * @return unknown |
---|
403 | */ |
---|
404 | function media_upload_form_handler() { |
---|
405 | check_admin_referer('media-form'); |
---|
406 | |
---|
407 | $errors = null; |
---|
408 | |
---|
409 | if ( isset($_POST['send']) ) { |
---|
410 | $keys = array_keys($_POST['send']); |
---|
411 | $send_id = (int) array_shift($keys); |
---|
412 | } |
---|
413 | |
---|
414 | if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) { |
---|
415 | $post = $_post = get_post($attachment_id, ARRAY_A); |
---|
416 | if ( isset($attachment['post_content']) ) |
---|
417 | $post['post_content'] = $attachment['post_content']; |
---|
418 | if ( isset($attachment['post_title']) ) |
---|
419 | $post['post_title'] = $attachment['post_title']; |
---|
420 | if ( isset($attachment['post_excerpt']) ) |
---|
421 | $post['post_excerpt'] = $attachment['post_excerpt']; |
---|
422 | if ( isset($attachment['menu_order']) ) |
---|
423 | $post['menu_order'] = $attachment['menu_order']; |
---|
424 | |
---|
425 | if ( isset($send_id) && $attachment_id == $send_id ) { |
---|
426 | if ( isset($attachment['post_parent']) ) |
---|
427 | $post['post_parent'] = $attachment['post_parent']; |
---|
428 | } |
---|
429 | |
---|
430 | $post = apply_filters('attachment_fields_to_save', $post, $attachment); |
---|
431 | |
---|
432 | if ( isset($attachment['image_alt']) ) { |
---|
433 | $image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); |
---|
434 | if ( $image_alt != stripslashes($attachment['image_alt']) ) { |
---|
435 | $image_alt = wp_strip_all_tags( stripslashes($attachment['image_alt']), true ); |
---|
436 | // update_meta expects slashed |
---|
437 | update_post_meta( $attachment_id, '_wp_attachment_image_alt', addslashes($image_alt) ); |
---|
438 | } |
---|
439 | } |
---|
440 | |
---|
441 | if ( isset($post['errors']) ) { |
---|
442 | $errors[$attachment_id] = $post['errors']; |
---|
443 | unset($post['errors']); |
---|
444 | } |
---|
445 | |
---|
446 | if ( $post != $_post ) |
---|
447 | wp_update_post($post); |
---|
448 | |
---|
449 | foreach ( get_attachment_taxonomies($post) as $t ) { |
---|
450 | if ( isset($attachment[$t]) ) |
---|
451 | wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false); |
---|
452 | } |
---|
453 | } |
---|
454 | |
---|
455 | if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?> |
---|
456 | <script type="text/javascript"> |
---|
457 | /* <![CDATA[ */ |
---|
458 | var win = window.dialogArguments || opener || parent || top; |
---|
459 | win.tb_remove(); |
---|
460 | /* ]]> */ |
---|
461 | </script> |
---|
462 | <?php |
---|
463 | exit; |
---|
464 | } |
---|
465 | |
---|
466 | if ( isset($send_id) ) { |
---|
467 | $attachment = stripslashes_deep( $_POST['attachments'][$send_id] ); |
---|
468 | |
---|
469 | $html = $attachment['post_title']; |
---|
470 | if ( !empty($attachment['url']) ) { |
---|
471 | $rel = ''; |
---|
472 | if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] ) |
---|
473 | $rel = " rel='attachment wp-att-" . esc_attr($send_id) . "'"; |
---|
474 | $html = "<a href='{$attachment['url']}'$rel>$html</a>"; |
---|
475 | } |
---|
476 | |
---|
477 | $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment); |
---|
478 | return media_send_to_editor($html); |
---|
479 | } |
---|
480 | |
---|
481 | return $errors; |
---|
482 | } |
---|
483 | |
---|
484 | /** |
---|
485 | * {@internal Missing Short Description}} |
---|
486 | * |
---|
487 | * @since unknown |
---|
488 | * |
---|
489 | * @return unknown |
---|
490 | */ |
---|
491 | function media_upload_image() { |
---|
492 | $errors = array(); |
---|
493 | $id = 0; |
---|
494 | |
---|
495 | if ( isset($_POST['html-upload']) && !empty($_FILES) ) { |
---|
496 | // Upload File button was clicked |
---|
497 | $id = media_handle_upload('async-upload', $_REQUEST['post_id']); |
---|
498 | unset($_FILES); |
---|
499 | if ( is_wp_error($id) ) { |
---|
500 | $errors['upload_error'] = $id; |
---|
501 | $id = false; |
---|
502 | } |
---|
503 | } |
---|
504 | |
---|
505 | if ( !empty($_POST['insertonlybutton']) ) { |
---|
506 | $alt = $align = ''; |
---|
507 | |
---|
508 | $src = $_POST['insertonly']['src']; |
---|
509 | if ( !empty($src) && !strpos($src, '://') ) |
---|
510 | $src = "http://$src"; |
---|
511 | $alt = esc_attr($_POST['insertonly']['alt']); |
---|
512 | if ( isset($_POST['insertonly']['align']) ) { |
---|
513 | $align = esc_attr($_POST['insertonly']['align']); |
---|
514 | $class = " class='align$align'"; |
---|
515 | } |
---|
516 | if ( !empty($src) ) |
---|
517 | $html = "<img src='" . esc_url($src) . "' alt='$alt'$class />"; |
---|
518 | |
---|
519 | $html = apply_filters('image_send_to_editor_url', $html, esc_url_raw($src), $alt, $align); |
---|
520 | return media_send_to_editor($html); |
---|
521 | } |
---|
522 | |
---|
523 | if ( !empty($_POST) ) { |
---|
524 | $return = media_upload_form_handler(); |
---|
525 | |
---|
526 | if ( is_string($return) ) |
---|
527 | return $return; |
---|
528 | if ( is_array($return) ) |
---|
529 | $errors = $return; |
---|
530 | } |
---|
531 | |
---|
532 | if ( isset($_POST['save']) ) { |
---|
533 | $errors['upload_notice'] = __('Saved.'); |
---|
534 | return media_upload_gallery(); |
---|
535 | } |
---|
536 | |
---|
537 | if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) |
---|
538 | return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id ); |
---|
539 | |
---|
540 | return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); |
---|
541 | } |
---|
542 | |
---|
543 | /** |
---|
544 | * {@internal Missing Short Description}} |
---|
545 | * |
---|
546 | * @since unknown |
---|
547 | * |
---|
548 | * @param unknown_type $file |
---|
549 | * @param unknown_type $post_id |
---|
550 | * @param unknown_type $desc |
---|
551 | * @return unknown |
---|
552 | */ |
---|
553 | function media_sideload_image($file, $post_id, $desc = null) { |
---|
554 | if (!empty($file) ) { |
---|
555 | // Download file to temp location |
---|
556 | $tmp = download_url($file); |
---|
557 | |
---|
558 | // Set variables for storage |
---|
559 | // fix file filename for query strings |
---|
560 | preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches); |
---|
561 | $file_array['name'] = basename($matches[0]); |
---|
562 | $file_array['tmp_name'] = $tmp; |
---|
563 | |
---|
564 | // If error storing temporarily, unlink |
---|
565 | if ( is_wp_error($tmp) ) { |
---|
566 | @unlink($file_array['tmp_name']); |
---|
567 | $file_array['tmp_name'] = ''; |
---|
568 | } |
---|
569 | |
---|
570 | // do the validation and storage stuff |
---|
571 | $id = media_handle_sideload($file_array, $post_id, @$desc); |
---|
572 | $src = $id; |
---|
573 | |
---|
574 | // If error storing permanently, unlink |
---|
575 | if ( is_wp_error($id) ) { |
---|
576 | @unlink($file_array['tmp_name']); |
---|
577 | return $id; |
---|
578 | } |
---|
579 | } |
---|
580 | |
---|
581 | // Finally check to make sure the file has been saved, then return the html |
---|
582 | if ( !empty($src) ) { |
---|
583 | $alt = @$desc; |
---|
584 | $html = "<img src='$src' alt='$alt' />"; |
---|
585 | return $html; |
---|
586 | } |
---|
587 | } |
---|
588 | |
---|
589 | /** |
---|
590 | * {@internal Missing Short Description}} |
---|
591 | * |
---|
592 | * @since unknown |
---|
593 | * |
---|
594 | * @return unknown |
---|
595 | */ |
---|
596 | function media_upload_audio() { |
---|
597 | $errors = array(); |
---|
598 | $id = 0; |
---|
599 | |
---|
600 | if ( isset($_POST['html-upload']) && !empty($_FILES) ) { |
---|
601 | // Upload File button was clicked |
---|
602 | $id = media_handle_upload('async-upload', $_REQUEST['post_id']); |
---|
603 | unset($_FILES); |
---|
604 | if ( is_wp_error($id) ) { |
---|
605 | $errors['upload_error'] = $id; |
---|
606 | $id = false; |
---|
607 | } |
---|
608 | } |
---|
609 | |
---|
610 | if ( !empty($_POST['insertonlybutton']) ) { |
---|
611 | $href = $_POST['insertonly']['href']; |
---|
612 | if ( !empty($href) && !strpos($href, '://') ) |
---|
613 | $href = "http://$href"; |
---|
614 | |
---|
615 | $title = esc_attr($_POST['insertonly']['title']); |
---|
616 | if ( empty($title) ) |
---|
617 | $title = esc_attr( basename($href) ); |
---|
618 | |
---|
619 | if ( !empty($title) && !empty($href) ) |
---|
620 | $html = "<a href='" . esc_url($href) . "' >$title</a>"; |
---|
621 | |
---|
622 | $html = apply_filters('audio_send_to_editor_url', $html, $href, $title); |
---|
623 | |
---|
624 | return media_send_to_editor($html); |
---|
625 | } |
---|
626 | |
---|
627 | if ( !empty($_POST) ) { |
---|
628 | $return = media_upload_form_handler(); |
---|
629 | |
---|
630 | if ( is_string($return) ) |
---|
631 | return $return; |
---|
632 | if ( is_array($return) ) |
---|
633 | $errors = $return; |
---|
634 | } |
---|
635 | |
---|
636 | if ( isset($_POST['save']) ) { |
---|
637 | $errors['upload_notice'] = __('Saved.'); |
---|
638 | return media_upload_gallery(); |
---|
639 | } |
---|
640 | |
---|
641 | if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) |
---|
642 | return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id ); |
---|
643 | |
---|
644 | return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id ); |
---|
645 | } |
---|
646 | |
---|
647 | /** |
---|
648 | * {@internal Missing Short Description}} |
---|
649 | * |
---|
650 | * @since unknown |
---|
651 | * |
---|
652 | * @return unknown |
---|
653 | */ |
---|
654 | function media_upload_video() { |
---|
655 | $errors = array(); |
---|
656 | $id = 0; |
---|
657 | |
---|
658 | if ( isset($_POST['html-upload']) && !empty($_FILES) ) { |
---|
659 | // Upload File button was clicked |
---|
660 | $id = media_handle_upload('async-upload', $_REQUEST['post_id']); |
---|
661 | unset($_FILES); |
---|
662 | if ( is_wp_error($id) ) { |
---|
663 | $errors['upload_error'] = $id; |
---|
664 | $id = false; |
---|
665 | } |
---|
666 | } |
---|
667 | |
---|
668 | if ( !empty($_POST['insertonlybutton']) ) { |
---|
669 | $href = $_POST['insertonly']['href']; |
---|
670 | if ( !empty($href) && !strpos($href, '://') ) |
---|
671 | $href = "http://$href"; |
---|
672 | |
---|
673 | $title = esc_attr($_POST['insertonly']['title']); |
---|
674 | if ( empty($title) ) |
---|
675 | $title = esc_attr( basename($href) ); |
---|
676 | |
---|
677 | if ( !empty($title) && !empty($href) ) |
---|
678 | $html = "<a href='" . esc_url($href) . "' >$title</a>"; |
---|
679 | |
---|
680 | $html = apply_filters('video_send_to_editor_url', $html, $href, $title); |
---|
681 | |
---|
682 | return media_send_to_editor($html); |
---|
683 | } |
---|
684 | |
---|
685 | if ( !empty($_POST) ) { |
---|
686 | $return = media_upload_form_handler(); |
---|
687 | |
---|
688 | if ( is_string($return) ) |
---|
689 | return $return; |
---|
690 | if ( is_array($return) ) |
---|
691 | $errors = $return; |
---|
692 | } |
---|
693 | |
---|
694 | if ( isset($_POST['save']) ) { |
---|
695 | $errors['upload_notice'] = __('Saved.'); |
---|
696 | return media_upload_gallery(); |
---|
697 | } |
---|
698 | |
---|
699 | if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) |
---|
700 | return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id ); |
---|
701 | |
---|
702 | return wp_iframe( 'media_upload_type_form', 'video', $errors, $id ); |
---|
703 | } |
---|
704 | |
---|
705 | /** |
---|
706 | * {@internal Missing Short Description}} |
---|
707 | * |
---|
708 | * @since unknown |
---|
709 | * |
---|
710 | * @return unknown |
---|
711 | */ |
---|
712 | function media_upload_file() { |
---|
713 | $errors = array(); |
---|
714 | $id = 0; |
---|
715 | |
---|
716 | if ( isset($_POST['html-upload']) && !empty($_FILES) ) { |
---|
717 | // Upload File button was clicked |
---|
718 | $id = media_handle_upload('async-upload', $_REQUEST['post_id']); |
---|
719 | unset($_FILES); |
---|
720 | if ( is_wp_error($id) ) { |
---|
721 | $errors['upload_error'] = $id; |
---|
722 | $id = false; |
---|
723 | } |
---|
724 | } |
---|
725 | |
---|
726 | if ( !empty($_POST['insertonlybutton']) ) { |
---|
727 | $href = $_POST['insertonly']['href']; |
---|
728 | if ( !empty($href) && !strpos($href, '://') ) |
---|
729 | $href = "http://$href"; |
---|
730 | |
---|
731 | $title = esc_attr($_POST['insertonly']['title']); |
---|
732 | if ( empty($title) ) |
---|
733 | $title = basename($href); |
---|
734 | if ( !empty($title) && !empty($href) ) |
---|
735 | $html = "<a href='" . esc_url($href) . "' >$title</a>"; |
---|
736 | $html = apply_filters('file_send_to_editor_url', $html, esc_url_raw($href), $title); |
---|
737 | return media_send_to_editor($html); |
---|
738 | } |
---|
739 | |
---|
740 | if ( !empty($_POST) ) { |
---|
741 | $return = media_upload_form_handler(); |
---|
742 | |
---|
743 | if ( is_string($return) ) |
---|
744 | return $return; |
---|
745 | if ( is_array($return) ) |
---|
746 | $errors = $return; |
---|
747 | } |
---|
748 | |
---|
749 | if ( isset($_POST['save']) ) { |
---|
750 | $errors['upload_notice'] = __('Saved.'); |
---|
751 | return media_upload_gallery(); |
---|
752 | } |
---|
753 | |
---|
754 | if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) |
---|
755 | return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id ); |
---|
756 | |
---|
757 | return wp_iframe( 'media_upload_type_form', 'file', $errors, $id ); |
---|
758 | } |
---|
759 | |
---|
760 | /** |
---|
761 | * {@internal Missing Short Description}} |
---|
762 | * |
---|
763 | * @since unknown |
---|
764 | * |
---|
765 | * @return unknown |
---|
766 | */ |
---|
767 | function media_upload_gallery() { |
---|
768 | $errors = array(); |
---|
769 | |
---|
770 | if ( !empty($_POST) ) { |
---|
771 | $return = media_upload_form_handler(); |
---|
772 | |
---|
773 | if ( is_string($return) ) |
---|
774 | return $return; |
---|
775 | if ( is_array($return) ) |
---|
776 | $errors = $return; |
---|
777 | } |
---|
778 | |
---|
779 | wp_enqueue_script('admin-gallery'); |
---|
780 | return wp_iframe( 'media_upload_gallery_form', $errors ); |
---|
781 | } |
---|
782 | |
---|
783 | /** |
---|
784 | * {@internal Missing Short Description}} |
---|
785 | * |
---|
786 | * @since unknown |
---|
787 | * |
---|
788 | * @return unknown |
---|
789 | */ |
---|
790 | function media_upload_library() { |
---|
791 | $errors = array(); |
---|
792 | if ( !empty($_POST) ) { |
---|
793 | $return = media_upload_form_handler(); |
---|
794 | |
---|
795 | if ( is_string($return) ) |
---|
796 | return $return; |
---|
797 | if ( is_array($return) ) |
---|
798 | $errors = $return; |
---|
799 | } |
---|
800 | |
---|
801 | return wp_iframe( 'media_upload_library_form', $errors ); |
---|
802 | } |
---|
803 | |
---|
804 | /** |
---|
805 | * Retrieve HTML for the image alignment radio buttons with the specified one checked. |
---|
806 | * |
---|
807 | * @since unknown |
---|
808 | * |
---|
809 | * @param unknown_type $post |
---|
810 | * @param unknown_type $checked |
---|
811 | * @return unknown |
---|
812 | */ |
---|
813 | function image_align_input_fields( $post, $checked = '' ) { |
---|
814 | |
---|
815 | if ( empty($checked) ) |
---|
816 | $checked = get_user_setting('align', 'none'); |
---|
817 | |
---|
818 | $alignments = array('none' => __('None'), 'left' => __('Left'), 'center' => __('Center'), 'right' => __('Right')); |
---|
819 | if ( !array_key_exists( (string) $checked, $alignments ) ) |
---|
820 | $checked = 'none'; |
---|
821 | |
---|
822 | $out = array(); |
---|
823 | foreach ( $alignments as $name => $label ) { |
---|
824 | $name = esc_attr($name); |
---|
825 | $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'". |
---|
826 | ( $checked == $name ? " checked='checked'" : "" ) . |
---|
827 | " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>"; |
---|
828 | } |
---|
829 | return join("\n", $out); |
---|
830 | } |
---|
831 | |
---|
832 | /** |
---|
833 | * Retrieve HTML for the size radio buttons with the specified one checked. |
---|
834 | * |
---|
835 | * @since unknown |
---|
836 | * |
---|
837 | * @param unknown_type $post |
---|
838 | * @param unknown_type $checked |
---|
839 | * @return unknown |
---|
840 | */ |
---|
841 | function image_size_input_fields( $post, $check = '' ) { |
---|
842 | |
---|
843 | // get a list of the actual pixel dimensions of each possible intermediate version of this image |
---|
844 | $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')); |
---|
845 | |
---|
846 | global $_wp_additional_image_sizes; |
---|
847 | foreach($_wp_additional_image_sizes as $size_name => $size_name_attr){ |
---|
848 | $size_names[$size_name] = __($size_name_attr['label']); |
---|
849 | } |
---|
850 | $size_names = apply_filters('image_size_names', $size_names); |
---|
851 | |
---|
852 | if ( empty($check) ) |
---|
853 | $check = get_user_setting('imgsize', 'medium'); |
---|
854 | |
---|
855 | foreach ( $size_names as $size => $label ) { |
---|
856 | $downsize = image_downsize($post->ID, $size); |
---|
857 | $checked = ''; |
---|
858 | |
---|
859 | // is this size selectable? |
---|
860 | $enabled = ( $downsize[3] || 'full' == $size ); |
---|
861 | $css_id = "image-size-{$size}-{$post->ID}"; |
---|
862 | // if this size is the default but that's not available, don't select it |
---|
863 | if ( $size == $check ) { |
---|
864 | if ( $enabled ) |
---|
865 | $checked = " checked='checked'"; |
---|
866 | else |
---|
867 | $check = ''; |
---|
868 | } elseif ( !$check && $enabled && 'thumbnail' != $size ) { |
---|
869 | // if $check is not enabled, default to the first available size that's bigger than a thumbnail |
---|
870 | $check = $size; |
---|
871 | $checked = " checked='checked'"; |
---|
872 | } |
---|
873 | |
---|
874 | $html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />"; |
---|
875 | |
---|
876 | $html .= "<label for='{$css_id}'>$label</label>"; |
---|
877 | // only show the dimensions if that choice is available |
---|
878 | if ( $enabled ) |
---|
879 | $html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d × %d)", $downsize[1], $downsize[2] ). "</label>"; |
---|
880 | |
---|
881 | $html .= '</div>'; |
---|
882 | |
---|
883 | $out[] = $html; |
---|
884 | } |
---|
885 | |
---|
886 | return array( |
---|
887 | 'label' => __('Size'), |
---|
888 | 'input' => 'html', |
---|
889 | 'html' => join("\n", $out), |
---|
890 | ); |
---|
891 | } |
---|
892 | |
---|
893 | /** |
---|
894 | * Retrieve HTML for the Link URL buttons with the default link type as specified. |
---|
895 | * |
---|
896 | * @since unknown |
---|
897 | * |
---|
898 | * @param unknown_type $post |
---|
899 | * @param unknown_type $url_type |
---|
900 | * @return unknown |
---|
901 | */ |
---|
902 | function image_link_input_fields($post, $url_type = '') { |
---|
903 | |
---|
904 | $file = wp_get_attachment_url($post->ID); |
---|
905 | $link = get_attachment_link($post->ID); |
---|
906 | |
---|
907 | if ( empty($url_type) ) |
---|
908 | $url_type = get_user_setting('urlbutton', 'post'); |
---|
909 | |
---|
910 | $url = ''; |
---|
911 | if ( $url_type == 'file' ) |
---|
912 | $url = $file; |
---|
913 | elseif ( $url_type == 'post' ) |
---|
914 | $url = $link; |
---|
915 | |
---|
916 | return " |
---|
917 | <input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br /> |
---|
918 | <button type='button' class='button urlnone' title=''>" . __('None') . "</button> |
---|
919 | <button type='button' class='button urlfile' title='" . esc_attr($file) . "'>" . __('File URL') . "</button> |
---|
920 | <button type='button' class='button urlpost' title='" . esc_attr($link) . "'>" . __('Post URL') . "</button> |
---|
921 | "; |
---|
922 | } |
---|
923 | |
---|
924 | /** |
---|
925 | * {@internal Missing Short Description}} |
---|
926 | * |
---|
927 | * @since unknown |
---|
928 | * |
---|
929 | * @param unknown_type $form_fields |
---|
930 | * @param unknown_type $post |
---|
931 | * @return unknown |
---|
932 | */ |
---|
933 | function image_attachment_fields_to_edit($form_fields, $post) { |
---|
934 | if ( substr($post->post_mime_type, 0, 5) == 'image' ) { |
---|
935 | $alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true); |
---|
936 | if ( empty($alt) ) |
---|
937 | $alt = ''; |
---|
938 | |
---|
939 | $form_fields['post_title']['required'] = true; |
---|
940 | |
---|
941 | $form_fields['image_alt'] = array( |
---|
942 | 'value' => $alt, |
---|
943 | 'label' => __('Alternate Text'), |
---|
944 | 'helps' => __('Alt text for the image, e.g. “The Mona Lisa”') |
---|
945 | ); |
---|
946 | |
---|
947 | $form_fields['align'] = array( |
---|
948 | 'label' => __('Alignment'), |
---|
949 | 'input' => 'html', |
---|
950 | 'html' => image_align_input_fields($post, get_option('image_default_align')), |
---|
951 | ); |
---|
952 | |
---|
953 | $form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size', 'medium') ); |
---|
954 | |
---|
955 | } else { |
---|
956 | unset( $form_fields['image_alt'] ); |
---|
957 | } |
---|
958 | return $form_fields; |
---|
959 | } |
---|
960 | |
---|
961 | add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2); |
---|
962 | |
---|
963 | /** |
---|
964 | * {@internal Missing Short Description}} |
---|
965 | * |
---|
966 | * @since unknown |
---|
967 | * |
---|
968 | * @param unknown_type $form_fields |
---|
969 | * @param unknown_type $post |
---|
970 | * @return unknown |
---|
971 | */ |
---|
972 | function media_single_attachment_fields_to_edit( $form_fields, $post ) { |
---|
973 | unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']); |
---|
974 | return $form_fields; |
---|
975 | } |
---|
976 | |
---|
977 | function media_post_single_attachment_fields_to_edit( $form_fields, $post ) { |
---|
978 | unset($form_fields['image_url']); |
---|
979 | return $form_fields; |
---|
980 | } |
---|
981 | |
---|
982 | /** |
---|
983 | * {@internal Missing Short Description}} |
---|
984 | * |
---|
985 | * @since unknown |
---|
986 | * |
---|
987 | * @param unknown_type $post |
---|
988 | * @param unknown_type $attachment |
---|
989 | * @return unknown |
---|
990 | */ |
---|
991 | function image_attachment_fields_to_save($post, $attachment) { |
---|
992 | if ( substr($post['post_mime_type'], 0, 5) == 'image' ) { |
---|
993 | if ( strlen(trim($post['post_title'])) == 0 ) { |
---|
994 | $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid'])); |
---|
995 | $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.'); |
---|
996 | } |
---|
997 | } |
---|
998 | |
---|
999 | return $post; |
---|
1000 | } |
---|
1001 | |
---|
1002 | add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2); |
---|
1003 | |
---|
1004 | /** |
---|
1005 | * {@internal Missing Short Description}} |
---|
1006 | * |
---|
1007 | * @since unknown |
---|
1008 | * |
---|
1009 | * @param unknown_type $html |
---|
1010 | * @param unknown_type $attachment_id |
---|
1011 | * @param unknown_type $attachment |
---|
1012 | * @return unknown |
---|
1013 | */ |
---|
1014 | function image_media_send_to_editor($html, $attachment_id, $attachment) { |
---|
1015 | $post =& get_post($attachment_id); |
---|
1016 | if ( substr($post->post_mime_type, 0, 5) == 'image' ) { |
---|
1017 | $url = $attachment['url']; |
---|
1018 | $align = !empty($attachment['align']) ? $attachment['align'] : 'none'; |
---|
1019 | $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium'; |
---|
1020 | $alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : ''; |
---|
1021 | $rel = ( $url == get_attachment_link($attachment_id) ); |
---|
1022 | |
---|
1023 | return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt); |
---|
1024 | } |
---|
1025 | |
---|
1026 | return $html; |
---|
1027 | } |
---|
1028 | |
---|
1029 | add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3); |
---|
1030 | |
---|
1031 | /** |
---|
1032 | * {@internal Missing Short Description}} |
---|
1033 | * |
---|
1034 | * @since unknown |
---|
1035 | * |
---|
1036 | * @param unknown_type $post |
---|
1037 | * @param unknown_type $errors |
---|
1038 | * @return unknown |
---|
1039 | */ |
---|
1040 | function get_attachment_fields_to_edit($post, $errors = null) { |
---|
1041 | if ( is_int($post) ) |
---|
1042 | $post =& get_post($post); |
---|
1043 | if ( is_array($post) ) |
---|
1044 | $post = (object) $post; |
---|
1045 | |
---|
1046 | $image_url = wp_get_attachment_url($post->ID); |
---|
1047 | |
---|
1048 | $edit_post = sanitize_post($post, 'edit'); |
---|
1049 | |
---|
1050 | |
---|
1051 | |
---|
1052 | $form_fields = array( |
---|
1053 | 'post_title' => array( |
---|
1054 | 'label' => __('Title'), |
---|
1055 | 'value' => $edit_post->post_title |
---|
1056 | ), |
---|
1057 | 'image_alt' => array(), |
---|
1058 | 'post_excerpt' => array( |
---|
1059 | 'label' => __('Caption'), |
---|
1060 | 'value' => $edit_post->post_excerpt |
---|
1061 | ), |
---|
1062 | 'post_content' => array( |
---|
1063 | 'label' => __('Description'), |
---|
1064 | 'value' => $edit_post->post_content, |
---|
1065 | 'input' => 'textarea' |
---|
1066 | ), |
---|
1067 | 'url' => array( |
---|
1068 | 'label' => __('Link URL'), |
---|
1069 | 'input' => 'html', |
---|
1070 | 'html' => image_link_input_fields($post, get_option('image_default_link_type')), |
---|
1071 | 'helps' => __('Enter a link URL or click above for presets.') |
---|
1072 | ), |
---|
1073 | 'menu_order' => array( |
---|
1074 | 'label' => __('Order'), |
---|
1075 | 'value' => $edit_post->menu_order |
---|
1076 | ), |
---|
1077 | 'image_url' => array( |
---|
1078 | 'label' => __('File URL'), |
---|
1079 | 'input' => 'html', |
---|
1080 | 'html' => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr($image_url) . "' /><br />", |
---|
1081 | 'value' => wp_get_attachment_url($post->ID), |
---|
1082 | 'helps' => __('Location of the uploaded file.') |
---|
1083 | ) |
---|
1084 | ); |
---|
1085 | |
---|
1086 | foreach ( get_attachment_taxonomies($post) as $taxonomy ) { |
---|
1087 | $t = (array) get_taxonomy($taxonomy); |
---|
1088 | if ( empty($t['label']) ) |
---|
1089 | $t['label'] = $taxonomy; |
---|
1090 | if ( empty($t['args']) ) |
---|
1091 | $t['args'] = array(); |
---|
1092 | |
---|
1093 | $terms = get_object_term_cache($post->ID, $taxonomy); |
---|
1094 | if ( empty($terms) ) |
---|
1095 | $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); |
---|
1096 | |
---|
1097 | $values = array(); |
---|
1098 | |
---|
1099 | foreach ( $terms as $term ) |
---|
1100 | $values[] = $term->name; |
---|
1101 | $t['value'] = join(', ', $values); |
---|
1102 | |
---|
1103 | $form_fields[$taxonomy] = $t; |
---|
1104 | } |
---|
1105 | |
---|
1106 | // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
---|
1107 | // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing ) |
---|
1108 | $form_fields = array_merge_recursive($form_fields, (array) $errors); |
---|
1109 | |
---|
1110 | $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post); |
---|
1111 | |
---|
1112 | return $form_fields; |
---|
1113 | } |
---|
1114 | |
---|
1115 | /** |
---|
1116 | * Retrieve HTML for media items of post gallery. |
---|
1117 | * |
---|
1118 | * The HTML markup retrieved will be created for the progress of SWF Upload |
---|
1119 | * component. Will also create link for showing and hiding the form to modify |
---|
1120 | * the image attachment. |
---|
1121 | * |
---|
1122 | * @since unknown |
---|
1123 | * |
---|
1124 | * @param int $post_id Optional. Post ID. |
---|
1125 | * @param array $errors Errors for attachment, if any. |
---|
1126 | * @return string |
---|
1127 | */ |
---|
1128 | function get_media_items( $post_id, $errors ) { |
---|
1129 | $attachments = array(); |
---|
1130 | if ( $post_id ) { |
---|
1131 | $post = get_post($post_id); |
---|
1132 | if ( $post && $post->post_type == 'attachment' ) |
---|
1133 | $attachments = array($post->ID => $post); |
---|
1134 | else |
---|
1135 | $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') ); |
---|
1136 | } else { |
---|
1137 | if ( is_array($GLOBALS['wp_the_query']->posts) ) |
---|
1138 | foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) |
---|
1139 | $attachments[$attachment->ID] = $attachment; |
---|
1140 | } |
---|
1141 | |
---|
1142 | $output = ''; |
---|
1143 | foreach ( (array) $attachments as $id => $attachment ) { |
---|
1144 | if ( $attachment->post_status == 'trash' ) |
---|
1145 | continue; |
---|
1146 | if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) ) |
---|
1147 | $output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress'><div class='bar'></div></div><div id='media-upload-error-$id'></div><div class='filename'></div>$item\n</div>"; |
---|
1148 | } |
---|
1149 | |
---|
1150 | return $output; |
---|
1151 | } |
---|
1152 | |
---|
1153 | /** |
---|
1154 | * Retrieve HTML form for modifying the image attachment. |
---|
1155 | * |
---|
1156 | * @since unknown |
---|
1157 | * |
---|
1158 | * @param int $attachment_id Attachment ID for modification. |
---|
1159 | * @param string|array $args Optional. Override defaults. |
---|
1160 | * @return string HTML form for attachment. |
---|
1161 | */ |
---|
1162 | function get_media_item( $attachment_id, $args = null ) { |
---|
1163 | global $redir_tab; |
---|
1164 | |
---|
1165 | if ( ( $attachment_id = intval( $attachment_id ) ) && $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ) ) |
---|
1166 | $thumb_url = $thumb_url[0]; |
---|
1167 | else |
---|
1168 | $thumb_url = false; |
---|
1169 | |
---|
1170 | $post = get_post( $attachment_id ); |
---|
1171 | |
---|
1172 | $default_args = array( 'errors' => null, 'send' => post_type_supports(get_post_type($post->post_parent), 'editor'), 'delete' => true, 'toggle' => true, 'show_title' => true ); |
---|
1173 | $args = wp_parse_args( $args, $default_args ); |
---|
1174 | extract( $args, EXTR_SKIP ); |
---|
1175 | |
---|
1176 | $toggle_on = __( 'Show' ); |
---|
1177 | $toggle_off = __( 'Hide' ); |
---|
1178 | |
---|
1179 | $filename = basename( $post->guid ); |
---|
1180 | $title = esc_attr( $post->post_title ); |
---|
1181 | |
---|
1182 | if ( $_tags = get_the_tags( $attachment_id ) ) { |
---|
1183 | foreach ( $_tags as $tag ) |
---|
1184 | $tags[] = $tag->name; |
---|
1185 | $tags = esc_attr( join( ', ', $tags ) ); |
---|
1186 | } |
---|
1187 | |
---|
1188 | $post_mime_types = get_post_mime_types(); |
---|
1189 | $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); |
---|
1190 | $type = array_shift( $keys ); |
---|
1191 | $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />"; |
---|
1192 | |
---|
1193 | $form_fields = get_attachment_fields_to_edit( $post, $errors ); |
---|
1194 | |
---|
1195 | if ( $toggle ) { |
---|
1196 | $class = empty( $errors ) ? 'startclosed' : 'startopen'; |
---|
1197 | $toggle_links = " |
---|
1198 | <a class='toggle describe-toggle-on' href='#'>$toggle_on</a> |
---|
1199 | <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>"; |
---|
1200 | } else { |
---|
1201 | $class = 'form-table'; |
---|
1202 | $toggle_links = ''; |
---|
1203 | } |
---|
1204 | |
---|
1205 | $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case |
---|
1206 | $display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60 ) . "</span></div>" : ''; |
---|
1207 | |
---|
1208 | $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) ); |
---|
1209 | $order = ''; |
---|
1210 | |
---|
1211 | foreach ( $form_fields as $key => $val ) { |
---|
1212 | if ( 'menu_order' == $key ) { |
---|
1213 | if ( $gallery ) |
---|
1214 | $order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ). "' /></div>"; |
---|
1215 | else |
---|
1216 | $order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />"; |
---|
1217 | |
---|
1218 | unset( $form_fields['menu_order'] ); |
---|
1219 | break; |
---|
1220 | } |
---|
1221 | } |
---|
1222 | |
---|
1223 | $media_dims = ''; |
---|
1224 | $meta = wp_get_attachment_metadata( $post->ID ); |
---|
1225 | if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) ) |
---|
1226 | $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; |
---|
1227 | $media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
---|
1228 | |
---|
1229 | $image_edit_button = ''; |
---|
1230 | if ( gd_edit_image_support( $post->post_mime_type ) ) { |
---|
1231 | $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
---|
1232 | $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <img src='" . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . "' class='imgedit-wait-spin' alt='' />"; |
---|
1233 | } |
---|
1234 | |
---|
1235 | $attachment_url = get_permalink( $attachment_id ); |
---|
1236 | |
---|
1237 | $item = " |
---|
1238 | $type_html |
---|
1239 | $toggle_links |
---|
1240 | $order |
---|
1241 | $display_title |
---|
1242 | <table class='slidetoggle describe $class'> |
---|
1243 | <thead class='media-item-info' id='media-head-$post->ID'> |
---|
1244 | <tr valign='top'> |
---|
1245 | <td class='A1B1' id='thumbnail-head-$post->ID'> |
---|
1246 | <p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' style='margin-top: 3px' /></a></p> |
---|
1247 | <p>$image_edit_button</p> |
---|
1248 | </td> |
---|
1249 | <td> |
---|
1250 | <p><strong>" . __('File name:') . "</strong> $filename</p> |
---|
1251 | <p><strong>" . __('File type:') . "</strong> $post->post_mime_type</p> |
---|
1252 | <p><strong>" . __('Upload date:') . "</strong> " . mysql2date( get_option('date_format'), $post->post_date ). '</p>'; |
---|
1253 | if ( !empty( $media_dims ) ) |
---|
1254 | $item .= "<p><strong>" . __('Dimensions:') . "</strong> $media_dims</p>\n"; |
---|
1255 | |
---|
1256 | $item .= "</td></tr>\n"; |
---|
1257 | |
---|
1258 | |
---|
1259 | |
---|
1260 | $item .= " |
---|
1261 | </thead> |
---|
1262 | <tbody> |
---|
1263 | <tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr> |
---|
1264 | <tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n"; |
---|
1265 | |
---|
1266 | $defaults = array( |
---|
1267 | 'input' => 'text', |
---|
1268 | 'required' => false, |
---|
1269 | 'value' => '', |
---|
1270 | 'extra_rows' => array(), |
---|
1271 | ); |
---|
1272 | |
---|
1273 | if ( $send ) |
---|
1274 | $send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . esc_attr__( 'Insert into Post' ) . "' />"; |
---|
1275 | if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { |
---|
1276 | if ( !EMPTY_TRASH_DAYS ) { |
---|
1277 | $delete = "<a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Delete Permanently' ) . '</a>'; |
---|
1278 | } elseif ( !MEDIA_TRASH ) { |
---|
1279 | $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a> |
---|
1280 | <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" . sprintf( __( 'You are about to delete <strong>%s</strong>.' ), $filename ) . " |
---|
1281 | <a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a> |
---|
1282 | <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a> |
---|
1283 | </div>"; |
---|
1284 | } else { |
---|
1285 | $delete = "<a href='" . wp_nonce_url( "post.php?action=trash&post=$attachment_id", 'trash-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a> |
---|
1286 | <a href='" . wp_nonce_url( "post.php?action=untrash&post=$attachment_id", 'untrash-attachment_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . "</a>"; |
---|
1287 | } |
---|
1288 | } else { |
---|
1289 | $delete = ''; |
---|
1290 | } |
---|
1291 | |
---|
1292 | $thumbnail = ''; |
---|
1293 | $calling_post_id = 0; |
---|
1294 | if ( isset( $_GET['post_id'] ) ) |
---|
1295 | $calling_post_id = absint( $_GET['post_id'] ); |
---|
1296 | elseif ( isset( $_POST ) && count( $_POST ) ) // Like for async-upload where $_GET['post_id'] isn't set |
---|
1297 | $calling_post_id = $post->post_parent; |
---|
1298 | if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) { |
---|
1299 | $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); |
---|
1300 | $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html__( "Use as featured image" ) . "</a>"; |
---|
1301 | } |
---|
1302 | |
---|
1303 | if ( ( $send || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) |
---|
1304 | $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $thumbnail $delete</td></tr>\n" ); |
---|
1305 | |
---|
1306 | $hidden_fields = array(); |
---|
1307 | |
---|
1308 | foreach ( $form_fields as $id => $field ) { |
---|
1309 | if ( $id{0} == '_' ) |
---|
1310 | continue; |
---|
1311 | |
---|
1312 | if ( !empty( $field['tr'] ) ) { |
---|
1313 | $item .= $field['tr']; |
---|
1314 | continue; |
---|
1315 | } |
---|
1316 | |
---|
1317 | $field = array_merge( $defaults, $field ); |
---|
1318 | $name = "attachments[$attachment_id][$id]"; |
---|
1319 | |
---|
1320 | if ( $field['input'] == 'hidden' ) { |
---|
1321 | $hidden_fields[$name] = $field['value']; |
---|
1322 | continue; |
---|
1323 | } |
---|
1324 | |
---|
1325 | $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : ''; |
---|
1326 | $aria_required = $field['required'] ? " aria-required='true' " : ''; |
---|
1327 | $class = $id; |
---|
1328 | $class .= $field['required'] ? ' form-required' : ''; |
---|
1329 | |
---|
1330 | $item .= "\t\t<tr class='$class'>\n\t\t\t<th valign='top' scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label></th>\n\t\t\t<td class='field'>"; |
---|
1331 | if ( !empty( $field[ $field['input'] ] ) ) |
---|
1332 | $item .= $field[ $field['input'] ]; |
---|
1333 | elseif ( $field['input'] == 'textarea' ) { |
---|
1334 | $item .= "<textarea type='text' id='$name' name='$name' $aria_required>" . esc_html( $field['value'] ) . '</textarea>'; |
---|
1335 | } else { |
---|
1336 | $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />"; |
---|
1337 | } |
---|
1338 | if ( !empty( $field['helps'] ) ) |
---|
1339 | $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
---|
1340 | $item .= "</td>\n\t\t</tr>\n"; |
---|
1341 | |
---|
1342 | $extra_rows = array(); |
---|
1343 | |
---|
1344 | if ( !empty( $field['errors'] ) ) |
---|
1345 | foreach ( array_unique( (array) $field['errors'] ) as $error ) |
---|
1346 | $extra_rows['error'][] = $error; |
---|
1347 | |
---|
1348 | if ( !empty( $field['extra_rows'] ) ) |
---|
1349 | foreach ( $field['extra_rows'] as $class => $rows ) |
---|
1350 | foreach ( (array) $rows as $html ) |
---|
1351 | $extra_rows[$class][] = $html; |
---|
1352 | |
---|
1353 | foreach ( $extra_rows as $class => $rows ) |
---|
1354 | foreach ( $rows as $html ) |
---|
1355 | $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; |
---|
1356 | } |
---|
1357 | |
---|
1358 | if ( !empty( $form_fields['_final'] ) ) |
---|
1359 | $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; |
---|
1360 | $item .= "\t</tbody>\n"; |
---|
1361 | $item .= "\t</table>\n"; |
---|
1362 | |
---|
1363 | foreach ( $hidden_fields as $name => $value ) |
---|
1364 | $item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n"; |
---|
1365 | |
---|
1366 | if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) { |
---|
1367 | $parent = (int) $_REQUEST['post_id']; |
---|
1368 | $parent_name = "attachments[$attachment_id][post_parent]"; |
---|
1369 | $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n"; |
---|
1370 | } |
---|
1371 | |
---|
1372 | return $item; |
---|
1373 | } |
---|
1374 | |
---|
1375 | /** |
---|
1376 | * {@internal Missing Short Description}} |
---|
1377 | * |
---|
1378 | * @since unknown |
---|
1379 | */ |
---|
1380 | function media_upload_header() { |
---|
1381 | ?> |
---|
1382 | <script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script> |
---|
1383 | <div id="media-upload-header"> |
---|
1384 | <?php the_media_upload_tabs(); ?> |
---|
1385 | </div> |
---|
1386 | <?php |
---|
1387 | } |
---|
1388 | |
---|
1389 | /** |
---|
1390 | * {@internal Missing Short Description}} |
---|
1391 | * |
---|
1392 | * @since unknown |
---|
1393 | * |
---|
1394 | * @param unknown_type $errors |
---|
1395 | */ |
---|
1396 | function media_upload_form( $errors = null ) { |
---|
1397 | global $type, $tab; |
---|
1398 | |
---|
1399 | $flash_action_url = admin_url('async-upload.php'); |
---|
1400 | |
---|
1401 | // If Mac and mod_security, no Flash. :( |
---|
1402 | $flash = true; |
---|
1403 | if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'mac') && apache_mod_loaded('mod_security') ) |
---|
1404 | $flash = false; |
---|
1405 | |
---|
1406 | $flash = apply_filters('flash_uploader', $flash); |
---|
1407 | $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0; |
---|
1408 | |
---|
1409 | $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
---|
1410 | $sizes = array( 'KB', 'MB', 'GB' ); |
---|
1411 | for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) |
---|
1412 | $upload_size_unit /= 1024; |
---|
1413 | if ( $u < 0 ) { |
---|
1414 | $upload_size_unit = 0; |
---|
1415 | $u = 0; |
---|
1416 | } else { |
---|
1417 | $upload_size_unit = (int) $upload_size_unit; |
---|
1418 | } |
---|
1419 | ?> |
---|
1420 | <script type="text/javascript"> |
---|
1421 | //<![CDATA[ |
---|
1422 | var uploaderMode = 0; |
---|
1423 | jQuery(document).ready(function($){ |
---|
1424 | uploaderMode = getUserSetting('uploader'); |
---|
1425 | $('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;}); |
---|
1426 | $('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;}); |
---|
1427 | }); |
---|
1428 | //]]> |
---|
1429 | </script> |
---|
1430 | <div id="media-upload-notice"> |
---|
1431 | <?php if (isset($errors['upload_notice']) ) { ?> |
---|
1432 | <?php echo $errors['upload_notice']; ?> |
---|
1433 | <?php } ?> |
---|
1434 | </div> |
---|
1435 | <div id="media-upload-error"> |
---|
1436 | <?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?> |
---|
1437 | <?php echo $errors['upload_error']->get_error_message(); ?> |
---|
1438 | <?php } ?> |
---|
1439 | </div> |
---|
1440 | <?php |
---|
1441 | // Check quota for this blog if multisite |
---|
1442 | if ( is_multisite() && !is_upload_space_available() ) { |
---|
1443 | echo '<p>' . sprintf( __( 'Sorry, you have filled your storage quota (%s MB).' ), get_space_allowed() ) . '</p>'; |
---|
1444 | return; |
---|
1445 | } |
---|
1446 | |
---|
1447 | do_action('pre-upload-ui'); |
---|
1448 | |
---|
1449 | if ( $flash ) : ?> |
---|
1450 | <script type="text/javascript"> |
---|
1451 | //<![CDATA[ |
---|
1452 | var swfu; |
---|
1453 | SWFUpload.onload = function() { |
---|
1454 | var settings = { |
---|
1455 | button_text: '<span class="button"><?php _e('Select Files'); ?><\/span>', |
---|
1456 | button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; font-size: 11px; text-shadow: 0 1px 0 #FFFFFF; color:#464646; }', |
---|
1457 | button_height: "23", |
---|
1458 | button_width: "132", |
---|
1459 | button_text_top_padding: 3, |
---|
1460 | button_image_url: '<?php echo includes_url('images/upload.png?ver=20100531'); ?>', |
---|
1461 | button_placeholder_id: "flash-browse-button", |
---|
1462 | upload_url : "<?php echo esc_attr( $flash_action_url ); ?>", |
---|
1463 | flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>", |
---|
1464 | file_post_name: "async-upload", |
---|
1465 | file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>", |
---|
1466 | post_params : { |
---|
1467 | "post_id" : "<?php echo $post_id; ?>", |
---|
1468 | "auth_cookie" : "<?php echo (is_ssl() ? $_COOKIE[SECURE_AUTH_COOKIE] : $_COOKIE[AUTH_COOKIE]); ?>", |
---|
1469 | "logged_in_cookie": "<?php echo $_COOKIE[LOGGED_IN_COOKIE]; ?>", |
---|
1470 | "_wpnonce" : "<?php echo wp_create_nonce('media-form'); ?>", |
---|
1471 | "type" : "<?php echo $type; ?>", |
---|
1472 | "tab" : "<?php echo $tab; ?>", |
---|
1473 | "short" : "1" |
---|
1474 | }, |
---|
1475 | file_size_limit : "<?php echo $max_upload_size; ?>b", |
---|
1476 | file_dialog_start_handler : fileDialogStart, |
---|
1477 | file_queued_handler : fileQueued, |
---|
1478 | upload_start_handler : uploadStart, |
---|
1479 | upload_progress_handler : uploadProgress, |
---|
1480 | upload_error_handler : uploadError, |
---|
1481 | upload_success_handler : uploadSuccess, |
---|
1482 | upload_complete_handler : uploadComplete, |
---|
1483 | file_queue_error_handler : fileQueueError, |
---|
1484 | file_dialog_complete_handler : fileDialogComplete, |
---|
1485 | swfupload_pre_load_handler: swfuploadPreLoad, |
---|
1486 | swfupload_load_failed_handler: swfuploadLoadFailed, |
---|
1487 | custom_settings : { |
---|
1488 | degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable |
---|
1489 | swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available |
---|
1490 | }, |
---|
1491 | debug: false |
---|
1492 | }; |
---|
1493 | swfu = new SWFUpload(settings); |
---|
1494 | }; |
---|
1495 | //]]> |
---|
1496 | </script> |
---|
1497 | |
---|
1498 | <div id="flash-upload-ui" class="hide-if-no-js"> |
---|
1499 | <?php do_action('pre-flash-upload-ui'); ?> |
---|
1500 | |
---|
1501 | <div> |
---|
1502 | <?php _e( 'Choose files to upload' ); ?> |
---|
1503 | <div id="flash-browse-button"></div> |
---|
1504 | <span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span> |
---|
1505 | </div> |
---|
1506 | <p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p> |
---|
1507 | <?php do_action('post-flash-upload-ui'); ?> |
---|
1508 | <p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p> |
---|
1509 | </div> |
---|
1510 | <?php endif; // $flash ?> |
---|
1511 | |
---|
1512 | <div id="html-upload-ui"> |
---|
1513 | <?php do_action('pre-html-upload-ui'); ?> |
---|
1514 | <p id="async-upload-wrap"> |
---|
1515 | <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label> |
---|
1516 | <input type="file" name="async-upload" id="async-upload" /> <input type="submit" class="button" name="html-upload" value="<?php esc_attr_e('Upload'); ?>" /> <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a> |
---|
1517 | </p> |
---|
1518 | <div class="clear"></div> |
---|
1519 | <p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p> |
---|
1520 | <?php if ( is_lighttpd_before_150() ): ?> |
---|
1521 | <p><?php _e('If you want to use all capabilities of the uploader, like uploading multiple files at once, please upgrade to lighttpd 1.5.'); ?></p> |
---|
1522 | <?php endif;?> |
---|
1523 | <?php do_action('post-html-upload-ui', $flash); ?> |
---|
1524 | </div> |
---|
1525 | <?php do_action('post-upload-ui'); ?> |
---|
1526 | <?php |
---|
1527 | } |
---|
1528 | |
---|
1529 | /** |
---|
1530 | * {@internal Missing Short Description}} |
---|
1531 | * |
---|
1532 | * @since unknown |
---|
1533 | * |
---|
1534 | * @param unknown_type $type |
---|
1535 | * @param unknown_type $errors |
---|
1536 | * @param unknown_type $id |
---|
1537 | */ |
---|
1538 | function media_upload_type_form($type = 'file', $errors = null, $id = null) { |
---|
1539 | media_upload_header(); |
---|
1540 | |
---|
1541 | $post_id = isset( $_REQUEST['post_id'] )? intval( $_REQUEST['post_id'] ) : 0; |
---|
1542 | |
---|
1543 | $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id"); |
---|
1544 | $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); |
---|
1545 | ?> |
---|
1546 | |
---|
1547 | <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form"> |
---|
1548 | <input type="submit" class="hidden" name="save" value="" /> |
---|
1549 | <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
---|
1550 | <?php wp_nonce_field('media-form'); ?> |
---|
1551 | |
---|
1552 | <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3> |
---|
1553 | |
---|
1554 | <?php media_upload_form( $errors ); ?> |
---|
1555 | |
---|
1556 | <script type="text/javascript"> |
---|
1557 | //<![CDATA[ |
---|
1558 | jQuery(function($){ |
---|
1559 | var preloaded = $(".media-item.preloaded"); |
---|
1560 | if ( preloaded.length > 0 ) { |
---|
1561 | preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
---|
1562 | } |
---|
1563 | updateMediaForm(); |
---|
1564 | }); |
---|
1565 | //]]> |
---|
1566 | </script> |
---|
1567 | <div id="media-items"> |
---|
1568 | <?php |
---|
1569 | if ( $id ) { |
---|
1570 | if ( !is_wp_error($id) ) { |
---|
1571 | add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); |
---|
1572 | echo get_media_items( $id, $errors ); |
---|
1573 | } else { |
---|
1574 | echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div>'; |
---|
1575 | exit; |
---|
1576 | } |
---|
1577 | } |
---|
1578 | ?> |
---|
1579 | </div> |
---|
1580 | <p class="savebutton ml-submit"> |
---|
1581 | <input type="submit" class="button" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" /> |
---|
1582 | </p> |
---|
1583 | </form> |
---|
1584 | <?php |
---|
1585 | } |
---|
1586 | |
---|
1587 | /** |
---|
1588 | * {@internal Missing Short Description}} |
---|
1589 | * |
---|
1590 | * @since unknown |
---|
1591 | * |
---|
1592 | * @param unknown_type $type |
---|
1593 | * @param unknown_type $errors |
---|
1594 | * @param unknown_type $id |
---|
1595 | */ |
---|
1596 | function media_upload_type_url_form($type = 'file', $errors = null, $id = null) { |
---|
1597 | media_upload_header(); |
---|
1598 | |
---|
1599 | $post_id = intval($_REQUEST['post_id']); |
---|
1600 | |
---|
1601 | $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id"); |
---|
1602 | $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); |
---|
1603 | |
---|
1604 | $callback = "type_url_form_$type"; |
---|
1605 | ?> |
---|
1606 | |
---|
1607 | <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form"> |
---|
1608 | <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
---|
1609 | <?php wp_nonce_field('media-form'); ?> |
---|
1610 | |
---|
1611 | <?php if ( is_callable($callback) ) { ?> |
---|
1612 | |
---|
1613 | <h3 class="media-title"><?php _e('Add media file from URL'); ?></h3> |
---|
1614 | |
---|
1615 | <script type="text/javascript"> |
---|
1616 | //<![CDATA[ |
---|
1617 | var addExtImage = { |
---|
1618 | |
---|
1619 | width : '', |
---|
1620 | height : '', |
---|
1621 | align : 'alignnone', |
---|
1622 | |
---|
1623 | insert : function() { |
---|
1624 | var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = ''; |
---|
1625 | |
---|
1626 | if ( '' == f.src.value || '' == t.width ) |
---|
1627 | return false; |
---|
1628 | |
---|
1629 | if ( f.title.value ) { |
---|
1630 | title = f.title.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); |
---|
1631 | title = ' title="'+title+'"'; |
---|
1632 | } |
---|
1633 | |
---|
1634 | if ( f.alt.value ) |
---|
1635 | alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); |
---|
1636 | |
---|
1637 | <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?> |
---|
1638 | if ( f.caption.value ) |
---|
1639 | caption = f.caption.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); |
---|
1640 | <?php } ?> |
---|
1641 | |
---|
1642 | cls = caption ? '' : ' class="'+t.align+'"'; |
---|
1643 | |
---|
1644 | html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />'; |
---|
1645 | |
---|
1646 | if ( f.url.value ) |
---|
1647 | html = '<a href="'+f.url.value+'">'+html+'</a>'; |
---|
1648 | |
---|
1649 | if ( caption ) |
---|
1650 | html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]'; |
---|
1651 | |
---|
1652 | var win = window.dialogArguments || opener || parent || top; |
---|
1653 | win.send_to_editor(html); |
---|
1654 | return false; |
---|
1655 | }, |
---|
1656 | |
---|
1657 | resetImageData : function() { |
---|
1658 | var t = addExtImage; |
---|
1659 | |
---|
1660 | t.width = t.height = ''; |
---|
1661 | document.getElementById('go_button').style.color = '#bbb'; |
---|
1662 | if ( ! document.forms[0].src.value ) |
---|
1663 | document.getElementById('status_img').innerHTML = '*'; |
---|
1664 | else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />'; |
---|
1665 | }, |
---|
1666 | |
---|
1667 | updateImageData : function() { |
---|
1668 | var t = addExtImage; |
---|
1669 | |
---|
1670 | t.width = t.preloadImg.width; |
---|
1671 | t.height = t.preloadImg.height; |
---|
1672 | document.getElementById('go_button').style.color = '#333'; |
---|
1673 | document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/yes.png' ) ); ?>" alt="" />'; |
---|
1674 | }, |
---|
1675 | |
---|
1676 | getImageData : function() { |
---|
1677 | var t = addExtImage, src = document.forms[0].src.value; |
---|
1678 | |
---|
1679 | if ( ! src ) { |
---|
1680 | t.resetImageData(); |
---|
1681 | return false; |
---|
1682 | } |
---|
1683 | document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />'; |
---|
1684 | t.preloadImg = new Image(); |
---|
1685 | t.preloadImg.onload = t.updateImageData; |
---|
1686 | t.preloadImg.onerror = t.resetImageData; |
---|
1687 | t.preloadImg.src = src; |
---|
1688 | } |
---|
1689 | } |
---|
1690 | //]]> |
---|
1691 | </script> |
---|
1692 | |
---|
1693 | <div id="media-items"> |
---|
1694 | <div class="media-item media-blank"> |
---|
1695 | <?php echo apply_filters($callback, call_user_func($callback)); ?> |
---|
1696 | </div> |
---|
1697 | </div> |
---|
1698 | </form> |
---|
1699 | <?php |
---|
1700 | } else { |
---|
1701 | wp_die( __('Unknown action.') ); |
---|
1702 | } |
---|
1703 | } |
---|
1704 | |
---|
1705 | /** |
---|
1706 | * {@internal Missing Short Description}} |
---|
1707 | * |
---|
1708 | * @since unknown |
---|
1709 | * |
---|
1710 | * @param unknown_type $errors |
---|
1711 | */ |
---|
1712 | function media_upload_gallery_form($errors) { |
---|
1713 | global $redir_tab, $type; |
---|
1714 | |
---|
1715 | $redir_tab = 'gallery'; |
---|
1716 | media_upload_header(); |
---|
1717 | |
---|
1718 | $post_id = intval($_REQUEST['post_id']); |
---|
1719 | $form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id"); |
---|
1720 | $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); |
---|
1721 | ?> |
---|
1722 | |
---|
1723 | <script type="text/javascript"> |
---|
1724 | <!-- |
---|
1725 | jQuery(function($){ |
---|
1726 | var preloaded = $(".media-item.preloaded"); |
---|
1727 | if ( preloaded.length > 0 ) { |
---|
1728 | preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
---|
1729 | updateMediaForm(); |
---|
1730 | } |
---|
1731 | }); |
---|
1732 | --> |
---|
1733 | </script> |
---|
1734 | <div id="sort-buttons" class="hide-if-no-js"> |
---|
1735 | <span> |
---|
1736 | <?php _e('All Tabs:'); ?> |
---|
1737 | <a href="#" id="showall"><?php _e('Show'); ?></a> |
---|
1738 | <a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a> |
---|
1739 | </span> |
---|
1740 | <?php _e('Sort Order:'); ?> |
---|
1741 | <a href="#" id="asc"><?php _e('Ascending'); ?></a> | |
---|
1742 | <a href="#" id="desc"><?php _e('Descending'); ?></a> | |
---|
1743 | <a href="#" id="clear"><?php _ex('Clear', 'verb'); ?></a> |
---|
1744 | </div> |
---|
1745 | <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="gallery-form"> |
---|
1746 | <?php wp_nonce_field('media-form'); ?> |
---|
1747 | <?php //media_upload_form( $errors ); ?> |
---|
1748 | <table class="widefat" cellspacing="0"> |
---|
1749 | <thead><tr> |
---|
1750 | <th><?php _e('Media'); ?></th> |
---|
1751 | <th class="order-head"><?php _e('Order'); ?></th> |
---|
1752 | <th class="actions-head"><?php _e('Actions'); ?></th> |
---|
1753 | </tr></thead> |
---|
1754 | </table> |
---|
1755 | <div id="media-items"> |
---|
1756 | <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?> |
---|
1757 | <?php echo get_media_items($post_id, $errors); ?> |
---|
1758 | </div> |
---|
1759 | |
---|
1760 | <p class="ml-submit"> |
---|
1761 | <input type="submit" class="button savebutton" style="display:none;" name="save" id="save-all" value="<?php esc_attr_e( 'Save all changes' ); ?>" /> |
---|
1762 | <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
---|
1763 | <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> |
---|
1764 | <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> |
---|
1765 | </p> |
---|
1766 | |
---|
1767 | <div id="gallery-settings" style="display:none;"> |
---|
1768 | <div class="title"><?php _e('Gallery Settings'); ?></div> |
---|
1769 | <table id="basic" class="describe"><tbody> |
---|
1770 | <tr> |
---|
1771 | <th scope="row" class="label"> |
---|
1772 | <label> |
---|
1773 | <span class="alignleft"><?php _e('Link thumbnails to:'); ?></span> |
---|
1774 | </label> |
---|
1775 | </th> |
---|
1776 | <td class="field"> |
---|
1777 | <input type="radio" name="linkto" id="linkto-file" value="file" /> |
---|
1778 | <label for="linkto-file" class="radio"><?php _e('Image File'); ?></label> |
---|
1779 | |
---|
1780 | <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" /> |
---|
1781 | <label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label> |
---|
1782 | </td> |
---|
1783 | </tr> |
---|
1784 | |
---|
1785 | <tr> |
---|
1786 | <th scope="row" class="label"> |
---|
1787 | <label> |
---|
1788 | <span class="alignleft"><?php _e('Order images by:'); ?></span> |
---|
1789 | </label> |
---|
1790 | </th> |
---|
1791 | <td class="field"> |
---|
1792 | <select id="orderby" name="orderby"> |
---|
1793 | <option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option> |
---|
1794 | <option value="title"><?php _e('Title'); ?></option> |
---|
1795 | <option value="ID"><?php _e('Date/Time'); ?></option> |
---|
1796 | <option value="rand"><?php _e('Random'); ?></option> |
---|
1797 | </select> |
---|
1798 | </td> |
---|
1799 | </tr> |
---|
1800 | |
---|
1801 | <tr> |
---|
1802 | <th scope="row" class="label"> |
---|
1803 | <label> |
---|
1804 | <span class="alignleft"><?php _e('Order:'); ?></span> |
---|
1805 | </label> |
---|
1806 | </th> |
---|
1807 | <td class="field"> |
---|
1808 | <input type="radio" checked="checked" name="order" id="order-asc" value="asc" /> |
---|
1809 | <label for="order-asc" class="radio"><?php _e('Ascending'); ?></label> |
---|
1810 | |
---|
1811 | <input type="radio" name="order" id="order-desc" value="desc" /> |
---|
1812 | <label for="order-desc" class="radio"><?php _e('Descending'); ?></label> |
---|
1813 | </td> |
---|
1814 | </tr> |
---|
1815 | |
---|
1816 | <tr> |
---|
1817 | <th scope="row" class="label"> |
---|
1818 | <label> |
---|
1819 | <span class="alignleft"><?php _e('Gallery columns:'); ?></span> |
---|
1820 | </label> |
---|
1821 | </th> |
---|
1822 | <td class="field"> |
---|
1823 | <select id="columns" name="columns"> |
---|
1824 | <option value="2">2</option> |
---|
1825 | <option value="3" selected="selected">3</option> |
---|
1826 | <option value="4">4</option> |
---|
1827 | <option value="5">5</option> |
---|
1828 | <option value="6">6</option> |
---|
1829 | <option value="7">7</option> |
---|
1830 | <option value="8">8</option> |
---|
1831 | <option value="9">9</option> |
---|
1832 | </select> |
---|
1833 | </td> |
---|
1834 | </tr> |
---|
1835 | </tbody></table> |
---|
1836 | |
---|
1837 | <p class="ml-submit"> |
---|
1838 | <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" /> |
---|
1839 | <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" /> |
---|
1840 | </p> |
---|
1841 | </div> |
---|
1842 | </form> |
---|
1843 | <?php |
---|
1844 | } |
---|
1845 | |
---|
1846 | /** |
---|
1847 | * {@internal Missing Short Description}} |
---|
1848 | * |
---|
1849 | * @since unknown |
---|
1850 | * |
---|
1851 | * @param unknown_type $errors |
---|
1852 | */ |
---|
1853 | function media_upload_library_form($errors) { |
---|
1854 | global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; |
---|
1855 | |
---|
1856 | media_upload_header(); |
---|
1857 | |
---|
1858 | $post_id = intval($_REQUEST['post_id']); |
---|
1859 | |
---|
1860 | $form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id"); |
---|
1861 | $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); |
---|
1862 | |
---|
1863 | $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0; |
---|
1864 | if ( $_GET['paged'] < 1 ) |
---|
1865 | $_GET['paged'] = 1; |
---|
1866 | $start = ( $_GET['paged'] - 1 ) * 10; |
---|
1867 | if ( $start < 1 ) |
---|
1868 | $start = 0; |
---|
1869 | add_filter( 'post_limits', create_function( '$a', "return 'LIMIT $start, 10';" ) ); |
---|
1870 | |
---|
1871 | list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); |
---|
1872 | |
---|
1873 | ?> |
---|
1874 | |
---|
1875 | <form id="filter" action="" method="get"> |
---|
1876 | <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" /> |
---|
1877 | <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" /> |
---|
1878 | <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> |
---|
1879 | <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" /> |
---|
1880 | |
---|
1881 | <p id="media-search" class="search-box"> |
---|
1882 | <label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label> |
---|
1883 | <input type="text" id="media-search-input" name="s" value="<?php the_search_query(); ?>" /> |
---|
1884 | <input type="submit" value="<?php esc_attr_e( 'Search Media' ); ?>" class="button" /> |
---|
1885 | </p> |
---|
1886 | |
---|
1887 | <ul class="subsubsub"> |
---|
1888 | <?php |
---|
1889 | $type_links = array(); |
---|
1890 | $_num_posts = (array) wp_count_attachments(); |
---|
1891 | $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); |
---|
1892 | foreach ( $matches as $_type => $reals ) |
---|
1893 | foreach ( $reals as $real ) |
---|
1894 | if ( isset($num_posts[$_type]) ) |
---|
1895 | $num_posts[$_type] += $_num_posts[$real]; |
---|
1896 | else |
---|
1897 | $num_posts[$_type] = $_num_posts[$real]; |
---|
1898 | // If available type specified by media button clicked, filter by that type |
---|
1899 | if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) { |
---|
1900 | $_GET['post_mime_type'] = $type; |
---|
1901 | list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); |
---|
1902 | } |
---|
1903 | if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' ) |
---|
1904 | $class = ' class="current"'; |
---|
1905 | else |
---|
1906 | $class = ''; |
---|
1907 | $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>"; |
---|
1908 | foreach ( $post_mime_types as $mime_type => $label ) { |
---|
1909 | $class = ''; |
---|
1910 | |
---|
1911 | if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) |
---|
1912 | continue; |
---|
1913 | |
---|
1914 | if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) |
---|
1915 | $class = ' class="current"'; |
---|
1916 | |
---|
1917 | $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf(_n($label[2][0], $label[2][1], $num_posts[$mime_type]), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>'; |
---|
1918 | } |
---|
1919 | echo implode(' | </li>', $type_links) . '</li>'; |
---|
1920 | unset($type_links); |
---|
1921 | ?> |
---|
1922 | </ul> |
---|
1923 | |
---|
1924 | <div class="tablenav"> |
---|
1925 | |
---|
1926 | <?php |
---|
1927 | $page_links = paginate_links( array( |
---|
1928 | 'base' => add_query_arg( 'paged', '%#%' ), |
---|
1929 | 'format' => '', |
---|
1930 | 'prev_text' => __('«'), |
---|
1931 | 'next_text' => __('»'), |
---|
1932 | 'total' => ceil($wp_query->found_posts / 10), |
---|
1933 | 'current' => $_GET['paged'] |
---|
1934 | )); |
---|
1935 | |
---|
1936 | if ( $page_links ) |
---|
1937 | echo "<div class='tablenav-pages'>$page_links</div>"; |
---|
1938 | ?> |
---|
1939 | |
---|
1940 | <div class="alignleft actions"> |
---|
1941 | <?php |
---|
1942 | |
---|
1943 | $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC"; |
---|
1944 | |
---|
1945 | $arc_result = $wpdb->get_results( $arc_query ); |
---|
1946 | |
---|
1947 | $month_count = count($arc_result); |
---|
1948 | |
---|
1949 | if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?> |
---|
1950 | <select name='m'> |
---|
1951 | <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option> |
---|
1952 | <?php |
---|
1953 | foreach ($arc_result as $arc_row) { |
---|
1954 | if ( $arc_row->yyear == 0 ) |
---|
1955 | continue; |
---|
1956 | $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 ); |
---|
1957 | |
---|
1958 | if ( isset($_GET['m']) && ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] ) ) |
---|
1959 | $default = ' selected="selected"'; |
---|
1960 | else |
---|
1961 | $default = ''; |
---|
1962 | |
---|
1963 | echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>"; |
---|
1964 | echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" ); |
---|
1965 | echo "</option>\n"; |
---|
1966 | } |
---|
1967 | ?> |
---|
1968 | </select> |
---|
1969 | <?php } ?> |
---|
1970 | |
---|
1971 | <input type="submit" id="post-query-submit" value="<?php echo esc_attr( __( 'Filter »' ) ); ?>" class="button-secondary" /> |
---|
1972 | |
---|
1973 | </div> |
---|
1974 | |
---|
1975 | <br class="clear" /> |
---|
1976 | </div> |
---|
1977 | </form> |
---|
1978 | |
---|
1979 | <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="library-form"> |
---|
1980 | |
---|
1981 | <?php wp_nonce_field('media-form'); ?> |
---|
1982 | <?php //media_upload_form( $errors ); ?> |
---|
1983 | |
---|
1984 | <script type="text/javascript"> |
---|
1985 | <!-- |
---|
1986 | jQuery(function($){ |
---|
1987 | var preloaded = $(".media-item.preloaded"); |
---|
1988 | if ( preloaded.length > 0 ) { |
---|
1989 | preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
---|
1990 | updateMediaForm(); |
---|
1991 | } |
---|
1992 | }); |
---|
1993 | --> |
---|
1994 | </script> |
---|
1995 | |
---|
1996 | <div id="media-items"> |
---|
1997 | <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?> |
---|
1998 | <?php echo get_media_items(null, $errors); ?> |
---|
1999 | </div> |
---|
2000 | <p class="ml-submit"> |
---|
2001 | <input type="submit" class="button savebutton" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" /> |
---|
2002 | <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
---|
2003 | </p> |
---|
2004 | </form> |
---|
2005 | <?php |
---|
2006 | } |
---|
2007 | |
---|
2008 | /** |
---|
2009 | * {@internal Missing Short Description}} |
---|
2010 | * |
---|
2011 | * @since unknown |
---|
2012 | * |
---|
2013 | * @return unknown |
---|
2014 | */ |
---|
2015 | function type_url_form_image() { |
---|
2016 | if ( !apply_filters( 'disable_captions', '' ) ) { |
---|
2017 | $caption = ' |
---|
2018 | <tr> |
---|
2019 | <th valign="top" scope="row" class="label"> |
---|
2020 | <span class="alignleft"><label for="caption">' . __('Image Caption') . '</label></span> |
---|
2021 | </th> |
---|
2022 | <td class="field"><input id="caption" name="caption" value="" type="text" /></td> |
---|
2023 | </tr> |
---|
2024 | '; |
---|
2025 | } else { |
---|
2026 | $caption = ''; |
---|
2027 | } |
---|
2028 | |
---|
2029 | $default_align = get_option('image_default_align'); |
---|
2030 | if ( empty($default_align) ) |
---|
2031 | $default_align = 'none'; |
---|
2032 | |
---|
2033 | return ' |
---|
2034 | <h4 class="media-sub-title">' . __('Insert an image from another web site') . '</h4> |
---|
2035 | <table class="describe"><tbody> |
---|
2036 | <tr> |
---|
2037 | <th valign="top" scope="row" class="label" style="width:130px;"> |
---|
2038 | <span class="alignleft"><label for="src">' . __('Image URL') . '</label></span> |
---|
2039 | <span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span> |
---|
2040 | </th> |
---|
2041 | <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td> |
---|
2042 | </tr> |
---|
2043 | |
---|
2044 | <tr> |
---|
2045 | <th valign="top" scope="row" class="label"> |
---|
2046 | <span class="alignleft"><label for="title">' . __('Image Title') . '</label></span> |
---|
2047 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
---|
2048 | </th> |
---|
2049 | <td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td> |
---|
2050 | </tr> |
---|
2051 | |
---|
2052 | <tr> |
---|
2053 | <th valign="top" scope="row" class="label"> |
---|
2054 | <span class="alignleft"><label for="alt">' . __('Alternate Text') . '</label></span> |
---|
2055 | </th> |
---|
2056 | <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" /> |
---|
2057 | <p class="help">' . __('Alt text for the image, e.g. “The Mona Lisa”') . '</p></td> |
---|
2058 | </tr> |
---|
2059 | ' . $caption . ' |
---|
2060 | <tr class="align"> |
---|
2061 | <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th> |
---|
2062 | <td class="field"> |
---|
2063 | <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' /> |
---|
2064 | <label for="align-none" class="align image-align-none-label">' . __('None') . '</label> |
---|
2065 | <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' /> |
---|
2066 | <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label> |
---|
2067 | <input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' /> |
---|
2068 | <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label> |
---|
2069 | <input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' /> |
---|
2070 | <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label> |
---|
2071 | </td> |
---|
2072 | </tr> |
---|
2073 | |
---|
2074 | <tr> |
---|
2075 | <th valign="top" scope="row" class="label"> |
---|
2076 | <span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span> |
---|
2077 | </th> |
---|
2078 | <td class="field"><input id="url" name="url" value="" type="text" /><br /> |
---|
2079 | |
---|
2080 | <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button> |
---|
2081 | <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button> |
---|
2082 | <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td> |
---|
2083 | </tr> |
---|
2084 | ' . _insert_into_post_button('image') . ' |
---|
2085 | </tbody></table> |
---|
2086 | '; |
---|
2087 | |
---|
2088 | } |
---|
2089 | |
---|
2090 | /** |
---|
2091 | * {@internal Missing Short Description}} |
---|
2092 | * |
---|
2093 | * @since unknown |
---|
2094 | * |
---|
2095 | * @return unknown |
---|
2096 | */ |
---|
2097 | function type_url_form_audio() { |
---|
2098 | return ' |
---|
2099 | <table class="describe"><tbody> |
---|
2100 | <tr> |
---|
2101 | <th valign="top" scope="row" class="label"> |
---|
2102 | <span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span> |
---|
2103 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
---|
2104 | </th> |
---|
2105 | <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td> |
---|
2106 | </tr> |
---|
2107 | <tr> |
---|
2108 | <th valign="top" scope="row" class="label"> |
---|
2109 | <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span> |
---|
2110 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
---|
2111 | </th> |
---|
2112 | <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td> |
---|
2113 | </tr> |
---|
2114 | <tr><td></td><td class="help">' . __('Link text, e.g. “Still Alive by Jonathan Coulton”') . '</td></tr> |
---|
2115 | ' . _insert_into_post_button('audio') . ' |
---|
2116 | </tbody></table> |
---|
2117 | '; |
---|
2118 | } |
---|
2119 | |
---|
2120 | /** |
---|
2121 | * {@internal Missing Short Description}} |
---|
2122 | * |
---|
2123 | * @since unknown |
---|
2124 | * |
---|
2125 | * @return unknown |
---|
2126 | */ |
---|
2127 | function type_url_form_video() { |
---|
2128 | return ' |
---|
2129 | <table class="describe"><tbody> |
---|
2130 | <tr> |
---|
2131 | <th valign="top" scope="row" class="label"> |
---|
2132 | <span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span> |
---|
2133 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
---|
2134 | </th> |
---|
2135 | <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td> |
---|
2136 | </tr> |
---|
2137 | <tr> |
---|
2138 | <th valign="top" scope="row" class="label"> |
---|
2139 | <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span> |
---|
2140 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
---|
2141 | </th> |
---|
2142 | <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td> |
---|
2143 | </tr> |
---|
2144 | <tr><td></td><td class="help">' . __('Link text, e.g. “Lucy on YouTube”') . '</td></tr> |
---|
2145 | ' . _insert_into_post_button('video') . ' |
---|
2146 | </tbody></table> |
---|
2147 | '; |
---|
2148 | } |
---|
2149 | |
---|
2150 | /** |
---|
2151 | * {@internal Missing Short Description}} |
---|
2152 | * |
---|
2153 | * @since unknown |
---|
2154 | * |
---|
2155 | * @return unknown |
---|
2156 | */ |
---|
2157 | function type_url_form_file() { |
---|
2158 | return ' |
---|
2159 | <table class="describe"><tbody> |
---|
2160 | <tr> |
---|
2161 | <th valign="top" scope="row" class="label"> |
---|
2162 | <span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span> |
---|
2163 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
---|
2164 | </th> |
---|
2165 | <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td> |
---|
2166 | </tr> |
---|
2167 | <tr> |
---|
2168 | <th valign="top" scope="row" class="label"> |
---|
2169 | <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span> |
---|
2170 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
---|
2171 | </th> |
---|
2172 | <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td> |
---|
2173 | </tr> |
---|
2174 | <tr><td></td><td class="help">' . __('Link text, e.g. “Ransom Demands (PDF)”') . '</td></tr> |
---|
2175 | ' . _insert_into_post_button('file') . ' |
---|
2176 | </tbody></table> |
---|
2177 | '; |
---|
2178 | } |
---|
2179 | |
---|
2180 | |
---|
2181 | function _insert_into_post_button($type) { |
---|
2182 | if ( !post_type_supports(get_post_type($_GET['post_id']), 'editor') ) |
---|
2183 | return ''; |
---|
2184 | |
---|
2185 | if ( 'image' == $type ) |
---|
2186 | return ' |
---|
2187 | <tr> |
---|
2188 | <td></td> |
---|
2189 | <td> |
---|
2190 | <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" /> |
---|
2191 | </td> |
---|
2192 | </tr> |
---|
2193 | '; |
---|
2194 | |
---|
2195 | return ' |
---|
2196 | <tr> |
---|
2197 | <td></td> |
---|
2198 | <td> |
---|
2199 | <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" /> |
---|
2200 | </td> |
---|
2201 | </tr> |
---|
2202 | '; |
---|
2203 | } |
---|
2204 | |
---|
2205 | /** |
---|
2206 | * {@internal Missing Short Description}} |
---|
2207 | * |
---|
2208 | * Support a GET parameter for disabling the flash uploader. |
---|
2209 | * |
---|
2210 | * @since unknown |
---|
2211 | * |
---|
2212 | * @param unknown_type $flash |
---|
2213 | * @return unknown |
---|
2214 | */ |
---|
2215 | function media_upload_use_flash($flash) { |
---|
2216 | if ( array_key_exists('flash', $_REQUEST) ) |
---|
2217 | $flash = !empty($_REQUEST['flash']); |
---|
2218 | return $flash; |
---|
2219 | } |
---|
2220 | |
---|
2221 | add_filter('flash_uploader', 'media_upload_use_flash'); |
---|
2222 | |
---|
2223 | /** |
---|
2224 | * {@internal Missing Short Description}} |
---|
2225 | * |
---|
2226 | * @since unknown |
---|
2227 | */ |
---|
2228 | function media_upload_flash_bypass() { |
---|
2229 | echo '<p class="upload-flash-bypass">'; |
---|
2230 | printf( __('You are using the Flash uploader. Problems? Try the <a href="%s">Browser uploader</a> instead.'), esc_url(add_query_arg('flash', 0)) ); |
---|
2231 | echo '</p>'; |
---|
2232 | } |
---|
2233 | |
---|
2234 | /** |
---|
2235 | * {@internal Missing Short Description}} |
---|
2236 | * |
---|
2237 | * @since unknown |
---|
2238 | */ |
---|
2239 | function media_upload_html_bypass($flash = true) { |
---|
2240 | echo '<p class="upload-html-bypass hide-if-no-js">'; |
---|
2241 | _e('You are using the Browser uploader.'); |
---|
2242 | if ( $flash ) { |
---|
2243 | // the user manually selected the browser uploader, so let them switch back to Flash |
---|
2244 | echo ' '; |
---|
2245 | printf( __('Try the <a href="%s">Flash uploader</a> instead.'), esc_url(add_query_arg('flash', 1)) ); |
---|
2246 | } |
---|
2247 | echo "</p>\n"; |
---|
2248 | } |
---|
2249 | |
---|
2250 | add_action('post-flash-upload-ui', 'media_upload_flash_bypass'); |
---|
2251 | add_action('post-html-upload-ui', 'media_upload_html_bypass'); |
---|
2252 | |
---|
2253 | /** |
---|
2254 | * {@internal Missing Short Description}} |
---|
2255 | * |
---|
2256 | * Make sure the GET parameter sticks when we submit a form. |
---|
2257 | * |
---|
2258 | * @since unknown |
---|
2259 | * |
---|
2260 | * @param unknown_type $url |
---|
2261 | * @return unknown |
---|
2262 | */ |
---|
2263 | function media_upload_bypass_url($url) { |
---|
2264 | if ( array_key_exists('flash', $_REQUEST) ) |
---|
2265 | $url = add_query_arg('flash', intval($_REQUEST['flash'])); |
---|
2266 | return $url; |
---|
2267 | } |
---|
2268 | |
---|
2269 | add_filter('media_upload_form_url', 'media_upload_bypass_url'); |
---|
2270 | |
---|
2271 | add_filter('async_upload_image', 'get_media_item', 10, 2); |
---|
2272 | add_filter('async_upload_audio', 'get_media_item', 10, 2); |
---|
2273 | add_filter('async_upload_video', 'get_media_item', 10, 2); |
---|
2274 | add_filter('async_upload_file', 'get_media_item', 10, 2); |
---|
2275 | |
---|
2276 | add_action('media_upload_image', 'media_upload_image'); |
---|
2277 | add_action('media_upload_audio', 'media_upload_audio'); |
---|
2278 | add_action('media_upload_video', 'media_upload_video'); |
---|
2279 | add_action('media_upload_file', 'media_upload_file'); |
---|
2280 | |
---|
2281 | add_filter('media_upload_gallery', 'media_upload_gallery'); |
---|
2282 | |
---|
2283 | add_filter('media_upload_library', 'media_upload_library'); |
---|