', $after='' ) {
$result = false;
// if the Plugin Output Cache is installed we can cheat...
if (defined('POC_CACHE')) {
$key = 'c_a'.$style.$before.$after;
$cache = new POC_Cache();
$cache->timer_start();
$result = $cache->fetch($key);
if ($result) $cache_time = sprintf('', 1000 * $cache->timer_stop());
}
// ... otherwise we do it the hard way
if (false === $result) {
$result = utf8_encode(get_compact_archive($style, $before, $after));
if (defined('POC_CACHE')) $cache->store($key, $result);
}
echo $result;
if (defined('POC_CACHE')) echo $cache_time;
}
/********************************************************************************************************
Stuff below this point is not meant to be used directly
*********************************************************************************************************/
function get_compact_archive( $style='numeric', $before='
', $after='' ) {
global $wpdb, $wp_version;
setlocale(LC_ALL,WPLANG); // set localization language
$below21 = version_compare($wp_version, '2.1','<');
// WP 2.1 changed the way post_status and post_type fields work
if ($below21) {
$time_difference = get_settings('gmt_offset');
$now = gmdate("Y-m-d H:i:s",(time()+($time_difference*3600)));
$year_results = $wpdb->get_results("SELECT distinct year(post_date) as year
FROM $wpdb->posts
WHERE post_status='publish'
AND post_password=''
AND post_date <= '$now'
ORDER BY year desc");
} else {
$year_results = $wpdb->get_results("SELECT distinct year(post_date) as year
FROM $wpdb->posts
WHERE post_status='publish'
AND post_password=''
AND post_type='post'
ORDER BY year desc");
}
if (!$year_results) {
return $before.__('Archive is empty').$after;
}
$result = '';
foreach ($year_results as $year_result) {
$year = $year_result->year;
if ($year == 0) continue;
$result .= $before.''.$year.': ';
for ( $month = 1; $month <= 12; $month += 1) {
if ($below21) {
$month_has_posts = $wpdb->get_var("SELECT id
FROM $wpdb->posts
WHERE year(post_date)='$year'
AND month(post_date)='$month'
AND post_status='publish'
AND post_password=''
AND post_date <= '$now'
ORDER BY id desc");
} else {
$month_has_posts = $wpdb->get_var("SELECT id
FROM $wpdb->posts
WHERE year(post_date)='$year'
AND month(post_date)='$month'
AND post_status='publish'
AND post_password=''
AND post_type='post'
ORDER BY id desc");
}
$dummydate = strtotime("$month/01/2001");
// get the month name; strftime() localizes
$month_name = strftime("%B", $dummydate);
switch ($style) {
case 'initial':
$month_abbrev = $month_name[0]; // the inital of the month
break;
case 'block':
$month_abbrev = strftime("%b", $dummydate); // get the short month name; strftime() localizes
break;
case 'numeric':
$month_abbrev = strftime("%m", $dummydate); // get the month number, e.g., '04'
break;
default:
$month_abbrev = $month_name[0]; // the inital of the month
}
if ($month_has_posts) {
$result .= ''.$month_abbrev.' ';
} else {
$result .= ''.$month_abbrev.' ';
}
}
$result .= $after."\n";
}
return $result;
}
?>