/[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, Wed Jan 3 03:45:54 2007 UTC revision 1.11, Sun Jun 8 18:25:58 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /* $Id: comment_closer.module,v 1.9 2006/12/31 22:45:02 prometheus6 Exp $ */  // $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  function comment_closer_help($section) {   */
8    switch($section) {  
9    
10    define('COMMENT_CLOSER_SUBJECT', t('Comments closed at !date'));
11    define('COMMENT_CLOSER_BODY', t('The entry no longer accepts comments.'));
12    
13    function comment_closer_help($path, $arg) {
14      switch ($path) {
15      case 'admin/block/help':      case 'admin/block/help':
16        return t('<p>Automatically close comments</p>');        return t('<p>Automatically close comments</p>');
17        break;        break;
# Line 24  function comment_closer_help($section) { Line 30  function comment_closer_help($section) {
30    return $output;    return $output;
31  }  }
32    
33  function _comment_closer_nodeoptions($nodetypes){  function _comment_closer_nodeoptions($nodetypes) {
34    return drupal_map_assoc(array_keys($nodetypes));    return drupal_map_assoc(array_keys($nodetypes));
35  }  }
36    
# Line 62  function comment_closer_settings() { Line 68  function comment_closer_settings() {
68      '#default_value' => variable_get('comment_closer_cycle_period', array('daily')),      '#default_value' => variable_get('comment_closer_cycle_period', array('daily')),
69      '#options' => $cycle_length_list,      '#options' => $cycle_length_list,
70    );    );
71      $cc_form['comment_closer_insert_closing_comment'] = array(
72        '#type' => 'checkbox',
73        '#title' => t('Insert Comment'),
74        '#default_value' => variable_get('comment_closer_insert_closing_comment', 0),
75        '#description' => t('Insert a comment when closed comments are closed.'),
76      );
77      $cc_form['comment_closer_insert_subject'] = array(
78        '#type' => 'textfield',
79        '#title' => t('Comment Closer Subject'),
80        '#default_value' => variable_get('comment_closer_insert_subject', COMMENT_CLOSER_SUBJECT),
81        '#description' => t('Subject of messages when closing the comments')
82      );
83      $cc_form['comment_closer_insert_body'] = array(
84        '#type' => 'textarea',
85        '#title' => t('Comment Closer Body'),
86        '#default_value' => variable_get('comment_closer_insert_body', COMMENT_CLOSER_BODY),
87        '#rows' => 10,
88        '#description' => t('Customize the messages when closing the comments.') .' '. t('Available variables are:') .' !site, !uri, !uri_brief, !date.'
89      );
90    return system_settings_form($cc_form);    return system_settings_form($cc_form);
91  }  }
92    
93  function _comment_closer_node_select($nodetypes){  function _comment_closer_node_select($nodetypes) {
94    if ($nodetypes == 0) {    if ($nodetypes == 0 || ! is_array($nodetypes) || ! count($nodetypes) ) {
95      return '';      return '';
96    } else {    }
97      foreach ($nodetypes as $nodetype_index){    else {
98        foreach ($nodetypes as $nodetype_index) {
99        $node_condition[] = "(type='$nodetype_index')";        $node_condition[] = "(type='$nodetype_index')";
100      }      }
101      return " AND (".implode(" OR ", $node_condition).')';      return " AND (". implode(" OR ", $node_condition) .")";
102    }    }
103  }  }
104    
# Line 81  function comment_closer_cron() { Line 107  function comment_closer_cron() {
107    $now = time();    $now = time();
108    $current_date = getdate($now);    $current_date = getdate($now);
109    $next_cycle_time = variable_get('comment_closer_next_date', $now);    $next_cycle_time = variable_get('comment_closer_next_date', $now);
110      $variables = array(
111        '!site' => variable_get('site_name', 'Drupal'),
112        '!uri' => $base_url,
113        '!uri_brief' => substr($base_url, strlen('http://')),
114        '!date' => format_date(time()),
115      );
116    
117    if ($now >= $next_cycle_time) {    if ($now >= $next_cycle_time) {
118      //set it up      //set it up
# Line 107  function comment_closer_cron() { Line 139  function comment_closer_cron() {
139      $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']);
140    
141      // knock it out      // knock it out
     $qstr = "UPDATE {node} SET comment = 1 WHERE (created < $oldest_allowed) ".  
                         _comment_closer_node_select($process_node_type_list);  
142      cache_clear_all();      cache_clear_all();
     $result = db_query($qstr);  
143    
144        if (variable_get('comment_closer_insert_closing_comment', 0)) {
145          $result = db_query(
146            "UPDATE {node} SET comment = 1 WHERE (created < '%d') '%s'",
147            $oldest_allowed,
148            _comment_closer_node_select($process_node_type_list)
149          );
150        }
151        else {
152          $result = db_query(
153            "SELECT * FROM {node} WHERE comment = 2 AND (created < '%d') '%s'",
154            $oldest_allowed,
155            _comment_closer_node_select($process_node_type_list)
156          );
157          while ($data = db_fetch_object($result)) {
158            $post_comment = array(
159              'nid' => $data->nid,
160              'pid' => 0,
161              'uid' => 1,
162              'subject' => t(variable_get('comment_closer_insert_subject', COMMENT_CLOSER_SUBJECT), $variables),
163              'comment' => t(variable_get('comment_closer_insert_body', COMMENT_CLOSER_BODY), $variables),
164              'format' => '',
165              'timestamp' => '',
166              'status' => '',
167              'name' => 'admin',
168              'mail' => 'emailaddress',
169              'homepage' => 'homepage',
170            );
171            comment_save($post_comment);
172            db_query(
173              "UPDATE {node} SET comment = 1 WHERE nid = %d",
174              $data->nid
175            );
176          }
177        }
178      // clean it up      // clean it up
179      $current_date = getdate();      $current_date = getdate();
180    
# Line 120  function comment_closer_cron() { Line 183  function comment_closer_cron() {
183          $current_date['mon'] = $current_date['mon'] + 1;          $current_date['mon'] = $current_date['mon'] + 1;
184          break;          break;
185        }        }
186         case 'quarterly': {        case 'quarterly': {
187          $current_date['mon'] = $current_date['mon'] + 3;          $current_date['mon'] = $current_date['mon'] + 3;
188          break;          break;
189        }        }
# Line 139  function comment_closer_cron() { Line 202  function comment_closer_cron() {
202      }      }
203    $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']);
204    
205      variable_set('comment_closer_next_date',$comment_closer_next_date);      variable_set('comment_closer_next_date', $comment_closer_next_date);
206    }    }
207  }  }
208    
209  function comment_closer_menu($may_cache) {  function comment_closer_menu() {
210          $items[] = array(    $items['admin/settings/comment_closer'] = array(
211      'path' => 'admin/settings/comment_closer',      'title' => 'Comment closer',
212      'title' => t('Comment closer'),      'description' => 'Set age, frequency and types of nodes for which comments will be closed.',
213      'description' => t('Set age, frequency and types of nodes for which comments will be closed.'),      'page callback' => 'drupal_get_form',
214      'callback' => 'drupal_get_form',      'page arguments' => array('comment_closer_settings'),
215      'callback arguments' => 'comment_closer_settings',      'access arguments' => array('administer site configuration'),
     'access' => user_access('administer site configuration'),  
216    );    );
217    return $items;    return $items;
218  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.2