webmaster@1
|
1 <?php |
webmaster@1
|
2 // $Id: comment.pages.inc,v 1.2.2.1 2008/02/07 18:53:38 goba Exp $ |
webmaster@1
|
3 |
webmaster@1
|
4 /** |
webmaster@1
|
5 * @file |
webmaster@1
|
6 * User page callbacks for the comment module. |
webmaster@1
|
7 */ |
webmaster@1
|
8 |
webmaster@1
|
9 /** |
webmaster@1
|
10 * Form builder; generate a comment editing form. |
webmaster@1
|
11 * |
webmaster@1
|
12 * @param $cid |
webmaster@1
|
13 * ID of the comment to be edited. |
webmaster@1
|
14 * @ingroup forms |
webmaster@1
|
15 */ |
webmaster@1
|
16 function comment_edit($cid) { |
webmaster@1
|
17 global $user; |
webmaster@1
|
18 |
webmaster@1
|
19 $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)); |
webmaster@1
|
20 $comment = drupal_unpack($comment); |
webmaster@1
|
21 $comment->name = $comment->uid ? $comment->registered_name : $comment->name; |
webmaster@1
|
22 if (comment_access('edit', $comment)) { |
webmaster@1
|
23 return comment_form_box((array)$comment); |
webmaster@1
|
24 } |
webmaster@1
|
25 else { |
webmaster@1
|
26 drupal_access_denied(); |
webmaster@1
|
27 } |
webmaster@1
|
28 } |
webmaster@1
|
29 |
webmaster@1
|
30 /** |
webmaster@1
|
31 * This function is responsible for generating a comment reply form. |
webmaster@1
|
32 * There are several cases that have to be handled, including: |
webmaster@1
|
33 * - replies to comments |
webmaster@1
|
34 * - replies to nodes |
webmaster@1
|
35 * - attempts to reply to nodes that can no longer accept comments |
webmaster@1
|
36 * - respecting access permissions ('access comments', 'post comments', etc.) |
webmaster@1
|
37 * |
webmaster@1
|
38 * The node or comment that is being replied to must appear above the comment |
webmaster@1
|
39 * form to provide the user context while authoring the comment. |
webmaster@1
|
40 * |
webmaster@1
|
41 * @param $node |
webmaster@1
|
42 * Every comment belongs to a node. This is that node. |
webmaster@1
|
43 * |
webmaster@1
|
44 * @param $pid |
webmaster@1
|
45 * Some comments are replies to other comments. In those cases, $pid is the parent |
webmaster@1
|
46 * comment's cid. |
webmaster@1
|
47 * |
webmaster@1
|
48 * @return |
webmaster@1
|
49 * The rendered parent node or comment plus the new comment form. |
webmaster@1
|
50 */ |
webmaster@1
|
51 function comment_reply($node, $pid = NULL) { |
webmaster@1
|
52 // Set the breadcrumb trail. |
webmaster@1
|
53 drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title, 'node/'. $node->nid))); |
webmaster@1
|
54 $op = isset($_POST['op']) ? $_POST['op'] : ''; |
webmaster@1
|
55 |
webmaster@1
|
56 $output = ''; |
webmaster@1
|
57 |
webmaster@1
|
58 if (user_access('access comments')) { |
webmaster@1
|
59 // The user is previewing a comment prior to submitting it. |
webmaster@1
|
60 if ($op == t('Preview')) { |
webmaster@1
|
61 if (user_access('post comments')) { |
webmaster@1
|
62 $output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), NULL); |
webmaster@1
|
63 } |
webmaster@1
|
64 else { |
webmaster@1
|
65 drupal_set_message(t('You are not authorized to post comments.'), 'error'); |
webmaster@1
|
66 drupal_goto("node/$node->nid"); |
webmaster@1
|
67 } |
webmaster@1
|
68 } |
webmaster@1
|
69 else { |
webmaster@1
|
70 // $pid indicates that this is a reply to a comment. |
webmaster@1
|
71 if ($pid) { |
webmaster@1
|
72 // load the comment whose cid = $pid |
webmaster@1
|
73 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
|
74 // If that comment exists, make sure that the current comment and the parent comment both |
webmaster@1
|
75 // belong to the same parent node. |
webmaster@1
|
76 if ($comment->nid != $node->nid) { |
webmaster@1
|
77 // Attempting to reply to a comment not belonging to the current nid. |
webmaster@1
|
78 drupal_set_message(t('The comment you are replying to does not exist.'), 'error'); |
webmaster@1
|
79 drupal_goto("node/$node->nid"); |
webmaster@1
|
80 } |
webmaster@1
|
81 // Display the parent comment |
webmaster@1
|
82 $comment = drupal_unpack($comment); |
webmaster@1
|
83 $comment->name = $comment->uid ? $comment->registered_name : $comment->name; |
webmaster@1
|
84 $output .= theme('comment_view', $comment, $node); |
webmaster@1
|
85 } |
webmaster@1
|
86 else { |
webmaster@1
|
87 drupal_set_message(t('The comment you are replying to does not exist.'), 'error'); |
webmaster@1
|
88 drupal_goto("node/$node->nid"); |
webmaster@1
|
89 } |
webmaster@1
|
90 } |
webmaster@1
|
91 // This is the case where the comment is in response to a node. Display the node. |
webmaster@1
|
92 else if (user_access('access content')) { |
webmaster@1
|
93 $output .= node_view($node); |
webmaster@1
|
94 } |
webmaster@1
|
95 |
webmaster@1
|
96 // Should we show the reply box? |
webmaster@1
|
97 if (node_comment_mode($node->nid) != COMMENT_NODE_READ_WRITE) { |
webmaster@1
|
98 drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error'); |
webmaster@1
|
99 drupal_goto("node/$node->nid"); |
webmaster@1
|
100 } |
webmaster@1
|
101 else if (user_access('post comments')) { |
webmaster@1
|
102 $output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), t('Reply')); |
webmaster@1
|
103 } |
webmaster@1
|
104 else { |
webmaster@1
|
105 drupal_set_message(t('You are not authorized to post comments.'), 'error'); |
webmaster@1
|
106 drupal_goto("node/$node->nid"); |
webmaster@1
|
107 } |
webmaster@1
|
108 } |
webmaster@1
|
109 } |
webmaster@1
|
110 else { |
webmaster@1
|
111 drupal_set_message(t('You are not authorized to view comments.'), 'error'); |
webmaster@1
|
112 drupal_goto("node/$node->nid"); |
webmaster@1
|
113 } |
webmaster@1
|
114 |
webmaster@1
|
115 return $output; |
webmaster@1
|
116 } |