Better date editing from MarkJaquith. see #6250

git-svn-id: http://svn.automattic.com/wordpress/trunk@7338 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-03-16 23:05:16 +00:00
parent 7039083a89
commit 385677b909
6 changed files with 60 additions and 19 deletions

View File

@ -100,19 +100,19 @@ else
<p><label for="post_status_private" class="selectit"><input id="post_status_private" name="post_status" type="checkbox" value="private" <?php checked($post->post_status, 'private'); ?> /> <?php _e('Keep this post private') ?></label></p> <p><label for="post_status_private" class="selectit"><input id="post_status_private" name="post_status" type="checkbox" value="private" <?php checked($post->post_status, 'private'); ?> /> <?php _e('Keep this post private') ?></label></p>
<?php <?php
if ($post_ID) { if ($post_ID) {
if ( 'future' == $post->post_status ) { // scheduled for publishing at a future date
if ( 'future' == $post->post_status ) {
$stamp = __('Scheduled for:<br />%1$s at %2$s'); $stamp = __('Scheduled for:<br />%1$s at %2$s');
} else if ( 'publish' == $post->post_status ) { } else if ( 'publish' == $post->post_status ) { // already published
$stamp = __('%1$s at %2$s'); $stamp = __('Published on:<br />%1$s at %2$s');
} else { } else if ( '0000-00-00 00:00:00' == $post->post_date ) { // draft, 1 or more saves, no date specified
$stamp = __('Saved on:<br />%1$s at %2$s'); $stamp = __('Publish immediately');
} else { // draft, 1 or more saves, date specified
$stamp = __('Publish on:<br />%1$s at %2$s');
} }
$date = mysql2date(get_option('date_format'), $post->post_date); $date = mysql2date(get_option('date_format'), $post->post_date);
$time = mysql2date(get_option('time_format'), $post->post_date); $time = mysql2date(get_option('time_format'), $post->post_date);
} else { } else { // draft (no saves, and thus no date specified)
$stamp = __('%1$s at %2$s'); $stamp = __('Publish immediately');
$date = mysql2date(get_option('date_format'), current_time('mysql')); $date = mysql2date(get_option('date_format'), current_time('mysql'));
$time = mysql2date(get_option('time_format'), current_time('mysql')); $time = mysql2date(get_option('time_format'), current_time('mysql'));
} }
@ -142,7 +142,13 @@ if ( ( 'edit' == $action) && current_user_can('delete_post', $post_ID) )
?> ?>
<br class="clear" /> <br class="clear" />
<?php if ($post_ID): ?> <?php if ($post_ID): ?>
<?php printf(__('Last edit: %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified)); ?> <?php if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {
$last_user = get_userdata($last_id);
printf(__('Last edited by %1$s on %2$s at %3$s'), wp_specialchars( $last_user->display_name ), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));
} else {
printf(__('Last edited on %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));
}
?>
<br class="clear" /> <br class="clear" />
<?php endif; ?> <?php endif; ?>
<span id="autosave"></span> <span id="autosave"></span>

View File

@ -21,6 +21,14 @@ function edit_comment() {
$_POST['comment_content'] = $_POST['content']; $_POST['comment_content'] = $_POST['content'];
$_POST['comment_ID'] = (int) $_POST['comment_ID']; $_POST['comment_ID'] = (int) $_POST['comment_ID'];
foreach ( array ('aa', 'mm', 'jj', 'hh', 'mm') as $timeunit ) {
if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
$_POST['edit_date'] = '1';
break;
}
}
if (!empty ( $_POST['edit_date'] ) ) { if (!empty ( $_POST['edit_date'] ) ) {
$aa = $_POST['aa']; $aa = $_POST['aa'];
$mm = $_POST['mm']; $mm = $_POST['mm'];

View File

@ -74,6 +74,13 @@ function edit_post() {
if (!isset( $_POST['ping_status'] )) if (!isset( $_POST['ping_status'] ))
$_POST['ping_status'] = 'closed'; $_POST['ping_status'] = 'closed';
foreach ( array ('aa', 'mm', 'jj', 'hh', 'mm') as $timeunit ) {
if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
$_POST['edit_date'] = '1';
break;
}
}
if (!empty ( $_POST['edit_date'] ) ) { if (!empty ( $_POST['edit_date'] ) ) {
$aa = $_POST['aa']; $aa = $_POST['aa'];
$mm = $_POST['mm']; $mm = $_POST['mm'];
@ -281,6 +288,13 @@ function wp_write_post() {
if (!isset( $_POST['ping_status'] )) if (!isset( $_POST['ping_status'] ))
$_POST['ping_status'] = 'closed'; $_POST['ping_status'] = 'closed';
foreach ( array ('aa', 'mm', 'jj', 'hh', 'mm') as $timeunit ) {
if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
$_POST['edit_date'] = '1';
break;
}
}
if (!empty ( $_POST['edit_date'] ) ) { if (!empty ( $_POST['edit_date'] ) ) {
$aa = $_POST['aa']; $aa = $_POST['aa'];
$mm = $_POST['mm']; $mm = $_POST['mm'];

View File

@ -830,7 +830,7 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) {
if ( (int) $tab_index > 0 ) if ( (int) $tab_index > 0 )
$tab_index_attribute = " tabindex=\"$tab_index\""; $tab_index_attribute = " tabindex=\"$tab_index\"";
echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />'; // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
$time_adj = time() + (get_option( 'gmt_offset' ) * 3600 ); $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 );
$post_date = ($for_post) ? $post->post_date : $comment->comment_date; $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
@ -841,22 +841,26 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) {
$mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj ); $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj );
$ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj ); $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj );
$month = "<select name=\"mm\" onchange=\"edit_date.checked=true\"$tab_index_attribute>\n"; $month = "<select id=\"mm\" name=\"mm\" onchange=\"edit_date.checked=true\"$tab_index_attribute>\n";
for ( $i = 1; $i < 13; $i = $i +1 ) { for ( $i = 1; $i < 13; $i = $i +1 ) {
$month .= "\t\t\t<option value=\"$i\""; $month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
if ( $i == $mm ) if ( $i == $mm )
$month .= ' selected="selected"'; $month .= ' selected="selected"';
$month .= '>' . $wp_locale->get_month( $i ) . "</option>\n"; $month .= '>' . $wp_locale->get_month( $i ) . "</option>\n";
} }
$month .= '</select>'; $month .= '</select>';
$day = '<input type="text" id="jj" name="jj" value="' . $jj . '" size="2" maxlength="2" onchange="edit_date.checked=true"' . $tab_index_attribute . ' autocomplete="off" />'; $day = '<input type="text" id="jj" name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
$year = '<input type="text" id="aa" name="aa" value="' . $aa . '" size="4" maxlength="5" onchange="edit_date.checked=true"' . $tab_index_attribute . ' autocomplete="off" />'; $year = '<input type="text" id="aa" name="aa" value="' . $aa . '" size="4" maxlength="5"' . $tab_index_attribute . ' autocomplete="off" />';
$hour = '<input type="text" id="hh" name="hh" value="' . $hh . '" size="2" maxlength="2" onchange="edit_date.checked=true"' . $tab_index_attribute . ' autocomplete="off" />'; $hour = '<input type="text" id="hh" name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
$minute = '<input type="text" id="mn" name="mn" value="' . $mn . '" size="2" maxlength="2" onchange="edit_date.checked=true"' . $tab_index_attribute . ' autocomplete="off" />'; $minute = '<input type="text" id="mn" name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
printf(_c('%1$s%2$s%3$s @ %4$s : %5$s|1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input'), $month, $day, $year, $hour, $minute); printf(_c('%1$s%2$s, %3$s <br />@ %4$s : %5$s|1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input'), $month, $day, $year, $hour, $minute);
echo "\n\n";
foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit )
echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
?> ?>
<input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" />
<input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" />
<?php <?php
} }

View File

@ -149,8 +149,15 @@ jQuery(document).ready( function() {
jQuery('.edit-timestamp').click(function () { jQuery('.edit-timestamp').click(function () {
if (jQuery('#timestampdiv').is(":hidden")) { if (jQuery('#timestampdiv').is(":hidden")) {
jQuery('#timestampdiv').slideDown("normal"); jQuery('#timestampdiv').slideDown("normal");
jQuery('.edit-timestamp').text(postL10n.cancel);
} else { } else {
jQuery('#timestampdiv').hide(); jQuery('#timestampdiv').hide();
jQuery('#mm').val(jQuery('#hidden_mm').val());
jQuery('#jj').val(jQuery('#hidden_jj').val());
jQuery('#aa').val(jQuery('#hidden_aa').val());
jQuery('#hh').val(jQuery('#hidden_hh').val());
jQuery('#mn').val(jQuery('#hidden_mn').val());
jQuery('.edit-timestamp').text(postL10n.edit);
} }
return false; return false;
}); });

View File

@ -147,6 +147,8 @@ class WP_Scripts {
'add' => attribute_escape(__('Add')), 'add' => attribute_escape(__('Add')),
'addTag' => attribute_escape(__('Add new tag')), 'addTag' => attribute_escape(__('Add new tag')),
'separate' => __('Separate tags with commas'), 'separate' => __('Separate tags with commas'),
'cancel' => __('Cancel'),
'edit' => __('Edit'),
) ); ) );
$this->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox'), '20080208' ); $this->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox'), '20080208' );
$this->add( 'link', '/wp-admin/js/link.js', array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20080131' ); $this->add( 'link', '/wp-admin/js/link.js', array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20080131' );