Ticket #19840: 19840.15.diff
File 19840.15.diff, 14.6 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
403 403 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>"; 404 404 } 405 405 406 function get_upload_iframe_src( $ type = null, $post_id = null) {406 function get_upload_iframe_src( $args = array() ) { 407 407 global $post_ID; 408 408 409 if ( empty( $post_id ) ) 410 $post_id = $post_ID; 409 $defaults = array( 'type' => '', 'post_id' => $post_ID ); 410 // Backwards compat for first parameter being type 411 if ( is_string( $args ) ) 412 $args = array( 413 'type' => $args, 414 'post_id'=> $post_ID 415 ); 411 416 412 $uploading_iframe_ID = (int) $post_id; 413 $upload_iframe_src = add_query_arg( 'post_id', $uploading_iframe_ID, admin_url('media-upload.php') ); 417 $args = wp_parse_args( $args, $defaults ); 414 418 415 if ( $type && 'media' != $type ) 416 $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); 419 $upload_iframe_src = add_query_arg( 'post_id', (int) $args['post_id'], admin_url('media-upload.php') ); 417 420 418 $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src); 421 if ( $args['type'] && 'media' != $args['type'] ) 422 $upload_iframe_src = add_query_arg('type', $args['type'], $upload_iframe_src); 419 423 424 if ( ! empty( $args['tab'] ) ) 425 $upload_iframe_src = add_query_arg('tab', $args['tab'], $upload_iframe_src); 426 427 $upload_iframe_src = apply_filters($args['type'] . '_upload_iframe_src', $upload_iframe_src); 428 420 429 return add_query_arg('TB_iframe', true, $upload_iframe_src); 421 430 } 422 431 … … 497 506 if ( isset($send_id) ) { 498 507 $attachment = stripslashes_deep( $_POST['attachments'][$send_id] ); 499 508 500 $html = $attachment['post_title'];509 $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; 501 510 if ( !empty($attachment['url']) ) { 502 511 $rel = ''; 503 512 if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] ) -
wp-admin/js/custom-background.dev.js
53 53 }); 54 54 }); 55 55 }); 56 57 function WPSetAsBackground(id, img_size){ 58 jQuery.post(ajaxurl, { 59 action: 'set-background-image', 60 attachment_id: id, 61 size: img_size 62 }, function(){ 63 win = window.dialogArguments || opener || parent || top; 64 win.tb_remove(); 65 win.location.reload(); 66 }); 67 } -
wp-admin/custom-background.php
55 55 $this->admin_image_div_callback = $admin_image_div_callback; 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 60 61 /** … … 71 72 add_action("load-$page", array(&$this, 'admin_load')); 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 ) 76 79 add_action("admin_head-$page", $this->admin_header_callback, 51); … … 98 101 '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' 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'); 103 108 } … … 126 131 set_theme_mod('background_image', ''); 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 } 131 137 … … 248 254 <input type="hidden" name="action" value="save" /> 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( array( 'type' => 'image', 'tab' => '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> 254 266 </tbody> … … 368 380 $this->updated = true; 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 href="javascript: ( window.dialogArguments || opener || parent || top ).WPSetAsBackground(' . $post->ID . ', jQuery(\'input[name=\\\'attachments[' . $post->ID . '][image-size]\\\']\').filter(\':checked\').val());">' . _( '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 } -
wp-admin/custom-header.php
92 92 add_action("admin_head-$page", array(&$this, 'take_action'), 50); 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 97 100 /** … … 128 131 return 1; 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; 135 141 } … … 142 148 function js_includes() { 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 151 162 /** … … 395 406 <?php if ( display_header_text() ) { ?> 396 407 pickColor('#<?php echo get_header_textcolor(); ?>'); 397 408 <?php } else { ?> 398 toggle_text(); 409 toggle_text(); 399 410 <?php } ?> 400 411 }); 401 412 })(jQuery); … … 553 564 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> 554 565 </p> 555 566 </form> 567 <?php 568 $image_library_url = get_upload_iframe_src( array( 'type' => 'image', 'tab' => '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> 558 575 <?php endif; ?> … … 674 691 if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) 675 692 wp_die( __( 'Cheatin’ uh?' ) ); 676 693 677 $overrides = array('test_form' => false); 678 $file = wp_handle_upload($_FILES['import'], $overrides); 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 } 679 702 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 array689 $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 data698 $id = wp_insert_attachment($object, $file);699 700 703 list($width, $height, $type, $attr) = getimagesize( $file ); 701 704 702 705 $max_width = 0; … … 753 756 <input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>"/> 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 758 764 <?php submit_button( __( 'Crop and Publish' ) ); ?> … … 762 768 <?php 763 769 } 764 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' ); 796 } 797 765 798 /** 766 799 * Display third step of custom header image page. 767 800 * … … 826 859 'guid' => $url, 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' ) ); 834 869 … … 845 880 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(); 852 889 } … … 870 907 if ( ! current_user_can('edit_theme_options') ) 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(); 879 916 } 880 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 = rawurlencode(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 href="javascript: ( window.dialogArguments || opener || parent || top ).location.href=\'' . $href . '\';">' . _( '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; 940 } 941 881 942 }