/[drupal]/drupal/modules/comment/comment.pages.inc
ViewVC logotype

Contents of /drupal/modules/comment/comment.pages.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.28 - (show annotations) (download) (as text)
Sun Nov 1 12:11:10 2009 UTC (3 weeks, 4 days ago) by dries
Branch: MAIN
Changes since 1.27: +2 -2 lines
File MIME type: text/x-php
- Patch #595084 by c960657: use type hinting for .
1 <?php
2 // $Id: comment.pages.inc,v 1.27 2009/10/16 20:40:05 dries Exp $
3
4 /**
5 * @file
6 * User page callbacks for the comment module.
7 */
8
9 /**
10 * This function is responsible for generating a comment reply form.
11 * There are several cases that have to be handled, including:
12 * - replies to comments
13 * - replies to nodes
14 * - attempts to reply to nodes that can no longer accept comments
15 * - respecting access permissions ('access comments', 'post comments', etc.)
16 *
17 * The node or comment that is being replied to must appear above the comment
18 * form to provide the user context while authoring the comment.
19 *
20 * @param $node
21 * Every comment belongs to a node. This is that node.
22 *
23 * @param $pid
24 * Some comments are replies to other comments. In those cases, $pid is the parent
25 * comment's cid.
26 *
27 * @return
28 * The rendered parent node or comment plus the new comment form.
29 */
30 function comment_reply(stdClass $node, $pid = NULL) {
31 // Set the breadcrumb trail.
32 drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title[FIELD_LANGUAGE_NONE][0]['value'], 'node/' . $node->nid)));
33 $op = isset($_POST['op']) ? $_POST['op'] : '';
34 $build = array();
35
36 if (user_access('access comments')) {
37 // The user is previewing a comment prior to submitting it.
38 if ($op == t('Preview')) {
39 if (user_access('post comments')) {
40 $build['comment_form'] = drupal_get_form('comment_form', (object) array('pid' => $pid, 'nid' => $node->nid));
41 }
42 else {
43 drupal_set_message(t('You are not authorized to post comments.'), 'error');
44 drupal_goto("node/$node->nid");
45 }
46 }
47 else {
48 // $pid indicates that this is a reply to a comment.
49 if ($pid) {
50 // Load the comment whose cid = $pid
51 $comment = db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.picture, u.data FROM {comment} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = :cid AND c.status = :status', array(
52 ':cid' => $pid,
53 ':status' => COMMENT_PUBLISHED,
54 ))->fetchObject();
55 if ( $comment ) {
56 // If that comment exists, make sure that the current comment and the
57 // parent comment both belong to the same parent node.
58 if ($comment->nid != $node->nid) {
59 // Attempting to reply to a comment not belonging to the current nid.
60 drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
61 drupal_goto("node/$node->nid");
62 }
63 // Display the parent comment
64 $comment = drupal_unpack($comment);
65 $comment->node_type = 'comment_node_' . $node->type;
66 field_attach_load('comment', array($comment->cid => $comment));
67 $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
68 $build['comment_parent'] = comment_build($comment, $node);
69 }
70 else {
71 drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
72 drupal_goto("node/$node->nid");
73 }
74 }
75 // This is the case where the comment is in response to a node. Display the node.
76 elseif (user_access('access content')) {
77 $build['comment_node'] = node_build($node);
78 }
79
80 // Should we show the reply box?
81 if ($node->comment != COMMENT_NODE_OPEN) {
82 drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error');
83 drupal_goto("node/$node->nid");
84 }
85 elseif (user_access('post comments')) {
86 $edit = array('nid' => $node->nid, 'pid' => $pid);
87 $build['comment_form'] = drupal_get_form('comment_form', (object) $edit);
88 }
89 else {
90 drupal_set_message(t('You are not authorized to post comments.'), 'error');
91 drupal_goto("node/$node->nid");
92 }
93 }
94 }
95 else {
96 drupal_set_message(t('You are not authorized to view comments.'), 'error');
97 drupal_goto("node/$node->nid");
98 }
99
100 return $build;
101 }
102
103 /**
104 * Menu callback; publish specified comment.
105 *
106 * @param $comment
107 * A comment object.
108 */
109 function comment_approve($comment) {
110 $comment->status = COMMENT_PUBLISHED;
111 $comment->comment_format = $comment->format;
112 comment_save($comment);
113
114 drupal_set_message(t('Comment approved.'));
115 drupal_goto('node/' . $comment->nid);
116 }

  ViewVC Help
Powered by ViewVC 1.1.2