comment_nodeapi
Definition
comment_nodeapi(&$node, $op, $arg = 0)
modules/comment.module, line 238
Description
Implementation of hook_nodeapi().
Code
<?php
function comment_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case 'settings':
return form_radios(t('Default comment setting'), 'comment_'. $node->type, variable_get('comment_'. $node->type, 2), array(t('Disabled'), t('Read only'), t('Read/Write')), t('Users with the <em>administer comments</em> permission will be able to override this setting.'));
case 'fields':
return array('comment');
case 'form pre':
if (user_access('administer comments')) {
$selected = isset($node->comment) ? $node->comment : variable_get("comment_$node->type", 2);
$output = form_radios('', 'comment', $selected, array(t('Disabled'), t('Read only'), t('Read/write')));
return form_group(t('User comments'), $output);
}
break;
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));
case 'validate':
if (!user_access('administer comments')) {
// Force default for normal users:
$node->comment = variable_get("comment_$node->type", 2);
}
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 = 0', $node->nid);
while ($comment = db_fetch_object($comments)) {
$text .= '<h2>'. check_plain($comment->subject) .'</h2>'. check_output($comment->comment, $comment->format);
}
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');
}
}
?> 