diff --git a/sites/all/modules/forum_access/forum_access.module b/sites/all/modules/forum_access/forum_access.module index 19f6a17..9af64dd 100644 --- a/sites/all/modules/forum_access/forum_access.module +++ b/sites/all/modules/forum_access/forum_access.module @@ -125,9 +125,8 @@ function forum_access_init() { if ($level = forum_access_access($tid, $a)) { module_load_include('node.inc', 'forum_access'); $user->_forum_access_moderator = $level; - if (arg(0) == 'comment' || arg(0) == 'node' && arg(2) == 'edit') { - _forum_access_enable_moderator(); - } + // globally enable comment moderator on node view - not only on node edits and comment paths + _forum_access_enable_moderator(); } } } @@ -321,12 +320,34 @@ if (!variable_get('forum_access_D5_legacy_mode', FALSE)) * Remove the 'Add new comment' link from nodes, if the user does not have the * 'create' permission. */ -function forum_access_link_alter(&$links, $node) +function forum_access_link_alter(&$links, $node, $comment = NULL) { global $user; + if ($user->uid != 1 && ($tid = _forum_access_get_tid($node)) && isset($links['comment_add']) && !forum_access_access($tid, 'create')) { unset($links['comment_add']); } + + $tid = $node->tid; + if (isset($links['comment_reply']) && (!forum_access_access($tid, 'create'))) + { + unset($links['comment_reply']); + } + if (isset($links['comment_edit']) && !forum_access_access($tid, 'update') && +!comment_access('edit', $comment)) { + unset($links['comment_edit']); + } + if (isset($links['comment_delete']) && !forum_access_access($tid, 'delete')) +{ + unset($links['comment_delete']); + } + + if (!isset($links['comment_reply'])) { + $links['comment_forbidden'] = array( + 'title' => theme('comment_post_forbidden', $variables['node']), + 'html' => TRUE, + ); + } } /** @@ -342,19 +363,6 @@ function forum_access_preprocess_box(&$variables) { } } -/** - * Implementation of $modulename_preprocess_$hook() for comment. - * - * Recreate comment links (they've already been themed), and - * remove those that aren't accessible to the user. - */ -function forum_access_preprocess_comment(&$variables) { - if (isset($variables['node']->tid)) { - module_load_include('node.inc', 'forum_access'); - _forum_access_preprocess_comment($variables); - } -} - } // End of !LEGACY-MODE /** diff --git a/sites/all/modules/forum_access/forum_access.node.inc b/sites/all/modules/forum_access/forum_access.node.inc index cf4cad5..e1c4a24 100644 --- a/sites/all/modules/forum_access/forum_access.node.inc +++ b/sites/all/modules/forum_access/forum_access.node.inc @@ -202,42 +202,3 @@ function _forum_access_get_all_roles() { return $roles; } -/** - * Recreate comment links (they've already been themed), and - * remove those that aren't accessible to the user. - */ -function _forum_access_preprocess_comment(&$variables) { - global $user; - if (!empty($user->_forum_access_moderator)) { - _forum_access_enable_moderator(); // this allows us to retrieve the comment links (without setting precedent!) - } - - $tid = $variables['node']->tid; - $links = module_invoke_all('link', 'comment', $variables['comment'], 0); - - if (!empty($user->_forum_access_moderator) && arg(0) == 'node' && arg(2) == NULL) { - _forum_access_disable_moderator(); - } - - if (isset($links['comment_reply']) && (!preg_match('#
  • #U', $variables['links']) || !forum_access_access($tid, 'create'))) { - unset($links['comment_reply']); - } - if (isset($links['comment_edit']) && !forum_access_access($tid, 'update') && !comment_access('edit', $variables['comment'])) { - unset($links['comment_edit']); - } - if (isset($links['comment_delete']) && !forum_access_access($tid, 'delete')) { - unset($links['comment_delete']); - } - foreach(array_keys($links) as $link) { - if (!in_array($link, array('comment_reply', 'comment_edit', 'comment_delete')) && !preg_match('#
  • #U', $variables['links'])) { - unset($links[$link]); // eliminate possible additional unknown links that came in for 'administer_comments' - } - } - if (empty($links)) { - $links['comment_forbidden'] = array( - 'title' => theme('comment_post_forbidden', $variables['node']), - 'html' => TRUE, - ); - } - $variables['links'] = theme('links', $links); -}