Ticket #19840: v3.diff
File v3.diff, 11.7 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( $type = null, $tab = null ) { 390 390 global $post_ID; 391 391 392 392 $uploading_iframe_ID = (int) $post_ID; … … 395 395 if ( $type && 'media' != $type ) 396 396 $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); 397 397 398 if ( $tab ) 399 $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src); 400 398 401 $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src); 399 402 400 403 return add_query_arg('TB_iframe', true, $upload_iframe_src); -
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('image_send_to_editor', array(&$this, 'image_send_to_editor'), 10, 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() ) 147 if ( ( 1 == $step || 3 == $step ) && $this->header_text() ) { 148 add_thickbox(); 144 149 wp_enqueue_script('farbtastic'); 145 elseif ( 2 == $step )150 } elseif ( 2 == $step ) { 146 151 wp_enqueue_script('imgareaselect'); 152 } 147 153 } 148 154 149 155 /** … … 376 382 } 377 383 } 378 384 385 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') ); ?>'; 386 function send_to_editor( file_id ) { 387 window.location = step2_url + '&file=' + file_id; 388 } 389 379 390 jQuery(document).ready(function() { 380 391 jQuery('#pickcolor').click(function() { 381 392 jQuery('#color-picker').show(); … … 581 592 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> 582 593 </p> 583 594 </form> 595 <?php 596 $image_library_url = get_upload_iframe_src('image', 'library'); 597 $image_library_url = remove_query_arg('TB_iframe', $image_library_url); 598 $image_library_url = add_query_arg( array( 'context' => 'custom-header', 'TB_iframe' => 1 ), $image_library_url ); 599 ?> 600 <span class="howto"><?php _e('or'); ?></span> <a class="thickbox" href="<?php echo $image_library_url; ?>"><?php _e( 'Choose from image library' ); ?></a> 584 601 </td> 585 602 </tr> 586 603 <?php endif; ?> … … 698 715 if ( ! current_theme_supports( 'custom-header-uploads' ) ) 699 716 wp_die( __( 'Cheatin’ uh?' ) ); 700 717 701 $overrides = array('test_form' => false); 702 $file = wp_handle_upload($_FILES['import'], $overrides); 718 if ( empty( $_POST ) && isset( $_GET['file'] ) ) { 719 $id = absint($_GET['file']); 720 $file = get_attached_file( $id, true ); 721 $url = wp_get_attachment_image_src( $id, 'full'); 722 $url = $url[0]; 723 } else if ( isset( $_POST ) ) { 724 extract($this->step_2_manage_upload()); 725 } 703 726 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 727 list($width, $height, $type, $attr) = getimagesize( $file ); 725 728 726 729 $header_support = get_theme_support( 'custom-header' ); … … 777 780 <input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>"/> 778 781 <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $id ); ?>" /> 779 782 <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" /> 783 <?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?> 784 <input type="hidden" name="new-attachment" value="true" /> 785 <?php } ?> 780 786 <?php wp_nonce_field( 'custom-header-crop-image' ) ?> 781 787 782 788 <?php submit_button( __( 'Crop and Publish' ) ); ?> … … 786 792 <?php 787 793 } 788 794 795 796 function step_2_manage_upload() { 797 $overrides = array('test_form' => false); 798 $file = wp_handle_upload($_FILES['import'], $overrides); 799 800 if ( isset($file['error']) ) 801 wp_die( $file['error'], __( 'Image Upload Error' ) ); 802 803 $url = $file['url']; 804 $type = $file['type']; 805 $file = $file['file']; 806 $filename = basename($file); 807 808 // Construct the object array 809 $object = array( 810 'post_title' => $filename, 811 'post_content' => $url, 812 'post_mime_type' => $type, 813 'guid' => $url, 814 'context' => 'custom-header' 815 ); 816 817 // Save the data 818 $id = wp_insert_attachment($object, $file); 819 return compact( 'id', 'file', 'filename', 'url', 'type' ); 820 } 821 789 822 /** 790 823 * Display third step of custom header image page. 791 824 * … … 851 884 'guid' => $url, 852 885 'context' => 'custom-header' 853 886 ); 887 if ( isset( $_POST['new-attachment'] ) && $_POST['new-attachment'] ) 888 unset($object['ID']); 854 889 855 890 // Update the attachment 856 wp_insert_attachment($object, $cropped);891 $attachment_id = wp_insert_attachment($object, $cropped); 857 892 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) ); 858 893 update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); 859 894 … … 870 905 871 906 // cleanup 872 907 $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 ) ); 908 if ( file_exists( $medium ) ) 909 @unlink( apply_filters( 'wp_delete_file', $medium ) ); 910 if ( empty ( $_POST['new-attachment'] ) ) 911 @unlink( apply_filters( 'wp_delete_file', $original ) ); 875 912 876 913 return $this->finished(); 877 914 } … … 903 940 $this->step_3(); 904 941 } 905 942 943 function attachment_fields_to_edit( $form_fields, $post ) { 944 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) { 945 $form_fields = array(); // Reset 946 $button = get_submit_button( __( 'Use as header image' ), 'button', "send[{$post->ID}]", false ); 947 $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td>'.$button.'</td></tr>' ); 948 $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-header' ); 949 } 950 951 return $form_fields; 952 } 953 954 function image_send_to_editor( $html, $id ) { 955 if ( isset( $_REQUEST['attachments'][$id]['context'] ) && $_REQUEST['attachments'][$id]['context'] == 'custom-header' ) 956 return $id; 957 958 return $html; 959 } 960 961 function filter_upload_tabs( $tabs ) { 962 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) 963 return array( 'library' => __('Media Library') ); 964 965 return $tabs; 966 } 967 906 968 } -
wp-admin/custom-background.php
69 69 add_action("load-$page", array(&$this, 'admin_load')); 70 70 add_action("load-$page", array(&$this, 'take_action'), 49); 71 71 add_action("load-$page", array(&$this, 'handle_upload'), 49); 72 add_filter('attachment_fields_to_edit', array(&$this, 'attachment_fields_to_edit'), 10, 2); 73 add_filter('image_send_to_editor', array(&$this, 'image_send_to_editor'), 10, 7); 74 add_filter('media_upload_tabs', array(&$this, 'filter_upload_tabs')); 72 75 73 76 if ( $this->admin_header_callback ) 74 77 add_action("admin_head-$page", $this->admin_header_callback, 51); … … 96 99 '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' 97 100 ); 98 101 102 add_thickbox(); 103 wp_enqueue_script('media-upload'); 99 104 wp_enqueue_script('custom-background'); 100 105 wp_enqueue_style('farbtastic'); 101 106 } … … 246 251 <input type="hidden" name="action" value="save" /> 247 252 <?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?> 248 253 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> 249 </form> 254 <?php 255 $image_library_url = get_upload_iframe_src('image', 'library'); 256 $image_library_url = remove_query_arg('TB_iframe', $image_library_url); 257 $image_library_url = add_query_arg( array( 'context' => 'custom-background', 'TB_iframe' => 1 ), $image_library_url ); 258 ?> 259 </form> 260 <span class="howto"><?php _e('or'); ?></span> <a class="thickbox" href="<?php echo $image_library_url; ?>"><?php _e( 'Choose from image library' ); ?></a> 250 261 </td> 251 262 </tr> 252 263 </tbody> … … 366 377 $this->updated = true; 367 378 } 368 379 380 function attachment_fields_to_edit( $form_fields, $post ) { 381 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) { 382 $form_fields = array( 'image-size' => $form_fields['image-size'] ); // Reset 383 $button = get_submit_button( __( 'Use as background image' ), 'button', "send[{$post->ID}]", false ); 384 $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td>'.$button.'</td></tr>' ); 385 $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' ); 386 } 387 388 return $form_fields; 389 } 390 391 function image_send_to_editor( $html, $id, $caption = '', $title = '', $align = '', $url = '', $size ) { 392 if ( isset( $_REQUEST['attachments'][$id]['context'] ) && $_REQUEST['attachments'][$id]['context'] == 'custom-background' ) 393 return json_encode( array( 'id' => $id, 'size' => $size ) ); 394 395 return $html; 396 } 397 398 function filter_upload_tabs ( $tabs ){ 399 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) 400 return array( 'library' => __('Media Library') ); 401 402 return $tabs; 403 } 369 404 } 405 406 function wp_set_background_image() { 407 if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit; 408 $attachment_id = absint($_POST['attachment_id']); 409 $sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) )); 410 $size = 'thumbnail'; 411 if ( in_array( $_POST['size'], $sizes ) ) 412 $size = esc_attr( $_POST['size'] ); 413 414 update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); 415 $url = wp_get_attachment_image_src($attachment_id, $size); 416 $thumbnail = wp_get_attachment_image_src($attachment_id, 'thumbnail'); 417 set_theme_mod('background_image', esc_url($url[0])); 418 set_theme_mod('background_image_thumb', esc_url($thumbnail[0])); 419 exit; 420 } 421 add_action('wp_ajax_set-background-image', 'wp_set_background_image'); 422 No newline at end of file