function archive_page in Archive 6
Same name and namespace in other branches
- 5 archive.module \archive_page()
- 7.2 archive.pages.inc \archive_page()
- 7 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 15
Code
function archive_page($type = 'all', $year = 0, $month = 0, $day = 0) {
// Argument validation, should be a valid node type and numeric.
$node_types = node_get_types();
if ($type != 'all' && !isset($node_types[$type]) || !is_numeric($year) || !is_numeric($month) || $month > 12 || !is_numeric($day) || $day > 31) {
return MENU_NOT_FOUND;
}
// 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', $type, $year, $month, $day));
// Check that there're nodes we can display.
$nodes = db_result(db_query(db_rewrite_sql("SELECT COUNT(1) FROM {node} n WHERE n.status = 1 AND n.type IN ('" . implode("', '", variable_get('archive_type_filters', array())) . "')")));
if (!$nodes && $type == 'all' && $year == 0 && $month == 0 && $day == 0) {
return t('No content found.');
}
drupal_add_css(drupal_get_path('module', 'archive') . '/archive.css');
$date = _archive_date($type, $year, $month, $day);
$output = theme('archive_navigation', $type, $date);
$nodes = variable_get('default_nodes_main', 10);
$query = _archive_query($type, $date);
$result = pager_query(db_rewrite_sql(array_shift($query)), $nodes, 0, null, $query);
$found_rows = false;
$node_date = 0;
while ($o = db_fetch_object($result)) {
$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 = date('Y', $node_created);
$last_year = date('Y', $node_date);
if ($created_year != $last_year) {
$separators['year'] = 1;
}
}
// Print month separaters
if (!$month) {
$created_month = date('n', $node_created);
$last_month = date('n', $node_date);
if ($created_month != $last_month) {
$separators['month'] = 1;
}
}
// Print day separaters
if (!$day) {
$created_day = date('j', $node_created);
$last_day = date('j', $node_date);
if ($created_day != $last_day) {
$separators['day'] = 1;
}
}
$output .= theme('archive_separator', $node_created, $separators);
$output .= node_view($node, true);
$found_rows = true;
$node_date = $node->created + $date->tz;
}
if ($found_rows) {
$output .= theme('pager', null, $nodes);
}
else {
if ($date->days[$date->day]) {
drupal_goto(_archive_url($type, $date->year, $date->month, $date->day));
}
else {
if ($date->months[$date->month]) {
drupal_goto(_archive_url($type, $date->year, $date->month));
}
else {
if ($date->years[$date->year]) {
drupal_goto(_archive_url($type, $date->year));
}
else {
drupal_goto(_archive_url($type));
}
}
}
}
return $output;
}