Changeset 20358
- Timestamp:
- 04/05/2012 12:20:28 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/custom-background.php
r20212 r20358 56 56 57 57 add_action( 'admin_menu', array( $this, 'init' ) ); 58 add_action( 'wp_ajax_set-background-image', array( $this, 'wp_set_background_image' ) ); 58 59 } 59 60 … … 72 73 add_action("load-$page", array(&$this, 'take_action'), 49); 73 74 add_action("load-$page", array(&$this, 'handle_upload'), 49); 75 add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 ); 76 add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) ); 74 77 75 78 if ( $this->admin_header_callback ) … … 99 102 ); 100 103 104 add_thickbox(); 105 wp_enqueue_script('media-upload'); 101 106 wp_enqueue_script('custom-background'); 102 107 wp_enqueue_style('farbtastic'); … … 127 132 set_theme_mod('background_image_thumb', ''); 128 133 $this->updated = true; 134 wp_safe_redirect( $_POST['_wp_http_referer'] ); 129 135 return; 130 136 } … … 249 255 <?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?> 250 256 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> 251 </form> 257 <?php 258 $image_library_url = get_upload_iframe_src( 'image', null, 'library' ); 259 $image_library_url = remove_query_arg( 'TB_iframe', $image_library_url ); 260 $image_library_url = add_query_arg( array( 'context' => 'custom-background', 'TB_iframe' => 1 ), $image_library_url ); 261 ?> 262 </form> 263 <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> 252 264 </td> 253 265 </tr> … … 369 381 } 370 382 383 function attachment_fields_to_edit( $form_fields, $post ) { 384 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) { 385 $form_fields = array( 'image-size' => $form_fields['image-size'] ); 386 $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-attachment-id="' . $post->ID . '" class="wp-set-background">' . _( 'Set as background' ) . '</a></td></tr>' ); 387 $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' ); 388 } 389 390 return $form_fields; 391 } 392 393 function filter_upload_tabs ( $tabs ){ 394 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) 395 return array( 'library' => __('Media Library') ); 396 397 return $tabs; 398 } 399 400 public function wp_set_background_image() { 401 if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit; 402 $attachment_id = absint($_POST['attachment_id']); 403 $sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) )); 404 $size = 'thumbnail'; 405 if ( in_array( $_POST['size'], $sizes ) ) 406 $size = esc_attr( $_POST['size'] ); 407 408 update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); 409 $url = wp_get_attachment_image_src( $attachment_id, $size ); 410 $thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' ); 411 set_theme_mod( 'background_image', esc_url( $url[0] ) ); 412 set_theme_mod( 'background_image_thumb', esc_url( $thumbnail[0] ) ); 413 exit; 414 } 371 415 } -
trunk/wp-admin/custom-header.php
r20243 r20358 93 93 add_action("admin_head-$page", array(&$this, 'js'), 50); 94 94 add_action("admin_head-$page", $this->admin_header_callback, 51); 95 96 add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 ); 97 add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) ); 95 98 } 96 99 … … 129 132 130 133 $step = (int) $_GET['step']; 131 if ( $step < 1 || 3 < $step ) 132 $step = 1; 134 if ( $step < 1 || 3 < $step || 135 ( 2 == $step && ! wp_verify_nonce( $_REQUEST['_wpnonce-custom-header-upload'], 'custom-header-upload' ) ) || 136 ( 3 == $step && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom-header-crop-image' ) ) 137 ) 138 return 1; 133 139 134 140 return $step; … … 143 149 $step = $this->step(); 144 150 145 if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) 146 wp_enqueue_script('farbtastic'); 147 elseif ( 2 == $step ) 151 if ( ( 1 == $step || 3 == $step ) ) { 152 add_thickbox(); 153 wp_enqueue_script( 'media-upload' ); 154 wp_enqueue_script( 'custom-header' ); 155 if ( current_theme_supports( 'custom-header', 'header-text' ) ) 156 wp_enqueue_script('farbtastic'); 157 } elseif ( 2 == $step ) { 148 158 wp_enqueue_script('imgareaselect'); 159 } 149 160 } 150 161 … … 396 407 pickColor('#<?php echo get_header_textcolor(); ?>'); 397 408 <?php } else { ?> 398 toggle_text(); 409 toggle_text(); 399 410 <?php } ?> 400 411 }); … … 554 565 </p> 555 566 </form> 567 <?php 568 $image_library_url = get_upload_iframe_src( 'image', null, 'library' ); 569 $image_library_url = remove_query_arg( 'TB_iframe', $image_library_url ); 570 $image_library_url = add_query_arg( array( 'context' => 'custom-header', 'TB_iframe' => 1 ), $image_library_url ); 571 ?> 572 <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> 556 573 </td> 557 574 </tr> … … 675 692 wp_die( __( 'Cheatin’ uh?' ) ); 676 693 677 $overrides = array('test_form' => false); 678 $file = wp_handle_upload($_FILES['import'], $overrides); 679 680 if ( isset($file['error']) ) 681 wp_die( $file['error'], __( 'Image Upload Error' ) ); 682 683 $url = $file['url']; 684 $type = $file['type']; 685 $file = $file['file']; 686 $filename = basename($file); 687 688 // Construct the object array 689 $object = array( 690 'post_title' => $filename, 691 'post_content' => $url, 692 'post_mime_type' => $type, 693 'guid' => $url, 694 'context' => 'custom-header' 695 ); 696 697 // Save the data 698 $id = wp_insert_attachment($object, $file); 694 if ( empty( $_POST ) && isset( $_GET['file'] ) ) { 695 $id = absint( $_GET['file'] ); 696 $file = get_attached_file( $id, true ); 697 $url = wp_get_attachment_image_src( $id, 'full'); 698 $url = $url[0]; 699 } elseif ( isset( $_POST ) ) { 700 extract($this->step_2_manage_upload()); 701 } 699 702 700 703 list($width, $height, $type, $attr) = getimagesize( $file ); … … 754 757 <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $id ); ?>" /> 755 758 <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" /> 759 <?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?> 760 <input type="hidden" name="new-attachment" value="true" /> 761 <?php } ?> 756 762 <?php wp_nonce_field( 'custom-header-crop-image' ) ?> 757 763 … … 761 767 </div> 762 768 <?php 769 } 770 771 772 function step_2_manage_upload() { 773 $overrides = array('test_form' => false); 774 $file = wp_handle_upload($_FILES['import'], $overrides); 775 776 if ( isset($file['error']) ) 777 wp_die( $file['error'], __( 'Image Upload Error' ) ); 778 779 $url = $file['url']; 780 $type = $file['type']; 781 $file = $file['file']; 782 $filename = basename($file); 783 784 // Construct the object array 785 $object = array( 786 'post_title' => $filename, 787 'post_content' => $url, 788 'post_mime_type' => $type, 789 'guid' => $url, 790 'context' => 'custom-header' 791 ); 792 793 // Save the data 794 $id = wp_insert_attachment( $object, $file ); 795 return compact( 'id', 'file', 'filename', 'url', 'type' ); 763 796 } 764 797 … … 827 860 'context' => 'custom-header' 828 861 ); 862 if ( isset( $_POST['new-attachment'] ) && $_POST['new-attachment'] ) 863 unset($object['ID']); 829 864 830 865 // Update the attachment 831 wp_insert_attachment($object, $cropped);866 $attachment_id = wp_insert_attachment( $object, $cropped ); 832 867 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) ); 833 868 update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); … … 846 881 // cleanup 847 882 $medium = str_replace(basename($original), 'midsize-'.basename($original), $original); 848 @unlink( apply_filters( 'wp_delete_file', $medium ) ); 849 @unlink( apply_filters( 'wp_delete_file', $original ) ); 883 if ( file_exists( $medium ) ) 884 @unlink( apply_filters( 'wp_delete_file', $medium ) ); 885 if ( empty ( $_POST['new-attachment'] ) ) 886 @unlink( apply_filters( 'wp_delete_file', $original ) ); 850 887 851 888 return $this->finished(); … … 871 908 wp_die(__('You do not have permission to customize headers.')); 872 909 $step = $this->step(); 873 if ( 1 == $step || ! $_POST ) 874 $this->step_1(); 875 elseif ( 2 == $step ) 910 if ( 2 == $step ) 876 911 $this->step_2(); 877 912 elseif ( 3 == $step ) 878 913 $this->step_3(); 914 else 915 $this->step_1(); 916 } 917 918 function attachment_fields_to_edit( $form_fields, $post ) { 919 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) { 920 $form_fields = array(); 921 $href = esc_url(add_query_arg(array( 922 'page' => 'custom-header', 923 'step' => 2, 924 '_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'), 925 'file' => $post->ID 926 ), admin_url('themes.php'))); 927 928 $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-location="' . $href . '" class="wp-set-header">' . _( 'Set as header' ) . '</a></td></tr>' ); 929 $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-header' ); 930 } 931 932 return $form_fields; 933 } 934 935 function filter_upload_tabs( $tabs ) { 936 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) 937 return array( 'library' => __('Media Library') ); 938 939 return $tabs; 879 940 } 880 941 -
trunk/wp-admin/includes/media.php
r20310 r20358 404 404 } 405 405 406 function get_upload_iframe_src( $type = null, $post_id = null ) {406 function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) { 407 407 global $post_ID; 408 408 … … 410 410 $post_id = $post_ID; 411 411 412 $uploading_iframe_ID = (int) $post_id; 413 $upload_iframe_src = add_query_arg( 'post_id', $uploading_iframe_ID, admin_url('media-upload.php') ); 412 $upload_iframe_src = add_query_arg( 'post_id', (int) $post_id, admin_url('media-upload.php') ); 414 413 415 414 if ( $type && 'media' != $type ) 416 415 $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); 416 417 if ( ! empty( $tab ) ) 418 $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src); 417 419 418 420 $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src); … … 498 500 $attachment = stripslashes_deep( $_POST['attachments'][$send_id] ); 499 501 500 $html = $attachment['post_title'];502 $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; 501 503 if ( !empty($attachment['url']) ) { 502 504 $rel = ''; -
trunk/wp-admin/media-upload.php
r20143 r20358 23 23 wp_enqueue_script('set-post-thumbnail' ); 24 24 wp_enqueue_style('imgareaselect'); 25 wp_enqueue_script( 'media-gallery' ); 25 26 26 27 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); -
trunk/wp-includes/script-loader.php
r20340 r20358 418 418 419 419 $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array('farbtastic'), false, 1 ); 420 $scripts->add( 'media-gallery', "/wp-admin/js/media-gallery$suffix.js", array('jquery'), false, 1 ); 420 421 } 421 422 }
Note: See TracChangeset
for help on using the changeset viewer.