--- orig_comment.module	2006-01-03 14:16:26.000000000 +0200
+++ tmc_comment.module	2005-12-21 01:20:06.000000000 +0200
@@ -1,5 +1,5 @@
 <?php
-// $Id: comment.module,v 1.347.2.8 2005-11-15 20:37:56 dries Exp $
+// $Id: comment.module,v 1.12 2005/12/20 23:20:06 mait Exp $
 
 /**
  * @file
@@ -92,7 +92,7 @@ function comment_menu($may_cache) {
     $items[] = array('path' => 'admin/comment/edit', 'title' => t('edit comment'),
       'callback' => 'comment_admin_edit', 'access' => $access, 'type' => MENU_CALLBACK);
     $items[] = array('path' => 'admin/comment/delete', 'title' => t('delete comment'),
-      'callback' => 'comment_delete', 'access' => $access, 'type' => MENU_CALLBACK);
+      'callback' => 'comment_delete', 'access' => 1, 'type' => MENU_CALLBACK);
 
     // Tabs:
     $items[] = array('path' => 'admin/comment/list', 'title' => t('list'),
@@ -266,8 +266,13 @@ function comment_nodeapi(&$node, $op, $a
       break;
 
     case 'delete':
-      db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid);
-      db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid);
+      if(variable_get('comment_delete_mode', 0) == 1) {
+        db_query('UPDATE {comments} set status = 1 WHERE nid = %d', $node->nid);
+        db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid);
+      } else {
+        db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid);
+        db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid);
+      }
       break;
 
     case 'update index':
@@ -320,6 +325,10 @@ function comment_configure() {
   $group .= form_radios(t('Location of comment submission form'), 'comment_form_location', variable_get('comment_form_location', 0), array(t('Display on separate page'), t('Display below post or comments')));
   $output .= form_group(t('Comment posting settings'), $group);
 
+  $group = form_radios(t('Delete mode'), 'comment_delete_mode', variable_get('comment_delete_mode', 0), array(t('Delete'), t('Unpublish')));
+  $group .= form_radios(t('Node owner can delete node comments'), 'comment_moderating_nodeowner', variable_get('comment_moderating_nodeowner', 0), array(t('Disabled'), t('Enabled')));
+  $output .= form_group(t('Comment management settings'), $group);
+
   $result = db_query('SELECT fid, filter FROM {moderation_filters} ');
   while ($filter = db_fetch_object($result)) {
     $thresholds[$filter->fid] = ($filter->filter);
@@ -672,6 +681,7 @@ function comment_post($edit) {
 
 function comment_links($comment, $return = 1) {
   global $user;
+  global $node_info;
 
   $links = array();
 
@@ -681,8 +691,15 @@ function comment_links($comment, $return
   }
 
   if (node_comment_mode($comment->nid) == 2) {
+    if($node_info['uid'] == $user->uid && variable_get('comment_moderating_nodeowner', 0) == 1 || user_access('administer comments') && user_access('access administration pages')) {
+      if(variable_get('comment_delete_mode', 0) == 1) {
+        $links[] = l(t('unpublish'), "admin/comment/delete/$comment->cid");
+      } else {
+        $links[] = l(t('delete'), "admin/comment/delete/$comment->cid");
+      }
+    }
+
     if (user_access('administer comments') && user_access('access administration pages')) {
-      $links[] = l(t('delete'), "admin/comment/delete/$comment->cid");
       $links[] = l(t('edit'), "admin/comment/edit/$comment->cid");
       $links[] = l(t('reply'), "comment/reply/$comment->nid/$comment->cid");
     }
@@ -707,6 +724,12 @@ function comment_links($comment, $return
 function comment_render($node, $cid = 0) {
   global $user;
 
+  // Give out node owner information to detect node owner:
+  global $node_info;
+  $node_info = array();
+  $node_info['uid'] = $node->uid;
+  $node_info['nid'] = $node->nid;
+
   $mode = $_GET['mode'];
   $order = $_GET['order'];
   $threshold = $_GET['threshold'];
@@ -959,38 +982,52 @@ function comment_delete($cid) {
 
   $output = '';
 
-  // We'll only delete if the user has confirmed the
-  // deletion using the form in our else clause below.
-  if ($comment->cid && $_POST['edit']['confirm']) {
-    drupal_set_message(t('The comment and all its replies have been deleted.'));
+  // Access check
+  if (
+    user_access('administer comments') == 1 // if user is admin
+    || variable_get('comment_moderating_nodeowner', 0) == 1 // comment_moderating_nodeowner Enabled
+    && db_fetch_object(db_query('SELECT uid from {node} where nid = %d and uid = %d',$comment->nid,$GLOBALS['user']->uid)) // user owns node
+  ) {
 
-    // Delete comment and its replies.
-    _comment_delete_thread($comment);
+    // We'll only delete if the user has confirmed the
+    // deletion using the form in our else clause below.
 
-    _comment_update_node_statistics($comment->nid);
+    if ($comment->cid && $_POST['edit']['confirm']) {
 
-    // Clear the cache so an anonymous user sees that his comment was deleted.
-    cache_clear_all();
+      drupal_set_message(t('The comment and all its replies have been deleted.'));
 
-    drupal_goto("node/$comment->nid");
+      // Delete comment and its replies.
+      _comment_delete_thread($comment);
 
-  }
-  else if ($comment->cid) {
-    $output = theme('confirm',
-                    t('Are you sure you want to delete the comment %title?', array('%title' => theme('placeholder', $comment->subject))),
-                    'node/'. $comment->nid,
-                    t('Any replies to this comment will be lost. This action cannot be undone.'),
-                    t('Delete'));
-    // Show comment that is being deleted
-    $comment->comment = check_output($comment->comment, $comment->format);
-    $output .= theme('comment', $comment);
+      _comment_update_node_statistics($comment->nid);
 
-  }
-  else {
-    drupal_set_message(t('The comment no longer exists.'));
+      // Clear the cache so an anonymous user sees that his comment was deleted.
+      cache_clear_all();
+
+      drupal_goto("node/$comment->nid");
+
+    }
+    else if ($comment->cid) {
+      $output = theme('confirm',
+                      t('Are you sure you want to delete the comment %title?', array('%title' => theme('placeholder', $comment->subject))),
+                      'node/'. $comment->nid,
+                      t('Any replies to this comment will be lost. This action cannot be undone.'),
+                      t('Delete'));
+      // Show comment that is being deleted
+      $comment->comment = check_output($comment->comment, $comment->format);
+      $output .= theme('comment', $comment);
+
+    }
+    else {
+      drupal_set_message(t('The comment no longer exists.'));
+    }
+
+  } else {
+    drupal_set_message(t('You are not authorized to access this page.'));
   }
 
   print theme('page', $output);
+
 }
 
 function comment_save($id, $edit) {
@@ -1609,8 +1646,13 @@ function theme_comment_post_forbidden() 
 
 function _comment_delete_thread($comment) {
   // Delete the comment:
-  db_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid);
-  watchdog('content', t('Comment: deleted %subject.', array('%subject' => theme('placeholder', $comment->subject))));
+  if(variable_get('comment_delete_mode', 0) == 1) {
+    db_query('UPDATE {comments} set status = 1 WHERE cid = %d', $comment->cid);
+    watchdog('content', t('Comment: unpublished %subject.', array('%subject' => theme('placeholder', $comment->subject))));
+  } else {
+    db_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid);
+    watchdog('content', t('Comment: deleted %subject.', array('%subject' => theme('placeholder', $comment->subject))));
+  }
 
   module_invoke_all('comment', 'delete', $comment);
 
