Changeset 9131

Show
Ignore:
Timestamp:
10/13/08 18:32:16 (3 months ago)
Author:
ryan
Message:

Date and time presets from Viper007Bond. see #7552

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/options-general.php

    r9032 r9131  
    1212$title = __('General Settings'); 
    1313$parent_file = 'options-general.php'; 
     14 
     15/** 
     16 * Display JavaScript on the page. 
     17 * 
     18 * @package WordPress 
     19 * @subpackage General_Settings_Panel 
     20 */ 
     21function add_js() { 
     22?> 
     23<script type="text/javascript"> 
     24//<![CDATA[ 
     25    jQuery(document).ready(function($){ 
     26        $("input[name='date_format']").click(function(){ 
     27            if ( "date_format_custom_radio" != $(this).attr("id") ) 
     28                $("input[name='date_format_custom']").val( $(this).val() ); 
     29        }); 
     30        $("input[name='date_format_custom']").focus(function(){ 
     31            $("#date_format_custom_radio").attr("checked", "checked"); 
     32        }); 
     33 
     34        $("input[name='time_format']").click(function(){ 
     35            if ( "time_format_custom_radio" != $(this).attr("id") ) 
     36                $("input[name='time_format_custom']").val( $(this).val() ); 
     37        }); 
     38        $("input[name='time_format_custom']").focus(function(){ 
     39            $("#time_format_custom_radio").attr("checked", "checked"); 
     40        }); 
     41    }); 
     42//]]> 
     43</script> 
     44<?php 
     45} 
     46add_filter('admin_head', 'add_js'); 
    1447 
    1548include('./admin-header.php'); 
     
    97130<tr> 
    98131<th scope="row"><label for="date_format"><?php _e('Date Format') ?></label></th> 
    99 <td><input name="date_format" type="text" id="date_format" size="30" value="<?php form_option('date_format'); ?>" /><br /> 
    100 <?php _e('Output:') ?> <strong><?php echo mysql2date(get_option('date_format'), current_time('mysql')); ?></strong></td> 
     132<td> 
     133    <fieldset><legend class="hidden"><?php _e('Date Format') ?></legend> 
     134<?php 
     135 
     136    $date_formats = apply_filters( 'date_formats', array( 
     137        __('F j, Y'), 
     138        'Y/m/d', 
     139        'm/d/Y', 
     140        'd/m/Y', 
     141    ) ); 
     142 
     143    $custom = TRUE; 
     144 
     145    foreach ( $date_formats as $format ) { 
     146        echo "\t<label title='" . attribute_escape($format) . "'><input type='radio' name='date_format' value='" . attribute_escape($format) . "'"; 
     147        if ( get_option('date_format') === $format ) { // checked() uses "==" rather than "===" 
     148            echo " checked='checked'"; 
     149            $custom = FALSE; 
     150        } 
     151        echo ' /> ' . gmdate( $format, current_time('timestamp') ) . "</label><br />\n"; 
     152    } 
     153 
     154    echo '  <label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"'; 
     155    checked( $custom, TRUE ); 
     156    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"; 
     157 
     158    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"; 
     159?> 
     160    </fieldset> 
     161</td> 
    101162</tr> 
    102163<tr> 
    103164<th scope="row"><label for="time_format"><?php _e('Time Format') ?></label></th> 
    104 <td><input name="time_format" type="text" id="time_format" size="30" value="<?php form_option('time_format'); ?>" /><br /> 
    105 <?php _e('Output:') ?> <strong><?php echo gmdate(get_option('time_format'), current_time('timestamp')); ?></strong><br /> 
    106 <?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> 
     165<td> 
     166    <fieldset><legend class="hidden"><?php _e('Time Format') ?></legend> 
     167<?php 
     168 
     169    $time_formats = apply_filters( 'time_formats', array( 
     170        __('g:i a'), 
     171        'g:i A', 
     172        'H:i', 
     173    ) ); 
     174 
     175    $custom = TRUE; 
     176 
     177    foreach ( $time_formats as $format ) { 
     178        echo "\t<label title='" . attribute_escape($format) . "'><input type='radio' name='time_format' value='" . attribute_escape($format) . "'"; 
     179        if ( get_option('time_format') === $format ) { // checked() uses "==" rather than "===" 
     180            echo " checked='checked'"; 
     181            $custom = FALSE; 
     182        } 
     183        echo ' /> ' . gmdate( $format, current_time('timestamp') ) . "</label><br />\n"; 
     184    } 
     185 
     186    echo '  <label><input type="radio" name="time_format" id="time_format_custom_radio" value="\c\u\s\t\o\m"'; 
     187    checked( $custom, TRUE ); 
     188    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"; 
     189?> 
     190    </fieldset> 
     191</td> 
    107192</tr> 
    108193<tr> 
  • trunk/wp-admin/options.php

    r9066 r9131  
    4242 
    4343case 'update': 
    44     $any_changed = 0; 
    45  
    4644    $option_page = $_POST[ 'option_page' ]; 
    4745    check_admin_referer( $option_page . '-options' ); 
     
    5048        wp_die( __( 'Error! Options page not found.' ) ); 
    5149 
    52     if ( $option_page == 'options' ) { 
     50    if ( 'options' == $option_page ) { 
    5351        $options = explode(',', stripslashes( $_POST[ 'page_options' ] )); 
    5452    } else { 
     
    5654    } 
    5755 
    58     if ($options) { 
    59         foreach ($options as $option) { 
     56    // Handle custom date/time formats 
     57    if ( 'general' == $option_page ) { 
     58        if ( !empty($_POST['date_format']) && !empty($_POST['date_format_custom']) && '\c\u\s\t\o\m' == stripslashes( $_POST['date_format'] ) ) 
     59            $_POST['date_format'] = $_POST['date_format_custom']; 
     60        if ( !empty($_POST['time_format']) && !empty($_POST['time_format_custom']) && '\c\u\s\t\o\m' == stripslashes( $_POST['time_format'] ) ) 
     61            $_POST['time_format'] = $_POST['time_format_custom']; 
     62    } 
     63 
     64    if ( $options ) { 
     65        foreach ( $options as $option ) { 
    6066            $option = trim($option); 
    6167            $value = $_POST[$option]; 
    62             if(!is_array($value))  $value = trim($value); 
     68            if ( !is_array($value) ) $value = trim($value); 
    6369            $value = stripslashes_deep($value); 
    6470            update_option($option, $value); 
     
    6672    } 
    6773 
    68     $goback = add_query_arg('updated', 'true', wp_get_referer()); 
    69     wp_redirect($goback); 
    70     break; 
     74    $goback = add_query_arg( 'updated', 'true', wp_get_referer() ); 
     75    wp_redirect( $goback ); 
     76   break; 
    7177 
    7278default: