WordPress.org

Make WordPress Core

Ticket #10397: 10397.diff

File 10397.diff, 3.2 KB (added by mdawaffe, 8 years ago)
  • wp-includes/functions.php

     
    192192        $md = substr( $mysqlstring, 5, 2 ); // Mysql string day
    193193        $day = mktime( 0, 0, 0, $md, $mm, $my ); // The timestamp for mysqlstring day.
    194194        $weekday = date( 'w', $day ); // The day of the week from the timestamp
    195         $i = 86400; // One day
    196195        if ( !is_numeric($start_of_week) )
    197196                $start_of_week = get_option( 'start_of_week' );
    198197
    199198        if ( $weekday < $start_of_week )
    200                 $weekday = 7 - $start_of_week - $weekday;
     199                $weekday += 7;
    201200
    202         while ( $weekday > $start_of_week ) {
    203                 $weekday = date( 'w', $day );
    204                 if ( $weekday < $start_of_week )
    205                         $weekday = 7 - $start_of_week - $weekday;
    206 
    207                 $day -= 86400;
    208                 $i = 0;
    209         }
    210         $week['start'] = $day + 86400 - $i;
    211         $week['end'] = $week['start'] + 604799;
    212         return $week;
     201        $start = $day - 86400 * ( $weekday - $start_of_week ); // The most recent week start day on or before $day
     202        $end = $start + 604799; // $start + 7 days - 1 second
     203        return compact( 'start', 'end' );
    213204}
    214205
    215206/**
     
    41644155        @header( 'X-Content-Type-Options: nosniff' );
    41654156}
    41664157
     4158/**
     4159 * Returns a MySQL expression for selecting the week number based on the start_of_week option.
     4160 *
     4161 * @internal
     4162 * @since 3.0.0
     4163 * @param string $column
     4164 * @return string
     4165 */
     4166function _wp_mysql_week( $column ) {
     4167        switch ( $start_of_week = (int) get_option( 'start_of_week' ) ) {
     4168        default :
     4169        case 0 :
     4170                return "WEEK( $column, 0 )";
     4171        case 1 :
     4172                return "WEEK( $column, 1 )";
     4173        case 2 :
     4174        case 3 :
     4175        case 4 :
     4176        case 5 :
     4177        case 6 :
     4178                return "WEEK( DATE_SUB( $column, INTERVAL $start_of_week DAY ), 0 )";
     4179        }
     4180}
     4181
    41674182?>
  • wp-includes/query.php

     
    17811781                }
    17821782
    17831783                if ( $q['w'] )
    1784                         $where .= " AND WEEK($wpdb->posts.post_date, 1)='" . $q['w'] . "'";
     1784                        $where .= ' AND ' . _wp_mysql_week( "`$wpdb->posts`.`post_date`" ) . " = '" . $q['w'] . "'";
    17851785
    17861786                if ( intval($q['comments_popup']) )
    17871787                        $q['p'] = absint($q['comments_popup']);
  • wp-includes/general-template.php

     
    965965                        }
    966966                }
    967967        } elseif ( 'weekly' == $type ) {
    968                 $start_of_week = get_option('start_of_week');
    969                 $query = "SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY WEEK(post_date, $start_of_week), YEAR(post_date) ORDER BY post_date DESC $limit";
     968                $week = _wp_mysql_week( '`post_date`' );
     969                $query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` DESC $limit";
    970970                $key = md5($query);
    971971                $cache = wp_cache_get( 'wp_get_archives' , 'general');
    972972                if ( !isset( $cache[ $key ] ) ) {