Make WordPress Core

Ticket #9588: 9588.21.diff

File 9588.21.diff, 8.7 KB (added by ryan, 14 years ago)
  • wp-includes/post-template.php

     
    12101210        /* translators: 1: date */
    12111211        $currentf  = __( '%1$s [Current Revision]' );
    12121212
    1213         $date = date_i18n( $datef, strtotime( $revision->post_modified_gmt . ' +0000' ) );
     1213        $date = date_i18n( $datef, strtotime( $revision->post_modified ) );
    12141214        if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
    12151215                $date = "<a href='$link'>$date</a>";
    12161216
  • wp-includes/post.php

     
    19741974
    19751975        $time = strtotime( $post->post_date_gmt . ' GMT' );
    19761976
    1977         if ( $time > time() ) { // Uh oh, someone jumped the gun!
     1977        if ( $time > current_time('timestamp', true) ) { // Uh oh, someone jumped the gun!
    19781978                wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); // clear anything else in the system
    19791979                wp_schedule_single_event( $time, 'publish_future_post', array( $post_id ) );
    19801980                return;
  • wp-includes/functions.php

     
    5959 * @return int|string String if $type is 'gmt', int if $type is 'timestamp'.
    6060 */
    6161function current_time( $type, $gmt = 0 ) {
    62         switch ( $type ) {
    63                 case 'mysql':
    64                         return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
    65                         break;
    66                 case 'timestamp':
    67                         return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * 3600 );
    68                         break;
     62        if ( function_exists('date_default_timezone_set') && '' != get_option('timezone_string') ) {
     63                // Use the PHP5 DateTime support. The timezone is already correctly set.
     64                switch ( $type ) {
     65                        case 'mysql':
     66                                return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : date( 'Y-m-d H:i:s' );
     67                                break;
     68                        case 'timestamp':
     69                                return ( $gmt ) ? gmdate('U') : time();
     70                                break;
     71                }
     72        } else {
     73                // No PHP5 DateTime support or timezone not set. Add in gmt_offset.
     74                switch ( $type ) {
     75                        case 'mysql':
     76                                return ( $gmt ) ? gmdate( 'Y-m-d H:i:s') : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
     77                                break;
     78                        case 'timestamp':
     79                                return ( $gmt ) ? time() : ( time() + ( get_option( 'gmt_offset' ) * 3600 ) );
     80                                break;
     81                }
    6982        }
    7083}
    7184
     
    88101        $i = $unixtimestamp;
    89102        // Sanity check for PHP 5.1.0-
    90103        if ( false === $i || intval($i) < 0 ) {
    91                 if ( ! $gmt )
    92                         $i = current_time( 'timestamp' );
    93                 else
    94                         $i = time();
     104                $i = current_time( 'timestamp', $gmt );
    95105                // we should not let date() interfere with our
    96106                // specially computed timestamp
    97                 $gmt = true;
     107                if ( !function_exists('date_default_timezone_set') )
     108                        $gmt = true;
    98109        }
    99110
    100111        // store original value for language with untypical grammars
    101112        // see http://core.trac.wordpress.org/ticket/9396
    102113        $req_format = $dateformatstring;
    103114
    104         $datefunc = $gmt? 'gmdate' : 'date';
     115        $datefunc = $gmt ? 'gmdate' : 'date';
    105116
    106117        if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
    107118                $datemonth = $wp_locale->get_month( $datefunc( 'm', $i ) );
     
    127138}
    128139
    129140/**
     141 * WP wrapper for date() that hides differences between PHP4 and PHP 5 date and time support.
     142 *
     143 * @since 3.0
     144 *
     145 * @param string $format Format to display the date.
     146 * @param int $timestamp Optional. Unix timestamp.
     147 * @return string The formatted date
     148 */
     149function compat_date($format, $timestamp = false) {
     150        if ( function_exists('date_default_timezone_set') )
     151                return date($format, $timestamp);
     152        else
     153                return gmdate($format, $timestamp);
     154}
     155
     156/**
    130157 * Convert number to format based on the locale.
    131158 *
    132159 * @since 2.3.0
  • wp-settings.php

     
    1818set_magic_quotes_runtime(0);
    1919@ini_set('magic_quotes_sybase', 0);
    2020
    21 if ( function_exists('date_default_timezone_set') )
    22         date_default_timezone_set('UTC');
    23 
    2421/**
    2522 * Turn register globals off.
    2623 *
     
    719716// Load in support for template functions which the theme supports
    720717require_if_theme_supports( 'post-thumbnails', ABSPATH . WPINC . '/post-thumbnail-template.php' );
    721718
     719// Set the timezone
     720if ( function_exists('date_default_timezone_set') ) {
     721        if ( $timezone_string = get_option( 'timezone_string' ) )
     722                @date_default_timezone_set( $timezone_string );
     723        else
     724                @date_default_timezone_set('UTC');
     725}
     726
    722727/**
    723728 * Runs just before PHP shuts down execution.
    724729 *
  • wp-admin/includes/meta-boxes.php

     
    165165        $date = date_i18n( $datef, strtotime( $post->post_date ) );
    166166} else { // draft (no saves, and thus no date specified)
    167167        $stamp = __('Publish <b>immediately</b>');
    168         $date = date_i18n( $datef, strtotime( current_time('mysql') ) );
     168        $date = date_i18n( $datef, current_time('timestamp') );
    169169}
    170170
    171171if ( $can_publish ) : // Contributors don't get to choose the date of publish ?>
  • wp-admin/includes/template.php

     
    14081408                                $m_time = $post->post_date;
    14091409                                $time = get_post_time('G', true, $post);
    14101410
    1411                                 $time_diff = time() - $time;
     1411                                $time_diff = current_time('timestamp', true) - $time;
    14121412
    14131413                                if ( $time_diff > 0 && $time_diff < 24*60*60 )
    14141414                                        $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
     
    16351635                        $m_time = $page->post_date;
    16361636                        $time = get_post_time('G', true);
    16371637
    1638                         $time_diff = time() - $time;
     1638                        $time_diff = current_time('timestamp', true) - $time;
    16391639
    16401640                        if ( $time_diff > 0 && $time_diff < 24*60*60 )
    16411641                                $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
     
    21052105                $author_url_display = substr($author_url_display, 0, 49) . '...';
    21062106
    21072107        $ptime = date('G', strtotime( $comment->comment_date ) );
    2108         if ( ( abs(time() - $ptime) ) < 86400 )
     2108        if ( ( abs(current_time('timestamp') - $ptime) ) < 86400 )
    21092109                $ptime = sprintf( __('%s ago'), human_time_diff( $ptime ) );
    21102110        else
    21112111                $ptime = mysql2date(__('Y/m/d \a\t g:i A'), $comment->comment_date );
     
    26122612
    26132613        $time_adj = current_time('timestamp');
    26142614        $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
    2615         $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
    2616         $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
    2617         $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
    2618         $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
    2619         $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
    2620         $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
     2615        $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : compat_date( 'd', $time_adj );
     2616        $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : compat_date( 'm', $time_adj );
     2617        $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : compat_date( 'Y', $time_adj );
     2618        $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : compat_date( 'H', $time_adj );
     2619        $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : compat_date( 'i', $time_adj );
     2620        $ss = ($edit) ? mysql2date( 's', $post_date, false ) : compat_date( 's', $time_adj );
    26212621
    2622         $cur_jj = gmdate( 'd', $time_adj );
    2623         $cur_mm = gmdate( 'm', $time_adj );
    2624         $cur_aa = gmdate( 'Y', $time_adj );
    2625         $cur_hh = gmdate( 'H', $time_adj );
    2626         $cur_mn = gmdate( 'i', $time_adj );
     2622        $cur_jj = compat_date( 'd', $time_adj );
     2623        $cur_mm = compat_date( 'm', $time_adj );
     2624        $cur_aa = compat_date( 'Y', $time_adj );
     2625        $cur_hh = compat_date( 'H', $time_adj );
     2626        $cur_mn = compat_date( 'i', $time_adj );
    26272627
    26282628        $month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n";
    26292629        for ( $i = 1; $i < 13; $i = $i +1 ) {
  • wp-admin/upload.php

     
    417417                        $t_time = get_the_time(__('Y/m/d g:i:s A'));
    418418                        $m_time = $post->post_date;
    419419                        $time = get_post_time( 'G', true );
    420                         if ( ( abs($t_diff = time() - $time) ) < 86400 ) {
     420                        if ( ( abs($t_diff = current_time('timestamp', true) - $time) ) < 86400 ) {
    421421                                if ( $t_diff < 0 )
    422422                                        $h_time = sprintf( __('%s from now'), human_time_diff( $time ) );
    423423                                else