/[drupal]/contributions/tricks/phpbb2drupal/4.6.5/comment.module
ViewVC logotype

Contents of /contributions/tricks/phpbb2drupal/4.6.5/comment.module

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


Revision 1.2 - (show annotations) (download) (as text)
Thu Apr 6 09:27:25 2006 UTC (3 years, 7 months ago) by tavon
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/x-php
Updated the phpbb2drupal_import.php
  -Removed some major bugs
  -Imports Polls

Added redirection scripts
  -viewtopic.php
  -stories.php
1 <?php
2 // $Id: comment.module,v 1.347.2.8 2005-11-15 20:37:56 dries Exp $
3
4 /**
5 * @file
6 * Enables users to comment on published content.
7 *
8 * When enabled, the Drupal comment module creates a discussion
9 * board for each Drupal node. Users can post comments to discuss
10 * a forum topic, weblog post, story, collaborative book page, etc.
11 */
12
13 /**
14 * Implementation of hook_help().
15 */
16 function comment_help($section = "admin/help#comment") {
17 switch ($section) {
18 case 'admin/help#comment':
19 return t("
20 <p>When enabled, the Drupal comment module creates a discussion board for each Drupal node. Users can post comments to discuss a forum topic, weblog post, story, collaborative book page, etc. An administrator can give comment permissions to user groups, and users can (optionally) edit their last comment, assuming no others have been posted since.</p>
21
22 <h3>User control of comment display</h3>
23 <p>Attached to each comment board is a control panel for customizing the way that comments are displayed. Users can control the chronological ordering of posts (newest or oldest first) and the number of posts to display on each page. Additional settings include:</p>
24 <ul><li><strong>Threaded</strong> &mdash; Displays the posts grouped according to conversations and subconversations.</li>
25 <li><strong>Flat</strong> &mdash; Displays the posts in chronological order, with no threading whatsoever.</li>
26 <li><strong>Expanded</strong> &mdash; Displays the title and text for each post.</li>
27 <li><strong>Collapsed</strong> &mdash; Displays only the title for each post.</li></ul>
28 <p>When a user chooses <em>save settings</em>, the comments are then redisplayed using the user's new choices. Administrators can set the default settings for the comment control panel, along with other comment defaults, in <a href=\"%comment-config\">administer &raquo; comments &raquo; configure</a>. NOTE: When comment moderation is enabled, users will have another control panel option to control thresholds (see below).</p>
29
30 <h3>Additional comment configurations</h3>
31 <p>Comments behave like other user submissions in Drupal. Filters, smileys and HTML that work in nodes will also work with comments. Administrators can control access to various comment module functions through <a href=\"%permissions\">administer &raquo; access control &raquo; permissions</a>. Know that in a new Drupal installation, all comment permissions are disabled by default. The choice of which permissions to grant to which roles (groups of users) is left up to the site administrator. The following permissions:</p>
32 <ul><li><strong>Access comments</strong> &mdash; Allows users to view comments.</li>
33 <li><strong>Administrate comments</strong> &mdash; Allows users complete control over configuring, editing and deleting all comments.</li>
34 <li><strong>Moderate comments</strong> &mdash; Allows users to rate comment postings (see more on moderation below).</li>
35 <li><strong>Post comments</strong> &mdash; Allows users to post comments into an administrator moderation queue.</li>
36 <li><strong>Post comments without approval</strong> &mdash; Allows users to directly post comments, bypassing the moderation queue.</li></ul>
37
38 <h3>Notification of new comments</h3>
39 <p>Drupal provides specific features to inform site members when new comments have been posted.</p>
40 <p>Drupal displays the total number of comments attached to each node, and tracks comments read by individual site members. Members which have logged in will see a notice accompanying nodes which contain comments they have not read. Some administrators may want to <a href=\"%download-notify\">download, install and configure the notify module</a>. Users can then request that Drupal send them an e-mail when new comments are posted (the notify module requires that cron.php be configured properly).</p>
41 <p>The <em>tracker</em> module, disabled by default, displays all the site's recent posts. There is a link to the <a href=\"%tracker\">recent posts</a> page in the navigation block. This page is a useful way to browse new or updated nodes and comments. Content which the user has not yet read is tagged with a red star (this graphic depends on the current theme). Visit the comment board for any node, and Drupal will display a red <em>\"new\"</em> label beside the text of unread comments.</p>
42
43 <h3>Comment moderation</h3>
44 <p>On sites with active commenting from users, the administrator can turn over comment moderation to the community. </p>
45 <p>With comment moderation, each comment is automatically assigned an initial rating. As users read comments, they can apply a vote which affects the comment rating. At the same time, users have an additional option in the control panel which allows them to set a threshold for the comments they wish to view. Those comments with ratings lower than the set threshold will not be shown. To enable moderation, the administrator must grant <a href=\"%permissions\">moderate comments</a> permissions. Then, a number of options in <a href=\"%comment-config\">administer &raquo; comments &raquo; configure</a> must be configured.</p>
46
47 <h4>Moderation votes</h4>
48 <p>The first step is to create moderation labels which allow users to rate a comment. Go to <a href=\"%comment-votes\">administer &raquo; comments &raquo; configure &raquo; moderation votes</a>. In the <em>vote</em> field, enter the textual labels which users will see when casting their votes. Some examples are</p>
49 <ul><li>Excellent +3</li><li>Insightful +2</li><li>Useful +1</li><li>Redundant -1</li><li>Flame -3</li></ul>
50 <p>So that users know how their votes affect the comment, these examples include the vote value as part of the label, although that is optional. Using the weight option, you can control the order in which the votes appear to users. Setting the weight heavier (positive numbers) will make the vote label appear at the bottom of the list. Lighter (a negative number) will push it to the top. To encourage positive voting, a useful order might be higher values, positive votes, at the top, with negative votes at the bottom.</p>
51
52 <h4>Moderator vote/values matrix</h4>
53 <p>Next go to <a href=\"%comment-matrix\">administer &raquo; comments &raquo; configure &raquo; moderation matrix</a>. Enter the values for the vote labels for each permission role in the vote matrix. The values entered here will be used to create the rating for each comment. NOTE: Comment ratings are calculated by averaging user votes with the initial rating.</p>
54
55 <h4>Creating comment thresholds</h4>
56 <p>In <a href=\"%comment-thresholds\">administer &raquo; comments &raquo; configure &raquo; moderation thresholds</a>, you'll have to create some comment thresholds to make the comment rating system useful. When comment moderation is enabled and the thresholds are created, users will find another comment control panel option for selecting their thresholds. They'll use the thresholds you enter here to filter out comments with low ratings. Consequently, you'll probably want to create more than one threshold to give users some flexibility in filtering comments.</p>
57 <p>When creating the thresholds, note that the <em>Minimum score</em> is asking you for the lowest rating that a comment can have in order to be displayed. To see a common example of how thresholds work, you might visit <a href=\"%slashdot\">Slashdot</a> and view one of their comment boards associated with a story. You can reset the thresholds in their comment control panel.</p>
58
59 <h4>Initial comment scores</h4>
60 <p>Finally, you may want to enter some <em>initial comment scores</em>. In <a href=\"%comment-initial\">administer &raquo; comments &raquo; configure &raquo; moderation roles</a> you can assign a beginning rating for all comments posted by a particular permission role. If you do not assign any initial scores, Drupal will assign a rating of <strong>0</strong> as the default.</p>", array('%comment-config' => url('admin/comment/configure'), '%permissions' => url('admin/access/permissions'), '%tracker' => url('tracker'), '%download-notify' => 'http://drupal.org/project/releases', '%comment-votes' => url('admin/comment/configure/votes'), '%comment-matrix' => url('admin/comment/configure/matrix'), '%comment-thresholds' => url('admin/comment/configure/thresholds'), '%slashdot' => ' http://slashdot.org', '%comment-initial' => url('admin/comment/configure/roles')));
61 case 'admin/comment':
62 case 'admin/comment/new':
63 return t("<p>Below is a list of the latest comments posted to your site. Click on a subject to see the comment, the author's name to edit the author's user information , \"edit\" to modify the text, and \"delete\" to remove their submission.</p>");
64 case 'admin/comment/approval':
65 return t("<p>Below is a list of the comments posted to your site that need approval. To approve a comment, click on \"edit\" and then change its \"moderation status\" to Approved. Click on a subject to see the comment, the author's name to edit the author's user information, \"edit\" to modify the text, and \"delete\" to remove their submission.</p>");
66 case 'admin/comment/configure':
67 case 'admin/comment/configure/settings':
68 return t("<p>Comments can be attached to any node, and their settings are below. The display comes in two types: a \"flat list\" where everything is flush to the left side, and comments come in chronological order, and a \"threaded list\" where replies to other comments are placed immediately below and slightly indented, forming an outline. They also come in two styles: \"expanded\", where you see both the title and the contents, and \"collapsed\" where you only see the title. Preview comment forces a user to look at their comment by clicking on a \"Preview\" button before they can actually add the comment.</p>");
69 case 'admin/comment/configure/matrix':
70 return t("<p>Here you assign a value to each item in the comment moderation dropdown menu. This value is added to the vote total, which is then divided by the number of users who have voted and rounded off to the nearest integer.</p><ul><li>In order to use comment moderation, every text box on this page should be populated.</li><li>You must assign the \"moderate comments\" permission to at least one role in order to use this page.</li><li>Every box not filled in will have a value of zero, which will have the effect of lowering a comments overall score.</li></ul>");
71 case 'admin/comment/configure/roles':
72 return t("<p>You can setup the initial vote value of a comment posted by each user role using these forms. This value is used before any other users vote on the comment. Blank entries are valued at zero.</p>");
73 case 'admin/comment/configure/thresholds':
74 return t("<p>Use these forms to setup the name and minimum \"cut off\" score to help your users hide comments they don't want to see. These thresholds appear in the user's comment control panel. Click \"edit threshold\" to modify the values of an already existing configuration. To delete a setting, \"edit\" it first, and then choose \"delete threshold\".</p>");
75 case 'admin/comment/configure/votes':
76 return t('<p>Create and control the possible comment moderation votes here. "Weight" lets you set the order of the drop down menu. Click "edit" to edit a current vote weight. To delete a name/weight combination go to the "edit" area. To delete a setting, "edit" it first, and then choose "delete vote".</p>');
77 case 'admin/modules#description':
78 return t('Allows users to comment on and discuss published content.');
79 }
80 }
81
82 /**
83 * Implementation of hook_menu().
84 */
85 function comment_menu($may_cache) {
86 $items = array();
87
88 if ($may_cache) {
89 $access = user_access('administer comments');
90 $items[] = array('path' => 'admin/comment', 'title' => t('comments'),
91 'callback' => 'comment_admin_overview', 'access' => $access);
92 $items[] = array('path' => 'admin/comment/edit', 'title' => t('edit comment'),
93 'callback' => 'comment_admin_edit', 'access' => $access, 'type' => MENU_CALLBACK);
94 $items[] = array('path' => 'admin/comment/delete', 'title' => t('delete comment'),
95 'callback' => 'comment_delete', 'access' => $access, 'type' => MENU_CALLBACK);
96
97 // Tabs:
98 $items[] = array('path' => 'admin/comment/list', 'title' => t('list'),
99 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
100 $items[] = array('path' => 'admin/comment/configure', 'title' => t('configure'),
101 'callback' => 'comment_configure', 'access' => $access, 'type' => MENU_LOCAL_TASK);
102
103 // Subtabs:
104 $items[] = array('path' => 'admin/comment/list/new', 'title' => t('new comments'),
105 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
106 $items[] = array('path' => 'admin/comment/list/approval', 'title' => t('approval queue'),
107 'callback' => 'comment_admin_overview', 'access' => $access,
108 'callback arguments' => 'approval',
109 'type' => MENU_LOCAL_TASK);
110
111 $items[] = array('path' => 'admin/comment/configure/settings', 'title' => t('settings'),
112 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
113
114 $access = user_access('administer comments') && user_access('administer moderation');
115 $items[] = array('path' => 'admin/comment/configure/matrix', 'title' => t('moderation matrix'),
116 'callback' => 'comment_matrix_settings', 'access' => $access, 'type' => MENU_LOCAL_TASK);
117 $items[] = array('path' => 'admin/comment/configure/thresholds', 'title' => t('moderation thresholds'),
118 'callback' => 'comment_threshold_settings', 'access' => $access, 'type' => MENU_LOCAL_TASK);
119 $items[] = array('path' => 'admin/comment/configure/roles', 'title' => t('moderation roles'),
120 'callback' => 'comment_role_settings', 'access' => $access, 'type' => MENU_LOCAL_TASK);
121 $items[] = array('path' => 'admin/comment/configure/votes', 'title' => t('moderation votes'),
122 'callback' => 'comment_vote_settings', 'access' => $access,'type' => MENU_LOCAL_TASK);
123
124 $access = user_access('post comments');
125 $items[] = array('path' => 'comment/edit', 'title' => t('edit comment'),
126 'callback' => 'comment_edit', 'access' => $access, 'type' => MENU_CALLBACK);
127
128 $items[] = array('path' => 'comment', 'title' => t('reply to comment'),
129 'callback' => 'comment_save_settings', 'access' => 1, 'type' => MENU_CALLBACK);
130 }
131 else {
132 if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) {
133 $node = node_load(array('nid' => arg(2)));
134 if ($node->nid) {
135 $items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'),
136 'callback' => 'comment_reply', 'access' => node_access('view', $node), 'type' => MENU_CALLBACK);
137 }
138 }
139 if ((arg(0) == 'node') && is_numeric(arg(1)) && is_numeric(arg(2))) {
140 $items[] = array('path' => ('node/'. arg(1) .'/'. arg(2)), 'title' => t('view'),
141 'callback' => 'node_page',
142 'type' => MENU_CALLBACK);
143 }
144 }
145
146 return $items;
147 }
148
149 /**
150 * Implementation of hook_perm().
151 */
152 function comment_perm() {
153 return array('access comments', 'post comments', 'administer comments', 'moderate comments', 'post comments without approval', 'administer moderation');
154 }
155
156 /**
157 * Implementation of hook_block().
158 *
159 * Generates a block with the most recent comments.
160 */
161 function comment_block($op = 'list', $delta = 0) {
162 if ($op == 'list') {
163 $blocks[0]['info'] = t('Recent comments');
164 return $blocks;
165 }
166 else if ($op == 'view' && user_access('access comments')) {
167 $result = db_query_range(db_rewrite_sql('SELECT c.nid, c.* FROM {comments} c WHERE c.status = 0 ORDER BY c.timestamp DESC', 'c'), 0, 10);
168 $items = array();
169 while ($comment = db_fetch_object($result)) {
170 $items[] = l($comment->subject, 'node/'. $comment->nid, NULL, NULL, 'comment-'. $comment->cid) .'<br />'. t('%time ago', array('%time' => format_interval(time() - $comment->timestamp)));
171 }
172
173 $block['subject'] = t('Recent comments');
174 $block['content'] = theme('item_list', $items);
175 return $block;
176 }
177 }
178
179 /**
180 * Implementation of hook_link().
181 */
182 function comment_link($type, $node = 0, $main = 0) {
183 $links = array();
184
185 if ($type == 'node' && $node->comment) {
186
187 if ($main) {
188 // Main page: display the number of comments that have been posted.
189
190 if (user_access('access comments')) {
191 $all = comment_num_all($node->nid);
192 $new = comment_num_new($node->nid);
193
194 if ($all) {
195 $links[] = l(format_plural($all, '1 comment', '%count comments'), "node/$node->nid", array('title' => t('Jump to the first comment of this posting.')), NULL, 'comment');
196
197 if ($new) {
198 $links[] = l(format_plural($new, '1 new comment', '%count new comments'), "node/$node->nid", array('title' => t('Jump to the first new comment of this posting.')), NULL, 'new');
199 }
200 }
201 else {
202 if ($node->comment == 2) {
203 if (user_access('post comments')) {
204 $links[] = l(t('add new comment'), "comment/reply/$node->nid", array('title' => t('Add a new comment to this page.')));
205 }
206 else {
207 $links[] = theme('comment_post_forbidden');
208 }
209 }
210 }
211 }
212 }
213 else {
214 // Node page: add a "post comment" link if the user is allowed to
215 // post comments, if this node is not read-only, and if the comment form isn't already shown
216
217 if ($node->comment == 2 && variable_get('comment_form_location', 0) == 0) {
218 if (user_access('post comments')) {
219 $links[] = l(t('add new comment'), "comment/reply/$node->nid", array('title' => t('Share your thoughts and opinions related to this posting.')), NULL, 'comment');
220 }
221 else {
222 $links[] = theme('comment_post_forbidden');
223 }
224 }
225 }
226 }
227
228 if ($type == 'comment') {
229 $links = comment_links($node, $main);
230 }
231
232 return $links;
233 }
234
235 /**
236 * Implementation of hook_nodeapi().
237 *
238 */
239 function comment_nodeapi(&$node, $op, $arg = 0) {
240 switch ($op) {
241 case 'settings':
242 return form_radios(t('Default comment setting'), 'comment_'. $node->type, variable_get('comment_'. $node->type, 2), array(t('Disabled'), t('Read only'), t('Read/Write')), t('Users with the <em>administer comments</em> permission will be able to override this setting.'));
243
244 case 'fields':
245 return array('comment');
246
247 case 'form admin':
248 if (user_access('administer comments')) {
249 $selected = isset($node->comment) ? $node->comment : variable_get("comment_$node->type", 2);
250 $output = form_radios('', 'comment', $selected, array(t('Disabled'), t('Read only'), t('Read/write')));
251 return form_group(t('User comments'), $output);
252 }
253 break;
254
255 case 'load':
256 return db_fetch_array(db_query("SELECT last_comment_timestamp, last_comment_name, comment_count FROM {node_comment_statistics} WHERE nid = %d", $node->nid));
257 case 'validate':
258 if (!user_access('administer comments')) {
259 // Force default for normal users:
260 $node->comment = variable_get("comment_$node->type", 2);
261 }
262 break;
263
264 case 'insert':
265 db_query('INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) VALUES (%d, %d, NULL, %d, 0)', $node->nid, $node->created, $node->uid);
266 break;
267
268 case 'delete':
269 db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid);
270 db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid);
271 break;
272
273 case 'update index':
274 $text = '';
275 $comments = db_query('SELECT subject, comment, format FROM {comments} WHERE nid = %d AND status = 0', $node->nid);
276 while ($comment = db_fetch_object($comments)) {
277 $text .= '<h2>'. check_plain($comment->subject) .'</h2>'. check_output($comment->comment, $comment->format);
278 }
279 return $text;
280
281 case 'search result':
282 $comments = db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $node->nid));
283 return format_plural($comments, '1 comment', '%count comments');
284 }
285 }
286
287 /**
288 * Implementation of hook_user().
289 *
290 * Provides signature customization for the user's comments.
291 */
292 function comment_user($type, $edit, &$user, $category = NULL) {
293 if ($type == 'form' && $category == 'account') {
294 // when user tries to edit his own data
295 return array(array('title' => t('Comment settings'), 'data' => form_textarea(t('Signature'), 'signature', $edit['signature'], 64, 3, t('Your signature will be publicly displayed at the end of your comments.')), 'weight' => 2));
296 }
297 if ($type == 'validate') {
298 // validate user data editing
299 return array('signature' => $edit['signature']);
300 }
301 }
302
303 /**
304 * Menu callback; presents the comment settings page.
305 */
306 function comment_configure() {
307 if ($_POST) {
308 system_settings_save();
309 }
310
311 $group = form_radios(t('Default display mode'), 'comment_default_mode', variable_get('comment_default_mode', 4), _comment_get_modes(), t('The default view for comments. Expanded views display the body of the comment. Threaded views keep replies together.'));
312 $group .= form_radios(t('Default display order'), 'comment_default_order', variable_get('comment_default_order', 1), _comment_get_orders(), t('The default sorting for new users and anonymous users while viewing comments. These users may change their view using the comment control panel. For registered users, this change is remembered as a persistent user preference.'));
313 $group .= form_select(t('Default comments per page'), 'comment_default_per_page', variable_get('comment_default_per_page', '50'), _comment_per_page(), t('Default number of comments for each page: more comments are distributed in several pages.'));
314 $group .= form_radios(t('Comment controls'), 'comment_controls', variable_get('comment_controls', 3), array(t('Display above the comments'), t('Display below the comments'), t('Display above and below the comments'), t('Do not display')), t('Position of the comment controls box. The comment controls let the user change the default display mode and display order of comments.'));
315 $output = form_group(t('Comment viewing options'), $group);
316
317 $group = form_radios(t('Anonymous poster settings'), 'comment_anonymous', variable_get('comment_anonymous', 0), array(t('Anonymous posters may not enter their contact information'), t('Anonymous posters may leave their contact information'), t('Anonymous posters must leave their contact information')), t('This feature is only useful if you allow anonymous users to post comments. See the <a href="%url">permissions page</a>.', array('%url' => url('admin/access/permissions'))));
318 $group .= form_radios(t('Comment subject field'), 'comment_subject_field', variable_get('comment_subject_field', 1), array(t('Disabled'), t('Enabled')), t('Can users provide a unique subject for their comments?'));
319 $group .= form_radios(t('Preview comment'), 'comment_preview', variable_get('comment_preview', 1), array(t('Optional'), t('Required')));
320 $group .= form_radios(t('Location of comment submission form'), 'comment_form_location', variable_get('comment_form_location', 0), array(t('Display on separate page'), t('Display below post or comments')));
321 $output .= form_group(t('Comment posting settings'), $group);
322
323 $result = db_query('SELECT fid, filter FROM {moderation_filters} ');
324 while ($filter = db_fetch_object($result)) {
325 $thresholds[$filter->fid] = ($filter->filter);
326 }
327 if ($thresholds) {
328 $group = form_select(t('Default threshold'), 'comment_default_threshold', variable_get('comment_default_threshold', 0), $thresholds, t('Thresholds are values below which comments are hidden. These thresholds are useful for busy sites which want to hide poor comments from most users.'));
329 $output .= form_group(t('Comment moderation settings'), $group);
330 }
331
332 print theme('page', system_settings_form($output));
333 }
334
335 /**
336 * This is *not* a hook_access() implementation. This function is called
337 * to determine whether the current user has access to a particular comment.
338 *
339 * Authenticated users can edit their comments as long they have not been
340 * replied to. This prevents people from changing or revising their
341 * statements based on the replies their posts got. Furthermore, users
342 * can't reply to their own comments and are encouraged instead to extend
343 * their original comment.
344 */
345 function comment_access($op, $comment) {
346 global $user;
347
348 if ($op == 'edit') {
349 return $user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0;
350 }
351 }
352
353 function comment_node_url() {
354 return arg(0) .'/'. arg(1);
355 }
356
357 function comment_edit($cid) {
358 global $user;
359
360 $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));
361 $comment = drupal_unpack($comment);
362 $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
363 if (comment_access('edit', $comment)) {
364 print theme('page', comment_preview(object2array($comment)));
365 }
366 else {
367 drupal_access_denied();
368 }
369 }
370
371 function comment_reply($nid, $pid = NULL) {
372 // set the breadcrumb trail
373 $node = node_load(array('nid' => $nid));
374 menu_set_location(array(array('path' => "node/$nid", 'title' => $node->title), array('path' => "comment/reply/$nid")));
375
376 $output = '';
377
378 // are we posting or previewing a reply?
379 if ($_POST['op'] == t('Post comment')) {
380 $edit = $_POST['edit'];
381 $edit = comment_validate_form($edit);
382 drupal_set_title(t('Post comment'));
383 print theme('page', comment_post($edit));
384 return;
385 }
386 else if ($_POST['op'] == t('Preview comment')) {
387 $edit = $_POST['edit'];
388 $edit = comment_validate_form($edit);
389 drupal_set_title(t('Preview comment'));
390 print theme('page', comment_preview($edit));
391 return;
392 }
393
394 // or are we merely showing the form?
395 if (user_access('access comments')) {
396
397 // if this is a reply to another comment, show that comment first
398 // else, we'll just show the user the node they're commenting on.
399 if ($pid) {
400 $comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0', $pid));
401 $comment = drupal_unpack($comment);
402 $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
403 $output .= theme('comment_view', $comment);
404 }
405 else if (user_access('access content')) {
406 $output .= node_view($node);
407 $pid = 0;
408 }
409
410 // should we show the reply box?
411 if (node_comment_mode($nid) != 2) {
412 $output .= theme('box', t('Reply'), t("This discussion is closed: you can't post new comments."));
413 }
414 else if (user_access('post comments')) {
415 $output .= theme('comment_form', array('pid' => $pid, 'nid' => $nid), t('Reply'));
416 }
417 else {
418 $output .= theme('box', t('Reply'), t('You are not authorized to post comments.'));
419 }
420 }
421 else {
422 $output .= theme('box', t('Reply'), t('You are not authorized to view comments.'));
423 }
424
425 drupal_set_title(t('Add new comment'));
426 print theme('page', $output);
427 }
428
429 function comment_validate_form($edit) {
430 global $user;
431
432 // Validate the comment's subject. If not specified, extract
433 // one from the comment's body.
434 if (trim($edit['subject']) == '') {
435 // The body may be in any format, so we:
436 // 1) Filter it into HTML
437 // 2) Strip out all HTML tags
438 // 3) Convert entities back to plain-text.
439 // Note: format is checked by check_output().
440 $edit['subject'] = truncate_utf8(decode_entities(strip_tags(check_output($edit['comment'], $edit['format'], TRUE))), 29, TRUE);
441 }
442
443 // Validate the comment's body.
444 if ($edit['comment'] == '') {
445 form_set_error('comment', t('The body of your comment is empty.'));
446 }
447
448 // Validate filter format
449 if (array_key_exists('format', $edit) && !filter_access($edit['format'])) {
450 form_set_error('format', t('The supplied input format is invalid.'));
451 }
452
453 // Check validity of name, mail and homepage (if given)
454 if (!$user->uid) {
455 if (variable_get('comment_anonymous', 0) > 0) {
456 if ($edit['name']) {
457 $taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", $edit['name']), 0);
458
459 if ($taken != 0) {
460 form_set_error('name', t('The name you used belongs to a registered user.'));
461 }
462
463 }
464 else if (variable_get('comment_anonymous', 0) == 2) {
465 form_set_error('name', t('You have to leave your name.'));
466 }
467
468 if ($edit['mail']) {
469 if (!valid_email_address($edit['mail'])) {
470 form_set_error('mail', t('The e-mail address you specified is not valid.'));
471 }
472 }
473 else if (variable_get('comment_anonymous', 0) == 2) {
474 form_set_error('mail', t('You have to leave an e-mail address.'));
475 }
476
477 if ($edit['homepage']) {
478 if (!valid_url($edit['homepage'], TRUE)) {
479 form_set_error('homepage', t('The URL of your homepage is not valid. Remember that it must be fully qualified, i.e. of the form <code>http://example.com/directory</code>.'));
480 }
481 }
482 }
483 }
484
485 // Invoke other validation handlers
486 module_invoke_all('comment', 'validate', $edit);
487
488 return $edit;
489 }
490
491 function comment_preview($edit) {
492 global $user;
493
494 $output = '';
495
496 $comment = array2object($edit);
497
498 // Attach the user and time information.
499 $comment->uid = $user->uid;
500 $comment->timestamp = time();
501 $comment->name = check_plain($user->name ? $user->name : $comment->name);
502
503 // Preview the comment if there were no errors, including the 'The supplied input format is invalid.'
504 // error message, ie. this is a security check here.
505 if (!form_get_errors()) {
506 $output .= theme('comment_preview', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 1)));
507 }
508 $output .= theme('comment_form', $edit, t('Reply'));
509
510 if ($edit['pid']) {
511 $comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0', $edit['pid']));
512 $comment = drupal_unpack($comment);
513 $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
514 $output .= theme('comment_view', $comment);
515 }
516 else {
517 $output .= node_view(node_load(array('nid' => $edit['nid'])));
518 $edit['pid'] = 0;
519 }
520
521 return $output;
522 }
523
524 function comment_post($edit) {
525 global $user;
526
527 if (user_access('post comments') && node_comment_mode($edit['nid']) == 2) {
528 if (!form_get_errors()) {
529 // Check for duplicate comments. Note that we have to use the
530 // validated/filtered data to perform such check.
531 $duplicate = db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND nid = %d AND subject = '%s' AND comment = '%s'", $edit['pid'], $edit['nid'], $edit['subject'], $edit['comment']), 0);
532 if ($duplicate != 0) {
533 watchdog('content', t('Comment: duplicate %subject.', array('%subject' => theme('placeholder', $edit['subject']))), WATCHDOG_WARNING);
534 }
535
536 if ($edit['cid']) {
537 // Update the comment in the database. Note that the update
538 // query will fail if the comment isn't owned by the current
539 // user.
540 db_query("UPDATE {comments} SET subject = '%s', comment = '%s', format = '%s' WHERE cid = %d AND uid = %d", $edit['subject'], $edit['comment'], $edit['format'], $edit['cid'], $user->uid);
541
542 _comment_update_node_statistics($edit['nid']);
543
544 // Allow modules to respond to the updating of a comment.
545 module_invoke_all('comment', 'update', $edit);
546
547 // Add an entry to the watchdog log.
548 watchdog('content', t('Comment: updated %subject.', array('%subject' => theme('placeholder', $edit['subject']))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
549 }
550 else {
551 // Add the comment to database.
552 $status = user_access('post comments without approval') ? 0 : 1;
553 $roles = variable_get('comment_roles', array());
554 $score = 0;
555
556 foreach (array_intersect(array_keys($roles), array_keys($user->roles)) as $rid) {
557 $score = max($roles[$rid], $score);
558 }
559
560 $users = serialize(array(0 => $score));
561
562 // Here we are building the thread field. See the comment
563 // in comment_render().
564 if ($edit['pid'] == 0) {
565 // This is a comment with no parent comment (depth 0): we start
566 // by retrieving the maximum thread level.
567 $max = db_result(db_query('SELECT MAX(thread) FROM {comments} WHERE nid = %d', $edit['nid']));
568
569 // Strip the "/" from the end of the thread.
570 $max = rtrim($max, '/');
571
572 // Next, we increase this value by one. Note that we can't
573 // use 1, 2, 3, ... 9, 10, 11 because we order by string and
574 // 10 would be right after 1. We use 1, 2, 3, ..., 9, 91,
575 // 92, 93, ... instead. Ugly but fast.
576 $decimals = (string) substr($max, 0, strlen($max) - 1);
577 $units = substr($max, -1, 1);
578 if ($units) {
579 $units++;
580 }
581 else {
582 $units = 1;
583 }
584
585 if ($units == 10) {
586 $units = '90';
587 }
588
589 // Finally, build the thread field for this new comment.
590 $thread = $decimals . $units .'/';
591 }
592 else {
593 // This is comment with a parent comment: we increase
594 // the part of the thread value at the proper depth.
595
596 // Get the parent comment:
597 $parent = db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $edit['pid']));
598
599 // Strip the "/" from the end of the parent thread.
600 $parent->thread = (string) rtrim((string) $parent->thread, '/');
601
602 // Get the max value in _this_ thread.
603 $max = db_result(db_query("SELECT MAX(thread) FROM {comments} WHERE thread LIKE '%s.%%' AND nid = %d", $parent->thread, $edit['nid']));
604
605 if ($max == '') {
606 // First child of this parent.
607 $thread = $parent->thread .'.1/';
608 }
609 else {
610 // Strip the "/" at the end of the thread.
611 $max = rtrim($max, '/');
612
613 // We need to get the value at the correct depth.
614 $parts = explode('.', $max);
615 $parent_depth = count(explode('.', $parent->thread));
616 $last = $parts[$parent_depth];
617
618 // Next, we increase this value by one. Note that we can't
619 // use 1, 2, 3, ... 9, 10, 11 because we order by string and
620 // 10 would be right after 1. We use 1, 2, 3, ..., 9, 91,
621 // 92, 93, ... instead. Ugly but fast.
622 $decimals = (string)substr($last, 0, strlen($last) - 1);
623 $units = substr($last, -1, 1);
624 $units++;
625 if ($units == 10) {
626 $units = '90';
627 }
628
629 // Finally, build the thread field for this new comment.
630 $thread = $parent->thread .'.'. $decimals . $units .'/';
631 }
632 }
633
634
635 $edit['cid'] = db_next_id('{comments}_cid');
636 $edit['timestamp'] = time();
637
638 if ($edit['uid'] = $user->uid) {
639 $edit['name'] = $user->name;
640 }
641
642
643 db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, format, hostname, timestamp, status, score, users, thread, name, mail, homepage) VALUES (%d, %d, %d, %d, '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", $edit['cid'], $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['format'], $_SERVER['REMOTE_ADDR'], $edit['timestamp'], $status, $score, $users, $thread, $edit['name'], $edit['mail'], $edit['homepage']);
644
645 _comment_update_node_statistics($edit['nid']);
646
647 // Tell the other modules a new comment has been submitted.
648 module_invoke_all('comment', 'insert', $edit);
649
650 // Add an entry to the watchdog log.
651 watchdog('content', t('Comment: added %subject.', array('%subject' => theme('placeholder', $edit['subject']))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
652 }
653
654 // Clear the cache so an anonymous user can see his comment being added.
655 cache_clear_all();
656
657 // Explain the approval queue if necessary, and then
658 // redirect the user to the node he's commenting on.
659 if ($status == 1) {
660 drupal_set_message(t('Your comment has been queued for moderation by site administrators and will be published after approval.'));
661 drupal_goto('node/'. $edit['nid']);
662 }
663 else {
664 drupal_goto('node/'. $edit['nid'], NULL, 'comment-'. $edit['cid']);
665 }
666 }
667 else {
668 return comment_preview($edit);
669 }
670 }
671 else {
672 watchdog('content', t('Comment: unauthorized comment submitted or comment submitted to a closed node (%subject).', array('%subject' => theme('placeholder', $edit['subject']))), WATCHDOG_WARNING);
673 }
674 }
675
676 function comment_links($comment, $return = 1) {
677 global $user;
678
679 $links = array();
680
681 // If we are viewing just this comment, we link back to the node.
682 if ($return) {
683 $links[] = l(t('parent'), comment_node_url(), NULL, NULL, "comment-$comment->cid");
684 }
685
686 if (node_comment_mode($comment->nid) == 2) {
687 if (user_access('administer comments') && user_access('access administration pages')) {
688 $links[] = l(t('delete'), "admin/comment/delete/$comment->cid");
689 $links[] = l(t('edit'), "admin/comment/edit/$comment->cid");
690 $links[] = l(t('reply'), "comment/reply/$comment->nid/$comment->cid");
691 }
692 else if (user_access('post comments')) {
693 if (comment_access('edit', $comment)) {
694 $links[] = l(t('edit'), "comment/edit/$comment->cid");
695 }
696 $links[] = l(t('reply'), "comment/reply/$comment->nid/$comment->cid");
697 }
698 else {
699 $links[] = theme('comment_post_forbidden');
700 }
701 }
702
703 if ($moderation = comment_moderation_form($comment)) {
704 $links[] = $moderation;
705 }
706
707 return $links;
708 }
709
710 function comment_render($node, $cid = 0) {
711 global $user;
712
713 $mode = $_GET['mode'];
714 $order = $_GET['order'];
715 $threshold = $_GET['threshold'];
716 $comments_per_page = $_GET['comments_per_page'];
717 $comment_page = $_GET['comment_page'];
718
719 $output = '';
720
721 if (user_access('access comments')) {
722 // Pre-process variables.
723 $nid = $node->nid;
724 if (empty($nid)) {
725 $nid = 0;
726 }
727
728 if (empty($mode)) {
729 $mode = $user->mode ? $user->mode : ($_SESSION['comment_mode'] ? $_SESSION['comment_mode'] : variable_get('comment_default_mode', 4));
730 }
731
732 if (empty($order)) {
733 $order = $user->sort ? $user->sort : ($_SESSION['comment_sort'] ? $_SESSION['comment_sort'] : variable_get('comment_default_order', 1));
734 }
735 if (empty($threshold)) {
736 $threshold = $user->threshold ? $user->threshold : ($_SESSION['comment_threshold'] ? $_SESSION['comment_threshold'] : variable_get('comment_default_threshold', 0));
737 }
738 $threshold_min = db_result(db_query('SELECT minimum FROM {moderation_filters} WHERE fid = %d', $threshold));
739
740 if (empty($comments_per_page)) {
741 $comments_per_page = $user->comments_per_page ? $user->comments_per_page : ($_SESSION['comment_comments_per_page'] ? $_SESSION['comment_comments_per_page'] : variable_get('comment_default_per_page', '50'));
742 }
743
744 $output .= "<a id=\"comment\"></a>\n";
745
746 if ($cid) {
747 // Single comment view.
748
749 $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
750 $output .= form_hidden('nid', $nid);
751
752 $result = db_query('SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0 GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users', $cid);
753
754 if ($comment = db_fetch_object($result)) {
755 $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
756 $output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 1)));
757 }
758
759 if ((comment_user_can_moderate($node)) && $user->uid != $comment->uid && !(comment_already_moderated($user->uid, $comment->users))) {
760 $output .= '<div style="text-align: center;">'. form_submit(t('Moderate comment')) .'</div><br />';
761 }
762 $output .= '</div></form>';
763 }
764 else {
765 // Multiple comment view
766
767 $query .= "SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name , c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.thread FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0";
768
769 $query .= ' GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users, c.thread';
770
771 /*
772 ** We want to use the standard pager, but threads would need every
773 ** comment to build the thread structure, so we need to store some
774 ** extra info.
775 **
776 ** We use a "thread" field to store this extra info. The basic idea
777 ** is to store a value and to order by that value. The "thread" field
778 ** keeps this data in a way which is easy to update and convenient
779 ** to use.
780 **
781 ** A "thread" value starts at "1". If we add a child (A) to this
782 ** comment, we assign it a "thread" = "1.1". A child of (A) will have
783 ** "1.1.1". Next brother of (A) will get "1.2". Next brother of the
784 ** parent of (A) will get "2" and so on.
785 **
786 ** First of all note that the thread field stores the depth of the
787 ** comment: depth 0 will be "X", depth 1 "X.X", depth 2 "X.X.X", etc.
788 **
789 ** Now to get the ordering right, consider this example:
790 **
791 ** 1
792 ** 1.1
793 ** 1.1.1
794 ** 1.2
795 ** 2
796 **
797 ** If we "ORDER BY thread ASC" we get the above result, and this is
798 ** the natural order sorted by time. However, if we "ORDER BY thread
799 ** DESC" we get:
800 **
801 ** 2
802 ** 1.2
803 ** 1.1.1
804 ** 1.1
805 ** 1
806 **
807 ** Clearly, this is not a natural way to see a thread, and users
808 ** will get confused. The natural order to show a thread by time
809 ** desc would be:
810 **
811 ** 2
812 ** 1
813 ** 1.2
814 ** 1.1
815 ** 1.1.1
816 **
817 ** which is what we already did before the standard pager patch. To
818 ** achieve this we simply add a "/" at the end of each "thread" value.
819 ** This way out thread fields will look like depicted below:
820 **
821 ** 1/
822 ** 1.1/
823 ** 1.1.1/
824 ** 1.2/
825 ** 2/
826 **
827 ** we add "/" since this char is, in ASCII, higher than every number,
828 ** so if now we "ORDER BY thread DESC" we get the correct order. Try
829 ** it, it works ;). However this would spoil the "ORDER BY thread ASC"
830 ** Here, we do not need to consider the trailing "/" so we use a
831 ** substring only.
832 */
833
834 if ($order == 1) {
835 if ($mode == 1 || $mode == 2) {
836 $query .= ' ORDER BY c.timestamp DESC';
837 }
838 else {
839 $query .= ' ORDER BY c.thread DESC';
840 }
841 }
842 else if ($order == 2) {
843 if ($mode == 1 || $mode == 2) {
844 $query .= ' ORDER BY c.timestamp';
845 }
846 else {
847
848 /*
849 ** See comment above. Analysis learns that this doesn't cost
850 ** too much. It scales much much better than having the whole
851 ** comment structure.
852 */
853
854 $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))';
855 }
856 }
857
858 // Start a form, for use with comment control and moderation.
859 $result = pager_query($query, $comments_per_page, 0, "SELECT COUNT(*) FROM {comments} WHERE status = 0 AND nid = %d", $nid);
860 if (db_num_rows($result) && (variable_get('comment_controls', 3) == 0 || variable_get('comment_controls', 3) == 2)) {
861 $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
862 $output .= theme('comment_controls', $threshold, $mode, $order, $comments_per_page);
863 $output .= form_hidden('nid', $nid);
864 $output .= '</div></form>';
865 }
866
867 $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
868 $output .= form_hidden('nid', $nid);
869
870 while ($comment = db_fetch_object($result)) {
871 $comment = drupal_unpack($comment);
872 $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
873 $comment->depth = count(explode('.', $comment->thread)) - 1;
874
875 if ($mode == 1) {
876 $output .= theme('comment_flat_collapsed', $comment, $threshold_min);
877 }
878 else if ($mode == 2) {
879 $output .= theme('comment_flat_expanded', $comment, $threshold_min);
880 }
881 else if ($mode == 3) {
882 $output .= theme('comment_thread_min', $comment, $threshold_min);
883 }
884 else if ($mode == 4) {
885 $output .= theme('comment_thread_max', $comment, $threshold_min);
886 }
887 }
888
889 // Use the standard pager; $pager_total is the number of returned rows,
890 // is global and defined in pager.inc.
891 if ($pager = theme('pager', NULL, $comments_per_page, 0, array('comments_per_page' => $comments_per_page))) {
892 $output .= $pager;
893 }
894
895 if (db_num_rows($result) && comment_user_can_moderate($node)) {
896 $output .= '<div id="comment-moderation-button">'. form_submit(t('Moderate comments')) .'</div>';
897 }
898
899 $output .= '</div></form>';
900
901 if (db_num_rows($result) && (variable_get('comment_controls', 3) == 1 || variable_get('comment_controls', 3) == 2)) {
902 $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
903 $output .= theme('comment_controls', $threshold, $mode, $order, $comments_per_page);
904 $output .= form_hidden('nid', $nid);
905 $output .= '</div></form>';
906 }
907 }
908
909 // If enabled, show new comment form.
910 if (user_access('post comments') && node_comment_mode($nid) == 2 && variable_get('comment_form_location', 0)) {
911 $output .= theme('comment_form', array('nid' => $nid), t('Post new comment'));
912 }
913 }
914 return $output;
915 }
916
917 /**
918 * Menu callback; edit a comment from the administrative interface.
919 */
920 function comment_admin_edit($cid) {
921 // Comment edits need to be saved.
922 if ($_POST['op'] == t('Submit')) {
923 $edit = $_POST['edit'];
924 comment_save($edit['cid'], $edit);
925 drupal_goto('admin/comment');
926 }
927
928 // If we're not saving our changes above, we're editing it.
929 $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', $cid);
930 $comment = db_fetch_object($result);
931 $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
932 $comment = drupal_unpack($comment);
933
934 if ($comment) {
935 if (!$comment->uid && (variable_get('comment_anonymous', 0) > 0)) {
936 // If comment from non-registered user, allow admin to modify anonymous fields.
937 $form .= form_textfield(t('Name'), 'name', $comment->name ? $comment->name : variable_get('anonymous', 'Anonymous') , 20, 60);
938 $form .= form_textfield(t('E-mail'), 'mail', $comment->mail, 20, 64);
939 $form .= form_textfield(t('Homepage'), 'homepage', $comment->homepage, 20, 255);
940 }
941 else {
942 // Otherwise, just display the author's name.
943 $form .= form_item(t('Author'), format_name($comment));
944 }
945 $form .= form_textfield(t('Subject'), 'subject', $comment->subject, 70, 128);
946 $form .= form_textarea(t('Comment'), 'comment', $comment->comment, 70, 15, '');
947 $form .= filter_form('format', $comment->format);
948 $form .= form_radios(t('Status'), 'status', $comment->status, array(t('Published'), t('Not published')));
949 $form .= form_hidden('nid', $comment->nid);
950 $form .= form_hidden('cid', $comment->cid);
951 $form .= form_submit(t('Submit'));
952 print theme('page', form($form));
953 }
954 }
955
956 /**
957 * Menu callback; delete a comment.
958 */
959 function comment_delete($cid) {
960 $comment = db_fetch_object(db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.cid = %d', $cid));
961 $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
962
963 $output = '';
964
965 // We'll only delete if the user has confirmed the
966 // deletion using the form in our else clause below.
967 if ($comment->cid && $_POST['edit']['confirm']) {
968 drupal_set_message(t('The comment and all its replies have been deleted.'));
969
970 // Delete comment and its replies.
971 _comment_delete_thread($comment);
972
973 _comment_update_node_statistics($comment->nid);
974
975 // Clear the cache so an anonymous user sees that his comment was deleted.
976 cache_clear_all();
977
978 drupal_goto("node/$comment->nid");
979
980 }
981 else if ($comment->cid) {
982 $output = theme('confirm',
983 t('Are you sure you want to delete the comment %title?', array('%title' => theme('placeholder', $comment->subject))),
984 'node/'. $comment->nid,
985 t('Any replies to this comment will be lost. This action cannot be undone.'),
986 t('Delete'));
987 // Show comment that is being deleted
988 $comment->comment = check_output($comment->comment, $comment->format);
989 $output .= theme('comment', $comment);
990
991 }
992 else {
993 drupal_set_message(t('The comment no longer exists.'));
994 }
995
996 print theme('page', $output);
997 }
998
999 function comment_save($id, $edit) {
1000 db_query("UPDATE {comments} SET subject = '%s', comment = '%s', status = %d, format = '%s', name = '%s', mail = '%s', homepage = '%s' WHERE cid = %d", $edit['subject'], $edit['comment'], $edit['status'], $edit['format'], $edit['name'], $edit['mail'], $edit['homepage'], $id);
1001 watchdog('content', t('Comment: modified %subject.', array('%subject' => theme('placeholder', $edit['subject']))));
1002 drupal_set_message(t('The comment has been saved.'));
1003
1004 _comment_update_node_statistics($edit['nid']);
1005
1006 // Allow modules to respond to the updating of a comment.
1007 module_invoke_all('comment', 'update', $edit);
1008 }
1009
1010 /**
1011 * Menu callback; present an administrative comment listing.
1012 */
1013 function comment_admin_overview($type = 'new') {
1014
1015 $header = array(
1016 array