/[drupal]/contributions/modules/archive/archive.pages.inc
ViewVC logotype

Diff of /contributions/modules/archive/archive.pages.inc

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

revision 1.3 by susurrus, Sat Aug 25 05:49:12 2007 UTC revision 1.4 by susurrus, Sun Aug 26 01:23:18 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: archive.pages.inc,v 1.3 2007/08/25 05:49:12 susurrus Exp $
3    
4  /**  /**
5   * * Fetch nodes for the selected date, or current date if none selected.   * * Fetch nodes for the selected date, or current date if none selected.
# Line 37  function _archive_page($type = 'all', $y Line 37  function _archive_page($type = 'all', $y
37    if ($found_rows) {    if ($found_rows) {
38      $output .= theme('pager', NULL, $nodes);      $output .= theme('pager', NULL, $nodes);
39    }    }
40    elseif ($date->days[$date->day] > 0) {    elseif (array_key_exists($date->day, $date->days) && $date->days[$date->day] > 0) {
41      drupal_goto(_archive_url('all', $date->year, $date->month, $date->day));      drupal_goto(_archive_url('all', $date->year, $date->month, $date->day));
42    }    }
43    elseif ($date->months[$date->month] > 0) {    elseif (array_key_exists($date->month, $date->months) && $date->months[$date->month] > 0) {
44      drupal_goto(_archive_url('all', $date->year, $date->month));      drupal_goto(_archive_url('all', $date->year, $date->month));
45    }    }
46    elseif ($date->year[$date->year] > 0) {    elseif (array_key_exists($date->year, $date->years) && $date->years[$date->year] > 0) {
47      drupal_goto(_archive_url('all', $date->year));      drupal_goto(_archive_url('all', $date->year));
48    }    }
49      else {
50        drupal_goto('archive');
51      }
52    
53    return $output;    return $output;
54  }  }
# Line 58  function _archive_page($type = 'all', $y Line 61  function _archive_page($type = 'all', $y
61   *   Number of year   *   Number of year
62   * @param $month   * @param $month
63   *   Number of month   *   Number of month
64   * @param $month   * @param $day
65   *   Number of day   *   Number of day
66   * @return   * @return
67   *   A date object with GMT date values and a timezone value   *   A date object with GMT date values and a timezone value
# Line 132  function _archive_query($type, $date) { Line 135  function _archive_query($type, $date) {
135   * @return   * @return
136   *    A SQL string   *    A SQL string
137   */   */
138  function _archive_types_sql_string($type){  function _archive_types_sql_string($type) {
139    // Validate type and specify node types to include    // Validate type and specify node types to include
140    $final_types = '';    $final_types = '';
141    if (_archive_validate_type($type) && $type != 'all') {    if (_archive_validate_type($type) && $type != 'all') {
# Line 151  function _archive_types_sql_string($type Line 154  function _archive_types_sql_string($type
154      }      }
155    }    }
156    if (strlen($final_types) > 0) {    if (strlen($final_types) > 0) {
157      $final_types = 'AND n.type IN ("' . $final_types . '") ';      $final_types = 'AND n.type IN ("'. $final_types .'") ';
158    }    }
159    return $final_types;    return $final_types;
160  }  }
# Line 168  function _archive_types_sql_string($type Line 171  function _archive_types_sql_string($type
171   */   */
172  function _archive_post_count($timeframe, $type, $date) {  function _archive_post_count($timeframe, $type, $date) {
173    $final_types = _archive_types_sql_string($type);    $final_types = _archive_types_sql_string($type);
174    $result = db_fetch_object(db_query(db_rewrite_sql('SELECT MIN(n.created) AS min_date, MAX(n.created) AS max_date FROM {node} n WHERE n.status = 1 ' . $final_types)));    $result = db_fetch_object(db_query(db_rewrite_sql('SELECT MIN(n.created) AS min_date, MAX(n.created) AS max_date FROM {node} n WHERE n.status = 1 '. $final_types)));
175    $result->min_date += $date->tz;    $result->min_date += $date->tz;
176    $result->max_date += $date->tz;    $result->max_date += $date->tz;
177    $first_date = new DateTime("@{$result->min_date}");    $first_date = new DateTime("@{$result->min_date}");
# Line 199  function _archive_post_count($timeframe, Line 202  function _archive_post_count($timeframe,
202    }    }
203    $start_timeframe = $first_date;    $start_timeframe = $first_date;
204    $with_posts = array();    $with_posts = array();
205    while ($start_timeframe->format($mod) <= $last_date->format($mod)){    while ($start_timeframe->format($mod) <= $last_date->format($mod)) {
206      $end_timeframe = clone $start_timeframe;      $end_timeframe = clone $start_timeframe;
207      $end_timeframe->modify('+1 '. $timeframe);      $end_timeframe->modify('+1 '. $timeframe);
208      $sql = db_rewrite_sql('SELECT COUNT(*) AS count FROM {node} n WHERE n.status = 1 ' . $final_types . 'AND n.created >= %d AND n.created < %d');      $sql = db_rewrite_sql('SELECT COUNT(*) AS count FROM {node} n WHERE n.status = 1 '. $final_types .'AND n.created >= %d AND n.created < %d');
209      $result = db_result(db_query($sql, $start_timeframe->format('U') - $date->tz, $end_timeframe->format('U') - $date->tz));      $result = db_result(db_query($sql, $start_timeframe->format('U') - $date->tz, $end_timeframe->format('U') - $date->tz));
210      if ($result) {      if ($result) {
211        $with_posts[$start_timeframe->format($mod)] = (int)$result;        $with_posts[$start_timeframe->format($mod)] = (int)$result;
# Line 247  function _archive_node_types($date) { Line 250  function _archive_node_types($date) {
250      $start = gmmktime(0, 0, 0, 1, 1, $date->year);      $start = gmmktime(0, 0, 0, 1, 1, $date->year);
251      $end   = gmmktime(0, 0, 0, 1, 1, $date->year + 1);      $end   = gmmktime(0, 0, 0, 1, 1, $date->year + 1);
252    }    }
253    $result = db_query('SELECT t.type, t.name, COUNT(n.nid) AS node_count FROM {node} n INNER JOIN {node_type} t ON t.type = n.type WHERE n.status = 1 AND t.type IN ("' . join(array_keys($types), '", "') . '") AND n.created BETWEEN %d AND %d GROUP BY n.type ORDER BY n.created', $start - $date->tz, $end - $date->tz);    $result = db_query('SELECT t.type, t.name, COUNT(n.nid) AS node_count FROM {node} n INNER JOIN {node_type} t ON t.type = n.type WHERE n.status = 1 AND t.type IN ("'. join(array_keys($types), '", "') .'") AND n.created BETWEEN %d AND %d GROUP BY n.type ORDER BY n.created', $start - $date->tz, $end - $date->tz);
254    
255    $n_types['all'] = array('count' => 0,    $n_types['all'] = array('count' => 0,
256                            'name'  => t('All'));                            'name'  => t('All'));
# Line 342  function _archive_validate_type($type) { Line 345  function _archive_validate_type($type) {
345   *   *
346   * @param $type   * @param $type
347   *    The node type to use if valid   *    The node type to use if valid
348     * @param $date
349     *    A date object returned from _archive_date
350   * @param $y   * @param $y
351   *    The year to use if valid   *    The year to use if valid
352   * @param $m   * @param $m
# Line 355  function _archive_url($type, $date, $y = Line 360  function _archive_url($type, $date, $y =
360    $url = 'archive';    $url = 'archive';
361    
362    if (_archive_validate_type($type)) {    if (_archive_validate_type($type)) {
363      $url .= '/' . $type;      $url .= '/'. $type;
364    }    }
365    else {    else {
366      $url .= '/all';      $url .= '/all';
367    }    }
368    
369    if (_archive_validate_year($y)) {    if (_archive_validate_year($y)) {
370      $url .= '/'. $y;      $url .= '/'. $y;
371      if (_archive_validate_month($m)) {      if (_archive_validate_month($m)) {
# Line 435  function theme_archive_navigation_years( Line 440  function theme_archive_navigation_years(
440    for ($year = min($all_years); $year <= max($all_years); $year++) {    for ($year = min($all_years); $year <= max($all_years); $year++) {
441    
442      if ($year == $date->year) {      if ($year == $date->year) {
443        $output .= '<li class="selected">'. l($year, _archive_url($type, $date, $year)). "</li>\n";        $output .= '<li class="selected">'. l($year, _archive_url($type, $date, $year)) ."</li>\n";
444      }      }
445      else {      else {
446        $output .= "<li>$name</li>\n";        $output .= "<li>$name</li>\n";
# Line 452  function theme_archive_navigation_years( Line 457  function theme_archive_navigation_years(
457   */   */
458  function theme_archive_navigation_months($type, $date) {  function theme_archive_navigation_months($type, $date) {
459    $output = "<ul id=\"archive-months\">\n";    $output = "<ul id=\"archive-months\">\n";
460      $curr_month = date('n', time());
461      $curr_year = date('Y', time());
462    foreach (range(1, 12) as $month) {    foreach (range(1, 12) as $month) {
463      $posts = !empty($date->months[$month]) ? $date->months[$month] : 0;      $posts = !empty($date->months[$month]) ? $date->months[$month] : 0;
464      $class = ($month == $date->month) ? ' class="selected"' : '';      $class = '';
465      $name = t(gmdate('M', gmmktime(0, 0, 0, $month, 1, $date->year)));      if ($month == $date->month) {
466      $output .= "<li$class>". ($posts > 0 ? l($name, _archive_url($type, $date, 0, $month), array('attributes' => array('title' => format_plural($posts, "1 post", "@count posts")))) : $name) ."</li>\n";        $class = ' class="selected"';
467        }
468        elseif ($curr_year == $date->year && $month > $curr_month) {
469          $class = ' class="future"';
470        }
471        $month_names = array('', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
472        $output .= "<li$class>". ($posts > 0 ? l($month_names[$month], _archive_url($type, $date, 0, $month), array('attributes' => array('title' => format_plural($posts, "1 post", "@count posts")))) : $month_names[$month]) ."</li>\n";
473    }    }
474    $output .= "</ul>\n";    $output .= "</ul>\n";
475    return $output;    return $output;
# Line 470  function theme_archive_navigation_days($ Line 483  function theme_archive_navigation_days($
483    $output = "";    $output = "";
484    $day_stop = gmdate('t', gmmktime(0, 0, 0, $date->month, 1, $date->year));    $day_stop = gmdate('t', gmmktime(0, 0, 0, $date->month, 1, $date->year));
485    $output = "<ul id=\"archive-days\">\n";    $output = "<ul id=\"archive-days\">\n";
486      $curr_month = date('n', time());
487      $curr_year = date('Y', time());
488      $curr_day = date('j', time());
489    for ($day = 1; $day <= $day_stop; $day++) {    for ($day = 1; $day <= $day_stop; $day++) {
490      $posts = array_key_exists($day, $date->days) ? $date->days[$day] : 0;      $posts = array_key_exists($day, $date->days) ? $date->days[$day] : 0;
491      $class = ($day == $date->day) ? ' class="selected"' : '';      $class = '';
492        if ($day == $date->day) {
493          $class = ' class="selected"';
494        }
495        elseif ($curr_year == $date->year && $curr_month == $date->month && $day > $curr_day) {
496          $class = ' class="future"';
497        }
498      $output .= "<li$class>". ($posts ? l($day, _archive_url($type, $date, 0, 0, $day), array('attributes' => array("title" => format_plural($posts, "1 post", "@count posts")))) : $day) ."</li>\n";      $output .= "<li$class>". ($posts ? l($day, _archive_url($type, $date, 0, 0, $day), array('attributes' => array("title" => format_plural($posts, "1 post", "@count posts")))) : $day) ."</li>\n";
499    }    }
500    $output .= "</ul>\n";    $output .= "</ul>\n";

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.3