function archive_page in Archive 7
Same name and namespace in other branches
- 5 archive.module \archive_page()
- 6 archive.pages.inc \archive_page()
- 7.2 archive.pages.inc \archive_page()
Fetch nodes for the selected date, or current date if none selected.
Parameters
$year: Number of year.
$month: Number of month.
$day: Number of day.
Return value
A string with the themed page.
1 string reference to 'archive_page'
- archive_menu in ./
archive.module - Implementation of hook_menu().
File
- ./
archive.pages.inc, line 20 - Pages for the archive module.
Code
function archive_page($type = 'all', $year = 0, $month = 0, $day = 0) {
// Make sure all values are secure.
$day = (int) $day;
$year = (int) $year;
$month = (int) $month;
if ($month < 0 || $month > 12) {
// Ensure that we have a proper array index later.
$month = 0;
}
if (!_archive_validate_type($type)) {
$type = 'all';
}
drupal_set_title(theme('archive_page_title', array(
'type' => $type,
'year' => $year,
'month' => $month,
'day' => $day,
)));
$date = _archive_date($type, $year, $month, $day);
$query = _archive_query($type, $date);
$nodes = variable_get('default_nodes_main', 10);
$result = $query
->extend('PagerDefault')
->limit($nodes)
->execute();
$nodes = $query
->countQuery()
->execute()
->fetchField();
drupal_add_css(drupal_get_path('module', 'archive') . '/archive.css');
$output = theme('archive_navigation', array(
'type' => $type,
'date' => $date,
));
if (!$nodes && $type == 'all') {
$output .= t('No content found.');
return $output;
}
$found_rows = FALSE;
$node_date = 0;
foreach ($result as $o) {
$node = node_load($o->nid);
$node_created = $node->created + $date->tz;
// Determine which separators are needed
$separators = array(
'year' => 0,
'month' => 0,
'day' => 0,
);
if (!$year) {
$created_year = format_date($node_created, 'custom', 'Y');
$last_year = format_date($node_date, 'custom', 'Y');
if ($created_year != $last_year) {
$separators['year'] = 1;
}
}
// Print month separaters
if (!$month) {
$created_month = format_date($node_created, 'custom', 'n');
$last_month = format_date($node_date, 'custom', 'n');
if ($created_month != $last_month) {
$separators['month'] = 1;
}
}
// Print day separaters
if (!$day) {
$created_day = format_date($node_created, 'custom', 'j');
$last_day = format_date($node_date, 'custom', 'j');
if ($created_day != $last_day) {
$separators['day'] = 1;
}
}
$output .= theme('archive_separator', array(
'date_created' => $node_created,
'separators' => $separators,
));
$output .= drupal_render(node_view($node, 'teaser'));
$found_rows = TRUE;
$node_date = $node->created + $date->tz;
}
if ($found_rows) {
$output .= theme('pager');
}
else {
if ($date->days[$date->day]) {
drupal_goto(_archive_url($type, $date->year, $date->month, $date->day));
}
elseif ($date->months[$date->month]) {
drupal_goto(_archive_url($type, $date->year, $date->month));
}
elseif ($date->years[$date->year]) {
drupal_goto(_archive_url($type, $date->year));
}
else {
drupal_goto(_archive_url($type));
}
}
return $output;
}