/[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.11, Sun Jun 8 18:25:58 2008 UTC revision 1.12, Sun Jun 29 19:37:15 2008 UTC
# Line 8  Line 8 
8    
9    
10  define('COMMENT_CLOSER_SUBJECT', t('Comments closed at !date'));  define('COMMENT_CLOSER_SUBJECT', t('Comments closed at !date'));
11  define('COMMENT_CLOSER_BODY', t('The entry no longer accepts comments.'));  define('COMMENT_CLOSER_BODY', t('This item is no longer accepting comments.'));
12    
13  function comment_closer_help($path, $arg) {  function comment_closer_help($path, $arg) {
14    switch ($path) {    switch ($path) {
# Line 91  function comment_closer_settings() { Line 91  function comment_closer_settings() {
91  }  }
92    
93  function _comment_closer_node_select($nodetypes) {  function _comment_closer_node_select($nodetypes) {
94    if ($nodetypes == 0 || ! is_array($nodetypes) || ! count($nodetypes) ) {    foreach ($nodetypes as $nodetype_index) {
95      return '';      $node_condition[] = '(type=\''. $nodetype_index .'\')';
96    }    }
97    else {    return implode(' OR ', $node_condition);
98      foreach ($nodetypes as $nodetype_index) {  }
99        $node_condition[] = "(type='$nodetype_index')";  
100      }  function _comment_closer_comment_save($post_comment) {
101      return " AND (". implode(" OR ", $node_condition) .")";    if ($cid = comment_save($post_comment)) {
102        $node = node_load($post_comment->$nid);
103        comment_new_page_count($node->comment_count, 1, $node);
104        return;
105    }    }
106  }  }
107    
108    
109  function comment_closer_cron() {  function comment_closer_cron() {
110    
111    $now = time();    $now = time();
112    $current_date = getdate($now);    $current_date = getdate($now);
113    $next_cycle_time = variable_get('comment_closer_next_date', $now);    $next_cycle_time = variable_get('comment_closer_next_date', $now);
114    $variables = array(    $process_node_type_list = variable_get('comment_closer_types', 0);
     '!site' => variable_get('site_name', 'Drupal'),  
     '!uri' => $base_url,  
     '!uri_brief' => substr($base_url, strlen('http://')),  
     '!date' => format_date(time()),  
   );  
115    
116    if ($now >= $next_cycle_time) {    if ($now >= $next_cycle_time) {
117      //set it up      if ($process_node_type_list != 0 || is_array($process_node_type_list) ) {
118      $limit = variable_get('comment_closer_age', 'month');        //set it up
119      switch ($limit) {        $variables = array(
120        case 'month': {          '!site' => variable_get('site_name', 'Drupal'),
121          $current_date['mon'] = $current_date['mon'] - 1;          '!uri' => $base_url,
122          break;          '!uri_brief' => substr($base_url, strlen('http://')),
123        }          '!date' => format_date(time()),
         case 'quarterly': {  
         $current_date['mon'] = $current_date['mon'] - 3;  
         break;  
       }  
       case 'year': {  
         $current_date['year'] = $current_date['year'] - 1;  
         break;  
       }  
       case 'week': {  
         $current_date['mday'] = $current_date['mday'] - 7;  
         break;  
       }  
     }  
     $process_node_type_list = variable_get('comment_closer_types', 0);  
     $oldest_allowed = mktime($current_date['hours'], $current_date['minutes'], $current_date['seconds'], $current_date['mon'], $current_date['mday'], $current_date['year']);  
   
     // knock it out  
     cache_clear_all();  
   
     if (variable_get('comment_closer_insert_closing_comment', 0)) {  
       $result = db_query(  
         "UPDATE {node} SET comment = 1 WHERE (created < '%d') '%s'",  
         $oldest_allowed,  
         _comment_closer_node_select($process_node_type_list)  
       );  
     }  
     else {  
       $result = db_query(  
         "SELECT * FROM {node} WHERE comment = 2 AND (created < '%d') '%s'",  
         $oldest_allowed,  
         _comment_closer_node_select($process_node_type_list)  
124        );        );
125        while ($data = db_fetch_object($result)) {        $admin = user_load (1);  // load the 1st account
126          $post_comment = array(        $limit = variable_get('comment_closer_age', 'month');
127            'nid' => $data->nid,        switch ($limit) {
128            'pid' => 0,          case 'month': {
129            'uid' => 1,            $current_date['mon'] = $current_date['mon'] - 1;
130            'subject' => t(variable_get('comment_closer_insert_subject', COMMENT_CLOSER_SUBJECT), $variables),            break;
131            'comment' => t(variable_get('comment_closer_insert_body', COMMENT_CLOSER_BODY), $variables),          }
132            'format' => '',          case 'quarterly': {
133            'timestamp' => '',            $current_date['mon'] = $current_date['mon'] - 3;
134            'status' => '',            break;
135            'name' => 'admin',          }
136            'mail' => 'emailaddress',          case 'year': {
137            'homepage' => 'homepage',            $current_date['year'] = $current_date['year'] - 1;
138          );            break;
139          comment_save($post_comment);          }
140          db_query(          case 'week': {
141            "UPDATE {node} SET comment = 1 WHERE nid = %d",            $current_date['mday'] = $current_date['mday'] - 7;
142            $data->nid            break;
143          );          }
144          }
145          $oldest_allowed = mktime($current_date['hours'], $current_date['minutes'], $current_date['seconds'], $current_date['mon'], $current_date['mday'], $current_date['year']);
146    
147          // knock it out
148          cache_clear_all();
149          if (variable_get('comment_closer_insert_closing_comment', 0)==0) {
150            $sql = sprintf("UPDATE {node} SET comment = 1 WHERE (created < '%d') AND (comment = 2) AND (%s)", //%s is escaped on in the fuction and breaks the sql statement
151              $oldest_allowed,
152              _comment_closer_node_select($process_node_type_list)
153              );
154            $result = db_query($sql);
155            $msg = 'sql = %sql';
156            $vars = array( '%sql' => $sql );
157            watchdog('comment_closer',$msg, $vars, WATCHDOG_DEBUG);
158          }
159          else {
160            $sql = sprintf(
161              "SELECT * FROM {node} WHERE (created < '%d') AND (comment = 2) AND (%s)", //%s is escaped on in the fuction and breaks the sql statement
162              $oldest_allowed,
163              _comment_closer_node_select($process_node_type_list)
164              );
165            $result = db_query($sql);
166            $msg = 'sql = %sql';
167            $vars = array( '%sql' => $sql );
168            watchdog('comment_closer',$msg, $vars, WATCHDOG_DEBUG);
169    
170            while ($data = db_fetch_object($result)) {
171              $post_comment = array(
172                'nid' => $data->nid,
173                'pid' => 0,
174                'uid' => 1,
175                'subject' => t(variable_get('comment_closer_insert_subject', COMMENT_CLOSER_SUBJECT), $variables),
176                'comment' => t(variable_get('comment_closer_insert_body', COMMENT_CLOSER_BODY), $variables),
177                'format' =>  FILTER_FORMAT_DEFAULT,
178                'timestamp' =>  format_date($now, 'custom', 'Y-m-d H:i O'),
179                'status' => 0,
180                'name' => $admin->name,
181                'mail' => variable_get('site_mail', ini_get('sendmail_from')),
182                'homepage' => '',
183              );
184              _comment_closer_comment_save($post_comment);
185              $sql = sprintf(
186                "UPDATE {node} SET comment = 1 WHERE nid = %d",
187                $data->nid
188              );
189              db_query($sql);
190              $msg = 'comment_closer: Closing comments for node %node';
191              $vars = array( '%node' => $data->nid);
192              watchdog('comment_closer', $msg, $vars, WATCHDOG_INFO);
193            }
194          }
195          // clean it up
196          $current_date = getdate();
197    
198          switch (variable_get('comment_closer_cycle_period', 'weekly')) {
199            case 'monthly': {
200              $current_date['mon'] = $current_date['mon'] + 1;
201              break;
202            }
203            case 'quarterly': {
204              $current_date['mon'] = $current_date['mon'] + 3;
205              break;
206            }
207            case 'yearly': {
208              $current_date['year'] = $current_date['year'] + 1;
209              break;
210            }
211            case 'weekly': {
212              $current_date['mday'] = $current_date['mday'] + 7;
213              break;
214            }
215            case 'daily': {
216              $current_date['mday'] = $current_date['mday'] + 1;
217              break;
218            }
219        }        }
220      }        $comment_closer_next_date = mktime($current_date['hours'], $current_date['minutes'], $current_date['seconds'], $current_date['mon'], $current_date['mday'], $current_date['year']);
     // clean it up  
     $current_date = getdate();  
221    
222      switch (variable_get('comment_closer_cycle_period', 'weekly')) {        variable_set('comment_closer_next_date', $comment_closer_next_date);
       case 'monthly': {  
         $current_date['mon'] = $current_date['mon'] + 1;  
         break;  
       }  
       case 'quarterly': {  
         $current_date['mon'] = $current_date['mon'] + 3;  
         break;  
       }  
       case 'yearly': {  
         $current_date['year'] = $current_date['year'] + 1;  
         break;  
       }  
       case 'weekly': {  
         $current_date['mday'] = $current_date['mday'] + 7;  
         break;  
       }  
       case 'daily': {  
         $current_date['mday'] = $current_date['mday'] + 1;  
         break;  
       }  
223      }      }
   $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);  
224    }    }
225  }  }
226    

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

  ViewVC Help
Powered by ViewVC 1.1.2