Index: comment_perm.info
===================================================================
--- comment_perm.info	(revision 930)
+++ comment_perm.info	(working copy)
@@ -1,7 +1,7 @@
-; $Id: 
+; $Id$
 name = Comment Permissions
 description = Control commenting permissions by role AND by node type.
-dependencies = comment
+dependencies[] = comment
 ; Information added by drupal.org packaging script on 2008-11-24
 version = "6.x-1.x-dev"
 core = "6.x"
Index: INSTALL.txt
===================================================================
--- INSTALL.txt	(revision 930)
+++ INSTALL.txt	(working copy)
@@ -1,4 +1,4 @@
-// $Id: 
+// $Id$
 
 INSTALLATION:
 
@@ -11,4 +11,4 @@
 
 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: comment_perm.module
===================================================================
--- comment_perm.module	(revision 930)
+++ comment_perm.module	(working copy)
@@ -1,61 +1,68 @@
 <?php
-// $Id: 
+// $Id$
 
 /**
+ * @file
+ * Module to control commenting permissions by role and by node type.
+ */
+
+/**
  * Implementation of hook_menu().
  */
-function comment_perm_menu($may_cache) {
+function comment_perm_menu() {
   $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
-    );
-  }
+
+  $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,
+  );
+
   return $items;
 }
 
+
 /**
  * Menu callback; presents the comment_perm settings page.
  */
 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')))
+    '#prefix' => '<p>',
+    '#value' => t('Enable the extended comment permissions for certain content types here.
+  Then go to the !administer_permissions to configure which roles can post comments for the
+  these content types.', array('!administer_permissions' => l('administer permissions', 'admin/user/permissions'))),
+    '#suffix' => '</p>',
   );
-  
+
   // get node types
   $node_types = node_get_types();
   foreach ($node_types as $type => $obj) {
-    switch (variable_get('comment_' . $type, 0)) {
+    switch (variable_get('comment_'. $type, 0)) {
       case 1:
         $status = '<em> (comments are currently read only)</em>';
         break;
       case 2:
         $status = '';
-        break;  
+        break;
       default: // case 0
         $status = '<em>  (comments are currently disabled)</em>';
         break;
     }
-    $types[$type] = $obj->name . $status; 
+    $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', ''),
+    '#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'),
@@ -63,7 +70,7 @@
     '#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'),
@@ -71,7 +78,7 @@
     '#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);
 }
 
@@ -80,11 +87,12 @@
  */
 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 on '. $type .' content';
+        $perms[] = 'edit own comment on '. $type .' content';
       }
     }
   }
@@ -108,15 +116,16 @@
 /**
  * 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
       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 {
+        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) {
@@ -133,22 +142,32 @@
             }
           }
         }
-        
+
         // 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']);
+    }
   }
 }
 
@@ -159,25 +178,66 @@
   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('comment on '. $node->type .' content')) {
+        return FALSE;
       }
     }
   }
-  return true;
+  return TRUE;
 }
 
+/**
+ * Can the current user edit comment?
+ */
+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', array());
+  if (is_array($types)) {
+    if (in_array($node->type, $types)) {
+      if (user_access('administer comments')) {
+        return TRUE;
+      }
+      if (!user_access('edit own comment on '. $node->type .' content')) {
+        return FALSE;
+      }
+    }
+  }
+  return TRUE;
+}
+
+
 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 {
+  }
+  else {
     return variable_get('comment_perm_message_reg', "We're sorry, but you can't post comments here!");
   }
 }
+
+/**
+ * Process variables for comment.tpl.php.
+ *
+ * @see comment.tpl.php
+ * @see theme_comment()
+ */
+function comment_perm_preprocess_comment(&$variables) {
+  // remove edit link
+  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']);
+    }
+  }
+}
+
Index: README.txt
===================================================================
--- README.txt	(revision 930)
+++ README.txt	(working copy)
@@ -1,5 +1,5 @@
-// $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.
 
-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.
