]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/media.php
Wordpress 2.7.1-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / media.php
1 <?php
2 /**
3  * WordPress Administration Media API.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /**
10  * {@internal Missing Short Description}}
11  *
12  * @since unknown
13  *
14  * @return unknown
15  */
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')
22         );
23
24         return apply_filters('media_upload_tabs', $_default_tabs);
25 }
26
27 /**
28  * {@internal Missing Short Description}}
29  *
30  * @since unknown
31  *
32  * @param unknown_type $tabs
33  * @return unknown
34  */
35 function update_gallery_tab($tabs) {
36         global $wpdb;
37
38         if ( !isset($_REQUEST['post_id']) ) {
39                 unset($tabs['gallery']);
40                 return $tabs;
41         }
42
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'])));
45
46         if ( empty($attachments) ) {
47                 unset($tabs['gallery']);
48                 return $tabs;
49         }
50
51         $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
52
53         return $tabs;
54 }
55 add_filter('media_upload_tabs', 'update_gallery_tab');
56
57 /**
58  * {@internal Missing Short Description}}
59  *
60  * @since unknown
61  */
62 function the_media_upload_tabs() {
63         global $redir_tab;
64         $tabs = media_upload_tabs();
65
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'];
72                 else {
73                         $keys = array_keys($tabs);
74                         $current = array_shift($keys);
75                 }
76                 foreach ( $tabs as $callback => $text ) {
77                         $class = '';
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";
83                 }
84                 echo "</ul>\n";
85         }
86 }
87
88 /**
89  * {@internal Missing Short Description}}
90  *
91  * @since unknown
92  *
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
100  * @return unknown
101  */
102 function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
103
104         $htmlalt = ( empty($alt) ) ? $title : $alt;
105
106         $html = get_image_tag($id, $htmlalt, $title, $align, $size);
107
108         $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
109
110         if ( $url )
111                 $html = '<a href="' . clean_url($url) . "\"$rel>$html</a>";
112
113         $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size );
114
115         return $html;
116 }
117
118 /**
119  * {@internal Missing Short Description}}
120  *
121  * @since unknown
122  *
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
130  * @return unknown
131  */
132 function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) {
133
134         if ( empty($alt) || apply_filters( 'disable_captions', '' ) ) return $html;
135         $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
136
137         preg_match( '/width="([0-9]+)/', $html, $matches );
138         if ( ! isset($matches[1]) ) return $html;
139         $width = $matches[1];
140
141         $html = preg_replace( '/align[^\s\'"]+\s?/', '', $html );
142         if ( empty($align) ) $align = 'none';
143
144         $alt = ! empty($alt) ? addslashes($alt) : '';
145
146         $shcode = '[caption id="' . $id . '" align="align' . $align
147         . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/caption]';
148
149         return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
150 }
151 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 );
152
153 /**
154  * {@internal Missing Short Description}}
155  *
156  * @since unknown
157  *
158  * @param unknown_type $html
159  */
160 function media_send_to_editor($html) {
161 ?>
162 <script type="text/javascript">
163 /* <![CDATA[ */
164 var win = window.dialogArguments || opener || parent || top;
165 win.send_to_editor('<?php echo addslashes($html); ?>');
166 /* ]]> */
167 </script>
168         <?php
169         exit;
170 }
171
172 /**
173  * {@internal Missing Short Description}}
174  *
175  * This handles the file upload POST itself, creating the attachment post.
176  *
177  * @since unknown
178  *
179  * @param unknown_type $file_id
180  * @param unknown_type $post_id
181  * @param unknown_type $post_data
182  * @return unknown
183  */
184 function media_handle_upload($file_id, $post_id, $post_data = array()) {
185         $overrides = array('test_form'=>false);
186
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;
191         }
192
193         $file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
194
195         if ( isset($file['error']) )
196                 return new WP_Error( 'upload_error', $file['error'] );
197
198         $url = $file['url'];
199         $type = $file['type'];
200         $file = $file['file'];
201         $title = preg_replace('/\.[^.]+$/', '', basename($file));
202         $content = '';
203
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'];
210         }
211
212         // Construct the attachment array
213         $attachment = array_merge( array(
214                 'post_mime_type' => $type,
215                 'guid' => $url,
216                 'post_parent' => $post_id,
217                 'post_title' => $title,
218                 'post_content' => $content,
219         ), $post_data );
220
221         // Save the data
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 ) );
225         }
226
227         return $id;
228
229 }
230
231 /**
232  * {@internal Missing Short Description}}
233  *
234  * @since unknown
235  *
236  * @param unknown_type $file_array
237  * @param unknown_type $post_id
238  * @param unknown_type $desc
239  * @param unknown_type $post_data
240  * @return unknown
241  */
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);
245
246         if ( isset($file['error']) )
247                 return new WP_Error( 'upload_error', $file['error'] );
248
249         $url = $file['url'];
250         $type = $file['type'];
251         $file = $file['file'];
252         $title = preg_replace('/\.[^.]+$/', '', basename($file));
253         $content = '';
254
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'];
261         }
262
263         $title = @$desc;
264
265         // Construct the attachment array
266         $attachment = array_merge( array(
267                 'post_mime_type' => $type,
268                 'guid' => $url,
269                 'post_parent' => $post_id,
270                 'post_title' => $title,
271                 'post_content' => $content,
272         ), $post_data );
273
274         // Save the data
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 ) );
278                 return $url;
279         }
280         return $id;
281 }
282
283 /**
284  * {@internal Missing Short Description}}
285  *
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.
288  *
289  * @since unknown
290  *
291  * @param unknown_type $content_func
292  */
293 function wp_iframe($content_func /* ... */) {
294 ?>
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(); ?>>
297 <head>
298 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
299 <title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; <?php _e('WordPress'); ?></title>
300 <?php
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' );
306
307 ?>
308 <script type="text/javascript">
309 //<![CDATA[
310 function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}else{ var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}
311 //]]>
312 </script>
313 <?php
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}" );
319 ?>
320 </head>
321 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>>
322 <?php
323         $args = func_get_args();
324         $args = array_slice($args, 1);
325         call_user_func_array($content_func, $args);
326 ?>
327 </body>
328 </html>
329 <?php
330 }
331
332 /**
333  * {@internal Missing Short Description}}
334  *
335  * @since unknown
336  */
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&amp;type=image");
344         $image_title = __('Add an Image');
345         $video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src&amp;type=video");
346         $video_title = __('Add Video');
347         $audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src&amp;type=audio");
348         $audio_title = __('Add Audio');
349         $out = <<<EOF
350
351         <a href="{$image_upload_iframe_src}&amp;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}&amp;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}&amp;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}&amp;TB_iframe=true" id="add_media" class="thickbox" title='$media_title'><img src='images/media-button-other.gif' alt='$media_title' /></a>
355
356 EOF;
357         printf($context, $out);
358 }
359 add_action( 'media_buttons', 'media_buttons' );
360 add_action('media_upload_media', 'media_upload_handler');
361
362 /**
363  * {@internal Missing Short Description}}
364  *
365  * @since unknown
366  *
367  * @return unknown
368  */
369 function media_upload_form_handler() {
370         check_admin_referer('media-form');
371
372         if ( isset($_POST['send']) ) {
373                 $keys = array_keys($_POST['send']);
374                 $send_id = (int) array_shift($keys);
375         }
376         
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'];
390                 }
391
392                 $post = apply_filters('attachment_fields_to_save', $post, $attachment);
393
394                 if ( isset($post['errors']) ) {
395                         $errors[$attachment_id] = $post['errors'];
396                         unset($post['errors']);
397                 }
398
399                 if ( $post != $_post )
400                         wp_update_post($post);
401
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);
405         }
406
407         if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?>
408                 <script type="text/javascript">
409                 /* <![CDATA[ */
410                 var win = window.dialogArguments || opener || parent || top;
411                 win.tb_remove();
412                 /* ]]> */
413                 </script>
414                 <?php
415                 exit;
416         }
417
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>";
425                 }
426                 $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
427                 return media_send_to_editor($html);
428         }
429
430         return $errors;
431 }
432
433 /**
434  * {@internal Missing Short Description}}
435  *
436  * @since unknown
437  *
438  * @return unknown
439  */
440 function media_upload_image() {
441         $errors = array();
442         $id = 0;
443
444         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
445                 // Upload File button was clicked
446                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
447                 unset($_FILES);
448                 if ( is_wp_error($id) ) {
449                         $errors['upload_error'] = $id;
450                         $id = false;
451                 }
452         }
453
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'";
462                 }
463                 if ( !empty($src) )
464                         $html = "<img src='$src' alt='$alt'$class />";
465                 return media_send_to_editor($html);
466         }
467
468         if ( !empty($_POST) ) {
469                 $return = media_upload_form_handler();
470
471                 if ( is_string($return) )
472                         return $return;
473                 if ( is_array($return) )
474                         $errors = $return;
475         }
476
477         if ( isset($_POST['save']) ) {
478                 $errors['upload_notice'] = __('Saved.');
479                 return media_upload_gallery();
480         }
481
482         if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
483                 return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id );
484
485         return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
486 }
487
488 /**
489  * {@internal Missing Short Description}}
490  *
491  * @since unknown
492  *
493  * @param unknown_type $file
494  * @param unknown_type $post_id
495  * @param unknown_type $desc
496  * @return unknown
497  */
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;
503                 $desc = @$desc;
504
505                 if ( is_wp_error($tmp) ) {
506                         @unlink($file_array['tmp_name']);
507                         $file_array['tmp_name'] = '';
508                 }
509
510                 $id = media_handle_sideload($file_array, $post_id, $desc);
511                 $src = $id;
512
513                 if ( is_wp_error($id) ) {
514                         @unlink($file_array['tmp_name']);
515                         return $id;
516                 }
517         }
518
519         if ( !empty($src) ) {
520                 $alt = @$desc;
521                 $html = "<img src='$src' alt='$alt' />";
522                 return $html;
523         }
524 }
525
526 /**
527  * {@internal Missing Short Description}}
528  *
529  * @since unknown
530  *
531  * @return unknown
532  */
533 function media_upload_audio() {
534         $errors = array();
535         $id = 0;
536
537         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
538                 // Upload File button was clicked
539                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
540                 unset($_FILES);
541                 if ( is_wp_error($id) ) {
542                         $errors['upload_error'] = $id;
543                         $id = false;
544                 }
545         }
546
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']);
552                 if ( empty($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);
557         }
558
559         if ( !empty($_POST) ) {
560                 $return = media_upload_form_handler();
561
562                 if ( is_string($return) )
563                         return $return;
564                 if ( is_array($return) )
565                         $errors = $return;
566         }
567
568         if ( isset($_POST['save']) ) {
569                 $errors['upload_notice'] = __('Saved.');
570                 return media_upload_gallery();
571         }
572
573         if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
574                 return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id );
575
576         return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
577 }
578
579 /**
580  * {@internal Missing Short Description}}
581  *
582  * @since unknown
583  *
584  * @return unknown
585  */
586 function media_upload_video() {
587         $errors = array();
588         $id = 0;
589
590         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
591                 // Upload File button was clicked
592                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
593                 unset($_FILES);
594                 if ( is_wp_error($id) ) {
595                         $errors['upload_error'] = $id;
596                         $id = false;
597                 }
598         }
599
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']);
605                 if ( empty($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);
610         }
611
612         if ( !empty($_POST) ) {
613                 $return = media_upload_form_handler();
614
615                 if ( is_string($return) )
616                         return $return;
617                 if ( is_array($return) )
618                         $errors = $return;
619         }
620
621         if ( isset($_POST['save']) ) {
622                 $errors['upload_notice'] = __('Saved.');
623                 return media_upload_gallery();
624         }
625
626         if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
627                 return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id );
628
629         return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
630 }
631
632 /**
633  * {@internal Missing Short Description}}
634  *
635  * @since unknown
636  *
637  * @return unknown
638  */
639 function media_upload_file() {
640         $errors = array();
641         $id = 0;
642
643         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
644                 // Upload File button was clicked
645                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
646                 unset($_FILES);
647                 if ( is_wp_error($id) ) {
648                         $errors['upload_error'] = $id;
649                         $id = false;
650                 }
651         }
652
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']);
658                 if ( empty($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);
663         }
664
665         if ( !empty($_POST) ) {
666                 $return = media_upload_form_handler();
667
668                 if ( is_string($return) )
669                         return $return;
670                 if ( is_array($return) )
671                         $errors = $return;
672         }
673
674         if ( isset($_POST['save']) ) {
675                 $errors['upload_notice'] = __('Saved.');
676                 return media_upload_gallery();
677         }
678
679         if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
680                 return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id );
681
682         return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
683 }
684
685 /**
686  * {@internal Missing Short Description}}
687  *
688  * @since unknown
689  *
690  * @return unknown
691  */
692 function media_upload_gallery() {
693         $errors = array();
694
695         if ( !empty($_POST) ) {
696                 $return = media_upload_form_handler();
697
698                 if ( is_string($return) )
699                         return $return;
700                 if ( is_array($return) )
701                         $errors = $return;
702         }
703
704         wp_enqueue_script('admin-gallery');
705         return wp_iframe( 'media_upload_gallery_form', $errors );
706 }
707
708 /**
709  * {@internal Missing Short Description}}
710  *
711  * @since unknown
712  *
713  * @return unknown
714  */
715 function media_upload_library() {
716         $errors = array();
717         if ( !empty($_POST) ) {
718                 $return = media_upload_form_handler();
719
720                 if ( is_string($return) )
721                         return $return;
722                 if ( is_array($return) )
723                         $errors = $return;
724         }
725
726         return wp_iframe( 'media_upload_library_form', $errors );
727 }
728
729 /**
730  * Retrieve HTML for the image alignment radio buttons with the specified one checked.
731  *
732  * @since unknown
733  *
734  * @param unknown_type $post
735  * @param unknown_type $checked
736  * @return unknown
737  */
738 function image_align_input_fields($post, $checked='') {
739
740         $alignments = array('none' => 'None', 'left' => 'Left', 'center' => 'Center', 'right' => 'Right');
741         if ( !array_key_exists($checked, $alignments) )
742                 $checked = 'none';
743
744         $out = array();
745         foreach ($alignments as $name => $label) {
746
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>";
750         }
751         return join("\n", $out);
752 }
753
754 /**
755  * Retrieve HTML for the size radio buttons with the specified one checked.
756  *
757  * @since unknown
758  *
759  * @param unknown_type $post
760  * @param unknown_type $checked
761  * @return unknown
762  */
763 function image_size_input_fields($post, $checked='') {
764
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'));
767
768                 foreach ( $size_names as $size => $name) {
769                         $downsize = image_downsize($post->ID, $size);
770
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 )
776                                 $checked = '';
777                         // if $checked was not specified, default to the first available size that's bigger than a thumbnail
778                         if ( !$checked && $enabled && 'thumbnail' != $size )
779                                 $checked = $size;
780
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'" : '') ." />";
782
783                         $html .= "<label for='{$css_id}'>" . __($name). "</label>";
784                         // only show the dimensions if that choice is available
785                         if ( $enabled )
786                                 $html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d&nbsp;&times;&nbsp;%d)"), $downsize[1], $downsize[2] ). "</label>";
787
788                         $html .= '</div>';
789
790                         $out[] = $html;
791                 }
792
793                 return array(
794                         'label' => __('Size'),
795                         'input' => 'html',
796                         'html'  => join("\n", $out),
797                 );
798 }
799
800 /**
801  * Retrieve HTML for the Link URL buttons with the default link type as specified.
802  *
803  * @since unknown
804  *
805  * @param unknown_type $post
806  * @param unknown_type $url_type
807  * @return unknown
808  */
809 function image_link_input_fields($post, $url_type='') {
810
811         $file = wp_get_attachment_url($post->ID);
812         $link = get_attachment_link($post->ID);
813
814         $url = '';
815         if ( $url_type == 'file' )
816                 $url = $file;
817         elseif ( $url_type == 'post' )
818                 $url = $link;
819
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>
824 ";
825 }
826
827 /**
828  * {@internal Missing Short Description}}
829  *
830  * @since unknown
831  *
832  * @param unknown_type $form_fields
833  * @param unknown_type $post
834  * @return unknown
835  */
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;
839
840                 $form_fields['post_excerpt']['label'] = __('Caption');
841                 $form_fields['post_excerpt']['helps'][] = __('Also used as alternate text for the image');
842
843                 $form_fields['post_content']['label'] = __('Description');
844
845                 $form_fields['align'] = array(
846                         'label' => __('Alignment'),
847                         'input' => 'html',
848                         'html'  => image_align_input_fields($post, get_option('image_default_align')),
849                 );
850
851                 $form_fields['image-size'] = image_size_input_fields($post, get_option('image_default_size'));
852         }
853         return $form_fields;
854 }
855
856 add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
857
858 /**
859  * {@internal Missing Short Description}}
860  *
861  * @since unknown
862  *
863  * @param unknown_type $form_fields
864  * @param unknown_type $post
865  * @return unknown
866  */
867 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
868         unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
869         return $form_fields;
870 }
871
872 /**
873  * {@internal Missing Short Description}}
874  *
875  * @since unknown
876  *
877  * @param unknown_type $post
878  * @param unknown_type $attachment
879  * @return unknown
880  */
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.');
886                 }
887         }
888
889         return $post;
890 }
891
892 add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2);
893
894 /**
895  * {@internal Missing Short Description}}
896  *
897  * @since unknown
898  *
899  * @param unknown_type $html
900  * @param unknown_type $attachment_id
901  * @param unknown_type $attachment
902  * @return unknown
903  */
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'];
908
909                 if ( isset($attachment['align']) )
910                         $align = $attachment['align'];
911                 else
912                         $align = 'none';
913
914                 if ( !empty($attachment['image-size']) )
915                         $size = $attachment['image-size'];
916                 else
917                         $size = 'medium';
918
919                 $rel = ( $url == get_attachment_link($attachment_id) );
920
921                 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size);
922         }
923
924         return $html;
925 }
926
927 add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3);
928
929 /**
930  * {@internal Missing Short Description}}
931  *
932  * @since unknown
933  *
934  * @param unknown_type $post
935  * @param unknown_type $errors
936  * @return unknown
937  */
938 function get_attachment_fields_to_edit($post, $errors = null) {
939         if ( is_int($post) )
940                 $post =& get_post($post);
941         if ( is_array($post) )
942                 $post = (object) $post;
943
944         $edit_post = sanitize_post($post, 'edit');
945
946         $form_fields = array(
947                 'post_title'   => array(
948                         'label'      => __('Title'),
949                         'value'      => $edit_post->post_title,
950                 ),
951                 'post_excerpt' => array(
952                         'label'      => __('Caption'),
953                         'value'      => $edit_post->post_excerpt,
954                 ),
955                 'post_content' => array(
956                         'label'      => __('Description'),
957                         'value'      => $edit_post->post_content,
958                         'input'      => 'textarea',
959                 ),
960                 'url'          => array(
961                         'label'      => __('Link URL'),
962                         'input'      => 'html',
963                         'html'       => image_link_input_fields($post, get_option('image_default_link_type')),
964                         'helps'      => __('Enter a link URL or click above for presets.'),
965                 ),
966                 'menu_order'   => array(
967                         'label'      => __('Order'),
968                         'value'      => $edit_post->menu_order
969                 ),
970         );
971
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();
978
979                 $terms = get_object_term_cache($post->ID, $taxonomy);
980                 if ( empty($terms) )
981                         $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
982
983                 $values = array();
984
985                 foreach ( $terms as $term )
986                         $values[] = $term->name;
987                 $t['value'] = join(', ', $values);
988
989                 $form_fields[$taxonomy] = $t;
990         }
991
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);
995
996         $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
997
998         return $form_fields;
999 }
1000
1001 /**
1002  * Retrieve HTML for media items of post gallery.
1003  *
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.
1007  *
1008  * @since unknown
1009  *
1010  * @param int $post_id Optional. Post ID.
1011  * @param array $errors Errors for attachment, if any.
1012  * @return string
1013  */
1014 function get_media_items( $post_id, $errors ) {
1015         if ( $post_id ) {
1016                 $post = get_post($post_id);
1017                 if ( $post && $post->post_type == 'attachment' )
1018                         $attachments = array($post->ID => $post);
1019                 else
1020                         $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
1021         } else {
1022                 if ( is_array($GLOBALS['wp_the_query']->posts) )
1023                         foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
1024                                 $attachments[$attachment->ID] = $attachment;
1025         }
1026
1027         $output = '';
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>";
1031
1032         return $output;
1033 }
1034
1035 /**
1036  * Retrieve HTML form for modifying the image attachment.
1037  *
1038  * @since unknown
1039  *
1040  * @param int $attachment_id Attachment ID for modification.
1041  * @param string|array $args Optional. Override defaults.
1042  * @return string HTML form for attachment.
1043  */
1044 function get_media_item( $attachment_id, $args = null ) {
1045         global $redir_tab;
1046
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 );
1050
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];
1054         else
1055                 return false;
1056
1057         $toggle_on = __('Show');
1058         $toggle_off = __('Hide');
1059
1060         $post = get_post($attachment_id);
1061
1062         $filename = basename($post->guid);
1063         $title = attribute_escape($post->post_title);
1064
1065         if ( $_tags = get_the_tags($attachment_id) ) {
1066                 foreach ( $_tags as $tag )
1067                         $tags[] = $tag->name;
1068                 $tags = attribute_escape(join(', ', $tags));
1069         }
1070
1071         $type = '';
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 ) . "' />";
1076         }
1077
1078         $form_fields = get_attachment_fields_to_edit($post, $errors);
1079
1080         if ( $toggle ) {
1081                 $class = empty($errors) ? 'startclosed' : 'startopen';
1082                 $toggle_links = "
1083         <a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
1084         <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
1085         } else {
1086                 $class = 'form-table';
1087                 $toggle_links = '';
1088         }
1089
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>" : '';
1092
1093         $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false;
1094         $order = '';
1095
1096         foreach ( $form_fields as $key => $val ) {
1097                 if ( 'menu_order' == $key ) {
1098                         if ( $gallery )
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>';
1100                         else
1101                                 $order = '<input type="hidden" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" />';
1102
1103                         unset($form_fields['menu_order']);
1104                         break;
1105                 }
1106         }
1107
1108         $item = "
1109         $type
1110         $toggle_links
1111         $order
1112         $display_title
1113         <table class='slidetoggle describe $class'>
1114                 <thead class='media-item-info'>
1115                 <tr>
1116                         <td class='A1B1' rowspan='4'><img class='thumbnail' src='$thumb_url' alt='' /></td>
1117                         <td>$filename</td>
1118                 </tr>
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>
1122                 </thead>
1123                 <tbody>\n";
1124
1125         $defaults = array(
1126                 'input'      => 'text',
1127                 'required'   => false,
1128                 'value'      => '',
1129                 'extra_rows' => array(),
1130         );
1131
1132         $delete_href = wp_nonce_url("post.php?action=delete-post&amp;post=$attachment_id", 'delete-post_' . $attachment_id);
1133         if ( $send )
1134                 $send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . attribute_escape( __( 'Insert into Post' ) ) . "' />";
1135         if ( $delete )
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");
1141
1142         $hidden_fields = array();
1143
1144         foreach ( $form_fields as $id => $field ) {
1145                 if ( $id{0} == '_' )
1146                         continue;
1147
1148                 if ( !empty($field['tr']) ) {
1149                         $item .= $field['tr'];
1150                         continue;
1151                 }
1152
1153                 $field = array_merge($defaults, $field);
1154                 $name = "attachments[$attachment_id][$id]";
1155
1156                 if ( $field['input'] == 'hidden' ) {
1157                         $hidden_fields[$name] = $field['value'];
1158                         continue;
1159                 }
1160
1161                 $required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : '';
1162                 $aria_required = $field['required'] ? " aria-required='true' " : '';
1163                 $class  = $id;
1164                 $class .= $field['required'] ? ' form-required' : '';
1165
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>";
1171                 } else {
1172                         $item .= "<input type='text' id='$name' name='$name' value='" . attribute_escape( $field['value'] ) . "'" . $aria_required . "/>";
1173                 }
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";
1177
1178                 $extra_rows = array();
1179
1180                 if ( !empty($field['errors']) )
1181                         foreach ( array_unique((array) $field['errors']) as $error )
1182                                 $extra_rows['error'][] = $error;
1183
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;
1188
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";
1192         }
1193
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";
1198
1199         foreach ( $hidden_fields as $name => $value )
1200                 $item .= "\t<input type='hidden' name='$name' id='$name' value='" . attribute_escape( $value ) . "' />\n";
1201
1202         if ( $post->post_parent < 1 && (int) $_REQUEST['post_id'] ) {
1203                 $parent = (int) $_REQUEST['post_id'];
1204                 $parent_name = "attachments[$attachment_id][post_parent]";
1205
1206                 $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='" . $parent . "' />\n";
1207         }
1208
1209         return $item;
1210 }
1211
1212 /**
1213  * {@internal Missing Short Description}}
1214  *
1215  * @since unknown
1216  */
1217 function media_upload_header() {
1218         ?>
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(); ?>
1222         </div>
1223         <?php
1224 }
1225
1226 /**
1227  * {@internal Missing Short Description}}
1228  *
1229  * @since unknown
1230  *
1231  * @param unknown_type $errors
1232  */
1233 function media_upload_form( $errors = null ) {
1234         global $type, $tab;
1235
1236         $flash_action_url = admin_url('async-upload.php');
1237
1238         // If Mac and mod_security, no Flash. :(
1239         $flash = true;
1240         if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mac') && apache_mod_loaded('mod_security') )
1241                 $flash = false;
1242
1243         $flash = apply_filters('flash_uploader', $flash);
1244         $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
1245
1246 ?>
1247 <div id="media-upload-notice">
1248 <?php if (isset($errors['upload_notice']) ) { ?>
1249         <?php echo $errors['upload_notice']; ?>
1250 <?php } ?>
1251 </div>
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(); ?>
1255 <?php } ?>
1256 </div>
1257
1258 <?php do_action('pre-upload-ui'); ?>
1259
1260 <?php if ( $flash ) : ?>
1261 <script type="text/javascript">
1262 <!--
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', '*.*'); ?>",
1275                         post_params : {
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; ?>",
1281                                 "short" : "1"
1282                         },
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,
1295                         custom_settings : {
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
1298                         },
1299                         debug: false
1300                 });
1301 };
1302 //-->
1303 </script>
1304
1305 <div id="flash-upload-ui">
1306 <?php do_action('pre-flash-upload-ui'); ?>
1307
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>
1311 </div>
1312
1313 <?php endif; // $flash ?>
1314
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>
1319         </p>
1320
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>
1324         <?php endif;?>
1325 <?php do_action('post-html-upload-ui'); ?>
1326 </div>
1327 <?php do_action('post-upload-ui'); ?>
1328 <?php
1329 }
1330
1331 /**
1332  * {@internal Missing Short Description}}
1333  *
1334  * @since unknown
1335  *
1336  * @param unknown_type $type
1337  * @param unknown_type $errors
1338  * @param unknown_type $id
1339  */
1340 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
1341         media_upload_header();
1342
1343         $post_id = intval($_REQUEST['post_id']);
1344
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);
1347 ?>
1348
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'); ?>
1352
1353 <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
1354
1355 <?php media_upload_form( $errors ); ?>
1356
1357 <script type="text/javascript">
1358 <!--
1359 jQuery(function($){
1360         var preloaded = $(".media-item.preloaded");
1361         if ( preloaded.length > 0 ) {
1362                 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1363         }
1364         updateMediaForm();
1365 });
1366 -->
1367 </script>
1368 <div id="media-items">
1369 <?php
1370 if ( $id ) {
1371         if ( !is_wp_error($id) ) {
1372                 echo get_media_items( $id, $errors );
1373         } else {
1374                 echo '<div id="media-upload-error">'.wp_specialchars($id->get_error_message()).'</div>';
1375                 exit;
1376         }
1377 }
1378 ?>
1379 </div>
1380 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
1381 <?php
1382 }
1383
1384 /**
1385  * {@internal Missing Short Description}}
1386  *
1387  * @since unknown
1388  *
1389  * @param unknown_type $type
1390  * @param unknown_type $errors
1391  * @param unknown_type $id
1392  */
1393 function media_upload_type_url_form($type = 'file', $errors = null, $id = null) {
1394         media_upload_header();
1395
1396         $post_id = intval($_REQUEST['post_id']);
1397
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);
1400
1401         $callback = "type_url_form_$type";
1402 ?>
1403
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'); ?>
1407
1408 <?php if ( is_callable($callback) ) { ?>
1409
1410 <h3 class="media-title"><?php _e('Add media file from URL'); ?></h3>
1411
1412 <script type="text/javascript">
1413 //<![CDATA[
1414 var addExtImage = {
1415
1416         width : '',
1417         height : '',
1418         align : 'alignnone',
1419
1420         insert : function() {
1421                 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = null;
1422
1423                 if ( '' == f.src.value || '' == t.width ) return false;
1424
1425                 if ( f.title.value ) {
1426                         title = f.title.value.replace(/['"<>]+/g, '');
1427                         title = ' title="'+title+'"';
1428                 }
1429
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, '&#39;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
1434 <?php } ?>
1435                 }
1436
1437                 cls = caption ? '' : ' class="'+t.align+'"';
1438
1439                 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
1440
1441                 if ( f.url.value )
1442                         html = '<a href="'+f.url.value+'">'+html+'</a>';
1443
1444                 if ( caption )
1445                         html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';
1446
1447                 var win = window.dialogArguments || opener || parent || top;
1448                 win.send_to_editor(html);
1449         },
1450
1451         resetImageData : function() {
1452                 var t = addExtImage;
1453
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';
1459         },
1460
1461         updateImageData : function() {
1462                 var t = addExtImage;
1463
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';
1468         },
1469
1470         getImageData : function() {
1471                 var t = addExtImage, src = document.forms[0].src.value;
1472
1473                 if ( ! src ) {
1474                         t.resetImageData();
1475                         return false;
1476                 }
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;
1482         }
1483 }
1484 //]]>
1485 </script>
1486
1487 <div id="media-items">
1488 <div class="media-item media-blank">
1489 <?php echo call_user_func($callback); ?>
1490 </div>
1491 </div>
1492 </form>
1493 <?php
1494         } else {
1495                 wp_die( __('Unknown action.') );
1496         }
1497 }
1498
1499 /**
1500  * {@internal Missing Short Description}}
1501  *
1502  * @since unknown
1503  *
1504  * @param unknown_type $errors
1505  */
1506 function media_upload_gallery_form($errors) {
1507         global $redir_tab;
1508
1509         $redir_tab = 'gallery';
1510         media_upload_header();
1511
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");
1514 ?>
1515
1516 <script type="text/javascript">
1517 <!--
1518 jQuery(function($){
1519         var preloaded = $(".media-item.preloaded");
1520         if ( preloaded.length > 0 ) {
1521                 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1522                 updateMediaForm();
1523         }
1524 });
1525 -->
1526 </script>
1527
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">
1532 <thead><tr>
1533 <th><?php _e('Media'); ?></th>
1534 <th class="order-head"><?php _e('Order'); ?></th>
1535 </tr></thead>
1536 </table>
1537 <div id="media-items">
1538 <?php echo get_media_items($post_id, $errors); ?>
1539 </div>
1540
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'] ); ?>" />
1546 </p>
1547
1548 <div id="gallery-settings" style="display:none;">
1549 <div class="title"><?php _e('Gallery Settings'); ?></div>
1550 <table id="basic" class="describe"><tbody>
1551         <tr>
1552         <th scope="row" class="label">
1553                 <label>
1554                 <span class="alignleft"><?php _e('Link thumbnails to:'); ?></span>
1555                 </label>
1556         </th>
1557         <td class="field">
1558                 <input type="radio" name="linkto" id="linkto-file" value="file" />
1559                 <label for="linkto-file" class="radio"><?php _e('Image File'); ?></label>
1560
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>
1563         </td>
1564         </tr>
1565
1566         <tr>
1567         <th scope="row" class="label">
1568                 <label>
1569                 <span class="alignleft"><?php _e('Order images by:'); ?></span>
1570                 </label>
1571         </th>
1572         <td class="field">
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>
1577                 </select>
1578         </td>
1579         </tr>
1580
1581         <tr>
1582         <th scope="row" class="label">
1583                 <label>
1584                 <span class="alignleft"><?php _e('Order:'); ?></span>
1585                 </label>
1586         </th>
1587         <td class="field">
1588                 <input type="radio" checked="checked" name="order" id="order-asc" value="asc" />
1589                 <label for="order-asc" class="radio"><?php _e('Ascending'); ?></label>
1590
1591                 <input type="radio" name="order" id="order-desc" value="desc" />
1592                 <label for="order-desc" class="radio"><?php _e('Descending'); ?></label>
1593         </td>
1594         </tr>
1595
1596         <tr>
1597         <th scope="row" class="label">
1598                 <label>
1599                 <span class="alignleft"><?php _e('Gallery columns:'); ?></span>
1600                 </label>
1601         </th>
1602         <td class="field">
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>
1612                 </select>
1613         </td>
1614         </tr>
1615 </tbody></table>
1616
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' ) ); ?>" />
1620 </p>
1621 </div>
1622 </form>
1623 <?php
1624 }
1625
1626 /**
1627  * {@internal Missing Short Description}}
1628  *
1629  * @since unknown
1630  *
1631  * @param unknown_type $errors
1632  */
1633 function media_upload_library_form($errors) {
1634         global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
1635
1636         media_upload_header();
1637
1638         $post_id = intval($_REQUEST['post_id']);
1639
1640         $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=library&post_id=$post_id");
1641
1642         $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;
1643         if ( $_GET['paged'] < 1 )
1644                 $_GET['paged'] = 1;
1645         $start = ( $_GET['paged'] - 1 ) * 10;
1646         if ( $start < 1 )
1647                 $start = 0;
1648         add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
1649
1650         list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1651
1652 ?>
1653
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'] ); ?>" />
1659
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" />
1664 </p>
1665
1666 <ul class="subsubsub">
1667 <?php
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();
1678 }
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 ) {
1683         $class = '';
1684
1685         if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
1686                 continue;
1687
1688         if ( wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
1689                 $class = ' class="current"';
1690
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>';
1692 }
1693 echo implode(' | </li>', $type_links) . '</li>';
1694 unset($type_links);
1695 ?>
1696 </ul>
1697
1698 <div class="tablenav">
1699
1700 <?php
1701 $page_links = paginate_links( array(
1702         'base' => add_query_arg( 'paged', '%#%' ),
1703         'format' => '',
1704         'prev_text' => __('&laquo;'),
1705         'next_text' => __('&raquo;'),
1706         'total' => ceil($wp_query->found_posts / 10),
1707         'current' => $_GET['paged']
1708 ));
1709
1710 if ( $page_links )
1711         echo "<div class='tablenav-pages'>$page_links</div>";
1712 ?>
1713
1714 <div class="alignleft actions">
1715 <?php
1716
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";
1718
1719 $arc_result = $wpdb->get_results( $arc_query );
1720
1721 $month_count = count($arc_result);
1722
1723 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
1724 <select name='m'>
1725 <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
1726 <?php
1727 foreach ($arc_result as $arc_row) {
1728         if ( $arc_row->yyear == 0 )
1729                 continue;
1730         $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
1731
1732         if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
1733                 $default = ' selected="selected"';
1734         else
1735                 $default = '';
1736
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" );
1739         echo "</option>\n";
1740 }
1741 ?>
1742 </select>
1743 <?php } ?>
1744
1745 <input type="submit" id="post-query-submit" value="<?php echo attribute_escape( __( 'Filter &#187;' ) ); ?>" class="button-secondary" />
1746
1747 </div>
1748
1749 <br class="clear" />
1750 </div>
1751 </form>
1752
1753 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="library-form">
1754
1755 <?php wp_nonce_field('media-form'); ?>
1756 <?php //media_upload_form( $errors ); ?>
1757
1758 <script type="text/javascript">
1759 <!--
1760 jQuery(function($){
1761         var preloaded = $(".media-item.preloaded");
1762         if ( preloaded.length > 0 ) {
1763                 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1764                 updateMediaForm();
1765         }
1766 });
1767 -->
1768 </script>
1769
1770 <div id="media-items">
1771 <?php echo get_media_items(null, $errors); ?>
1772 </div>
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; ?>" />
1776 </p>
1777 </form>
1778 <?php
1779 }
1780
1781 /**
1782  * {@internal Missing Short Description}}
1783  *
1784  * @since unknown
1785  *
1786  * @return unknown
1787  */
1788 function type_url_form_image() {
1789
1790         if ( apply_filters( 'disable_captions', '' ) ) {
1791                 $alt = __('Alternate Text');
1792                 $alt_help = __('Alt text for the image, e.g. "The Mona Lisa"');
1793         } else {
1794                 $alt = __('Image Caption');
1795                 $alt_help = __('Also used as alternate text for the image');
1796         }
1797
1798         $default_align = get_option('image_default_align');
1799         if ( empty($default_align) )
1800                 $default_align = 'none';
1801
1802         return '
1803         <table class="describe"><tbody>
1804                 <tr>
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>
1808                         </th>
1809                         <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
1810                 </tr>
1811
1812                 <tr>
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>
1816                         </th>
1817                         <td class="field"><p><input id="title" name="title" value="" type="text" aria-required="true" /></p></td>
1818                 </tr>
1819
1820                 <tr>
1821                         <th valign="top" scope="row" class="label">
1822                                 <span class="alignleft"><label for="alt">' . $alt . '</label></span>
1823                         </th>
1824                         <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
1825                         <p class="help">' . $alt_help . '</p></td>
1826                 </tr>
1827
1828                 <tr class="align">
1829                         <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
1830                         <td class="field">
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>
1839                         </td>
1840                 </tr>
1841
1842                 <tr>
1843                         <th valign="top" scope="row" class="label">
1844                                 <span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span>
1845                         </th>
1846                         <td class="field"><input id="url" name="url" value="" type="text" /><br />
1847
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>
1851                 </tr>
1852
1853                 <tr>
1854                         <td></td>
1855                         <td>
1856                                 <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . attribute_escape(__('Insert into Post')) . '" />
1857                         </td>
1858                 </tr>
1859         </tbody></table>
1860 ';
1861
1862 }
1863
1864 /**
1865  * {@internal Missing Short Description}}
1866  *
1867  * @since unknown
1868  *
1869  * @return unknown
1870  */
1871 function type_url_form_audio() {
1872         return '
1873         <table class="describe"><tbody>
1874                 <tr>
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>
1878                         </th>
1879                         <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1880                 </tr>
1881                 <tr>
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>
1885                         </th>
1886                         <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1887                 </tr>
1888                 <tr><td></td><td class="help">' . __('Link text, e.g. "Still Alive by Jonathan Coulton"') . '</td></tr>
1889                 <tr>
1890                         <td></td>
1891                         <td>
1892                                 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1893                         </td>
1894                 </tr>
1895         </tbody></table>
1896 ';
1897 }
1898
1899 /**
1900  * {@internal Missing Short Description}}
1901  *
1902  * @since unknown
1903  *
1904  * @return unknown
1905  */
1906 function type_url_form_video() {
1907         return '
1908         <table class="describe"><tbody>
1909                 <tr>
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>
1913                         </th>
1914                         <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1915                 </tr>
1916                 <tr>
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>
1920                         </th>
1921                         <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1922                 </tr>
1923                 <tr><td></td><td class="help">' . __('Link text, e.g. "Lucy on YouTube"') . '</td></tr>
1924                 <tr>
1925                         <td></td>
1926                         <td>
1927                                 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1928                         </td>
1929                 </tr>
1930         </tbody></table>
1931 ';
1932 }
1933
1934 /**
1935  * {@internal Missing Short Description}}
1936  *
1937  * @since unknown
1938  *
1939  * @return unknown
1940  */
1941 function type_url_form_file() {
1942         return '
1943         <table class="describe"><tbody>
1944                 <tr>
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>
1948                         </th>
1949                         <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1950                 </tr>
1951                 <tr>
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>
1955                         </th>
1956                         <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1957                 </tr>
1958                 <tr><td></td><td class="help">' . __('Link text, e.g. "Ransom Demands (PDF)"') . '</td></tr>
1959                 <tr>
1960                         <td></td>
1961                         <td>
1962                                 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1963                         </td>
1964                 </tr>
1965         </tbody></table>
1966 ';
1967 }
1968
1969 /**
1970  * {@internal Missing Short Description}}
1971  *
1972  * Support a GET parameter for disabling the flash uploader.
1973  *
1974  * @since unknown
1975  *
1976  * @param unknown_type $flash
1977  * @return unknown
1978  */
1979 function media_upload_use_flash($flash) {
1980         if ( array_key_exists('flash', $_REQUEST) )
1981                 $flash = !empty($_REQUEST['flash']);
1982         return $flash;
1983 }
1984
1985 add_filter('flash_uploader', 'media_upload_use_flash');
1986
1987 /**
1988  * {@internal Missing Short Description}}
1989  *
1990  * @since unknown
1991  */
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)) );
1995         echo '</p>';
1996 }
1997
1998 /**
1999  * {@internal Missing Short Description}}
2000  *
2001  * @since unknown
2002  */
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)) );
2008         else
2009                 // the user probably doesn't have Flash
2010                 printf( __('You are using the Browser uploader.') );
2011
2012         echo '</p>';
2013 }
2014
2015 add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
2016 add_action('post-html-upload-ui', 'media_upload_html_bypass');
2017
2018 /**
2019  * {@internal Missing Short Description}}
2020  *
2021  * Make sure the GET parameter sticks when we submit a form.
2022  *
2023  * @since unknown
2024  *
2025  * @param unknown_type $url
2026  * @return unknown
2027  */
2028 function media_upload_bypass_url($url) {
2029         if ( array_key_exists('flash', $_REQUEST) )
2030                 $url = add_query_arg('flash', intval($_REQUEST['flash']));
2031         return $url;
2032 }
2033
2034 add_filter('media_upload_form_url', 'media_upload_bypass_url');
2035
2036
2037
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);
2042
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');
2047
2048 add_filter('media_upload_gallery', 'media_upload_gallery');
2049
2050 add_filter('media_upload_library', 'media_upload_library');
2051
2052 ?>