Changeset 7043 for trunk/wp-admin/includes/media.php
- Timestamp:
- 02/26/2008 07:30:10 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/media.php
r7002 r7043 1 1 <?php 2 2 3 function image_upload_tabs() {3 function media_upload_tabs() { 4 4 $_default_tabs = array( 5 'image_upload_handler' => __('From Computer'), // handler function name => tab text 5 'computer' => __('From Computer'), // handler action suffix => tab text 6 'attachments' => __('Attachments'), 7 'library' => __('Media Library'), 6 8 ); 7 9 8 return apply_filters('image_upload_tabs', $_default_tabs); 9 } 10 11 function the_image_upload_tabs() { 12 $tabs = image_upload_tabs(); 10 return apply_filters('media_upload_tabs', $_default_tabs); 11 } 12 13 function update_attachments_tab($tabs) { 14 global $wpdb; 15 if ( !isset($_REQUEST['post_id']) ) { 16 unset($tabs['attachments']); 17 return $tabs; 18 } 19 if ( intval($_REQUEST['post_id']) ) 20 $attachments = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id'])); 21 22 $tabs['attachments'] = sprintf(__('Attachments (%s)'), "<span id='attachments-count'>$attachments</span>"); 23 24 return $tabs; 25 } 26 add_filter('media_upload_tabs', 'update_attachments_tab'); 27 28 function the_media_upload_tabs() { 29 $tabs = media_upload_tabs(); 13 30 14 31 if ( !empty($tabs) ) { … … 21 38 if ( ++$i == count($tabs) ) 22 39 $class = ' class="last"'; 23 if ( $callback == $current )24 $disabled = ' disabled="disabled"';25 else26 $disabled = '';27 40 $href = add_query_arg('tab', $callback); 28 41 if ( $callback == $current ) … … 30 43 else 31 44 $link = "<a href='$href'>$text</a>"; 32 echo "\t<li $class>$link</li>\n";45 echo "\t<li id='tab-$callback'$class>$link</li>\n"; 33 46 } 34 47 echo "</ul>\n"; … … 144 157 global $post_ID, $temp_ID; 145 158 $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID); 146 $m ultimedia_upload_iframe_src = "media-upload.php?type=multimedia&post_id=$uploading_iframe_ID";147 $m ultimedia_upload_iframe_src = apply_filters('multimedia_upload_iframe_src', $multimedia_upload_iframe_src);148 echo "<a href='$m ultimedia_upload_iframe_src&TB_iframe=true&height=500&width=640' class='button-secondary thickbox'>" . __('Add media'). '</a>';159 $media_upload_iframe_src = "media-upload.php?type=media&post_id=$uploading_iframe_ID"; 160 $media_upload_iframe_src = apply_filters('media_upload_iframe_src', $media_upload_iframe_src); 161 echo "<a href='$media_upload_iframe_src&TB_iframe=true&height=500&width=640' class='button-secondary thickbox'>" . __('Add media'). '</a>'; 149 162 } 150 163 add_action( 'media_buttons', 'media_buttons' ); … … 170 183 } 171 184 172 add_action('media_upload_multimedia', 'multimedia_upload_handler'); 173 add_action('admin_head_image_upload_form', 'media_admin_css'); 174 175 function multimedia_upload_handler() { 176 if ( !current_user_can('upload_files') ) { 177 return new wp_error( 'upload_not_allowed', __('You are not allowed to upload files.') ); 178 } 179 180 // no button click, we're just displaying the form 181 if ( empty($_POST) ) 182 return wp_iframe( 'multimedia_upload_form' ); 183 184 check_admin_referer('multimedia-form'); 185 186 // Insert multimedia button was clicked 185 add_action('media_upload_media', 'media_upload_handler'); 186 187 function media_upload_form_handler() { 188 check_admin_referer('media-form'); 189 190 // Insert media button was clicked 187 191 if ( !empty($_FILES) ) { 188 192 // Upload File button was clicked … … 218 222 } 219 223 220 if ( isset($_POST['insert-m ultimedia']) )224 if ( isset($_POST['insert-media']) ) 221 225 return media_send_to_editor('[gallery]'); 222 226 … … 228 232 } 229 233 230 wp_iframe( 'multimedia_upload_form', $errors ); 231 } 232 233 function get_multimedia_items( $post_id, $errors ) { 234 $attachments = get_children("post_parent=$post_id&post_type=attachment&orderby=\"menu_order ASC, ID ASC\""); 234 return $errors; 235 } 236 237 function media_upload_computer() { 238 if ( !empty($_POST) ) { 239 $return = media_upload_form_handler(); 240 241 if ( is_string($return) ) 242 return $return; 243 if ( is_array($return) ) 244 $errors = $return; 245 } 246 247 return wp_iframe( 'media_upload_computer_form', $errors ); 248 } 249 250 function media_upload_attachments() { 251 if ( !empty($_POST) ) { 252 $return = media_upload_form_handler(); 253 254 if ( is_string($return) ) 255 return $return; 256 if ( is_array($return) ) 257 $errors = $return; 258 } 259 260 return wp_iframe( 'media_upload_attachments_form', $errors ); 261 } 262 263 function media_upload_library() { 264 if ( empty($_POST) ) 265 wp_iframe( 'media_upload_library_form', $errors ); 266 } 267 268 function get_media_items( $post_id, $errors ) { 269 if ( $post_id ) 270 $attachments = get_children("post_parent=$post_id&post_type=attachment&orderby=menu_order ASC, ID&order=DESC"); 271 else 272 $attachments = get_paged_attachments(); 235 273 236 274 if ( empty($attachments) ) … … 238 276 239 277 foreach ( $attachments as $id => $attachment ) 240 if ( $item = get_m ultimedia_item($id, isset($errors[$id]) ? $errors[$id] : null) )241 $output .= "\n<div id='m ultimedia-item-$id' class='multimedia-item preloaded'><div id='media-upload-error-$id'></div><span class='filename'></span><div class='progress'><div class='bar'></div></div>$item<div class='progress clickmask'></div>\n</div>";278 if ( $item = get_media_item($id, isset($errors[$id]) ? $errors[$id] : null) ) 279 $output .= "\n<div id='media-item-$id' class='media-item preloaded'><div id='media-upload-error-$id'></div><span class='filename'></span><div class='progress'><div class='bar'></div></div>$item<div class='progress clickmask'></div>\n</div>"; 242 280 243 281 return $output; … … 416 454 } 417 455 418 function get_m ultimedia_item( $attachment_id, $errors = null, $send = true ) {456 function get_media_item( $attachment_id, $errors = null, $send = true ) { 419 457 if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) ) 420 $thumb_url = $thumb_url[ 1];458 $thumb_url = $thumb_url[0]; 421 459 else 422 460 return false; … … 454 492 <tr><td>$post->post_mime_type</td></tr> 455 493 <tr><td>" . mysql2date($post->post_date, get_option('time_format')) . "</td></tr> 456 <tr><td>" . apply_filters('m ultimedia_meta', '', $post) . "</tr></td>\n";494 <tr><td>" . apply_filters('media_meta', '', $post) . "</tr></td>\n"; 457 495 458 496 $defaults = array( … … 537 575 } 538 576 539 function multimedia_upload_form( $errors = null ) { 540 $flash_action_url = get_option('siteurl') . '/wp-admin/async-upload.php?type=multimedia'; 541 $form_action_url = get_option('siteurl') . '/wp-admin/media-upload.php?type=multimedia'; 577 function media_upload_header() { 578 ?> 579 <div id="media-upload-header"> 580 <h3><?php _e('Add Media'); ?></h3> 581 <?php the_media_upload_tabs(); ?> 582 </div> 583 <?php 584 } 585 586 function media_upload_form( $errors = null ) { 587 $flash_action_url = get_option('siteurl') . '/wp-admin/async-upload.php?type=media'; 542 588 543 589 $post_id = intval($_REQUEST['post_id']); 544 590 545 591 ?> 546 <div id="media-upload-header">547 <h3><?php _e('Add Media'); ?></h3>548 <?php the_image_upload_tabs(); ?>549 </div>550 551 592 <div id="media-upload-error"> 552 593 <?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?> … … 565 606 "post_id" : "<?php echo $post_id; ?>", 566 607 "auth_cookie" : "<?php echo $_COOKIE[AUTH_COOKIE]; ?>", 567 "type" : "m ultimedia"608 "type" : "media" 568 609 }, 569 610 swfupload_element_id : "flash-upload-ui", // id of the element displayed when swfupload is available … … 583 624 }); 584 625 $("#flash-browse-button").bind( "click", function(){swfu.selectFiles();}); 585 var preloaded = $(".multimedia-item.preloaded");586 if ( preloaded.length > 0 ) {587 jQuery('#insert-multimedia').attr('disabled', '');588 preloaded.each(function(){uploadSuccess({id:this.id.replace(/[^0-9]/g, '')},'');});589 }590 626 }); 591 627 //--> 592 628 </script> 593 629 594 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form">595 630 596 631 <div id="flash-upload-ui"> 597 632 <p><input id="flash-browse-button" type="button" value="<?php _e('Choose files to upload'); ?>" class="button" /></p> 598 <p><?php _e('A s each upload completes, you can add titles and descriptions below.'); ?></p>633 <p><?php _e('After a file has been uploaded, you can add titles and descriptions below.'); ?></p> 599 634 </div> 600 635 … … 611 646 <br style="clear:both" /> 612 647 </div> 613 614 <div id="multimedia-items"> 615 616 <?php echo get_multimedia_items($post_id, $errors); ?> 617 648 <?php 649 } 650 651 function media_upload_computer_form( $errors = null ) { 652 media_upload_header(); 653 654 $post_id = intval($_REQUEST['post_id']); 655 656 $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type=media&tab=computer&post_id=$post_id"; 657 658 ?> 659 660 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="computer-form"> 661 <?php wp_nonce_field('media-form'); ?> 662 <?php media_upload_form( $errors ); ?> 663 664 <div id="media-items"></div> 665 <p class="submit"> 666 <input type="submit" class="submit insert-gallery" name="insert-media" value="<?php _e('Insert gallery into post'); ?>" /> 667 </p> 668 </form> 669 670 <?php 671 } 672 673 function media_upload_attachments_form($errors) { 674 media_upload_header(); 675 676 $post_id = intval($_REQUEST['post_id']); 677 678 $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type=media&tab=attachments&post_id=$post_id"; 679 680 ?> 681 682 <script type="text/javascript"> 683 <!-- 684 jQuery(function($){ 685 var preloaded = $(".media-item.preloaded"); 686 if ( preloaded.length > 0 ) { 687 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); 688 updateMediaForm(); 689 } 690 }); 691 --> 692 </script> 693 694 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="attachments-form"> 695 <?php wp_nonce_field('media-form'); ?> 696 <?php //media_upload_form( $errors ); ?> 697 698 <div id="media-items"> 699 <?php echo get_media_items($post_id, $errors); ?> 618 700 </div> 619 620 701 <p class="submit"> 621 <input type="submit" class="submit insert-gallery" name="insert-m ultimedia" value="<?php _e('Insert gallery into post'); ?>" />702 <input type="submit" class="submit insert-gallery" name="insert-media" value="<?php _e('Insert gallery into post'); ?>" /> 622 703 </p> 623 624 <?php wp_nonce_field('multimedia-form'); ?> 625 704 <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" /> 626 705 </form> 627 628 706 <?php 629 707 } 630 708 631 add_action('admin_head_multimedia_upload_form', 'media_admin_css'); 632 add_filter('async_upload_multimedia', 'get_multimedia_item', 10, 2); 633 add_filter('media_upload_multimedia', 'multimedia_upload_handler'); 709 function media_upload_library_form($errors) { 710 media_upload_header(); 711 } 712 713 add_filter('async_upload_media', 'get_media_item', 10, 2); 714 715 add_filter('media_upload_computer', 'media_upload_computer'); 716 add_action('admin_head_media_upload_computer_form', 'media_admin_css'); 717 718 add_filter('media_upload_attachments', 'media_upload_attachments'); 719 add_action('admin_head_media_upload_attachments_form', 'media_admin_css'); 720 721 add_filter('media_upload_library', 'media_upload_library'); 722 add_action('admin_head_media_upload_library_form', 'media_admin_css'); 634 723 635 724
Note: See TracChangeset
for help on using the changeset viewer.