Ticket #19840: 19840.11.diff
File 19840.11.diff, 14.0 KB (added by , 13 years ago) |
---|
-
wp-admin/js/set-post-thumbnail.dev.js
5 5 jQuery.post(ajaxurl, { 6 6 action:"set-post-thumbnail", post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie) 7 7 }, function(str){ 8 var win = window.dialogArguments || opener || parent || top;8 var win = GetParentWindow(); 9 9 $link.text( setPostThumbnailL10n.setThumbnail ); 10 10 if ( str == '0' ) { 11 11 alert( setPostThumbnailL10n.error ); … … 19 19 } 20 20 ); 21 21 } 22 23 function WPSetAsBackground(id){ 24 jQuery.post(ajaxurl, { 25 action: 'set-background-image', 26 attachment_id: id, 27 size: jQuery('input[name="attachments[' + id + '][image-size]"]').filter(':checked').val() 28 }, function(){ 29 tb_remove(); 30 GetParentWindow().location.reload(); 31 }); 32 } 33 34 function GetParentWindow() { 35 return ( window.dialogArguments || opener || parent || top ); 36 } -
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
401 401 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>"; 402 402 } 403 403 404 function get_upload_iframe_src( $ type = null, $post_id = null) {404 function get_upload_iframe_src( $args = array() ) { 405 405 global $post_ID; 406 406 407 if ( empty( $post_id ) ) 408 $post_id = $post_ID; 407 $defaults = array( 'type' => '', 'post_id' => $post_ID ); 408 // Backwards compat for first parameter being type 409 if ( is_string( $args ) ) 410 $args = array( 411 'type' => $args, 412 'post_id'=> $post_ID 413 ); 409 414 410 $uploading_iframe_ID = (int) $post_id; 411 $upload_iframe_src = add_query_arg( 'post_id', $uploading_iframe_ID, admin_url('media-upload.php') ); 415 $args = wp_parse_args( $args, $defaults ); 412 416 413 if ( $type && 'media' != $type ) 414 $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); 417 $upload_iframe_src = add_query_arg( 'post_id', (int) $args['post_id'], admin_url('media-upload.php') ); 415 418 416 $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src); 419 if ( $args['type'] && 'media' != $args['type'] ) 420 $upload_iframe_src = add_query_arg('type', $args['type'], $upload_iframe_src); 417 421 422 if ( ! empty( $args['tab'] ) ) 423 $upload_iframe_src = add_query_arg('tab', $args['tab'], $upload_iframe_src); 424 425 $upload_iframe_src = apply_filters($args['type'] . '_upload_iframe_src', $upload_iframe_src); 426 418 427 return add_query_arg('TB_iframe', true, $upload_iframe_src); 419 428 } 420 429 … … 495 504 if ( isset($send_id) ) { 496 505 $attachment = stripslashes_deep( $_POST['attachments'][$send_id] ); 497 506 498 $html = $attachment['post_title'];507 $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; 499 508 if ( !empty($attachment['url']) ) { 500 509 $rel = ''; 501 510 if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] ) -
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' ) ); 93 96 } 94 97 95 98 /** … … 140 143 function js_includes() { 141 144 $step = $this->step(); 142 145 143 if ( 1 == $step ) 146 if ( ( 1 == $step || 3 == $step ) ) { 147 add_thickbox(); 148 wp_enqueue_script('media-upload'); 144 149 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'); 150 151 if ( $this->header_text() ) 152 wp_enqueue_script('farbtastic'); 153 } elseif ( 2 == $step ) { 154 wp_enqueue_script('imgareaselect'); 155 } 149 156 } 150 157 151 158 /** … … 583 590 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> 584 591 </p> 585 592 </form> 593 <?php 594 $image_library_url = get_upload_iframe_src( array( 'type' => 'image', 'tab' => 'library' ) ); 595 $image_library_url = remove_query_arg( 'TB_iframe', $image_library_url ); 596 $image_library_url = add_query_arg( array( 'context' => 'custom-header', 'TB_iframe' => 1 ), $image_library_url ); 597 ?> 598 <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 599 </td> 587 600 </tr> 588 601 <?php endif; ?> … … 706 719 if ( ! current_theme_supports( 'custom-header-uploads' ) ) 707 720 wp_die( __( 'Cheatin’ uh?' ) ); 708 721 709 $overrides = array('test_form' => false); 710 $file = wp_handle_upload($_FILES['import'], $overrides); 722 if ( empty( $_POST ) && isset( $_GET['file'] ) ) { 723 $id = absint( $_GET['file'] ); 724 $file = get_attached_file( $id, true ); 725 $url = wp_get_attachment_image_src( $id, 'full'); 726 $url = $url[0]; 727 } else if ( isset( $_POST ) ) { 728 extract($this->step_2_manage_upload()); 729 } 711 730 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 731 list($width, $height, $type, $attr) = getimagesize( $file ); 733 732 734 733 $header_support = get_theme_support( 'custom-header' ); … … 785 784 <input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>"/> 786 785 <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $id ); ?>" /> 787 786 <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" /> 787 <?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?> 788 <input type="hidden" name="new-attachment" value="true" /> 789 <?php } ?> 788 790 <?php wp_nonce_field( 'custom-header-crop-image' ) ?> 789 791 790 792 <?php submit_button( __( 'Crop and Publish' ) ); ?> … … 794 796 <?php 795 797 } 796 798 799 800 function step_2_manage_upload() { 801 $overrides = array('test_form' => false); 802 $file = wp_handle_upload($_FILES['import'], $overrides); 803 804 if ( isset($file['error']) ) 805 wp_die( $file['error'], __( 'Image Upload Error' ) ); 806 807 $url = $file['url']; 808 $type = $file['type']; 809 $file = $file['file']; 810 $filename = basename($file); 811 812 // Construct the object array 813 $object = array( 814 'post_title' => $filename, 815 'post_content' => $url, 816 'post_mime_type' => $type, 817 'guid' => $url, 818 'context' => 'custom-header' 819 ); 820 821 // Save the data 822 $id = wp_insert_attachment( $object, $file ); 823 return compact( 'id', 'file', 'filename', 'url', 'type' ); 824 } 825 797 826 /** 798 827 * Display third step of custom header image page. 799 828 * … … 859 888 'guid' => $url, 860 889 'context' => 'custom-header' 861 890 ); 891 if ( isset( $_POST['new-attachment'] ) && $_POST['new-attachment'] ) 892 unset($object['ID']); 862 893 863 894 // Update the attachment 864 wp_insert_attachment($object, $cropped);895 $attachment_id = wp_insert_attachment( $object, $cropped ); 865 896 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) ); 866 897 update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); 867 898 … … 878 909 879 910 // cleanup 880 911 $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 ) ); 912 if ( file_exists( $medium ) ) 913 @unlink( apply_filters( 'wp_delete_file', $medium ) ); 914 if ( empty ( $_POST['new-attachment'] ) ) 915 @unlink( apply_filters( 'wp_delete_file', $original ) ); 883 916 884 917 return $this->finished(); 885 918 } … … 911 944 $this->step_3(); 912 945 } 913 946 947 function attachment_fields_to_edit( $form_fields, $post ) { 948 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) { 949 $form_fields = array(); 950 $href = rawurlencode(add_query_arg(array( 951 'page' => 'custom-header', 952 'step' => 2, 953 '_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'), 954 'file' => $post->ID 955 ), admin_url('themes.php'))); 956 957 $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a href="javascript: GetParentWindow().location.href=\'' . $href . '\';">' . _( 'Set as header' ) . '</a></td></tr>' ); 958 $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-header' ); 959 } 960 961 return $form_fields; 962 } 963 964 function filter_upload_tabs( $tabs ) { 965 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) 966 return array( 'library' => __('Media Library') ); 967 968 return $tabs; 969 } 970 914 971 } -
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_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( array( 'type' => 'image', 'tab' => '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 _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 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'] ); 383 $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a href="javascript: WPSetAsBackground(' . $post->ID . ');">' . _( 'Set as background' ) . '</a></td></tr>' ); 384 $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' ); 385 } 386 387 return $form_fields; 388 } 389 390 function filter_upload_tabs ( $tabs ){ 391 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) 392 return array( 'library' => __('Media Library') ); 393 394 return $tabs; 395 } 396 397 public function wp_set_background_image() { 398 if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit; 399 $attachment_id = absint($_POST['attachment_id']); 400 $sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) )); 401 $size = 'thumbnail'; 402 if ( in_array( $_POST['size'], $sizes ) ) 403 $size = esc_attr( $_POST['size'] ); 404 405 update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); 406 $url = wp_get_attachment_image_src( $attachment_id, $size ); 407 $thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' ); 408 set_theme_mod( 'background_image', esc_url( $url[0] ) ); 409 set_theme_mod( 'background_image_thumb', esc_url( $thumbnail[0] ) ); 410 exit; 411 } 369 412 }