function commentaccess_node_view in Comment Access 7
Implementation of hook_node_view().
We duplicate code from comment_node_page_additions() to add the comment thread when it might need to be added, but only when the original code has not run because there are no published comments. Our query alter hook is still active in this circumstance.
See also
commentaccess_query_comment_filter_alter()
File
- ./
commentaccess.module, line 209 - Provides users with permissions for comments on nodes they own.
Code
function commentaccess_node_view($node, $view_mode) {
global $user;
// this first condition is copied from comment_node_view():
// add comments only if we are on the node page, in "full" view mode
if ($node->comment && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) {
if (empty($node->content['comments']['comments']) && $node->comment_count == 0) {
if ($node->uid == $user->uid && (user_access("approve comments on own {$node->type}") || user_access("administer comments on own {$node->type}"))) {
// there are no published comments, but this user has permissions to
// work with unpublished comments. So we run the same code as
// comment_node_page_additions() to add the comment thread.
$mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
$comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
if ($cids = comment_get_thread($node, $mode, $comments_per_page)) {
$comments = comment_load_multiple($cids);
comment_prepare_thread($comments);
$build = comment_view_multiple($comments, $node);
$build['pager']['#theme'] = 'pager';
$node->content['comments']['comments'] = $build;
}
}
}
}
}