Visibility section of Publish Module for Posts. Pages later.

git-svn-id: http://svn.automattic.com/wordpress/trunk@9639 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2008-11-12 18:36:48 +00:00
parent 6690ad435f
commit d6c4fac277
5 changed files with 220 additions and 60 deletions

View File

@ -92,8 +92,8 @@ function post_submit_meta_box($post) {
</div>
<div id="save-action">
<?php if ( 'publish' != $post->post_status && 'private' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?>
<input type="submit" name="save" id="save-post" value="<?php echo attribute_escape( __('Save Draft') ); ?>" tabindex="4" class="button button-highlighted" />
<?php if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?>
<input <?php if ( 'private' == $post->post_status ) { ?>style="display:none"<?php } ?> type="submit" name="save" id="save-post" value="<?php echo attribute_escape( __('Save Draft') ); ?>" tabindex="4" class="button button-highlighted" />
<?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?>
<input type="submit" name="save" id="save-post" value="<?php echo attribute_escape( __('Save as Pending') ); ?>" tabindex="4" class="button button-highlighted" />
<?php } ?>
@ -113,8 +113,10 @@ function post_submit_meta_box($post) {
<b><span id="post-status-display">
<?php
switch ( $post->post_status ) {
case 'publish':
case 'private':
_e('Privately Published');
break;
case 'publish':
_e('Published');
break;
case 'future':
@ -130,13 +132,15 @@ switch ( $post->post_status ) {
?>
</span></b>
<?php if ( 'publish' == $post->post_status || 'private' == $post->post_status || $can_publish ) { ?>
<a href="#post_status" class="edit-post-status hide-if-no-js" tabindex='4'><?php _e('Edit') ?></a>
<a href="#post_status" <?php if ( 'private' == $post->post_status ) { ?>style="display:none;" <?php } ?>class="edit-post-status hide-if-no-js" tabindex='4'><?php _e('Edit') ?></a>
<div id="post-status-select" class="hide-if-js">
<input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php echo $post->post_status; ?>" />
<select name='post_status' id='post_status' tabindex='4'>
<?php if ( $post->post_status == 'publish' ) : ?>
<option<?php selected( $post->post_status, 'publish' ); selected( $post->post_status, 'private' );?> value='publish'><?php _e('Published') ?></option>
<?php if ( 'publish' == $post->post_status ) : ?>
<option<?php selected( $post->post_status, 'publish' ); ?> value='publish'><?php _e('Published') ?></option>
<?php elseif ( 'private' == $post->post_status ) : ?>
<option<?php selected( $post->post_status, 'private' ); ?> value='publish'><?php _e('Privately Published') ?></option>
<?php elseif ( 'future' == $post->post_status ) : ?>
<option<?php selected( $post->post_status, 'future' ); ?> value='future'><?php _e('Scheduled') ?></option>
<?php endif; ?>
@ -150,20 +154,54 @@ switch ( $post->post_status ) {
<?php } ?>
</div><?php // /misc-pub-section ?>
<div class="misc-pub-section " id="visibility">
<?php _e('Visibility:'); ?> <b><span id="post-visibility-display"><?php
<?php if ( $can_publish && current_user_can( 'edit_others_posts' ) ) { ?>
<div class="misc-pub-section " id="sticky-checkbox">
<input id="sticky" name="sticky" type="checkbox" value="sticky" <?php checked(is_sticky($post->ID), true); ?> tabindex="4" /> <label for="sticky" class="selectit"><?php _e('Stick this post to the front page') ?></label>
</div><?php // /misc-pub-section ?>
if ( !empty( $post->post_password ) ) {
$visibility = 'password';
$visibility_trans = __('Password protected');
} elseif ( 'private' == $post->post_status ) {
$visibility = 'private';
$visibility_trans = __('Private');
} elseif ( is_sticky( $post->ID ) ) {
$visibility = 'public';
$visibility_trans = __('Public, sticky');
$sticky = 'sticky';
} else {
$visibility = 'public';
$visibility_trans = __('Public');
}
?><?php echo wp_specialchars( $visibility_trans ); ?></span></b> <?php if ( $can_publish ) { ?> <a href="#visibility" class="edit-visibility hide-if-no-js"><?php _e('Edit'); ?></a>
<div id="post-visibility-select" class="hide-if-js">
<input type="hidden" name="hidden_post_password" id="hidden-post-password" value="<?php echo attribute_escape($post->post_password); ?>" />
<input type="checkbox" style="display:none" name="hidden_post_sticky" id="hidden-post-sticky" value="sticky" <?php checked(is_sticky($post->ID), true); ?> />
<input type="hidden" name="hidden_post_visibility" id="hidden-post-visibility" value="<?php echo attribute_escape( $visibility ); ?>" />
<input type="radio" name="visibility" id="visibility-radio-public" value="public" <?php checked( $visibility, 'public' ); ?> /> <label for="visibility-radio-public" class="selectit"><?php _e('Public'); ?></label><br />
<span id="sticky-span"><input id="sticky" name="sticky" type="checkbox" value="sticky" <?php checked(is_sticky($post->ID), true); ?> tabindex="4" /> <label for="sticky" class="selectit"><?php _e('Stick this post to the front page') ?></label><br /></span>
<input type="radio" name="visibility" id="visibility-radio-password" value="password" <?php checked( $visibility, 'password' ); ?> /> <label for="visibility-radio-password" class="selectit"><?php _e('Password protected'); ?></label><br />
<span id="password-span"><label for="post_password"><?php _e('Password:'); ?></label> <input type="text" name="post_password" id="post_password" value="<?php echo attribute_escape($post->post_password); ?>" /><br /></span>
<input type="radio" name="visibility" id="visibility-radio-private" value="private" <?php checked( $visibility, 'private' ); ?> /> <label for="visibility-radio-private" class="selectit"><?php _e('Private'); ?></label><br />
<p>
<a href="#visibility" class="save-post-visibility hide-if-no-js button"><?php _e('OK'); ?></a>
<a href="#visibility" class="cancel-post-visibility hide-if-no-js"><?php _e('Cancel'); ?></a>
</p>
</div>
<?php } ?>
</div><?php // /misc-pub-section ?>
<?php
$datef = _c( 'M j, Y @ G:i|Publish box date format');
if ( 0 != $post->ID ) {
if ( 'future' == $post->post_status ) { // scheduled for publishing at a future date
$stamp = __('Scheduled for: <b>%1$s</b>');
} else if ( 'publish' == $post->post_status ) { // already published
} else if ( 'publish' == $post->post_status || 'private' == $post->post_status ) { // already published
$stamp = __('Published on: <b>%1$s</b>');
} else if ( '0000-00-00 00:00:00' == $post->post_date_gmt ) { // draft, 1 or more saves, no date specified
$stamp = __('Publish <b>immediately</b>');
@ -202,17 +240,21 @@ if ( ( 'edit' == $action ) && current_user_can('delete_post', $post->ID) ) { ?>
<div id="publishing-action">
<?php
if ( !in_array( $post->post_status, array('publish', 'future') ) || 0 == $post->ID ) { ?>
if ( !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0 == $post->ID ) { ?>
<?php if ( current_user_can('publish_posts') ) : ?>
<?php if ( !empty($post->post_date_gmt) && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) : ?>
<input name="original_publish" type="hidden" id="original_publish" value="<?php _e('Schedule') ?>" />
<input name="publish" type="submit" class="button-primary" id="publish" tabindex="5" accesskey="p" value="<?php _e('Schedule') ?>" />
<?php else : ?>
<input name="original_publish" type="hidden" id="original_publish" value="<?php _e('Publish') ?>" />
<input name="publish" type="submit" class="button-primary" id="publish" tabindex="5" accesskey="p" value="<?php _e('Publish') ?>" />
<?php endif; ?>
<?php else : ?>
<input name="original_publish" type="hidden" id="original_publish" value="<?php _e('Submit for Review') ?>" />
<input name="publish" type="submit" class="button-primary" id="publish" tabindex="5" accesskey="p" value="<?php _e('Submit for Review') ?>" />
<?php endif; ?>
<?php } else { ?>
<input name="original_publish" type="hidden" id="original_publish" value="<?php _e('Update Post') ?>" />
<input name="save" type="submit" class="button-primary" id="publish" tabindex="5" accesskey="p" value="<?php _e('Update Post') ?>" />
<?php } ?>
</div>
@ -300,7 +342,7 @@ function post_password_meta_box($post) {
<p><?php _e('Setting a password will require people who visit your blog to enter the above password to view this post and its comments.'); ?></p>
<?php
}
add_meta_box('passworddiv', __('Privacy Options'), 'post_password_meta_box', 'post', 'side', 'core');
// add_meta_box('passworddiv', __('Privacy Options'), 'post_password_meta_box', 'post', 'side', 'core');
/**
* Display post excerpt form fields.

View File

@ -153,6 +153,20 @@ function edit_post( $post_data = null ) {
if ( is_wp_error($post_data) )
wp_die( $post_data->get_error_message() );
switch ( $post_data['visibility'] ) {
case 'public' :
unset( $post_data['post_password'] );
break;
case 'password' :
unset( $post_data['sticky'] );
break;
case 'private' :
$post_data['post_status'] = 'private';
$post_data['post_password'] = '';
unset( $post_data['sticky'] );
break;
}
// Meta Stuff
if ( isset($post_data['meta']) && $post_data['meta'] ) {
foreach ( $post_data['meta'] as $key => $value )
@ -442,6 +456,20 @@ function wp_write_post() {
if ( is_wp_error($translated) )
return $translated;
switch ( $_POST['visibility'] ) {
case 'public' :
$_POST['post_password'] = '';
break;
case 'password' :
unset( $_POST['sticky'] );
break;
case 'private' :
$_POST['post_status'] = 'private';
$_POST['post_password'] = '';
unset( $_POST['sticky'] );
break;
}
// Create the post.
$post_ID = wp_insert_post( $_POST );
if ( is_wp_error( $post_ID ) )

View File

@ -192,6 +192,126 @@ jQuery(document).ready( function($) {
} );
jQuery('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change();
var stamp = $('#timestamp').html();
var visibility = $('#post-visibility-display').html();
var sticky = '';
function updateVisibility() {
if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
$('#sticky').attr('checked', false);
$('#sticky-span').hide();
} else {
$('#sticky-span').show();
}
if ( $('#post-visibility-select input:radio:checked').val() != 'password' ) {
$('#password-span').hide();
} else {
$('#password-span').show();
}
}
function updateText() {
var attemptedDate = new Date( $('#aa').val(), $('#mm').val() -1, $('#jj').val(), $('#hh').val(), $('#mn').val());
var originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val());
var currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val());
if ( attemptedDate > currentDate ) {
var publishOn = postL10n.publishOnFuture;
$('#publish').val( postL10n.schedule );
} else if ( $('#original_post_status').val() != 'publish' ) {
var publishOn = postL10n.publishOn;
$('#publish').val( postL10n.publish );
} else {
var publishOn = postL10n.publishOnPast;
$('#publish').val( postL10n.update );
}
if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
$('#timestamp').html(stamp);
} else {
$('#timestamp').html(
publishOn + ' <b>' +
$( '#mm option[value=' + $('#mm').val() + ']' ).text() + ' ' +
$('#jj').val() + ', ' +
$('#aa').val() + ' @ ' +
$('#hh').val() + ':' +
$('#mn').val() + '</b> '
);
}
if ( $('#post-visibility-select input:radio:checked').val() == 'private' ) {
$('#publish').val( postL10n.update );
if ( $('#post_status option[value=publish]').length == 0 ) {
$('#post_status').append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
}
$('#post_status option[value=publish]').html( postL10n.privatelyPublished );
$('#post_status option[value=publish]').attr('selected', true);
$('.edit-post-status').hide();
} else {
if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
if ( $('#post_status option[value=publish]').length != 0 ) {
$('#post_status option[value=publish]').remove();
$('#post_status').val($('#hidden_post_status').val());
}
} else {
$('#post_status option[value=publish]').html( postL10n.published );
}
$('.edit-post-status').show();
}
$('#post-status-display').html($('#post_status :selected').text());
if ( $('#post_status :selected').val() == 'private' || $('#post_status :selected').val() == 'publish' ) {
$('#save-post').hide();
} else {
$('#save-post').show();
if ( $('#post_status :selected').val() == 'pending' ) {
$('#save-post').show().val( postL10n.savePending );
} else {
$('#save-post').show().val( postL10n.saveDraft );
}
}
}
$('.edit-visibility').click(function () {
if ($('#post-visibility-select').is(":hidden")) {
updateVisibility();
$('#post-visibility-select').slideDown("normal");
$('.edit-visibility').hide();
}
return false;
});
$('.cancel-post-visibility').click(function () {
$('#post-visibility-select').slideUp("normal");
$('#visibility-radio-' + $('#hidden-post-visibility').val()).attr('checked', true);
$('#post_password').val($('#hidden_post_password').val());
$('#sticky').attr('checked', $('#hidden-post-sticky').attr('checked'));
$('#post-visibility-display').html(visibility);
$('.edit-visibility').show();
updateText();
return false;
});
$('.save-post-visibility').click(function () { // crazyhorse - multiple ok cancels
$('#post-visibility-select').slideUp("normal");
$('.edit-visibility').show();
updateText();
if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
$('#sticky').attr('checked', false);
}
if ( true == $('#sticky').attr('checked') ) {
sticky = 'Sticky';
} else {
sticky = '';
}
$('#post-visibility-display').html(
postL10n[$('#post-visibility-select input:radio:checked').val() + sticky]
);
return false;
});
$('#post-visibility-select input:radio').change(function() {
updateVisibility();
});
$('.edit-timestamp').click(function () {
if ($('#timestampdiv').is(":hidden")) {
@ -209,45 +329,15 @@ jQuery(document).ready( function($) {
$('#aa').val($('#hidden_aa').val());
$('#hh').val($('#hidden_hh').val());
$('#mn').val($('#hidden_mn').val());
$('#timestamp').html(stamp);
$('.edit-timestamp').show();
var attemptedDate = new Date( $('#aa').val(), $('#mm').val() -1, $('#jj').val(), $('#hh').val(), $('#mn').val() );
var currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() );
if ( attemptedDate > currentDate ) {
$('#publish').val( postL10n.schedule );
} else if ( $('#original_post_status').val() != 'publish' ) {
$('#publish').val( postL10n.publish );
} else {
$('#publish').val( postL10n.update );
}
updateText();
return false;
});
$('.save-timestamp').click(function () { // crazyhorse - multiple ok cancels
$('#timestampdiv').slideUp("normal");
$('.edit-timestamp').show();
var attemptedDate = new Date( $('#aa').val(), $('#mm').val() -1, $('#jj').val(), $('#hh').val(), $('#mn').val() );
var currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() );
if ( attemptedDate > currentDate ) {
var publishOn = postL10n.publishOnFuture;
$('#publish').val( postL10n.schedule );
} else if ( $('#original_post_status').val() != 'publish' ) {
var publishOn = postL10n.publishOn;
$('#publish').val( postL10n.publish );
} else {
var publishOn = postL10n.publishOnPast;
$('#publish').val( postL10n.update );
}
$('#timestamp').html(
publishOn + ' <b>' +
$( '#mm option[value=' + $('#mm').val() + ']' ).text() + ' ' +
$('#jj').val() + ', ' +
$('#aa').val() + ' @ ' +
$('#hh').val() + ':' +
$('#mn').val() + '</b> '
);
updateText();
return false;
});
@ -263,27 +353,16 @@ jQuery(document).ready( function($) {
$('.save-post-status').click(function() {
$('#post-status-select').slideUp("normal");
$('#post-status-display').html($('#post_status :selected').text());
$('.edit-post-status').show();
if ( $('#post_status :selected').val() == 'pending' ) {
$('#save-post').val( postL10n.savePending );
} else {
$('#save-post').val( postL10n.saveDraft );
}
updateText();
return false;
});
$('.cancel-post-status').click(function() {
$('#post-status-select').slideUp("normal");
$('#post_status').val($('#hidden_post_status').val());
$('#post-status-display').html($('#post_status :selected').text());
$('.edit-post-status').show();
if ( $('#post_status :selected').val() == 'pending' ) {
$('#save-post').val( postL10n.savePending );
} else {
$('#save-post').val( postL10n.saveDraft );
}
updateText();
return false;
});

View File

@ -303,6 +303,10 @@ form p.submit .cancel:hover {
border-right: 0;
}
#sticky-span {
margin-left: 18px;
}
.side-info {
margin: 0;
padding: 4px;

View File

@ -191,7 +191,14 @@ function wp_default_scripts( &$scripts ) {
'schedule' => __('Schedule'),
'update' => __('Update Post'),
'savePending' => __('Save as Pending'),
'saveDraft' => __('Save Draft')
'saveDraft' => __('Save Draft'),
'private' => __('Private'),
'public' => __('Public'),
'publicSticky' => __('Public, sticky'),
'password' => __('Password protected'),
'privatelyPublished' => __('Privately Published'),
'published' => __('Published')
) );
$scripts->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'wp-lists', 'postbox'), '20081107' );
$scripts->localize( 'page', 'postL10n', array(
@ -290,7 +297,7 @@ function wp_default_styles( &$styles ) {
$rtl_styles = array( 'global', 'colors', 'dashboard', 'ie', 'install', 'login', 'media', 'theme-editor', 'upload', 'widgets', 'press-this', 'press-this-ie', 'plugin-install', 'farbtastic' );
$styles->add( 'wp-admin', '/wp-admin/wp-admin.css', array(), '20081110' );
$styles->add( 'wp-admin', '/wp-admin/wp-admin.css', array(), '20081112' );
$styles->add_data( 'wp-admin', 'rtl', '/wp-admin/rtl.css' );
$styles->add( 'ie', '/wp-admin/css/ie.css' );