function theme_archive_block_calendar in Archive 7
Same name and namespace in other branches
- 5 archive.module \theme_archive_block_calendar()
- 6 archive.module \theme_archive_block_calendar()
- 7.2 archive.module \theme_archive_block_calendar()
Returns a single month as a calendar grid.
@todo Take the archive logic out to allow better theme-overloading of this function.
1 theme call to theme_archive_block_calendar()
File
- ./
archive.module, line 94 - Implements a block and page showing an archive of all site content.
Code
function theme_archive_block_calendar($variables) {
$the_date = explode(' ', format_date($variables['timestamp'], 'custom', 'F Y n t'));
$title = $the_date[0] . ' ' . $the_date[1];
$year = $the_date[1];
$month = $the_date[2];
$num_days = (int) $the_date[3];
// Get the number of days for the previous month for adding those dates
// to the block calendar. Store the month/year for the previous month
// so that we can find and link to archive pages in those extra days.
// We don't need to get days for the next month as we'll never need to fit
// the entire month into the block.
$prev_month = $month == 1 ? 12 : $month - 1;
$prev_year = $month == 1 ? $year - 1 : $year;
$num_days_prev = cal_days_in_month(CAL_GREGORIAN, $prev_month, $year);
$next_month = $month == 12 ? 1 : $month + 1;
$next_year = $month == 12 ? $year + 1 : $year;
$date = _archive_date('all', $year, $month);
$month_title = '';
if (isset($date->months[$month])) {
$month_title = l($title, _archive_url('all', $year, $month), array(
'title' => format_plural($date->months[format_date($variables['timestamp'], 'custom', 'n')], '1 post', '@count posts'),
));
}
else {
$month_title = $title;
}
// Build the week starting with
$first_day_of_week = variable_get('date_first_day', 0);
$week = array(
t('Sun'),
t('Mon'),
t('Tue'),
t('Wed'),
t('Thu'),
t('Fri'),
t('Sat'),
);
$day_headers = array();
for ($i = $first_day_of_week; $i < $first_day_of_week + 7; $i++) {
$day_headers[] = $week[$i % 7];
}
// Grab the first day of the month using the user's timezone
list($start_year, $start_month) = explode(' ', format_date($variables['timestamp'], 'custom', 'Y m'));
$start = gmmktime(0, 0, 0, (int) $start_month, 1, (int) $start_year);
$weekday = gmdate('w', $start);
if ($first_day_of_week) {
$weekday = ($weekday ? $weekday : 7) - $first_day_of_week;
}
$days_row = array();
// From http://www.theadminzone.com/forums/showthread.php?t=17490
for ($i = 1 - $weekday; $i <= ceil(($weekday + $num_days) / 7) * 7; $i++) {
if ($i > 0) {
if (array_key_exists($i, $date->days)) {
$days_row[] = l($i, _archive_url('all', $year, $month, $i), array(
'attributes' => array(
'title' => format_plural($date->days[$i], '1 post', '@count posts'),
),
));
}
elseif ($i <= $num_days) {
$days_row[] = $i;
}
else {
$curr_cal_date = $i - $num_days;
if (isset($date->next_month_days[$curr_cal_date])) {
$data = l($curr_cal_date, _archive_url('all', $next_year, $next_month, $curr_cal_date), array(
'attributes' => array(
'title' => format_plural($date->next_month_days[$curr_cal_date], '1 post', '@count posts'),
),
));
}
else {
$data = $curr_cal_date;
}
$days_row[] = array(
'data' => $data,
'class' => 'out-of-month',
);
}
// Add the week table row we just created if we've finished it
if (($i + $weekday) % 7 == 0) {
$rows[] = $days_row;
$days_row = array();
}
}
else {
$curr_cal_date = $num_days_prev + $i;
if (isset($date->prev_month_days[$curr_cal_date])) {
$data = l($curr_cal_date, _archive_url('all', $prev_year, $prev_month, $curr_cal_date), array(
'attributes' => array(
'title' => format_plural($date->prev_month_days[$curr_cal_date], '1 post', '@count posts'),
),
));
}
else {
$data = $curr_cal_date;
}
$days_row[] = array(
'data' => $data,
'class' => 'out-of-month',
);
}
}
return theme('table', array(
'header' => $day_headers,
'rows' => $rows,
'caption' => $month_title,
));
}