Wordpress 2.5.1
[autoinstalls/wordpress.git] / wp-admin / includes / media.php
1 <?php
2
3 function media_upload_tabs() {
4         $_default_tabs = array(
5                 'type' => __('Choose File'), // handler action suffix => tab text
6                 'gallery' => __('Gallery'),
7                 'library' => __('Media Library'),
8         );
9
10         return apply_filters('media_upload_tabs', $_default_tabs);
11 }
12
13 function update_gallery_tab($tabs) {
14         global $wpdb;
15         if ( !isset($_REQUEST['post_id']) ) {
16                 unset($tabs['gallery']);
17                 return $tabs;
18         }
19         if ( intval($_REQUEST['post_id']) )
20                 $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id'])));
21
22         $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
23
24         return $tabs;
25 }
26 add_filter('media_upload_tabs', 'update_gallery_tab');
27
28 function the_media_upload_tabs() {
29         $tabs = media_upload_tabs();
30
31         if ( !empty($tabs) ) {
32                 echo "<ul id='sidemenu'>\n";
33                 if ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
34                         $current = $_GET['tab'];
35                 else {
36                         $keys = array_keys($tabs);
37                         $current = array_shift($keys);
38                 }
39                 foreach ( $tabs as $callback => $text ) {
40                         $class = '';
41                         if ( $current == $callback )
42                                 $class = " class='current'";
43                         $href = add_query_arg(array('tab'=>$callback, 's'=>false, 'paged'=>false, 'post_mime_type'=>false, 'm'=>false));
44                         $link = "<a href='$href'$class>$text</a>";
45                         echo "\t<li id='tab-$callback'>$link</li>\n";
46                 }
47                 echo "</ul>\n";
48         }
49 }
50
51 function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
52
53         $html = get_image_tag($id, $alt, $title, $align, $size);
54
55         $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
56
57         if ( $url )
58                 $html = "<a href='".attribute_escape($url)."'$rel>$html</a>";
59
60         $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size );
61
62         return $html;
63 }
64
65 function media_send_to_editor($html) {
66         ?>
67 <script type="text/javascript">
68 <!--
69 top.send_to_editor('<?php echo addslashes($html); ?>');
70 top.tb_remove();
71 -->
72 </script>
73         <?php
74         exit;
75 }
76
77 // this handles the file upload POST itself, creating the attachment post
78 function media_handle_upload($file_id, $post_id, $post_data = array()) {
79         $overrides = array('test_form'=>false);
80         $file = wp_handle_upload($_FILES[$file_id], $overrides);
81
82         if ( isset($file['error']) )
83                 return new wp_error( 'upload_error', $file['error'] );
84
85         $url = $file['url'];
86         $type = $file['type'];
87         $file = $file['file'];
88         $title = preg_replace('/\.[^.]+$/', '', basename($file));
89         $content = '';
90
91         // use image exif/iptc data for title and caption defaults if possible
92         if ( $image_meta = @wp_read_image_metadata($file) ) {
93                 if ( trim($image_meta['title']) )
94                         $title = $image_meta['title'];
95                 if ( trim($image_meta['caption']) )
96                         $content = $image_meta['caption'];
97         }
98
99         // Construct the attachment array
100         $attachment = array_merge( array(
101                 'post_mime_type' => $type,
102                 'guid' => $url,
103                 'post_parent' => $post_id,
104                 'post_title' => $title,
105                 'post_content' => $content,
106         ), $post_data );
107
108         // Save the data
109         $id = wp_insert_attachment($attachment, $file, $post_parent);
110         if ( !is_wp_error($id) ) {
111                 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
112         }
113
114         return $id;
115
116 }
117
118
119 // wrap iframe content (produced by $content_func) in a doctype, html head/body etc
120 // any additional function args will be passed to content_func
121 function wp_iframe($content_func /* ... */) {
122 ?>
123 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
124 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
125 <head>
126 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
127 <title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; <?php _e('WordPress'); ?></title>
128 <?php
129 wp_admin_css( 'css/global' );
130 wp_admin_css();
131 wp_admin_css( 'css/colors' );
132 ?>
133 <script type="text/javascript">
134 //<![CDATA[
135 function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}else{ var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}
136 //]]>
137 </script>
138 <?php
139 do_action('admin_print_scripts');
140 do_action('admin_head');
141 if ( is_string($content_func) )
142         do_action( "admin_head_{$content_func}" );
143 ?>
144 </head>
145 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>>
146 <?php
147         $args = func_get_args();
148         $args = array_slice($args, 1);
149         call_user_func_array($content_func, $args);
150 ?>
151 </body>
152 </html>
153 <?php
154 }
155
156 function media_buttons() {
157         global $post_ID, $temp_ID;
158         $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
159         $context = apply_filters('media_buttons_context', __('Add media: %s'));
160         $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
161         $media_title = __('Add Media');
162         $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&amp;type=image");
163         $image_title = __('Add an Image');
164         $video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src&amp;type=video");
165         $video_title = __('Add Video');
166         $audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src&amp;type=audio");
167         $audio_title = __('Add Audio');
168         $out = <<<EOF
169
170         <a href="{$image_upload_iframe_src}&amp;TB_iframe=true&amp;height=500&amp;width=640" class="thickbox" title='$image_title'><img src='images/media-button-image.gif' alt='$image_title' /></a>
171         <a href="{$video_upload_iframe_src}&amp;TB_iframe=true&amp;height=500&amp;width=640" class="thickbox" title='$video_title'><img src='images/media-button-video.gif' alt='$video_title' /></a>
172         <a href="{$audio_upload_iframe_src}&amp;TB_iframe=true&amp;height=500&amp;width=640" class="thickbox" title='$audio_title'><img src='images/media-button-music.gif' alt='$audio_title' /></a>
173         <a href="{$media_upload_iframe_src}&amp;TB_iframe=true&amp;height=500&amp;width=640" class="thickbox" title='$media_title'><img src='images/media-button-other.gif' alt='$media_title' /></a>
174
175 EOF;
176         printf($context, $out);
177 }
178 add_action( 'media_buttons', 'media_buttons' );
179
180 function media_buttons_head() {
181 $siteurl = get_option('siteurl');
182 echo "<style type='text/css' media='all'>
183         @import '{$siteurl}/wp-includes/js/thickbox/thickbox.css?1';
184         div#TB_title {
185                 background-color: #222222;
186                 color: #cfcfcf;
187         }
188         div#TB_title a, div#TB_title a:visited {
189                 color: #cfcfcf;
190         }
191 </style>\n";
192 }
193
194 add_action( 'admin_print_scripts', 'media_buttons_head' );
195
196 function media_admin_css() {
197         wp_admin_css('css/media');
198 }
199
200 add_action('media_upload_media', 'media_upload_handler');
201
202 function media_upload_form_handler() {
203         check_admin_referer('media-form');
204
205         if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
206                 $post = $_post = get_post($attachment_id, ARRAY_A);
207                 if ( isset($attachment['post_content']) )
208                         $post['post_content'] = $attachment['post_content'];
209                 if ( isset($attachment['post_title']) )
210                         $post['post_title'] = $attachment['post_title'];
211                 if ( isset($attachment['post_excerpt']) )
212                         $post['post_excerpt'] = $attachment['post_excerpt'];
213
214                 $post = apply_filters('attachment_fields_to_save', $post, $attachment);
215
216                 if ( isset($post['errors']) ) {
217                         $errors[$attachment_id] = $post['errors'];
218                         unset($post['errors']);
219                 }
220
221                 if ( $post != $_post )
222                         wp_update_post($post);
223
224                 foreach ( get_attachment_taxonomies($post) as $t )
225                         if ( isset($attachment[$t]) )
226                                 wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
227         }
228
229         if ( isset($_POST['insert-gallery']) )
230                 return media_send_to_editor('[gallery]');
231
232         if ( isset($_POST['send']) ) {
233                 $keys = array_keys($_POST['send']);
234                 $send_id = (int) array_shift($keys);
235                 $attachment = $_POST['attachments'][$send_id];
236                 $html = $attachment['post_title'];
237                 if ( !empty($attachment['url']) ) {
238                         if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
239                                 $rel = " rel='attachment wp-att-".attribute_escape($send_id)."'";
240                         $html = "<a href='{$attachment['url']}'$rel>$html</a>";
241                 }
242                 $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
243                 return media_send_to_editor($html);
244         }
245
246         return $errors;
247 }
248
249 function media_upload_image() {
250         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
251                 // Upload File button was clicked
252                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
253                 unset($_FILES);
254                 if ( is_wp_error($id) ) {
255                         $errors['upload_error'] = $id;
256                         $id = false;
257                 }
258         }
259
260         if ( !empty($_POST['insertonlybutton']) ) {
261                 $src = $_POST['insertonly']['src'];
262                 if ( !empty($src) && !strpos($src, '://') )
263                         $src = "http://$src";
264                 $alt = attribute_escape($_POST['insertonly']['alt']);
265                 if ( isset($_POST['insertonly']['align']) ) {
266                         $align = attribute_escape($_POST['insertonly']['align']);
267                         $class = " class='align$align'";
268                 }
269                 if ( !empty($src) )
270                         $html = "<img src='$src' alt='$alt'$class />";
271                 return media_send_to_editor($html);
272         }
273
274         if ( !empty($_POST) ) {
275                 $return = media_upload_form_handler();
276
277                 if ( is_string($return) )
278                         return $return;
279                 if ( is_array($return) )
280                         $errors = $return;
281         }
282
283         if ( isset($_POST['save']) )
284                 $errors['upload_notice'] = __('Saved.');
285
286         return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
287 }
288
289 function media_upload_audio() {
290         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
291                 // Upload File button was clicked
292                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
293                 unset($_FILES);
294                 if ( is_wp_error($id) ) {
295                         $errors['upload_error'] = $id;
296                         $id = false;
297                 }
298         }
299
300         if ( !empty($_POST['insertonlybutton']) ) {
301                 $href = $_POST['insertonly']['href'];
302                 if ( !empty($href) && !strpos($href, '://') )
303                         $href = "http://$href";
304                 $title = attribute_escape($_POST['insertonly']['title']);
305                 if ( empty($title) )
306                         $title = basename($href);
307                 if ( !empty($title) && !empty($href) )
308                         $html = "<a href='$href' >$title</a>";
309                 return media_send_to_editor($html);
310         }
311
312         if ( !empty($_POST) ) {
313                 $return = media_upload_form_handler();
314
315                 if ( is_string($return) )
316                         return $return;
317                 if ( is_array($return) )
318                         $errors = $return;
319         }
320
321         if ( isset($_POST['save']) )
322                 $errors['upload_notice'] = __('Saved.');
323
324         return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
325 }
326
327 function media_upload_video() {
328         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
329                 // Upload File button was clicked
330                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
331                 unset($_FILES);
332                 if ( is_wp_error($id) ) {
333                         $errors['upload_error'] = $id;
334                         $id = false;
335                 }
336         }
337
338         if ( !empty($_POST['insertonlybutton']) ) {
339                 $href = $_POST['insertonly']['href'];
340                 if ( !empty($href) && !strpos($href, '://') )
341                         $href = "http://$href";
342                 $title = attribute_escape($_POST['insertonly']['title']);
343                 if ( empty($title) )
344                         $title = basename($href);
345                 if ( !empty($title) && !empty($href) )
346                         $html = "<a href='$href' >$title</a>";
347                 return media_send_to_editor($html);
348         }
349
350         if ( !empty($_POST) ) {
351                 $return = media_upload_form_handler();
352
353                 if ( is_string($return) )
354                         return $return;
355                 if ( is_array($return) )
356                         $errors = $return;
357         }
358
359         if ( isset($_POST['save']) )
360                 $errors['upload_notice'] = __('Saved.');
361
362         return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
363 }
364
365 function media_upload_file() {
366         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
367                 // Upload File button was clicked
368                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
369                 unset($_FILES);
370                 if ( is_wp_error($id) ) {
371                         $errors['upload_error'] = $id;
372                         $id = false;
373                 }
374         }
375
376         if ( !empty($_POST['insertonlybutton']) ) {
377                 $href = $_POST['insertonly']['href'];
378                 if ( !empty($href) && !strpos($href, '://') )
379                         $href = "http://$href";
380                 $title = attribute_escape($_POST['insertonly']['title']);
381                 if ( empty($title) )
382                         $title = basename($href);
383                 if ( !empty($title) && !empty($href) )
384                         $html = "<a href='$href' >$title</a>";
385                 return media_send_to_editor($html);
386         }
387
388         if ( !empty($_POST) ) {
389                 $return = media_upload_form_handler();
390
391                 if ( is_string($return) )
392                         return $return;
393                 if ( is_array($return) )
394                         $errors = $return;
395         }
396
397         if ( isset($_POST['save']) )
398                 $errors['upload_notice'] = __('Saved.');
399
400         return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
401 }
402
403 function media_upload_gallery() {
404         if ( !empty($_POST) ) {
405                 $return = media_upload_form_handler();
406
407                 if ( is_string($return) )
408                         return $return;
409                 if ( is_array($return) )
410                         $errors = $return;
411         }
412
413         return wp_iframe( 'media_upload_gallery_form', $errors );
414 }
415
416 function media_upload_library() {
417         if ( !empty($_POST) ) {
418                 $return = media_upload_form_handler();
419
420                 if ( is_string($return) )
421                         return $return;
422                 if ( is_array($return) )
423                         $errors = $return;
424         }
425
426         return wp_iframe( 'media_upload_library_form', $errors );
427 }
428
429 function image_attachment_fields_to_edit($form_fields, $post) {
430         if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
431                 $form_fields['post_title']['required'] = true;
432                 $form_fields['post_excerpt']['label'] = __('Caption');
433                 $form_fields['post_excerpt']['helps'][] = __('Alternate text, e.g. "The Mona Lisa"');
434
435                 $form_fields['post_content']['label'] = __('Description');
436
437                 $thumb = wp_get_attachment_thumb_url($post->ID);
438
439                 $form_fields['align'] = array(
440                         'label' => __('Alignment'),
441                         'input' => 'html',
442                         'html'  => "
443                                 <input type='radio' name='attachments[$post->ID][align]' id='image-align-none-$post->ID' value='none' checked='checked' />
444                                 <label for='image-align-none-$post->ID' class='align image-align-none-label'>" . __('None') . "</label>
445                                 <input type='radio' name='attachments[$post->ID][align]' id='image-align-left-$post->ID' value='left' />
446                                 <label for='image-align-left-$post->ID' class='align image-align-left-label'>" . __('Left') . "</label>
447                                 <input type='radio' name='attachments[$post->ID][align]' id='image-align-center-$post->ID' value='center' />
448                                 <label for='image-align-center-$post->ID' class='align image-align-center-label'>" . __('Center') . "</label>
449                                 <input type='radio' name='attachments[$post->ID][align]' id='image-align-right-$post->ID' value='right' />
450                                 <label for='image-align-right-$post->ID' class='align image-align-right-label'>" . __('Right') . "</label>\n",
451                 );
452                 $form_fields['image-size'] = array(
453                         'label' => __('Size'),
454                         'input' => 'html',
455                         'html'  => "
456                                 " . ( $thumb ? "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-thumb-$post->ID' value='thumbnail' />
457                                 <label for='image-size-thumb-$post->ID'>" . __('Thumbnail') . "</label>
458                                 " : '' ) . "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-medium-$post->ID' value='medium' checked='checked' />
459                                 <label for='image-size-medium-$post->ID'>" . __('Medium') . "</label>
460                                 <input type='radio' name='attachments[$post->ID][image-size]' id='image-size-full-$post->ID' value='full' />
461                                 <label for='image-size-full-$post->ID'>" . __('Full size') . "</label>",
462                 );
463         }
464         return $form_fields;
465 }
466
467 add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
468
469 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
470         unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
471         return $form_fields;
472 }
473
474 function image_attachment_fields_to_save($post, $attachment) {
475         if ( substr($post['post_mime_type'], 0, 5) == 'image' ) {
476                 if ( strlen(trim($post['post_title'])) == 0 ) {
477                         $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid']));
478                         $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.');
479                 }
480         }
481
482         return $post;
483 }
484
485 add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2);
486
487 function image_media_send_to_editor($html, $attachment_id, $attachment) {
488         $post =& get_post($attachment_id);
489         if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
490                 $url = $attachment['url'];
491
492                 if ( isset($attachment['align']) )
493                         $align = $attachment['align'];
494                 else
495                         $align = 'none';
496
497                 if ( !empty($attachment['image-size']) )
498                         $size = $attachment['image-size'];
499                 else
500                         $size = 'medium';
501
502                 $rel = ( $url == get_attachment_link($attachment_id) );
503
504                 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size);
505         }
506
507         return $html;
508 }
509
510 add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3);
511
512 function get_attachment_fields_to_edit($post, $errors = null) {
513         if ( is_int($post) )
514                 $post =& get_post($post);
515         if ( is_array($post) )
516                 $post = (object) $post;
517
518         $edit_post = sanitize_post($post, 'edit');
519         $file = wp_get_attachment_url($post->ID);
520         $link = get_attachment_link($post->ID);
521
522         $form_fields = array(
523                 'post_title'   => array(
524                         'label'      => __('Title'),
525                         'value'      => $edit_post->post_title,
526                 ),
527                 'post_excerpt' => array(
528                         'label'      => __('Caption'),
529                         'value'      => $edit_post->post_excerpt,
530                 ),
531                 'post_content' => array(
532                         'label'      => __('Description'),
533                         'value'      => $edit_post->post_content,
534                         'input'      => 'textarea',
535                 ),
536                 'url'          => array(
537                         'label'      => __('Link URL'),
538                         'input'      => 'html',
539                         'html'       => "
540                                 <input type='text' name='attachments[$post->ID][url]' value='" . attribute_escape($file) . "' /><br />
541                                 <button type='button' class='button url-$post->ID' value=''>" . __('None') . "</button>
542                                 <button type='button' class='button url-$post->ID' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
543                                 <button type='button' class='button url-$post->ID' value='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>
544                                 <script type='text/javascript'>
545                                 jQuery('button.url-$post->ID').bind('click', function(){jQuery(this).siblings('input').val(this.value);});
546                                 </script>\n",
547                         'helps'      => __('Enter a link URL or click above for presets.'),
548                 ),
549         );
550
551         foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
552                 $t = (array) get_taxonomy($taxonomy);
553                 if ( empty($t['label']) )
554                         $t['label'] = $taxonomy;
555                 if ( empty($t['args']) )
556                         $t['args'] = array();
557
558                 $terms = get_object_term_cache($post->ID, $taxonomy);
559                 if ( empty($terms) )
560                         $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
561
562                 $values = array();
563
564                 foreach ( $terms as $term )
565                         $values[] = $term->name;
566                 $t['value'] = join(', ', $values);
567
568                 $form_fields[$taxonomy] = $t;
569         }
570
571         // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
572         // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
573         $form_fields = array_merge_recursive($form_fields, (array) $errors);
574
575         $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
576
577         return $form_fields;
578 }
579
580 function get_media_items( $post_id, $errors ) {
581         if ( $post_id ) {
582                 $post = get_post($post_id);
583                 if ( $post && $post->post_type == 'attachment' )
584                         $attachments = array($post->ID => $post);
585                 else
586                         $attachments = get_children("post_parent=$post_id&post_type=attachment&orderby=menu_order ASC, ID&order=DESC");
587         } else {
588                 if ( is_array($GLOBALS['wp_the_query']->posts) )
589                         foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
590                                 $attachments[$attachment->ID] = $attachment;
591         }
592
593         if ( empty($attachments) )
594                 return '';
595
596         foreach ( $attachments as $id => $attachment )
597                 if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
598                         $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>";
599
600         return $output;
601 }
602
603 function get_media_item( $attachment_id, $args = null ) {
604         $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true );
605         $args = wp_parse_args( $args, $default_args );
606         extract( $args, EXTR_SKIP );
607
608         global $post_mime_types;
609         if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) )
610                 $thumb_url = $thumb_url[0];
611         else
612                 return false;
613
614         $title_label = __('Title');
615         $description_label = __('Description');
616         $tags_label = __('Tags');
617
618         $toggle_on = __('Show');
619         $toggle_off = __('Hide');
620
621         $post = get_post($attachment_id);
622
623         $filename = basename($post->guid);
624         $title = attribute_escape($post->post_title);
625         $description = attribute_escape($post->post_content);
626         if ( $_tags = get_the_tags($attachment_id) ) {
627                 foreach ( $_tags as $tag )
628                         $tags[] = $tag->name;
629                 $tags = attribute_escape(join(', ', $tags));
630         }
631
632         if ( isset($post_mime_types) ) {
633                 $keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type));
634                 $type = array_shift($keys);
635                 $type = "<input type='hidden' id='type-of-$attachment_id' value='" . attribute_escape( $type ) . "' />";
636         }
637
638         $form_fields = get_attachment_fields_to_edit($post, $errors);
639
640         if ( $toggle ) {
641                 $class = empty($errors) ? 'startclosed' : 'startopen';
642                 $toggle_links = "
643         <a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
644         <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
645         } else {
646                 $class = 'form-table';
647                 $toggle_links = '';
648         }
649
650         $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
651
652         $item = "
653         $type
654         $toggle_links
655         <div class='filename new'>$display_title</div>
656         <table class='slidetoggle describe $class'>
657                 <thead class='media-item-info'>
658                 <tr>
659                         <td class='A1B1' rowspan='4'><img class='thumbnail' src='$thumb_url' alt='' /></td>
660                         <td>$filename</td>
661                 </tr>
662                 <tr><td>$post->post_mime_type</td></tr>
663                 <tr><td>" . mysql2date($post->post_date, get_option('time_format')) . "</td></tr>
664                 <tr><td>" . apply_filters('media_meta', '', $post) . "</td></tr>
665                 </thead>
666                 <tbody>\n";
667
668         $defaults = array(
669                 'input'      => 'text',
670                 'required'   => false,
671                 'value'      => '',
672                 'extra_rows' => array(),
673         );
674
675         $delete_href = wp_nonce_url("post.php?action=delete-post&amp;post=$attachment_id", 'delete-post_' . $attachment_id);
676         if ( $send )
677                 $send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . attribute_escape( __( 'Insert into Post' ) ) . "' />";
678         if ( $delete )
679                 $delete = "<a href='$delete_href' id='del[$attachment_id]' disabled='disabled' class='delete'>" . __('Delete') . "</button>";
680         if ( ( $send || $delete ) && !isset($form_fields['buttons']) )
681                 $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $delete</td></tr>\n");
682
683         $hidden_fields = array();
684
685         foreach ( $form_fields as $id => $field ) {
686                 if ( $id{0} == '_' )
687                         continue;
688
689                 if ( !empty($field['tr']) ) {
690                         $item .= $field['tr'];
691                         continue;
692                 }
693
694                 $field = array_merge($defaults, $field);
695                 $name = "attachments[$attachment_id][$id]";
696
697                 if ( $field['input'] == 'hidden' ) {
698                         $hidden_fields[$name] = $field['value'];
699                         continue;
700                 }
701
702                 $required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : '';
703                 $class  = $id;
704                 $class .= $field['required'] ? ' form-required' : '';
705
706                 $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'>";
707                 if ( !empty($field[$field['input']]) )
708                         $item .= $field[$field['input']];
709                 elseif ( $field['input'] == 'textarea' ) {
710                         $item .= "<textarea type='text' id='$name' name='$name'>" . attribute_escape( $field['value'] ) . "</textarea>";
711                 } else {
712                         $item .= "<input type='text' id='$name' name='$name' value='" . attribute_escape( $field['value'] ) . "' />";
713                 }
714                 if ( !empty($field['helps']) )
715                         $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique((array) $field['helps']) ) . '</p>';
716                 $item .= "</td>\n\t\t</tr>\n";
717
718                 $extra_rows = array();
719
720                 if ( !empty($field['errors']) )
721                         foreach ( array_unique((array) $field['errors']) as $error )
722                                 $extra_rows['error'][] = $error;
723
724                 if ( !empty($field['extra_rows']) )
725                         foreach ( $field['extra_rows'] as $class => $rows )
726                                 foreach ( (array) $rows as $html )
727                                         $extra_rows[$class][] = $html;
728
729                 foreach ( $extra_rows as $class => $rows )
730                         foreach ( $rows as $html )
731                                 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
732         }
733
734         if ( !empty($form_fields['_final']) )
735                 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
736         $item .= "\t</tbody>\n";
737         $item .= "\t</table>\n";
738
739         foreach ( $hidden_fields as $name => $value )
740                 $item .= "\t<input type='hidden' name='$name' id='$name' value='" . attribute_escape( $value ) . "' />\n";
741
742         return $item;
743 }
744
745 function media_upload_header() {
746         ?>
747         <script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script>
748         <div id="media-upload-header">
749         <?php the_media_upload_tabs(); ?>
750         </div>
751         <?php
752 }
753
754 function media_upload_form( $errors = null ) {
755         global $type, $tab;
756
757         $flash_action_url = get_option('siteurl') . "/wp-admin/async-upload.php";
758
759         // If Mac and mod_security, no Flash. :(
760         $flash = true;
761         if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mac') && apache_mod_loaded('mod_security') )
762                 $flash = false;
763
764         $flash = apply_filters('flash_uploader', $flash);
765         $post_id = intval($_REQUEST['post_id']);
766
767 ?>
768 <input type='hidden' name='post_id' value='<?php echo (int) $post_id; ?>' />
769 <div id="media-upload-notice">
770 <?php if (isset($errors['upload_notice']) ) { ?>
771         <?php echo $errors['upload_notice']; ?>
772 <?php } ?>
773 </div>
774 <div id="media-upload-error">
775 <?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?>
776         <?php echo $errors['upload_error']->get_error_message(); ?>
777 <?php } ?>
778 </div>
779 <?php if ( $flash ) : ?>
780 <script type="text/javascript">
781 <!--
782 jQuery(function($){
783         swfu = new SWFUpload({
784                         upload_url : "<?php echo attribute_escape( $flash_action_url ); ?>",
785                         flash_url : "<?php echo get_option('siteurl').'/wp-includes/js/swfupload/swfupload_f9.swf'; ?>",
786                         file_post_name: "async-upload",
787                         file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",
788                         post_params : {
789                                 "post_id" : "<?php echo $post_id; ?>",
790                                 "auth_cookie" : "<?php echo $_COOKIE[AUTH_COOKIE]; ?>",
791                                 "type" : "<?php echo $type; ?>",
792                                 "tab" : "<?php echo $tab; ?>",
793                                 "short" : "1"
794                         },
795                         file_size_limit : "<?php echo wp_max_upload_size(); ?>b",
796                         swfupload_element_id : "flash-upload-ui", // id of the element displayed when swfupload is available
797                         degraded_element_id : "html-upload-ui",   // when swfupload is unavailable
798                         file_dialog_start_handler : fileDialogStart,
799                         file_queued_handler : fileQueued,
800                         upload_start_handler : uploadStart,
801                         upload_progress_handler : uploadProgress,
802                         upload_error_handler : uploadError,
803                         upload_success_handler : uploadSuccess,
804                         upload_complete_handler : uploadComplete,
805                         file_queue_error_handler : fileQueueError,
806                         file_dialog_complete_handler : fileDialogComplete,
807
808                         debug: false
809                 });
810         $("#flash-browse-button").bind( "click", function(){swfu.selectFiles();});
811 });
812 //-->
813 </script>
814
815
816 <div id="flash-upload-ui">
817         <p><input id="flash-browse-button" type="button" value="<?php echo attribute_escape( __( 'Choose files to upload' ) ); ?>" class="button" /></p>
818         <p><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
819 </div>
820
821 <?php endif; // $flash ?>
822
823 <div id="html-upload-ui">
824         <p>
825         <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>
826         </p>
827         <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
828         <br class="clear" />
829         <?php if ( is_lighttpd_before_150() ): ?>
830         <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>
831         <?php endif;?>
832 </div>
833 <?php
834 }
835
836 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
837         media_upload_header();
838
839         $post_id = intval($_REQUEST['post_id']);
840
841         $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type=$type&tab=type&post_id=$post_id";
842
843         $callback = "type_form_$type";
844 ?>
845
846 <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">
847 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
848 <?php wp_nonce_field('media-form'); ?>
849 <h3><?php _e('From Computer'); ?></h3>
850 <?php media_upload_form( $errors ); ?>
851
852 <script type="text/javascript">
853 <!--
854 jQuery(function($){
855         var preloaded = $(".media-item.preloaded");
856         if ( preloaded.length > 0 ) {
857                 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
858         }
859         updateMediaForm();
860 });
861 -->
862 </script>
863 <?php if ( $id && !is_wp_error($id) ) : ?>
864 <div id="media-items">
865 <?php echo get_media_items( $id, $errors ); ?>
866 </div>
867 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
868
869 <?php elseif ( is_callable($callback) ) : ?>
870
871 <div class="media-blank">
872 <p style="text-align:center"><?php _e('&mdash; OR &mdash;'); ?></p>
873 <h3><?php _e('From URL'); ?></h3>
874 </div>
875
876 <div id="media-items">
877 <div class="media-item media-blank">
878 <?php echo call_user_func($callback); ?>
879 </div>
880 </div>
881 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
882 <?php
883         endif;
884 }
885
886 function media_upload_gallery_form($errors) {
887         media_upload_header();
888
889         $post_id = intval($_REQUEST['post_id']);
890
891         $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id";
892
893 ?>
894
895 <script type="text/javascript">
896 <!--
897 jQuery(function($){
898         var preloaded = $(".media-item.preloaded");
899         if ( preloaded.length > 0 ) {
900                 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
901                 updateMediaForm();
902         }
903 });
904 -->
905 </script>
906
907 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
908 <?php wp_nonce_field('media-form'); ?>
909 <?php //media_upload_form( $errors ); ?>
910
911 <div id="media-items">
912 <?php echo get_media_items($post_id, $errors); ?>
913 </div>
914 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
915 <input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php echo attribute_escape( __( 'Insert gallery into post' ) ); ?>" />
916 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
917 <input type="hidden" name="type" value="<?php echo attribute_escape( $GLOBALS['type'] ); ?>" />
918 <input type="hidden" name="tab" value="<?php echo attribute_escape( $GLOBALS['tab'] ); ?>" />
919 </form>
920 <?php
921 }
922
923 function media_upload_library_form($errors) {
924         global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
925
926         media_upload_header();
927
928         $post_id = intval($_REQUEST['post_id']);
929
930         $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=library&post_id=$post_id";
931
932         $_GET['paged'] = intval($_GET['paged']);
933         if ( $_GET['paged'] < 1 )
934                 $_GET['paged'] = 1;
935         $start = ( $_GET['paged'] - 1 ) * 10;
936         if ( $start < 1 )
937                 $start = 0;
938         add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
939
940         list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
941
942 ?>
943
944 <form id="filter" action="" method="get">
945 <input type="hidden" name="type" value="<?php echo attribute_escape( $type ); ?>" />
946 <input type="hidden" name="tab" value="<?php echo attribute_escape( $tab ); ?>" />
947 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
948 <input type="hidden" name="post_mime_type" value="<?php echo attribute_escape( $_GET['post_mime_type'] ); ?>" />
949
950 <div id="search-filter">
951         <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>" />
952         <input type="submit" value="<?php echo attribute_escape( __( 'Search Media' ) ); ?>" class="button" />
953 </div>
954
955 <p>
956 <ul class="subsubsub">
957 <?php
958 $type_links = array();
959 $_num_posts = (array) wp_count_attachments();
960 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
961 foreach ( $matches as $_type => $reals )
962         foreach ( $reals as $real )
963                 $num_posts[$_type] += $_num_posts[$real];
964 // If available type specified by media button clicked, filter by that type
965 if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {
966         $_GET['post_mime_type'] = $type;
967         list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
968 }
969 if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )
970         $class = ' class="current"';
971 $type_links[] = "<li><a href='" . add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false)) . "'$class>".__('All Types')."</a>";
972 foreach ( $post_mime_types as $mime_type => $label ) {
973         $class = '';
974
975         if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
976                 continue;
977
978         if ( wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
979                 $class = ' class="current"';
980
981         $type_links[] = "<li><a href='" . 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>';
982 }
983 echo implode(' | </li>', $type_links) . '</li>';
984 unset($type_links);
985 ?>
986 </ul>
987 </p>
988
989 <div class="tablenav">
990
991 <?php
992 $page_links = paginate_links( array(
993         'base' => add_query_arg( 'paged', '%#%' ),
994         'format' => '',
995         'total' => ceil($wp_query->found_posts / 10),
996         'current' => $_GET['paged']
997 ));
998
999 if ( $page_links )
1000         echo "<div class='tablenav-pages'>$page_links</div>";
1001 ?>
1002
1003 <div class="alignleft">
1004 <?php
1005
1006 $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";
1007
1008 $arc_result = $wpdb->get_results( $arc_query );
1009
1010 $month_count = count($arc_result);
1011
1012 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
1013 <select name='m'>
1014 <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
1015 <?php
1016 foreach ($arc_result as $arc_row) {
1017         if ( $arc_row->yyear == 0 )
1018                 continue;
1019         $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
1020
1021         if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
1022                 $default = ' selected="selected"';
1023         else
1024                 $default = '';
1025
1026         echo "<option$default value='" . attribute_escape( $arc_row->yyear . $arc_row->mmonth ) . "'>";
1027         echo wp_specialchars( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" );
1028         echo "</option>\n";
1029 }
1030 ?>
1031 </select>
1032 <?php } ?>
1033
1034 <input type="submit" id="post-query-submit" value="<?php echo attribute_escape( __( 'Filter &#187;' ) ); ?>" class="button-secondary" />
1035
1036 </div>
1037
1038 <br class="clear" />
1039 </div>
1040 </form>
1041
1042 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="library-form">
1043
1044 <?php wp_nonce_field('media-form'); ?>
1045 <?php //media_upload_form( $errors ); ?>
1046
1047 <script type="text/javascript">
1048 <!--
1049 jQuery(function($){
1050         var preloaded = $(".media-item.preloaded");
1051         if ( preloaded.length > 0 ) {
1052                 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1053                 updateMediaForm();
1054         }
1055 });
1056 -->
1057 </script>
1058
1059 <div id="media-items">
1060 <?php echo get_media_items(null, $errors); ?>
1061 </div>
1062 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
1063 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1064 </form>
1065 <?php
1066 }
1067
1068 function type_form_image() {
1069         return '
1070         <table class="describe"><tbody>
1071                 <tr>
1072                         <th valign="top" scope="row" class="label">
1073                                 <span class="alignleft"><label for="insertonly[src]">' . __('Image URL') . '</label></span>
1074                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1075                         </th>
1076                         <td class="field"><input id="insertonly[src]" name="insertonly[src]" value="" type="text"></td>
1077                 </tr>
1078                 <tr>
1079                         <th valign="top" scope="row" class="label">
1080                                 <span class="alignleft"><label for="insertonly[alt]">' . __('Description') . '</label></span>
1081                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1082                         </th>
1083                         <td class="field"><input id="insertonly[alt]" name="insertonly[alt]" value="" type="text"></td>
1084                 </tr>
1085                 <tr><td></td><td class="help">' . __('Alternate text, e.g. "The Mona Lisa"') . '</td></tr>
1086                 <tr class="align">
1087                         <th valign="top" scope="row" class="label"><label for="insertonly[align]">' . __('Alignment') . '</label></th>
1088                         <td class="field">
1089                                 <input name="insertonly[align]" id="image-align-none-0" value="none" type="radio" checked="checked" />
1090                                 <label for="image-align-none-0" class="align image-align-none-label">' . __('None') . '</label>
1091                                 <input name="insertonly[align]" id="image-align-left-0" value="left" type="radio" />
1092                                 <label for="image-align-left-0" class="align image-align-left-label">' . __('Left') . '</label>
1093                                 <input name="insertonly[align]" id="image-align-center-0" value="center" type="radio" />
1094                                 <label for="image-align-center-0" class="align image-align-center-label">' . __('Center') . '</label>
1095                                 <input name="insertonly[align]" id="image-align-right-0" value="right" type="radio" />
1096                                 <label for="image-align-right-0" class="align image-align-right-label">' . __('Right') . '</label>
1097                         </td>
1098                 </tr>
1099                 <tr>
1100                         <td></td>
1101                         <td>
1102                                 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1103                         </td>
1104                 </tr>
1105         </tbody></table>
1106 ';
1107 }
1108
1109 function type_form_audio() {
1110         return '
1111         <table class="describe"><tbody>
1112                 <tr>
1113                         <th valign="top" scope="row" class="label">
1114                                 <span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span>
1115                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1116                         </th>
1117                         <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text"></td>
1118                 </tr>
1119                 <tr>
1120                         <th valign="top" scope="row" class="label">
1121                                 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1122                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1123                         </th>
1124                         <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text"></td>
1125                 </tr>
1126                 <tr><td></td><td class="help">' . __('Link text, e.g. "Still Alive by Jonathan Coulton"') . '</td></tr>
1127                 <tr>
1128                         <td></td>
1129                         <td>
1130                                 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1131                         </td>
1132                 </tr>
1133         </tbody></table>
1134 ';
1135 }
1136
1137 function type_form_video() {
1138         return '
1139         <table class="describe"><tbody>
1140                 <tr>
1141                         <th valign="top" scope="row" class="label">
1142                                 <span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span>
1143                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1144                         </th>
1145                         <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text"></td>
1146                 </tr>
1147                 <tr>
1148                         <th valign="top" scope="row" class="label">
1149                                 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1150                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1151                         </th>
1152                         <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text"></td>
1153                 </tr>
1154                 <tr><td></td><td class="help">' . __('Link text, e.g. "Lucy on YouTube"') . '</td></tr>
1155                 <tr>
1156                         <td></td>
1157                         <td>
1158                                 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1159                         </td>
1160                 </tr>
1161         </tbody></table>
1162 ';
1163 }
1164
1165 function type_form_file() {
1166         return '
1167         <table class="describe"><tbody>
1168                 <tr>
1169                         <th valign="top" scope="row" class="label">
1170                                 <span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span>
1171                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1172                         </th>
1173                         <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text"></td>
1174                 </tr>
1175                 <tr>
1176                         <th valign="top" scope="row" class="label">
1177                                 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1178                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1179                         </th>
1180                         <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text"></td>
1181                 </tr>
1182                 <tr><td></td><td class="help">' . __('Link text, e.g. "Ransom Demands (PDF)"') . '</td></tr>
1183                 <tr>
1184                         <td></td>
1185                         <td>
1186                                 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1187                         </td>
1188                 </tr>
1189         </tbody></table>
1190 ';
1191 }
1192
1193 add_filter('async_upload_image', 'get_media_item', 10, 2);
1194 add_filter('async_upload_audio', 'get_media_item', 10, 2);
1195 add_filter('async_upload_video', 'get_media_item', 10, 2);
1196 add_filter('async_upload_file', 'get_media_item', 10, 2);
1197
1198 add_action('media_upload_image', 'media_upload_image');
1199 add_action('media_upload_audio', 'media_upload_audio');
1200 add_action('media_upload_video', 'media_upload_video');
1201 add_action('media_upload_file', 'media_upload_file');
1202 add_action('admin_head_media_upload_type_form', 'media_admin_css');
1203
1204 add_filter('media_upload_gallery', 'media_upload_gallery');
1205 add_action('admin_head_media_upload_gallery_form', 'media_admin_css');
1206
1207 add_filter('media_upload_library', 'media_upload_library');
1208 add_action('admin_head_media_upload_library_form', 'media_admin_css');
1209
1210 ?>