Date and time presets from Viper007Bond. see #7552

git-svn-id: https://develop.svn.wordpress.org/trunk@9131 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-10-13 18:32:16 +00:00
parent 1a372ccc34
commit b16a2c07c6
2 changed files with 105 additions and 14 deletions

View File

@ -12,6 +12,39 @@ require_once('./admin.php');
$title = __('General Settings'); $title = __('General Settings');
$parent_file = 'options-general.php'; $parent_file = 'options-general.php';
/**
* Display JavaScript on the page.
*
* @package WordPress
* @subpackage General_Settings_Panel
*/
function add_js() {
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function($){
$("input[name='date_format']").click(function(){
if ( "date_format_custom_radio" != $(this).attr("id") )
$("input[name='date_format_custom']").val( $(this).val() );
});
$("input[name='date_format_custom']").focus(function(){
$("#date_format_custom_radio").attr("checked", "checked");
});
$("input[name='time_format']").click(function(){
if ( "time_format_custom_radio" != $(this).attr("id") )
$("input[name='time_format_custom']").val( $(this).val() );
});
$("input[name='time_format_custom']").focus(function(){
$("#time_format_custom_radio").attr("checked", "checked");
});
});
//]]>
</script>
<?php
}
add_filter('admin_head', 'add_js');
include('./admin-header.php'); include('./admin-header.php');
?> ?>
@ -96,14 +129,66 @@ foreach ( $offset_range as $offset ) {
</tr> </tr>
<tr> <tr>
<th scope="row"><label for="date_format"><?php _e('Date Format') ?></label></th> <th scope="row"><label for="date_format"><?php _e('Date Format') ?></label></th>
<td><input name="date_format" type="text" id="date_format" size="30" value="<?php form_option('date_format'); ?>" /><br /> <td>
<?php _e('Output:') ?> <strong><?php echo mysql2date(get_option('date_format'), current_time('mysql')); ?></strong></td> <fieldset><legend class="hidden"><?php _e('Date Format') ?></legend>
<?php
$date_formats = apply_filters( 'date_formats', array(
__('F j, Y'),
'Y/m/d',
'm/d/Y',
'd/m/Y',
) );
$custom = TRUE;
foreach ( $date_formats as $format ) {
echo "\t<label title='" . attribute_escape($format) . "'><input type='radio' name='date_format' value='" . attribute_escape($format) . "'";
if ( get_option('date_format') === $format ) { // checked() uses "==" rather than "==="
echo " checked='checked'";
$custom = FALSE;
}
echo ' /> ' . gmdate( $format, current_time('timestamp') ) . "</label><br />\n";
}
echo ' <label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"';
checked( $custom, TRUE );
echo '/> ' . __('Custom') . ': </label><input type="text" name="date_format_custom" value="' . attribute_escape( get_option('date_format') ) . '" size="30" /> ' . gmdate( get_option('date_format'), current_time('timestamp') ) . "</label>\n";
echo "\t<p>" . __('<a href="http://codex.wordpress.org/Formatting_Date_and_Time">Documentation on date formatting</a>. Click "Save Changes" to update sample output.') . "</p>\n";
?>
</fieldset>
</td>
</tr> </tr>
<tr> <tr>
<th scope="row"><label for="time_format"><?php _e('Time Format') ?></label></th> <th scope="row"><label for="time_format"><?php _e('Time Format') ?></label></th>
<td><input name="time_format" type="text" id="time_format" size="30" value="<?php form_option('time_format'); ?>" /><br /> <td>
<?php _e('Output:') ?> <strong><?php echo gmdate(get_option('time_format'), current_time('timestamp')); ?></strong><br /> <fieldset><legend class="hidden"><?php _e('Time Format') ?></legend>
<?php _e('<a href="http://codex.wordpress.org/Formatting_Date_and_Time">Documentation on date formatting</a>. Click "Save Changes" to update sample output.') ?></td> <?php
$time_formats = apply_filters( 'time_formats', array(
__('g:i a'),
'g:i A',
'H:i',
) );
$custom = TRUE;
foreach ( $time_formats as $format ) {
echo "\t<label title='" . attribute_escape($format) . "'><input type='radio' name='time_format' value='" . attribute_escape($format) . "'";
if ( get_option('time_format') === $format ) { // checked() uses "==" rather than "==="
echo " checked='checked'";
$custom = FALSE;
}
echo ' /> ' . gmdate( $format, current_time('timestamp') ) . "</label><br />\n";
}
echo ' <label><input type="radio" name="time_format" id="time_format_custom_radio" value="\c\u\s\t\o\m"';
checked( $custom, TRUE );
echo '/> ' . __('Custom') . ': </label><input type="text" name="time_format_custom" value="' . attribute_escape( get_option('time_format') ) . '" size="30" /> ' . gmdate( get_option('time_format'), current_time('timestamp') ) . "</label>\n";
?>
</fieldset>
</td>
</tr> </tr>
<tr> <tr>
<th scope="row"><label for="start_of_week"><?php _e('Week Starts On') ?></label></th> <th scope="row"><label for="start_of_week"><?php _e('Week Starts On') ?></label></th>

View File

@ -41,33 +41,39 @@ if ( !current_user_can('manage_options') )
switch($action) { switch($action) {
case 'update': case 'update':
$any_changed = 0;
$option_page = $_POST[ 'option_page' ]; $option_page = $_POST[ 'option_page' ];
check_admin_referer( $option_page . '-options' ); check_admin_referer( $option_page . '-options' );
if ( !isset( $whitelist_options[ $option_page ] ) ) if ( !isset( $whitelist_options[ $option_page ] ) )
wp_die( __( 'Error! Options page not found.' ) ); wp_die( __( 'Error! Options page not found.' ) );
if ( $option_page == 'options' ) { if ( 'options' == $option_page ) {
$options = explode(',', stripslashes( $_POST[ 'page_options' ] )); $options = explode(',', stripslashes( $_POST[ 'page_options' ] ));
} else { } else {
$options = $whitelist_options[ $option_page ]; $options = $whitelist_options[ $option_page ];
} }
if ($options) { // Handle custom date/time formats
foreach ($options as $option) { if ( 'general' == $option_page ) {
if ( !empty($_POST['date_format']) && !empty($_POST['date_format_custom']) && '\c\u\s\t\o\m' == stripslashes( $_POST['date_format'] ) )
$_POST['date_format'] = $_POST['date_format_custom'];
if ( !empty($_POST['time_format']) && !empty($_POST['time_format_custom']) && '\c\u\s\t\o\m' == stripslashes( $_POST['time_format'] ) )
$_POST['time_format'] = $_POST['time_format_custom'];
}
if ( $options ) {
foreach ( $options as $option ) {
$option = trim($option); $option = trim($option);
$value = $_POST[$option]; $value = $_POST[$option];
if(!is_array($value)) $value = trim($value); if ( !is_array($value) ) $value = trim($value);
$value = stripslashes_deep($value); $value = stripslashes_deep($value);
update_option($option, $value); update_option($option, $value);
} }
} }
$goback = add_query_arg('updated', 'true', wp_get_referer()); $goback = add_query_arg( 'updated', 'true', wp_get_referer() );
wp_redirect($goback); wp_redirect( $goback );
break; break;
default: default:
include('admin-header.php'); ?> include('admin-header.php'); ?>