Changeset 6974 for trunk/wp-admin/includes/media.php
- Timestamp:
- 02/22/2008 05:53:47 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/media.php
r6952 r6974 36 36 } 37 37 38 function image_upload_callback() {39 $tabs = image_upload_tabs();40 if ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) && is_callable($_GET['tab']) )41 return $_GET['tab']();42 elseif ( is_callable($first = array_shift(array_keys($tabs))) )43 return $first();44 else45 return image_upload_handler();46 }47 48 add_action('media_upload_image', 'image_upload_callback');49 50 function image_upload_form( $action_url, $values = array(), $error = null ) {51 $action_url = attribute_escape( $action_url );52 $image_alt = attribute_escape( @$values['image-alt'] );53 $image_url = attribute_escape( @$values['image-url'] );54 $image_title = attribute_escape( @$values['image-title'] );55 $image_align = @$values['image-url'];56 $post_id = $_GET['post_id'];57 58 ?>59 <div id="media-upload-header">60 <h3><?php _e('Add Image') ?></h3>61 <?php the_image_upload_tabs(); ?>62 </div>63 <div id="media-upload-error">64 <?php if ($error) {65 echo $error->get_error_message();66 } ?>67 </div>68 <script type="text/javascript">69 <!--70 71 jQuery(document).ready(function(){72 var swfu = new SWFUpload({73 upload_url : "<?php echo get_option('siteurl').'/wp-admin/async-upload.php'; ?>",74 flash_url : "<?php echo get_option('siteurl').'/wp-includes/js/swfupload/swfupload_f9.swf'; ?>",75 file_post_name: "async-upload",76 swfupload_element_id : "flash-upload-ui", // id of the element displayed when swfupload is available77 degraded_element_id : "html-upload-ui", // when swfupload is unavailable78 //file_types : "*.jpg;*.gif;*.png",79 file_size_limit : "<?php echo wp_max_upload_size(); ?> B",80 post_params : {81 "post_id" : "<?php echo $post_id; ?>",82 "auth_cookie" : "<?php echo $_COOKIE[AUTH_COOKIE]; ?>",83 "type" : "image",84 },85 swfupload_loaded_handler : uploadLoadedImage,86 upload_progress_handler : uploadProgressImage,87 upload_success_handler : uploadSuccessImage,88 upload_error_handler: uploadError,89 file_queued_handler : fileQueuedImage,90 file_queue_error_handler : fileQueueError,91 file_dialog_complete_handler : fileDialogComplete,92 93 custom_settings : {94 progressTarget : "flash-upload-ui",95 cancelButtonId : "btnCancel2"96 },97 98 debug: false,99 100 });101 102 document.getElementById("flash-browse-button").onclick = function () { swfu.selectFile(); };103 });104 //-->105 </script>106 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($action_url); ?>" id="image-upload" class="media-upload-form">107 <p id="flash-upload-ui">108 <label for="flash-browse-button"><?php _e('Choose image'); ?></label>109 <input id="flash-browse-button" type="button" value="<?php _e('Browse'); ?>" />110 <label for="image-file" class="form-help"><?php _e('Only PNG, JPG, GIF'); ?></label></p>111 <p id="html-upload-ui"><label for="image-file"><?php _e('Choose image'); ?></label>112 <input type="file" name="image-file" id="image-file" />113 <label for="image-file" class="form-help"><?php _e('Only PNG, JPG, GIF'); ?></label></p>114 <p><label for="image-alt" class="required"><?php _e('<alt> (required)'); ?></label>115 <input type="text" name="image-alt" id="image-alt" />116 <label for="image-alt" class="form-help"><?php _e('e.g., The Mona Lisa'); ?></label></p>117 <p><label for="image-url"><?php _e('URL'); ?></label>118 <input type="text" name="image-url" id="image-url" />119 <label for="image-url" class="form-help"><?php _e('e.g., http://www.wordpress.org/'); ?></label></p>120 <p><label for="image-title"><?php _e('<title>'); ?></label>121 <input type="text" name="image-title" id="image-title" />122 <label for="image-url" class="form-help"><?php _e('e.g., The Mona Lisa, one of many paintings in the Louvre'); ?></label></p>123 <fieldset id="image-align">124 <legend><?php _e('Alignment'); ?></legend>125 <input type="radio" name="image-align" id="image-align-none" value="none" <?php if ($image_align == 'none' || !$image_align) echo ' checked="checked"'; ?>/>126 <label for="image-align-none" id="image-align-none-label"><?php _e('None'); ?></label>127 <input type="radio" name="image-align" id="image-align-left" value="left" <?php if ($image_align == 'left') echo ' checked="checked"'; ?>/>128 <label for="image-align-left" id="image-align-left-label"><?php _e('Left'); ?></label>129 <input type="radio" name="image-align" id="image-align-center" value="center" <?php if ($image_align == 'center') echo ' checked="checked"'; ?>/>130 <label for="image-align-center" id="image-align-center-label"><?php _e('Center'); ?></label>131 <input type="radio" name="image-align" id="image-align-right" value="right" <?php if ($image_align == 'right') echo ' checked="checked"'; ?>/>132 <label for="image-align-right" id="image-align-right-label"><?php _e('Right'); ?></label>133 </fieldset>134 <fieldset id="image-size">135 <legend><?php _e('Size'); ?></legend>136 <input type="radio" name="image-size" id="image-size-thumb" value="thumb" <?php if ($image_size == 'thumb') echo ' checked="checked"'; ?>/>137 <label for="image-size-thumb" id="image-size-thumb-label"><?php _e('Thumbnail'); ?></label>138 <input type="radio" name="image-size" id="image-size-medium" value="medium" <?php if ($image_size == 'medium' || !$image_size) echo ' checked="checked"'; ?>/>139 <label for="image-size-medium" id="image-size-medium-label"><?php _e('Medium'); ?></label>140 <input type="radio" name="image-size" id="image-size-full" value="full" <?php if ($image_size == 'full') echo ' checked="checked"'; ?>/>141 <label for="image-size-full" id="image-size-full-label"><?php _e('Full size'); ?></label>142 </fieldset>143 <p>144 <button name="image-add" id="image-add" class="button-ok" value="1"><?php _e('Add Image'); ?></button>145 <a href="#" onClick="return top.tb_remove();" id="image-cancel" class="button-cancel"><?php _e('Cancel'); ?></a>146 </p>147 <input type="hidden" name="post_id" value="<?php echo attribute_escape($post_id); ?>" />148 <?php wp_nonce_field( 'inlineuploading' ); ?>149 </form>150 <?php151 }152 153 function image_upload_handler() {154 155 if ( !current_user_can('upload_files') ) {156 return new wp_error( 'upload_not_allowed', __('You are not allowed to upload files.') );157 }158 159 if ( empty($_POST['image-add']) ) {160 // no button click, we're just displaying the form161 wp_iframe( 'image_upload_form', get_option('siteurl') . '/wp-admin/media-upload.php?type=image' );162 }163 else {164 // Add Image button was clicked165 check_admin_referer('inlineuploading');166 167 // if the async flash uploader was used, the attachment has already been inserted and its ID is passed in post.168 // otherwise this is a regular form post and we still have to handle the upload and create the attachment.169 if ( !empty($_POST['attachment_id']) ) {170 $id = intval($_POST['attachment_id']);171 // store the title and alt into the attachment post172 wp_update_post(array(173 'ID' => $id,174 'post_title' => $_POST['image-title'],175 'post_content' => $_POST['image-alt'],176 ));177 }178 else {179 $id = image_upload_post();180 }181 182 // if the input was invalid, redisplay the form with its current values183 if ( is_wp_error($id) )184 wp_iframe( 'image_upload_form', get_option('siteurl') . '/wp-admin/media-upload.php?type=image', $_POST, $id );185 else {186 media_send_to_editor(get_image_send_to_editor($id, $_POST['image-alt'], $_POST['image-title'], $_POST['image-align'], $_POST['image-url'], true, $_POST['image-size']));187 }188 }189 }190 191 // this returns html to include in the single image upload form when the async flash upload has finished192 // i.e. show a thumb of the image, and include the attachment id as a hidden input193 function async_image_callback($id) {194 $thumb_url = wp_get_attachment_thumb_url($id);195 if ( empty($thumb_url) )196 $thumb_url = wp_mime_type_icon($id);197 198 if ($thumb_url) {199 $out = '<p><input type="hidden" name="attachment_id" id="attachment_id" value="'.intval($id).'" />'200 . '<img src="'.wp_get_attachment_thumb_url($id).'" class="pinkynail" /> '201 . basename(wp_get_attachment_url($id)).'</p>';202 }203 else {204 $out = '<p><input type="hidden" name="attachment_id" id="attachment_id" value="'.intval($id).'" />'205 . basename(wp_get_attachment_url($id)).'</p>';206 }207 208 $post = get_post($id);209 $title = addslashes($post->post_title);210 $alt = addslashes($post->post_content);211 212 // populate the input fields with post data (which in turn comes from exif/iptc)213 $out .= <<<EOF214 <script type="text/javascript">215 <!--216 jQuery('#image-alt').val('{$alt}').attr('disabled', false);217 jQuery('#image-title').val('{$title}').attr('disabled', false);218 jQuery('#image-url').attr('disabled', false);219 jQuery('#image-add').attr('disabled', false);220 -->221 </script>222 EOF;223 224 return $out;225 }226 227 add_filter('async_upload_image', 'async_image_callback');228 229 230 38 function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') { 231 39 … … 253 61 <?php 254 62 exit; 255 }256 257 // this handles the file upload POST itself, validating input and inserting the file if it's valid258 function image_upload_post() {259 if ( empty($_FILES['image-file']['name']) )260 return new wp_error( 'image_file_required', __('Please choose an image file to upload') );261 if ( empty($_POST['image-alt']) )262 return new wp_error( 'image_alt_required', __('Please enter an <alt> description') );263 264 $overrides = array('test_form'=>false);265 $file = wp_handle_upload($_FILES['image-file'], $overrides);266 267 if ( isset($file['error']) )268 return new wp_error( 'upload_error', $file['error'] );269 270 $url = $file['url'];271 $type = $file['type'];272 $file = $file['file'];273 274 $post_title = trim($_POST['image-title']);275 $post_content = trim($_POST['image-alt']);276 $post_parent = intval($_POST['parent_post_id']);277 278 // Construct the attachment array279 $attachment = array(280 'post_title' => $post_title,281 'post_content' => $post_content,282 'post_type' => 'attachment',283 'post_parent' => $post_parent,284 'post_mime_type' => $type,285 'guid' => $url286 );287 288 // Save the data289 $id = wp_insert_attachment($attachment, $file, $post_parent);290 if ( !is_wp_error($id) )291 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );292 293 return $id;294 63 } 295 64 … … 372 141 } 373 142 374 function media_buttons() { // just a placeholder for now143 function media_buttons() { 375 144 global $post_ID, $temp_ID; 376 145 $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID); 377 $image_upload_iframe_src = wp_nonce_url("media-upload.php?type=image&post_id=$uploading_iframe_ID", 'inlineuploading'); 378 $image_upload_iframe_src = apply_filters('image_upload_iframe_src', $image_upload_iframe_src); 379 $multimedia_upload_iframe_src = wp_nonce_url("media-upload.php?type=multimedia&post_id=$uploading_iframe_ID", 'inlineuploading'); 146 $multimedia_upload_iframe_src = "media-upload.php?type=multimedia&post_id=$uploading_iframe_ID"; 380 147 $multimedia_upload_iframe_src = apply_filters('multimedia_upload_iframe_src', $multimedia_upload_iframe_src); 381 $out = <<<EOF 382 383 <a href="{$image_upload_iframe_src}&TB_iframe=true&height=550&width=480" class="thickbox"><img src='images/media-button-image.gif' alt='' /></a> 384 <a href="{$multimedia_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox"><img src='images/media-button-gallery.gif' alt='' /></a> 385 <a href="{$image_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox"><img src='images/media-button-video.gif' alt='' /></a> 386 <a href="{$image_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox"><img src='images/media-button-music.gif' alt='' /></a> 387 <a href="{$image_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox"><img src='images/media-button-other.gif' alt='' /></a> 388 389 390 EOF; 391 echo $out; 148 echo "<a href='$multimedia_upload_iframe_src&TB_iframe=true&height=500&width=640' class='button thickbox'>" . __('Add media'). '</a>'; 392 149 } 393 150 add_action( 'media_buttons', 'media_buttons' ); … … 523 280 if ( substr($post->post_mime_type, 0, 5) == 'image' ) { 524 281 $form_fields['post_title']['required'] = true; 525 $form_fields['post_excerpt']['label'] = __('Alternate Text'); 526 $form_fields['post_content']['label'] = __('Description'); 527 528 if ( strlen(trim($post->post_excerpt)) == 0 ) 529 $form_fields['post_excerpt']['helps'][] = __('Alternate Text helps people who can not see the image.'); 282 $form_fields['post_excerpt']['label'] = __('Description'); 283 $form_fields['post_excerpt']['helps'][] = __('Alternate text, e.g. "The Mona Lisa"'); 284 285 $form_fields['post_content']['label'] = __('Long Description'); 286 287 $thumb = wp_get_attachment_thumb_url(); 530 288 531 289 $form_fields['_send']['url'] = array( … … 548 306 <label for='image-align-right-$post->ID' class='align image-align-right-label'>" . __('Right') . "</label>\n", 549 307 ); 308 $form_fields['_send']['image-size'] = array( 309 'label' => __('Size'), 310 'input' => 'html', 311 'html' => " 312 " . ( $thumb ? "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-thumb-$post->ID' value='thumb' /> 313 <label for='image-size-thumb-$post->ID'>" . __('Thumbnail') . "</label> 314 " : '' ) . "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-medium-$post->ID' value='medium' checked='checked' /> 315 <label for='image-size-medium-$post->ID'>" . __('Medium') . "</label> 316 <input type='radio' name='attachments[$post->ID][image-size]' id='image-size-full-$post->ID' value='full' /> 317 <label for='image-size-full-$post->ID'>" . __('Full size') . "</label>", 318 ); 550 319 } 551 320 return $form_fields; … … 582 351 $align = 'none'; 583 352 584 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel); 353 if ( !empty($attachment['image-size']) ) 354 $size = $attachment['image-size']; 355 else 356 $size = 'medium'; 357 358 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size); 585 359 } 586 360 … … 604 378 ), 605 379 'post_excerpt' => array( 606 'label' => __(' Excerpt'),380 'label' => __('Description'), 607 381 'value' => $edit_post->post_excerpt, 608 382 ), 609 383 'post_content' => array( 610 'label' => __(' Description'),384 'label' => __('Long description'), 611 385 'value' => $edit_post->post_content, 612 386 'input' => 'textarea', … … 638 412 // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing ) 639 413 $form_fields = array_merge_recursive($form_fields, (array) $errors); 640 414 641 415 $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post); 642 416 … … 645 419 646 420 function get_multimedia_item( $attachment_id, $errors = null, $send = true ) { 647 $thumb_url = wp_get_attachment_thumb_url( $attachment_id ); 648 if ( empty($thumb_url) ) 649 $thumb_url = wp_mime_type_icon( $attachment_id ); 650 if ( empty($thumb_url) && ( $post =& get_post( $attachment_id ) ) && substr($post->post_mime_type, 0, 5) == 'image' ) 651 $thumb_url = wp_get_attachment_url( $attachment_id ); 421 $thumb_url = array_shift(get_attachment_icon_src( $attachment_id )); 652 422 653 423 $title_label = __('Title'); … … 655 425 $tags_label = __('Tags'); 656 426 657 $toggle_on = __(' Describe');658 $toggle_off = __(' Describe «');427 $toggle_on = __('Show'); 428 $toggle_off = __('Hide'); 659 429 660 430 $post = get_post($attachment_id); … … 698 468 699 469 if ( empty($form_fields['save']) && empty($form_fields['_send']) ) { 700 $form_fields['save'] = array('tr' => "\t\t<tr class='submit'><td colspan='2' class='del'><a id='del[$attachment_id]' class='delete ' href='$delete_href'>$delete</a></td><td class='savesend'>$save$send</td></tr>\n");470 $form_fields['save'] = array('tr' => "\t\t<tr class='submit'><td colspan='2' class='del'><a id='del[$attachment_id]' class='delete button' href='$delete_href'>$delete</a></td><td class='savesend'>$save$send</td></tr>\n"); 701 471 } elseif ( empty($form_fields['save']) ) { 702 472 $form_fields['save'] = array('tr' => "\t\t<tr class='submit'><td></td><td></td><td class='savesend'>$save</td></tr>\n"); 703 473 foreach ( $form_fields['_send'] as $id => $field ) 704 474 $form_fields[$id] = $field; 705 $form_fields['send'] = array('tr' => "\t\t<tr class='submit'><td colspan='2' class='del'><a id='del[$attachment_id]' class='delete ' href='$delete_href'>$delete</a></td><td class='savesend'>$send</td>");475 $form_fields['send'] = array('tr' => "\t\t<tr class='submit'><td colspan='2' class='del'><a id='del[$attachment_id]' class='delete button' href='$delete_href'>$delete</a></td><td class='savesend'>$send</td>"); 706 476 } 707 477 … … 774 544 ?> 775 545 <div id="media-upload-header"> 776 <h3><?php _e('Add Images'); ?></h3> 546 <h3><?php _e('Add Media'); ?></h3> 547 <?php the_image_upload_tabs(); ?> 777 548 </div> 778 <div id="media-upload-error"> 549 550 <div id="media-upload-error"> 779 551 <?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?> 780 552 <?php echo $errors['upload_error']->get_error_message(); ?> 781 553 <?php } ?> 782 554 </div> 783 555 <script type="text/javascript"> 784 556 <!-- … … 796 568 swfupload_element_id : "flash-upload-ui", // id of the element displayed when swfupload is available 797 569 degraded_element_id : "html-upload-ui", // when swfupload is unavailable 798 swfupload_loaded_handler : uploadLoadedMultimedia, 799 //upload_start_handler : uploadStart, 800 upload_progress_handler : uploadProgressMultimedia, 801 //upload_error_handler : uploadError, 802 upload_success_handler : uploadSuccessMultimedia, 803 upload_complete_handler : uploadCompleteMultimedia, 570 swfupload_loaded_handler : uploadLoaded, 804 571 file_dialog_start_handler : fileDialogStart, 805 file_queued_handler : fileQueuedMultimedia, 572 file_queued_handler : fileQueued, 573 upload_start_handler : uploadStart, 574 upload_progress_handler : uploadProgress, 575 upload_error_handler : uploadError, 576 upload_success_handler : uploadSuccess, 577 upload_complete_handler : uploadComplete, 806 578 file_queue_error_handler : fileQueueError, 807 579 file_dialog_complete_handler : fileDialogComplete, … … 811 583 $("#flash-browse-button").bind( "click", function(){swfu.selectFiles();}); 812 584 var preloaded = $(".multimedia-item.preloaded"); 813 if ( preloaded ) {585 if ( preloaded.length > 0 ) { 814 586 jQuery('#insert-multimedia').attr('disabled', ''); 815 preloaded.each(function(){uploadSuccessMultimedia({id:this.id.replace(/[^0-9]/g, '')},'');}); 816 } 817 $("a.delete").bind('click',function(){$.ajax({url:'admin-ajax.php',type:'post',data:{id:this.id.replace(/del/,''),action:'delete-post',_ajax_nonce:this.href.replace(/^.*wpnonce=/,'')}});$(this).parents(".multimedia-item").eq(0).slideToggle(300, function(){$(this).remove();});return false;}); 587 preloaded.each(function(){uploadSuccess({id:this.id.replace(/[^0-9]/g, '')},'');}); 588 } 818 589 }); 819 590 //--> 820 591 </script> 821 <p id="flash-upload-ui" style="display:none">822 <input id="flash-browse-button" type="button" value="<?php _e('Choose Files'); ?>" />823 <label for="image-file" class="form-help"><?php _e('Only PNG, JPG, GIF'); ?></label>824 </p>825 592 826 593 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form"> 594 595 <div id="flash-upload-ui"> 596 <p><input id="flash-browse-button" type="button" value="<?php _e('Choose files to upload'); ?>" class="button" /></p> 597 <p><?php _e('As each upload completes, you can add titles and descriptions below.'); ?></p> 598 </div> 827 599 828 600 <div id="html-upload-ui"> … … 839 611 </div> 840 612 841 842 843 613 <div id="multimedia-items"> 844 614 … … 848 618 849 619 <p class="submit"> 850 <a href="#" onClick="return top.tb_remove();" id="image-cancel" class="button-cancel"><?php _e('Cancel'); ?></a> 851 <input type="submit" class="submit" id="insert-multimedia" name="insert-multimedia" value="<?php _e('Insert gallery into post'); ?>" disabled="disabled" /> 620 <input type="submit" class="submit insert-gallery" name="insert-multimedia" value="<?php _e('Insert gallery into post'); ?>" /> 852 621 </p> 853 622 … … 863 632 add_filter('media_upload_multimedia', 'multimedia_upload_handler'); 864 633 634 865 635 // Any 'attachment' taxonomy will be included in the description input form for the multi uploader 866 636 // Example: 637 /* 867 638 register_taxonomy( 868 //869 639 'image_people', 870 640 'attachment:image', 871 641 array( 872 642 'label' => __('People'), 873 'template' => __('People: %s'), 643 'template' => __('People: %l'), 644 'helps' => __('Left to right, top to bottom.'), 874 645 'sort' => true, 875 646 'args' => array( … … 878 649 ) 879 650 ); 651 */ 652 /* 653 register_taxonomy('movie_director', 'attachment:video', array('label'=>__('Directors'), 'template'=>__('Directed by %l.'))); 654 register_taxonomy('movie_producer', 'attachment:video', array('label'=>__('Producers'), 'template'=>__('Produced by %l.'))); 655 register_taxonomy('movie_screenwriter', 'attachment:video', array('label'=>__('Screenwriter'), 'template'=>__('Screenplay by %l.'))); 656 register_taxonomy('movie_actor', 'attachment:video', array('label'=>__('Cast'), 'template'=>array(__('Cast: %l.'))); 657 register_taxonomy('movie_crew', 'attachment:video', array('label'=>__('Crew'), 'template'=>array(__('Crew: %l.'))); 658 */ 880 659 881 660 ?>
Note: See TracChangeset
for help on using the changeset viewer.