/[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.2.2.4, Thu May 29 21:02:31 2008 UTC revision 1.10.2.2.2.5, Sun Jun 29 19:38:25 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: comment_closer.module,v 1.10.2.2.2.3 2008/05/28 20:39:36 rmiddle Exp $  // $Id$
3  /**  /**
4    * @file   * @file
5    *comment_closer.module   * comment_closer.module
6    *Automatically close comments on nodes beyond a configurable age   * Automatically close comments on nodes beyond a configurable age
7  */   */
8  function comment_closer_help($path, $arg) {  function comment_closer_help($path, $arg) {
9    switch ($path) {    switch ($path) {
10      case 'admin/block/help':      case 'admin/block/help':
# Line 67  function comment_closer_settings() { Line 67  function comment_closer_settings() {
67  }  }
68    
69  function _comment_closer_node_select($nodetypes) {  function _comment_closer_node_select($nodetypes) {
70    if ($nodetypes == 0 || ! is_array($nodetypes) || ! count($nodetypes) ) {    foreach ($nodetypes as $nodetype_index) {
71      return '';      $node_condition[] = '(type=\''.$nodetype_index.'\')';
   }  
   else {  
     foreach ($nodetypes as $nodetype_index) {  
       $node_condition[] = "(type='$nodetype_index')";  
     }  
     return " AND (".implode(" OR ", $node_condition).")";  
72    }    }
73      return implode(' OR ', $node_condition);
74  }  }
75    
76  function comment_closer_cron() {  function comment_closer_cron() {
# Line 83  function comment_closer_cron() { Line 78  function comment_closer_cron() {
78    $now = time();    $now = time();
79    $current_date = getdate($now);    $current_date = getdate($now);
80    $next_cycle_time = variable_get('comment_closer_next_date', $now);    $next_cycle_time = variable_get('comment_closer_next_date', $now);
81      $process_node_type_list = variable_get('comment_closer_types', 0);
82    
83    if ($now >= $next_cycle_time) {    if ($now >= $next_cycle_time) {
84      //set it up      if ($process_node_type_list != 0 || is_array($process_node_type_list) ) {
85      $limit = variable_get('comment_closer_age', 'month');        //set it up
86      switch ($limit) {        $limit = variable_get('comment_closer_age', 'month');
87        case 'month': {        switch ($limit) {
88          $current_date['mon'] = $current_date['mon'] - 1;          case 'month': {
89          break;            $current_date['mon'] = $current_date['mon'] - 1;
90        }            break;
91          case 'quarterly': {          }
92          $current_date['mon'] = $current_date['mon'] - 3;            case 'quarterly': {
93          break;            $current_date['mon'] = $current_date['mon'] - 3;
94        }            break;
95        case 'year': {          }
96          $current_date['year'] = $current_date['year'] - 1;          case 'year': {
97          break;            $current_date['year'] = $current_date['year'] - 1;
98        }            break;
99        case 'week': {          }
100          $current_date['mday'] = $current_date['mday'] - 7;          case 'week': {
101          break;            $current_date['mday'] = $current_date['mday'] - 7;
102        }            break;
103      }          }
104      $process_node_type_list = variable_get('comment_closer_types', 0);        }
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      cache_clear_all();        cache_clear_all();
109    
110      $result = db_query(        $sql = sprintf("UPDATE {node} SET comment = 1 WHERE (created < '%d') AND (%s)", // Can't escape the %s it breaks the SQL.
111        "UPDATE {node} SET comment = 1 WHERE (created < '%d') '%s'",          $oldest_allowed,
112        $oldest_allowed,          _comment_closer_node_select($process_node_type_list)
       _comment_closer_node_select($process_node_type_list)  
113        );        );
114          $result = db_query($sql);
115      // clean it up        $msg = 'sql = %sql';
116      $current_date = getdate();        $vars = array( '%sql' => $sql );
117          watchdog('comment_closer',$msg, $vars, WATCHDOG_DEBUG);
118      switch (variable_get('comment_closer_cycle_period', 'weekly')) {        // clean it up
119        case 'monthly': {       $current_date = getdate();
120          $current_date['mon'] = $current_date['mon'] + 1;  
121          break;       switch (variable_get('comment_closer_cycle_period', 'weekly')) {
122        }          case 'monthly': {
123         case 'quarterly': {            $current_date['mon'] = $current_date['mon'] + 1;
124          $current_date['mon'] = $current_date['mon'] + 3;            break;
125          break;          }
126        }          case 'quarterly': {
127        case 'yearly': {            $current_date['mon'] = $current_date['mon'] + 3;
128          $current_date['year'] = $current_date['year'] + 1;            break;
129          break;          }
130        }          case 'yearly': {
131        case 'weekly': {            $current_date['year'] = $current_date['year'] + 1;
132          $current_date['mday'] = $current_date['mday'] + 7;            break;
133          break;          }
134        }          case 'weekly': {
135        case 'daily': {           $current_date['mday'] = $current_date['mday'] + 7;
136          $current_date['mday'] = $current_date['mday'] + 1;            break;
137          break;          }
138            case 'daily': {
139              $current_date['mday'] = $current_date['mday'] + 1;
140              break;
141            }
142        }        }
143          $comment_closer_next_date = mktime($current_date['hours'], $current_date['minutes'], $current_date['seconds'], $current_date['mon'], $current_date['mday'], $current_date['year']);
144          variable_set('comment_closer_next_date', $comment_closer_next_date);
145      }      }
   $comment_closer_next_date = mktime($current_date['hours'], $current_date['minutes'], $current_date['seconds'], $current_date['mon'], $current_date['mday'], $current_date['year']);  
   
     variable_set('comment_closer_next_date', $comment_closer_next_date);  
146    }    }
147  }  }
148    
149  function comment_closer_menu() {  function comment_closer_menu() {
150    $items['admin/settings/comment_closer'] = array(    $items['admin/settings/comment_closer'] = array(
151      'title' => 'Comment closer',      'title' => 'Comment closer',
152      'description' => t('Set age, frequency and types of nodes for which comments will be closed.'),      'description' => 'Set age, frequency and types of nodes for which comments will be closed.',
153      'page callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
154      'page arguments' => array('comment_closer_settings'),      'page arguments' => array('comment_closer_settings'),
155      'access arguments' => array('administer site configuration'),      'access arguments' => array('administer site configuration'),

Legend:
Removed from v.1.10.2.2.2.4  
changed lines
  Added in v.1.10.2.2.2.5

  ViewVC Help
Powered by ViewVC 1.1.2