added a timezone argument to get�_lastpost*()

git-svn-id: https://develop.svn.wordpress.org/trunk@952 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
michelvaldrighi 2004-02-28 17:51:41 +00:00
parent 8d2b1fdee4
commit 73817b4edc
1 changed files with 40 additions and 12 deletions

View File

@ -95,26 +95,54 @@ function get_weekstartend($mysqlstring, $start_of_week) {
return $week; return $week;
} }
function get_lastpostdate() { function get_lastpostdate($timezone = 'server') {
global $tableposts, $cache_lastpostdate, $use_cache, $pagenow, $wpdb; global $tableposts, $cache_lastpostdate, $use_cache, $pagenow, $wpdb;
if ((!isset($cache_lastpostdate)) OR (!$use_cache)) { $add_seconds_blog = get_settings('gmt_offset') * 3600;
$now = gmdate('Y-m-d H:i:s'); $add_seconds_server = date('Z');
$lastpostdate = $wpdb->get_var("SELECT post_date FROM $tableposts WHERE post_date <= '$now' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); $now = gmdate('Y-m-d H:i:s');
$cache_lastpostdate = $lastpostdate; if ((!isset($cache_lastpostdate[$timezone])) OR (!$use_cache)) {
switch(strtolower($timezone)) {
case 'gmt':
$lastpostdate = $wpdb->get_var("SELECT post_date FROM $tableposts WHERE post_date <= '$now' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
break;
case 'blog':
$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");
break;
case 'server':
$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");
break;
}
$cache_lastpostdate[$timezone] = $lastpostdate;
} else { } else {
$lastpostdate = $cache_lastpostdate; $lastpostdate = $cache_lastpostdate[$timezone];
} }
return $lastpostdate; return $lastpostdate;
} }
function get_lastpostmodified() { function get_lastpostmodified($timezone = 'server') {
global $tableposts, $cache_lastpostmodified, $use_cache, $pagenow, $wpdb; global $tableposts, $cache_lastpostmodified, $use_cache, $pagenow, $wpdb;
if ((!isset($cache_lastpostmodified)) OR (!$use_cache)) { $add_seconds_blog = get_settings('gmt_offset') * 3600;
$now = gmdate('Y-m-d H:i:s'); $add_seconds_server = date('Z');
$lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $tableposts WHERE post_modified <= '$now' AND post_status = 'publish' ORDER BY post_modified DESC LIMIT 1"); $now = gmdate('Y-m-d H:i:s');
$cache_lastpostmodified = $lastpostmodified; if ((!isset($cache_lastpostmodified[$timezone])) OR (!$use_cache)) {
switch($timezone) {
case 'gmt':
$lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $tableposts WHERE post_modified <= '$now' AND post_status = 'publish' ORDER BY post_modified DESC LIMIT 1");
break;
case 'blog':
$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");
break;
case 'server':
$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");
break;
}
$lastpostdate = get_lastpostdate($timezone);
if ($lastpostdate > $lastpostmodified) {
$lastpostmodified = $lastpostdate;
}
$cache_lastpostmodified[$timezone] = $lastpostmodified;
} else { } else {
$lastpostmodified = $cache_lastpostmodified; $lastpostmodified = $cache_lastpostmodified[$timezone];
} }
return $lastpostmodified; return $lastpostmodified;
} }