Index: usercomment.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/usercomment/usercomment.module,v retrieving revision 1.5.2.5 diff -u -p -r1.5.2.5 usercomment.module --- usercomment.module 30 Jan 2009 23:49:09 -0000 1.5.2.5 +++ usercomment.module 7 Feb 2009 17:01:46 -0000 @@ -127,7 +127,7 @@ function usercomment_menu() { $items['usercomment/delete'] = array( 'type' => MENU_CALLBACK, 'page callback' => 'comment_delete', - 'access callback' => usercomment_menu_access, + 'access callback' => 'usercomment_menu_access', 'access arguments' => array('delete'), 'file path' => drupal_get_path('module', 'comment'), 'file' => 'comment.admin.inc', @@ -136,8 +136,8 @@ function usercomment_menu() { 'type' => MENU_CALLBACK, 'page callback' => 'usercomment_approve', 'page arguments' => array(2), - 'access callback' => usercomment_menu_access, - 'access arguments' => array('approve'), + 'access callback' => 'usercomment_menu_access', + 'access arguments' => array('approve', 2), ); return $items; } @@ -145,19 +145,26 @@ function usercomment_menu() { /** * Define menu access permission */ -function usercomment_menu_access($op) { +function usercomment_menu_access($op, $cid = NULL) { global $user; - $cid = arg(2); - if (!empty($cid)) { + + if (is_numeric($cid)) { $comment = _comment_load($cid); $node = node_load($comment->nid); - } + } + + if (user_access('administer comments')) { + return TRUE; + } + switch ($op) { case 'approve': - return ($user->uid == $node->uid || user_access('administer comments', $user)); + return ($user->uid == $node->uid); case 'delete': return ($user->uid == $node->uid || usercomment_access_check($comment->cid)); } + + return FALSE; } /** @@ -177,19 +184,34 @@ function usercomment_nodeapi(&$node, $op } /** - * Implementation of hook_perm() + * Implementation of hook_perm(). */ function usercomment_perm() { - $perms = array(); - $perms[] = 'skip author\'s approval queue when posting comments'; - foreach (node_get_types() as $node) { + $perms = array( + "skip author's approval queue when posting comments", + 'administer comments on own content', + ); + + foreach (node_get_types() as $node) { $perms[] = 'delete comments on own '. check_plain($node->type) .' content'; $perms[] = 'approve comments on own '. check_plain($node->type) .' content'; } + return $perms; } /** + * Implementation of hook_form_alter(). + */ +function usercomment_form_alter(&$form, $form_state, $form_id) { + global $user; + + if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { + $form['comment_settings']['#access'] |= ($user->uid == $form['#node']->uid && user_access('administer comments on own content')); + } +} + +/** * Implementation of hook_user() */ function usercomment_user($op, &$edit, &$account, $category = NULL) { @@ -497,7 +519,7 @@ function usercomment_approval_form($node function usercomment_theme() { return array( 'usercomment' => array( - 'arguments' => array($content), + 'arguments' => array('content' => NULL), ), ); }