function comment_nodeapi in Drupal 4
Same name and namespace in other branches
- 5 modules/comment/comment.module \comment_nodeapi()
- 6 modules/comment/comment.module \comment_nodeapi()
Implementation of hook_nodeapi().
File
- modules/
comment.module, line 276 - Enables users to comment on published content.
Code
function comment_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case 'load':
return db_fetch_array(db_query("SELECT last_comment_timestamp, last_comment_name, comment_count FROM {node_comment_statistics} WHERE nid = %d", $node->nid));
break;
case 'prepare':
if (!isset($node->comment)) {
$node->comment = variable_get("comment_{$node->type}", COMMENT_NODE_READ_WRITE);
}
break;
case 'insert':
db_query('INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) VALUES (%d, %d, NULL, %d, 0)', $node->nid, $node->created, $node->uid);
break;
case 'delete':
db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid);
break;
case 'update index':
$text = '';
$comments = db_query('SELECT subject, comment, format FROM {comments} WHERE nid = %d AND status = %d', $node->nid, COMMENT_PUBLISHED);
while ($comment = db_fetch_object($comments)) {
$text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format, FALSE);
}
return $text;
case 'search result':
$comments = db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $node->nid));
return format_plural($comments, '1 comment', '%count comments');
case 'rss item':
return array(
array(
'key' => 'comments',
'value' => url('node/' . $node->nid, NULL, 'comment', TRUE),
),
);
}
}