/[drupal]/contributions/modules/archive/archive.module
ViewVC logotype

Diff of /contributions/modules/archive/archive.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.15 by susurrus, Sat Aug 25 05:49:12 2007 UTC revision 1.16 by susurrus, Sun Aug 26 01:23:18 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: archive.module,v 1.15 2007/08/25 05:49:12 susurrus Exp $
3    
4  /**  /**
5   * Implementation of hook_help().   * Implementation of hook_help().
# Line 10  function archive_help($path, $arg) { Line 10  function archive_help($path, $arg) {
10        $output = '<p>'. t('The archive module provides a suggested menu item, which shows a page allowing content to be filtered by date and node type. The date selectors allow visitors to view content published in any given year, month or day. The node type selectors allow visitors to view content of all node types or only specific ones.') .'</p>';        $output = '<p>'. t('The archive module provides a suggested menu item, which shows a page allowing content to be filtered by date and node type. The date selectors allow visitors to view content published in any given year, month or day. The node type selectors allow visitors to view content of all node types or only specific ones.') .'</p>';
11        $output .= t('<p>You can</p>        $output .= t('<p>You can</p>
12  <ul>  <ul>
13  <li>view your <a href="%archive">archive page</a>.</li>  <li>view your <a href="!archive">archive page</a>.</li>
14  <li><a href="%admin-menu">enable or disable the archive menu item</a>.</li>  <li><a href="!admin-menu">enable or disable the archive menu item</a>.</li>
15  </ul>  </ul>
16  ', array('%archive' => url('archive'), '%admin-menu' => url('admin/menu')));  ', array('!archive' => url('archive'), '!admin-menu' => url('admin/menu')));
17        $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%archive">Archive page</a>.', array('%archive' => 'http://drupal.org/handbook/modules/archive/')) .'</p>';        $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="http://drupal.org/handbook/modules/archive/">Archive page</a>.') .'</p>';
18        return $output;        return $output;
19    }    }
20  }  }
# Line 73  function archive_theme() { Line 73  function archive_theme() {
73   */   */
74    
75  function theme_archive_block_calendar($timestamp) {  function theme_archive_block_calendar($timestamp) {
76    $title = format_date($timestamp, 'custom', "F Y");    include_once('archive.pages.inc');
77    $year = date('Y',$timestamp);    $title = format_date($timestamp, 'custom', 'F Y');
78    $month = date('m',$timestamp);    $year = date('Y', $timestamp);
79    $date = _archive_date($year,$month,1);    $month = date('n', $timestamp);
80    $have_nodes = _archive_days($date);    $date = _archive_date($year, $month, 1);
81    $num_days = date('t',$timestamp);    $have_nodes = _archive_post_count('day', 'all', $date);
82    // this is inefficient but necessary to determine the start of the month:    $num_days = date('t', $timestamp);
   $start = strtotime(date("Y-m-01",$timestamp));  
   $weekday = date('N',$start) - 1;  
   // and this is legacy for making it work in PHP < 5.1.0 ('N' didn't exist)  
   // TODO: remove this if minimum PHP version becomes 5.1+  
   //var_dump($weekday);  
   if ($weekday < 0) {  
     $weekdays=array('Mon' => 0,'Tue' => 1,'Wed' => 2,'Thu' => 3,'Fri' => 4,'Sat' => 5,'Sun' => 6);  
     $weekday = $weekdays[date('D',$start)];  
   }  
83    $prev['month'] = ($month>1)?$month-1:12;    $prev['month'] = ($month>1)?$month-1:12;
84    $prev['year'] = ($month>1)?$year:$year-1;    $prev['year'] = ($month>1)?$year:$year-1;
85    $next['month'] = ($month<12)?$month+1:1;    $next['month'] = ($month<12)?$month+1:1;
86    $next['year'] = ($month<12)?$year:$year-1;    $next['year'] = ($month<12)?$year:$year-1;
87    $rows[0][] = array('data' => l('&laquo;', _archive_url($date,$prev['year'],$prev['month']),array(),NULL,NULL,NULL,true), 'colspan' => 2); // avoid escaping entity    $rows[] = array(
88    $rows[0][] = array('data' => l($title, _archive_url($date,$year,$month)), 'colspan' => 3);      array('data' => l('&laquo;', _archive_url('all', $date, $prev['year'], $prev['month']), array('html' => TRUE)), 'colspan' => 2), // avoid escaping entity
89    $rows[0][] = array('data' => l('&raquo;', _archive_url($date,$next['year'],$next['month']),array(),NULL,NULL,NULL,true), 'colspan' => 2);      array('data' => l($title, _archive_url('all', $date, $year, $month)), 'colspan' => 3, 'style' => 'text-align:center'),
90    $rows[1] = array('M', 'T', 'W', 'Th', 'F', 'S', 'Su');      array('data' => l('&raquo;', _archive_url('all', $date, $next['year'], $next['month']), array('html' => TRUE)), 'colspan' => 2, 'style' => 'text-align:right')
91    for ($i =- $weekday + 1;$i <= $num_days;$i++) {    );
92      if (($i-$weekday)%7 == 0 && $i > 0) {    $rows[] = array('Su', 'M', 'T', 'W', 'Th', 'F', 'S');
93        $days_row = array();    // this is inefficient but necessary to determine the start of the month:
94      }    $start = strtotime(date('Y-m-01', $timestamp));
95      $weekday = date('w', $start);
96      $days_row = array();
97      for ($j = 0;$j<$weekday;$j++) {
98        $days_row[] = '';
99      }
100      for ($i = -$weekday;$i <= $num_days+$weekday+(7-($num_days+$weekday)%7);$i++) {
101      if ($i > 0) {      if ($i > 0) {
102        if ($have_nodes[$i]){        if (($i+$weekday-1)%7 == 0) {
103          $days_row[] = l($i, _archive_url($date, $year, $month, $i), array('title' => t("!n article". ($have_nodes[$i]>1?'s':''),array('!n'=>$have_nodes[$i]))));          $rows[] = $days_row;
104        } else {          $days_row = array();
105          }
106          if (array_key_exists($i, $date->days)) {
107            $days_row[] = l($i, _archive_url('all', $date, $year, $month, $i), array('attributes' => array('title' => format_plural($date->days[$i], '1 node', '@count nodes'))));
108          }
109          elseif ($i <= $num_days) {
110          $days_row[] = $i;          $days_row[] = $i;
111        }        }
112      }        else {
113      else{          $days_row[] = '';
114        $rows[] = $days_row;        }
115      }      }
116    }    }
117    var_dump($rows);    return theme('table', array(), $rows);
   $out .= theme('table', array(), $rows);  
   return $out;  
118  }  }
119    
120    
# Line 124  function theme_archive_block_calendar($t Line 124  function theme_archive_block_calendar($t
124    
125  function archive_block($op = 'list', $delta = 0) {  function archive_block($op = 'list', $delta = 0) {
126    if ($op == 'list') {    if ($op == 'list') {
127      $blocks[0] = array('info' => t("Calendar month with archive links"));      $blocks[0] = array('info' => t('Current calendar month with archive links'));
128      return $blocks;      return $blocks;
129    }    }
130    else if ($op == 'view') {    else if ($op == 'view') {
131      global $archive_block_time;      global $_archive_block_time;
132      if (!$archive_block_time) $archive_block_time = time();      if (!$_archive_block_time) {
133          $_archive_block_time = time();
134        }
135      $block = array(      $block = array(
136        'subject' => t("Archives"),        'subject' => t('Archives'),
137        'content' => theme('archive_block_calendar', $archive_block_time),        'content' => theme('archive_block_calendar', $_archive_block_time),
138      );      );
139      return $block;      return $block;
140    }    }
# Line 147  function archive_block($op = 'list', $de Line 149  function archive_block($op = 'list', $de
149    
150  function archive_nodeapi($node, $op) {  function archive_nodeapi($node, $op) {
151    if (!defined('ARCHIVE_NODE_LOADED') && $op == 'view') {    if (!defined('ARCHIVE_NODE_LOADED') && $op == 'view') {
152      global $archive_block_time;      global $_archive_block_time;
153      $archive_block_time = $node->created;      $_archive_block_time = $node->created;
154      define('ARCHIVE_NODE_LOADED',true); // don't do this for any additional nodes on the page      define('ARCHIVE_NODE_LOADED', true); // don't do this for any additional nodes on the page
155    }    }
156  }  }
157    
158  function archive_init() {  function archive_init() {
159    if (arg(0) == 'archive' && arg(1) != '') {    if (arg(0) == 'archive' && arg(1) != '') {
160      global $archive_block_time;      global $_archive_block_time;
161      $year = arg(1);      $year = arg(1);
162      $month = arg(2)?arg(2):1;      $month = arg(2)?arg(2):1;
163      $day = arg(3)?arg(3):1;      $day = arg(3)?arg(3):1;
164      $time = strtotime("$year-$month-$day");      $time = strtotime("$year-$month-$day");
165      if ($time != -1){      if ($time != -1) {
166        $archive_block_time=$time;        $_archive_block_time = $time;
167      }      }
168    }    }
169  }  }

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.3