Code coverage for /20081101/modules/comment/comment.pages.inc

Line #Times calledCode
1
<?php
2
// $Id: comment.pages.inc,v 1.7 2008/10/12 04:30:05 webchick Exp $
3
4
/**
5
 * @file
6
 * User page callbacks for the comment module.
7
 */
8
9
/**
10
 * Form builder; generate a comment editing form.
11
 *
12
 * @param $cid
13
 *   ID of the comment to be edited.
14
 * @ingroup forms
15
 */
1650
function comment_edit($cid) {
173
  global $user;
183
  $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));
193
  $comment = drupal_unpack($comment);
203
  $comment->name = $comment->uid ? $comment->registered_name :
$comment->name;
21
223
  if (comment_access('edit', $comment)) {
233
    return comment_form_box((array)$comment);
240
  }
25
  else {
260
    drupal_access_denied();
27
  }
280
}
29
30
/**
31
 * This function is responsible for generating a comment reply form.
32
 * There are several cases that have to be handled, including:
33
 *   - replies to comments
34
 *   - replies to nodes
35
 *   - attempts to reply to nodes that can no longer accept comments
36
 *   - respecting access permissions ('access comments', 'post comments',
etc.)
37
 *
38
 * The node or comment that is being replied to must appear above the
comment
39
 * form to provide the user context while authoring the comment.
40
 *
41
 * @param $node
42
 *   Every comment belongs to a node. This is that node.
43
 *
44
 * @param $pid
45
 *   Some comments are replies to other comments. In those cases, $pid is
the parent
46
 *   comment's cid.
47
 *
48
 * @return
49
 *   The rendered parent node or comment plus the new comment form.
50
 */
5150
function comment_reply($node, $pid = NULL) {
52
  // Set the breadcrumb trail.
5346
  drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title, 'node/' .
$node->nid)));
5446
  $op = isset($_POST['op']) ? $_POST['op'] : '';
5546
  $output = '';
56
5746
  if (user_access('access comments')) {
58
    // The user is previewing a comment prior to submitting it.
5945
    if ($op == t('Preview')) {
6012
      if (user_access('post comments')) {
6112
        $output .= comment_form_box(array('pid' => $pid, 'nid' =>
$node->nid), NULL);
6212
      }
63
      else {
640
        drupal_set_message(t('You are not authorized to post comments.'),
'error');
650
        drupal_goto("node/$node->nid");
66
      }
6712
    }
68
    else {
69
      // $pid indicates that this is a reply to a comment.
7033
      if ($pid) {
71
        // Load the comment whose cid = $pid
724
        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))) {
73
          // If that comment exists, make sure that the current comment and
the
74
          // parent comment both belong to the same parent node.
754
          if ($comment->nid != $node->nid) {
76
            // Attempting to reply to a comment not belonging to the
current nid.
770
            drupal_set_message(t('The comment you are replying to does not
exist.'), 'error');
780
            drupal_goto("node/$node->nid");
790
          }
80
          // Display the parent comment
814
          $comment = drupal_unpack($comment);
824
          $comment->name = $comment->uid ? $comment->registered_name :
$comment->name;
834
          $output .= theme('comment_view', $comment, $node);
844
        }
85
        else {
860
          drupal_set_message(t('The comment you are replying to does not
exist.'), 'error');
870
          drupal_goto("node/$node->nid");
88
        }
894
      }
90
      // This is the case where the comment is in response to a node.
Display the node.
9129
      elseif (user_access('access content')) {
9229
        $output .= node_view($node);
9329
      }
94
95
      // Should we show the reply box?
9633
      if (node_comment_mode($node->nid) != COMMENT_NODE_READ_WRITE) {
972
        drupal_set_message(t("This discussion is closed: you can't post new
comments."), 'error');
982
        drupal_goto("node/$node->nid");
990
      }
10031
      elseif (user_access('post comments')) {
10131
        $output .= comment_form_box(array('pid' => $pid, 'nid' =>
$node->nid), t('Reply'));
10218
      }
103
      else {
1040
        drupal_set_message(t('You are not authorized to post comments.'),
'error');
1050
        drupal_goto("node/$node->nid");
106
      }
107
    }
10830
  }
109
  else {
1101
    drupal_set_message(t('You are not authorized to view comments.'),
'error');
1111
    drupal_goto("node/$node->nid");
112
  }
113
11430
  return $output;
1150
}
116
117
/**
118
 * Publish specified comment.
119
 *
120
 * @param $cid ID of comment to be published.
121
 */
12250
function comment_approve($cid) {
123
  // Load the comment whose cid = $cid
1241
  if ($comment = comment_load($cid)) {
1251
    $operations = comment_operations('publish');
1261
    db_query($operations['publish'][1], $cid);
127
1281
    drupal_set_message(t('Comment approved.'));
1291
    drupal_goto("node/$comment->nid");
1300
  }
131
  else {
1320
    drupal_set_message(t('The comment you are approving does not exist.'),
'error');
1330
    drupal_goto();
134
  }
1350
}
13650