Make WordPress Core


Ignore:
Timestamp:
02/28/2004 05:51:41 PM (21 years ago)
Author:
michelvaldrighi
Message:

added a timezone argument to get�_lastpost*()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r945 r952  
    9696}
    9797
    98 function get_lastpostdate() {
     98function get_lastpostdate($timezone = 'server') {
    9999    global $tableposts, $cache_lastpostdate, $use_cache, $pagenow, $wpdb;
    100     if ((!isset($cache_lastpostdate)) OR (!$use_cache)) {
    101         $now = gmdate('Y-m-d H:i:s');
    102         $lastpostdate = $wpdb->get_var("SELECT post_date FROM $tableposts WHERE post_date <= '$now' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
    103         $cache_lastpostdate = $lastpostdate;
    104     } else {
    105         $lastpostdate = $cache_lastpostdate;
     100    $add_seconds_blog = get_settings('gmt_offset') * 3600;
     101    $add_seconds_server = date('Z');
     102    $now = gmdate('Y-m-d H:i:s');
     103    if ((!isset($cache_lastpostdate[$timezone])) OR (!$use_cache)) {
     104        switch(strtolower($timezone)) {
     105            case 'gmt':
     106                $lastpostdate = $wpdb->get_var("SELECT post_date FROM $tableposts WHERE post_date <= '$now' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
     107                break;
     108            case 'blog':
     109                $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date, INTERVAL '$add_seconds_blog' SECOND) FROM $tableposts WHERE post_date <= '$now' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
     110                break;
     111            case 'server':
     112                $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date, INTERVAL '$add_seconds_server' SECOND) FROM $tableposts WHERE post_date <= '$now' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
     113                break;
     114        }
     115        $cache_lastpostdate[$timezone] = $lastpostdate;
     116    } else {
     117        $lastpostdate = $cache_lastpostdate[$timezone];
    106118    }
    107119    return $lastpostdate;
    108120}
    109121
    110 function get_lastpostmodified() {
     122function get_lastpostmodified($timezone = 'server') {
    111123    global $tableposts, $cache_lastpostmodified, $use_cache, $pagenow, $wpdb;
    112     if ((!isset($cache_lastpostmodified)) OR (!$use_cache)) {
    113         $now = gmdate('Y-m-d H:i:s');
    114         $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $tableposts WHERE post_modified <= '$now' AND post_status = 'publish' ORDER BY post_modified DESC LIMIT 1");
    115         $cache_lastpostmodified = $lastpostmodified;
    116     } else {
    117         $lastpostmodified = $cache_lastpostmodified;
     124    $add_seconds_blog = get_settings('gmt_offset') * 3600;
     125    $add_seconds_server = date('Z');
     126    $now = gmdate('Y-m-d H:i:s');
     127    if ((!isset($cache_lastpostmodified[$timezone])) OR (!$use_cache)) {
     128        switch($timezone) {
     129            case 'gmt':
     130                $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $tableposts WHERE post_modified <= '$now' AND post_status = 'publish' ORDER BY post_modified DESC LIMIT 1");
     131                break;
     132            case 'blog':
     133                $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified, INTERVAL '$add_seconds_blog' SECOND) FROM $tableposts WHERE post_modified <= '$now' AND post_status = 'publish' ORDER BY post_modified DESC LIMIT 1");
     134                break;
     135            case 'server':
     136                $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified, INTERVAL '$add_seconds_server' SECOND) FROM $tableposts WHERE post_modified <= '$now' AND post_status = 'publish' ORDER BY post_modified DESC LIMIT 1");
     137                break;
     138        }
     139        $lastpostdate = get_lastpostdate($timezone);
     140        if ($lastpostdate > $lastpostmodified) {
     141            $lastpostmodified = $lastpostdate;
     142        }
     143        $cache_lastpostmodified[$timezone] = $lastpostmodified;
     144    } else {
     145        $lastpostmodified = $cache_lastpostmodified[$timezone];
    118146    }
    119147    return $lastpostmodified;
Note: See TracChangeset for help on using the changeset viewer.