/[drupal]/contributions/modules/commentcloser/comment_closer.module
ViewVC logotype

Diff of /contributions/modules/commentcloser/comment_closer.module

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

revision 1.10.2.4, Thu May 29 21:20:02 2008 UTC revision 1.10.2.5, Sat Jan 10 18:52:26 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id:  // $Id$
3  /**  /**
4    *comment_closer.module   * @file
5    *Automatically close comments on nodes beyond a configurable age   * comment_closer.module
6  */   * Automatically close comments on nodes beyond a configurable age
7     *
8     * Drupal 5 Version
9     */
10    
11    /**
12     * Implementation of hook_help().
13     */
14  function comment_closer_help($section) {  function comment_closer_help($section) {
15    switch($section) {    switch ($section) {
16      case 'admin/block/help':      case 'admin/block/help':
17        return t('<p>Automatically close comments</p>');        return t('<p>Automatically close comments</p>');
18        break;        break;
# Line 25  function comment_closer_help($section) { Line 31  function comment_closer_help($section) {
31    return $output;    return $output;
32  }  }
33    
34  function _comment_closer_nodeoptions(){  function _comment_closer_nodeoptions() {
35          $nodetypes = node_get_types();    $nodetypes = node_get_types();
36          foreach ($nodetypes as $machine_name => $node_def) {    foreach ($nodetypes as $machine_name => $node_def) {
37                  $option_array[$machine_name] = $node_def->name;      $option_array[$machine_name] = $node_def->name;
38          }    }
39          return $option_array;    return $option_array;
40  }  }
41    
42  function comment_closer_settings() {  function comment_closer_settings() {
# Line 68  function comment_closer_settings() { Line 74  function comment_closer_settings() {
74    return system_settings_form($cc_form);    return system_settings_form($cc_form);
75  }  }
76    
 function _comment_closer_node_select($nodetypes){  
   if ($nodetypes == 0 || ! is_array($nodetypes) || ! count($nodetypes) ) {  
     return '';  
   } else {  
     foreach ($nodetypes as $nodetype_index){  
       $node_condition[] = "(type='$nodetype_index')";  
     }  
     return " AND (".implode(" OR ", $node_condition).')';  
   }  
 }  
   
77  function comment_closer_cron() {  function comment_closer_cron() {
78    
79    $now = time();    $now = time();
# Line 110  function comment_closer_cron() { Line 105  function comment_closer_cron() {
105      $oldest_allowed = mktime($current_date['hours'], $current_date['minutes'], $current_date['seconds'], $current_date['mon'], $current_date['mday'], $current_date['year']);      $oldest_allowed = mktime($current_date['hours'], $current_date['minutes'], $current_date['seconds'], $current_date['mon'], $current_date['mday'], $current_date['year']);
106    
107      // knock it out      // knock it out
108      $qstr = "UPDATE {node} SET comment = 1 WHERE (created < $oldest_allowed) ".      $args = array();
109                          _comment_closer_node_select($process_node_type_list);      $query = "UPDATE {node} SET comment = 1 WHERE (created < %d)";
110        $args[] = $oldest_allowed;
111        if (!empty($process_node_type_list) && is_array($process_node_type_list)) {
112          $node_conditions = array();
113          foreach ($process_node_type_list as $nodetype_index) {
114            $node_conditions[] = "type = '%s'";
115            $args[] = $nodetype_index;
116          }
117          $query .= " AND (". implode(" OR ", $node_conditions) .')';
118        }
119      cache_clear_all();      cache_clear_all();
120      $result = db_query($qstr);      $result = db_query($query, $args);
121    
122      // clean it up      // clean it up
123      $current_date = getdate();      $current_date = getdate();
# Line 123  function comment_closer_cron() { Line 127  function comment_closer_cron() {
127          $current_date['mon'] = $current_date['mon'] + 1;          $current_date['mon'] = $current_date['mon'] + 1;
128          break;          break;
129        }        }
130         case 'quarterly': {        case 'quarterly': {
131          $current_date['mon'] = $current_date['mon'] + 3;          $current_date['mon'] = $current_date['mon'] + 3;
132          break;          break;
133        }        }
# Line 142  function comment_closer_cron() { Line 146  function comment_closer_cron() {
146      }      }
147    $comment_closer_next_date = mktime($current_date['hours'], $current_date['minutes'], $current_date['seconds'], $current_date['mon'], $current_date['mday'], $current_date['year']);    $comment_closer_next_date = mktime($current_date['hours'], $current_date['minutes'], $current_date['seconds'], $current_date['mon'], $current_date['mday'], $current_date['year']);
148    
149      variable_set('comment_closer_next_date',$comment_closer_next_date);      variable_set('comment_closer_next_date', $comment_closer_next_date);
150    }    }
151  }  }
152    
153  function comment_closer_menu($may_cache) {  function comment_closer_menu($may_cache) {
154          $items[] = array(    if ($may_cache) {
155      'path' => 'admin/settings/comment_closer',      $items[] = array(
156      'title' => t('Comment closer'),        'path' => 'admin/settings/comment_closer',
157      'description' => t('Set age, frequency and types of nodes for which comments will be closed.'),        'title' => t('Comment closer'),
158      'callback' => 'drupal_get_form',        'description' => t('Set age, frequency and types of nodes for which comments will be closed.'),
159      'callback arguments' => 'comment_closer_settings',        'callback' => 'drupal_get_form',
160      'access' => user_access('administer site configuration'),        'callback arguments' => 'comment_closer_settings',
161    );        'access' => user_access('administer site configuration'),
162        );
163      }
164    return $items;    return $items;
165  }  }

Legend:
Removed from v.1.10.2.4  
changed lines
  Added in v.1.10.2.5

  ViewVC Help
Powered by ViewVC 1.1.2