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

Diff of /contributions/modules/week/week.module

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

revision 1.20, Thu Aug 6 22:52:05 2009 UTC revision 1.21, Tue Nov 10 03:12:13 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /* $Id: week.module,v 1.1 2008/10/06 22:16:15 Earl Exp $ */  /* $Id: week.module,v 1.19.2.1.2.8 2009/11/07 17:37:30 prometheus6 Exp $ */
3  define('ARCHIVEROOTBEFORETYPE', 1);  define('ARCHIVEROOTBEFORETYPE', 1);
4  define('TYPEBEFOREARCHIVEROOT', 2);  define('TYPEBEFOREARCHIVEROOT', 2);
5    
 function week_help($section) {  
   switch($section) {  
     case 'admin/settings/week':  
       $output = 'Create block containing a list of weekly archives, collectively or by node type.';  
       break;  
     case 'admin/build/modules#description':  
       $output = 'Create block containing a list of weekly archives, collectively or by node type.';  
       break;  
     default:  
       $output = '';  
       break;  
   }  
   return $output;  
 }  
   
6  /**  /**
7   * Generate a page listing links to all the archives that can be generated   * Calculate beginning and end dates for a given year and week
8   *   * @param $date_data must have at least $date_data['year'] and $date_data['week'] populated
  * @return string  
9   */   */
10  function week_link_page() {  function _week_week_data(&$date_data) {
11    $week_include_node_type = variable_get('week_include_node_type', array_keys(node_get_types('names')));    //  This is a mess because there's no function that gives you the first day of the week for a given year and week combination.
12    $query = week_block_links_query($week_include_node_type);  
13    $weeklist = db_query(db_rewrite_sql($query, 'n', 'nid'));  
14    $block_content = array();    //  Drupal allows you to set any day as the first day of the week. However, the ISO8601 standard specifies Monday as the first day of the week
15    $listed_links = 0;    //  and the USofA standard specifies Sunday. So we are going to make Sunday the first day of the week if specified; otherwise it will be Monday.
16    while ($week = db_fetch_array($weeklist)) {    $date_first_day = (variable_get('date_first_day', 1) == 0) ? 0 : 1;
17      $listed_links += 1;  
18      $block_content[] = theme('week_link', $week);    // First we need to create a date variable holding SOME day in the given week (the first day of the year, plus a number of weeks).
19    }    // the $date_first_day adjustment reflects the practical observation that starting the week with Monday gets you a lower week number
20    return theme('item_list', $block_content);    // for a given date.
21      $wk_ts = strtotime('+'. ($date_data['week'] - $date_first_day) .' weeks', strtotime($date_data['year'] .'-01-01'));
22    
23      // Now that we have a time stamp that falls somewhere in the week specified by the week number, we want a timestamp for the first day
24      // of the week. We get the day number of the date in this timestamp (0 = Sunday), subtract that number of days from the timestamp if
25      // the week starts with Sunday, or one less than the day number if the week starts with Monday
26      $start_week_ts = strtotime('-'. (date('w', $wk_ts) - $date_first_day) .' days', $wk_ts);
27    
28      // The end of the week is six days later
29      $end_week_ts = strtotime('+6 days', $start_week_ts);
30    
31      $month_names = date_month_names(1);
32      $month_names_abbr = date_month_names_abbr(1);
33      $day_names = date_week_days(1);
34      $day_names_abbr = date_week_days_abbr(1);
35    
36      $date_data['monthno'] = date('m', $start_week_ts);
37      $month_index = (integer) $date_data['monthno'];
38      $date_data['month'] = $month_names[$month_index];
39      $date_data['mon'] = $month_names_abbr[$month_index];
40    
41      $date_data['day'] = date('d', $start_week_ts);
42    
43      $day_index = date('w', $start_week_ts);
44      $date_data['dayname'] = $day_names[$day_index];
45      $date_data['sdayname'] = $day_names_abbr[$day_index];
46    
47      $date_data['end_year'] = date('Y', $end_week_ts);
48    
49      $date_data['end_monthno'] = date('m', $end_week_ts);
50      $end_month_index = (integer) $date_data['end_monthno'];
51      $date_data['end_month'] = $month_names[$end_month_index];
52      $date_data['end_mon'] = $month_names_abbr[$end_month_index];
53    
54      $date_data['end_day'] = date('d', $end_week_ts);
55      $end_day_index = (integer) date('w', $end_week_ts);
56      $date_data['end_dayname'] = $day_names[$end_day_index];
57      $date_data['end_sdayname'] = $day_names_abbr[$end_day_index];
58  }  }
59    
60  /**  /**
61   * Create SQL for links query   *
62   *   * @param $archive_type
63   * @param array $node_types   * @return boolean
  * @return string  
64   */   */
65  function week_block_links_query($node_types) {  function week_access_page($archive_type) {
66    foreach ($node_types as $key => $value) {    if (is_string($archive_type)) {
67      $node_types[$key] = "'" . db_escape_string($value) . "'";      $archive_types = variable_get('week_block_node_type', array());
68        return user_access('access content') and ($archive_types[$archive_type]);
69    }    }
70    $week_rev_linksort = variable_get('week_rev_linksort', 1);    elseif (is_null($archive_type)) {return user_access('access content');}
   // WEEK(date, 3) gets precisely the ISO-8601 week number that PHP uses so I can calculate the first and last day of the week in the token module hooks  
   $query = "SELECT CONCAT(YEAR(FROM_UNIXTIME(created)),WEEK(FROM_UNIXTIME(created), 3)) AS yearweek,  
     COUNT(CONCAT(YEAR(FROM_UNIXTIME(created)),WEEK(FROM_UNIXTIME(created), 3))) AS postcount,  
     YEAR(FROM_UNIXTIME(created)) AS year,  
     WEEK(FROM_UNIXTIME(created), 3) AS week,  
     MONTH(FROM_UNIXTIME(created)) AS month  
     FROM {node} n ";  
   $query .= 'WHERE n.type IN (' . implode(',', $node_types) . ') ';  
   $query .= ' AND status = 1 ';  
   $query .= ' GROUP BY week ORDER BY week ';  
   $query .= $week_rev_linksort ? ' ASC' : ' DESC ';  
   return $query;  
 }  
   
 function week_perm(){  
   return array('administer week');  
71  }  }
72    
73  function week_block($op='list', $delta=0, $edit=array()) {  /**
74     *
75     * hook_block() implementation
76     */
77    function week_block($op = 'list', $delta = 0, $edit = array()) {
78    switch ($op) {    switch ($op) {
79      // listing of blocks, such as on the admin/system/block page      // listing of blocks, such as on the admin/system/block page
80      case 'list':      case 'list' :
81        $block['week_all']['info'] = t('Weekly archives');        $block['week_all']['info'] = t('Weekly archives');
82        $requested_types = variable_get('week_block_node_type', array());        $requested_types = variable_get('week_block_node_type', array());
83        foreach ($requested_types as $type) {        foreach ($requested_types as $type) {
# Line 77  function week_block($op='list', $delta=0 Line 86  function week_block($op='list', $delta=0
86          if ($type) {          if ($type) {
87            $nodetypes = node_get_types('names');            $nodetypes = node_get_types('names');
88            // I have no idea why the inserted string is wrapped in <em> tags...delete the word 'strip_tags' calls if you don't believe me.            // I have no idea why the inserted string is wrapped in <em> tags...delete the word 'strip_tags' calls if you don't believe me.
89            $block['week_' . $type]['info'] = strip_tags(t('Weekly %type archives', array(            $block['week_'. $type]['info'] = strip_tags(t('Weekly %type archives', array(
90    
91              '%type' => $nodetypes[$type]              '%type' => $nodetypes[$type]
92            )));            )));
93          }          }
94        }        }
95        return $block;        return $block;
96          break;      break;
97      case 'view':      case 'view' :
98        // our block content        // our block content
99        // plus one is the easiest way to find out if you need a "more" link        $week_max_block_links = variable_get('week_block_link_max', 26);
       $week_max_block_links = variable_get('week_block_link_max', 26) + 1;  
100        if ($delta == 'week_all') {        if ($delta == 'week_all') {
101          $week_include_node_type = variable_get('week_include_node_type', array_keys(node_get_types('names')));          $week_include_node_type = variable_get('week_include_node_type', array_keys(node_get_types('names')));
102            $week_include_node_type = array_flip($week_include_node_type);
103            unset($week_include_node_type[0]);
104          $block['subject'] = t('Weekly archives');          $block['subject'] = t('Weekly archives');
105        }        }
106        else {        else {
107          $requested_type = substr($delta, strlen('week_'));          $requested_type = substr($delta, strlen('week_'));
108          $block['subject'] = t('Weekly %type archives', array('%type' => node_get_types('name', $requested_type)));          $block['subject'] = t('Weekly %type archives', array(
109          $week_include_node_type = array($requested_type);            '%type' => node_get_types('name', $requested_type)
110            ));
111            $week_include_node_type = array(
112              $requested_type
113            );
114        }        }
115          if ($week_include_node_type) {
116            $week_rev_chronsort = variable_get('week_rev_chronsort', 0);
117            $query = week_links_query($week_include_node_type, $week_rev_chronsort);
118            // plus one is the easiest way to find out if you need a "more" link
119            $weeklist = db_query_range(db_rewrite_sql($query, 'n', 'nid'), $week_max_block_links + 1);
120    
121            $block_content = array();
122            $listed_links = 0;
123            while (($listed_links < $week_max_block_links) && $week = db_fetch_array($weeklist)) {
124              $listed_links += 1;
125              $week['type'] = $requested_type;
126              $week['type_name'] = node_get_types('name', $requested_type);
127              _week_week_data($week);
128              $block_content[] = theme('week_link', $week);
129            }
130            if (db_fetch_object($weeklist)) {
131              $week_path = variable_get('week_path', 'archive');
132              $path_order = variable_get('week_path_order', ARCHIVEROOTBEFORETYPE);
133              $node_path = variable_get('week_'. $week['type'] .'_path', $week['type']);
134              $path = $requested_type ? ($path_order == TYPEBEFOREARCHIVEROOT ? $node_path .'/'. $week_path : $week_path .'/'. $node_path) : $week_path;
135              $morelink = l(t('more...'), $path);
136            }
137            if (count($block_content)) {
138              $block['content'] = theme('item_list', $block_content) . $morelink;
139              return $block;
140            }
141          }
142        break;
143        default :
144      }
145    }
146    
147        $week_rev_chronsort = variable_get('week_rev_chronsort', 0);  /**
148     *
149     * (Really weak) hook_help() implementation
150     */
151    function week_help($section) {
152      switch ($section) {
153        case 'admin/settings/week' :
154          $output = 'Create block containing a list of weekly archives, collectively or by node type.';
155        break;
156        case 'admin/build/modules#description' :
157          $output = 'Create block containing a list of weekly archives, collectively or by node type.';
158        break;
159        default :
160          $output = '';
161        break;
162      }
163      return $output;
164    }
165    
166        $query = week_block_links_query($week_include_node_type, $week_rev_chronsort);  /**
167     * The archive link query builder
168        $weeklist = db_query_range(db_rewrite_sql($query, 'n', 'nid'), $week_max_block_links);   *
169        $block_content = array();   * @param array $node_types
170        $listed_links = 0;   * @return string
171        while (($listed_links < $week_max_block_links) && $week = db_fetch_array($weeklist)) {   */
172          $listed_links += 1;  function week_links_query($node_types) {
173          $week['type'] = $requested_type;    foreach ($node_types as $key => $value) {
174          $week['type_name'] = node_get_types('name', $requested_type);      $node_types[$key] = "'". db_escape_string($value) ."'";
         _week_end_of_week_data($week);  
         $block_content[] = theme('week_link', $week);  
       }  
       if (db_fetch_object($weeklist)) {  
         $morelink = l(t('more...'), variable_get('week_path', 'archive'));  
       }  
       if (count($block_content)) {  
         $block['content'] = theme('item_list', $block_content) . $morelink;  
         return $block;  
       }  
         break;  
     default:  
175    }    }
176      $week_rev_linksort = variable_get('week_rev_linksort', 1);
177      // WEEK(date, 3) gets precisely the ISO-8601 week number that PHP uses so I can calculate the first and last day of the week in the token module hooks
178      $date_first_day = variable_get('date_first_day', 1);
179      $week_option = $date_first_day == 1 ? '%v' : '%V';
180      $query = "SELECT CONCAT(DATE_FORMAT(FROM_UNIXTIME(created), '%Y'),DATE_FORMAT(FROM_UNIXTIME(created), '$week_option')) AS yearweek,
181        COUNT(CONCAT(DATE_FORMAT(FROM_UNIXTIME(created), '%Y'),DATE_FORMAT(FROM_UNIXTIME(created), '$week_option'))) AS postcount,
182        DATE_FORMAT(FROM_UNIXTIME(created), '%Y') AS year,
183        DATE_FORMAT(FROM_UNIXTIME(created), '$week_option') AS week,
184        MONTH(FROM_UNIXTIME(created)) AS month
185        FROM {node} n ";
186      $query .= 'WHERE n.type IN ('. implode(',', $node_types) .') ';
187      $query .= ' AND status = 1 ';
188      $query .= ' GROUP BY yearweek ORDER BY yearweek ';
189      $query .= $week_rev_linksort ? ' ASC' : ' DESC ';
190      return $query;
191  }  }
192    
193  function _week_end_of_week_data(&$link_data) {  /**
194          // calculate the start and end of the week   * Generate a page listing links to all the archives that can be generated
195          $wk_ts  = strtotime('+' . $link_data['week'] . ' weeks', strtotime($link_data['year'] . '0101'));   *
196          $end_week_ts = strtotime('-' . date('w', $wk_ts) . ' days', $wk_ts - 86400);   * @return string
197          $start_week_ts = strtotime('-' . date('w', $wk_ts) . ' days', $wk_ts  - 604800);   */
198    function week_link_page($include_node_types) {
199          // add the parsed date data to the $link_data object    if (is_string($include_node_types)) {
200    $link_data['month'] = date('F', $start_week_ts);      $week_include_node_type[] = $include_node_types;
201    $link_data['mon'] = date('M', $start_week_ts);    }
202    $link_data['monthno'] = date('m', $start_week_ts);    else {
203    $link_data['day'] = date('d', $start_week_ts);      $week_include_node_type = variable_get('week_include_node_type', array_keys(node_get_types('names')));
204    $link_data['dayname'] = date('l', $start_week_ts);    }
205    $link_data['sdayname'] = date('D', $start_week_ts);    $query = week_links_query($week_include_node_type);
206      $weeklist = db_query(db_rewrite_sql($query, 'n', 'nid'));
207    $link_data['end_year'] = date('Y', $end_week_ts);    $block_content = array();
208    $link_data['end_month'] = date('F', $end_week_ts);    $listed_links = 0;
209    $link_data['end_mon'] = date('M', $end_week_ts);    while ($week = db_fetch_array($weeklist)) {
210    $link_data['end_monthno'] = date('m', $end_week_ts);      $listed_links += 1;
211    $link_data['end_day'] = date('d', $end_week_ts);      _week_week_data($week);
212    $link_data['end_dayname'] = date('l', $end_week_ts);      $block_content[] = theme('week_link', $week);
213    $link_data['end_sdayname'] = date('D', $end_week_ts);    }
214    $link_data['end_year'] = date('Y', $end_week_ts);    // TODO: needs a week_link_page_title variale series
215      if (is_string($include_node_types)) {
216        $link_data['type'] = $include_node_types;
217        $link_data['type_name'] = node_get_types('name', $include_node_types);
218        $page_title = 'Weekly [type_name] archive links';
219      }
220      else {
221        $page_title = 'Weekly archive links';
222      }
223      drupal_set_title(token_replace($page_title, 'week', (object) $link_data));
224      return theme('item_list', $block_content);
225  }  }
226    
227    /**
228     * hook_menu() implementation
229     */
230  function week_menu() {  function week_menu() {
231  //  $archive_types = array_flip(variable_get('week_block_node_type', array()));    $archive_types = array_flip(variable_get('week_block_node_type', array()));
232  //  $archive_types['all'] = NULL;    $archive_types['all'] = NULL;
233  //  unset($archive_types[0]);    unset($archive_types[0]);
234  //  $archive_root = variable_get('week_path', 'archive');    $archive_root = variable_get('week_path', 'archive');
235  //  $path_order = variable_get('week_path_order', ARCHIVEROOTBEFORETYPE);    $path_order = variable_get('week_path_order', ARCHIVEROOTBEFORETYPE);
236  //  foreach ($archive_types as $archive_type) {    foreach ($archive_types as $archive_type) {
237  //    $node_path = variable_get('week_' . $archive_type . '_path', $archive_type);      $node_path = variable_get('week_'. $archive_type .'_path', $archive_type);
238  //    $archive_index = $archive_type ? ($path_order == TYPEBEFOREARCHIVEROOT ? $node_path . '/' . $archive_root : $archive_root . '/' . $node_path) : $archive_root;      $archive_index = $archive_type ? ($path_order == TYPEBEFOREARCHIVEROOT ? $node_path .'/'. $archive_root : $archive_root .'/'. $node_path) : $archive_root;
239  //    $items[$archive_index] = array(      $items[$archive_index] = array(
240  //      'title' => $archive_type ? t('Weekly %type archives links', array('%type' => $archive_type)) : t('Weekly archives links'),        'title' => $archive_type ? "Weekly $archive_type archives links" : 'Weekly archives links',
241  //      'page callback' => 'week_link_page',        'page callback' => 'week_link_page',
242  //      'type' => MENU_CALLBACK,        'page arguments' => array(
243  //      'access arguments' => array('access content')          $archive_type
244  //    );        ),
245  //    $items[$archive_index . '/%/%'] = array(        'type' => MENU_CALLBACK,
246  //      'title' => $archive_type ? variable_get('week_' . $archive_type . '_title', $archive_type) : variable_get('week_title', 'Weekly archive [month] [yyyy]'),        'access callback' => 'week_access_page',
247  //      'page callback' => 'week_post_page',        'access arguments' => array(
248  //      'page arguments' => $archive_type ? array(2, 3, $archive_type) : array(1, 2),          $archive_type
249  //      'type' => MENU_CALLBACK,        )
250  //      'access arguments' => array('access content'),      );
251  //    );      $items[$archive_index .'/%/%'] = array(
252  //  }        'title' => $archive_type ? variable_get('week_'. $archive_type .'_title', $archive_type) : variable_get('week_title', 'Weekly archive [month] [yyyy]'),
253          'page callback' => 'week_post_page',
254          'page arguments' => $archive_type ? array(
255            2,
256            3,
257            $archive_type
258          ) : array(
259            1,
260            2
261          ),
262          'type' => MENU_CALLBACK,
263          'access callback' => 'week_access_page',
264          'access arguments' => array(
265            $archive_type
266          )
267        );
268      }
269    
270    $items['admin/settings/week'] = array(    $items['admin/settings/week'] = array(
271      'title' => t('Weekly archive settings'),  
272      'page callback' => 'drupal_get_form',      'title' => 'Weekly archive settings',
273      'page arguments' => array('week_settings_form'),      'page callback' => 'drupal_get_form',
274      'type' => MENU_NORMAL_ITEM,      'page arguments' => array(
275      'access arguments' => array('access administration pages')  
276          'week_settings_form'
277        ),
278        'type' => MENU_NORMAL_ITEM,
279        'access arguments' => array(
280    
281          'access administration pages'
282        )
283    );    );
284    $items['admin/settings/week/'] = array(    $items['admin/settings/week/'] = array(
285      'title' => t('Weekly archive settings'),  
286      'description' => 'Configure node types for which blocks will be generated.',      'title' => 'Weekly archive settings',
287      'type' => MENU_DEFAULT_LOCAL_TASK,      'description' => 'Configure node types for which blocks will be generated.',
288      'weight' => 5,      'type' => MENU_DEFAULT_LOCAL_TASK,
289        'weight' => 5
290    );    );
291    $items['admin/settings/week/type_path'] = array(    $items['admin/settings/week/type_path'] = array(
292      'title' => t('Links and titles'),  
293      'description' => 'Configure path names for node types for which blocks will be generated and date format of the link text.',      'title' => 'Links and titles',
294      'page callback' => 'drupal_get_form',      'description' => 'Configure path names for node types for which blocks will be generated and date format of the link text.',
295        'page callback' => 'drupal_get_form',
296      'page arguments' => array(      'page arguments' => array(
297    
298        'week_settings_type_path_form'        'week_settings_type_path_form'
299      ),      ),
300      'type' => MENU_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
301      'access arguments' => array(      'access arguments' => array(
302    
303        'access administration pages'        'access administration pages'
304      ),      ),
305      'weight' => 10      'weight' => 10
306    );    );
307    return $items;    return $items;
308  }  }
309    
310    /**
311     * hook_perm() implementation
312     */
313    function week_perm() {
314      return array(
315    
316        'administer week'
317      );
318    }
319    
320    /**
321     * Generate the archive page
322     * @param $year
323     * @param $week
324     * @param $include_node_types
325     * @return unknown_type
326     */
327    function week_post_page($year, $week, $include_node_types = NULL) {
328      if (is_numeric($year) and is_numeric($week)) {
329        $default_nodes_main = variable_get('default_nodes_main', 20);
330        $week_paginate = variable_get('week_paginate', 1);
331        $week_include_node_types = is_string($include_node_types) ? array(
332    
333          $include_node_types
334        ) : array_flip(variable_get('week_include_node_type', node_get_types('names')));
335        unset($week_include_node_types[0]);
336    
337        $node_query_str = week_post_query($week_include_node_types, $year, $week);
338    
339        $node_query = $week_paginate ? pager_query($node_query_str, $default_nodes_main, 0) : db_query($node_query_str);
340        while ($nid = db_fetch_array($node_query)) {
341          $node = node_load($nid['nid']);
342          $page .= node_view($node, 1);
343        }
344        if ($week_paginate) {
345          $page .= theme('pager', NULL, $default_nodes_main, 0);
346        }
347    
348        $link_data['week'] = $week;
349        $link_data['year'] = $year;
350        _week_week_data($link_data);
351        if (is_string($include_node_types)) {
352          $link_data['type'] = $include_node_types;
353          $link_data['type_name'] = node_get_types('name', $include_node_types);
354          $page_title = variable_get('week_'. $include_node_types .'_title', '[type_name] [month] [d], [yyyy] thru [end_month] [end_d], [end_yyyy]');
355        }
356        else {
357          $page_title = variable_get('week_title', 'Week of [month] [d], [yyyy] thru [end_month] [end_d], [end_yyyy]');
358        }
359        drupal_set_title(token_replace($page_title, 'week', (object) $link_data));
360      }
361      return $page ? $page : '';
362    }
363    
364    /**
365     * the archive page query builder
366     * @param $week_include_node_types
367     * @param $year
368     * @param $week
369     * @return unknown_type
370     */
371    function week_post_query($week_include_node_types, $year, $week) {
372      if (is_string($week_include_node_types)) {
373        $week_include_node_types[] = $week_include_node_types;
374      }
375      foreach ($week_include_node_types as $key => $value) {
376        $node_types[$key] = "'". db_escape_string($value) ."'";
377      }
378      $week_rev_pagesort = variable_get('week_rev_pagesort', 1);
379      $date_first_day = variable_get('date_first_day', 1);
380      $week_option = $date_first_day == '0' ? '0' : '1';
381      $query = "SELECT n.nid FROM {node} n
382        WHERE YEAR(FROM_UNIXTIME(n.created)) = '{$year}'
383        AND WEEK(FROM_UNIXTIME(n.created), $week_option) = '{$week}'";
384      $query .= ' AND n.type IN ('. implode(',', $node_types) .') ';
385      $query .= ' AND status = 1 ';
386      $query .= ' ORDER BY n.created';
387      $query .= $week_rev_pagesort ? '' : ' DESC ';
388      return $query;
389    }
390    
391    /**
392     * Creates the form to enable node type blocks
393     * @return array
394     */
395  function week_settings_form() {  function week_settings_form() {
396    $output['week_all'] = array(    $output['week_all'] = array(
397      '#tree' => FALSE,  
398      '#type' => 'fieldset',      '#tree' => FALSE,
399      '#collapsible' => TRUE,      '#type' => 'fieldset',
400      '#collapsed' => TRUE,      '#collapsible' => TRUE,
401      '#title' => t('Global block node types'),      '#collapsed' => TRUE,
402        '#title' => t('Global block node types'),
403      'week_include_node_type' => array(      'week_include_node_type' => array(
404        '#type' => 'checkboxes',  
405        '#multiple' => TRUE,        '#type' => 'checkboxes',
406        '#default_value' => variable_get('week_include_node_type', array_keys(node_get_types('names'))),        '#multiple' => TRUE,
407        '#options' => node_get_types('names'),        '#default_value' => variable_get('week_include_node_type', array_keys(node_get_types('names'))),
408          '#options' => node_get_types('names'),
409        '#description' => t('Selected node types will be included in the global block and archive pages.')        '#description' => t('Selected node types will be included in the global block and archive pages.')
410      )      )
411    );    );
412    $output['week_block'] = array(    $output['week_block'] = array(
413      '#tree' => FALSE,  
414      '#type' => 'fieldset',      '#tree' => FALSE,
415      '#collapsible' => TRUE,      '#type' => 'fieldset',
416      '#collapsed' => TRUE,      '#collapsible' => TRUE,
417      '#title' => t('Blocks by node type'),      '#collapsed' => TRUE,
418        '#title' => t('Blocks by node type'),
419      'week_block_node_type' => array(      'week_block_node_type' => array(
420        '#type' => 'checkboxes',  
421        '#multiple' => TRUE,        '#type' => 'checkboxes',
422        '#default_value' => variable_get('week_block_node_type', array()),        '#multiple' => TRUE,
423        '#options' => node_get_types('names'),        '#default_value' => variable_get('week_block_node_type', array()),
424          '#options' => node_get_types('names'),
425        '#description' => t('Blocks and archive pages for the selected node types will be created.')        '#description' => t('Blocks and archive pages for the selected node types will be created.')
426      )      )
427    );    );
428    
429    $output['week_block_link_max'] = array(    $output['week_block_link_max'] = array(
430      '#type' => 'textfield',  
431      '#title' => t('Maximum week links in block'),      '#type' => 'textfield',
432      '#default_value' => variable_get('week_block_link_max', 26),      '#title' => t('Maximum week links in block'),
433      '#size' => 5,      '#default_value' => variable_get('week_block_link_max', 26),
434      '#maxlength' => 5,      '#size' => 5,
435      '#description' => t('Enter a number to limit the number of months linked in the block, blank or "0" to list all months.')      '#maxlength' => 5,
436        '#required' => true,
437        '#description' => t('Enter a number to set the number of weeks linked in the block.')
438    );    );
439    
440    $output['week_rev_linksort'] = array(    $output['week_rev_linksort'] = array(
441      '#type' => 'checkbox',  
442      '#title' => t('Sort links in chronological order'),      '#type' => 'checkbox',
443      '#return_value' => 1,      '#title' => t('Sort links in chronological order'),
444      '#default_value' => variable_get('week_rev_linksort', 0),      '#return_value' => 1,
445        '#default_value' => variable_get('week_rev_linksort', 0),
446      '#description' => t('If checked, the list of archive links will be sorted from oldest to newest. Otherwise it will be sorted from newest to oldest')      '#description' => t('If checked, the list of archive links will be sorted from oldest to newest. Otherwise it will be sorted from newest to oldest')
447    );    );
448    
449    $output['week_show_linkcount'] = array(    $output['week_show_linkcount'] = array(
450      '#type' => 'checkbox',  
451      '#title' => t('Show link count'),      '#type' => 'checkbox',
452      '#return_value' => 1,      '#title' => t('Show link count'),
453      '#default_value' => variable_get('week_show_linkcount', 1),      '#return_value' => 1,
454        '#default_value' => variable_get('week_show_linkcount', 1),
455      '#description' => t('If checked, the link to each weekly archive page in blocks will show the number of nodes in that week ')      '#description' => t('If checked, the link to each weekly archive page in blocks will show the number of nodes in that week ')
456    );    );
457    
458    $output['week_rev_pagesort'] = array(    $output['week_rev_pagesort'] = array(
459      '#type' => 'checkbox',  
460      '#title' => t('Sort archive page in chronological order'),      '#type' => 'checkbox',
461      '#return_value' => 1,      '#title' => t('Sort archive page in chronological order'),
462      '#default_value' => variable_get('week_rev_pagesort', 0),      '#return_value' => 1,
463        '#default_value' => variable_get('week_rev_pagesort', 0),
464      '#description' => t('If checked, the list of archive links will be sorted from oldest to newest. Otherwise it will be sorted from newest to oldest')      '#description' => t('If checked, the list of archive links will be sorted from oldest to newest. Otherwise it will be sorted from newest to oldest')
465    );    );
466    
467    $output['week_paginate'] = array(    $output['week_paginate'] = array(
468      '#type' => 'checkbox',  
469      '#title' => t('Paginate archive page'),      '#type' => 'checkbox',
470      '#return_value' => 1,      '#title' => t('Paginate archive page'),
471      '#default_value' => variable_get('week_paginate', 0),      '#return_value' => 1,
472        '#default_value' => variable_get('week_paginate', 0),
473      '#description' => t('If checked the output will be split into pages. The number of posts will respect the global nodes per page setting.')      '#description' => t('If checked the output will be split into pages. The number of posts will respect the global nodes per page setting.')
474    );    );
475    $form = system_settings_form($output);    $form = system_settings_form($output);
476    $form['#submit'] = array(    $form['#submit'] = array(
477    
478      'week_settings_form_submit'      'week_settings_form_submit'
479    );    );
480    $output['#validate'][] = 'week_settings_form_validate';    $output['#validate'][] = 'week_settings_form_validate';
# Line 286  function week_settings_form() { Line 488  function week_settings_form() {
488  function week_settings_form_reset() {  function week_settings_form_reset() {
489    variable_del('week_include_node_type');    variable_del('week_include_node_type');
490    variable_del('week_block_node_type');    variable_del('week_block_node_type');
491    
492    variable_del('week_block_link_max');    variable_del('week_block_link_max');
493    variable_del('week_rev_linksort');    variable_del('week_rev_linksort');
494    variable_del('week_show_linkcount');    variable_del('week_show_linkcount');
495    variable_del('week_rev_pagesort');    variable_del('week_rev_pagesort');
496    variable_del('week_paginate');    variable_del('week_paginate');
497  //  week_settings_type_path_form_reset();    week_settings_type_path_form_reset();
498  }  }
499    
500  /**  /**
# Line 309  function week_settings_form_submit($form Line 511  function week_settings_form_submit($form
511    else {    else {
512      variable_set('week_include_node_type', $edit['week_include_node_type']);      variable_set('week_include_node_type', $edit['week_include_node_type']);
513      variable_set('week_block_node_type', $edit['week_block_node_type']);      variable_set('week_block_node_type', $edit['week_block_node_type']);
514    
515      variable_set('week_block_link_max', $edit['week_block_link_max']);      variable_set('week_block_link_max', $edit['week_block_link_max']);
516      variable_set('week_rev_linksort', $edit['week_rev_linksort']);      variable_set('week_rev_linksort', $edit['week_rev_linksort']);
517      variable_set('week_show_linkcount', $edit['week_show_linkcount']);      variable_set('week_show_linkcount', $edit['week_show_linkcount']);
# Line 329  function week_settings_form_validate($fo Line 531  function week_settings_form_validate($fo
531    if (!is_numeric($form_state['values']['week_block_link_max'])) {    if (!is_numeric($form_state['values']['week_block_link_max'])) {
532      form_set_error('week_block_link_max', 'Maximum number of links must be numeric.');      form_set_error('week_block_link_max', 'Maximum number of links must be numeric.');
533    }    }
534      if ($form_state['values']['week_block_link_max'] <= 0) {
535        form_set_error('week_block_link_max', 'Maximum number of links must be greater than 0.');
536      }
537  }  }
538    
539  function week_settings_type_path_form() {  function week_settings_type_path_form() {
# Line 338  function week_settings_type_path_form() Line 543  function week_settings_type_path_form()
543    }    }
544    $archive_path = variable_get('week_path', 'archive');    $archive_path = variable_get('week_path', 'archive');
545    $output['global'] = array(    $output['global'] = array(
546      '#tree' => FALSE,  
547      '#type' => 'fieldset',      '#tree' => FALSE,
548      '#collapsible' => TRUE,      '#type' => 'fieldset',
549      '#collapsed' => TRUE,      '#collapsible' => TRUE,
550      '#title' => t('Global settings'),      '#collapsed' => TRUE,
551        '#title' => t('Global settings'),
552      'week_link_text' => array(      'week_link_text' => array(
553        '#type' => 'textfield',  
554        '#title' => t('Link text'),        '#type' => 'textfield',
555        '#default_value' => variable_get('week_link_text', 'Week of [month] [d], [yyyy]'),        '#title' => t('Link text'),
556          '#default_value' => variable_get('week_link_text', '[month] [d], [yyyy] thru [end_month] [end_d], [end_yyyy]'),
557        '#description' => t('Define how the block link text is constructed.')        '#description' => t('Define how the block link text is constructed.')
558      ),      ),
559      'week_path' => array(      'week_path' => array(
560        '#type' => 'textfield',  
561        '#title' => t('Archive path'),        '#type' => 'textfield',
562        '#default_value' => variable_get('week_path', 'archive'),        '#title' => t('Archive path'),
563          '#default_value' => variable_get('week_path', 'archive'),
564        '#description' => t('Enter the path to use as the default archive path. Please use only letters, numbers and underscores (_).<br />The global archive path        '#description' => t('Enter the path to use as the default archive path. Please use only letters, numbers and underscores (_).<br />The global archive path
565        will be "archive_path/year/weekno".')        will be "archive_path/year/week".')
566      ),      ),
567      'week_title' => array(      'week_title' => array(
568        '#type' => 'textfield',  
569        '#title' => t('Archive title'),        '#type' => 'textfield',
570        '#default_value' => variable_get('week_title', 'Week of [month] [d], [yyyy]'),        '#title' => t('Archive title'),
571          '#default_value' => variable_get('week_title', 'Week of [month] [d], [yyyy] thru [end_month] [end_d], [end_yyyy]'),
572        '#description' => t('Enter the base title to use for the archive pages.')        '#description' => t('Enter the base title to use for the archive pages.')
573      ),      ),
574      'help' => array(      'help' => array(
575        '#tree' => FALSE,  
576        '#type' => 'fieldset',        '#tree' => FALSE,
577        '#collapsible' => TRUE,        '#type' => 'fieldset',
578        '#collapsed' => TRUE,        '#collapsible' => TRUE,
579        '#title' => t('Replacement patterns'),        '#collapsed' => TRUE,
580          '#title' => t('Replacement patterns'),
581        'output' => array(        'output' => array(
582          '#type' => 'markup',  
583          '#value' => theme('item_list', $token_help),          '#type' => 'markup',
584          '#prefix' => '<div>',          '#value' => theme('item_list', $token_help),
585            '#prefix' => '<div>',
586          '#sufffix' => '</div>'          '#sufffix' => '</div>'
587        )        )
588      )      )
589    );    );
590    $output['by_node_type'] = array(    $output['by_node_type'] = array(
591      '#tree' => FALSE,  
592      '#type' => 'fieldset',      '#tree' => FALSE,
593      '#collapsible' => TRUE,      '#type' => 'fieldset',
594      '#collapsed' => TRUE,      '#collapsible' => TRUE,
595        '#collapsed' => TRUE,
596      '#title' => t('Node type settings')      '#title' => t('Node type settings')
597    );    );
598    
599    $output['by_node_type']['week_path_order'] = array(    $output['by_node_type']['week_path_order'] = array(
600      '#type' => 'radios',  
601      '#title' => t('Node type archive path'),      '#type' => 'radios',
602        '#title' => t('Node type archive path'),
603      '#options' => array(      '#options' => array(
604        ARCHIVEROOTBEFORETYPE => $archive_path . '/node_type',  
605        TYPEBEFOREARCHIVEROOT => 'node_type/' . $archive_path        ARCHIVEROOTBEFORETYPE => $archive_path .'/node_type',
606      ),        TYPEBEFOREARCHIVEROOT => 'node_type/'. $archive_path
607      '#default_value' => variable_get('week_path_order', ARCHIVEROOTBEFORETYPE),      ),
608        '#default_value' => variable_get('week_path_order', ARCHIVEROOTBEFORETYPE),
609      '#description' => 'Select the order in which the parts of node specific archive appear in the path to the archive page. <br />The node type archive paths will be      '#description' => 'Select the order in which the parts of node specific archive appear in the path to the archive page. <br />The node type archive paths will be
610      archive_path/node_type/year/month or node_type/archive_path/year/month.'      archive_path/node_type/year/week or node_type/archive_path/year/week.'
611    );    );
612    $output['by_node_type']['node_type'] = array(    $output['by_node_type']['node_type'] = array(
613      '#tree' => TRUE,  
614      '#type' => 'fieldset',      '#tree' => TRUE,
615        '#type' => 'fieldset',
616      '#title' => t('Titles and paths')      '#title' => t('Titles and paths')
617    );    );
618    
619    $node_types = variable_get('week_block_node_type', array());    $node_types = variable_get('week_block_node_type', array());
620    foreach ($node_types as $key => $node_type) {    if (count($node_types)) {
621      if ($node_type) {      foreach ($node_types as $key => $node_type) {
622        $output['by_node_type']['node_type'][$node_type] = array(        if ($node_type) {
623          'title' => array(          $output['by_node_type']['node_type'][$node_type] = array(
624            '#type' => 'textfield',  
625            '#title' => node_get_types('name', $node_type) . t(' archive title'),            'title' => array(
626            '#default_value' => variable_get('week_' . $node_type . '_title', '[type_name] [month] [d], [yyyy]')  
627          ),              '#type' => 'textfield',
628          'path' => array(              '#title' => node_get_types('name', $node_type) . t(' archive title'),
629            '#type' => 'textfield',              '#default_value' => variable_get('week_'. $node_type .'_title', '[type_name] [month] [d], [yyyy]')
630            '#title' => node_get_types('name', $node_type) . t(' archive path'),            ),
631            '#default_value' => variable_get('week_' . $node_type . '_path', $node_type)            'path' => array(
632          )  
633        );              '#type' => 'textfield',
634                '#title' => node_get_types('name', $node_type) . t(' archive path'),
635                '#default_value' => variable_get('week_'. $node_type .'_path', $node_type)
636              )
637            );
638          }
639      }      }
640        $output['by_node_type']['node_type']['help'] = array(
641    
642          '#tree' => FALSE,
643          '#type' => 'fieldset',
644          '#collapsible' => TRUE,
645          '#collapsed' => TRUE,
646          '#title' => t('Replacement patterns'),
647          'output' => array(
648    
649            '#type' => 'markup',
650            '#value' => theme('item_list', $token_help),
651            '#prefix' => '<div>',
652            '#sufffix' => '</div>'
653          )
654        );
655    }    }
   $output['by_node_type']['node_type']['help'] = array(  
     '#tree' => FALSE,  
     '#type' => 'fieldset',  
     '#collapsible' => TRUE,  
     '#collapsed' => TRUE,  
     '#title' => t('Replacement patterns'),  
     'output' => array(  
       '#type' => 'markup',  
       '#value' => theme('item_list', $token_help),  
       '#prefix' => '<div>',  
       '#sufffix' => '</div>'  
     )  
   );  
   
656    $output = system_settings_form($output);    $output = system_settings_form($output);
657    $output['#submit'] = array(    $output['#submit'] = array(
658    
659      'week_settings_type_path_submit'      'week_settings_type_path_submit'
660    );    );
661    $output['#validate'][] = 'week_settings_type_path_validate';    $output['#validate'][] = 'week_settings_type_path_validate';
662    return $output;    return $output;
663  }  }
664    
665    /**
666     * week_settings_type_path_form reset function
667     */
668  function week_settings_type_path_form_reset() {  function week_settings_type_path_form_reset() {
669    variable_del('week_link_text');    variable_del('week_link_text');
670    variable_del('week_path');    variable_del('week_path');
# Line 448  function week_settings_type_path_form_re Line 673  function week_settings_type_path_form_re
673    $node_types = node_get_types('names');    $node_types = node_get_types('names');
674    foreach ($node_types as $key => $node_type) {    foreach ($node_types as $key => $node_type) {
675      if ($node_type) {      if ($node_type) {
676        variable_del('week_' . $key . '_path');        variable_del('week_'. $key .'_path');
677        variable_del('week_' . $key . '_title');        variable_del('week_'. $key .'_title');
678      }      }
679    }    }
680      cache_clear_all();
681  }  }
682    
683    /**
684     * week_settings_type_path_form submit function
685     * @param $form
686     * @param $form_state
687     */
688  function week_settings_type_path_submit($form, &$form_state) {  function week_settings_type_path_submit($form, &$form_state) {
689    if ($form_state['clicked_button']['#value'] == 'Reset to defaults') {    if ($form_state['clicked_button']['#value'] == 'Reset to defaults') {
690      week_settings_type_path_form_reset();      week_settings_type_path_form_reset();
# Line 464  function week_settings_type_path_submit( Line 695  function week_settings_type_path_submit(
695      variable_set('week_path', $edit['week_path']);      variable_set('week_path', $edit['week_path']);
696      variable_set('week_title', $edit['week_title']);      variable_set('week_title', $edit['week_title']);
697      variable_set('week_path_order', $edit['week_path_order']);      variable_set('week_path_order', $edit['week_path_order']);
698    
699      $edit = $form_state['values']['node_type'];      $edit = $form_state['values']['node_type'];
700      foreach ($edit as $key => $value) {      foreach ($edit as $key => $value) {
701        variable_set('week_' . $key . '_path', $value['path']);        variable_set('week_'. $key .'_path', $value['path']);
702        variable_set('week_' . $key . '_title', $value['title']);        variable_set('week_'. $key .'_title', $value['title']);
703      }      }
704    }    }
705    menu_rebuild();    menu_rebuild();
706  }  }
707    
708    /**
709     * week_settings_type_path_form validate function
710     * @param $form
711     * @param $form_state
712     */
713  function week_settings_type_path_validate($form, &$form_state) {  function week_settings_type_path_validate($form, &$form_state) {
714    $found = preg_match('%^[a-z|0-9|_]+$%', $form_state['values']['week_path']);    $found = preg_match('%^[a-z|0-9|_]+$%', $form_state['values']['week_path']);
715    if (!$found) {    if (!$found) {
716      form_set_error('global', 'Archive path must be all lowercase, and begin with an alphabetic character or underscore. The remainder must be all alphanumerics.', TRUE);      form_set_error('global', 'Archive path must be all lowercase, and begin with an alphabetic character or underscore. The remainder must be all alphanumerics.', TRUE);
717    }    }
718    
719    $edit = $form_state['values']['node_type'];    $edit = $form_state['values']['node_type'];
720    foreach ($edit as $value) {    foreach ($edit as $value) {
721      $found = preg_match('%^[a-z|0-9|_]+$%', $value['path']);      $found = preg_match('%^[a-z|0-9|_]+$%', $value['path']);
# Line 496  function week_settings_type_path_validat Line 732  function week_settings_type_path_validat
732   */   */
733  function week_theme($existing, $type, $theme, $path) {  function week_theme($existing, $type, $theme, $path) {
734    return array(    return array(
735    
736      'week_link' => array(      'week_link' => array(
737    
738        'arguments' => array(        'arguments' => array(
739    
740          'link_data' => NULL          'link_data' => NULL
741        )        )
742      )      )
# Line 514  function week_token_list($type = 'all') Line 753  function week_token_list($type = 'all')
753    if ($type == 'week') {    if ($type == 'week') {
754      $tokens['week']['type'] = t('Machine readable type name');      $tokens['week']['type'] = t('Machine readable type name');
755      $tokens['week']['type_name'] = t('Displayable type label');      $tokens['week']['type_name'] = t('Displayable type label');
756    
757      $tokens['week']['month'] = t('Long month name (January, February...December) of the first day of the week');      $tokens['week']['month'] = t('Long month name (January, February...December) of the first day of the week');
758      $tokens['week']['mon'] = t('Short month name (Jan, Feb...Dec) of the first day of the week');      $tokens['week']['mon'] = t('Short month name (Jan, Feb...Dec) of the first day of the week');
759      $tokens['week']['mm'] = t('Two digit month (01, 02...12) of the first day of the week');      $tokens['week']['mm'] = t('Two digit month (01, 02...12) of the first day of the week');
760      $tokens['week']['m'] = t('Variable digit month (1, 2...12) of the first day of the week');      $tokens['week']['m'] = t('Variable digit month (1, 2...12) of the first day of the week');
761        $tokens['week']['week'] = t('ISO-8601 week number. Week 1 is the first week with more than three days in it.');
762      $tokens['week']['dd'] = t('Two digit day (01, 02...31) of the first day of the week');      $tokens['week']['dd'] = t('Two digit day (01, 02...31) of the first day of the week');
763      $tokens['week']['d'] = t('Variable digit day (1, 2...31) of the first day of the week');      $tokens['week']['d'] = t('Variable digit day (1, 2...31) of the first day of the week');
764      $tokens['week']['day'] = t('Day name (Sunday, Monday...Saturday) of the first day of the week');      $tokens['week']['day'] = t('Day name (Sunday, Monday...Saturday) of the first day of the week');
# Line 553  function week_token_list($type = 'all') Line 793  function week_token_list($type = 'all')
793  function week_token_values($type, $object = NULL) {  function week_token_values($type, $object = NULL) {
794    if ($type == 'week') {    if ($type == 'week') {
795      $link_data = $object;      $link_data = $object;
796    
797      $token['type'] = $link_data->type;      $token['type'] = $link_data->type;
798      $token['type_name'] = $link_data->type_name;      $token['type_name'] = $link_data->type_name;
799    
800      $token['month'] = $link_data->month;      $token['month'] = $link_data->month;
801      $token['mon'] = $link_data->mon;      $token['mon'] = $link_data->mon;
802      $token['mm'] = $link_data->monthno;      $token['mm'] = $link_data->monthno;
803        $token['week'] = (integer) $link_data->week;
804      $token['m'] = (integer) $link_data->monthno;      $token['m'] = (integer) $link_data->monthno;
805      $token['dd'] = $link_data->day;      $token['dd'] = $link_data->day;
806      $token['d'] = (integer) $link_data->day;      $token['d'] = (integer) $link_data->day;
# Line 568  function week_token_values($type, $objec Line 809  function week_token_values($type, $objec
809      $token['yyyy'] = $link_data->year;      $token['yyyy'] = $link_data->year;
810      $token['yy'] = substr($link_data->year, -2);      $token['yy'] = substr($link_data->year, -2);
811    
812            $token['end_month'] = $link_data->end_month;      $token['end_month'] = $link_data->end_month;
813            $token['end_mon'] = $link_data->end_mon;      $token['end_mon'] = $link_data->end_mon;
814            $token['end_mm'] = $link_data->end_monthno;      $token['end_mm'] = $link_data->end_monthno;
815            $token['end_m'] = (integer) $link_data->end_monthno;      $token['end_m'] = (integer) $link_data->end_monthno;
816            $token['end_dd'] = $link_data->end_day;      $token['end_dd'] = $link_data->end_day;
817            $token['end_d'] = (integer) $link_data->end_day;      $token['end_d'] = (integer) $link_data->end_day;
818            $token['end_day'] = $link_data->end_dayname;      $token['end_day'] = $link_data->end_dayname;
819            $token['end_sday'] = $link_data->end_sdayname;      $token['end_sday'] = $link_data->end_sdayname;
820            $token['end_yyyy'] = $link_data->end_year;      $token['end_yyyy'] = $link_data->end_year;
821            $token['end_yy'] = substr($link_data->end_year, -2);      $token['end_yy'] = substr($link_data->end_year, -2);
822            return $token;      return $token;
823    }    }
824    else {    else {
825      return array();      return array();
# Line 613  function _week_linktext($link_data) { Line 854  function _week_linktext($link_data) {
854   */   */
855  function _week_linkpath($link_data, $week_path) {  function _week_linkpath($link_data, $week_path) {
856    $path_order = variable_get('week_path_order', ARCHIVEROOTBEFORETYPE);    $path_order = variable_get('week_path_order', ARCHIVEROOTBEFORETYPE);
857    $node_path = variable_get('week_' . $link_data['type'] . '_path', $link_data['type']);    $node_path = variable_get('week_'. $link_data['type'] .'_path', $link_data['type']);
858    $path = $link_data['type'] ? ($path_order == TYPEBEFOREARCHIVEROOT ? $node_path . '/' . $week_path : $week_path . '/' . $node_path) : $week_path;    $path = $link_data['type'] ? ($path_order == TYPEBEFOREARCHIVEROOT ? $node_path .'/'. $week_path : $week_path .'/'. $node_path) : $week_path;
859    return $path . "/{$link_data['year']}/{$link_data['weekno']}";    return $path ."/{$link_data['year']}/{$link_data['week']}";
860  }  }
861    
862  /**  /**

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.2