Ticket #21329: 21329.3.diff
| File 21329.3.diff, 8.2 KB (added by , 14 years ago) |
|---|
-
wp-admin/includes/media.php
7 7 */ 8 8 9 9 /** 10 * {@internal Missing Short Description}}10 * Defines media tabs to be used in thickbox 11 11 * 12 12 * @since 2.5.0 13 13 * 14 * @return unknown 14 * @uses apply_filters() calls media_upload_tabs 15 * 16 * @return an associative array of tab names in the form of type=>name 15 17 */ 16 18 function media_upload_tabs() { 17 19 $_default_tabs = array( … … 25 27 } 26 28 27 29 /** 28 * {@internal Missing Short Description}} 30 * Added to media_upload_tabs filter to define the gallery tab 31 * checks for attachments and removes gallery tab if the current post has none. 29 32 * 30 33 * @since 2.5.0 31 34 * 32 * @param unknown_type$tabs33 * @return unknown35 * @param array $tabs 36 * @return an associative array of tab names in the form of type=>name 34 37 */ 35 38 function update_gallery_tab($tabs) { 36 39 global $wpdb; … … 57 60 add_filter('media_upload_tabs', 'update_gallery_tab'); 58 61 59 62 /** 60 * {@internal Missing Short Description}}63 * Echoes the thickbox media upload tabs to the screen 61 64 * 62 65 * @since 2.5.0 63 66 */ … … 65 68 global $redir_tab; 66 69 $tabs = media_upload_tabs(); 67 70 $default = 'type'; 68 71 $html = ''; 72 69 73 if ( !empty($tabs) ) { 70 echo"<ul id='sidemenu'>\n";74 $html = "<ul id='sidemenu'>\n"; 71 75 if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) ) 72 76 $current = $redir_tab; 73 77 elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) ) … … 83 87 84 88 $href = add_query_arg(array('tab' => $callback, 's' => false, 'paged' => false, 'post_mime_type' => false, 'm' => false)); 85 89 $link = "<a href='" . esc_url($href) . "'$class>$text</a>"; 86 echo"\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n";90 $html .= "\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n"; 87 91 } 88 echo"</ul>\n";92 $html .= "</ul>\n"; 89 93 } 94 echo $html; 90 95 } 91 96 92 97 /** 93 * {@internal Missing Short Description}}98 * Creates the html for an image as it is added to the editor 94 99 * 95 100 * @since 2.5.0 96 101 * 102 * @uses apply_filters() calls image_send_to_editor 97 103 * @param unknown_type $id 98 104 * @param unknown_type $alt 99 105 * @param unknown_type $title … … 101 107 * @param unknown_type $url 102 108 * @param unknown_type $rel 103 109 * @param unknown_type $size 104 * @return unknown110 * @return string - the html for an image tag 105 111 */ 106 112 function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') { 107 113 … … 118 124 } 119 125 120 126 /** 121 * {@internal Missing Short Description}}127 * Wraps an image in the caption code 122 128 * 123 129 * @since 2.6.0 124 130 * … … 170 176 } 171 177 172 178 /** 173 * {@internal Missing Short Description}}179 * Echoes the javascript used to send html back to the editor 174 180 * 175 181 * @since 2.5.0 176 182 * 177 * @param unknown_type$html183 * @param string $html 178 184 */ 179 185 function media_send_to_editor($html) { 180 186 ?> … … 189 195 } 190 196 191 197 /** 192 * {@internal Missing Short Description}}193 *194 198 * This handles the file upload POST itself, creating the attachment post. 195 199 * 196 200 * @since 2.5.0 … … 260 264 * 261 265 * @since 2.6.0 262 266 * 267 * @uses wp_handle_sideload 268 * @uses wp_read_image_metadata 269 * @uses wp_insert_attachment 270 * @uses wp_update_attachment_metadata 271 * @uses wp_generate_attachment_metadata 263 272 * @param array $file_array Array similar to a {@link $_FILES} upload array 264 273 * @param int $post_id The post ID the media is associated with 265 274 * @param string $desc Description of the sideloaded file … … 312 321 } 313 322 314 323 /** 315 * {@internal Missing Short Description}}324 * Generates html for the iframe used in the thickbox window for uploads 316 325 * 317 326 * Wrap iframe content (produced by $content_func) in a doctype, html head/body 318 327 * etc any additional function args will be passed to content_func. … … 373 382 } 374 383 375 384 /** 376 * {@internal Missing Short Description}} 385 * Echoes the html for media upload buttons 386 * added to the action call for 'media_buttons' 377 387 * 378 388 * @since 2.5.0 379 389 */ … … 386 396 } 387 397 add_action( 'media_buttons', 'media_buttons' ); 388 398 399 /** 400 * Determine url of the upload thickbox to be used in the media_buttons() link 401 * 402 * @uses apply_filters() calls $type . '_upload_iframe_src' 403 * @param string $type 404 * @param int $post_id 405 * @param string $tab 406 * @since unknown 407 */ 389 408 function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) { 390 409 global $post_ID; 391 410 … … 625 644 } 626 645 627 646 /** 628 * {@internal Missing Short Description}}647 * Download an image from the specified URL and attach it to a post. 629 648 * 630 * @since 2. 5.0649 * @since 2.6.0 631 650 * 632 * @return unknown 651 * @param string $file The URL of the image to download 652 * @param int $post_id The post ID the media is to be associated with 653 * @param string $desc Optional. Description of the image 654 * @return string|WP_Error Populated HTML img tag on success 633 655 */ 634 function media_upload_gallery() { 656 function media_sideload_image($file, $post_id, $desc = null) { 657 if ( ! empty($file) ) { 658 // Download file to temp location 659 $tmp = download_url( $file ); 660 661 // Set variables for storage 662 // fix file filename for query strings 663 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); 664 $file_array['name'] = basename($matches[0]); 665 $file_array['tmp_name'] = $tmp; 666 667 // If error storing temporarily, unlink 668 if ( is_wp_error( $tmp ) ) { 669 @unlink($file_array['tmp_name']); 670 $file_array['tmp_name'] = ''; 671 } 672 673 // do the validation and storage stuff 674 $id = media_handle_sideload( $file_array, $post_id, $desc ); 675 // If error storing permanently, unlink 676 if ( is_wp_error($id) ) { 677 @unlink($file_array['tmp_name']); 678 return $id; 679 } 680 681 $src = wp_get_attachment_url( $id ); 682 } 683 684 // Finally check to make sure the file has been saved, then return the html 685 if ( ! empty($src) ) { 686 $alt = isset($desc) ? esc_attr($desc) : ''; 687 $html = "<img src='$src' alt='$alt' />"; 688 return $html; 689 } 690 } 691 692 /** 693 * Returns wp_iframe with the proper upload form for media uploads 694 * added to the media_upload filter in media-upload.php 695 * 696 * @since 3.5.0 697 * 698 * @return HTML from the wp_iframe function 699 */ 700 function media_upload() { 635 701 $errors = array(); 636 637 if ( !empty($_POST) ) { 702 $current_filter = current_filter(); 703 $type = str_replace( 'media_upload_' , '' , $current_filter ); 704 705 if ( !empty($_POST) || empty($type) ) { 638 706 $return = media_upload_form_handler(); 639 640 707 if ( is_string($return) ) 641 708 return $return; 642 709 if ( is_array($return) ) … … 644 711 } 645 712 646 713 wp_enqueue_script('admin-gallery'); 647 return wp_iframe( 'media_upload_gallery_form', $errors ); 714 715 switch($type) { 716 case 'library' : 717 $return = 'media_upload_library_form'; 718 break; 719 case 'gallery' : 720 $return = 'media_upload_gallery_form'; 721 break; 722 default : 723 $return = 'wp_media_upload_handler'; 724 break; 725 } 726 return wp_iframe( $return , $errors ); 648 727 } 649 728 650 729 /** … … 654 733 * 655 734 * @return unknown 656 735 */ 736 function media_upload_gallery() { 737 media_upload( 'gallery' ); 738 } 739 740 /** 741 * {@internal Missing Short Description}} 742 * 743 * @since 2.5.0 744 * 745 * @return unknown 746 */ 657 747 function media_upload_library() { 658 $errors = array(); 659 if ( !empty($_POST) ) { 660 $return = media_upload_form_handler(); 661 662 if ( is_string($return) ) 663 return $return; 664 if ( is_array($return) ) 665 $errors = $return; 666 } 667 668 return wp_iframe( 'media_upload_library_form', $errors ); 748 media_upload( 'library' ); 669 749 } 670 750 671 751 /** … … 2100 2180 add_filter( 'async_upload_video', 'get_media_item', 10, 2 ); 2101 2181 add_filter( 'async_upload_file', 'get_media_item', 10, 2 ); 2102 2182 2103 add_action( 'media_upload_image', ' wp_media_upload_handler' );2104 add_action( 'media_upload_audio', ' wp_media_upload_handler' );2105 add_action( 'media_upload_video', ' wp_media_upload_handler' );2106 add_action( 'media_upload_file', ' wp_media_upload_handler' );2183 add_action( 'media_upload_image', 'media_upload' ); 2184 add_action( 'media_upload_audio', 'media_upload' ); 2185 add_action( 'media_upload_video', 'media_upload' ); 2186 add_action( 'media_upload_file', 'media_upload' ); 2107 2187 2108 add_filter( 'media_upload_gallery', 'media_upload _gallery' );2109 add_filter( 'media_upload_library', 'media_upload _library' );2188 add_filter( 'media_upload_gallery', 'media_upload' ); 2189 add_filter( 'media_upload_library', 'media_upload' );