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 23 Jun 2009 16:16:11 -0000 @@ -1,4 +1,4 @@ -// $Id: +// $Id$ INSTALLATION: @@ -11,4 +11,4 @@ INSTALLATION: 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 23 Jun 2009 16:16:11 -0000 @@ -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. 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 23 Jun 2009 16:16:11 -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 23 Jun 2009 16:16:12 -0000 @@ -1,61 +1,68 @@ '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("

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.

", - array('!user-access-control' => l('user access control', 'admin/user/access'))) + '#prefix' => '

', + '#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' => '

', ); - + // 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 = ' (comments are currently read only)'; break; case 2: $status = ''; - break; + break; default: // case 0 $status = ' (comments are currently disabled)'; 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 @@ function comment_perm_admin_settings() { '#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 @@ function comment_perm_admin_settings() { '#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_admin_settings() { */ 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 @@ 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 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 @@ function comment_perm_form_alter($form_i } } } - + // display a message to users who can't post comments $form['text'] = array( - '#value' => '

' . _comment_perm_access_denied_message() . '

' + '#value' => '

'. _comment_perm_access_denied_message() .'

' ); } } + + 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 @@ function comment_perm_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('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('|