Index: INSTALL.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/comment_perm/INSTALL.txt,v
retrieving revision 1.1
diff -u -p -r1.1 INSTALL.txt
--- INSTALL.txt	4 Oct 2008 00:04:12 -0000	1.1
+++ INSTALL.txt	10 Oct 2009 09:46:21 -0000
@@ -1,4 +1,4 @@
-// $Id: 
+// $Id$
 
 INSTALLATION:
 
@@ -7,8 +7,14 @@ INSTALLATION:
 
 2) Enable the module.
 
-3) Go to Administer/Content management/Comment permissions and enable the extended comment permissions for certain content types here.
+3) Go to Administer/Content management/Comment permissions and enable the 
+   extended comment permissions for certain content types here.
 
-4) Go to Administer/User management/Access control and configure which roles can post comments for the these content types.
+4) Go to Administer/User management/Access control and configure which roles 
+   can post comments for the these content types.
 
-NOTE: Comments must already be enabled for this module to do anything.  This module simply removes the ability for a user to post comments if they don't have the right permissions.  It does not add the ability to comment on node types that don't have commenting enabled!
\ No newline at end of file
+NOTE: Comments must already be enabled for this module to do anything.  
+      This module simply removes the ability for a user to post comments if 
+      they don't have the right permissions.  
+      It does not add the ability to comment on node types that don't have 
+      commenting enabled!
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/comment_perm/README.txt,v
retrieving revision 1.1
diff -u -p -r1.1 README.txt
--- README.txt	4 Oct 2008 00:04:12 -0000	1.1
+++ README.txt	10 Oct 2009 09:46:21 -0000
@@ -1,5 +1,11 @@
-// $Id: 
+// $Id$
 
-The Comment Permissions module enables control of commenting by user role and by node type.  Additional user permissions for selected node types are added to the user access system so you can configure commenting with more control than Drupal core provides.
+The Comment Permissions module enables control of commenting by user role and 
+by node type.  Additional user permissions for selected node types are added 
+to the user access system so you can configure commenting with more control 
+than Drupal core provides.
 
-Note that "reply" links below comments may still appear for users without the permission to add comments.  This is unfortunate, but I haven't found a workaround.  See http://drupal.org/node/185855 for more information.  Of course, the links can easily be removed in the theme layer.
\ No newline at end of file
+Note that "reply" links below comments may still appear for users without the 
+permission to add comments.  This is unfortunate, but I haven't found a 
+workaround.  See http://drupal.org/node/185855 for more information.  
+Of course, the links can easily be removed in the theme layer.
Index: comment_perm.admin.inc
===================================================================
RCS file: comment_perm.admin.inc
diff -N comment_perm.admin.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ comment_perm.admin.inc	10 Oct 2009 09:46:22 -0000
@@ -0,0 +1,59 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Administration pages for Comment Permissions module.
+ */
+
+/**
+ * Menu callback.
+ * Presents the settings page for module Comment Permissions.
+ */
+function comment_perm_admin_settings() {
+  $form = array();
+  $form['help'] = array(
+    '#prefix' => '<p>',
+    '#suffix' => '</p>',
+    '#value' => t('Enable the extended comment permissions for certain content types here. Then go to the !user-permissions to configure which roles can post comments for the these content types.', array('!user-permissions' => l('user access permissions', 'admin/user/permissions'))),
+  );
+
+  // Get a list of all available node types.
+  $node_types = node_get_types();
+  foreach ($node_types as $type => $obj) {
+    switch (variable_get('comment_'. $type, 2)) {
+      case 0: // Disabled.
+        $status = '<em> '. t('(comments are currently disabled)') .'</em>';
+        break;
+      case 1: // Read only.
+        $status = '<em> '. t('(comments are currently read only)') .'</em>';
+        break;
+      case 2: // Read/Write.
+        $status = '';
+        break;
+    }
+    $types[$type] = $obj->name . $status;
+  }
+  $form['comment_perm_node_types'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Enable comment permissions by role for these content types'),
+    '#default_value' => variable_get('comment_perm_node_types', array()),
+    '#options' => $types,
+  );
+
+  $form['comment_perm_message_anon'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Commenting denied message for anonymous users'),
+    '#default_value' => variable_get('comment_perm_message_anon', t('Login or register to post comments!')),
+    '#description' => t('Ideally commentting will be invisible to those without permission to post, but just in case you can specify the message they will see.'),
+  );
+
+  $form['comment_perm_message_reg'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Commenting denied message for registered users'),
+    '#default_value' => variable_get('comment_perm_message_reg', t('Sorry, but you are not allowed to add comments here!')),
+    '#description' => t('Ideally commentting will be invisible to those without permission to post, but just in case you can specify the message they will see.'),
+  );
+
+  return system_settings_form($form);
+}
Index: comment_perm.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/comment_perm/comment_perm.info,v
retrieving revision 1.1
diff -u -p -r1.1 comment_perm.info
--- comment_perm.info	4 Oct 2008 00:04:12 -0000	1.1
+++ comment_perm.info	10 Oct 2009 09:46:22 -0000
@@ -1,4 +1,5 @@
-; $Id: 
+; $Id; 
 name = Comment Permissions
 description = Control commenting permissions by role AND by node type.
-dependencies = comment
\ No newline at end of file
+dependencies[] = comment
+core = 6.x
Index: comment_perm.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/comment_perm/comment_perm.module,v
retrieving revision 1.1
diff -u -p -r1.1 comment_perm.module
--- comment_perm.module	4 Oct 2008 00:04:12 -0000	1.1
+++ comment_perm.module	10 Oct 2009 09:46:23 -0000
@@ -1,90 +1,42 @@
 <?php
-// $Id: 
+// $Id$
 
 /**
- * Implementation of hook_menu().
+ * @file
+ * Module to control commenting permissions by role and by node type.
  */
-function comment_perm_menu($may_cache) {
-  $items = array();
-  
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/content/comment_perm',
-      'title' => t('Comment permissions'),
-      'description' => t('Setup comment permissions by user role and by node type.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => 'comment_perm_admin_settings',
-      'access' => user_access('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM
-    );
-  }
-  return $items;
-}
 
 /**
- * Menu callback; presents the comment_perm settings page.
+ * Implementation of hook_menu().
  */
-function comment_perm_admin_settings() {
-  $form = array();
-  $form['help'] = array(
-    '#value' => t("<p>Enable the extended comment permissions for certain content types here.
-      Then go to the !user-access-control to configure which roles can post comments for the
-      these content types.</p>",
-      array('!user-access-control' => l('user access control', 'admin/user/access')))
-  );
-  
-  // get node types
-  $node_types = node_get_types();
-  foreach ($node_types as $type => $obj) {
-    switch (variable_get('comment_' . $type, 0)) {
-      case 1:
-        $status = '<em> (comments are currently read only)</em>';
-        break;
-      case 2:
-        $status = '';
-        break;  
-      default: // case 0
-        $status = '<em>  (comments are currently disabled)</em>';
-        break;
-    }
-    $types[$type] = $obj->name . $status; 
-  }
-  $form['comment_perm_node_types'] = array(
-    '#type' => 'checkboxes',
-    '#title' => t('Enable comment permissions by role for these content types'),
-    '#default_value' => variable_get('comment_perm_node_types', ''),
-    '#options' => $types
-  );
-  
-  $form['comment_perm_message_anon'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Commenting denied message for anonymous users'),
-    '#default_value' => variable_get('comment_perm_message_anon', 'Login or register to post comments!'),
-    '#description' => t('Ideally commentting will be invisible to those without permission to post, but
-                         just in case you can specify the message they will see.')
-  );
-  
-  $form['comment_perm_message_reg'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Commenting denied message for registered users'),
-    '#default_value' => variable_get('comment_perm_message_reg', "We're sorry, but you can't post comments here!"),
-    '#description' => t('Ideally commentting will be invisible to those without permission to post, but
-                         just in case you can specify the message they will see.')
+function comment_perm_menu() {
+  $items = array();
+
+  $items['admin/content/comment_perm'] = array(
+    'title' => 'Comment permissions',
+    'description' => 'Setup comment permissions by user role and by node type.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('comment_perm_admin_settings'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
+    'file' => 'comment_perm.admin.inc',
   );
-  
-  return system_settings_form($form);
+  return $items;
 }
 
 /**
  * Implementation of hook_perm().
+ *
+ * Add two permissions per content type.
  */
 function comment_perm_perm() {
   $perms = array();
-  $types = variable_get('comment_perm_node_types', '');
+  $types = variable_get('comment_perm_node_types', array());
   if (is_array($types)) {
     foreach ($types as $type) {
       if ($type) {
-        $perms[] = 'comment on ' . $type . ' content';
+        $perms[] = 'comment '. $type .' content';
+        $perms[] = 'edit own comment on '. $type .' content';
       }
     }
   }
@@ -108,16 +60,17 @@ function comment_perm_comment($a1, $op) 
 /**
  * Implementation of hook_form_alter().
  */
-function comment_perm_form_alter($form_id, &$form) {
+function comment_perm_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'comment_form') {
     $nid = $form['nid']['#value'];
     if (!comment_perm_access($nid)) {
-      // for comment reply pages, redirect back to the node
+      // For comment reply pages, redirect back to the node.
       if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) {
         drupal_set_message(_comment_perm_access_denied_message(), 'error');
-        drupal_goto('node/' . arg(2));
-      } else {
-        // for inline comment forms, such remove their fields so nothing will show
+        drupal_goto('node/'. arg(2));
+      }
+      else {
+        // For inline comment forms, such remove their fields so nothing will show.
         unset($form['comment_filter']);
         foreach ($form as $key => $item) {
           if ($type = $item['#type']) {
@@ -133,51 +86,99 @@ function comment_perm_form_alter($form_i
             }
           }
         }
-        
-        // display a message to users who can't post comments
+
+        // Display a message to users who can't post comments.
         $form['text'] = array(
-          '#value' => '<p id="comment-perm-access-denied">' . _comment_perm_access_denied_message() . '</p>'
+          '#value' => '<p id="comment-perm-access-denied">'. _comment_perm_access_denied_message() .'</p>'
         );
       }
     }
+
+    if (arg(0) == 'comment' && arg(1) == 'edit' && is_numeric(arg(2))) {
+      if (!comment_perm_edit_access($nid)) {
+        drupal_set_message(_comment_perm_access_denied_message(), 'error');
+        drupal_goto('node/'. $nid);
+      }
+    }
   }
 }
 
 /**
  * Implementation of hook_link_alter().
  */
-function comment_perm_link_alter(&$node, &$links) {
+function comment_perm_link_alter(&$links, $node) {
   if (!comment_perm_access($node)) {
     unset($links['comment_add']);
+    if (module_exists('quote')) {
+      unset($links['quote']);
+    }
   }
 }
 
 /**
- * Can the current user add comments to a given node?
+ * Check if the current user is allowed to add comments to the given node.
  */
 function comment_perm_access($node) {
   if (is_numeric($node)) {
     $node = node_load($node);
   }
-  
+
+  // Get node types managed by module Comment Permissions.
+  $types = variable_get('comment_perm_node_types', array());
+  if (is_array($types)) {
+    if (in_array($node->type, $types)) {
+      if (!user_access('comment '. $node->type .' content')) {
+        return FALSE;
+      }
+    }
+  }
+  return TRUE;
+}
+
+/**
+ * Check if the current user is allowed to edit comments.
+ */
+function comment_perm_edit_access($node) {
+  if (is_numeric($node)) {
+    $node = node_load($node);
+  }
+
   // get node types managed by comment_perm
-  $types = variable_get('comment_perm_node_types', '');
+  $types = variable_get('comment_perm_node_types', array());
   if (is_array($types)) {
     if (in_array($node->type, $types)) {
-      if (!user_access('comment on ' . $node->type . ' content')) {
-        return false;
+      if (user_access('administer comments')) {
+        return TRUE;
+      }
+      if (!user_access('edit own comment on '. $node->type .' content')) {
+        return FALSE;
       }
     }
   }
-  return true;
+  return TRUE;
+}
+
+/**
+ * Process variables for comment.tpl.php.
+ *
+ * @see theme_comment()
+ */
+function comment_perm_preprocess_comment(&$variables) {
+  // Remove edit link if the user has no proper permissions to add or edit comments.
+  if (isset($variables['links']) && !user_access('administer comments')) {
+    if (!comment_perm_edit_access($variables['node'])) {
+      $variables['links'] = preg_replace('|<li class="comment_edit.*?</li>|i', '', $variables['links']);
+    }
+  }
 }
 
 function _comment_perm_access_denied_message() {
   global $user;
-  
+
   if ($user->uid == 0) {
-    return variable_get('comment_perm_message_anon', 'Login or register to post comments!');
-  } else {
-    return variable_get('comment_perm_message_reg', "We're sorry, but you can't post comments here!");
+    return variable_get('comment_perm_message_anon', t('Login or register to post comments!'));
+  }
+  else {
+    return variable_get('comment_perm_message_reg', t('Sorry, but you are not allowed to add comments here!'));
   }
 }
