Ticket #19840: 19840.9.diff
File 19840.9.diff, 15.2 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/post.php
1152 1152 if ( empty( $post_id ) ) 1153 1153 $post_id = $post_ID; 1154 1154 1155 $set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__( 'Set featured image' ) . '" href="' . esc_url( get_upload_iframe_src( 'image', $post_id) ) . '" id="set-post-thumbnail" class="thickbox">%s</a></p>';1155 $set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__( 'Set featured image' ) . '" href="' . esc_url( get_upload_iframe_src( array( 'type'=>'image', 'post_id'=>$post_id ) ) ) . '" id="set-post-thumbnail" class="thickbox">%s</a></p>'; 1156 1156 $content = sprintf($set_thumbnail_link, esc_html__( 'Set featured image' )); 1157 1157 1158 1158 if ( $thumbnail_id && get_post( $thumbnail_id ) ) { -
wp-admin/includes/media.php
392 392 return "<a href='" . esc_url( get_upload_iframe_src($type) ) . "' id='{$id}-add_{$type}' class='thickbox add_$type' title='" . esc_attr( $title ) . "'><img src='" . esc_url( admin_url( $icon ) ) . "' alt='$title' onclick='return false;' /></a>"; 393 393 } 394 394 395 function get_upload_iframe_src( $ type = null, $post_id = null) {395 function get_upload_iframe_src( $args = array() ) { 396 396 global $post_ID; 397 397 398 if ( empty( $post_id ) ) 399 $post_id = $post_ID; 398 $defaults = array( 'type' => '', 'post_id' => $post_ID ); 399 // Backwards compat for first parameter being type 400 if ( is_string( $args ) ) 401 $args = array( 402 'type' => $args, 403 'post_id'=> $post_ID 404 ); 400 405 401 $uploading_iframe_ID = (int) $post_id; 402 $upload_iframe_src = add_query_arg( 'post_id', $uploading_iframe_ID, admin_url('media-upload.php') ); 406 $args = wp_parse_args( $args, $defaults ); 403 407 404 if ( $type && 'media' != $type ) 405 $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); 408 $upload_iframe_src = add_query_arg( 'post_id', (int) $args['post_id'], admin_url('media-upload.php') ); 406 409 407 $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src); 410 if ( $args['type'] && 'media' != $args['type'] ) 411 $upload_iframe_src = add_query_arg('type', $args['type'], $upload_iframe_src); 408 412 413 if ( ! empty( $args['tab'] ) ) 414 $upload_iframe_src = add_query_arg('tab', $args['tab'], $upload_iframe_src); 415 416 $upload_iframe_src = apply_filters($args['type'] . '_upload_iframe_src', $upload_iframe_src); 417 409 418 return add_query_arg('TB_iframe', true, $upload_iframe_src); 410 419 } 411 420 … … 486 495 if ( isset($send_id) ) { 487 496 $attachment = stripslashes_deep( $_POST['attachments'][$send_id] ); 488 497 489 $html = $attachment['post_title'];498 $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; 490 499 if ( !empty($attachment['url']) ) { 491 500 $rel = ''; 492 501 if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] ) -
wp-admin/js/custom-background.dev.js
10 10 jQuery('#clearcolor').hide(); 11 11 } 12 12 13 function send_to_editor( data ) { 14 data = jQuery.parseJSON(data); 15 jQuery.post(ajaxurl, { action: 'set-background-image', attachment_id: data.id, size: data.size }, function(){ 16 tb_remove(); 17 window.location.reload(); 18 }); 19 } 20 13 21 jQuery(document).ready(function() { 14 22 jQuery('#pickcolor').click(function() { 15 23 jQuery('#colorPickerDiv').show(); -
wp-admin/custom-header.php
90 90 add_action("admin_head-$page", array(&$this, 'take_action'), 50); 91 91 add_action("admin_head-$page", array(&$this, 'js'), 50); 92 92 add_action("admin_head-$page", $this->admin_header_callback, 51); 93 94 add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 ); 95 add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) ); 96 add_filter( 'media_send_to_editor', array( $this, 'image_send_to_editor' ), 1, 2 ); 93 97 } 94 98 95 99 /** … … 140 144 function js_includes() { 141 145 $step = $this->step(); 142 146 143 if ( 1 == $step ) 144 wp_enqueue_script('jquery-masonry'); 145 if ( ( 1 == $step || 3 == $step ) && $this->header_text() ) 146 wp_enqueue_script('farbtastic'); 147 elseif ( 2 == $step ) 148 wp_enqueue_script('imgareaselect'); 147 if ( ( 1 == $step || 3 == $step ) ) { 148 add_thickbox(); 149 wp_enqueue_script('media-upload'); 150 if ( $this->header_text() ) 151 wp_enqueue_script('farbtastic'); 152 if ( 1 == $step ) 153 wp_enqueue_script('jquery-masonry'); 154 } elseif ( 2 == $step ) { 155 wp_enqueue_script('imgareaselect'); 156 } 149 157 } 150 158 151 159 /** … … 327 335 */ 328 336 function js() { 329 337 $step = $this->step(); 330 if ( ( 1 == $step || 3 == $step ) && $this->header_text() ) 331 $this->js_1(); 332 elseif ( 2 == $step ) 338 if ( ( 1 == $step || 3 == $step ) ) { 339 $this->js_0(); 340 if ( $this->header_text() ) 341 $this->js_1(); 342 } elseif ( 2 == $step ) { 333 343 $this->js_2(); 344 } 334 345 } 335 346 336 347 /** … … 338 349 * 339 350 * @since 2.6.0 340 351 */ 352 function js_0() { ?> 353 <script type="text/javascript"> 354 /* <![CDATA[ */ 355 step2_url = '<?php echo add_query_arg( array( 'page' => 'custom-header', 'step' => 2, '_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload') ), admin_url('themes.php') ); ?>'; 356 function send_to_editor( file_id ) { 357 window.location = step2_url + '&file=' + file_id; 358 } 359 /* ]]> */ 360 </script> 361 <?php 362 } 363 364 /** 365 * Display Javascript based on Step 1 and 3 if header text is active. 366 * 367 * @since 2.6.0 368 */ 341 369 function js_1() { ?> 342 370 <script type="text/javascript"> 343 371 /* <![CDATA[ */ … … 583 611 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> 584 612 </p> 585 613 </form> 614 <?php 615 $image_library_url = get_upload_iframe_src( array( 'type' => 'image', 'tab' => 'library' ) ); 616 $image_library_url = remove_query_arg( 'TB_iframe', $image_library_url ); 617 $image_library_url = add_query_arg( array( 'context' => 'custom-header', 'TB_iframe' => 1 ), $image_library_url ); 618 ?> 619 <span class="howto"><?php _ex( 'or', 'Custom Header: Choose an image from your computer - or - Choose from image library' ); ?></span> <a class="thickbox" href="<?php echo $image_library_url; ?>"><?php _e( 'Choose from image library' ); ?></a> 586 620 </td> 587 621 </tr> 588 622 <?php endif; ?> … … 706 740 if ( ! current_theme_supports( 'custom-header-uploads' ) ) 707 741 wp_die( __( 'Cheatin’ uh?' ) ); 708 742 709 $overrides = array('test_form' => false); 710 $file = wp_handle_upload($_FILES['import'], $overrides); 743 if ( empty( $_POST ) && isset( $_GET['file'] ) ) { 744 $id = absint( $_GET['file'] ); 745 $file = get_attached_file( $id, true ); 746 $url = wp_get_attachment_image_src( $id, 'full'); 747 $url = $url[0]; 748 } else if ( isset( $_POST ) ) { 749 extract($this->step_2_manage_upload()); 750 } 711 751 712 if ( isset($file['error']) )713 wp_die( $file['error'], __( 'Image Upload Error' ) );714 715 $url = $file['url'];716 $type = $file['type'];717 $file = $file['file'];718 $filename = basename($file);719 720 // Construct the object array721 $object = array(722 'post_title' => $filename,723 'post_content' => $url,724 'post_mime_type' => $type,725 'guid' => $url,726 'context' => 'custom-header'727 );728 729 // Save the data730 $id = wp_insert_attachment($object, $file);731 732 752 list($width, $height, $type, $attr) = getimagesize( $file ); 733 753 734 754 $header_support = get_theme_support( 'custom-header' ); … … 785 805 <input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>"/> 786 806 <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $id ); ?>" /> 787 807 <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" /> 808 <?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?> 809 <input type="hidden" name="new-attachment" value="true" /> 810 <?php } ?> 788 811 <?php wp_nonce_field( 'custom-header-crop-image' ) ?> 789 812 790 813 <?php submit_button( __( 'Crop and Publish' ) ); ?> … … 794 817 <?php 795 818 } 796 819 820 821 function step_2_manage_upload() { 822 $overrides = array('test_form' => false); 823 $file = wp_handle_upload($_FILES['import'], $overrides); 824 825 if ( isset($file['error']) ) 826 wp_die( $file['error'], __( 'Image Upload Error' ) ); 827 828 $url = $file['url']; 829 $type = $file['type']; 830 $file = $file['file']; 831 $filename = basename($file); 832 833 // Construct the object array 834 $object = array( 835 'post_title' => $filename, 836 'post_content' => $url, 837 'post_mime_type' => $type, 838 'guid' => $url, 839 'context' => 'custom-header' 840 ); 841 842 // Save the data 843 $id = wp_insert_attachment( $object, $file ); 844 return compact( 'id', 'file', 'filename', 'url', 'type' ); 845 } 846 797 847 /** 798 848 * Display third step of custom header image page. 799 849 * … … 859 909 'guid' => $url, 860 910 'context' => 'custom-header' 861 911 ); 912 if ( isset( $_POST['new-attachment'] ) && $_POST['new-attachment'] ) 913 unset($object['ID']); 862 914 863 915 // Update the attachment 864 wp_insert_attachment($object, $cropped);916 $attachment_id = wp_insert_attachment( $object, $cropped ); 865 917 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) ); 866 918 update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); 867 919 … … 878 930 879 931 // cleanup 880 932 $medium = str_replace(basename($original), 'midsize-'.basename($original), $original); 881 @unlink( apply_filters( 'wp_delete_file', $medium ) ); 882 @unlink( apply_filters( 'wp_delete_file', $original ) ); 933 if ( file_exists( $medium ) ) 934 @unlink( apply_filters( 'wp_delete_file', $medium ) ); 935 if ( empty ( $_POST['new-attachment'] ) ) 936 @unlink( apply_filters( 'wp_delete_file', $original ) ); 883 937 884 938 return $this->finished(); 885 939 } … … 911 965 $this->step_3(); 912 966 } 913 967 968 function attachment_fields_to_edit( $form_fields, $post ) { 969 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) { 970 $form_fields = array(); // Reset 971 $button = get_submit_button( __( 'Use as header image' ), 'button', "send[{$post->ID}]", false ); 972 $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td>'.$button.'</td></tr>' ); 973 $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-header' ); 974 } 975 976 return $form_fields; 977 } 978 979 function image_send_to_editor( $html, $id ) { 980 if ( isset( $_REQUEST['attachments'][$id]['context'] ) && $_REQUEST['attachments'][$id]['context'] == 'custom-header' ) { 981 remove_filter( 'media_send_to_editor', 'image_media_send_to_editor', 10, 3 ); 982 return $id; 983 } 984 985 return $html; 986 } 987 988 function filter_upload_tabs( $tabs ) { 989 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) 990 return array( 'library' => __('Media Library') ); 991 992 return $tabs; 993 } 994 914 995 } -
wp-admin/custom-background.php
53 53 function __construct($admin_header_callback = '', $admin_image_div_callback = '') { 54 54 $this->admin_header_callback = $admin_header_callback; 55 55 $this->admin_image_div_callback = $admin_image_div_callback; 56 add_action( 'wp_ajax_set-background-image', array( $this, 'wp_set_background_image' ) ); 56 57 } 57 58 58 59 /** … … 69 70 add_action("load-$page", array(&$this, 'admin_load')); 70 71 add_action("load-$page", array(&$this, 'take_action'), 49); 71 72 add_action("load-$page", array(&$this, 'handle_upload'), 49); 73 add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 ); 74 add_filter( 'media_send_to_editor', array( $this, 'image_send_to_editor' ), 1, 3 ); 75 add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) ); 72 76 73 77 if ( $this->admin_header_callback ) 74 78 add_action("admin_head-$page", $this->admin_header_callback, 51); … … 96 100 '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' 97 101 ); 98 102 103 add_thickbox(); 104 wp_enqueue_script('media-upload'); 99 105 wp_enqueue_script('custom-background'); 100 106 wp_enqueue_style('farbtastic'); 101 107 } … … 246 252 <input type="hidden" name="action" value="save" /> 247 253 <?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?> 248 254 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> 249 </form> 255 <?php 256 $image_library_url = get_upload_iframe_src( array( 'type' => 'image', 'tab' => 'library' ) ); 257 $image_library_url = remove_query_arg( 'TB_iframe', $image_library_url ); 258 $image_library_url = add_query_arg( array( 'context' => 'custom-background', 'TB_iframe' => 1 ), $image_library_url ); 259 ?> 260 </form> 261 <span class="howto"><?php _ex( 'or', 'Custom Background: Choose an image from your computer - or - Choose from image library' ); ?></span> <a class="thickbox" href="<?php echo $image_library_url; ?>"><?php _e( 'Choose from image library' ); ?></a> 250 262 </td> 251 263 </tr> 252 264 </tbody> … … 366 378 $this->updated = true; 367 379 } 368 380 381 function attachment_fields_to_edit( $form_fields, $post ) { 382 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) { 383 $form_fields = array( 'image-size' => $form_fields['image-size'] ); // Reset 384 $button = get_submit_button( __( 'Use as background image' ), 'button', "send[{$post->ID}]", false ); 385 $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td>'.$button.'</td></tr>' ); 386 $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' ); 387 } 388 389 return $form_fields; 390 } 391 392 function image_send_to_editor( $html, $id, $size ) { 393 if ( isset( $_REQUEST['attachments'][$id]['context'] ) && $_REQUEST['attachments'][$id]['context'] == 'custom-background' ) { 394 remove_filter( 'media_send_to_editor', 'image_media_send_to_editor', 10, 3 ); 395 return json_encode( array( 'id' => $id, 'size' => $size['image-size'] ) ); 396 } 397 398 return $html; 399 } 400 401 function filter_upload_tabs ( $tabs ){ 402 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) 403 return array( 'library' => __('Media Library') ); 404 405 return $tabs; 406 } 407 408 public function wp_set_background_image() { 409 if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit; 410 $attachment_id = absint($_POST['attachment_id']); 411 $sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) )); 412 $size = 'thumbnail'; 413 if ( in_array( $_POST['size'], $sizes ) ) 414 $size = esc_attr( $_POST['size'] ); 415 416 update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); 417 $url = wp_get_attachment_image_src( $attachment_id, $size ); 418 $thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' ); 419 set_theme_mod( 'background_image', esc_url( $url[0] ) ); 420 set_theme_mod( 'background_image_thumb', esc_url( $thumbnail[0] ) ); 421 exit; 422 } 369 423 }