Ticket #19840: 19840.7.diff
File 19840.7.diff, 15.0 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' => '' ); 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 || 3 == $step ) && $this->header_text() ) 144 wp_enqueue_script('farbtastic'); 145 elseif ( 2 == $step ) 147 if ( ( 1 == $step || 3 == $step ) ) { 148 add_thickbox(); 149 if ( $this->header_text() ) 150 wp_enqueue_script('farbtastic'); 151 } elseif ( 2 == $step ) { 146 152 wp_enqueue_script('imgareaselect'); 153 } 147 154 } 148 155 149 156 /** … … 325 332 */ 326 333 function js() { 327 334 $step = $this->step(); 328 if ( ( 1 == $step || 3 == $step ) && $this->header_text() ) 329 $this->js_1(); 330 elseif ( 2 == $step ) 335 if ( ( 1 == $step || 3 == $step ) ) { 336 $this->js_0(); 337 if ( $this->header_text() ) 338 $this->js_1(); 339 } elseif ( 2 == $step ) { 331 340 $this->js_2(); 341 } 332 342 } 333 343 334 344 /** … … 336 346 * 337 347 * @since 2.6.0 338 348 */ 349 function js_0() { ?> 350 <script type="text/javascript"> 351 /* <![CDATA[ */ 352 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') ); ?>'; 353 function send_to_editor( file_id ) { 354 window.location = step2_url + '&file=' + file_id; 355 } 356 /* ]]> */ 357 </script> 358 <?php 359 } 360 361 /** 362 * Display Javascript based on Step 1 and 3 if header text is active. 363 * 364 * @since 2.6.0 365 */ 339 366 function js_1() { ?> 340 367 <script type="text/javascript"> 341 368 /* <![CDATA[ */ … … 581 608 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> 582 609 </p> 583 610 </form> 611 <?php 612 $image_library_url = get_upload_iframe_src( array( 'type' => 'image', 'tab' => 'library' ) ); 613 $image_library_url = remove_query_arg( 'TB_iframe', $image_library_url ); 614 $image_library_url = add_query_arg( array( 'context' => 'custom-header', 'TB_iframe' => 1 ), $image_library_url ); 615 ?> 616 <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> 584 617 </td> 585 618 </tr> 586 619 <?php endif; ?> … … 698 731 if ( ! current_theme_supports( 'custom-header-uploads' ) ) 699 732 wp_die( __( 'Cheatin’ uh?' ) ); 700 733 701 $overrides = array('test_form' => false); 702 $file = wp_handle_upload($_FILES['import'], $overrides); 734 if ( empty( $_POST ) && isset( $_GET['file'] ) ) { 735 $id = absint( $_GET['file'] ); 736 $file = get_attached_file( $id, true ); 737 $url = wp_get_attachment_image_src( $id, 'full'); 738 $url = $url[0]; 739 } else if ( isset( $_POST ) ) { 740 extract($this->step_2_manage_upload()); 741 } 703 742 704 if ( isset($file['error']) )705 wp_die( $file['error'], __( 'Image Upload Error' ) );706 707 $url = $file['url'];708 $type = $file['type'];709 $file = $file['file'];710 $filename = basename($file);711 712 // Construct the object array713 $object = array(714 'post_title' => $filename,715 'post_content' => $url,716 'post_mime_type' => $type,717 'guid' => $url,718 'context' => 'custom-header'719 );720 721 // Save the data722 $id = wp_insert_attachment($object, $file);723 724 743 list($width, $height, $type, $attr) = getimagesize( $file ); 725 744 726 745 $header_support = get_theme_support( 'custom-header' ); … … 777 796 <input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>"/> 778 797 <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $id ); ?>" /> 779 798 <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" /> 799 <?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?> 800 <input type="hidden" name="new-attachment" value="true" /> 801 <?php } ?> 780 802 <?php wp_nonce_field( 'custom-header-crop-image' ) ?> 781 803 782 804 <?php submit_button( __( 'Crop and Publish' ) ); ?> … … 786 808 <?php 787 809 } 788 810 811 812 function step_2_manage_upload() { 813 $overrides = array('test_form' => false); 814 $file = wp_handle_upload($_FILES['import'], $overrides); 815 816 if ( isset($file['error']) ) 817 wp_die( $file['error'], __( 'Image Upload Error' ) ); 818 819 $url = $file['url']; 820 $type = $file['type']; 821 $file = $file['file']; 822 $filename = basename($file); 823 824 // Construct the object array 825 $object = array( 826 'post_title' => $filename, 827 'post_content' => $url, 828 'post_mime_type' => $type, 829 'guid' => $url, 830 'context' => 'custom-header' 831 ); 832 833 // Save the data 834 $id = wp_insert_attachment( $object, $file ); 835 return compact( 'id', 'file', 'filename', 'url', 'type' ); 836 } 837 789 838 /** 790 839 * Display third step of custom header image page. 791 840 * … … 851 900 'guid' => $url, 852 901 'context' => 'custom-header' 853 902 ); 903 if ( isset( $_POST['new-attachment'] ) && $_POST['new-attachment'] ) 904 unset($object['ID']); 854 905 855 906 // Update the attachment 856 wp_insert_attachment($object, $cropped);907 $attachment_id = wp_insert_attachment( $object, $cropped ); 857 908 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) ); 858 909 update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); 859 910 … … 870 921 871 922 // cleanup 872 923 $medium = str_replace(basename($original), 'midsize-'.basename($original), $original); 873 @unlink( apply_filters( 'wp_delete_file', $medium ) ); 874 @unlink( apply_filters( 'wp_delete_file', $original ) ); 924 if ( file_exists( $medium ) ) 925 @unlink( apply_filters( 'wp_delete_file', $medium ) ); 926 if ( empty ( $_POST['new-attachment'] ) ) 927 @unlink( apply_filters( 'wp_delete_file', $original ) ); 875 928 876 929 return $this->finished(); 877 930 } … … 903 956 $this->step_3(); 904 957 } 905 958 959 function attachment_fields_to_edit( $form_fields, $post ) { 960 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) { 961 $form_fields = array(); // Reset 962 $button = get_submit_button( __( 'Use as header image' ), 'button', "send[{$post->ID}]", false ); 963 $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td>'.$button.'</td></tr>' ); 964 $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-header' ); 965 } 966 967 return $form_fields; 968 } 969 970 function image_send_to_editor( $html, $id ) { 971 if ( isset( $_REQUEST['attachments'][$id]['context'] ) && $_REQUEST['attachments'][$id]['context'] == 'custom-header' ) { 972 remove_filter( 'media_send_to_editor', 'image_media_send_to_editor', 10, 3 ); 973 return $id; 974 } 975 976 return $html; 977 } 978 979 function filter_upload_tabs( $tabs ) { 980 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) 981 return array( 'library' => __('Media Library') ); 982 983 return $tabs; 984 } 985 906 986 } -
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 }