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
This commit is contained in:
markjaquith 2009-10-07 22:18:09 +00:00
parent 923a3ade8a
commit d7a30e235f
13 changed files with 93 additions and 3 deletions

View File

@ -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');

View File

@ -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;}
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;}

View File

@ -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;

View File

@ -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');

View File

@ -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 '<a href="#" id="cws-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . $thumbnail_html . '</a>';
}
return '<a href="#" id="cws-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . esc_html__( 'Set thumbnail' ) . '</a>';
}
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 = "
<a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
<a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
<a class='toggle describe-toggle-off' href='#'>$toggle_off</a>
<a class='wp-post-thumbnail' href='#' onclick='WPSetAsThumbnail(\"" . intval( $attachment_id ) . "\");return false;'>" . esc_html__( "Use for thumbnail" ) . "</a>";
} else {
$class = 'form-table';
$toggle_links = '';
@ -1629,6 +1645,7 @@ jQuery(function($){
<thead><tr>
<th><?php _e('Media'); ?></th>
<th class="order-head"><?php _e('Order'); ?></th>
<th class="actions-head"><?php _e('Actions'); ?></th>
</tr></thead>
</table>
<div id="media-items">

View File

@ -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();
}

View File

@ -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()};

View File

@ -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();
}
}
);
}

View File

@ -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()}})};

View File

@ -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'));

View File

@ -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'); ?>

View File

@ -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();

View File

@ -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' );