| 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; |
| 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() { |
| 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(); |
| 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(); |
| 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 |
} |
} |
| 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 |
} |
} |