--- commentcloser/comment_closer.module	2010-12-06 20:33:06.000000000 +0000
+++ Hacked/commentcloser/comment_closer.module	2011-07-20 19:55:30.000000000 +0100
@@ -7,6 +7,11 @@
  * Automatically close comments on nodes beyond a configurable age
  */
 
+define('COMMENT_CLOSER_STATUS_DEFAULT', 0); // Respect the default in settings (either auto close or nothing)
+define('COMMENT_CLOSER_STATUS_DONOTCLOSE', 1);
+//define('COMMENT_CLOSER_STATUS_AUTOCLOSE', 2);
+//define('COMMENT_CLOSER_STATUS_REOPENED', 3); // Unneeded - just set to donotclose
+
 /**
  * Implements hook_help().
  */
@@ -123,16 +128,52 @@ function comment_closer_settings() {
  * Show a message about when the closing will happen.
  */
 function comment_closer_nodeapi(&$node, $op, $teaser, $page) {
-  // If we are on a cc node type and have enabled the notice, display it.
-  if (variable_get("comment_closer_age_number_$node->type", 0)
-    && variable_get("comment_closer_notice_$node->type", 0) == 1) {
-    if ($op == 'view' && $page == TRUE) {
-      $node->content['comment_closer_notice'] = array(
-        '#value' => theme('comment_closer_notice', $node),
-        // Put it at the bottom, close to the comments.
-        '#weight' => 10,
-      );
-    }
+  
+  switch ($op) {
+    case 'view':
+      // If we are on a cc node type and have enabled the notice, display it.
+      if (variable_get("comment_closer_age_number_$node->type", 0)
+        && variable_get("comment_closer_notice_$node->type", 0) == 1) {
+        if ($page == TRUE) {
+          $node->content['comment_closer_notice'] = array(
+            '#value' => theme('comment_closer_notice', $node),
+            // Put it at the bottom, close to the comments.
+            '#weight' => 10,
+          );
+        }
+      }
+    
+      break;
+    case 'load':
+      $status = db_result(db_query("SELECT status FROM {comment_closer_node} WHERE nid = %d", $node->nid));
+      if ($status !== FALSE) {
+        $node->comment_closer_status = $status;
+      }
+      break;
+    case 'insert':
+    case 'update':
+      if (isset($node->comment_closer_status)) {
+        $object = new stdClass();
+        $object->nid = $node->nid;
+        $object->status = $node->comment_closer_status;        
+        $old_status = db_result(db_query("SELECT status FROM {comment_closer_node} WHERE nid = %d", $node->nid));
+        // Only record if set to not close or if record already exists
+        if ($object->status || (!$object->status && $old_status !== FALSE)) {
+          // New record
+          if ($old_status === FALSE) {
+            drupal_write_record('comment_closer_node', $object);
+          // Update record
+          } else {
+            $result = drupal_write_record('comment_closer_node', $object, 'nid');
+          }
+        }
+      }
+      break;
+    case 'delete':
+      db_query("DELETE FROM {comment_closer_node} WHERE nid = %d", $node->nid);
+      break;
+    case 'default':
+      break;
   }
 }
 
@@ -145,6 +186,11 @@ function theme_comment_closer_notice($no
 
   $type = node_get_types('name', $node);
 
+  // If node set to DONOTCLOSE no message needed.
+  if ($node->comment_closer_status == COMMENT_CLOSER_STATUS_DONOTCLOSE) {
+    return '';
+  }
+
   // Is commenting active now?
   if ($node->comment == COMMENT_NODE_READ_WRITE) {
     $when = strtotime("+$age_num $age_unit", $node->created);
@@ -188,10 +234,22 @@ function comment_closer_cron() {
       $oldest_allowed = _comment_closer_oldest_allowed($age_unit, $age_num, $now);
 
       // Knock it out.
-      $query = "UPDATE {node} SET comment = 1 WHERE created < %d AND type = '%s'";
+      $query = "SELECT nid FROM {node} WHERE created < %d AND type = '%s' AND comment = 2";
       $args = array($oldest_allowed, $type);
       $result = db_query($query, $args);
-      $affected = db_affected_rows();
+      // Cycle through nodes and check their status flag
+      $affected = 0;
+      while ($node = db_fetch_array($result)) {
+        $query = "SELECT status FROM comment_closer_node WHERE nid = %d";
+        $status = db_result(db_query($query, array($node['nid'])));
+        // If status flag is not set to "do not close", then update
+        if (!$status) {
+          $query = "UPDATE {node} n SET comment = 1 WHERE nid = %d";
+          $result_update = db_query($query, array($node['nid']));
+          if (db_affected_rows()) $affected++;
+        }
+      }
+      // Log
       if ($affected) {
         $vars = array(
           '!count' => $affected,
@@ -205,14 +263,25 @@ function comment_closer_cron() {
 
     // If a comment limit is set, do this one.
     if ($com_limit) {
-      $query = "UPDATE {node} n, {node_comment_statistics} ncs "
-        . "SET n.comment = 1 "
-        . "WHERE ncs.nid = n.nid AND n.comment = 2 "
-        . "AND ncs.comment_count >= %d AND n.type = '%s' "
+      $query = "SELECT n.nid FROM {node} n "
+        . "LEFT JOIN {node_comment_statistics} ncs ON (n.nid = ncs.nid) "
+        . "WHERE n.comment = 2 AND ncs.comment_count >= %d AND n.type = '%s' "
         ;
       $args = array($com_limit, $type);
       $result = db_query($query, $args);
-      $affected = db_affected_rows();
+      // Cycle through nodes and check their status flag
+      $affected = 0;
+      while ($node = db_fetch_array($result)) {
+        $query = "SELECT status FROM comment_closer_node WHERE nid = %d";
+        $status = db_result(db_query($query, array($node['nid'])));
+        // If status flag is not set to "do not close", then update
+        if (!$status) {
+          $query = "UPDATE {node} n SET comment = 1 WHERE nid = %d";
+          $result_update = db_query($query, array($node['nid']));
+          if (db_affected_rows()) $affected++;
+        }
+      }
+      // Log
       if ($affected) {
         $vars = array(
           '!count' => $affected,
@@ -315,7 +384,9 @@ function comment_closer_form_alter(&$for
 
   switch ($form_id) {
     case 'node_type_form':
-      $type = $form['identity']['type']['#value'];
+      if (!$type = $form['identity']['type']['#default_value']) { // unlocked edit form
+        $type = $form['identity']['type']['#value']; // locked edit form
+      }
 
       // This setting should already be at the top, but force it.
       $form['comment']['comment']['#weight'] = -10;
@@ -402,6 +473,25 @@ function comment_closer_form_alter(&$for
 
       return;
   }
+
+  if (isset($form['#node']) && $form_id == $form['#node']->type .'_node_form') {
+    $node = $form['#node'];
+    $age_num = variable_get("comment_closer_age_number_$node->type", 0);
+    $age_unit = variable_get("comment_closer_age_unit_$node->type", 'day');
+    $com_limit = variable_get("comment_closer_comment_limit_$node->type", 0);
+    if ($age_num != 0 || $com_limit != 0) {
+      $form['comment_settings']['comment_closer_status'] = array(
+        '#type' => 'select',
+        '#weight' => user_access('administer comments'),
+        '#title' => t('Comment closer settings for this node'),
+        '#default_value' => $node->comment_closer_status ? $node->comment_closer_status : COMMENT_CLOSER_STATUS_DEFAULT,
+        '#options' => array(
+          COMMENT_CLOSER_STATUS_DEFAULT => 'Site default',
+          COMMENT_CLOSER_STATUS_DONOTCLOSE => 'Do not close comments',
+        ),
+      );
+    }
+  }
 }
 
 function _comment_closer_age_validate($element, &$form_state) {
