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 if ( intval($_REQUEST['post_id']) )
44 $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id'])));
46 if ( empty($attachments) ) {
47 unset($tabs['gallery']);
51 $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
55 add_filter('media_upload_tabs', 'update_gallery_tab');
58 * {@internal Missing Short Description}}
62 function the_media_upload_tabs() {
64 $tabs = media_upload_tabs();
66 if ( !empty($tabs) ) {
67 echo "<ul id='sidemenu'>\n";
68 if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) )
69 $current = $redir_tab;
70 elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
71 $current = $_GET['tab'];
73 $current = apply_filters('media_upload_default_tab', 'type');
75 foreach ( $tabs as $callback => $text ) {
77 if ( $current == $callback )
78 $class = " class='current'";
79 $href = add_query_arg(array('tab'=>$callback, 's'=>false, 'paged'=>false, 'post_mime_type'=>false, 'm'=>false));
80 $link = "<a href='" . esc_url($href) . "'$class>$text</a>";
81 echo "\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n";
88 * {@internal Missing Short Description}}
92 * @param unknown_type $id
93 * @param unknown_type $alt
94 * @param unknown_type $title
95 * @param unknown_type $align
96 * @param unknown_type $url
97 * @param unknown_type $rel
98 * @param unknown_type $size
101 function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
103 $htmlalt = ( empty($alt) ) ? $title : $alt;
105 $html = get_image_tag($id, $htmlalt, $title, $align, $size);
107 $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : '';
110 $html = '<a href="' . esc_url($url) . "\"$rel>$html</a>";
112 $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size );
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, $alt, $title, $align, $url, $size ) {
133 if ( empty($alt) || apply_filters( 'disable_captions', '' ) )
136 $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
138 preg_match( '/width="([0-9]+)/', $html, $matches );
139 if ( ! isset($matches[1]) )
142 $width = $matches[1];
144 $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
148 $alt = ! empty($alt) ? addslashes($alt) : '';
150 $shcode = '[caption id="' . $id . '" align="align' . $align
151 . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/caption]';
153 return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
155 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 );
158 * {@internal Missing Short Description}}
162 * @param unknown_type $html
164 function media_send_to_editor($html) {
166 <script type="text/javascript">
168 var win = window.dialogArguments || opener || parent || top;
169 win.send_to_editor('<?php echo addslashes($html); ?>');
177 * {@internal Missing Short Description}}
179 * This handles the file upload POST itself, creating the attachment post.
183 * @param unknown_type $file_id
184 * @param unknown_type $post_id
185 * @param unknown_type $post_data
188 function media_handle_upload($file_id, $post_id, $post_data = array()) {
189 $overrides = array('test_form'=>false);
191 $time = current_time('mysql');
192 if ( $post = get_post($post_id) ) {
193 if ( substr( $post->post_date, 0, 4 ) > 0 )
194 $time = $post->post_date;
197 $name = $_FILES[$file_id]['name'];
198 $file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
200 if ( isset($file['error']) )
201 return new WP_Error( 'upload_error', $file['error'] );
203 $name_parts = pathinfo($name);
204 $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) );
207 $type = $file['type'];
208 $file = $file['file'];
212 // use image exif/iptc data for title and caption defaults if possible
213 if ( $image_meta = @wp_read_image_metadata($file) ) {
214 if ( trim($image_meta['title']) )
215 $title = $image_meta['title'];
216 if ( trim($image_meta['caption']) )
217 $content = $image_meta['caption'];
220 // Construct the attachment array
221 $attachment = array_merge( array(
222 'post_mime_type' => $type,
224 'post_parent' => $post_id,
225 'post_title' => $title,
226 'post_content' => $content,
230 $id = wp_insert_attachment($attachment, $file, $post_id);
231 if ( !is_wp_error($id) ) {
232 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
240 * {@internal Missing Short Description}}
244 * @param unknown_type $file_array
245 * @param unknown_type $post_id
246 * @param unknown_type $desc
247 * @param unknown_type $post_data
250 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
251 $overrides = array('test_form'=>false);
252 $file = wp_handle_sideload($file_array, $overrides);
254 if ( isset($file['error']) )
255 return new WP_Error( 'upload_error', $file['error'] );
258 $type = $file['type'];
259 $file = $file['file'];
260 $title = preg_replace('/\.[^.]+$/', '', basename($file));
263 // use image exif/iptc data for title and caption defaults if possible
264 if ( $image_meta = @wp_read_image_metadata($file) ) {
265 if ( trim($image_meta['title']) )
266 $title = $image_meta['title'];
267 if ( trim($image_meta['caption']) )
268 $content = $image_meta['caption'];
273 // Construct the attachment array
274 $attachment = array_merge( array(
275 'post_mime_type' => $type,
277 'post_parent' => $post_id,
278 'post_title' => $title,
279 'post_content' => $content,
283 $id = wp_insert_attachment($attachment, $file, $post_id);
284 if ( !is_wp_error($id) ) {
285 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
292 * {@internal Missing Short Description}}
294 * Wrap iframe content (produced by $content_func) in a doctype, html head/body
295 * etc any additional function args will be passed to content_func.
299 * @param unknown_type $content_func
301 function wp_iframe($content_func /* ... */) {
303 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
304 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
306 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
307 <title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?></title>
309 wp_enqueue_style( 'global' );
310 wp_enqueue_style( 'wp-admin' );
311 wp_enqueue_style( 'colors' );
312 if ( 0 === strpos( $content_func, 'media' ) )
313 wp_enqueue_style( 'media' );
314 wp_enqueue_style( 'ie' );
316 <script type="text/javascript">
318 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();}}};
319 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() ?>'};
323 do_action('admin_print_styles');
324 do_action('admin_print_scripts');
325 do_action('admin_head');
326 if ( is_string($content_func) )
327 do_action( "admin_head_{$content_func}" );
330 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>>
332 $args = func_get_args();
333 $args = array_slice($args, 1);
334 call_user_func_array($content_func, $args);
336 do_action('admin_print_footer_scripts');
338 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
345 * {@internal Missing Short Description}}
349 function media_buttons() {
350 global $post_ID, $temp_ID;
351 $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
352 $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
353 $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
354 $media_title = __('Add Media');
355 $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&type=image");
356 $image_title = __('Add an Image');
357 $video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src&type=video");
358 $video_title = __('Add Video');
359 $audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src&type=audio");
360 $audio_title = __('Add Audio');
363 <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>
364 <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>
365 <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>
366 <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>
369 printf($context, $out);
371 add_action( 'media_buttons', 'media_buttons' );
374 * {@internal Missing Short Description}}
380 function media_upload_form_handler() {
381 check_admin_referer('media-form');
385 if ( isset($_POST['send']) ) {
386 $keys = array_keys($_POST['send']);
387 $send_id = (int) array_shift($keys);
390 if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
391 $post = $_post = get_post($attachment_id, ARRAY_A);
392 if ( isset($attachment['post_content']) )
393 $post['post_content'] = $attachment['post_content'];
394 if ( isset($attachment['post_title']) )
395 $post['post_title'] = $attachment['post_title'];
396 if ( isset($attachment['post_excerpt']) )
397 $post['post_excerpt'] = $attachment['post_excerpt'];
398 if ( isset($attachment['menu_order']) )
399 $post['menu_order'] = $attachment['menu_order'];
401 if ( isset($send_id) && $attachment_id == $send_id ) {
402 if ( isset($attachment['post_parent']) )
403 $post['post_parent'] = $attachment['post_parent'];
406 $post = apply_filters('attachment_fields_to_save', $post, $attachment);
408 if ( isset($post['errors']) ) {
409 $errors[$attachment_id] = $post['errors'];
410 unset($post['errors']);
413 if ( $post != $_post )
414 wp_update_post($post);
416 foreach ( get_attachment_taxonomies($post) as $t )
417 if ( isset($attachment[$t]) )
418 wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
421 if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?>
422 <script type="text/javascript">
424 var win = window.dialogArguments || opener || parent || top;
432 if ( isset($send_id) ) {
433 $attachment = stripslashes_deep( $_POST['attachments'][$send_id] );
435 $html = $attachment['post_title'];
436 if ( !empty($attachment['url']) ) {
437 if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
438 $rel = " rel='attachment wp-att-" . esc_attr($send_id)."'";
439 $html = "<a href='{$attachment['url']}'$rel>$html</a>";
442 $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
443 return media_send_to_editor($html);
450 * {@internal Missing Short Description}}
456 function media_upload_image() {
460 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
461 // Upload File button was clicked
462 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
464 if ( is_wp_error($id) ) {
465 $errors['upload_error'] = $id;
470 if ( !empty($_POST['insertonlybutton']) ) {
471 $src = $_POST['insertonly']['src'];
472 if ( !empty($src) && !strpos($src, '://') )
473 $src = "http://$src";
474 $alt = esc_attr($_POST['insertonly']['alt']);
475 if ( isset($_POST['insertonly']['align']) ) {
476 $align = esc_attr($_POST['insertonly']['align']);
477 $class = " class='align$align'";
480 $html = "<img src='$src' alt='$alt'$class />";
481 $html = apply_filters('image_send_to_editor_url', $html, $src, $alt, $align);
482 return media_send_to_editor($html);
485 if ( !empty($_POST) ) {
486 $return = media_upload_form_handler();
488 if ( is_string($return) )
490 if ( is_array($return) )
494 if ( isset($_POST['save']) ) {
495 $errors['upload_notice'] = __('Saved.');
496 return media_upload_gallery();
499 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
500 return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id );
502 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
506 * {@internal Missing Short Description}}
510 * @param unknown_type $file
511 * @param unknown_type $post_id
512 * @param unknown_type $desc
515 function media_sideload_image($file, $post_id, $desc = null) {
516 if (!empty($file) ) {
517 $file_array['name'] = basename($file);
518 $tmp = download_url($file);
519 $file_array['tmp_name'] = $tmp;
522 if ( is_wp_error($tmp) ) {
523 @unlink($file_array['tmp_name']);
524 $file_array['tmp_name'] = '';
527 $id = media_handle_sideload($file_array, $post_id, $desc);
530 if ( is_wp_error($id) ) {
531 @unlink($file_array['tmp_name']);
536 if ( !empty($src) ) {
538 $html = "<img src='$src' alt='$alt' />";
544 * {@internal Missing Short Description}}
550 function media_upload_audio() {
554 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
555 // Upload File button was clicked
556 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
558 if ( is_wp_error($id) ) {
559 $errors['upload_error'] = $id;
564 if ( !empty($_POST['insertonlybutton']) ) {
565 $href = $_POST['insertonly']['href'];
566 if ( !empty($href) && !strpos($href, '://') )
567 $href = "http://$href";
568 $title = esc_attr($_POST['insertonly']['title']);
570 $title = basename($href);
571 if ( !empty($title) && !empty($href) )
572 $html = "<a href='$href' >$title</a>";
573 $html = apply_filters('audio_send_to_editor_url', $html, $href, $title);
574 return media_send_to_editor($html);
577 if ( !empty($_POST) ) {
578 $return = media_upload_form_handler();
580 if ( is_string($return) )
582 if ( is_array($return) )
586 if ( isset($_POST['save']) ) {
587 $errors['upload_notice'] = __('Saved.');
588 return media_upload_gallery();
591 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
592 return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id );
594 return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
598 * {@internal Missing Short Description}}
604 function media_upload_video() {
608 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
609 // Upload File button was clicked
610 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
612 if ( is_wp_error($id) ) {
613 $errors['upload_error'] = $id;
618 if ( !empty($_POST['insertonlybutton']) ) {
619 $href = $_POST['insertonly']['href'];
620 if ( !empty($href) && !strpos($href, '://') )
621 $href = "http://$href";
622 $title = esc_attr($_POST['insertonly']['title']);
624 $title = basename($href);
625 if ( !empty($title) && !empty($href) )
626 $html = "<a href='$href' >$title</a>";
627 $html = apply_filters('video_send_to_editor_url', $html, $href, $title);
628 return media_send_to_editor($html);
631 if ( !empty($_POST) ) {
632 $return = media_upload_form_handler();
634 if ( is_string($return) )
636 if ( is_array($return) )
640 if ( isset($_POST['save']) ) {
641 $errors['upload_notice'] = __('Saved.');
642 return media_upload_gallery();
645 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
646 return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id );
648 return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
652 * {@internal Missing Short Description}}
658 function media_upload_file() {
662 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
663 // Upload File button was clicked
664 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
666 if ( is_wp_error($id) ) {
667 $errors['upload_error'] = $id;
672 if ( !empty($_POST['insertonlybutton']) ) {
673 $href = $_POST['insertonly']['href'];
674 if ( !empty($href) && !strpos($href, '://') )
675 $href = "http://$href";
676 $title = esc_attr($_POST['insertonly']['title']);
678 $title = basename($href);
679 if ( !empty($title) && !empty($href) )
680 $html = "<a href='$href' >$title</a>";
681 $html = apply_filters('file_send_to_editor_url', $html, $href, $title);
682 return media_send_to_editor($html);
685 if ( !empty($_POST) ) {
686 $return = media_upload_form_handler();
688 if ( is_string($return) )
690 if ( is_array($return) )
694 if ( isset($_POST['save']) ) {
695 $errors['upload_notice'] = __('Saved.');
696 return media_upload_gallery();
699 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
700 return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id );
702 return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
706 * {@internal Missing Short Description}}
712 function media_upload_gallery() {
715 if ( !empty($_POST) ) {
716 $return = media_upload_form_handler();
718 if ( is_string($return) )
720 if ( is_array($return) )
724 wp_enqueue_script('admin-gallery');
725 return wp_iframe( 'media_upload_gallery_form', $errors );
729 * {@internal Missing Short Description}}
735 function media_upload_library() {
737 if ( !empty($_POST) ) {
738 $return = media_upload_form_handler();
740 if ( is_string($return) )
742 if ( is_array($return) )
746 return wp_iframe( 'media_upload_library_form', $errors );
750 * Retrieve HTML for the image alignment radio buttons with the specified one checked.
754 * @param unknown_type $post
755 * @param unknown_type $checked
758 function image_align_input_fields( $post, $checked = '' ) {
760 $alignments = array('none' => __('None'), 'left' => __('Left'), 'center' => __('Center'), 'right' => __('Right'));
761 if ( !array_key_exists( (string) $checked, $alignments ) )
765 foreach ($alignments as $name => $label) {
766 $name = esc_attr($name);
767 $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'".
768 ( $checked == $name ? " checked='checked'" : "" ) .
769 " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>" . $label . "</label>";
771 return join("\n", $out);
775 * Retrieve HTML for the size radio buttons with the specified one checked.
779 * @param unknown_type $post
780 * @param unknown_type $checked
783 function image_size_input_fields( $post, $checked = '' ) {
785 // get a list of the actual pixel dimensions of each possible intermediate version of this image
786 $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size'));
788 foreach ( $size_names as $size => $name ) {
789 $downsize = image_downsize($post->ID, $size);
791 // is this size selectable?
792 $enabled = ( $downsize[3] || 'full' == $size );
793 $css_id = "image-size-{$size}-{$post->ID}";
794 // if this size is the default but that's not available, don't select it
795 if ( $checked && !$enabled )
797 // if $checked was not specified, default to the first available size that's bigger than a thumbnail
798 if ( !$checked && $enabled && 'thumbnail' != $size )
801 $html = "<div class='image-size-item'><input type='radio' ".( $enabled ? '' : "disabled='disabled'")."name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'".( $checked == $size ? " checked='checked'" : '') ." />";
803 $html .= "<label for='{$css_id}'>" . __($name). "</label>";
804 // only show the dimensions if that choice is available
806 $html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d × %d)"), $downsize[1], $downsize[2] ). "</label>";
814 'label' => __('Size'),
816 'html' => join("\n", $out),
821 * Retrieve HTML for the Link URL buttons with the default link type as specified.
825 * @param unknown_type $post
826 * @param unknown_type $url_type
829 function image_link_input_fields($post, $url_type='') {
831 $file = wp_get_attachment_url($post->ID);
832 $link = get_attachment_link($post->ID);
835 if ( $url_type == 'file' )
837 elseif ( $url_type == 'post' )
840 return "<input type='text' class='urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
841 <button type='button' class='button urlnone' title=''>" . __('None') . "</button>
842 <button type='button' class='button urlfile' title='" . esc_attr($file) . "'>" . __('File URL') . "</button>
843 <button type='button' class='button urlpost' title='" . esc_attr($link) . "'>" . __('Post URL') . "</button>
848 * {@internal Missing Short Description}}
852 * @param unknown_type $form_fields
853 * @param unknown_type $post
856 function image_attachment_fields_to_edit($form_fields, $post) {
857 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
858 $form_fields['post_title']['required'] = true;
859 $file = wp_get_attachment_url($post->ID);
861 $form_fields['image_url']['value'] = $file;
863 $form_fields['post_excerpt']['label'] = __('Caption');
864 $form_fields['post_excerpt']['helps'][] = __('Also used as alternate text for the image');
866 $form_fields['post_content']['label'] = __('Description');
868 $form_fields['align'] = array(
869 'label' => __('Alignment'),
871 'html' => image_align_input_fields($post, get_option('image_default_align')),
874 $form_fields['image-size'] = image_size_input_fields($post, get_option('image_default_size'));
879 add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
882 * {@internal Missing Short Description}}
886 * @param unknown_type $form_fields
887 * @param unknown_type $post
890 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
891 unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
895 function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
896 unset($form_fields['image_url']);
901 * {@internal Missing Short Description}}
905 * @param unknown_type $post
906 * @param unknown_type $attachment
909 function image_attachment_fields_to_save($post, $attachment) {
910 if ( substr($post['post_mime_type'], 0, 5) == 'image' ) {
911 if ( strlen(trim($post['post_title'])) == 0 ) {
912 $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid']));
913 $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.');
920 add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2);
923 * {@internal Missing Short Description}}
927 * @param unknown_type $html
928 * @param unknown_type $attachment_id
929 * @param unknown_type $attachment
932 function image_media_send_to_editor($html, $attachment_id, $attachment) {
933 $post =& get_post($attachment_id);
934 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
935 $url = $attachment['url'];
937 if ( isset($attachment['align']) )
938 $align = $attachment['align'];
942 if ( !empty($attachment['image-size']) )
943 $size = $attachment['image-size'];
947 $rel = ( $url == get_attachment_link($attachment_id) );
949 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size);
955 add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3);
958 * {@internal Missing Short Description}}
962 * @param unknown_type $post
963 * @param unknown_type $errors
966 function get_attachment_fields_to_edit($post, $errors = null) {
968 $post =& get_post($post);
969 if ( is_array($post) )
970 $post = (object) $post;
972 $image_url = wp_get_attachment_url($post->ID);
974 $edit_post = sanitize_post($post, 'edit');
976 $form_fields = array(
977 'post_title' => array(
978 'label' => __('Title'),
979 'value' => $edit_post->post_title,
981 'post_excerpt' => array(
982 'label' => __('Caption'),
983 'value' => $edit_post->post_excerpt,
985 'post_content' => array(
986 'label' => __('Description'),
987 'value' => $edit_post->post_content,
988 'input' => 'textarea',
991 'label' => __('Link URL'),
993 'html' => image_link_input_fields($post, get_option('image_default_link_type')),
994 'helps' => __('Enter a link URL or click above for presets.'),
996 'menu_order' => array(
997 'label' => __('Order'),
998 'value' => $edit_post->menu_order
1000 'image_url' => array(
1001 'label' => __('File URL'),
1003 'html' => "<input type='text' class='urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr($image_url) . "' /><br />",
1004 'value' => isset($edit_post->post_url) ? $edit_post->post_url : '',
1005 'helps' => __('Location of the uploaded file.'),
1009 foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
1010 $t = (array) get_taxonomy($taxonomy);
1011 if ( empty($t['label']) )
1012 $t['label'] = $taxonomy;
1013 if ( empty($t['args']) )
1014 $t['args'] = array();
1016 $terms = get_object_term_cache($post->ID, $taxonomy);
1017 if ( empty($terms) )
1018 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
1022 foreach ( $terms as $term )
1023 $values[] = $term->name;
1024 $t['value'] = join(', ', $values);
1026 $form_fields[$taxonomy] = $t;
1029 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
1030 // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
1031 $form_fields = array_merge_recursive($form_fields, (array) $errors);
1033 $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
1035 return $form_fields;
1039 * Retrieve HTML for media items of post gallery.
1041 * The HTML markup retrieved will be created for the progress of SWF Upload
1042 * component. Will also create link for showing and hiding the form to modify
1043 * the image attachment.
1047 * @param int $post_id Optional. Post ID.
1048 * @param array $errors Errors for attachment, if any.
1051 function get_media_items( $post_id, $errors ) {
1053 $post = get_post($post_id);
1054 if ( $post && $post->post_type == 'attachment' )
1055 $attachments = array($post->ID => $post);
1057 $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
1059 if ( is_array($GLOBALS['wp_the_query']->posts) )
1060 foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
1061 $attachments[$attachment->ID] = $attachment;
1065 foreach ( (array) $attachments as $id => $attachment )
1066 if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
1067 $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>";
1073 * Retrieve HTML form for modifying the image attachment.
1077 * @param int $attachment_id Attachment ID for modification.
1078 * @param string|array $args Optional. Override defaults.
1079 * @return string HTML form for attachment.
1081 function get_media_item( $attachment_id, $args = null ) {
1084 $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true, 'show_title' => true );
1085 $args = wp_parse_args( $args, $default_args );
1086 extract( $args, EXTR_SKIP );
1088 global $post_mime_types;
1089 if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) )
1090 $thumb_url = $thumb_url[0];
1094 $toggle_on = __('Show');
1095 $toggle_off = __('Hide');
1097 $post = get_post($attachment_id);
1099 $filename = basename($post->guid);
1100 $title = esc_attr($post->post_title);
1102 if ( $_tags = get_the_tags($attachment_id) ) {
1103 foreach ( $_tags as $tag )
1104 $tags[] = $tag->name;
1105 $tags = esc_attr(join(', ', $tags));
1109 if ( isset($post_mime_types) ) {
1110 $keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type));
1111 $type = array_shift($keys);
1112 $type = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
1115 $form_fields = get_attachment_fields_to_edit($post, $errors);
1118 $class = empty($errors) ? 'startclosed' : 'startopen';
1120 <a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
1121 <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
1123 $class = 'form-table';
1127 $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
1128 $display_title = $show_title ? "<div class='filename new'>" . wp_html_excerpt($display_title, 60) . "</div>" : '';
1130 $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false;
1133 foreach ( $form_fields as $key => $val ) {
1134 if ( 'menu_order' == $key ) {
1136 $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>';
1138 $order = '<input type="hidden" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" />';
1140 unset($form_fields['menu_order']);
1150 <table class='slidetoggle describe $class'>
1151 <thead class='media-item-info'>
1153 <td class='A1B1' rowspan='4'><img class='thumbnail' src='$thumb_url' alt='' /></td>
1156 <tr><td>$post->post_mime_type</td></tr>
1157 <tr><td>" . mysql2date($post->post_date, get_option('time_format')) . "</td></tr>
1158 <tr><td>" . apply_filters('media_meta', '', $post) . "</td></tr>
1164 'required' => false,
1166 'extra_rows' => array(),
1169 $delete_href = wp_nonce_url("post.php?action=delete-post&post=$attachment_id", 'delete-post_' . $attachment_id);
1171 $send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . esc_attr__( 'Insert into Post' ) . "' />";
1173 $delete = "<a href=\"#\" class=\"del-link\" onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __('Delete') . "</a>";
1174 if ( ( $send || $delete ) && !isset($form_fields['buttons']) )
1175 $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $delete
1176 <div id=\"del_attachment_$attachment_id\" class=\"del-attachment\" style=\"display:none;\">" . sprintf(__("You are about to delete <strong>%s</strong>."), $filename) . " <a href=\"$delete_href\" id=\"del[$attachment_id]\" class=\"delete\">" . __('Continue') . "</a>
1177 <a href=\"#\" class=\"del-link\" onclick=\"this.parentNode.style.display='none';return false;\">" . __('Cancel') . "</a></div></td></tr>\n");
1179 $hidden_fields = array();
1181 foreach ( $form_fields as $id => $field ) {
1182 if ( $id{0} == '_' )
1185 if ( !empty($field['tr']) ) {
1186 $item .= $field['tr'];
1190 $field = array_merge($defaults, $field);
1191 $name = "attachments[$attachment_id][$id]";
1193 if ( $field['input'] == 'hidden' ) {
1194 $hidden_fields[$name] = $field['value'];
1198 $required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : '';
1199 $aria_required = $field['required'] ? " aria-required='true' " : '';
1201 $class .= $field['required'] ? ' form-required' : '';
1203 $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'>";
1204 if ( !empty($field[$field['input']]) )
1205 $item .= $field[$field['input']];
1206 elseif ( $field['input'] == 'textarea' ) {
1207 $item .= "<textarea type='text' id='$name' name='$name'" . $aria_required . ">" . esc_html( $field['value'] ) . "</textarea>";
1209 $item .= "<input type='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'" . $aria_required . "/>";
1211 if ( !empty($field['helps']) )
1212 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique((array) $field['helps']) ) . '</p>';
1213 $item .= "</td>\n\t\t</tr>\n";
1215 $extra_rows = array();
1217 if ( !empty($field['errors']) )
1218 foreach ( array_unique((array) $field['errors']) as $error )
1219 $extra_rows['error'][] = $error;
1221 if ( !empty($field['extra_rows']) )
1222 foreach ( $field['extra_rows'] as $class => $rows )
1223 foreach ( (array) $rows as $html )
1224 $extra_rows[$class][] = $html;
1226 foreach ( $extra_rows as $class => $rows )
1227 foreach ( $rows as $html )
1228 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
1231 if ( !empty($form_fields['_final']) )
1232 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
1233 $item .= "\t</tbody>\n";
1234 $item .= "\t</table>\n";
1236 foreach ( $hidden_fields as $name => $value )
1237 $item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
1239 if ( $post->post_parent < 1 && isset($_REQUEST['post_id']) ) {
1240 $parent = (int) $_REQUEST['post_id'];
1241 $parent_name = "attachments[$attachment_id][post_parent]";
1243 $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='" . $parent . "' />\n";
1250 * {@internal Missing Short Description}}
1254 function media_upload_header() {
1256 <script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script>
1257 <div id="media-upload-header">
1258 <?php the_media_upload_tabs(); ?>
1264 * {@internal Missing Short Description}}
1268 * @param unknown_type $errors
1270 function media_upload_form( $errors = null ) {
1273 $flash_action_url = admin_url('async-upload.php');
1275 // If Mac and mod_security, no Flash. :(
1277 if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mac') && apache_mod_loaded('mod_security') )
1280 $flash = apply_filters('flash_uploader', $flash);
1281 $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
1284 <script type="text/javascript">
1286 var uploaderMode = 0;
1287 jQuery(document).ready(function($){
1288 uploaderMode = getUserSetting('uploader');
1289 $('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;});
1290 $('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;});
1294 <div id="media-upload-notice">
1295 <?php if (isset($errors['upload_notice']) ) { ?>
1296 <?php echo $errors['upload_notice']; ?>
1299 <div id="media-upload-error">
1300 <?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?>
1301 <?php echo $errors['upload_error']->get_error_message(); ?>
1305 <?php do_action('pre-upload-ui'); ?>
1307 <?php if ( $flash ) : ?>
1308 <script type="text/javascript">
1311 SWFUpload.onload = function() {
1313 button_text: '<span class="button"><?php _e('Select Files'); ?></span>',
1314 button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; }',
1315 button_height: "24",
1316 button_width: "132",
1317 button_text_top_padding: 2,
1318 button_image_url: '<?php echo includes_url('images/upload.png'); ?>',
1319 button_placeholder_id: "flash-browse-button",
1320 upload_url : "<?php echo esc_attr( $flash_action_url ); ?>",
1321 flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>",
1322 file_post_name: "async-upload",
1323 file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",
1325 "post_id" : "<?php echo $post_id; ?>",
1326 "auth_cookie" : "<?php if ( is_ssl() ) echo $_COOKIE[SECURE_AUTH_COOKIE]; else echo $_COOKIE[AUTH_COOKIE]; ?>",
1327 "_wpnonce" : "<?php echo wp_create_nonce('media-form'); ?>",
1328 "type" : "<?php echo $type; ?>",
1329 "tab" : "<?php echo $tab; ?>",
1332 file_size_limit : "<?php echo wp_max_upload_size(); ?>b",
1333 file_dialog_start_handler : fileDialogStart,
1334 file_queued_handler : fileQueued,
1335 upload_start_handler : uploadStart,
1336 upload_progress_handler : uploadProgress,
1337 upload_error_handler : uploadError,
1338 upload_success_handler : uploadSuccess,
1339 upload_complete_handler : uploadComplete,
1340 file_queue_error_handler : fileQueueError,
1341 file_dialog_complete_handler : fileDialogComplete,
1342 swfupload_pre_load_handler: swfuploadPreLoad,
1343 swfupload_load_failed_handler: swfuploadLoadFailed,
1345 degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable
1346 swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available
1350 swfu = new SWFUpload(settings);
1355 <div id="flash-upload-ui">
1356 <?php do_action('pre-flash-upload-ui'); ?>
1359 <?php _e( 'Choose files to upload' ); ?>
1360 <div id="flash-browse-button"></div>
1361 <span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span>
1363 <?php do_action('post-flash-upload-ui'); ?>
1364 <p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
1366 <?php endif; // $flash ?>
1368 <div id="html-upload-ui">
1369 <?php do_action('pre-html-upload-ui'); ?>
1370 <p id="async-upload-wrap">
1371 <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>
1372 <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="return top.tb_remove();"><?php _e('Cancel'); ?></a>
1374 <div class="clear"></div>
1375 <?php if ( is_lighttpd_before_150() ): ?>
1376 <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>
1378 <?php do_action('post-html-upload-ui', $flash); ?>
1380 <?php do_action('post-upload-ui'); ?>
1385 * {@internal Missing Short Description}}
1389 * @param unknown_type $type
1390 * @param unknown_type $errors
1391 * @param unknown_type $id
1393 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
1394 media_upload_header();
1396 $post_id = intval($_REQUEST['post_id']);
1398 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
1399 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1402 <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">
1403 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1404 <?php wp_nonce_field('media-form'); ?>
1406 <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
1408 <?php media_upload_form( $errors ); ?>
1410 <script type="text/javascript">
1413 var preloaded = $(".media-item.preloaded");
1414 if ( preloaded.length > 0 ) {
1415 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1421 <div id="media-items">
1424 if ( !is_wp_error($id) ) {
1425 add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
1426 echo get_media_items( $id, $errors );
1428 echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div>';
1434 <p class="savebutton ml-submit">
1435 <input type="submit" class="button" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
1441 * {@internal Missing Short Description}}
1445 * @param unknown_type $type
1446 * @param unknown_type $errors
1447 * @param unknown_type $id
1449 function media_upload_type_url_form($type = 'file', $errors = null, $id = null) {
1450 media_upload_header();
1452 $post_id = intval($_REQUEST['post_id']);
1454 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
1455 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1457 $callback = "type_url_form_$type";
1460 <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">
1461 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1462 <?php wp_nonce_field('media-form'); ?>
1464 <?php if ( is_callable($callback) ) { ?>
1466 <h3 class="media-title"><?php _e('Add media file from URL'); ?></h3>
1468 <script type="text/javascript">
1474 align : 'alignnone',
1476 insert : function() {
1477 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = null;
1479 if ( '' == f.src.value || '' == t.width ) return false;
1481 if ( f.title.value ) {
1482 title = f.title.value.replace(/['"<>]+/g, '');
1483 title = ' title="'+title+'"';
1486 if ( f.alt.value ) {
1487 alt = f.alt.value.replace(/['"<>]+/g, '');
1488 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
1489 caption = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
1493 cls = caption ? '' : ' class="'+t.align+'"';
1495 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
1498 html = '<a href="'+f.url.value+'">'+html+'</a>';
1501 html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';
1503 var win = window.dialogArguments || opener || parent || top;
1504 win.send_to_editor(html);
1507 resetImageData : function() {
1508 var t = addExtImage;
1510 t.width = t.height = '';
1511 document.getElementById('go_button').style.color = '#bbb';
1512 if ( ! document.forms[0].src.value )
1513 document.getElementById('status_img').src = 'images/required.gif';
1514 else document.getElementById('status_img').src = 'images/no.png';
1517 updateImageData : function() {
1518 var t = addExtImage;
1520 t.width = t.preloadImg.width;
1521 t.height = t.preloadImg.height;
1522 document.getElementById('go_button').style.color = '#333';
1523 document.getElementById('status_img').src = 'images/yes.png';
1526 getImageData : function() {
1527 var t = addExtImage, src = document.forms[0].src.value;
1533 document.getElementById('status_img').src = 'images/wpspin_light.gif';
1534 t.preloadImg = new Image();
1535 t.preloadImg.onload = t.updateImageData;
1536 t.preloadImg.onerror = t.resetImageData;
1537 t.preloadImg.src = src;
1543 <div id="media-items">
1544 <div class="media-item media-blank">
1545 <?php echo apply_filters($callback, call_user_func($callback)); ?>
1551 wp_die( __('Unknown action.') );
1556 * {@internal Missing Short Description}}
1560 * @param unknown_type $errors
1562 function media_upload_gallery_form($errors) {
1565 $redir_tab = 'gallery';
1566 media_upload_header();
1568 $post_id = intval($_REQUEST['post_id']);
1569 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id");
1572 <script type="text/javascript">
1575 var preloaded = $(".media-item.preloaded");
1576 if ( preloaded.length > 0 ) {
1577 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1583 <div id="sort-buttons" class="hide-if-no-js">
1585 <?php _e('All Tabs:'); ?>
1586 <a href="#" id="showall"><?php _e('Show'); ?></a>
1587 <a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a>
1589 <?php _e('Sort Order:'); ?>
1590 <a href="#" id="asc"><?php _e('Ascending'); ?></a> |
1591 <a href="#" id="desc"><?php _e('Descending'); ?></a> |
1592 <a href="#" id="clear"><?php _e('Clear'); ?></a>
1594 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
1595 <?php wp_nonce_field('media-form'); ?>
1596 <?php //media_upload_form( $errors ); ?>
1597 <table class="widefat" cellspacing="0">
1599 <th><?php _e('Media'); ?></th>
1600 <th class="order-head"><?php _e('Order'); ?></th>
1603 <div id="media-items">
1604 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
1605 <?php echo get_media_items($post_id, $errors); ?>
1608 <p class="ml-submit">
1609 <input type="submit" class="button savebutton" style="display:none;" name="save" id="save-all" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
1610 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1611 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
1612 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
1615 <div id="gallery-settings" style="display:none;">
1616 <div class="title"><?php _e('Gallery Settings'); ?></div>
1617 <table id="basic" class="describe"><tbody>
1619 <th scope="row" class="label">
1621 <span class="alignleft"><?php _e('Link thumbnails to:'); ?></span>
1625 <input type="radio" name="linkto" id="linkto-file" value="file" />
1626 <label for="linkto-file" class="radio"><?php _e('Image File'); ?></label>
1628 <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" />
1629 <label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label>
1634 <th scope="row" class="label">
1636 <span class="alignleft"><?php _e('Order images by:'); ?></span>
1640 <select id="orderby" name="orderby">
1641 <option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option>
1642 <option value="title"><?php _e('Title'); ?></option>
1643 <option value="ID"><?php _e('Date/Time'); ?></option>
1644 <option value="rand"><?php _e('Random'); ?></option>
1650 <th scope="row" class="label">
1652 <span class="alignleft"><?php _e('Order:'); ?></span>
1656 <input type="radio" checked="checked" name="order" id="order-asc" value="asc" />
1657 <label for="order-asc" class="radio"><?php _e('Ascending'); ?></label>
1659 <input type="radio" name="order" id="order-desc" value="desc" />
1660 <label for="order-desc" class="radio"><?php _e('Descending'); ?></label>
1665 <th scope="row" class="label">
1667 <span class="alignleft"><?php _e('Gallery columns:'); ?></span>
1671 <select id="columns" name="columns">
1672 <option value="2"><?php _e('2'); ?></option>
1673 <option value="3" selected="selected"><?php _e('3'); ?></option>
1674 <option value="4"><?php _e('4'); ?></option>
1675 <option value="5"><?php _e('5'); ?></option>
1676 <option value="6"><?php _e('6'); ?></option>
1677 <option value="7"><?php _e('7'); ?></option>
1678 <option value="8"><?php _e('8'); ?></option>
1679 <option value="9"><?php _e('9'); ?></option>
1685 <p class="ml-submit">
1686 <input type="button" class="button" style="display:none;" onmousedown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" />
1687 <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' ); ?>" />
1695 * {@internal Missing Short Description}}
1699 * @param unknown_type $errors
1701 function media_upload_library_form($errors) {
1702 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
1704 media_upload_header();
1706 $post_id = intval($_REQUEST['post_id']);
1708 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=library&post_id=$post_id");
1710 $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;
1711 if ( $_GET['paged'] < 1 )
1713 $start = ( $_GET['paged'] - 1 ) * 10;
1716 add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
1718 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1722 <form id="filter" action="" method="get">
1723 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />
1724 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />
1725 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
1726 <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" />
1728 <p id="media-search" class="search-box">
1729 <label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label>
1730 <input type="text" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />
1731 <input type="submit" value="<?php esc_attr_e( 'Search Media' ); ?>" class="button" />
1734 <ul class="subsubsub">
1736 $type_links = array();
1737 $_num_posts = (array) wp_count_attachments();
1738 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
1739 foreach ( $matches as $_type => $reals )
1740 foreach ( $reals as $real )
1741 if ( isset($num_posts[$_type]) )
1742 $num_posts[$_type] += $_num_posts[$real];
1744 $num_posts[$_type] = $_num_posts[$real];
1745 // If available type specified by media button clicked, filter by that type
1746 if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {
1747 $_GET['post_mime_type'] = $type;
1748 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1750 if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )
1751 $class = ' class="current"';
1754 $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>";
1755 foreach ( $post_mime_types as $mime_type => $label ) {
1758 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
1761 if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
1762 $class = ' class="current"';
1764 $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>';
1766 echo implode(' | </li>', $type_links) . '</li>';
1771 <div class="tablenav">
1774 $page_links = paginate_links( array(
1775 'base' => add_query_arg( 'paged', '%#%' ),
1777 'prev_text' => __('«'),
1778 'next_text' => __('»'),
1779 'total' => ceil($wp_query->found_posts / 10),
1780 'current' => $_GET['paged']
1784 echo "<div class='tablenav-pages'>$page_links</div>";
1787 <div class="alignleft actions">
1790 $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";
1792 $arc_result = $wpdb->get_results( $arc_query );
1794 $month_count = count($arc_result);
1796 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
1798 <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
1800 foreach ($arc_result as $arc_row) {
1801 if ( $arc_row->yyear == 0 )
1803 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
1805 if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
1806 $default = ' selected="selected"';
1810 echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>";
1811 echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" );
1818 <input type="submit" id="post-query-submit" value="<?php echo esc_attr( __( 'Filter »' ) ); ?>" class="button-secondary" />
1822 <br class="clear" />
1826 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="library-form">
1828 <?php wp_nonce_field('media-form'); ?>
1829 <?php //media_upload_form( $errors ); ?>
1831 <script type="text/javascript">
1834 var preloaded = $(".media-item.preloaded");
1835 if ( preloaded.length > 0 ) {
1836 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1843 <div id="media-items">
1844 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
1845 <?php echo get_media_items(null, $errors); ?>
1847 <p class="ml-submit">
1848 <input type="submit" class="button savebutton" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
1849 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1856 * {@internal Missing Short Description}}
1862 function type_url_form_image() {
1864 if ( apply_filters( 'disable_captions', '' ) ) {
1865 $alt = __('Alternate Text');
1866 $alt_help = __('Alt text for the image, e.g. “The Mona Lisa”');
1868 $alt = __('Image Caption');
1869 $alt_help = __('Also used as alternate text for the image');
1872 $default_align = get_option('image_default_align');
1873 if ( empty($default_align) )
1874 $default_align = 'none';
1877 <table class="describe"><tbody>
1879 <th valign="top" scope="row" class="label" style="width:120px;">
1880 <span class="alignleft"><label for="src">' . __('Image URL') . '</label></span>
1881 <span class="alignright"><img id="status_img" src="images/required.gif" title="required" alt="required" /></span>
1883 <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
1887 <th valign="top" scope="row" class="label">
1888 <span class="alignleft"><label for="title">' . __('Image Title') . '</label></span>
1889 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1891 <td class="field"><p><input id="title" name="title" value="" type="text" aria-required="true" /></p></td>
1895 <th valign="top" scope="row" class="label">
1896 <span class="alignleft"><label for="alt">' . $alt . '</label></span>
1898 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
1899 <p class="help">' . $alt_help . '</p></td>
1903 <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
1905 <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
1906 <label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
1907 <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
1908 <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
1909 <input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' />
1910 <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
1911 <input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
1912 <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
1917 <th valign="top" scope="row" class="label">
1918 <span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span>
1920 <td class="field"><input id="url" name="url" value="" type="text" /><br />
1922 <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
1923 <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
1924 <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
1930 <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
1939 * {@internal Missing Short Description}}
1945 function type_url_form_audio() {
1947 <table class="describe"><tbody>
1949 <th valign="top" scope="row" class="label">
1950 <span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span>
1951 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1953 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1956 <th valign="top" scope="row" class="label">
1957 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1958 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1960 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1962 <tr><td></td><td class="help">' . __('Link text, e.g. “Still Alive by Jonathan Coulton”') . '</td></tr>
1966 <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
1974 * {@internal Missing Short Description}}
1980 function type_url_form_video() {
1982 <table class="describe"><tbody>
1984 <th valign="top" scope="row" class="label">
1985 <span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span>
1986 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1988 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1991 <th valign="top" scope="row" class="label">
1992 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1993 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1995 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1997 <tr><td></td><td class="help">' . __('Link text, e.g. “Lucy on YouTube“') . '</td></tr>
2001 <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
2009 * {@internal Missing Short Description}}
2015 function type_url_form_file() {
2017 <table class="describe"><tbody>
2019 <th valign="top" scope="row" class="label">
2020 <span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span>
2021 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2023 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
2026 <th valign="top" scope="row" class="label">
2027 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
2028 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2030 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
2032 <tr><td></td><td class="help">' . __('Link text, e.g. “Ransom Demands (PDF)”') . '</td></tr>
2036 <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
2044 * {@internal Missing Short Description}}
2046 * Support a GET parameter for disabling the flash uploader.
2050 * @param unknown_type $flash
2053 function media_upload_use_flash($flash) {
2054 if ( array_key_exists('flash', $_REQUEST) )
2055 $flash = !empty($_REQUEST['flash']);
2059 add_filter('flash_uploader', 'media_upload_use_flash');
2062 * {@internal Missing Short Description}}
2066 function media_upload_flash_bypass() {
2067 echo '<p class="upload-flash-bypass">';
2068 printf( __('You are using the Flash uploader. Problems? Try the <a href="%s">Browser uploader</a> instead.'), esc_url(add_query_arg('flash', 0)) );
2073 * {@internal Missing Short Description}}
2077 function media_upload_html_bypass($flash = true) {
2078 echo '<p class="upload-html-bypass">';
2079 _e('You are using the Browser uploader.');
2081 // the user manually selected the browser uploader, so let them switch back to Flash
2083 printf( __('Try the <a href="%s">Flash uploader</a> instead.'), esc_url(add_query_arg('flash', 1)) );
2088 add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
2089 add_action('post-html-upload-ui', 'media_upload_html_bypass');
2092 * {@internal Missing Short Description}}
2094 * Make sure the GET parameter sticks when we submit a form.
2098 * @param unknown_type $url
2101 function media_upload_bypass_url($url) {
2102 if ( array_key_exists('flash', $_REQUEST) )
2103 $url = add_query_arg('flash', intval($_REQUEST['flash']));
2107 add_filter('media_upload_form_url', 'media_upload_bypass_url');
2109 add_filter('async_upload_image', 'get_media_item', 10, 2);
2110 add_filter('async_upload_audio', 'get_media_item', 10, 2);
2111 add_filter('async_upload_video', 'get_media_item', 10, 2);
2112 add_filter('async_upload_file', 'get_media_item', 10, 2);
2114 add_action('media_upload_image', 'media_upload_image');
2115 add_action('media_upload_audio', 'media_upload_audio');
2116 add_action('media_upload_video', 'media_upload_video');
2117 add_action('media_upload_file', 'media_upload_file');
2119 add_filter('media_upload_gallery', 'media_upload_gallery');
2121 add_filter('media_upload_library', 'media_upload_library');