<?php
function comment_edit($cid) {
global $user;
$comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', $cid));
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
if (comment_access('edit', $comment)) {
return comment_form_box((array)$comment);
}
else {
drupal_access_denied();
}
}
function comment_reply($node, $pid = NULL) {
drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title, 'node/'. $node->nid)));
$op = isset($_POST['op']) ? $_POST['op'] : '';
$output = '';
if (user_access('access comments')) {
if ($op == t('Preview')) {
if (user_access('post comments')) {
$output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), NULL);
}
else {
drupal_set_message(t('You are not authorized to post comments.'), 'error');
drupal_goto("node/$node->nid");
}
}
else {
if ($pid) {
if ($comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d', $pid, COMMENT_PUBLISHED))) {
if ($comment->nid != $node->nid) {
drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
drupal_goto("node/$node->nid");
}
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$output .= theme('comment_view', $comment, $node);
}
else {
drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
drupal_goto("node/$node->nid");
}
}
else if (user_access('access content')) {
$output .= node_view($node);
}
if (node_comment_mode($node->nid) != COMMENT_NODE_READ_WRITE) {
drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error');
drupal_goto("node/$node->nid");
}
else if (user_access('post comments')) {
$output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), t('Reply'));
}
else {
drupal_set_message(t('You are not authorized to post comments.'), 'error');
drupal_goto("node/$node->nid");
}
}
}
else {
drupal_set_message(t('You are not authorized to view comments.'), 'error');
drupal_goto("node/$node->nid");
}
return $output;
}