Ticket #19840: 19840.5.diff
File 19840.5.diff, 14.1 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/media.php
386 386 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>"; 387 387 } 388 388 389 function get_upload_iframe_src( $ type = null) {389 function get_upload_iframe_src( $args = array() ) { 390 390 global $post_ID; 391 $defaults = array( 'type' => '' ); 392 // Backwards compat for first parameter being type 393 if ( is_string( $args ) ) 394 $args = array( 'type' => $args ); 391 395 396 $args = wp_parse_args( $args, $defaults ); 397 392 398 $uploading_iframe_ID = (int) $post_ID; 393 399 $upload_iframe_src = add_query_arg( 'post_id', $uploading_iframe_ID, admin_url('media-upload.php') ); 394 400 395 if ( $ type && 'media' != $type)396 $upload_iframe_src = add_query_arg('type', $ type, $upload_iframe_src);401 if ( $args['type'] && 'media' != $args['type'] ) 402 $upload_iframe_src = add_query_arg('type', $args['type'], $upload_iframe_src); 397 403 398 $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src); 404 if ( isset($args['tab']) && $args['tab'] ) 405 $upload_iframe_src = add_query_arg('tab', $args['tab'], $upload_iframe_src); 399 406 407 $upload_iframe_src = apply_filters($args['type'] . '_upload_iframe_src', $upload_iframe_src); 408 400 409 return add_query_arg('TB_iframe', true, $upload_iframe_src); 401 410 } 402 411 … … 477 486 if ( isset($send_id) ) { 478 487 $attachment = stripslashes_deep( $_POST['attachments'][$send_id] ); 479 488 480 $html = $attachment['post_title'];489 $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; 481 490 if ( !empty($attachment['url']) ) { 482 491 $rel = ''; 483 492 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 906 } 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 //exit; # Note: Uncomment this line to check if any php notices are thrown. 974 return $id; 975 } 976 977 return $html; 978 } 979 980 function filter_upload_tabs( $tabs ) { 981 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) 982 return array( 'library' => __('Media Library') ); 983 984 return $tabs; 985 } 986 987 } 988 No newline at end of file -
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 369 } 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 // exit; # Note: Uncomment this line to check if any php notices are thrown. 396 return json_encode( array( 'id' => $id, 'size' => $size['image-size'] ) ); 397 } 398 399 return $html; 400 } 401 402 function filter_upload_tabs ( $tabs ){ 403 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) 404 return array( 'library' => __('Media Library') ); 405 406 return $tabs; 407 } 408 409 public function wp_set_background_image() { 410 if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit; 411 $attachment_id = absint($_POST['attachment_id']); 412 $sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) )); 413 $size = 'thumbnail'; 414 if ( in_array( $_POST['size'], $sizes ) ) 415 $size = esc_attr( $_POST['size'] ); 416 417 update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); 418 $url = wp_get_attachment_image_src($attachment_id, $size); 419 $thumbnail = wp_get_attachment_image_src($attachment_id, 'thumbnail'); 420 set_theme_mod('background_image', esc_url($url[0])); 421 set_theme_mod('background_image_thumb', esc_url($thumbnail[0])); 422 exit; 423 } 424 } 425 No newline at end of file