comparison modules/comment/comment.pages.inc @ 1:c1f4ac30525a 6.0

Drupal 6.0
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:28:28 +0100
parents
children
comparison
equal deleted inserted replaced
0:5a113a1c4740 1:c1f4ac30525a
1 <?php
2 // $Id: comment.pages.inc,v 1.2.2.1 2008/02/07 18:53:38 goba 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 */
16 function comment_edit($cid) {
17 global $user;
18
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));
20 $comment = drupal_unpack($comment);
21 $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
22 if (comment_access('edit', $comment)) {
23 return comment_form_box((array)$comment);
24 }
25 else {
26 drupal_access_denied();
27 }
28 }
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 */
51 function comment_reply($node, $pid = NULL) {
52 // Set the breadcrumb trail.
53 drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title, 'node/'. $node->nid)));
54 $op = isset($_POST['op']) ? $_POST['op'] : '';
55
56 $output = '';
57
58 if (user_access('access comments')) {
59 // The user is previewing a comment prior to submitting it.
60 if ($op == t('Preview')) {
61 if (user_access('post comments')) {
62 $output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), NULL);
63 }
64 else {
65 drupal_set_message(t('You are not authorized to post comments.'), 'error');
66 drupal_goto("node/$node->nid");
67 }
68 }
69 else {
70 // $pid indicates that this is a reply to a comment.
71 if ($pid) {
72 // load the comment whose cid = $pid
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))) {
74 // If that comment exists, make sure that the current comment and the parent comment both
75 // belong to the same parent node.
76 if ($comment->nid != $node->nid) {
77 // Attempting to reply to a comment not belonging to the current nid.
78 drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
79 drupal_goto("node/$node->nid");
80 }
81 // Display the parent comment
82 $comment = drupal_unpack($comment);
83 $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
84 $output .= theme('comment_view', $comment, $node);
85 }
86 else {
87 drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
88 drupal_goto("node/$node->nid");
89 }
90 }
91 // This is the case where the comment is in response to a node. Display the node.
92 else if (user_access('access content')) {
93 $output .= node_view($node);
94 }
95
96 // Should we show the reply box?
97 if (node_comment_mode($node->nid) != COMMENT_NODE_READ_WRITE) {
98 drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error');
99 drupal_goto("node/$node->nid");
100 }
101 else if (user_access('post comments')) {
102 $output .= comment_form_box(array('pid' => $pid, 'nid' => $node->nid), t('Reply'));
103 }
104 else {
105 drupal_set_message(t('You are not authorized to post comments.'), 'error');
106 drupal_goto("node/$node->nid");
107 }
108 }
109 }
110 else {
111 drupal_set_message(t('You are not authorized to view comments.'), 'error');
112 drupal_goto("node/$node->nid");
113 }
114
115 return $output;
116 }