From b629afe5c10970a283c4f6dfc0749621190eaf44 Mon Sep 17 00:00:00 2001 From: saxmatt Date: Mon, 3 Nov 2003 07:30:04 +0000 Subject: [PATCH] Added get_calendar function. Not finished. git-svn-id: http://svn.automattic.com/wordpress/trunk@508 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- b2-include/b2template.functions.php | 115 ++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/b2-include/b2template.functions.php b/b2-include/b2template.functions.php index 616115e8d..f486d5506 100644 --- a/b2-include/b2template.functions.php +++ b/b2-include/b2template.functions.php @@ -227,6 +227,121 @@ function get_archives($type='', $limit='', $format='html', $before = "", $after } } } + +function get_calendar() { +// Quick check. If we have no posts at all, abort! +if (!$posts) { + $gotsome = $wpdb->get_var("SELECT ID from $tableposts WHERE post_status = 'publish' AND post_category > 0 ORDER BY post_date DESC LIMIT 1"); + if (!$gotsome) + return; +} + +$w = ''.intval($HTTP_GET_VARS['w']); +$time_difference = get_settings('time_difference'); + +// Let's figure out when we are +if (!empty($monthnum) && !empty($year)) { + $thismonth = ''.intval($monthnum); + $thisyear = ''.intval($year); +} elseif (!empty($w)) { + // We need to get the month from MySQL + $thisyear = ''.intval(substr($m, 0, 4)); + $d = (($w - 1) * 7) + 6; //it seems mysqls weeks disagree with php's + $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')"); +} elseif (!empty($m)) { + $calendar = substr($m, 0, 6); + $thisyear = ''.intval(substr($m, 0, 4)); + if (strlen($m) < 6) { + $thismonth = '01'; + } else { + $thismonth = ''.intval(substr($m, 4, 2)); + } +} else { + $thisyear = intval(date('Y', time()+($time_difference * 3600))); + $thismonth = intval(date('m', time()+($time_difference * 3600))); +} + +$unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); + +// Get the next and previous month and year with at least one post +$previous = $wpdb->get_row("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year + FROM $tableposts + WHERE post_date < '$thisyear-$thismonth-01' + ORDER BY post_date DESC + LIMIT 1"); +$next = $wpdb->get_row("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year + FROM $tableposts + WHERE post_date > '$thisyear-$thismonth-01' AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) + ORDER BY post_date ASC + LIMIT 1 "); + +echo ' + + + + + + + + + + + + + + + '; + +if ($previous) { + echo ''; +} + +echo ''; + +if ($next) { + echo ''; +} + +echo ' + + + + '; + +// Get days with posts +$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) + FROM wp_posts WHERE MONTH(post_date) = $thismonth + AND YEAR(post_date) = $thisyear + AND post_status = 'publish' + AND post_date < '" . date("Y-m-d H:i:s", (time() + ($time_difference * 3600))), ARRAY_N); + +// TODO: Make days with posts linked + +// See how much we should pad in the beginning +$pad = intval(date('w', $unixmonth)); +if (0 != $pad) echo "\n\t"; + +$daysinmonth = intval(date('t', $unixmonth)); +for ($day = 1; $day <= $daysinmonth; ++$day) { + if ($newrow) echo "\n\n "; + $newrow = false; + echo "\n\t"; + if (6 == date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))) $newrow = true; +} +$pad = 7 - date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear)); +if (0 != $pad) echo "\n\t"; + +echo "\n \n\n
' . $month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '
SunMonTueWedThuFriSat
« ' . substr($month[zeroise($previous->month, 2)], 0, 3) . ''; +} else { + echo '« » ' . substr($month[zeroise($next->month, 2)], 0, 3) . ''; +} else { + echo '»
 
$day 
"; +} + /***** // About-the-blog tags *****/