3 * WordPress Administration Media API.
6 * @subpackage Administration
10 * {@internal Missing Short Description}}
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')
24 return apply_filters('media_upload_tabs', $_default_tabs);
28 * {@internal Missing Short Description}}
32 * @param unknown_type $tabs
35 function update_gallery_tab($tabs) {
38 if ( !isset($_REQUEST['post_id']) ) {
39 unset($tabs['gallery']);
43 $post_id = intval($_REQUEST['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 ) ) );
48 if ( empty($attachments) ) {
49 unset($tabs['gallery']);
53 $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
57 add_filter('media_upload_tabs', 'update_gallery_tab');
60 * {@internal Missing Short Description}}
64 function the_media_upload_tabs() {
66 $tabs = media_upload_tabs();
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'];
75 $current = apply_filters('media_upload_default_tab', 'type');
77 foreach ( $tabs as $callback => $text ) {
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";
90 * {@internal Missing Short Description}}
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
103 function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') {
105 $html = get_image_tag($id, $alt, $title, $align, $size);
107 $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : '';
110 $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>";
112 $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt );
118 * {@internal Missing Short Description}}
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
131 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
133 if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
136 $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
138 if ( ! preg_match( '/width="([0-9]+)/', $html, $matches ) )
141 $width = $matches[1];
143 $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
147 $shcode = '[caption id="' . $id . '" align="align' . $align
148 . '" width="' . $width . '" caption="' . addslashes($caption) . '"]' . $html . '[/caption]';
150 return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
152 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 );
155 * {@internal Missing Short Description}}
159 * @param unknown_type $html
161 function media_send_to_editor($html) {
163 <script type="text/javascript">
165 var win = window.dialogArguments || opener || parent || top;
166 win.send_to_editor('<?php echo addslashes($html); ?>');
174 * {@internal Missing Short Description}}
176 * This handles the file upload POST itself, creating the attachment post.
180 * @param unknown_type $file_id
181 * @param unknown_type $post_id
182 * @param unknown_type $post_data
185 function media_handle_upload($file_id, $post_id, $post_data = array()) {
186 $overrides = array('test_form'=>false);
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;
194 $name = $_FILES[$file_id]['name'];
195 $file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
197 if ( isset($file['error']) )
198 return new WP_Error( 'upload_error', $file['error'] );
200 $name_parts = pathinfo($name);
201 $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) );
204 $type = $file['type'];
205 $file = $file['file'];
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']) )
212 $title = $image_meta['title'];
213 if ( trim($image_meta['caption']) )
214 $content = $image_meta['caption'];
217 // Construct the attachment array
218 $attachment = array_merge( array(
219 'post_mime_type' => $type,
221 'post_parent' => $post_id,
222 'post_title' => $title,
223 'post_content' => $content,
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 ) );
237 * {@internal Missing Short Description}}
241 * @param unknown_type $file_array
242 * @param unknown_type $post_id
243 * @param unknown_type $desc
244 * @param unknown_type $post_data
247 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
248 $overrides = array('test_form'=>false);
250 $file = wp_handle_sideload($file_array, $overrides);
251 if ( isset($file['error']) )
252 return new WP_Error( 'upload_error', $file['error'] );
255 $type = $file['type'];
256 $file = $file['file'];
257 $title = preg_replace('/\.[^.]+$/', '', basename($file));
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']) )
263 $title = $image_meta['title'];
264 if ( trim($image_meta['caption']) )
265 $content = $image_meta['caption'];
270 // Construct the attachment array
271 $attachment = array_merge( array(
272 'post_mime_type' => $type,
274 'post_parent' => $post_id,
275 'post_title' => $title,
276 'post_content' => $content,
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 ) );
289 * {@internal Missing Short Description}}
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.
296 * @param unknown_type $content_func
298 function wp_iframe($content_func /* ... */) {
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(); ?>>
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>
306 wp_enqueue_style( 'global' );
307 wp_enqueue_style( 'wp-admin' );
308 wp_enqueue_style( 'colors' );
309 if ( 0 === strpos( $content_func, 'media' ) )
310 wp_enqueue_style( 'media' );
311 wp_enqueue_style( 'ie' );
313 <script type="text/javascript">
315 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();}}};
316 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(); ?>'};
317 var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup';
321 do_action('admin_enqueue_scripts', 'media-upload-popup');
322 do_action('admin_print_styles-media-upload-popup');
323 do_action('admin_print_styles');
324 do_action('admin_print_scripts-media-upload-popup');
325 do_action('admin_print_scripts');
326 do_action('admin_head-media-upload-popup');
327 do_action('admin_head');
329 if ( is_string($content_func) )
330 do_action( "admin_head_{$content_func}" );
333 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>>
335 $args = func_get_args();
336 $args = array_slice($args, 1);
337 call_user_func_array($content_func, $args);
339 do_action('admin_print_footer_scripts');
341 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
348 * {@internal Missing Short Description}}
352 function media_buttons() {
353 global $post_ID, $temp_ID;
354 $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
355 $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
356 $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
357 $media_title = __('Add Media');
358 $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&type=image");
359 $image_title = __('Add an Image');
360 $video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src&type=video");
361 $video_title = __('Add Video');
362 $audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src&type=audio");
363 $audio_title = __('Add Audio');
366 <a href="{$image_upload_iframe_src}&TB_iframe=true" id="add_image" class="thickbox" title='$image_title' onclick="return false;"><img src='images/media-button-image.gif' alt='$image_title' /></a>
367 <a href="{$video_upload_iframe_src}&TB_iframe=true" id="add_video" class="thickbox" title='$video_title' onclick="return false;"><img src='images/media-button-video.gif' alt='$video_title' /></a>
368 <a href="{$audio_upload_iframe_src}&TB_iframe=true" id="add_audio" class="thickbox" title='$audio_title' onclick="return false;"><img src='images/media-button-music.gif' alt='$audio_title' /></a>
369 <a href="{$media_upload_iframe_src}&TB_iframe=true" id="add_media" class="thickbox" title='$media_title' onclick="return false;"><img src='images/media-button-other.gif' alt='$media_title' /></a>
372 printf($context, $out);
374 add_action( 'media_buttons', 'media_buttons' );
377 * {@internal Missing Short Description}}
383 function media_upload_form_handler() {
384 check_admin_referer('media-form');
388 if ( isset($_POST['send']) ) {
389 $keys = array_keys($_POST['send']);
390 $send_id = (int) array_shift($keys);
393 if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
394 $post = $_post = get_post($attachment_id, ARRAY_A);
395 if ( isset($attachment['post_content']) )
396 $post['post_content'] = $attachment['post_content'];
397 if ( isset($attachment['post_title']) )
398 $post['post_title'] = $attachment['post_title'];
399 if ( isset($attachment['post_excerpt']) )
400 $post['post_excerpt'] = $attachment['post_excerpt'];
401 if ( isset($attachment['menu_order']) )
402 $post['menu_order'] = $attachment['menu_order'];
404 if ( isset($send_id) && $attachment_id == $send_id ) {
405 if ( isset($attachment['post_parent']) )
406 $post['post_parent'] = $attachment['post_parent'];
409 $post = apply_filters('attachment_fields_to_save', $post, $attachment);
411 if ( isset($attachment['image_alt']) && !empty($attachment['image_alt']) ) {
412 $image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
413 if ( $image_alt != stripslashes($attachment['image_alt']) ) {
414 $image_alt = wp_strip_all_tags( stripslashes($attachment['image_alt']), true );
415 // update_meta expects slashed
416 update_post_meta( $attachment_id, '_wp_attachment_image_alt', addslashes($image_alt) );
420 if ( isset($post['errors']) ) {
421 $errors[$attachment_id] = $post['errors'];
422 unset($post['errors']);
425 if ( $post != $_post )
426 wp_update_post($post);
428 foreach ( get_attachment_taxonomies($post) as $t ) {
429 if ( isset($attachment[$t]) )
430 wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
434 if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?>
435 <script type="text/javascript">
437 var win = window.dialogArguments || opener || parent || top;
445 if ( isset($send_id) ) {
446 $attachment = stripslashes_deep( $_POST['attachments'][$send_id] );
448 $html = $attachment['post_title'];
449 if ( !empty($attachment['url']) ) {
450 if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
451 $rel = " rel='attachment wp-att-" . esc_attr($send_id)."'";
452 $html = "<a href='{$attachment['url']}'$rel>$html</a>";
455 $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
456 return media_send_to_editor($html);
463 * {@internal Missing Short Description}}
469 function media_upload_image() {
473 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
474 // Upload File button was clicked
475 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
477 if ( is_wp_error($id) ) {
478 $errors['upload_error'] = $id;
483 if ( !empty($_POST['insertonlybutton']) ) {
486 $src = $_POST['insertonly']['src'];
487 if ( !empty($src) && !strpos($src, '://') )
488 $src = "http://$src";
489 $alt = esc_attr($_POST['insertonly']['alt']);
490 if ( isset($_POST['insertonly']['align']) ) {
491 $align = esc_attr($_POST['insertonly']['align']);
492 $class = " class='align$align'";
495 $html = "<img src='" . esc_url($src) . "' alt='$alt'$class />";
497 $html = apply_filters('image_send_to_editor_url', $html, esc_url_raw($src), $alt, $align);
498 return media_send_to_editor($html);
501 if ( !empty($_POST) ) {
502 $return = media_upload_form_handler();
504 if ( is_string($return) )
506 if ( is_array($return) )
510 if ( isset($_POST['save']) ) {
511 $errors['upload_notice'] = __('Saved.');
512 return media_upload_gallery();
515 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
516 return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id );
518 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
522 * {@internal Missing Short Description}}
526 * @param unknown_type $file
527 * @param unknown_type $post_id
528 * @param unknown_type $desc
531 function media_sideload_image($file, $post_id, $desc = null) {
532 if (!empty($file) ) {
533 // Download file to temp location
534 $tmp = download_url($file);
536 // Set variables for storage
537 // fix file filename for query strings
538 preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
539 $file_array['name'] = basename($matches[0]);
540 $file_array['tmp_name'] = $tmp;
542 // If error storing temporarily, unlink
543 if ( is_wp_error($tmp) ) {
544 @unlink($file_array['tmp_name']);
545 $file_array['tmp_name'] = '';
548 // do the validation and storage stuff
549 $id = media_handle_sideload($file_array, $post_id, @$desc);
552 // If error storing permanently, unlink
553 if ( is_wp_error($id) ) {
554 @unlink($file_array['tmp_name']);
559 // Finally check to make sure the file has been saved, then return the html
560 if ( !empty($src) ) {
562 $html = "<img src='$src' alt='$alt' />";
568 * {@internal Missing Short Description}}
574 function media_upload_audio() {
578 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
579 // Upload File button was clicked
580 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
582 if ( is_wp_error($id) ) {
583 $errors['upload_error'] = $id;
588 if ( !empty($_POST['insertonlybutton']) ) {
589 $href = $_POST['insertonly']['href'];
590 if ( !empty($href) && !strpos($href, '://') )
591 $href = "http://$href";
593 $title = esc_attr($_POST['insertonly']['title']);
595 $title = esc_attr( basename($href) );
597 if ( !empty($title) && !empty($href) )
598 $html = "<a href='" . esc_url($href) . "' >$title</a>";
600 $html = apply_filters('audio_send_to_editor_url', $html, $href, $title);
602 return media_send_to_editor($html);
605 if ( !empty($_POST) ) {
606 $return = media_upload_form_handler();
608 if ( is_string($return) )
610 if ( is_array($return) )
614 if ( isset($_POST['save']) ) {
615 $errors['upload_notice'] = __('Saved.');
616 return media_upload_gallery();
619 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
620 return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id );
622 return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
626 * {@internal Missing Short Description}}
632 function media_upload_video() {
636 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
637 // Upload File button was clicked
638 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
640 if ( is_wp_error($id) ) {
641 $errors['upload_error'] = $id;
646 if ( !empty($_POST['insertonlybutton']) ) {
647 $href = $_POST['insertonly']['href'];
648 if ( !empty($href) && !strpos($href, '://') )
649 $href = "http://$href";
651 $title = esc_attr($_POST['insertonly']['title']);
653 $title = esc_attr( basename($href) );
655 if ( !empty($title) && !empty($href) )
656 $html = "<a href='" . esc_url($href) . "' >$title</a>";
658 $html = apply_filters('video_send_to_editor_url', $html, $href, $title);
660 return media_send_to_editor($html);
663 if ( !empty($_POST) ) {
664 $return = media_upload_form_handler();
666 if ( is_string($return) )
668 if ( is_array($return) )
672 if ( isset($_POST['save']) ) {
673 $errors['upload_notice'] = __('Saved.');
674 return media_upload_gallery();
677 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
678 return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id );
680 return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
684 * {@internal Missing Short Description}}
690 function media_upload_file() {
694 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
695 // Upload File button was clicked
696 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
698 if ( is_wp_error($id) ) {
699 $errors['upload_error'] = $id;
704 if ( !empty($_POST['insertonlybutton']) ) {
705 $href = $_POST['insertonly']['href'];
706 if ( !empty($href) && !strpos($href, '://') )
707 $href = "http://$href";
709 $title = esc_attr($_POST['insertonly']['title']);
711 $title = basename($href);
712 if ( !empty($title) && !empty($href) )
713 $html = "<a href='" . esc_url($href) . "' >$title</a>";
714 $html = apply_filters('file_send_to_editor_url', $html, esc_url_raw($href), $title);
715 return media_send_to_editor($html);
718 if ( !empty($_POST) ) {
719 $return = media_upload_form_handler();
721 if ( is_string($return) )
723 if ( is_array($return) )
727 if ( isset($_POST['save']) ) {
728 $errors['upload_notice'] = __('Saved.');
729 return media_upload_gallery();
732 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
733 return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id );
735 return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
739 * {@internal Missing Short Description}}
745 function media_upload_gallery() {
748 if ( !empty($_POST) ) {
749 $return = media_upload_form_handler();
751 if ( is_string($return) )
753 if ( is_array($return) )
757 wp_enqueue_script('admin-gallery');
758 return wp_iframe( 'media_upload_gallery_form', $errors );
762 * {@internal Missing Short Description}}
768 function media_upload_library() {
770 if ( !empty($_POST) ) {
771 $return = media_upload_form_handler();
773 if ( is_string($return) )
775 if ( is_array($return) )
779 return wp_iframe( 'media_upload_library_form', $errors );
783 * Retrieve HTML for the image alignment radio buttons with the specified one checked.
787 * @param unknown_type $post
788 * @param unknown_type $checked
791 function image_align_input_fields( $post, $checked = '' ) {
793 if ( empty($checked) )
794 $checked = get_user_setting('align', 'none');
796 $alignments = array('none' => __('None'), 'left' => __('Left'), 'center' => __('Center'), 'right' => __('Right'));
797 if ( !array_key_exists( (string) $checked, $alignments ) )
801 foreach ( $alignments as $name => $label ) {
802 $name = esc_attr($name);
803 $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'".
804 ( $checked == $name ? " checked='checked'" : "" ) .
805 " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
807 return join("\n", $out);
811 * Retrieve HTML for the size radio buttons with the specified one checked.
815 * @param unknown_type $post
816 * @param unknown_type $checked
819 function image_size_input_fields( $post, $check = '' ) {
821 // get a list of the actual pixel dimensions of each possible intermediate version of this image
822 $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size'));
825 $check = get_user_setting('imgsize', 'medium');
827 foreach ( $size_names as $size => $label ) {
828 $downsize = image_downsize($post->ID, $size);
831 // is this size selectable?
832 $enabled = ( $downsize[3] || 'full' == $size );
833 $css_id = "image-size-{$size}-{$post->ID}";
834 // if this size is the default but that's not available, don't select it
835 if ( $size == $check ) {
837 $checked = " checked='checked'";
840 } elseif ( !$check && $enabled && 'thumbnail' != $size ) {
841 // if $check is not enabled, default to the first available size that's bigger than a thumbnail
843 $checked = " checked='checked'";
846 $html = "<div class='image-size-item'><input type='radio' " . ( $enabled ? '' : "disabled='disabled' " ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
848 $html .= "<label for='{$css_id}'>$label</label>";
849 // only show the dimensions if that choice is available
851 $html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d × %d)"), $downsize[1], $downsize[2] ). "</label>";
859 'label' => __('Size'),
861 'html' => join("\n", $out),
866 * Retrieve HTML for the Link URL buttons with the default link type as specified.
870 * @param unknown_type $post
871 * @param unknown_type $url_type
874 function image_link_input_fields($post, $url_type = '') {
876 $file = wp_get_attachment_url($post->ID);
877 $link = get_attachment_link($post->ID);
879 if ( empty($url_type) )
880 $url_type = get_user_setting('urlbutton', 'post');
883 if ( $url_type == 'file' )
885 elseif ( $url_type == 'post' )
889 <input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
890 <button type='button' class='button urlnone' title=''>" . __('None') . "</button>
891 <button type='button' class='button urlfile' title='" . esc_attr($file) . "'>" . __('File URL') . "</button>
892 <button type='button' class='button urlpost' title='" . esc_attr($link) . "'>" . __('Post URL') . "</button>
897 * {@internal Missing Short Description}}
901 * @param unknown_type $form_fields
902 * @param unknown_type $post
905 function image_attachment_fields_to_edit($form_fields, $post) {
906 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
907 $alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
911 $form_fields['post_title']['required'] = true;
913 $form_fields['image_alt'] = array(
915 'label' => __('Alternate text'),
916 'helps' => __('Alt text for the image, e.g. “The Mona Lisa”')
919 $form_fields['align'] = array(
920 'label' => __('Alignment'),
922 'html' => image_align_input_fields($post, get_option('image_default_align')),
925 $form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size', 'medium') );
928 unset( $form_fields['image_alt'] );
933 add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
936 * {@internal Missing Short Description}}
940 * @param unknown_type $form_fields
941 * @param unknown_type $post
944 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
945 unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
949 function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
950 unset($form_fields['image_url']);
955 * {@internal Missing Short Description}}
959 * @param unknown_type $post
960 * @param unknown_type $attachment
963 function image_attachment_fields_to_save($post, $attachment) {
964 if ( substr($post['post_mime_type'], 0, 5) == 'image' ) {
965 if ( strlen(trim($post['post_title'])) == 0 ) {
966 $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid']));
967 $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.');
974 add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2);
977 * {@internal Missing Short Description}}
981 * @param unknown_type $html
982 * @param unknown_type $attachment_id
983 * @param unknown_type $attachment
986 function image_media_send_to_editor($html, $attachment_id, $attachment) {
987 $post =& get_post($attachment_id);
988 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
989 $url = $attachment['url'];
990 $align = !empty($attachment['align']) ? $attachment['align'] : 'none';
991 $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium';
992 $alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : '';
993 $rel = ( $url == get_attachment_link($attachment_id) );
995 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt);
1001 add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3);
1004 * {@internal Missing Short Description}}
1008 * @param unknown_type $post
1009 * @param unknown_type $errors
1012 function get_attachment_fields_to_edit($post, $errors = null) {
1013 if ( is_int($post) )
1014 $post =& get_post($post);
1015 if ( is_array($post) )
1016 $post = (object) $post;
1018 $image_url = wp_get_attachment_url($post->ID);
1020 $edit_post = sanitize_post($post, 'edit');
1022 $form_fields = array(
1023 'post_title' => array(
1024 'label' => __('Title'),
1025 'value' => $edit_post->post_title
1027 'image_alt' => array(),
1028 'post_excerpt' => array(
1029 'label' => __('Caption'),
1030 'value' => $edit_post->post_excerpt
1032 'post_content' => array(
1033 'label' => __('Description'),
1034 'value' => $edit_post->post_content,
1035 'input' => 'textarea'
1038 'label' => __('Link URL'),
1040 'html' => image_link_input_fields($post, get_option('image_default_link_type')),
1041 'helps' => __('Enter a link URL or click above for presets.')
1043 'menu_order' => array(
1044 'label' => __('Order'),
1045 'value' => $edit_post->menu_order
1047 'image_url' => array(
1048 'label' => __('File URL'),
1050 'html' => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr($image_url) . "' /><br />",
1051 'value' => wp_get_attachment_url($post->ID),
1052 'helps' => __('Location of the uploaded file.')
1056 foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
1057 $t = (array) get_taxonomy($taxonomy);
1058 if ( empty($t['label']) )
1059 $t['label'] = $taxonomy;
1060 if ( empty($t['args']) )
1061 $t['args'] = array();
1063 $terms = get_object_term_cache($post->ID, $taxonomy);
1064 if ( empty($terms) )
1065 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
1069 foreach ( $terms as $term )
1070 $values[] = $term->name;
1071 $t['value'] = join(', ', $values);
1073 $form_fields[$taxonomy] = $t;
1076 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
1077 // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
1078 $form_fields = array_merge_recursive($form_fields, (array) $errors);
1080 $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
1082 return $form_fields;
1086 * Retrieve HTML for media items of post gallery.
1088 * The HTML markup retrieved will be created for the progress of SWF Upload
1089 * component. Will also create link for showing and hiding the form to modify
1090 * the image attachment.
1094 * @param int $post_id Optional. Post ID.
1095 * @param array $errors Errors for attachment, if any.
1098 function get_media_items( $post_id, $errors ) {
1100 $post = get_post($post_id);
1101 if ( $post && $post->post_type == 'attachment' )
1102 $attachments = array($post->ID => $post);
1104 $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
1106 if ( is_array($GLOBALS['wp_the_query']->posts) )
1107 foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
1108 $attachments[$attachment->ID] = $attachment;
1112 foreach ( (array) $attachments as $id => $attachment ) {
1113 if ( $attachment->post_status == 'trash' )
1115 if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
1116 $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>";
1123 * Retrieve HTML form for modifying the image attachment.
1127 * @param int $attachment_id Attachment ID for modification.
1128 * @param string|array $args Optional. Override defaults.
1129 * @return string HTML form for attachment.
1131 function get_media_item( $attachment_id, $args = null ) {
1134 if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) )
1135 $thumb_url = $thumb_url[0];
1139 $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true, 'show_title' => true );
1140 $args = wp_parse_args( $args, $default_args );
1141 extract( $args, EXTR_SKIP );
1143 $toggle_on = __('Show');
1144 $toggle_off = __('Hide');
1146 $post = get_post($attachment_id);
1148 $filename = basename($post->guid);
1149 $title = esc_attr($post->post_title);
1151 if ( $_tags = get_the_tags($attachment_id) ) {
1152 foreach ( $_tags as $tag )
1153 $tags[] = $tag->name;
1154 $tags = esc_attr(join(', ', $tags));
1157 $post_mime_types = get_post_mime_types();
1158 $keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type));
1159 $type = array_shift($keys);
1160 $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
1162 $form_fields = get_attachment_fields_to_edit($post, $errors);
1165 $class = empty($errors) ? 'startclosed' : 'startopen';
1167 <a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
1168 <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
1170 $class = 'form-table';
1174 $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
1175 $display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt($display_title, 60) . "</span></div>" : '';
1177 $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false;
1180 foreach ( $form_fields as $key => $val ) {
1181 if ( 'menu_order' == $key ) {
1183 $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="'.$val['value'].'" /></div>';
1185 $order = '<input type="hidden" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" />';
1187 unset($form_fields['menu_order']);
1193 $meta = wp_get_attachment_metadata($post->ID);
1194 if ( is_array($meta) && array_key_exists('width', $meta) && array_key_exists('height', $meta) )
1195 $media_dims .= "<span id='media-dims-{$post->ID}'>{$meta['width']} × {$meta['height']}</span> ";
1196 $media_dims = apply_filters('media_meta', $media_dims, $post);
1198 $image_edit_button = '';
1199 if ( gd_edit_image_support($post->post_mime_type) ) {
1200 $nonce = wp_create_nonce("image_editor-$post->ID");
1201 $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='images/wpspin_light.gif' class='imgedit-wait-spin' alt='' />";
1209 <table class='slidetoggle describe $class'>
1210 <thead class='media-item-info' id='media-head-$post->ID'>
1212 <td class='A1B1' id='thumbnail-head-$post->ID' rowspan='5'><img class='thumbnail' src='$thumb_url' alt='' /></td>
1213 <td><strong>" . __('File name:') . "</strong> $filename</td>
1215 <tr><td><strong>" . __('File type:') . "</strong> $post->post_mime_type</td></tr>
1216 <tr><td><strong>" . __('Upload date:') . "</strong> " . mysql2date( get_option('date_format'), $post->post_date ) . "</td></tr>\n";
1218 if ( !empty($media_dims) )
1219 $item .= "<tr><td><strong>" . __('Dimensions:') . "</strong> $media_dims</td></tr>\n";
1222 <tr><td class='A1B1'>$image_edit_button</td></tr>
1225 <tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>
1226 <tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n";
1230 'required' => false,
1232 'extra_rows' => array(),
1236 $send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . esc_attr__( 'Insert into Post' ) . "' />";
1237 if ( $delete && current_user_can('delete_post', $attachment_id) ) {
1238 if ( !EMPTY_TRASH_DAYS ) {
1239 $delete = "<a href=\"" . wp_nonce_url("post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id) . "\" id=\"del[$attachment_id]\" class=\"delete\">" . __('Delete Permanently') . "</a>";
1240 } elseif ( !MEDIA_TRASH ) {
1241 $delete = "<a href=\"#\" class=\"del-link\" onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __('Delete') . "</a> <div id=\"del_attachment_$attachment_id\" class=\"del-attachment\" style=\"display:none;\">" . sprintf(__("You are about to delete <strong>%s</strong>."), $filename) . " <a href=\"" . wp_nonce_url("post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id) . "\" id=\"del[$attachment_id]\" class=\"button\">" . __('Continue') . "</a> <a href=\"#\" class=\"button\" onclick=\"this.parentNode.style.display='none';return false;\">" . __('Cancel') . "</a></div>";
1243 $delete = "<a href=\"" . wp_nonce_url("post.php?action=trash&post=$attachment_id", 'trash-post_' . $attachment_id) . "\" id=\"del[$attachment_id]\" class=\"delete\">" . __('Move to Trash') . "</a> <a href=\"" . wp_nonce_url("post.php?action=untrash&post=$attachment_id", 'untrash-post_' . $attachment_id) . "\" id=\"undo[$attachment_id]\" class=\"undo hidden\">" . __('Undo') . "</a>";
1250 $calling_post_id = 0;
1251 if ( isset( $_GET['post_id'] ) )
1252 $calling_post_id = $_GET['post_id'];
1253 elseif ( isset( $_POST ) && count( $_POST ) ) // Like for async-upload where $_GET['post_id'] isn't set
1254 $calling_post_id = $post->post_parent;
1255 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 )
1256 $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\");return false;'>" . esc_html__( "Use as thumbnail" ) . "</a>";
1258 if ( ( $send || $thumbnail || $delete ) && !isset($form_fields['buttons']) )
1259 $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $thumbnail $delete</td></tr>\n");
1261 $hidden_fields = array();
1263 foreach ( $form_fields as $id => $field ) {
1264 if ( $id{0} == '_' )
1267 if ( !empty($field['tr']) ) {
1268 $item .= $field['tr'];
1272 $field = array_merge($defaults, $field);
1273 $name = "attachments[$attachment_id][$id]";
1275 if ( $field['input'] == 'hidden' ) {
1276 $hidden_fields[$name] = $field['value'];
1280 $required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : '';
1281 $aria_required = $field['required'] ? " aria-required='true' " : '';
1283 $class .= $field['required'] ? ' form-required' : '';
1285 $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><span class='alignright'>$required</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>";
1286 if ( !empty($field[$field['input']]) )
1287 $item .= $field[$field['input']];
1288 elseif ( $field['input'] == 'textarea' ) {
1289 $item .= "<textarea type='text' id='$name' name='$name'" . $aria_required . ">" . esc_html( $field['value'] ) . "</textarea>";
1291 $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'" . $aria_required . "/>";
1293 if ( !empty($field['helps']) )
1294 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique((array) $field['helps']) ) . '</p>';
1295 $item .= "</td>\n\t\t</tr>\n";
1297 $extra_rows = array();
1299 if ( !empty($field['errors']) )
1300 foreach ( array_unique((array) $field['errors']) as $error )
1301 $extra_rows['error'][] = $error;
1303 if ( !empty($field['extra_rows']) )
1304 foreach ( $field['extra_rows'] as $class => $rows )
1305 foreach ( (array) $rows as $html )
1306 $extra_rows[$class][] = $html;
1308 foreach ( $extra_rows as $class => $rows )
1309 foreach ( $rows as $html )
1310 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
1313 if ( !empty($form_fields['_final']) )
1314 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
1315 $item .= "\t</tbody>\n";
1316 $item .= "\t</table>\n";
1318 foreach ( $hidden_fields as $name => $value )
1319 $item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
1321 if ( $post->post_parent < 1 && isset($_REQUEST['post_id']) ) {
1322 $parent = (int) $_REQUEST['post_id'];
1323 $parent_name = "attachments[$attachment_id][post_parent]";
1325 $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='" . $parent . "' />\n";
1332 * {@internal Missing Short Description}}
1336 function media_upload_header() {
1338 <script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script>
1339 <div id="media-upload-header">
1340 <?php the_media_upload_tabs(); ?>
1346 * {@internal Missing Short Description}}
1350 * @param unknown_type $errors
1352 function media_upload_form( $errors = null ) {
1355 $flash_action_url = admin_url('async-upload.php');
1357 // If Mac and mod_security, no Flash. :(
1359 if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mac') && apache_mod_loaded('mod_security') )
1362 $flash = apply_filters('flash_uploader', $flash);
1363 $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
1366 <script type="text/javascript">
1368 var uploaderMode = 0;
1369 jQuery(document).ready(function($){
1370 uploaderMode = getUserSetting('uploader');
1371 $('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;});
1372 $('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;});
1376 <div id="media-upload-notice">
1377 <?php if (isset($errors['upload_notice']) ) { ?>
1378 <?php echo $errors['upload_notice']; ?>
1381 <div id="media-upload-error">
1382 <?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?>
1383 <?php echo $errors['upload_error']->get_error_message(); ?>
1387 <?php do_action('pre-upload-ui'); ?>
1389 <?php if ( $flash ) : ?>
1390 <script type="text/javascript">
1393 SWFUpload.onload = function() {
1395 button_text: '<span class="button"><?php _e('Select Files'); ?></span>',
1396 button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; }',
1397 button_height: "24",
1398 button_width: "132",
1399 button_text_top_padding: 2,
1400 button_image_url: '<?php echo includes_url('images/upload.png'); ?>',
1401 button_placeholder_id: "flash-browse-button",
1402 upload_url : "<?php echo esc_attr( $flash_action_url ); ?>",
1403 flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>",
1404 file_post_name: "async-upload",
1405 file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",
1407 "post_id" : "<?php echo $post_id; ?>",
1408 "auth_cookie" : "<?php if ( is_ssl() ) echo $_COOKIE[SECURE_AUTH_COOKIE]; else echo $_COOKIE[AUTH_COOKIE]; ?>",
1409 "logged_in_cookie": "<?php echo $_COOKIE[LOGGED_IN_COOKIE]; ?>",
1410 "_wpnonce" : "<?php echo wp_create_nonce('media-form'); ?>",
1411 "type" : "<?php echo $type; ?>",
1412 "tab" : "<?php echo $tab; ?>",
1415 file_size_limit : "<?php echo wp_max_upload_size(); ?>b",
1416 file_dialog_start_handler : fileDialogStart,
1417 file_queued_handler : fileQueued,
1418 upload_start_handler : uploadStart,
1419 upload_progress_handler : uploadProgress,
1420 upload_error_handler : uploadError,
1421 upload_success_handler : uploadSuccess,
1422 upload_complete_handler : uploadComplete,
1423 file_queue_error_handler : fileQueueError,
1424 file_dialog_complete_handler : fileDialogComplete,
1425 swfupload_pre_load_handler: swfuploadPreLoad,
1426 swfupload_load_failed_handler: swfuploadLoadFailed,
1428 degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable
1429 swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available
1433 swfu = new SWFUpload(settings);
1438 <div id="flash-upload-ui">
1439 <?php do_action('pre-flash-upload-ui'); ?>
1442 <?php _e( 'Choose files to upload' ); ?>
1443 <div id="flash-browse-button"></div>
1444 <span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span>
1446 <?php do_action('post-flash-upload-ui'); ?>
1447 <p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
1449 <?php endif; // $flash ?>
1451 <div id="html-upload-ui">
1452 <?php do_action('pre-html-upload-ui'); ?>
1453 <p id="async-upload-wrap">
1454 <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>
1455 <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>
1457 <div class="clear"></div>
1458 <?php if ( is_lighttpd_before_150() ): ?>
1459 <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>
1461 <?php do_action('post-html-upload-ui', $flash); ?>
1463 <?php do_action('post-upload-ui'); ?>
1468 * {@internal Missing Short Description}}
1472 * @param unknown_type $type
1473 * @param unknown_type $errors
1474 * @param unknown_type $id
1476 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
1477 media_upload_header();
1479 $post_id = intval($_REQUEST['post_id']);
1481 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
1482 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1485 <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">
1486 <input type="submit" class="hidden" name="save" value="" />
1487 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1488 <?php wp_nonce_field('media-form'); ?>
1490 <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
1492 <?php media_upload_form( $errors ); ?>
1494 <script type="text/javascript">
1497 var preloaded = $(".media-item.preloaded");
1498 if ( preloaded.length > 0 ) {
1499 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1505 <div id="media-items">
1508 if ( !is_wp_error($id) ) {
1509 add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
1510 echo get_media_items( $id, $errors );
1512 echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div>';
1518 <p class="savebutton ml-submit">
1519 <input type="submit" class="button" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
1525 * {@internal Missing Short Description}}
1529 * @param unknown_type $type
1530 * @param unknown_type $errors
1531 * @param unknown_type $id
1533 function media_upload_type_url_form($type = 'file', $errors = null, $id = null) {
1534 media_upload_header();
1536 $post_id = intval($_REQUEST['post_id']);
1538 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
1539 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1541 $callback = "type_url_form_$type";
1544 <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">
1545 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1546 <?php wp_nonce_field('media-form'); ?>
1548 <?php if ( is_callable($callback) ) { ?>
1550 <h3 class="media-title"><?php _e('Add media file from URL'); ?></h3>
1552 <script type="text/javascript">
1558 align : 'alignnone',
1560 insert : function() {
1561 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = '';
1563 if ( '' == f.src.value || '' == t.width )
1566 if ( f.title.value ) {
1567 title = f.title.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
1568 title = ' title="'+title+'"';
1572 alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
1574 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
1575 if ( f.caption.value )
1576 caption = f.caption.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
1579 cls = caption ? '' : ' class="'+t.align+'"';
1581 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
1584 html = '<a href="'+f.url.value+'">'+html+'</a>';
1587 html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';
1589 var win = window.dialogArguments || opener || parent || top;
1590 win.send_to_editor(html);
1594 resetImageData : function() {
1595 var t = addExtImage;
1597 t.width = t.height = '';
1598 document.getElementById('go_button').style.color = '#bbb';
1599 if ( ! document.forms[0].src.value )
1600 document.getElementById('status_img').innerHTML = '*';
1601 else document.getElementById('status_img').innerHTML = '<img src="images/no.png" alt="" />';
1604 updateImageData : function() {
1605 var t = addExtImage;
1607 t.width = t.preloadImg.width;
1608 t.height = t.preloadImg.height;
1609 document.getElementById('go_button').style.color = '#333';
1610 document.getElementById('status_img').innerHTML = '<img src="images/yes.png" alt="" />';
1613 getImageData : function() {
1614 var t = addExtImage, src = document.forms[0].src.value;
1620 document.getElementById('status_img').innerHTML = '<img src="images/wpspin_light.gif" alt="" />';
1621 t.preloadImg = new Image();
1622 t.preloadImg.onload = t.updateImageData;
1623 t.preloadImg.onerror = t.resetImageData;
1624 t.preloadImg.src = src;
1630 <div id="media-items">
1631 <div class="media-item media-blank">
1632 <?php echo apply_filters($callback, call_user_func($callback)); ?>
1638 wp_die( __('Unknown action.') );
1643 * {@internal Missing Short Description}}
1647 * @param unknown_type $errors
1649 function media_upload_gallery_form($errors) {
1650 global $redir_tab, $type;
1652 $redir_tab = 'gallery';
1653 media_upload_header();
1655 $post_id = intval($_REQUEST['post_id']);
1656 $form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id");
1657 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1660 <script type="text/javascript">
1663 var preloaded = $(".media-item.preloaded");
1664 if ( preloaded.length > 0 ) {
1665 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1671 <div id="sort-buttons" class="hide-if-no-js">
1673 <?php _e('All Tabs:'); ?>
1674 <a href="#" id="showall"><?php _e('Show'); ?></a>
1675 <a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a>
1677 <?php _e('Sort Order:'); ?>
1678 <a href="#" id="asc"><?php _e('Ascending'); ?></a> |
1679 <a href="#" id="desc"><?php _e('Descending'); ?></a> |
1680 <a href="#" id="clear"><?php echo _x('Clear', 'verb'); ?></a>
1682 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
1683 <?php wp_nonce_field('media-form'); ?>
1684 <?php //media_upload_form( $errors ); ?>
1685 <table class="widefat" cellspacing="0">
1687 <th><?php _e('Media'); ?></th>
1688 <th class="order-head"><?php _e('Order'); ?></th>
1689 <th class="actions-head"><?php _e('Actions'); ?></th>
1692 <div id="media-items">
1693 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
1694 <?php echo get_media_items($post_id, $errors); ?>
1697 <p class="ml-submit">
1698 <input type="submit" class="button savebutton" style="display:none;" name="save" id="save-all" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
1699 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1700 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
1701 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
1704 <div id="gallery-settings" style="display:none;">
1705 <div class="title"><?php _e('Gallery Settings'); ?></div>
1706 <table id="basic" class="describe"><tbody>
1708 <th scope="row" class="label">
1710 <span class="alignleft"><?php _e('Link thumbnails to:'); ?></span>
1714 <input type="radio" name="linkto" id="linkto-file" value="file" />
1715 <label for="linkto-file" class="radio"><?php _e('Image File'); ?></label>
1717 <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" />
1718 <label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label>
1723 <th scope="row" class="label">
1725 <span class="alignleft"><?php _e('Order images by:'); ?></span>
1729 <select id="orderby" name="orderby">
1730 <option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option>
1731 <option value="title"><?php _e('Title'); ?></option>
1732 <option value="ID"><?php _e('Date/Time'); ?></option>
1733 <option value="rand"><?php _e('Random'); ?></option>
1739 <th scope="row" class="label">
1741 <span class="alignleft"><?php _e('Order:'); ?></span>
1745 <input type="radio" checked="checked" name="order" id="order-asc" value="asc" />
1746 <label for="order-asc" class="radio"><?php _e('Ascending'); ?></label>
1748 <input type="radio" name="order" id="order-desc" value="desc" />
1749 <label for="order-desc" class="radio"><?php _e('Descending'); ?></label>
1754 <th scope="row" class="label">
1756 <span class="alignleft"><?php _e('Gallery columns:'); ?></span>
1760 <select id="columns" name="columns">
1761 <option value="2"><?php _e('2'); ?></option>
1762 <option value="3" selected="selected"><?php _e('3'); ?></option>
1763 <option value="4"><?php _e('4'); ?></option>
1764 <option value="5"><?php _e('5'); ?></option>
1765 <option value="6"><?php _e('6'); ?></option>
1766 <option value="7"><?php _e('7'); ?></option>
1767 <option value="8"><?php _e('8'); ?></option>
1768 <option value="9"><?php _e('9'); ?></option>
1774 <p class="ml-submit">
1775 <input type="button" class="button" style="display:none;" onmousedown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" />
1776 <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' ); ?>" />
1784 * {@internal Missing Short Description}}
1788 * @param unknown_type $errors
1790 function media_upload_library_form($errors) {
1791 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
1793 media_upload_header();
1795 $post_id = intval($_REQUEST['post_id']);
1797 $form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id");
1798 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1800 $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;
1801 if ( $_GET['paged'] < 1 )
1803 $start = ( $_GET['paged'] - 1 ) * 10;
1806 add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
1808 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1812 <form id="filter" action="" method="get">
1813 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />
1814 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />
1815 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
1816 <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" />
1818 <p id="media-search" class="search-box">
1819 <label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label>
1820 <input type="text" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />
1821 <input type="submit" value="<?php esc_attr_e( 'Search Media' ); ?>" class="button" />
1824 <ul class="subsubsub">
1826 $type_links = array();
1827 $_num_posts = (array) wp_count_attachments();
1828 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
1829 foreach ( $matches as $_type => $reals )
1830 foreach ( $reals as $real )
1831 if ( isset($num_posts[$_type]) )
1832 $num_posts[$_type] += $_num_posts[$real];
1834 $num_posts[$_type] = $_num_posts[$real];
1835 // If available type specified by media button clicked, filter by that type
1836 if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {
1837 $_GET['post_mime_type'] = $type;
1838 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1840 if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )
1841 $class = ' class="current"';
1844 $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>";
1845 foreach ( $post_mime_types as $mime_type => $label ) {
1848 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
1851 if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
1852 $class = ' class="current"';
1854 $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>';
1856 echo implode(' | </li>', $type_links) . '</li>';
1861 <div class="tablenav">
1864 $page_links = paginate_links( array(
1865 'base' => add_query_arg( 'paged', '%#%' ),
1867 'prev_text' => __('«'),
1868 'next_text' => __('»'),
1869 'total' => ceil($wp_query->found_posts / 10),
1870 'current' => $_GET['paged']
1874 echo "<div class='tablenav-pages'>$page_links</div>";
1877 <div class="alignleft actions">
1880 $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";
1882 $arc_result = $wpdb->get_results( $arc_query );
1884 $month_count = count($arc_result);
1886 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
1888 <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
1890 foreach ($arc_result as $arc_row) {
1891 if ( $arc_row->yyear == 0 )
1893 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
1895 if ( isset($_GET['m']) && ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] ) )
1896 $default = ' selected="selected"';
1900 echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>";
1901 echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" );
1908 <input type="submit" id="post-query-submit" value="<?php echo esc_attr( __( 'Filter »' ) ); ?>" class="button-secondary" />
1912 <br class="clear" />
1916 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="library-form">
1918 <?php wp_nonce_field('media-form'); ?>
1919 <?php //media_upload_form( $errors ); ?>
1921 <script type="text/javascript">
1924 var preloaded = $(".media-item.preloaded");
1925 if ( preloaded.length > 0 ) {
1926 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1933 <div id="media-items">
1934 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
1935 <?php echo get_media_items(null, $errors); ?>
1937 <p class="ml-submit">
1938 <input type="submit" class="button savebutton" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
1939 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1946 * {@internal Missing Short Description}}
1952 function type_url_form_image() {
1954 if ( !apply_filters( 'disable_captions', '' ) ) {
1957 <th valign="top" scope="row" class="label">
1958 <span class="alignleft"><label for="caption">' . __('Image Caption') . '</label></span>
1960 <td class="field"><input id="caption" name="caption" value="" type="text" /></td>
1967 $default_align = get_option('image_default_align');
1968 if ( empty($default_align) )
1969 $default_align = 'none';
1972 <h4 class="media-sub-title">' . __('Insert an image from another web site') . '</h4>
1973 <table class="describe"><tbody>
1975 <th valign="top" scope="row" class="label" style="width:130px;">
1976 <span class="alignleft"><label for="src">' . __('Image URL') . '</label></span>
1977 <span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span>
1979 <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
1983 <th valign="top" scope="row" class="label">
1984 <span class="alignleft"><label for="title">' . __('Image Title') . '</label></span>
1985 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1987 <td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td>
1991 <th valign="top" scope="row" class="label">
1992 <span class="alignleft"><label for="alt">' . __('Alternate Text') . '</label></span>
1994 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
1995 <p class="help">' . __('Alt text for the image, e.g. “The Mona Lisa”') . '</p></td>
1999 <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
2001 <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
2002 <label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
2003 <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
2004 <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
2005 <input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' />
2006 <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
2007 <input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
2008 <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
2013 <th valign="top" scope="row" class="label">
2014 <span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span>
2016 <td class="field"><input id="url" name="url" value="" type="text" /><br />
2018 <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
2019 <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
2020 <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
2026 <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
2035 * {@internal Missing Short Description}}
2041 function type_url_form_audio() {
2043 <table class="describe"><tbody>
2045 <th valign="top" scope="row" class="label">
2046 <span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span>
2047 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2049 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
2052 <th valign="top" scope="row" class="label">
2053 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
2054 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2056 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
2058 <tr><td></td><td class="help">' . __('Link text, e.g. “Still Alive by Jonathan Coulton”') . '</td></tr>
2062 <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
2070 * {@internal Missing Short Description}}
2076 function type_url_form_video() {
2078 <table class="describe"><tbody>
2080 <th valign="top" scope="row" class="label">
2081 <span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span>
2082 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2084 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
2087 <th valign="top" scope="row" class="label">
2088 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
2089 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2091 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
2093 <tr><td></td><td class="help">' . __('Link text, e.g. “Lucy on YouTube“') . '</td></tr>
2097 <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
2105 * {@internal Missing Short Description}}
2111 function type_url_form_file() {
2113 <table class="describe"><tbody>
2115 <th valign="top" scope="row" class="label">
2116 <span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span>
2117 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2119 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
2122 <th valign="top" scope="row" class="label">
2123 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
2124 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2126 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
2128 <tr><td></td><td class="help">' . __('Link text, e.g. “Ransom Demands (PDF)”') . '</td></tr>
2132 <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
2140 * {@internal Missing Short Description}}
2142 * Support a GET parameter for disabling the flash uploader.
2146 * @param unknown_type $flash
2149 function media_upload_use_flash($flash) {
2150 if ( array_key_exists('flash', $_REQUEST) )
2151 $flash = !empty($_REQUEST['flash']);
2155 add_filter('flash_uploader', 'media_upload_use_flash');
2158 * {@internal Missing Short Description}}
2162 function media_upload_flash_bypass() {
2163 echo '<p class="upload-flash-bypass">';
2164 printf( __('You are using the Flash uploader. Problems? Try the <a href="%s">Browser uploader</a> instead.'), esc_url(add_query_arg('flash', 0)) );
2169 * {@internal Missing Short Description}}
2173 function media_upload_html_bypass($flash = true) {
2174 echo '<p class="upload-html-bypass">';
2175 _e('You are using the Browser uploader.');
2177 // the user manually selected the browser uploader, so let them switch back to Flash
2179 printf( __('Try the <a href="%s">Flash uploader</a> instead.'), esc_url(add_query_arg('flash', 1)) );
2184 add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
2185 add_action('post-html-upload-ui', 'media_upload_html_bypass');
2188 * {@internal Missing Short Description}}
2190 * Make sure the GET parameter sticks when we submit a form.
2194 * @param unknown_type $url
2197 function media_upload_bypass_url($url) {
2198 if ( array_key_exists('flash', $_REQUEST) )
2199 $url = add_query_arg('flash', intval($_REQUEST['flash']));
2203 add_filter('media_upload_form_url', 'media_upload_bypass_url');
2205 add_filter('async_upload_image', 'get_media_item', 10, 2);
2206 add_filter('async_upload_audio', 'get_media_item', 10, 2);
2207 add_filter('async_upload_video', 'get_media_item', 10, 2);
2208 add_filter('async_upload_file', 'get_media_item', 10, 2);
2210 add_action('media_upload_image', 'media_upload_image');
2211 add_action('media_upload_audio', 'media_upload_audio');
2212 add_action('media_upload_video', 'media_upload_video');
2213 add_action('media_upload_file', 'media_upload_file');
2215 add_filter('media_upload_gallery', 'media_upload_gallery');
2217 add_filter('media_upload_library', 'media_upload_library');