archive_page

Definition

archive_page($year = 0, $month = 0, $day = 0)
modules/archive.module, line 215

Description

Menu callback; lists all nodes posted on a given date.

Code

<?php
function archive_page($year = 0, $month = 0, $day = 0) {
  global $user;

  $output = '';
  $op = $_POST['op'];
  $edit = $_POST['edit'];

  if ($op == t('Show')) {
    $year = $edit['year'];
    $month = $edit['month'];
    $day = $edit['day'];
  }

  $date = mktime(0, 0, 0, $month, $day, $year) - $user->timezone;
  $date_end = mktime(0, 0, 0, $month, $day + 1, $year) - $user->timezone;

  // Prepare the values of the form fields.
  $years = drupal_map_assoc(range(2000, date('Y')));
  $months = array(1 => t('January'), 2 => t('February'), 3 => t('March'), 4 => t('April'), 5 => t('May'), 6 => t('June'), 7 => t('July'), 8 => t('August'), 9 => t('September'), 10 => t('October'), 11 => t('November'), 12 => t('December'));
  $days = drupal_map_assoc(range(0, 31));

  $start = '<div class="container-inline">';
  $start .= form_select('', 'year', ($year ? $year : date('Y')), $years). form_select('', 'month', ($month ? $month : date('m')), $months) . form_select('', 'day', ($day ? $day : date('d')), $days) . form_submit(t('Show'));
  $start .= '</div>';
  $output .= form($start);

  if ($year && $month && $day) {
    // Fetch nodes for the selected date, if one was specified.
    $sql = 'SELECT n.nid, n.created FROM {node} n WHERE n.status = 1 AND n.created > %d AND n.created < %d ORDER BY n.created';
    $sql = db_rewrite_sql($sql);
    $result = db_query_range($sql, $date, $date_end, 0, 20);

    while ($nid = db_fetch_object($result)) {
      $output .= node_view(node_load(array('nid' => $nid->nid)), 1);
    }
  }
  print theme('page', $output);
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.