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' );
372 add_action('media_upload_media', 'media_upload_handler');
375 * {@internal Missing Short Description}}
381 function media_upload_form_handler() {
382 check_admin_referer('media-form');
386 if ( isset($_POST['send']) ) {
387 $keys = array_keys($_POST['send']);
388 $send_id = (int) array_shift($keys);
391 if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
392 $post = $_post = get_post($attachment_id, ARRAY_A);
393 if ( isset($attachment['post_content']) )
394 $post['post_content'] = $attachment['post_content'];
395 if ( isset($attachment['post_title']) )
396 $post['post_title'] = $attachment['post_title'];
397 if ( isset($attachment['post_excerpt']) )
398 $post['post_excerpt'] = $attachment['post_excerpt'];
399 if ( isset($attachment['menu_order']) )
400 $post['menu_order'] = $attachment['menu_order'];
402 if ( isset($send_id) && $attachment_id == $send_id ) {
403 if ( isset($attachment['post_parent']) )
404 $post['post_parent'] = $attachment['post_parent'];
407 $post = apply_filters('attachment_fields_to_save', $post, $attachment);
409 if ( isset($post['errors']) ) {
410 $errors[$attachment_id] = $post['errors'];
411 unset($post['errors']);
414 if ( $post != $_post )
415 wp_update_post($post);
417 foreach ( get_attachment_taxonomies($post) as $t )
418 if ( isset($attachment[$t]) )
419 wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
422 if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?>
423 <script type="text/javascript">
425 var win = window.dialogArguments || opener || parent || top;
433 if ( isset($send_id) ) {
434 $attachment = stripslashes_deep( $_POST['attachments'][$send_id] );
436 $html = $attachment['post_title'];
437 if ( !empty($attachment['url']) ) {
438 if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
439 $rel = " rel='attachment wp-att-" . esc_attr($send_id)."'";
440 $html = "<a href='{$attachment['url']}'$rel>$html</a>";
443 $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
444 return media_send_to_editor($html);
451 * {@internal Missing Short Description}}
457 function media_upload_image() {
461 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
462 // Upload File button was clicked
463 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
465 if ( is_wp_error($id) ) {
466 $errors['upload_error'] = $id;
471 if ( !empty($_POST['insertonlybutton']) ) {
472 $src = $_POST['insertonly']['src'];
473 if ( !empty($src) && !strpos($src, '://') )
474 $src = "http://$src";
475 $alt = esc_attr($_POST['insertonly']['alt']);
476 if ( isset($_POST['insertonly']['align']) ) {
477 $align = esc_attr($_POST['insertonly']['align']);
478 $class = " class='align$align'";
481 $html = "<img src='$src' alt='$alt'$class />";
482 $html = apply_filters('image_send_to_editor_url', $html, $src, $alt, $align);
483 return media_send_to_editor($html);
486 if ( !empty($_POST) ) {
487 $return = media_upload_form_handler();
489 if ( is_string($return) )
491 if ( is_array($return) )
495 if ( isset($_POST['save']) ) {
496 $errors['upload_notice'] = __('Saved.');
497 return media_upload_gallery();
500 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
501 return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id );
503 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
507 * {@internal Missing Short Description}}
511 * @param unknown_type $file
512 * @param unknown_type $post_id
513 * @param unknown_type $desc
516 function media_sideload_image($file, $post_id, $desc = null) {
517 if (!empty($file) ) {
518 $file_array['name'] = basename($file);
519 $tmp = download_url($file);
520 $file_array['tmp_name'] = $tmp;
523 if ( is_wp_error($tmp) ) {
524 @unlink($file_array['tmp_name']);
525 $file_array['tmp_name'] = '';
528 $id = media_handle_sideload($file_array, $post_id, $desc);
531 if ( is_wp_error($id) ) {
532 @unlink($file_array['tmp_name']);
537 if ( !empty($src) ) {
539 $html = "<img src='$src' alt='$alt' />";
545 * {@internal Missing Short Description}}
551 function media_upload_audio() {
555 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
556 // Upload File button was clicked
557 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
559 if ( is_wp_error($id) ) {
560 $errors['upload_error'] = $id;
565 if ( !empty($_POST['insertonlybutton']) ) {
566 $href = $_POST['insertonly']['href'];
567 if ( !empty($href) && !strpos($href, '://') )
568 $href = "http://$href";
569 $title = esc_attr($_POST['insertonly']['title']);
571 $title = basename($href);
572 if ( !empty($title) && !empty($href) )
573 $html = "<a href='$href' >$title</a>";
574 $html = apply_filters('audio_send_to_editor_url', $html, $href, $title);
575 return media_send_to_editor($html);
578 if ( !empty($_POST) ) {
579 $return = media_upload_form_handler();
581 if ( is_string($return) )
583 if ( is_array($return) )
587 if ( isset($_POST['save']) ) {
588 $errors['upload_notice'] = __('Saved.');
589 return media_upload_gallery();
592 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
593 return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id );
595 return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
599 * {@internal Missing Short Description}}
605 function media_upload_video() {
609 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
610 // Upload File button was clicked
611 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
613 if ( is_wp_error($id) ) {
614 $errors['upload_error'] = $id;
619 if ( !empty($_POST['insertonlybutton']) ) {
620 $href = $_POST['insertonly']['href'];
621 if ( !empty($href) && !strpos($href, '://') )
622 $href = "http://$href";
623 $title = esc_attr($_POST['insertonly']['title']);
625 $title = basename($href);
626 if ( !empty($title) && !empty($href) )
627 $html = "<a href='$href' >$title</a>";
628 $html = apply_filters('video_send_to_editor_url', $html, $href, $title);
629 return media_send_to_editor($html);
632 if ( !empty($_POST) ) {
633 $return = media_upload_form_handler();
635 if ( is_string($return) )
637 if ( is_array($return) )
641 if ( isset($_POST['save']) ) {
642 $errors['upload_notice'] = __('Saved.');
643 return media_upload_gallery();
646 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
647 return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id );
649 return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
653 * {@internal Missing Short Description}}
659 function media_upload_file() {
663 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
664 // Upload File button was clicked
665 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
667 if ( is_wp_error($id) ) {
668 $errors['upload_error'] = $id;
673 if ( !empty($_POST['insertonlybutton']) ) {
674 $href = $_POST['insertonly']['href'];
675 if ( !empty($href) && !strpos($href, '://') )
676 $href = "http://$href";
677 $title = esc_attr($_POST['insertonly']['title']);
679 $title = basename($href);
680 if ( !empty($title) && !empty($href) )
681 $html = "<a href='$href' >$title</a>";
682 $html = apply_filters('file_send_to_editor_url', $html, $href, $title);
683 return media_send_to_editor($html);
686 if ( !empty($_POST) ) {
687 $return = media_upload_form_handler();
689 if ( is_string($return) )
691 if ( is_array($return) )
695 if ( isset($_POST['save']) ) {
696 $errors['upload_notice'] = __('Saved.');
697 return media_upload_gallery();
700 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
701 return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id );
703 return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
707 * {@internal Missing Short Description}}
713 function media_upload_gallery() {
716 if ( !empty($_POST) ) {
717 $return = media_upload_form_handler();
719 if ( is_string($return) )
721 if ( is_array($return) )
725 wp_enqueue_script('admin-gallery');
726 return wp_iframe( 'media_upload_gallery_form', $errors );
730 * {@internal Missing Short Description}}
736 function media_upload_library() {
738 if ( !empty($_POST) ) {
739 $return = media_upload_form_handler();
741 if ( is_string($return) )
743 if ( is_array($return) )
747 return wp_iframe( 'media_upload_library_form', $errors );
751 * Retrieve HTML for the image alignment radio buttons with the specified one checked.
755 * @param unknown_type $post
756 * @param unknown_type $checked
759 function image_align_input_fields( $post, $checked = '' ) {
761 $alignments = array('none' => __('None'), 'left' => __('Left'), 'center' => __('Center'), 'right' => __('Right'));
762 if ( !array_key_exists( (string) $checked, $alignments ) )
766 foreach ($alignments as $name => $label) {
767 $name = esc_attr($name);
768 $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'".
769 ( $checked == $name ? " checked='checked'" : "" ) .
770 " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>" . $label . "</label>";
772 return join("\n", $out);
776 * Retrieve HTML for the size radio buttons with the specified one checked.
780 * @param unknown_type $post
781 * @param unknown_type $checked
784 function image_size_input_fields( $post, $checked = '' ) {
786 // get a list of the actual pixel dimensions of each possible intermediate version of this image
787 $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size'));
789 foreach ( $size_names as $size => $name ) {
790 $downsize = image_downsize($post->ID, $size);
792 // is this size selectable?
793 $enabled = ( $downsize[3] || 'full' == $size );
794 $css_id = "image-size-{$size}-{$post->ID}";
795 // if this size is the default but that's not available, don't select it
796 if ( $checked && !$enabled )
798 // if $checked was not specified, default to the first available size that's bigger than a thumbnail
799 if ( !$checked && $enabled && 'thumbnail' != $size )
802 $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'" : '') ." />";
804 $html .= "<label for='{$css_id}'>" . __($name). "</label>";
805 // only show the dimensions if that choice is available
807 $html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d × %d)"), $downsize[1], $downsize[2] ). "</label>";
815 'label' => __('Size'),
817 'html' => join("\n", $out),
822 * Retrieve HTML for the Link URL buttons with the default link type as specified.
826 * @param unknown_type $post
827 * @param unknown_type $url_type
830 function image_link_input_fields($post, $url_type='') {
832 $file = wp_get_attachment_url($post->ID);
833 $link = get_attachment_link($post->ID);
836 if ( $url_type == 'file' )
838 elseif ( $url_type == 'post' )
841 return "<input type='text' class='urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
842 <button type='button' class='button urlnone' title=''>" . __('None') . "</button>
843 <button type='button' class='button urlfile' title='" . esc_attr($file) . "'>" . __('File URL') . "</button>
844 <button type='button' class='button urlpost' title='" . esc_attr($link) . "'>" . __('Post URL') . "</button>
849 * {@internal Missing Short Description}}
853 * @param unknown_type $form_fields
854 * @param unknown_type $post
857 function image_attachment_fields_to_edit($form_fields, $post) {
858 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
859 $form_fields['post_title']['required'] = true;
860 $file = wp_get_attachment_url($post->ID);
862 $form_fields['image_url']['value'] = $file;
864 $form_fields['post_excerpt']['label'] = __('Caption');
865 $form_fields['post_excerpt']['helps'][] = __('Also used as alternate text for the image');
867 $form_fields['post_content']['label'] = __('Description');
869 $form_fields['align'] = array(
870 'label' => __('Alignment'),
872 'html' => image_align_input_fields($post, get_option('image_default_align')),
875 $form_fields['image-size'] = image_size_input_fields($post, get_option('image_default_size'));
880 add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
883 * {@internal Missing Short Description}}
887 * @param unknown_type $form_fields
888 * @param unknown_type $post
891 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
892 unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
896 function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
897 unset($form_fields['image_url']);
902 * {@internal Missing Short Description}}
906 * @param unknown_type $post
907 * @param unknown_type $attachment
910 function image_attachment_fields_to_save($post, $attachment) {
911 if ( substr($post['post_mime_type'], 0, 5) == 'image' ) {
912 if ( strlen(trim($post['post_title'])) == 0 ) {
913 $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid']));
914 $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.');
921 add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2);
924 * {@internal Missing Short Description}}
928 * @param unknown_type $html
929 * @param unknown_type $attachment_id
930 * @param unknown_type $attachment
933 function image_media_send_to_editor($html, $attachment_id, $attachment) {
934 $post =& get_post($attachment_id);
935 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
936 $url = $attachment['url'];
938 if ( isset($attachment['align']) )
939 $align = $attachment['align'];
943 if ( !empty($attachment['image-size']) )
944 $size = $attachment['image-size'];
948 $rel = ( $url == get_attachment_link($attachment_id) );
950 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size);
956 add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3);
959 * {@internal Missing Short Description}}
963 * @param unknown_type $post
964 * @param unknown_type $errors
967 function get_attachment_fields_to_edit($post, $errors = null) {
969 $post =& get_post($post);
970 if ( is_array($post) )
971 $post = (object) $post;
973 $image_url = wp_get_attachment_url($post->ID);
975 $edit_post = sanitize_post($post, 'edit');
977 $form_fields = array(
978 'post_title' => array(
979 'label' => __('Title'),
980 'value' => $edit_post->post_title,
982 'post_excerpt' => array(
983 'label' => __('Caption'),
984 'value' => $edit_post->post_excerpt,
986 'post_content' => array(
987 'label' => __('Description'),
988 'value' => $edit_post->post_content,
989 'input' => 'textarea',
992 'label' => __('Link URL'),
994 'html' => image_link_input_fields($post, get_option('image_default_link_type')),
995 'helps' => __('Enter a link URL or click above for presets.'),
997 'menu_order' => array(
998 'label' => __('Order'),
999 'value' => $edit_post->menu_order
1001 'image_url' => array(
1002 'label' => __('File URL'),
1004 'html' => "<input type='text' class='urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr($image_url) . "' /><br />",
1005 'value' => isset($edit_post->post_url) ? $edit_post->post_url : '',
1006 'helps' => __('Location of the uploaded file.'),
1010 foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
1011 $t = (array) get_taxonomy($taxonomy);
1012 if ( empty($t['label']) )
1013 $t['label'] = $taxonomy;
1014 if ( empty($t['args']) )
1015 $t['args'] = array();
1017 $terms = get_object_term_cache($post->ID, $taxonomy);
1018 if ( empty($terms) )
1019 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
1023 foreach ( $terms as $term )
1024 $values[] = $term->name;
1025 $t['value'] = join(', ', $values);
1027 $form_fields[$taxonomy] = $t;
1030 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
1031 // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
1032 $form_fields = array_merge_recursive($form_fields, (array) $errors);
1034 $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
1036 return $form_fields;
1040 * Retrieve HTML for media items of post gallery.
1042 * The HTML markup retrieved will be created for the progress of SWF Upload
1043 * component. Will also create link for showing and hiding the form to modify
1044 * the image attachment.
1048 * @param int $post_id Optional. Post ID.
1049 * @param array $errors Errors for attachment, if any.
1052 function get_media_items( $post_id, $errors ) {
1054 $post = get_post($post_id);
1055 if ( $post && $post->post_type == 'attachment' )
1056 $attachments = array($post->ID => $post);
1058 $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
1060 if ( is_array($GLOBALS['wp_the_query']->posts) )
1061 foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
1062 $attachments[$attachment->ID] = $attachment;
1066 foreach ( (array) $attachments as $id => $attachment )
1067 if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
1068 $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>";
1074 * Retrieve HTML form for modifying the image attachment.
1078 * @param int $attachment_id Attachment ID for modification.
1079 * @param string|array $args Optional. Override defaults.
1080 * @return string HTML form for attachment.
1082 function get_media_item( $attachment_id, $args = null ) {
1085 $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true, 'show_title' => true );
1086 $args = wp_parse_args( $args, $default_args );
1087 extract( $args, EXTR_SKIP );
1089 global $post_mime_types;
1090 if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) )
1091 $thumb_url = $thumb_url[0];
1095 $toggle_on = __('Show');
1096 $toggle_off = __('Hide');
1098 $post = get_post($attachment_id);
1100 $filename = basename($post->guid);
1101 $title = esc_attr($post->post_title);
1103 if ( $_tags = get_the_tags($attachment_id) ) {
1104 foreach ( $_tags as $tag )
1105 $tags[] = $tag->name;
1106 $tags = esc_attr(join(', ', $tags));
1110 if ( isset($post_mime_types) ) {
1111 $keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type));
1112 $type = array_shift($keys);
1113 $type = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
1116 $form_fields = get_attachment_fields_to_edit($post, $errors);
1119 $class = empty($errors) ? 'startclosed' : 'startopen';
1121 <a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
1122 <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
1124 $class = 'form-table';
1128 $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
1129 $display_title = $show_title ? "<div class='filename new'>" . wp_html_excerpt($display_title, 60) . "</div>" : '';
1131 $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false;
1134 foreach ( $form_fields as $key => $val ) {
1135 if ( 'menu_order' == $key ) {
1137 $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>';
1139 $order = '<input type="hidden" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" />';
1141 unset($form_fields['menu_order']);
1151 <table class='slidetoggle describe $class'>
1152 <thead class='media-item-info'>
1154 <td class='A1B1' rowspan='4'><img class='thumbnail' src='$thumb_url' alt='' /></td>
1157 <tr><td>$post->post_mime_type</td></tr>
1158 <tr><td>" . mysql2date($post->post_date, get_option('time_format')) . "</td></tr>
1159 <tr><td>" . apply_filters('media_meta', '', $post) . "</td></tr>
1165 'required' => false,
1167 'extra_rows' => array(),
1170 $delete_href = wp_nonce_url("post.php?action=delete-post&post=$attachment_id", 'delete-post_' . $attachment_id);
1172 $send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . esc_attr__( 'Insert into Post' ) . "' />";
1174 $delete = "<a href=\"#\" class=\"del-link\" onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __('Delete') . "</a>";
1175 if ( ( $send || $delete ) && !isset($form_fields['buttons']) )
1176 $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $delete
1177 <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>
1178 <a href=\"#\" class=\"del-link\" onclick=\"this.parentNode.style.display='none';return false;\">" . __('Cancel') . "</a></div></td></tr>\n");
1180 $hidden_fields = array();
1182 foreach ( $form_fields as $id => $field ) {
1183 if ( $id{0} == '_' )
1186 if ( !empty($field['tr']) ) {
1187 $item .= $field['tr'];
1191 $field = array_merge($defaults, $field);
1192 $name = "attachments[$attachment_id][$id]";
1194 if ( $field['input'] == 'hidden' ) {
1195 $hidden_fields[$name] = $field['value'];
1199 $required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : '';
1200 $aria_required = $field['required'] ? " aria-required='true' " : '';
1202 $class .= $field['required'] ? ' form-required' : '';
1204 $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'>";
1205 if ( !empty($field[$field['input']]) )
1206 $item .= $field[$field['input']];
1207 elseif ( $field['input'] == 'textarea' ) {
1208 $item .= "<textarea type='text' id='$name' name='$name'" . $aria_required . ">" . esc_html( $field['value'] ) . "</textarea>";
1210 $item .= "<input type='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'" . $aria_required . "/>";
1212 if ( !empty($field['helps']) )
1213 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique((array) $field['helps']) ) . '</p>';
1214 $item .= "</td>\n\t\t</tr>\n";
1216 $extra_rows = array();
1218 if ( !empty($field['errors']) )
1219 foreach ( array_unique((array) $field['errors']) as $error )
1220 $extra_rows['error'][] = $error;
1222 if ( !empty($field['extra_rows']) )
1223 foreach ( $field['extra_rows'] as $class => $rows )
1224 foreach ( (array) $rows as $html )
1225 $extra_rows[$class][] = $html;
1227 foreach ( $extra_rows as $class => $rows )
1228 foreach ( $rows as $html )
1229 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
1232 if ( !empty($form_fields['_final']) )
1233 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
1234 $item .= "\t</tbody>\n";
1235 $item .= "\t</table>\n";
1237 foreach ( $hidden_fields as $name => $value )
1238 $item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
1240 if ( $post->post_parent < 1 && isset($_REQUEST['post_id']) ) {
1241 $parent = (int) $_REQUEST['post_id'];
1242 $parent_name = "attachments[$attachment_id][post_parent]";
1244 $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='" . $parent . "' />\n";
1251 * {@internal Missing Short Description}}
1255 function media_upload_header() {
1257 <script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script>
1258 <div id="media-upload-header">
1259 <?php the_media_upload_tabs(); ?>
1265 * {@internal Missing Short Description}}
1269 * @param unknown_type $errors
1271 function media_upload_form( $errors = null ) {
1274 $flash_action_url = admin_url('async-upload.php');
1276 // If Mac and mod_security, no Flash. :(
1278 if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mac') && apache_mod_loaded('mod_security') )
1281 $flash = apply_filters('flash_uploader', $flash);
1282 $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
1285 <script type="text/javascript">
1287 var uploaderMode = 0;
1288 jQuery(document).ready(function($){
1289 uploaderMode = getUserSetting('uploader');
1290 $('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;});
1291 $('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;});
1295 <div id="media-upload-notice">
1296 <?php if (isset($errors['upload_notice']) ) { ?>
1297 <?php echo $errors['upload_notice']; ?>
1300 <div id="media-upload-error">
1301 <?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?>
1302 <?php echo $errors['upload_error']->get_error_message(); ?>
1306 <?php do_action('pre-upload-ui'); ?>
1308 <?php if ( $flash ) : ?>
1309 <script type="text/javascript">
1312 SWFUpload.onload = function() {
1314 button_text: '<span class="button"><?php _e('Select Files'); ?></span>',
1315 button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana,sans-serif; }',
1316 button_height: "24",
1317 button_width: "132",
1318 button_text_top_padding: 1,
1319 button_image_url: '<?php echo includes_url('images/upload.png'); ?>',
1320 button_placeholder_id: "flash-browse-button",
1321 upload_url : "<?php echo esc_attr( $flash_action_url ); ?>",
1322 flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>",
1323 file_post_name: "async-upload",
1324 file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",
1326 "post_id" : "<?php echo $post_id; ?>",
1327 "auth_cookie" : "<?php if ( is_ssl() ) echo $_COOKIE[SECURE_AUTH_COOKIE]; else echo $_COOKIE[AUTH_COOKIE]; ?>",
1328 "_wpnonce" : "<?php echo wp_create_nonce('media-form'); ?>",
1329 "type" : "<?php echo $type; ?>",
1330 "tab" : "<?php echo $tab; ?>",
1333 file_size_limit : "<?php echo wp_max_upload_size(); ?>b",
1334 file_dialog_start_handler : fileDialogStart,
1335 file_queued_handler : fileQueued,
1336 upload_start_handler : uploadStart,
1337 upload_progress_handler : uploadProgress,
1338 upload_error_handler : uploadError,
1339 upload_success_handler : uploadSuccess,
1340 upload_complete_handler : uploadComplete,
1341 file_queue_error_handler : fileQueueError,
1342 file_dialog_complete_handler : fileDialogComplete,
1343 swfupload_pre_load_handler: swfuploadPreLoad,
1344 swfupload_load_failed_handler: swfuploadLoadFailed,
1346 degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable
1347 swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available
1351 swfu = new SWFUpload(settings);
1356 <div id="flash-upload-ui">
1357 <?php do_action('pre-flash-upload-ui'); ?>
1360 <?php _e( 'Choose files to upload' ); ?>
1361 <div id="flash-browse-button"></div>
1362 <span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span>
1364 <?php do_action('post-flash-upload-ui'); ?>
1365 <p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
1367 <?php endif; // $flash ?>
1369 <div id="html-upload-ui">
1370 <?php do_action('pre-html-upload-ui'); ?>
1371 <p id="async-upload-wrap">
1372 <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>
1373 <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>
1375 <div class="clear"></div>
1376 <?php if ( is_lighttpd_before_150() ): ?>
1377 <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>
1379 <?php do_action('post-html-upload-ui', $flash); ?>
1381 <?php do_action('post-upload-ui'); ?>
1386 * {@internal Missing Short Description}}
1390 * @param unknown_type $type
1391 * @param unknown_type $errors
1392 * @param unknown_type $id
1394 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
1395 media_upload_header();
1397 $post_id = intval($_REQUEST['post_id']);
1399 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
1400 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1403 <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">
1404 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1405 <?php wp_nonce_field('media-form'); ?>
1407 <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
1409 <?php media_upload_form( $errors ); ?>
1411 <script type="text/javascript">
1414 var preloaded = $(".media-item.preloaded");
1415 if ( preloaded.length > 0 ) {
1416 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1422 <div id="media-items">
1425 if ( !is_wp_error($id) ) {
1426 add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
1427 echo get_media_items( $id, $errors );
1429 echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div>';
1435 <p class="savebutton ml-submit">
1436 <input type="submit" class="button" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
1442 * {@internal Missing Short Description}}
1446 * @param unknown_type $type
1447 * @param unknown_type $errors
1448 * @param unknown_type $id
1450 function media_upload_type_url_form($type = 'file', $errors = null, $id = null) {
1451 media_upload_header();
1453 $post_id = intval($_REQUEST['post_id']);
1455 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
1456 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1458 $callback = "type_url_form_$type";
1461 <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">
1462 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1463 <?php wp_nonce_field('media-form'); ?>
1465 <?php if ( is_callable($callback) ) { ?>
1467 <h3 class="media-title"><?php _e('Add media file from URL'); ?></h3>
1469 <script type="text/javascript">
1475 align : 'alignnone',
1477 insert : function() {
1478 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = null;
1480 if ( '' == f.src.value || '' == t.width ) return false;
1482 if ( f.title.value ) {
1483 title = f.title.value.replace(/['"<>]+/g, '');
1484 title = ' title="'+title+'"';
1487 if ( f.alt.value ) {
1488 alt = f.alt.value.replace(/['"<>]+/g, '');
1489 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
1490 caption = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
1494 cls = caption ? '' : ' class="'+t.align+'"';
1496 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
1499 html = '<a href="'+f.url.value+'">'+html+'</a>';
1502 html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';
1504 var win = window.dialogArguments || opener || parent || top;
1505 win.send_to_editor(html);
1508 resetImageData : function() {
1509 var t = addExtImage;
1511 t.width = t.height = '';
1512 document.getElementById('go_button').style.color = '#bbb';
1513 if ( ! document.forms[0].src.value )
1514 document.getElementById('status_img').src = 'images/required.gif';
1515 else document.getElementById('status_img').src = 'images/no.png';
1518 updateImageData : function() {
1519 var t = addExtImage;
1521 t.width = t.preloadImg.width;
1522 t.height = t.preloadImg.height;
1523 document.getElementById('go_button').style.color = '#333';
1524 document.getElementById('status_img').src = 'images/yes.png';
1527 getImageData : function() {
1528 var t = addExtImage, src = document.forms[0].src.value;
1534 document.getElementById('status_img').src = 'images/wpspin_light.gif';
1535 t.preloadImg = new Image();
1536 t.preloadImg.onload = t.updateImageData;
1537 t.preloadImg.onerror = t.resetImageData;
1538 t.preloadImg.src = src;
1544 <div id="media-items">
1545 <div class="media-item media-blank">
1546 <?php echo apply_filters($callback, call_user_func($callback)); ?>
1552 wp_die( __('Unknown action.') );
1557 * {@internal Missing Short Description}}
1561 * @param unknown_type $errors
1563 function media_upload_gallery_form($errors) {
1566 $redir_tab = 'gallery';
1567 media_upload_header();
1569 $post_id = intval($_REQUEST['post_id']);
1570 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id");
1573 <script type="text/javascript">
1576 var preloaded = $(".media-item.preloaded");
1577 if ( preloaded.length > 0 ) {
1578 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1584 <div id="sort-buttons" class="hide-if-no-js">
1586 <?php _e('All Tabs:'); ?>
1587 <a href="#" id="showall"><?php _e('Show'); ?></a>
1588 <a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a>
1590 <?php _e('Sort Order:'); ?>
1591 <a href="#" id="asc"><?php _e('Ascending'); ?></a> |
1592 <a href="#" id="desc"><?php _e('Descending'); ?></a> |
1593 <a href="#" id="clear"><?php _e('Clear'); ?></a>
1595 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
1596 <?php wp_nonce_field('media-form'); ?>
1597 <?php //media_upload_form( $errors ); ?>
1598 <table class="widefat" cellspacing="0">
1600 <th><?php _e('Media'); ?></th>
1601 <th class="order-head"><?php _e('Order'); ?></th>
1604 <div id="media-items">
1605 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
1606 <?php echo get_media_items($post_id, $errors); ?>
1609 <p class="ml-submit">
1610 <input type="submit" class="button savebutton" style="display:none;" name="save" id="save-all" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
1611 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1612 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
1613 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
1616 <div id="gallery-settings" style="display:none;">
1617 <div class="title"><?php _e('Gallery Settings'); ?></div>
1618 <table id="basic" class="describe"><tbody>
1620 <th scope="row" class="label">
1622 <span class="alignleft"><?php _e('Link thumbnails to:'); ?></span>
1626 <input type="radio" name="linkto" id="linkto-file" value="file" />
1627 <label for="linkto-file" class="radio"><?php _e('Image File'); ?></label>
1629 <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" />
1630 <label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label>
1635 <th scope="row" class="label">
1637 <span class="alignleft"><?php _e('Order images by:'); ?></span>
1641 <select id="orderby" name="orderby">
1642 <option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option>
1643 <option value="title"><?php _e('Title'); ?></option>
1644 <option value="ID"><?php _e('Date/Time'); ?></option>
1645 <option value="rand"><?php _e('Random'); ?></option>
1651 <th scope="row" class="label">
1653 <span class="alignleft"><?php _e('Order:'); ?></span>
1657 <input type="radio" checked="checked" name="order" id="order-asc" value="asc" />
1658 <label for="order-asc" class="radio"><?php _e('Ascending'); ?></label>
1660 <input type="radio" name="order" id="order-desc" value="desc" />
1661 <label for="order-desc" class="radio"><?php _e('Descending'); ?></label>
1666 <th scope="row" class="label">
1668 <span class="alignleft"><?php _e('Gallery columns:'); ?></span>
1672 <select id="columns" name="columns">
1673 <option value="2"><?php _e('2'); ?></option>
1674 <option value="3" selected="selected"><?php _e('3'); ?></option>
1675 <option value="4"><?php _e('4'); ?></option>
1676 <option value="5"><?php _e('5'); ?></option>
1677 <option value="6"><?php _e('6'); ?></option>
1678 <option value="7"><?php _e('7'); ?></option>
1679 <option value="8"><?php _e('8'); ?></option>
1680 <option value="9"><?php _e('9'); ?></option>
1686 <p class="ml-submit">
1687 <input type="button" class="button" style="display:none;" onmousedown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" />
1688 <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' ); ?>" />
1696 * {@internal Missing Short Description}}
1700 * @param unknown_type $errors
1702 function media_upload_library_form($errors) {
1703 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
1705 media_upload_header();
1707 $post_id = intval($_REQUEST['post_id']);
1709 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=library&post_id=$post_id");
1711 $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;
1712 if ( $_GET['paged'] < 1 )
1714 $start = ( $_GET['paged'] - 1 ) * 10;
1717 add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
1719 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1723 <form id="filter" action="" method="get">
1724 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />
1725 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />
1726 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
1727 <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" />
1729 <p id="media-search" class="search-box">
1730 <label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label>
1731 <input type="text" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />
1732 <input type="submit" value="<?php esc_attr_e( 'Search Media' ); ?>" class="button" />
1735 <ul class="subsubsub">
1737 $type_links = array();
1738 $_num_posts = (array) wp_count_attachments();
1739 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
1740 foreach ( $matches as $_type => $reals )
1741 foreach ( $reals as $real )
1742 if ( isset($num_posts[$_type]) )
1743 $num_posts[$_type] += $_num_posts[$real];
1745 $num_posts[$_type] = $_num_posts[$real];
1746 // If available type specified by media button clicked, filter by that type
1747 if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {
1748 $_GET['post_mime_type'] = $type;
1749 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1751 if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )
1752 $class = ' class="current"';
1755 $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>";
1756 foreach ( $post_mime_types as $mime_type => $label ) {
1759 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
1762 if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
1763 $class = ' class="current"';
1765 $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>';
1767 echo implode(' | </li>', $type_links) . '</li>';
1772 <div class="tablenav">
1775 $page_links = paginate_links( array(
1776 'base' => add_query_arg( 'paged', '%#%' ),
1778 'prev_text' => __('«'),
1779 'next_text' => __('»'),
1780 'total' => ceil($wp_query->found_posts / 10),
1781 'current' => $_GET['paged']
1785 echo "<div class='tablenav-pages'>$page_links</div>";
1788 <div class="alignleft actions">
1791 $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";
1793 $arc_result = $wpdb->get_results( $arc_query );
1795 $month_count = count($arc_result);
1797 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
1799 <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
1801 foreach ($arc_result as $arc_row) {
1802 if ( $arc_row->yyear == 0 )
1804 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
1806 if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
1807 $default = ' selected="selected"';
1811 echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>";
1812 echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" );
1819 <input type="submit" id="post-query-submit" value="<?php echo esc_attr( __( 'Filter »' ) ); ?>" class="button-secondary" />
1823 <br class="clear" />
1827 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="library-form">
1829 <?php wp_nonce_field('media-form'); ?>
1830 <?php //media_upload_form( $errors ); ?>
1832 <script type="text/javascript">
1835 var preloaded = $(".media-item.preloaded");
1836 if ( preloaded.length > 0 ) {
1837 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1844 <div id="media-items">
1845 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
1846 <?php echo get_media_items(null, $errors); ?>
1848 <p class="ml-submit">
1849 <input type="submit" class="button savebutton" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
1850 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1857 * {@internal Missing Short Description}}
1863 function type_url_form_image() {
1865 if ( apply_filters( 'disable_captions', '' ) ) {
1866 $alt = __('Alternate Text');
1867 $alt_help = __('Alt text for the image, e.g. “The Mona Lisa”');
1869 $alt = __('Image Caption');
1870 $alt_help = __('Also used as alternate text for the image');
1873 $default_align = get_option('image_default_align');
1874 if ( empty($default_align) )
1875 $default_align = 'none';
1878 <table class="describe"><tbody>
1880 <th valign="top" scope="row" class="label" style="width:120px;">
1881 <span class="alignleft"><label for="src">' . __('Image URL') . '</label></span>
1882 <span class="alignright"><img id="status_img" src="images/required.gif" title="required" alt="required" /></span>
1884 <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
1888 <th valign="top" scope="row" class="label">
1889 <span class="alignleft"><label for="title">' . __('Image Title') . '</label></span>
1890 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1892 <td class="field"><p><input id="title" name="title" value="" type="text" aria-required="true" /></p></td>
1896 <th valign="top" scope="row" class="label">
1897 <span class="alignleft"><label for="alt">' . $alt . '</label></span>
1899 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
1900 <p class="help">' . $alt_help . '</p></td>
1904 <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
1906 <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
1907 <label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
1908 <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
1909 <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
1910 <input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' />
1911 <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
1912 <input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
1913 <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
1918 <th valign="top" scope="row" class="label">
1919 <span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span>
1921 <td class="field"><input id="url" name="url" value="" type="text" /><br />
1923 <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
1924 <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
1925 <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
1931 <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
1940 * {@internal Missing Short Description}}
1946 function type_url_form_audio() {
1948 <table class="describe"><tbody>
1950 <th valign="top" scope="row" class="label">
1951 <span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span>
1952 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1954 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1957 <th valign="top" scope="row" class="label">
1958 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1959 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1961 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1963 <tr><td></td><td class="help">' . __('Link text, e.g. “Still Alive by Jonathan Coulton”') . '</td></tr>
1967 <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
1975 * {@internal Missing Short Description}}
1981 function type_url_form_video() {
1983 <table class="describe"><tbody>
1985 <th valign="top" scope="row" class="label">
1986 <span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span>
1987 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1989 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1992 <th valign="top" scope="row" class="label">
1993 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1994 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1996 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1998 <tr><td></td><td class="help">' . __('Link text, e.g. “Lucy on YouTube“') . '</td></tr>
2002 <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
2010 * {@internal Missing Short Description}}
2016 function type_url_form_file() {
2018 <table class="describe"><tbody>
2020 <th valign="top" scope="row" class="label">
2021 <span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span>
2022 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2024 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
2027 <th valign="top" scope="row" class="label">
2028 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
2029 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2031 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
2033 <tr><td></td><td class="help">' . __('Link text, e.g. “Ransom Demands (PDF)”') . '</td></tr>
2037 <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
2045 * {@internal Missing Short Description}}
2047 * Support a GET parameter for disabling the flash uploader.
2051 * @param unknown_type $flash
2054 function media_upload_use_flash($flash) {
2055 if ( array_key_exists('flash', $_REQUEST) )
2056 $flash = !empty($_REQUEST['flash']);
2060 add_filter('flash_uploader', 'media_upload_use_flash');
2063 * {@internal Missing Short Description}}
2067 function media_upload_flash_bypass() {
2068 echo '<p class="upload-flash-bypass">';
2069 printf( __('You are using the Flash uploader. Problems? Try the <a href="%s">Browser uploader</a> instead.'), esc_url(add_query_arg('flash', 0)) );
2074 * {@internal Missing Short Description}}
2078 function media_upload_html_bypass($flash = true) {
2079 echo '<p class="upload-html-bypass">';
2080 _e('You are using the Browser uploader.');
2082 // the user manually selected the browser uploader, so let them switch back to Flash
2084 printf( __('Try the <a href="%s">Flash uploader</a> instead.'), esc_url(add_query_arg('flash', 1)) );
2089 add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
2090 add_action('post-html-upload-ui', 'media_upload_html_bypass');
2093 * {@internal Missing Short Description}}
2095 * Make sure the GET parameter sticks when we submit a form.
2099 * @param unknown_type $url
2102 function media_upload_bypass_url($url) {
2103 if ( array_key_exists('flash', $_REQUEST) )
2104 $url = add_query_arg('flash', intval($_REQUEST['flash']));
2108 add_filter('media_upload_form_url', 'media_upload_bypass_url');
2110 add_filter('async_upload_image', 'get_media_item', 10, 2);
2111 add_filter('async_upload_audio', 'get_media_item', 10, 2);
2112 add_filter('async_upload_video', 'get_media_item', 10, 2);
2113 add_filter('async_upload_file', 'get_media_item', 10, 2);
2115 add_action('media_upload_image', 'media_upload_image');
2116 add_action('media_upload_audio', 'media_upload_audio');
2117 add_action('media_upload_video', 'media_upload_video');
2118 add_action('media_upload_file', 'media_upload_file');
2120 add_filter('media_upload_gallery', 'media_upload_gallery');
2122 add_filter('media_upload_library', 'media_upload_library');