webmaster@1: name = $comment->uid ? $comment->registered_name : $comment->name; webmaster@1: if (comment_access('edit', $comment)) { webmaster@1: return comment_form_box((array)$comment); webmaster@1: } webmaster@1: else { webmaster@1: drupal_access_denied(); webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * This function is responsible for generating a comment reply form. webmaster@1: * There are several cases that have to be handled, including: webmaster@1: * - replies to comments webmaster@1: * - replies to nodes webmaster@1: * - attempts to reply to nodes that can no longer accept comments webmaster@1: * - respecting access permissions ('access comments', 'post comments', etc.) webmaster@1: * webmaster@1: * The node or comment that is being replied to must appear above the comment webmaster@1: * form to provide the user context while authoring the comment. webmaster@1: * webmaster@1: * @param $node webmaster@1: * Every comment belongs to a node. This is that node. webmaster@1: * webmaster@1: * @param $pid webmaster@1: * Some comments are replies to other comments. In those cases, $pid is the parent webmaster@1: * comment's cid. webmaster@1: * webmaster@1: * @return webmaster@1: * The rendered parent node or comment plus the new comment form. webmaster@1: */ webmaster@1: function comment_reply($node, $pid = NULL) { webmaster@1: // Set the breadcrumb trail. webmaster@1: drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title, 'node/'. $node->nid))); webmaster@1: $op = isset($_POST['op']) ? $_POST['op'] : ''; webmaster@1: webmaster@1: $output = ''; webmaster@1: webmaster@1: if (user_access('access comments')) { webmaster@1: // The user is previewing a comment prior to submitting it. webmaster@1: if ($op == t('Preview')) { webmaster@1: if (user_access('post comments')) { webmaster@1: $output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), NULL); webmaster@1: } webmaster@1: else { webmaster@1: drupal_set_message(t('You are not authorized to post comments.'), 'error'); webmaster@1: drupal_goto("node/$node->nid"); webmaster@1: } webmaster@1: } webmaster@1: else { webmaster@1: // $pid indicates that this is a reply to a comment. webmaster@1: if ($pid) { webmaster@1: // load the comment whose cid = $pid webmaster@1: if ($comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, 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))) { webmaster@1: // If that comment exists, make sure that the current comment and the parent comment both webmaster@1: // belong to the same parent node. webmaster@1: if ($comment->nid != $node->nid) { webmaster@1: // Attempting to reply to a comment not belonging to the current nid. webmaster@1: drupal_set_message(t('The comment you are replying to does not exist.'), 'error'); webmaster@1: drupal_goto("node/$node->nid"); webmaster@1: } webmaster@1: // Display the parent comment webmaster@1: $comment = drupal_unpack($comment); webmaster@1: $comment->name = $comment->uid ? $comment->registered_name : $comment->name; webmaster@1: $output .= theme('comment_view', $comment, $node); webmaster@1: } webmaster@1: else { webmaster@1: drupal_set_message(t('The comment you are replying to does not exist.'), 'error'); webmaster@1: drupal_goto("node/$node->nid"); webmaster@1: } webmaster@1: } webmaster@1: // This is the case where the comment is in response to a node. Display the node. webmaster@1: else if (user_access('access content')) { webmaster@1: $output .= node_view($node); webmaster@1: } webmaster@1: webmaster@1: // Should we show the reply box? webmaster@1: if (node_comment_mode($node->nid) != COMMENT_NODE_READ_WRITE) { webmaster@1: drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error'); webmaster@1: drupal_goto("node/$node->nid"); webmaster@1: } webmaster@1: else if (user_access('post comments')) { webmaster@1: $output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), t('Reply')); webmaster@1: } webmaster@1: else { webmaster@1: drupal_set_message(t('You are not authorized to post comments.'), 'error'); webmaster@1: drupal_goto("node/$node->nid"); webmaster@1: } webmaster@1: } webmaster@1: } webmaster@1: else { webmaster@1: drupal_set_message(t('You are not authorized to view comments.'), 'error'); webmaster@1: drupal_goto("node/$node->nid"); webmaster@1: } webmaster@1: webmaster@1: return $output; webmaster@1: }