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 $keys = array_keys($tabs);
74 $current = array_shift($keys);
76 foreach ( $tabs as $callback => $text ) {
78 if ( $current == $callback )
79 $class = " class='current'";
80 $href = add_query_arg(array('tab'=>$callback, 's'=>false, 'paged'=>false, 'post_mime_type'=>false, 'm'=>false));
81 $link = "<a href='" . clean_url($href) . "'$class>$text</a>";
82 echo "\t<li id='" . attribute_escape("tab-$callback") . "'>$link</li>\n";
89 * {@internal Missing Short Description}}
93 * @param unknown_type $id
94 * @param unknown_type $alt
95 * @param unknown_type $title
96 * @param unknown_type $align
97 * @param unknown_type $url
98 * @param unknown_type $rel
99 * @param unknown_type $size
102 function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
104 $htmlalt = ( empty($alt) ) ? $title : $alt;
106 $html = get_image_tag($id, $htmlalt, $title, $align, $size);
108 $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
111 $html = '<a href="' . clean_url($url) . "\"$rel>$html</a>";
113 $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size );
119 * {@internal Missing Short Description}}
123 * @param unknown_type $html
124 * @param unknown_type $id
125 * @param unknown_type $alt
126 * @param unknown_type $title
127 * @param unknown_type $align
128 * @param unknown_type $url
129 * @param unknown_type $size
132 function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) {
134 if ( empty($alt) || apply_filters( 'disable_captions', '' ) ) return $html;
135 $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
137 preg_match( '/width="([0-9]+)/', $html, $matches );
138 if ( ! isset($matches[1]) ) return $html;
139 $width = $matches[1];
141 $html = preg_replace( '/align[^\s\'"]+\s?/', '', $html );
142 if ( empty($align) ) $align = 'none';
144 $alt = ! empty($alt) ? addslashes($alt) : '';
146 $shcode = '[caption id="' . $id . '" align="align' . $align
147 . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/caption]';
149 return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
151 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 );
154 * {@internal Missing Short Description}}
158 * @param unknown_type $html
160 function media_send_to_editor($html) {
162 <script type="text/javascript">
164 var win = window.dialogArguments || opener || parent || top;
165 win.send_to_editor('<?php echo addslashes($html); ?>');
173 * {@internal Missing Short Description}}
175 * This handles the file upload POST itself, creating the attachment post.
179 * @param unknown_type $file_id
180 * @param unknown_type $post_id
181 * @param unknown_type $post_data
184 function media_handle_upload($file_id, $post_id, $post_data = array()) {
185 $overrides = array('test_form'=>false);
187 $time = current_time('mysql');
188 if ( $post = get_post($post_id) ) {
189 if ( substr( $post->post_date, 0, 4 ) > 0 )
190 $time = $post->post_date;
193 $file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
195 if ( isset($file['error']) )
196 return new WP_Error( 'upload_error', $file['error'] );
199 $type = $file['type'];
200 $file = $file['file'];
201 $title = preg_replace('/\.[^.]+$/', '', basename($file));
204 // use image exif/iptc data for title and caption defaults if possible
205 if ( $image_meta = @wp_read_image_metadata($file) ) {
206 if ( trim($image_meta['title']) )
207 $title = $image_meta['title'];
208 if ( trim($image_meta['caption']) )
209 $content = $image_meta['caption'];
212 // Construct the attachment array
213 $attachment = array_merge( array(
214 'post_mime_type' => $type,
216 'post_parent' => $post_id,
217 'post_title' => $title,
218 'post_content' => $content,
222 $id = wp_insert_attachment($attachment, $file, $post_id);
223 if ( !is_wp_error($id) ) {
224 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
232 * {@internal Missing Short Description}}
236 * @param unknown_type $file_array
237 * @param unknown_type $post_id
238 * @param unknown_type $desc
239 * @param unknown_type $post_data
242 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
243 $overrides = array('test_form'=>false);
244 $file = wp_handle_sideload($file_array, $overrides);
246 if ( isset($file['error']) )
247 return new WP_Error( 'upload_error', $file['error'] );
250 $type = $file['type'];
251 $file = $file['file'];
252 $title = preg_replace('/\.[^.]+$/', '', basename($file));
255 // use image exif/iptc data for title and caption defaults if possible
256 if ( $image_meta = @wp_read_image_metadata($file) ) {
257 if ( trim($image_meta['title']) )
258 $title = $image_meta['title'];
259 if ( trim($image_meta['caption']) )
260 $content = $image_meta['caption'];
265 // Construct the attachment array
266 $attachment = array_merge( array(
267 'post_mime_type' => $type,
269 'post_parent' => $post_id,
270 'post_title' => $title,
271 'post_content' => $content,
275 $id = wp_insert_attachment($attachment, $file, $post_id);
276 if ( !is_wp_error($id) ) {
277 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
284 * {@internal Missing Short Description}}
286 * Wrap iframe content (produced by $content_func) in a doctype, html head/body
287 * etc any additional function args will be passed to content_func.
291 * @param unknown_type $content_func
293 function wp_iframe($content_func /* ... */) {
295 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
296 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
298 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
299 <title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?></title>
301 wp_enqueue_style( 'global' );
302 wp_enqueue_style( 'wp-admin' );
303 wp_enqueue_style( 'colors' );
304 if ( 0 === strpos( $content_func, 'media' ) )
305 wp_enqueue_style( 'media' );
308 <script type="text/javascript">
310 function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}else{ var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}
314 do_action('admin_print_styles');
315 do_action('admin_print_scripts');
316 do_action('admin_head');
317 if ( is_string($content_func) )
318 do_action( "admin_head_{$content_func}" );
321 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>>
323 $args = func_get_args();
324 $args = array_slice($args, 1);
325 call_user_func_array($content_func, $args);
333 * {@internal Missing Short Description}}
337 function media_buttons() {
338 global $post_ID, $temp_ID;
339 $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
340 $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
341 $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
342 $media_title = __('Add Media');
343 $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&type=image");
344 $image_title = __('Add an Image');
345 $video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src&type=video");
346 $video_title = __('Add Video');
347 $audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src&type=audio");
348 $audio_title = __('Add Audio');
351 <a href="{$image_upload_iframe_src}&TB_iframe=true" id="add_image" class="thickbox" title='$image_title'><img src='images/media-button-image.gif' alt='$image_title' /></a>
352 <a href="{$video_upload_iframe_src}&TB_iframe=true" id="add_video" class="thickbox" title='$video_title'><img src='images/media-button-video.gif' alt='$video_title' /></a>
353 <a href="{$audio_upload_iframe_src}&TB_iframe=true" id="add_audio" class="thickbox" title='$audio_title'><img src='images/media-button-music.gif' alt='$audio_title' /></a>
354 <a href="{$media_upload_iframe_src}&TB_iframe=true" id="add_media" class="thickbox" title='$media_title'><img src='images/media-button-other.gif' alt='$media_title' /></a>
357 printf($context, $out);
359 add_action( 'media_buttons', 'media_buttons' );
360 add_action('media_upload_media', 'media_upload_handler');
363 * {@internal Missing Short Description}}
369 function media_upload_form_handler() {
370 check_admin_referer('media-form');
372 if ( isset($_POST['send']) ) {
373 $keys = array_keys($_POST['send']);
374 $send_id = (int) array_shift($keys);
377 if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
378 $post = $_post = get_post($attachment_id, ARRAY_A);
379 if ( isset($attachment['post_content']) )
380 $post['post_content'] = $attachment['post_content'];
381 if ( isset($attachment['post_title']) )
382 $post['post_title'] = $attachment['post_title'];
383 if ( isset($attachment['post_excerpt']) )
384 $post['post_excerpt'] = $attachment['post_excerpt'];
385 if ( isset($attachment['menu_order']) )
386 $post['menu_order'] = $attachment['menu_order'];
387 if ( isset($send_id) && $attachment_id == $send_id ) {
388 if ( isset($attachment['post_parent']) )
389 $post['post_parent'] = $attachment['post_parent'];
392 $post = apply_filters('attachment_fields_to_save', $post, $attachment);
394 if ( isset($post['errors']) ) {
395 $errors[$attachment_id] = $post['errors'];
396 unset($post['errors']);
399 if ( $post != $_post )
400 wp_update_post($post);
402 foreach ( get_attachment_taxonomies($post) as $t )
403 if ( isset($attachment[$t]) )
404 wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
407 if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?>
408 <script type="text/javascript">
410 var win = window.dialogArguments || opener || parent || top;
418 if ( isset($send_id) ) {
419 $attachment = stripslashes_deep( $_POST['attachments'][$send_id] );
420 $html = $attachment['post_title'];
421 if ( !empty($attachment['url']) ) {
422 if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
423 $rel = " rel='attachment wp-att-".attribute_escape($send_id)."'";
424 $html = "<a href='{$attachment['url']}'$rel>$html</a>";
426 $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
427 return media_send_to_editor($html);
434 * {@internal Missing Short Description}}
440 function media_upload_image() {
444 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
445 // Upload File button was clicked
446 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
448 if ( is_wp_error($id) ) {
449 $errors['upload_error'] = $id;
454 if ( !empty($_POST['insertonlybutton']) ) {
455 $src = $_POST['insertonly']['src'];
456 if ( !empty($src) && !strpos($src, '://') )
457 $src = "http://$src";
458 $alt = attribute_escape($_POST['insertonly']['alt']);
459 if ( isset($_POST['insertonly']['align']) ) {
460 $align = attribute_escape($_POST['insertonly']['align']);
461 $class = " class='align$align'";
464 $html = "<img src='$src' alt='$alt'$class />";
465 return media_send_to_editor($html);
468 if ( !empty($_POST) ) {
469 $return = media_upload_form_handler();
471 if ( is_string($return) )
473 if ( is_array($return) )
477 if ( isset($_POST['save']) ) {
478 $errors['upload_notice'] = __('Saved.');
479 return media_upload_gallery();
482 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
483 return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id );
485 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
489 * {@internal Missing Short Description}}
493 * @param unknown_type $file
494 * @param unknown_type $post_id
495 * @param unknown_type $desc
498 function media_sideload_image($file, $post_id, $desc = null) {
499 if (!empty($file) ) {
500 $file_array['name'] = basename($file);
501 $tmp = download_url($file);
502 $file_array['tmp_name'] = $tmp;
505 if ( is_wp_error($tmp) ) {
506 @unlink($file_array['tmp_name']);
507 $file_array['tmp_name'] = '';
510 $id = media_handle_sideload($file_array, $post_id, $desc);
513 if ( is_wp_error($id) ) {
514 @unlink($file_array['tmp_name']);
519 if ( !empty($src) ) {
521 $html = "<img src='$src' alt='$alt' />";
527 * {@internal Missing Short Description}}
533 function media_upload_audio() {
537 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
538 // Upload File button was clicked
539 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
541 if ( is_wp_error($id) ) {
542 $errors['upload_error'] = $id;
547 if ( !empty($_POST['insertonlybutton']) ) {
548 $href = $_POST['insertonly']['href'];
549 if ( !empty($href) && !strpos($href, '://') )
550 $href = "http://$href";
551 $title = attribute_escape($_POST['insertonly']['title']);
553 $title = basename($href);
554 if ( !empty($title) && !empty($href) )
555 $html = "<a href='$href' >$title</a>";
556 return media_send_to_editor($html);
559 if ( !empty($_POST) ) {
560 $return = media_upload_form_handler();
562 if ( is_string($return) )
564 if ( is_array($return) )
568 if ( isset($_POST['save']) ) {
569 $errors['upload_notice'] = __('Saved.');
570 return media_upload_gallery();
573 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
574 return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id );
576 return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
580 * {@internal Missing Short Description}}
586 function media_upload_video() {
590 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
591 // Upload File button was clicked
592 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
594 if ( is_wp_error($id) ) {
595 $errors['upload_error'] = $id;
600 if ( !empty($_POST['insertonlybutton']) ) {
601 $href = $_POST['insertonly']['href'];
602 if ( !empty($href) && !strpos($href, '://') )
603 $href = "http://$href";
604 $title = attribute_escape($_POST['insertonly']['title']);
606 $title = basename($href);
607 if ( !empty($title) && !empty($href) )
608 $html = "<a href='$href' >$title</a>";
609 return media_send_to_editor($html);
612 if ( !empty($_POST) ) {
613 $return = media_upload_form_handler();
615 if ( is_string($return) )
617 if ( is_array($return) )
621 if ( isset($_POST['save']) ) {
622 $errors['upload_notice'] = __('Saved.');
623 return media_upload_gallery();
626 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
627 return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id );
629 return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
633 * {@internal Missing Short Description}}
639 function media_upload_file() {
643 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
644 // Upload File button was clicked
645 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
647 if ( is_wp_error($id) ) {
648 $errors['upload_error'] = $id;
653 if ( !empty($_POST['insertonlybutton']) ) {
654 $href = $_POST['insertonly']['href'];
655 if ( !empty($href) && !strpos($href, '://') )
656 $href = "http://$href";
657 $title = attribute_escape($_POST['insertonly']['title']);
659 $title = basename($href);
660 if ( !empty($title) && !empty($href) )
661 $html = "<a href='$href' >$title</a>";
662 return media_send_to_editor($html);
665 if ( !empty($_POST) ) {
666 $return = media_upload_form_handler();
668 if ( is_string($return) )
670 if ( is_array($return) )
674 if ( isset($_POST['save']) ) {
675 $errors['upload_notice'] = __('Saved.');
676 return media_upload_gallery();
679 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
680 return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id );
682 return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
686 * {@internal Missing Short Description}}
692 function media_upload_gallery() {
695 if ( !empty($_POST) ) {
696 $return = media_upload_form_handler();
698 if ( is_string($return) )
700 if ( is_array($return) )
704 wp_enqueue_script('admin-gallery');
705 return wp_iframe( 'media_upload_gallery_form', $errors );
709 * {@internal Missing Short Description}}
715 function media_upload_library() {
717 if ( !empty($_POST) ) {
718 $return = media_upload_form_handler();
720 if ( is_string($return) )
722 if ( is_array($return) )
726 return wp_iframe( 'media_upload_library_form', $errors );
730 * Retrieve HTML for the image alignment radio buttons with the specified one checked.
734 * @param unknown_type $post
735 * @param unknown_type $checked
738 function image_align_input_fields($post, $checked='') {
740 $alignments = array('none' => 'None', 'left' => 'Left', 'center' => 'Center', 'right' => 'Right');
741 if ( !array_key_exists($checked, $alignments) )
745 foreach ($alignments as $name => $label) {
747 $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'".
748 ( $checked == $name ? " checked='checked'" : "" ) .
749 " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>" . __($label) . "</label>";
751 return join("\n", $out);
755 * Retrieve HTML for the size radio buttons with the specified one checked.
759 * @param unknown_type $post
760 * @param unknown_type $checked
763 function image_size_input_fields($post, $checked='') {
765 // get a list of the actual pixel dimensions of each possible intermediate version of this image
766 $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size'));
768 foreach ( $size_names as $size => $name) {
769 $downsize = image_downsize($post->ID, $size);
771 // is this size selectable?
772 $enabled = ( $downsize[3] || 'full' == $size );
773 $css_id = "image-size-{$size}-{$post->ID}";
774 // if this size is the default but that's not available, don't select it
775 if ( $checked && !$enabled )
777 // if $checked was not specified, default to the first available size that's bigger than a thumbnail
778 if ( !$checked && $enabled && 'thumbnail' != $size )
781 $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'" : '') ." />";
783 $html .= "<label for='{$css_id}'>" . __($name). "</label>";
784 // only show the dimensions if that choice is available
786 $html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d × %d)"), $downsize[1], $downsize[2] ). "</label>";
794 'label' => __('Size'),
796 'html' => join("\n", $out),
801 * Retrieve HTML for the Link URL buttons with the default link type as specified.
805 * @param unknown_type $post
806 * @param unknown_type $url_type
809 function image_link_input_fields($post, $url_type='') {
811 $file = wp_get_attachment_url($post->ID);
812 $link = get_attachment_link($post->ID);
815 if ( $url_type == 'file' )
817 elseif ( $url_type == 'post' )
820 return "<input type='text' class='urlfield' name='attachments[$post->ID][url]' value='" . attribute_escape($url) . "' /><br />
821 <button type='button' class='button urlnone' title=''>" . __('None') . "</button>
822 <button type='button' class='button urlfile' title='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
823 <button type='button' class='button urlpost' title='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>
828 * {@internal Missing Short Description}}
832 * @param unknown_type $form_fields
833 * @param unknown_type $post
836 function image_attachment_fields_to_edit($form_fields, $post) {
837 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
838 $form_fields['post_title']['required'] = true;
840 $form_fields['post_excerpt']['label'] = __('Caption');
841 $form_fields['post_excerpt']['helps'][] = __('Also used as alternate text for the image');
843 $form_fields['post_content']['label'] = __('Description');
845 $form_fields['align'] = array(
846 'label' => __('Alignment'),
848 'html' => image_align_input_fields($post, get_option('image_default_align')),
851 $form_fields['image-size'] = image_size_input_fields($post, get_option('image_default_size'));
856 add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
859 * {@internal Missing Short Description}}
863 * @param unknown_type $form_fields
864 * @param unknown_type $post
867 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
868 unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
873 * {@internal Missing Short Description}}
877 * @param unknown_type $post
878 * @param unknown_type $attachment
881 function image_attachment_fields_to_save($post, $attachment) {
882 if ( substr($post['post_mime_type'], 0, 5) == 'image' ) {
883 if ( strlen(trim($post['post_title'])) == 0 ) {
884 $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid']));
885 $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.');
892 add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2);
895 * {@internal Missing Short Description}}
899 * @param unknown_type $html
900 * @param unknown_type $attachment_id
901 * @param unknown_type $attachment
904 function image_media_send_to_editor($html, $attachment_id, $attachment) {
905 $post =& get_post($attachment_id);
906 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
907 $url = $attachment['url'];
909 if ( isset($attachment['align']) )
910 $align = $attachment['align'];
914 if ( !empty($attachment['image-size']) )
915 $size = $attachment['image-size'];
919 $rel = ( $url == get_attachment_link($attachment_id) );
921 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size);
927 add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3);
930 * {@internal Missing Short Description}}
934 * @param unknown_type $post
935 * @param unknown_type $errors
938 function get_attachment_fields_to_edit($post, $errors = null) {
940 $post =& get_post($post);
941 if ( is_array($post) )
942 $post = (object) $post;
944 $edit_post = sanitize_post($post, 'edit');
946 $form_fields = array(
947 'post_title' => array(
948 'label' => __('Title'),
949 'value' => $edit_post->post_title,
951 'post_excerpt' => array(
952 'label' => __('Caption'),
953 'value' => $edit_post->post_excerpt,
955 'post_content' => array(
956 'label' => __('Description'),
957 'value' => $edit_post->post_content,
958 'input' => 'textarea',
961 'label' => __('Link URL'),
963 'html' => image_link_input_fields($post, get_option('image_default_link_type')),
964 'helps' => __('Enter a link URL or click above for presets.'),
966 'menu_order' => array(
967 'label' => __('Order'),
968 'value' => $edit_post->menu_order
972 foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
973 $t = (array) get_taxonomy($taxonomy);
974 if ( empty($t['label']) )
975 $t['label'] = $taxonomy;
976 if ( empty($t['args']) )
977 $t['args'] = array();
979 $terms = get_object_term_cache($post->ID, $taxonomy);
981 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
985 foreach ( $terms as $term )
986 $values[] = $term->name;
987 $t['value'] = join(', ', $values);
989 $form_fields[$taxonomy] = $t;
992 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
993 // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
994 $form_fields = array_merge_recursive($form_fields, (array) $errors);
996 $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
1002 * Retrieve HTML for media items of post gallery.
1004 * The HTML markup retrieved will be created for the progress of SWF Upload
1005 * component. Will also create link for showing and hiding the form to modify
1006 * the image attachment.
1010 * @param int $post_id Optional. Post ID.
1011 * @param array $errors Errors for attachment, if any.
1014 function get_media_items( $post_id, $errors ) {
1016 $post = get_post($post_id);
1017 if ( $post && $post->post_type == 'attachment' )
1018 $attachments = array($post->ID => $post);
1020 $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
1022 if ( is_array($GLOBALS['wp_the_query']->posts) )
1023 foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
1024 $attachments[$attachment->ID] = $attachment;
1028 foreach ( (array) $attachments as $id => $attachment )
1029 if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
1030 $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>";
1036 * Retrieve HTML form for modifying the image attachment.
1040 * @param int $attachment_id Attachment ID for modification.
1041 * @param string|array $args Optional. Override defaults.
1042 * @return string HTML form for attachment.
1044 function get_media_item( $attachment_id, $args = null ) {
1047 $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true, 'show_title' => true );
1048 $args = wp_parse_args( $args, $default_args );
1049 extract( $args, EXTR_SKIP );
1051 global $post_mime_types;
1052 if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) )
1053 $thumb_url = $thumb_url[0];
1057 $toggle_on = __('Show');
1058 $toggle_off = __('Hide');
1060 $post = get_post($attachment_id);
1062 $filename = basename($post->guid);
1063 $title = attribute_escape($post->post_title);
1065 if ( $_tags = get_the_tags($attachment_id) ) {
1066 foreach ( $_tags as $tag )
1067 $tags[] = $tag->name;
1068 $tags = attribute_escape(join(', ', $tags));
1072 if ( isset($post_mime_types) ) {
1073 $keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type));
1074 $type = array_shift($keys);
1075 $type = "<input type='hidden' id='type-of-$attachment_id' value='" . attribute_escape( $type ) . "' />";
1078 $form_fields = get_attachment_fields_to_edit($post, $errors);
1081 $class = empty($errors) ? 'startclosed' : 'startopen';
1083 <a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
1084 <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
1086 $class = 'form-table';
1090 $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
1091 $display_title = $show_title ? "<div class='filename new'>" . wp_html_excerpt($display_title, 60) . "</div>" : '';
1093 $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false;
1096 foreach ( $form_fields as $key => $val ) {
1097 if ( 'menu_order' == $key ) {
1099 $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>';
1101 $order = '<input type="hidden" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" />';
1103 unset($form_fields['menu_order']);
1113 <table class='slidetoggle describe $class'>
1114 <thead class='media-item-info'>
1116 <td class='A1B1' rowspan='4'><img class='thumbnail' src='$thumb_url' alt='' /></td>
1119 <tr><td>$post->post_mime_type</td></tr>
1120 <tr><td>" . mysql2date($post->post_date, get_option('time_format')) . "</td></tr>
1121 <tr><td>" . apply_filters('media_meta', '', $post) . "</td></tr>
1127 'required' => false,
1129 'extra_rows' => array(),
1132 $delete_href = wp_nonce_url("post.php?action=delete-post&post=$attachment_id", 'delete-post_' . $attachment_id);
1134 $send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . attribute_escape( __( 'Insert into Post' ) ) . "' />";
1136 $delete = "<a href=\"#\" class=\"del-link\" onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __('Delete') . "</a>";
1137 if ( ( $send || $delete ) && !isset($form_fields['buttons']) )
1138 $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $delete
1139 <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>
1140 <a href=\"#\" class=\"del-link\" onclick=\"this.parentNode.style.display='none';return false;\">" . __('Cancel') . "</a></div></td></tr>\n");
1142 $hidden_fields = array();
1144 foreach ( $form_fields as $id => $field ) {
1145 if ( $id{0} == '_' )
1148 if ( !empty($field['tr']) ) {
1149 $item .= $field['tr'];
1153 $field = array_merge($defaults, $field);
1154 $name = "attachments[$attachment_id][$id]";
1156 if ( $field['input'] == 'hidden' ) {
1157 $hidden_fields[$name] = $field['value'];
1161 $required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : '';
1162 $aria_required = $field['required'] ? " aria-required='true' " : '';
1164 $class .= $field['required'] ? ' form-required' : '';
1166 $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'>";
1167 if ( !empty($field[$field['input']]) )
1168 $item .= $field[$field['input']];
1169 elseif ( $field['input'] == 'textarea' ) {
1170 $item .= "<textarea type='text' id='$name' name='$name'" . $aria_required . ">" . htmlspecialchars( $field['value'] ) . "</textarea>";
1172 $item .= "<input type='text' id='$name' name='$name' value='" . attribute_escape( $field['value'] ) . "'" . $aria_required . "/>";
1174 if ( !empty($field['helps']) )
1175 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique((array) $field['helps']) ) . '</p>';
1176 $item .= "</td>\n\t\t</tr>\n";
1178 $extra_rows = array();
1180 if ( !empty($field['errors']) )
1181 foreach ( array_unique((array) $field['errors']) as $error )
1182 $extra_rows['error'][] = $error;
1184 if ( !empty($field['extra_rows']) )
1185 foreach ( $field['extra_rows'] as $class => $rows )
1186 foreach ( (array) $rows as $html )
1187 $extra_rows[$class][] = $html;
1189 foreach ( $extra_rows as $class => $rows )
1190 foreach ( $rows as $html )
1191 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
1194 if ( !empty($form_fields['_final']) )
1195 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
1196 $item .= "\t</tbody>\n";
1197 $item .= "\t</table>\n";
1199 foreach ( $hidden_fields as $name => $value )
1200 $item .= "\t<input type='hidden' name='$name' id='$name' value='" . attribute_escape( $value ) . "' />\n";
1202 if ( $post->post_parent < 1 && (int) $_REQUEST['post_id'] ) {
1203 $parent = (int) $_REQUEST['post_id'];
1204 $parent_name = "attachments[$attachment_id][post_parent]";
1206 $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='" . $parent . "' />\n";
1213 * {@internal Missing Short Description}}
1217 function media_upload_header() {
1219 <script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script>
1220 <div id="media-upload-header">
1221 <?php the_media_upload_tabs(); ?>
1227 * {@internal Missing Short Description}}
1231 * @param unknown_type $errors
1233 function media_upload_form( $errors = null ) {
1236 $flash_action_url = admin_url('async-upload.php');
1238 // If Mac and mod_security, no Flash. :(
1240 if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mac') && apache_mod_loaded('mod_security') )
1243 $flash = apply_filters('flash_uploader', $flash);
1244 $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
1247 <div id="media-upload-notice">
1248 <?php if (isset($errors['upload_notice']) ) { ?>
1249 <?php echo $errors['upload_notice']; ?>
1252 <div id="media-upload-error">
1253 <?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?>
1254 <?php echo $errors['upload_error']->get_error_message(); ?>
1258 <?php do_action('pre-upload-ui'); ?>
1260 <?php if ( $flash ) : ?>
1261 <script type="text/javascript">
1263 SWFUpload.onload = function() {
1264 swfu = new SWFUpload({
1265 button_text: '<span class="button"><?php _e('Select Files'); ?></span>',
1266 button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana,sans-serif; }',
1267 button_height: "24",
1268 button_width: "132",
1269 button_image_url: '<?php echo includes_url('images/upload.png'); ?>',
1270 button_placeholder_id: "flash-browse-button",
1271 upload_url : "<?php echo attribute_escape( $flash_action_url ); ?>",
1272 flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>",
1273 file_post_name: "async-upload",
1274 file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",
1276 "post_id" : "<?php echo $post_id; ?>",
1277 "auth_cookie" : "<?php if ( is_ssl() ) echo $_COOKIE[SECURE_AUTH_COOKIE]; else echo $_COOKIE[AUTH_COOKIE]; ?>",
1278 "_wpnonce" : "<?php echo wp_create_nonce('media-form'); ?>",
1279 "type" : "<?php echo $type; ?>",
1280 "tab" : "<?php echo $tab; ?>",
1283 file_size_limit : "<?php echo wp_max_upload_size(); ?>b",
1284 file_dialog_start_handler : fileDialogStart,
1285 file_queued_handler : fileQueued,
1286 upload_start_handler : uploadStart,
1287 upload_progress_handler : uploadProgress,
1288 upload_error_handler : uploadError,
1289 upload_success_handler : uploadSuccess,
1290 upload_complete_handler : uploadComplete,
1291 file_queue_error_handler : fileQueueError,
1292 file_dialog_complete_handler : fileDialogComplete,
1293 swfupload_pre_load_handler: swfuploadPreLoad,
1294 swfupload_load_failed_handler: swfuploadLoadFailed,
1296 degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable
1297 swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available
1305 <div id="flash-upload-ui">
1306 <?php do_action('pre-flash-upload-ui'); ?>
1308 <div><?php _e( 'Choose files to upload' ); ?> <div id="flash-browse-button"></div></div>
1309 <?php do_action('post-flash-upload-ui'); ?>
1310 <p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
1313 <?php endif; // $flash ?>
1315 <div id="html-upload-ui">
1316 <?php do_action('pre-html-upload-ui'); ?>
1317 <p id="async-upload-wrap">
1318 <input type="file" name="async-upload" id="async-upload" /> <input type="submit" class="button" name="html-upload" value="<?php echo attribute_escape(__('Upload')); ?>" /> <a href="#" onclick="return top.tb_remove();"><?php _e('Cancel'); ?></a>
1321 <br class="clear" />
1322 <?php if ( is_lighttpd_before_150() ): ?>
1323 <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>
1325 <?php do_action('post-html-upload-ui'); ?>
1327 <?php do_action('post-upload-ui'); ?>
1332 * {@internal Missing Short Description}}
1336 * @param unknown_type $type
1337 * @param unknown_type $errors
1338 * @param unknown_type $id
1340 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
1341 media_upload_header();
1343 $post_id = intval($_REQUEST['post_id']);
1345 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
1346 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1349 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form">
1350 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1351 <?php wp_nonce_field('media-form'); ?>
1353 <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
1355 <?php media_upload_form( $errors ); ?>
1357 <script type="text/javascript">
1360 var preloaded = $(".media-item.preloaded");
1361 if ( preloaded.length > 0 ) {
1362 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1368 <div id="media-items">
1371 if ( !is_wp_error($id) ) {
1372 echo get_media_items( $id, $errors );
1374 echo '<div id="media-upload-error">'.wp_specialchars($id->get_error_message()).'</div>';
1380 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
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_url_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);
1401 $callback = "type_url_form_$type";
1404 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form">
1405 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1406 <?php wp_nonce_field('media-form'); ?>
1408 <?php if ( is_callable($callback) ) { ?>
1410 <h3 class="media-title"><?php _e('Add media file from URL'); ?></h3>
1412 <script type="text/javascript">
1418 align : 'alignnone',
1420 insert : function() {
1421 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = null;
1423 if ( '' == f.src.value || '' == t.width ) return false;
1425 if ( f.title.value ) {
1426 title = f.title.value.replace(/['"<>]+/g, '');
1427 title = ' title="'+title+'"';
1430 if ( f.alt.value ) {
1431 alt = f.alt.value.replace(/['"<>]+/g, '');
1432 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
1433 caption = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
1437 cls = caption ? '' : ' class="'+t.align+'"';
1439 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
1442 html = '<a href="'+f.url.value+'">'+html+'</a>';
1445 html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';
1447 var win = window.dialogArguments || opener || parent || top;
1448 win.send_to_editor(html);
1451 resetImageData : function() {
1452 var t = addExtImage;
1454 t.width = t.height = '';
1455 document.getElementById('go_button').style.color = '#bbb';
1456 if ( ! document.forms[0].src.value )
1457 document.getElementById('status_img').src = 'images/required.gif';
1458 else document.getElementById('status_img').src = 'images/no.png';
1461 updateImageData : function() {
1462 var t = addExtImage;
1464 t.width = t.preloadImg.width;
1465 t.height = t.preloadImg.height;
1466 document.getElementById('go_button').style.color = '#333';
1467 document.getElementById('status_img').src = 'images/yes.png';
1470 getImageData : function() {
1471 var t = addExtImage, src = document.forms[0].src.value;
1477 document.getElementById('status_img').src = 'images/loading.gif';
1478 t.preloadImg = new Image();
1479 t.preloadImg.onload = t.updateImageData;
1480 t.preloadImg.onerror = t.resetImageData;
1481 t.preloadImg.src = src;
1487 <div id="media-items">
1488 <div class="media-item media-blank">
1489 <?php echo call_user_func($callback); ?>
1495 wp_die( __('Unknown action.') );
1500 * {@internal Missing Short Description}}
1504 * @param unknown_type $errors
1506 function media_upload_gallery_form($errors) {
1509 $redir_tab = 'gallery';
1510 media_upload_header();
1512 $post_id = intval($_REQUEST['post_id']);
1513 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id");
1516 <script type="text/javascript">
1519 var preloaded = $(".media-item.preloaded");
1520 if ( preloaded.length > 0 ) {
1521 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1528 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
1529 <?php wp_nonce_field('media-form'); ?>
1530 <?php //media_upload_form( $errors ); ?>
1531 <table class="widefat" cellspacing="0">
1533 <th><?php _e('Media'); ?></th>
1534 <th class="order-head"><?php _e('Order'); ?></th>
1537 <div id="media-items">
1538 <?php echo get_media_items($post_id, $errors); ?>
1541 <p class="ml-submit">
1542 <input type="submit" class="button savebutton" style="display:none;" name="save" id="save-all" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
1543 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1544 <input type="hidden" name="type" value="<?php echo attribute_escape( $GLOBALS['type'] ); ?>" />
1545 <input type="hidden" name="tab" value="<?php echo attribute_escape( $GLOBALS['tab'] ); ?>" />
1548 <div id="gallery-settings" style="display:none;">
1549 <div class="title"><?php _e('Gallery Settings'); ?></div>
1550 <table id="basic" class="describe"><tbody>
1552 <th scope="row" class="label">
1554 <span class="alignleft"><?php _e('Link thumbnails to:'); ?></span>
1558 <input type="radio" name="linkto" id="linkto-file" value="file" />
1559 <label for="linkto-file" class="radio"><?php _e('Image File'); ?></label>
1561 <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" />
1562 <label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label>
1567 <th scope="row" class="label">
1569 <span class="alignleft"><?php _e('Order images by:'); ?></span>
1573 <select id="orderby" name="orderby">
1574 <option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option>
1575 <option value="post_name"><?php _e('Name'); ?></option>
1576 <option value="ID"><?php _e('Date/Time'); ?></option>
1582 <th scope="row" class="label">
1584 <span class="alignleft"><?php _e('Order:'); ?></span>
1588 <input type="radio" checked="checked" name="order" id="order-asc" value="asc" />
1589 <label for="order-asc" class="radio"><?php _e('Ascending'); ?></label>
1591 <input type="radio" name="order" id="order-desc" value="desc" />
1592 <label for="order-desc" class="radio"><?php _e('Descending'); ?></label>
1597 <th scope="row" class="label">
1599 <span class="alignleft"><?php _e('Gallery columns:'); ?></span>
1603 <select id="columns" name="columns">
1604 <option value="2"><?php _e('2'); ?></option>
1605 <option value="3" selected="selected"><?php _e('3'); ?></option>
1606 <option value="4"><?php _e('4'); ?></option>
1607 <option value="5"><?php _e('5'); ?></option>
1608 <option value="6"><?php _e('6'); ?></option>
1609 <option value="7"><?php _e('7'); ?></option>
1610 <option value="8"><?php _e('8'); ?></option>
1611 <option value="9"><?php _e('9'); ?></option>
1617 <p class="ml-submit">
1618 <input type="button" class="button" style="display:none;" onmousedown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php echo attribute_escape( __( 'Insert gallery' ) ); ?>" />
1619 <input type="button" class="button" style="display:none;" onmousedown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php echo attribute_escape( __( 'Update gallery settings' ) ); ?>" />
1627 * {@internal Missing Short Description}}
1631 * @param unknown_type $errors
1633 function media_upload_library_form($errors) {
1634 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
1636 media_upload_header();
1638 $post_id = intval($_REQUEST['post_id']);
1640 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=library&post_id=$post_id");
1642 $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;
1643 if ( $_GET['paged'] < 1 )
1645 $start = ( $_GET['paged'] - 1 ) * 10;
1648 add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
1650 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1654 <form id="filter" action="" method="get">
1655 <input type="hidden" name="type" value="<?php echo attribute_escape( $type ); ?>" />
1656 <input type="hidden" name="tab" value="<?php echo attribute_escape( $tab ); ?>" />
1657 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
1658 <input type="hidden" name="post_mime_type" value="<?php echo attribute_escape( $_GET['post_mime_type'] ); ?>" />
1660 <p id="media-search" class="search-box">
1661 <label class="hidden" for="media-search-input"><?php _e('Search Media');?>:</label>
1662 <input type="text" id="media-search-input" class="search-input" name="s" value="<?php the_search_query(); ?>" />
1663 <input type="submit" value="<?php echo attribute_escape( __( 'Search Media' ) ); ?>" class="button" />
1666 <ul class="subsubsub">
1668 $type_links = array();
1669 $_num_posts = (array) wp_count_attachments();
1670 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
1671 foreach ( $matches as $_type => $reals )
1672 foreach ( $reals as $real )
1673 $num_posts[$_type] += $_num_posts[$real];
1674 // If available type specified by media button clicked, filter by that type
1675 if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {
1676 $_GET['post_mime_type'] = $type;
1677 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1679 if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )
1680 $class = ' class="current"';
1681 $type_links[] = "<li><a href='" . clean_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>";
1682 foreach ( $post_mime_types as $mime_type => $label ) {
1685 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
1688 if ( wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
1689 $class = ' class="current"';
1691 $type_links[] = "<li><a href='" . clean_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf(__ngettext($label[2][0], $label[2][1], $num_posts[$mime_type]), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>';
1693 echo implode(' | </li>', $type_links) . '</li>';
1698 <div class="tablenav">
1701 $page_links = paginate_links( array(
1702 'base' => add_query_arg( 'paged', '%#%' ),
1704 'prev_text' => __('«'),
1705 'next_text' => __('»'),
1706 'total' => ceil($wp_query->found_posts / 10),
1707 'current' => $_GET['paged']
1711 echo "<div class='tablenav-pages'>$page_links</div>";
1714 <div class="alignleft actions">
1717 $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";
1719 $arc_result = $wpdb->get_results( $arc_query );
1721 $month_count = count($arc_result);
1723 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
1725 <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
1727 foreach ($arc_result as $arc_row) {
1728 if ( $arc_row->yyear == 0 )
1730 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
1732 if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
1733 $default = ' selected="selected"';
1737 echo "<option$default value='" . attribute_escape( $arc_row->yyear . $arc_row->mmonth ) . "'>";
1738 echo wp_specialchars( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" );
1745 <input type="submit" id="post-query-submit" value="<?php echo attribute_escape( __( 'Filter »' ) ); ?>" class="button-secondary" />
1749 <br class="clear" />
1753 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="library-form">
1755 <?php wp_nonce_field('media-form'); ?>
1756 <?php //media_upload_form( $errors ); ?>
1758 <script type="text/javascript">
1761 var preloaded = $(".media-item.preloaded");
1762 if ( preloaded.length > 0 ) {
1763 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1770 <div id="media-items">
1771 <?php echo get_media_items(null, $errors); ?>
1773 <p class="ml-submit">
1774 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
1775 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1782 * {@internal Missing Short Description}}
1788 function type_url_form_image() {
1790 if ( apply_filters( 'disable_captions', '' ) ) {
1791 $alt = __('Alternate Text');
1792 $alt_help = __('Alt text for the image, e.g. "The Mona Lisa"');
1794 $alt = __('Image Caption');
1795 $alt_help = __('Also used as alternate text for the image');
1798 $default_align = get_option('image_default_align');
1799 if ( empty($default_align) )
1800 $default_align = 'none';
1803 <table class="describe"><tbody>
1805 <th valign="top" scope="row" class="label" style="width:120px;">
1806 <span class="alignleft"><label for="src">' . __('Image URL') . '</label></span>
1807 <span class="alignright"><img id="status_img" src="images/required.gif" title="required" alt="required" /></span>
1809 <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
1813 <th valign="top" scope="row" class="label">
1814 <span class="alignleft"><label for="title">' . __('Image Title') . '</label></span>
1815 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1817 <td class="field"><p><input id="title" name="title" value="" type="text" aria-required="true" /></p></td>
1821 <th valign="top" scope="row" class="label">
1822 <span class="alignleft"><label for="alt">' . $alt . '</label></span>
1824 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
1825 <p class="help">' . $alt_help . '</p></td>
1829 <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
1831 <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
1832 <label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
1833 <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
1834 <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
1835 <input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' />
1836 <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
1837 <input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
1838 <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
1843 <th valign="top" scope="row" class="label">
1844 <span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span>
1846 <td class="field"><input id="url" name="url" value="" type="text" /><br />
1848 <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
1849 <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
1850 <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
1856 <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . attribute_escape(__('Insert into Post')) . '" />
1865 * {@internal Missing Short Description}}
1871 function type_url_form_audio() {
1873 <table class="describe"><tbody>
1875 <th valign="top" scope="row" class="label">
1876 <span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span>
1877 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1879 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1882 <th valign="top" scope="row" class="label">
1883 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1884 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1886 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1888 <tr><td></td><td class="help">' . __('Link text, e.g. "Still Alive by Jonathan Coulton"') . '</td></tr>
1892 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1900 * {@internal Missing Short Description}}
1906 function type_url_form_video() {
1908 <table class="describe"><tbody>
1910 <th valign="top" scope="row" class="label">
1911 <span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span>
1912 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1914 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1917 <th valign="top" scope="row" class="label">
1918 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1919 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1921 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1923 <tr><td></td><td class="help">' . __('Link text, e.g. "Lucy on YouTube"') . '</td></tr>
1927 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1935 * {@internal Missing Short Description}}
1941 function type_url_form_file() {
1943 <table class="describe"><tbody>
1945 <th valign="top" scope="row" class="label">
1946 <span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span>
1947 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1949 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1952 <th valign="top" scope="row" class="label">
1953 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1954 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1956 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1958 <tr><td></td><td class="help">' . __('Link text, e.g. "Ransom Demands (PDF)"') . '</td></tr>
1962 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1970 * {@internal Missing Short Description}}
1972 * Support a GET parameter for disabling the flash uploader.
1976 * @param unknown_type $flash
1979 function media_upload_use_flash($flash) {
1980 if ( array_key_exists('flash', $_REQUEST) )
1981 $flash = !empty($_REQUEST['flash']);
1985 add_filter('flash_uploader', 'media_upload_use_flash');
1988 * {@internal Missing Short Description}}
1992 function media_upload_flash_bypass() {
1993 echo '<p class="upload-flash-bypass">';
1994 printf( __('You are using the Flash uploader. Problems? Try the <a href="%s">Browser uploader</a> instead.'), clean_url(add_query_arg('flash', 0)) );
1999 * {@internal Missing Short Description}}
2003 function media_upload_html_bypass() {
2004 echo '<p class="upload-html-bypass">';
2005 if ( array_key_exists('flash', $_REQUEST) )
2006 // the user manually selected the browser uploader, so let them switch back to Flash
2007 printf( __('You are using the Browser uploader. Try the <a href="%s">Flash uploader</a> instead.'), clean_url(add_query_arg('flash', 1)) );
2009 // the user probably doesn't have Flash
2010 printf( __('You are using the Browser uploader.') );
2015 add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
2016 add_action('post-html-upload-ui', 'media_upload_html_bypass');
2019 * {@internal Missing Short Description}}
2021 * Make sure the GET parameter sticks when we submit a form.
2025 * @param unknown_type $url
2028 function media_upload_bypass_url($url) {
2029 if ( array_key_exists('flash', $_REQUEST) )
2030 $url = add_query_arg('flash', intval($_REQUEST['flash']));
2034 add_filter('media_upload_form_url', 'media_upload_bypass_url');
2038 add_filter('async_upload_image', 'get_media_item', 10, 2);
2039 add_filter('async_upload_audio', 'get_media_item', 10, 2);
2040 add_filter('async_upload_video', 'get_media_item', 10, 2);
2041 add_filter('async_upload_file', 'get_media_item', 10, 2);
2043 add_action('media_upload_image', 'media_upload_image');
2044 add_action('media_upload_audio', 'media_upload_audio');
2045 add_action('media_upload_video', 'media_upload_video');
2046 add_action('media_upload_file', 'media_upload_file');
2048 add_filter('media_upload_gallery', 'media_upload_gallery');
2050 add_filter('media_upload_library', 'media_upload_library');