From d7a30e235fa2e22a68c71ee43c28334028add0c5 Mon Sep 17 00:00:00 2001 From: markjaquith Date: Wed, 7 Oct 2009 22:18:09 +0000 Subject: [PATCH] First pass on canonical post thumbanils. Admin-side GUI only. Theme functions to follow. see #10928 git-svn-id: http://svn.automattic.com/wordpress/trunk@12007 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-ajax.php | 13 +++++++++++++ wp-admin/css/media.css | 2 +- wp-admin/css/media.dev.css | 12 ++++++++++++ wp-admin/edit-form-advanced.php | 1 + wp-admin/includes/media.php | 19 ++++++++++++++++++- wp-admin/js/set-post-thumbnail-handler.dev.js | 11 +++++++++++ wp-admin/js/set-post-thumbnail-handler.js | 1 + wp-admin/js/set-post-thumbnail.dev.js | 19 +++++++++++++++++++ wp-admin/js/set-post-thumbnail.js | 1 + wp-admin/media-upload.php | 1 + wp-admin/post-new.php | 1 + wp-admin/post.php | 1 + wp-includes/script-loader.php | 14 +++++++++++++- 13 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 wp-admin/js/set-post-thumbnail-handler.dev.js create mode 100644 wp-admin/js/set-post-thumbnail-handler.js create mode 100644 wp-admin/js/set-post-thumbnail.dev.js create mode 100644 wp-admin/js/set-post-thumbnail.js diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index fdb1f6b8c..b9a2b4ee1 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -1370,6 +1370,19 @@ case 'image-editor': wp_image_editor($attachment_id, $msg); die(); break; +case 'set-post-thumbnail': + $post_id = intval( $_POST['post_id'] ); + if ( !current_user_can( 'edit_post', $post_id ) ) + die( '-1' ); + $thumbnail_id = intval( $_POST['thumbnail_id'] ); + if ( $thumbnail_id && get_post( $thumbnail_id ) ) { + $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' ); + if ( !empty( $thumbnail_html ) ) { + update_post_meta( $post_id, '_thumbnail_id', $thumbnail_id ); + die( _wp_post_thumbnail_html( $thumbnail_id ) ); + } + } + die( '0' ); default : do_action( 'wp_ajax_' . $_POST['action'] ); die('0'); diff --git a/wp-admin/css/media.css b/wp-admin/css/media.css index 057359952..366b323d3 100644 --- a/wp-admin/css/media.css +++ b/wp-admin/css/media.css @@ -1 +1 @@ -div#media-upload-header{margin:0;padding:0 5px;font-weight:bold;position:relative;border-bottom-width:1px;border-bottom-style:solid;height:2.5em;}body#media-upload ul#sidemenu{font-weight:normal;margin:0 5px;position:absolute;left:0;bottom:-1px;}div#media-upload-error{margin:1em;font-weight:bold;}form{margin:1em;}#search-filter{text-align:right;}th{position:relative;}.media-upload-form label.form-help,td.help{font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif;font-style:italic;font-weight:normal;}.media-upload-form p.help{margin:0;padding:0;}.media-upload-form fieldset{width:100%;border:none;text-align:justify;margin:0 0 1em 0;padding:0;}.image-align-none-label{background:url(../images/align-none.png) no-repeat center left;}.image-align-left-label{background:url(../images/align-left.png) no-repeat center left;}.image-align-center-label{background:url(../images/align-center.png) no-repeat center left;}.image-align-right-label{background:url(../images/align-right.png) no-repeat center left;}tr.image-size td{width:460px;}tr.image-size div.image-size-item{float:left;width:25%;margin:0;}#library-form .progress,#gallery-form .progress,#flash-upload-ui,.insert-gallery,.describe.startopen,.describe.startclosed{display:none;}.media-item .thumbnail{max-width:128px;max-height:128px;}thead.media-item-info tr{background-color:transparent;}thead.media-item-info th,thead.media-item-info td{border:none;margin:0;}.form-table thead.media-item-info{border:8px solid #fff;}abbr.required{text-decoration:none;border:none;}.describe label{display:inline;}.describe td{vertical-align:middle;padding:0 5px 8px 0;}.describe td.A1{width:132px;}.describe input[type="text"],.describe textarea{width:460px;border-width:1px;border-style:solid;}.describe-toggle-on,.describe-toggle-off{display:block;line-height:36px;float:right;margin-right:20px;}.describe-toggle-off{display:none;}.hidden{height:0;width:0;overflow:hidden;border:none;}#media-upload p.ml-submit{padding:1em 0;}#media-upload p.help,#media-upload label.help{font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif;font-style:italic;font-weight:normal;}#media-upload tr.image-size td.field{text-align:center;}#media-upload #media-items{border-width:1px;border-style:solid;border-bottom:none;width:623px;}#media-upload .media-item{border-bottom-width:1px;border-bottom-style:solid;min-height:36px;width:100%;}#media-upload .ui-sortable .media-item{cursor:move;}.filename{line-height:36px;padding:0 10px;overflow:hidden;}#media-upload .describe{padding:5px;width:100%;clear:both;cursor:default;}#media-upload .slidetoggle{border-top-width:1px;border-top-style:solid;}#media-upload .describe th.label{padding-top:.2em;text-align:left;min-width:120px;}#media-upload tr.align td.field{text-align:center;}#media-upload tr.image-size{margin-bottom:1em;height:3em;}#media-upload #filter{width:623px;}#media-upload #filter .subsubsub{margin:8px 0;}#filter .tablenav select{border-style:solid;border-width:1px;padding:2px;vertical-align:top;width:auto;}#media-upload .del-attachment{display:none;margin:5px 0;}.menu_order{float:right;font-size:11px;margin:10px 10px 0;}.menu_order_input{border:1px solid #ddd;font-size:10px;padding:1px;width:23px;}.ui-sortable-helper{background-color:#fff;border:1px solid #aaa;opacity:.6;filter:alpha(opacity=60);}#media-upload th.order-head{width:25%;text-align:center;}#media-upload .widefat{width:626px;border-style:solid solid none;}.sorthelper{height:37px;width:623px;display:block;}#gallery-settings th.label{width:160px;}#gallery-settings #basic th.label{padding:5px 5px 5px 0;}#gallery-settings .title{clear:both;padding:0 0 3px;border-bottom-style:solid;border-bottom-width:1px;font-family:Georgia,"Times New Roman",Times,serif;font-size:1.6em;border-bottom-color:#DADADA;color:#5A5A5A;}h3.media-title{color:#5A5A5A;font-family:Georgia,"Times New Roman",Times,serif;font-size:1.6em;font-weight:normal;}#gallery-settings .describe td{vertical-align:middle;height:3.5em;}#gallery-settings .describe th.label{padding-top:.5em;text-align:left;}#gallery-settings .describe{padding:5px;width:615px;clear:both;cursor:default;}#gallery-settings .describe select{width:15em;border:1px solid #dfdfdf;}#gallery-settings label,#gallery-settings legend{font-size:13px;color:#464646;margin-right:15px;}#gallery-settings .align .field label{margin:0 1.5em 0 0;}#gallery-settings p.ml-submit{border-top:1px solid #dfdfdf;}#gallery-settings select#columns{width:6em;}#sort-buttons{font-size:.8em;margin:3px 25px -8px 0;text-align:right;max-width:625px;}#sort-buttons a{text-decoration:none;}#sort-buttons #asc,#sort-buttons #showall{padding-left:5px;}#sort-buttons span{margin-right:25px;} \ No newline at end of file +div#media-upload-header{margin:0;padding:0 5px;font-weight:bold;position:relative;border-bottom-width:1px;border-bottom-style:solid;height:2.5em;}body#media-upload ul#sidemenu{font-weight:normal;margin:0 5px;position:absolute;left:0;bottom:-1px;}div#media-upload-error{margin:1em;font-weight:bold;}form{margin:1em;}#search-filter{text-align:right;}th{position:relative;}.media-upload-form label.form-help,td.help{font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif;font-style:italic;font-weight:normal;}.media-upload-form p.help{margin:0;padding:0;}.media-upload-form fieldset{width:100%;border:none;text-align:justify;margin:0 0 1em 0;padding:0;}.image-align-none-label{background:url(../images/align-none.png) no-repeat center left;}.image-align-left-label{background:url(../images/align-left.png) no-repeat center left;}.image-align-center-label{background:url(../images/align-center.png) no-repeat center left;}.image-align-right-label{background:url(../images/align-right.png) no-repeat center left;}tr.image-size td{width:460px;}tr.image-size div.image-size-item{float:left;width:25%;margin:0;}#library-form .progress,#gallery-form .progress,#flash-upload-ui,.insert-gallery,.describe.startopen,.describe.startclosed{display:none;}.media-item .thumbnail{max-width:128px;max-height:128px;}thead.media-item-info tr{background-color:transparent;}thead.media-item-info th,thead.media-item-info td{border:none;margin:0;}.form-table thead.media-item-info{border:8px solid #fff;}abbr.required{text-decoration:none;border:none;}.describe label{display:inline;}.describe td{vertical-align:middle;padding:0 5px 8px 0;}.describe td.A1{width:132px;}.describe input[type="text"],.describe textarea{width:460px;border-width:1px;border-style:solid;}.describe-toggle-on,.describe-toggle-off{display:block;line-height:36px;float:right;margin-right:20px;}.describe-toggle-off{display:none;}.hidden{height:0;width:0;overflow:hidden;border:none;}#media-upload p.ml-submit{padding:1em 0;}#media-upload p.help,#media-upload label.help{font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif;font-style:italic;font-weight:normal;}#media-upload tr.image-size td.field{text-align:center;}#media-upload #media-items{border-width:1px;border-style:solid;border-bottom:none;width:623px;}#media-upload .media-item{border-bottom-width:1px;border-bottom-style:solid;min-height:36px;width:100%;}#media-upload .ui-sortable .media-item{cursor:move;}.filename{line-height:36px;padding:0 10px;overflow:hidden;}#media-upload .describe{padding:5px;width:100%;clear:both;cursor:default;}#media-upload .slidetoggle{border-top-width:1px;border-top-style:solid;}#media-upload .describe th.label{padding-top:.2em;text-align:left;min-width:120px;}#media-upload tr.align td.field{text-align:center;}#media-upload tr.image-size{margin-bottom:1em;height:3em;}#media-upload #filter{width:623px;}#media-upload #filter .subsubsub{margin:8px 0;}#filter .tablenav select{border-style:solid;border-width:1px;padding:2px;vertical-align:top;width:auto;}#media-upload .del-attachment{display:none;margin:5px 0;}.menu_order{float:right;font-size:11px;margin:10px 10px 0;}.menu_order_input{border:1px solid #ddd;font-size:10px;padding:1px;width:23px;}.ui-sortable-helper{background-color:#fff;border:1px solid #aaa;opacity:.6;filter:alpha(opacity=60);}#media-upload th.order-head{width:20%;text-align:center;}#media-upload th.actions-head{width:25%;text-align:center;}#media-upload a.wp-post-thumbnail{display:block;line-height:36px;float:right;margin-right:20px;}#media-upload .widefat{width:626px;border-style:solid solid none;}.sorthelper{height:37px;width:623px;display:block;}#gallery-settings th.label{width:160px;}#gallery-settings #basic th.label{padding:5px 5px 5px 0;}#gallery-settings .title{clear:both;padding:0 0 3px;border-bottom-style:solid;border-bottom-width:1px;font-family:Georgia,"Times New Roman",Times,serif;font-size:1.6em;border-bottom-color:#DADADA;color:#5A5A5A;}h3.media-title{color:#5A5A5A;font-family:Georgia,"Times New Roman",Times,serif;font-size:1.6em;font-weight:normal;}#gallery-settings .describe td{vertical-align:middle;height:3.5em;}#gallery-settings .describe th.label{padding-top:.5em;text-align:left;}#gallery-settings .describe{padding:5px;width:615px;clear:both;cursor:default;}#gallery-settings .describe select{width:15em;border:1px solid #dfdfdf;}#gallery-settings label,#gallery-settings legend{font-size:13px;color:#464646;margin-right:15px;}#gallery-settings .align .field label{margin:0 1.5em 0 0;}#gallery-settings p.ml-submit{border-top:1px solid #dfdfdf;}#gallery-settings select#columns{width:6em;}#sort-buttons{font-size:.8em;margin:3px 25px -8px 0;text-align:right;max-width:625px;}#sort-buttons a{text-decoration:none;}#sort-buttons #asc,#sort-buttons #showall{padding-left:5px;}#sort-buttons span{margin-right:25px;} \ No newline at end of file diff --git a/wp-admin/css/media.dev.css b/wp-admin/css/media.dev.css index a16df1f40..573a35584 100644 --- a/wp-admin/css/media.dev.css +++ b/wp-admin/css/media.dev.css @@ -263,10 +263,22 @@ abbr.required { } #media-upload th.order-head { + width: 20%; + text-align: center; +} + +#media-upload th.actions-head { width: 25%; text-align: center; } +#media-upload a.wp-post-thumbnail{ + display: block; + line-height: 36px; + float: right; + margin-right: 20px; +} + #media-upload .widefat { width: 626px; border-style: solid solid none; diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 7cce1f941..414e8fb14 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -74,6 +74,7 @@ foreach ( get_object_taxonomies('post') as $tax_name ) { } add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'post', 'side', 'core'); +add_meta_box('postthumbnaildiv', __('Post Thumbnail'), 'post_thumbnail_meta_box', 'post', 'side', 'low'); // add_meta_box('passworddiv', __('Privacy Options'), 'post_password_meta_box', 'post', 'side', 'core'); add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'post', 'normal', 'core'); add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', 'post', 'normal', 'core'); diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index a5c6c77be..f22504d9c 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -114,6 +114,21 @@ function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = fal return $html; } +function _wp_post_thumbnail_html( $thumbnail_id = NULL ) { + if ( $thumbnail_id && get_post( $thumbnail_id ) ) { + $thumbnail_html = wp_get_attachment_image($thumbnail_id, 'thumbnail'); + if ( !empty( $thumbnail_html ) ) + return '' . $thumbnail_html . ''; + } + return '' . esc_html__( 'Set thumbnail' ) . ''; +} + +function post_thumbnail_meta_box() { + global $post; + $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); + echo _wp_post_thumbnail_html( $thumbnail_id ); +} + /** * {@internal Missing Short Description}} * @@ -1135,7 +1150,8 @@ function get_media_item( $attachment_id, $args = null ) { $class = empty($errors) ? 'startclosed' : 'startopen'; $toggle_links = " $toggle_on - $toggle_off"; + $toggle_off + " . esc_html__( "Use for thumbnail" ) . ""; } else { $class = 'form-table'; $toggle_links = ''; @@ -1629,6 +1645,7 @@ jQuery(function($){ +
diff --git a/wp-admin/js/set-post-thumbnail-handler.dev.js b/wp-admin/js/set-post-thumbnail-handler.dev.js new file mode 100644 index 000000000..a7e12eced --- /dev/null +++ b/wp-admin/js/set-post-thumbnail-handler.dev.js @@ -0,0 +1,11 @@ +function WPSetThumbnailHTML(html){ + jQuery('#postthumbnaildiv .inside').html(html); +} +function WPSetThumbnailID(id){ + if ( jQuery('input[value=_thumbnail_id]').size() > 0 ) { + jQuery('#meta\\[' + jQuery('input[value=_thumbnail_id]').attr('id').match(/[0-9]+/) + '\\]\\[value\\]' ).text(id); + } +} +function WPCloseTB(){ + tb_remove(); +} \ No newline at end of file diff --git a/wp-admin/js/set-post-thumbnail-handler.js b/wp-admin/js/set-post-thumbnail-handler.js new file mode 100644 index 000000000..6dc36f6b4 --- /dev/null +++ b/wp-admin/js/set-post-thumbnail-handler.js @@ -0,0 +1 @@ +function WPSetThumbnailHTML(html){jQuery("#postthumbnaildiv .inside").html(html)}function WPSetThumbnailID(id){if(jQuery("input[value=_thumbnail_id]").size()>0){jQuery("#meta\\["+jQuery("input[value=_thumbnail_id]").attr("id").match(/[0-9]+/)+"\\]\\[value\\]").text(id)}}function WPCloseTB(){tb_remove()}; \ No newline at end of file diff --git a/wp-admin/js/set-post-thumbnail.dev.js b/wp-admin/js/set-post-thumbnail.dev.js new file mode 100644 index 000000000..723c37771 --- /dev/null +++ b/wp-admin/js/set-post-thumbnail.dev.js @@ -0,0 +1,19 @@ +function WPSetAsThumbnail(id){ + jQuery('#media-item-' + id + ' > a.wp-post-thumbnail').text( setPostThumbnailL10n.saving ).attr('href', '#'); + jQuery.post(ajaxurl, { + action:"set-post-thumbnail", post_id: post_id, thumbnail_id: id, cookie: encodeURIComponent(document.cookie) + }, function(str){ + var win = window.dialogArguments || opener || parent || top; + if ( str == '0' ) { + alert( setPostThumbnailL10n.error ); + win.cwsCloseTB(); + } else { + jQuery('a.wp-post-thumbnail').text( setPostThumbnailL10n.setThumbnail ); + jQuery('#media-item-' + id + ' > a.wp-post-thumbnail').hide(); + win.WPSetThumbnailID(id); + win.WPSetThumbnailHTML(str); + win.WPCloseTB(); + } + } + ); +} \ No newline at end of file diff --git a/wp-admin/js/set-post-thumbnail.js b/wp-admin/js/set-post-thumbnail.js new file mode 100644 index 000000000..cda94bf47 --- /dev/null +++ b/wp-admin/js/set-post-thumbnail.js @@ -0,0 +1 @@ +function WPSetAsThumbnail(id){jQuery("#media-item-"+id+" > a.wp-post-thumbnail").text(setPostThumbnailL10n.saving).attr("href","#");jQuery.post(ajaxurl,{action:"set-post-thumbnail",post_id:post_id,thumbnail_id:id,cookie:encodeURIComponent(document.cookie)},function(str){var win=window.dialogArguments||opener||parent||top;if(str=="0"){alert(setPostThumbnailL10n.error);win.cwsCloseTB()}else{jQuery("a.wp-post-thumbnail").text(setPostThumbnailL10n.setThumbnail);jQuery("#media-item-"+id+" > a.wp-post-thumbnail").hide();win.WPSetThumbnailID(id);win.WPSetThumbnailHTML(str);win.WPCloseTB()}})}; \ No newline at end of file diff --git a/wp-admin/media-upload.php b/wp-admin/media-upload.php index da090c91c..0bb745577 100644 --- a/wp-admin/media-upload.php +++ b/wp-admin/media-upload.php @@ -18,6 +18,7 @@ if (!current_user_can('upload_files')) wp_enqueue_script('swfupload-all'); wp_enqueue_script('swfupload-handlers'); wp_enqueue_script('image-edit'); +wp_enqueue_script('set-post-thumbnail' ); wp_enqueue_style('imgareaselect'); @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); diff --git a/wp-admin/post-new.php b/wp-admin/post-new.php index 229f3d06c..326a488e8 100644 --- a/wp-admin/post-new.php +++ b/wp-admin/post-new.php @@ -18,6 +18,7 @@ if ( user_can_richedit() ) add_thickbox(); wp_enqueue_script('media-upload'); wp_enqueue_script('word-count'); +wp_enqueue_script( 'set-post-thumbnail-handler' ); if ( ! current_user_can('edit_posts') ) { require_once ('./admin-header.php'); ?> diff --git a/wp-admin/post.php b/wp-admin/post.php index 14b34b5c1..a251e02cf 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -139,6 +139,7 @@ case 'edit': add_thickbox(); wp_enqueue_script('media-upload'); wp_enqueue_script('word-count'); + wp_enqueue_script( 'set-post-thumbnail-handler' ); wp_enqueue_script( 'admin-comments' ); enqueue_comment_hotkeys_js(); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 5fb8990d0..2454d1854 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -407,6 +407,18 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array('jquery', 'json2', 'imgareaselect'), '20090929' ); $scripts->add_data( 'image-edit', 'group', 1 ); + + $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), '20091005' ); + $scripts->add_data( 'set-post-thumbnail', 'group', 1 ); + $scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', array( + 'setThumbnail' => __( 'Use for thumbnail' ), + 'saving' => __( 'Saving...' ), + 'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' ) + ) ); + + $scripts->add( 'set-post-thumbnail-handler', "/wp-admin/js/set-post-thumbnail-handler$suffix.js", array( 'jquery' ), '20091005' ); + $scripts->add_data( 'set-post-thumbnail-handler', 'group', 1 ); + } } @@ -460,7 +472,7 @@ function wp_default_styles( &$styles ) { $styles->add_data( 'colors-classic', 'rtl', true ); $styles->add( 'global', "/wp-admin/css/global$suffix.css", array(), '20090630' ); - $styles->add( 'media', "/wp-admin/css/media$suffix.css", array(), '20090922' ); + $styles->add( 'media', "/wp-admin/css/media$suffix.css", array(), '20091005' ); $styles->add( 'widgets', "/wp-admin/css/widgets$suffix.css", array(), '20090603' ); $styles->add( 'dashboard', "/wp-admin/css/dashboard$suffix.css", array(), '20090514' ); $styles->add( 'install', "/wp-admin/css/install$suffix.css", array(), '20090514' );