Date and time presets from Viper007Bond. see #7552

git-svn-id: http://svn.automattic.com/wordpress/trunk@9131 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-10-13 18:32:16 +00:00
parent 209d229ed1
commit 91950354e9
2 changed files with 105 additions and 14 deletions

View File

@ -12,6 +12,39 @@ require_once('./admin.php');
$title = __('General Settings');
$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');
?>
@ -96,14 +129,66 @@ foreach ( $offset_range as $offset ) {
</tr>
<tr>
<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 />
<?php _e('Output:') ?> <strong><?php echo mysql2date(get_option('date_format'), current_time('mysql')); ?></strong></td>
<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>
<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 />
<?php _e('Output:') ?> <strong><?php echo gmdate(get_option('time_format'), current_time('timestamp')); ?></strong><br />
<?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>
<td>
<fieldset><legend class="hidden"><?php _e('Time Format') ?></legend>
<?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>
<th scope="row"><label for="start_of_week"><?php _e('Week Starts On') ?></label></th>

View File

@ -41,32 +41,38 @@ if ( !current_user_can('manage_options') )
switch($action) {
case 'update':
$any_changed = 0;
$option_page = $_POST[ 'option_page' ];
check_admin_referer( $option_page . '-options' );
if ( !isset( $whitelist_options[ $option_page ] ) )
wp_die( __( 'Error! Options page not found.' ) );
if ( $option_page == 'options' ) {
if ( 'options' == $option_page ) {
$options = explode(',', stripslashes( $_POST[ 'page_options' ] ));
} else {
$options = $whitelist_options[ $option_page ];
}
if ($options) {
foreach ($options as $option) {
// Handle custom date/time formats
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);
$value = $_POST[$option];
if(!is_array($value)) $value = trim($value);
if ( !is_array($value) ) $value = trim($value);
$value = stripslashes_deep($value);
update_option($option, $value);
}
}
$goback = add_query_arg('updated', 'true', wp_get_referer());
wp_redirect($goback);
$goback = add_query_arg( 'updated', 'true', wp_get_referer() );
wp_redirect( $goback );
break;
default: