function node_comment_block_block_view in Node Comment Block 7.2
Same name and namespace in other branches
- 7 node_comment_block.module \node_comment_block_block_view()
Implements hook_block_view().
File
- ./
node_comment_block.module, line 26 - Moves the comments for a node into a block.
Code
function node_comment_block_block_view($delta = '') {
$block = array();
if ($delta == 'node_comments' || $delta == 'node_comments_secondary') {
module_load_include('inc', 'node_comment_block', 'includes/node_comment_block.controller');
// Check if the current path is a node path, and extract the node ID.
if (!($node = NodeCommentBlock::getNode(current_path()))) {
return array();
}
if ($node->comment == 0) {
return array();
}
$block['content'] = array();
if ($comments = NodeCommentBlock::getComments($node)) {
$show_form = variable_get('node_comment_block_show_form_' . $delta, 1);
$show_comments = variable_get('node_comment_block_show_comments_' . $delta, 1);
if (!$show_form) {
unset($comments['comment_form']);
}
if (!$show_comments) {
$comments['comments'] = array();
}
if ((!$show_comments || empty($comments['comments'])) && !$show_form) {
return array();
}
$block['content'] = $comments;
return $block;
}
// Show the login or register text to anonymous users if the setting is
// enabled and there are no comments to display.
$show_anonymous = variable_get('node_comment_block_show_anonymous_' . $delta, 0) == 1;
if (user_is_anonymous() && !user_access('post comments') && $show_anonymous) {
$block['subject'] = t('Comments');
$block['content'] = theme('comment_post_forbidden', array(
'node' => $node,
));
}
}
return $block;
}