--- comment_perm.module 2008-10-03 20:04:12.000000000 -0400 +++ /comment_perm/comment_perm.module 2009-05-24 13:06:00.000000000 -0400 @@ -4,20 +4,17 @@ /** * 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; } @@ -27,12 +24,14 @@ function comment_perm_menu($may_cache) { 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) { @@ -71,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.') ); - + return system_settings_form($form); } @@ -85,6 +84,7 @@ function comment_perm_perm() { foreach ($types as $type) { if ($type) { $perms[] = 'comment on ' . $type . ' content'; + $perms[] = 'view comments on '. $type . ' content'; } } } @@ -104,11 +104,21 @@ function comment_perm_comment($a1, $op) break; } } +/** ++ * Implementation of hook_nodeapi(). ++ */ +function comment_perm_nodeapi(&$node, $op, $arg = 0) { + switch ($op) { + case 'alter': + $node->comment = comment_perm_access($node); + break; + } +} /** * 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)) { @@ -146,9 +156,12 @@ function comment_perm_form_alter($form_i /** * Implementation of hook_link_alter(). */ -function comment_perm_link_alter(&$node, &$links) { - if (!comment_perm_access($node)) { - unset($links['comment_add']); +function comment_perm_link_alter(&$links, $node) { + if (comment_perm_access($node) != COMMENT_NODE_READ_WRITE) { + unset($links['comment_add']); + if (module_exists('quote')) { + unset($links['quote']); + } } } @@ -159,14 +172,22 @@ 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', ''); if (is_array($types)) { if (in_array($node->type, $types)) { - if (!user_access('comment on ' . $node->type . ' content')) { - return false; - } + if(user_access('view comments on ' . $node->type . ' content') && user_access('comment on ' . $node->type . ' content')) + { + return COMMENT_NODE_READ_WRITE; + } + else if(!user_access('comment on ' . $node->type . ' content') && user_access('view comments on ' . $node->type . ' content')) + { + return COMMENT_NODE_READ; + } + else + { + return COMMENT_NODE_DISABLED; + } } } return true;