Commit 818d636e authored by Kjartan's avatar Kjartan
Browse files

- Commiting patch #7577: comment.module clean up.

parent 7cd54567
......@@ -262,11 +262,11 @@ function blogapi_new_media_object($req_params) {
if (!$data) {
return blogapi_error(t('No file sent'));
}
if (!$file = file_save_data($data, $name)) {
return blogapi_error(t('Error storing file'));
}
// Return the successful result.
$result = new xmlrpcval(array('url' => new xmlrpcval(file_create_url($file), 'string')), 'struct');
return new xmlrpcresp($result);
......
......@@ -262,11 +262,11 @@ function blogapi_new_media_object($req_params) {
if (!$data) {
return blogapi_error(t('No file sent'));
}
if (!$file = file_save_data($data, $name)) {
return blogapi_error(t('Error storing file'));
}
// Return the successful result.
$result = new xmlrpcval(array('url' => new xmlrpcval(file_create_url($file), 'string')), 'struct');
return new xmlrpcresp($result);
......
<?php
// $Id$
function comment_help($section = "admin/help#comment") {
$output = "";
/**
* Implementation of hook_help().
*/
function comment_help($section) {
switch ($section) {
case 'admin/help#comment':
$output = t("
return t("
<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, collaborative book page, etc.</p>
<h3>User control of comment display</h3>
<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>
......@@ -67,107 +68,105 @@ function comment_help($section = "admin/help#comment") {
<p>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>
<h4>Initial comment scores</h4>
<p>Finally, you may want to enter some <em>initial comment scores</em>. In <a href=\"%comment-initial\">administer &raquo; comments &raquo; initial comment scores</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/system/modules/comment"), "%site-config" => url("admin/system"), "%user-permissions" => url("admin/user/permission"), "%tracker" => url("tracker"), "%download-notify" => "http://drupal.org/project/releases", "%permission" => url("admin/user/permission"), "%comment-moderation" => url("admin/comment/moderation"), "%comment-votes" => url("admin/comment/moderation/votes"), "%comment-matrix" => url("admin/comment/moderation/matrix"), "%comment-thresholds" => url("admin/comment/moderation/filters"), "%slashdot" => " http://slashdot.org", "%comment-initial" => url("admin/comment/moderation/roles")));
break;
<p>Finally, you may want to enter some <em>initial comment scores</em>. In <a href=\"%comment-initial\">administer &raquo; comments &raquo; initial comment scores</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/system/modules/comment'), '%site-config' => url('admin/system'), '%user-permissions' => url('admin/user/permission'), '%tracker' => url('tracker'), '%download-notify' => 'http://drupal.org/project/releases', '%permission' => url('admin/user/permission'), '%comment-moderation' => url('admin/comment/moderation'), '%comment-votes' => url('admin/comment/moderation/votes'), '%comment-matrix' => url('admin/comment/moderation/matrix'), '%comment-thresholds' => url('admin/comment/moderation/filters'), '%slashdot' => ' http://slashdot.org', '%comment-initial' => url('admin/comment/moderation/roles')));
case 'admin/system/modules#description':
$output = t("Enables user to comment on content (nodes).");
break;
return t('Enables user to comment on content (nodes).');
case 'admin/system/modules/comment':
$output = t("Comments can be attached to any node. Below are the settings for comments. The display comes in two types, a \"flat list\" where everything is flush to the left side, and comments come in cronological order, and a \"threaded list\" where comments 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. To set the default threshold you first have to set up thresholds in the <a href=\"%threshold\">administer &raquo; comments &raquo; moderation &raquo; thresholds</a> area. Preview comment forces a user to look at their comment by clicking on a \"Preview\" button before they can actually add the comment. If \"New comment form\" is enabled then at the bottom of every comment page there will be a form too add a new comment.", array("%threshold" => url("admin/comment/moderation/filters")));
break;
return t("Comments can be attached to any node. Below are the settings for comments. The display comes in two types, a \"flat list\" where everything is flush to the left side, and comments come in cronological order, and a \"threaded list\" where comments 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. To set the default threshold you first have to set up thresholds in the <a href=\"%threshold\">administer &raquo; comments &raquo; moderation &raquo; thresholds</a> area. Preview comment forces a user to look at their comment by clicking on a \"Preview\" button before they can actually add the comment. If \"New comment form\" is enabled then at the bottom of every comment page there will be a form too add a new comment.", array('%threshold' => url('admin/comment/moderation/filters')));
case 'admin/comment':
$output = t("Comments let users give feedback to content authors. Here you may review/approve/deny recent comments, and configure moderation if desired.");
break;
return t('Comments let users give feedback to content authors. Here you may review/approve/deny recent comments, and configure moderation if desired.');
case 'admin/comment/comments':
$output = t("Click on <a href=\"%nup\">new or updated comments</a> to see your latest comments, or <a href=\"%queue\">comment approval queue</a> to approve new comments.", array("%nup" => url("admin/comment/comments/0"), "%queue" => url("admin/comment/comments/1")));
break;
return t("Click on <a href=\"%nup\">new or updated comments</a> to see your latest comments, or <a href=\"%queue\">comment approval queue</a> to approve new comments.", array('%nup' => url('admin/comment/comments/0'), '%queue' => url('admin/comment/comments/1')));
case 'admin/comment/comments/0':
$output = t("Below is a list of the latest comments posted your site. Click on a subject to see the comment, the author's name to edit the author's user information , \"edit comment\" to edit the comment, and \"delete comment\" to remove the comment.");
break;
return t("Below is a list of the latest comments posted your site. Click on a subject to see the comment, the author's name to edit the author's user information , \"edit comment\" to edit the comment, and \"delete comment\" to remove the comment.");
case 'admin/comment/comments/1':
$output = t("Below is a list of the comments posted to your site that need approval. To approve a comment click on <strong>\"edit comment\"</strong> and then change its <strong>moderation status</strong> to Approved.<br />Click on a subject to see the comment, the author's name to edit the author's user information, \"edit comment\" to edit the comment, and \"delete comment\" to remove the comment.");
break;
return t("Below is a list of the comments posted to your site that need approval. To approve a comment click on <strong>\"edit comment\"</strong> and then change its <strong>moderation status</strong> to Approved.<br />Click on a subject to see the comment, the author's name to edit the author's user information, \"edit comment\" to edit the comment, and \"delete comment\" to remove the comment.");
case 'admin/comment/moderation':
$output = t("If you have a get a lot of comments, you can enable comment moderation. Once moderation is enabled users can vote on a comment based on dropdown menus. <a href=\"%votes\">Votes</a> sets up the names in the dropdown menu, and the order in which they appear, using weights. <a href=\"%matrix\">Matrix</a> sets up the value of each user's vote, and <a href=\"%threshhold\">threshhold</a> sets up the levels at which a comment will be displayed.", array("%votes" => url("admin/comment/moderation/votes"), "%matrix" => url("admin/comment/moderation/matrix"), "%threshhold" => url("admin/comment/moderation/filters")));
break;
return t("If you have a get a lot of comments, you can enable comment moderation. Once moderation is enabled users can vote on a comment based on dropdown menus. <a href=\"%votes\">Votes</a> sets up the names in the dropdown menu, and the order in which they appear, using weights. <a href=\"%matrix\">Matrix</a> sets up the value of each user's vote, and <a href=\"%threshhold\">threshhold</a> sets up the levels at which a comment will be displayed.", array('%votes' => url('admin/comment/moderation/votes'), '%matrix' => url('admin/comment/moderation/matrix'), '%threshhold' => url('admin/comment/moderation/filters')));
case 'admin/comment/moderation/votes':
$output = t("Here is where you setup the names of each type of vote. Weight lets you set the order of the drop down menu. Click <strong>edit</strong> to edit a current vote weight.<br />Notes: <ul><li>you can have more than one type with the same name. The system does not protect you from this.</li><li>To <strong>delete</strong> a name/weight combiniation go to the <strong>edit</strong> area.</li></ul>");
break;
return t("Here is where you setup the names of each type of vote. Weight lets you set the order of the drop down menu. Click <strong>edit</strong> to edit a current vote weight.<br />Notes: <ul><li>you can have more than one type with the same name. The system does not protect you from this.</li><li>To <strong>delete</strong> a name/weight combiniation go to the <strong>edit</strong> area.</li></ul>");
case 'admin/comment/moderation/matrix':
$output = t("Here is where you assign a value to each item in the 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.<br />Notes:<ul><li>In order to use comment moderation, every text box on this page should be populated.</li><li>You must assign the <strong>moderate comments</strong> 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 <strong>lowering</strong> a comments over all score.</li></ul>");
break;
return t("Here is where you assign a value to each item in the 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.<br />Notes:<ul><li>In order to use comment moderation, every text box on this page should be populated.</li><li>You must assign the <strong>moderate comments</strong> 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 <strong>lowering</strong> a comments over all score.</li></ul>");
case 'admin/comment/moderation/filters':
$output = t("<em>Optional</em> Here you can setup the name and minimum \"cut off\" score to help your users hide comments that they don't want too see. These thresholds appear in the Comment Control Panel. Click \"edit\" to edit the values of an already exsisting threashold. To <strong>delete</strong> a threshold click on \"edit\".");
break;
return t("<em>Optional</em> Here you can setup the name and minimum \"cut off\" score to help your users hide comments that they don't want too see. These thresholds appear in the Comment Control Panel. Click \"edit\" to edit the values of an already exsisting threashold. To <strong>delete</strong> a threshold click on \"edit\".");
case 'admin/comment/moderation/roles':
$output = t("Here you can setup the <strong>initial</strong> vote value of a comment posted by each user role. This value is used before any other users vote on the comment.<br />Note: Blank entries are valued at zero");
break;
return t("Here you can setup the <strong>initial</strong> vote value of a comment posted by each user role. This value is used before any other users vote on the comment.<br />Note: Blank entries are valued at zero");
case 'admin/comment/search':
$output = t("Enter a simple pattern ( '*' maybe used as a wildcard match) to search for a comment. For example, one may search for 'br' and Drupal might return 'bread brakers', 'our daily bread' and 'brenda'.");
break;
}
return $output;
return t("Enter a simple pattern ( '*' maybe used as a wildcard match) to search for a comment. For example, one may search for 'br' and Drupal might return 'bread brakers', 'our daily bread' and 'brenda'.");
}
}
/**
* Menu callback; prints the comment-specific help text from admin/help.
*/
function comment_help_page() {
print theme('page', comment_help());
print theme('page', comment_help('admin/help#comment'));
}
/**
* Implementation of hook_settings().
*/
function comment_settings() {
$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."));
$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."));
$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."));
$group .= form_radios(t("Comment controls"), "comment_controls", variable_get("comment_controls", 0), 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."));
$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.'));
$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.'));
$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.'));
$group .= form_radios(t('Comment controls'), 'comment_controls', variable_get('comment_controls', 0), 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.'));
$output = form_group(t('Comment viewing options'), $group);
$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('user/admin/permission')));
$group .= form_radios(t("Comment subject field"), "comment_subject_field", variable_get('comment_subject_field', 1), array(t("Disabled"), t("Enabled")), t('Must users provide a subject for their comments?'));
$group .= form_radios(t("Preview comment"), 'comment_preview', variable_get('comment_preview', 1), array(t("Optional"), t("Required")), t("Must users preview comments before submitting?"));
$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")), t("The location of the comment submission form."));
$group .= form_radios(t('Comment subject field'), 'comment_subject_field', variable_get('comment_subject_field', 1), array(t('Disabled'), t('Enabled')), t('Must users provide a subject for their comments?'));
$group .= form_radios(t('Preview comment'), 'comment_preview', variable_get('comment_preview', 1), array(t('Optional'), t('Required')), t('Must users preview comments before submitting?'));
$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')), t('The location of the comment submission form.'));
$output .= form_group(t('Comment posting settings'), $group);
$result = db_query("SELECT fid, filter FROM {moderation_filters} ");
$result = db_query('SELECT fid, filter FROM {moderation_filters} ');
while ($filter = db_fetch_object($result)) {
$thresholds[$filter->fid] = ($filter->filter);
}
if ($thresholds) {
$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."));
$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.'));
$output .= form_group(t('Comment moderation settings'), $group);
}
return $output;
}
/**
* Implementation of hook_user().
*
* Provides signature customization for the user's comments.
*/
function comment_user($type, $edit, &$user) {
switch ($type) {
case 'edit':
// when user tries to edit his own data
return array(t('Personal information') => form_textarea(t("Signature"), "signature", $user->signature, 64, 3, t("Your signature will be publicly displayed at the end of your comments.") ."<br />". filter_tips_short()));
return array(t('Personal information') => form_textarea(t('Signature'), 'signature', $user->signature, 64, 3, t('Your signature will be publicly displayed at the end of your comments.') .'<br />'. filter_tips_short()));
case 'validate':
// validate user data editing
return array("signature" => $edit["signature"]);
return array('signature' => $edit['signature']);
}
}
/**
* This is *not* a hook_access() implementation. This function is called
* to determine whether the current user has access to a particular comment.
*
* Authenticated users can edit their comments as long they have not been
* replied to. This prevents people from changing or revising their
* statements based on the replies their posts got. Furthermore, users
* can't reply to their own comments and are encouraged instead to extend
* their original comment.
*/
function comment_access($op, $comment) {
global $user;
if ($op == "edit") {
/*
** Authenticated users can edit their comments as long they have
** not been replied to. This, in order to avoid people changing
** or revising their statements based on the replies their posts
** got. Furthermore, users can't reply to their own comments and
** are encouraged to extend their original comment.
*/
if ($op == 'edit') {
return $user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0;
}
}
function comment_node_url() {
return arg(0) ."/". arg(1) ."/". arg(2);
return arg(0) .'/'. arg(1) .'/'. arg(2);
}
function comment_edit($cid) {
......@@ -176,16 +175,16 @@ function comment_edit($cid) {
$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 AND c.status != 2', $cid));
$comment = drupal_unpack($comment);
$comment->name = $comment->registered_name ? $comment->registered_name : $comment->name;
if (comment_access("edit", $comment)) {
if (comment_access('edit', $comment)) {
return comment_preview(object2array($comment));
}
}
function comment_reply($pid, $nid) {
$output = "";
$output = '';
if (user_access("access comments")) {
if (user_access('access comments')) {
/*
** Show comment
......@@ -195,10 +194,10 @@ function comment_reply($pid, $nid) {
$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));
$comment = drupal_unpack($comment);
$comment->name = $comment->registered_name ? $comment->registered_name : $comment->name;
$output .= theme("comment_view", $comment);
$output .= theme('comment_view', $comment);
}
else if (user_access("access content")) {
$output .= node_view(node_load(array("nid" => $nid)));
else if (user_access('access content')) {
$output .= node_view(node_load(array('nid' => $nid)));
$pid = 0;
}
......@@ -207,17 +206,17 @@ function comment_reply($pid, $nid) {
*/
if (node_comment_mode($nid) != 2) {
$output .= theme('box', t("Reply"), t("This discussion is closed: you can't post new comments."));
$output .= theme('box', t('Reply'), t("This discussion is closed: you can't post new comments."));
}
else if (user_access("post comments")) {
$output .= theme("comment_form", array("pid" => $pid, "nid" => $nid), t("Reply"));
else if (user_access('post comments')) {
$output .= theme('comment_form', array('pid' => $pid, 'nid' => $nid), t('Reply'));
}
else {
$output .= theme('box', t("Reply"), t("You are not authorized to post comments."));
$output .= theme('box', t('Reply'), t('You are not authorized to post comments.'));
}
}
else {
$output .= theme('box', t("Reply"), t("You are not authorized to view comments."));
$output .= theme('box', t('Reply'), t('You are not authorized to view comments.'));
}
return $output;
......@@ -273,36 +272,30 @@ function comment_validate_form($edit) {
function comment_preview($edit) {
global $user;
$output = "";
$output = '';
foreach ($edit as $key => $value) {
$comment->$key = $value;
}
/*
** Attach the user and time information:
*/
// Attach the user and time information.
$comment->uid = $user->uid;
$comment->timestamp = time();
$comment->name = $user->name ? $user->name : $comment->name;
/*
** Preview the comment:
*/
$output .= theme("comment_view", $comment, theme('links', module_invoke_all('link', 'comment', $comment, 1)));
$output .= theme("comment_form", $edit, t("Reply"));
// Preview the comment.
$output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 1)));
$output .= theme('comment_form', $edit, t('Reply'));
if ($edit["pid"]) {
$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"]));
if ($edit['pid']) {
$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']));
$comment = drupal_unpack($comment);
$comment->name = $comment->registered_name ? $comment->registered_name : $comment->name;
$output .= theme("comment_view", $comment);
$output .= theme('comment_view', $comment);
}
else {
$output .= node_view(node_load(array("nid" => $edit["nid"])));
$edit["pid"] = 0;
$output .= node_view(node_load(array('nid' => $edit['nid'])));
$edit['pid'] = 0;
}
return $output;
......@@ -311,24 +304,19 @@ function comment_preview($edit) {
function comment_post($edit) {
global $user;
if (user_access("post comments") && node_comment_mode($edit['nid']) == 2) {
/*
** Validate the comment's subject. If not specified, extract
** one from the comment's body.
*/
if (user_access('post comments') && node_comment_mode($edit['nid']) == 2) {
// Validate the comment's subject. If not specified, extract
// one from the comment's body.
$edit['subject'] = strip_tags($edit['subject']);
if ($edit['subject'] == "") {
if ($edit['subject'] == '') {
$edit['subject'] = truncate_utf8(strip_tags($edit['comment']), 29);
}
if (!form_has_errors()) {
/*
** Check for duplicate comments. Note that we have to use the
** validated/filtered data to perform such check.
*/
// Check for duplicate comments. Note that we have to use the
// validated/filtered data to perform such check.
$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);
if ($duplicate != 0) {
......@@ -336,33 +324,21 @@ function comment_post($edit) {
}
if ($edit["cid"]) {
/*
** Update the comment in the database. Note that the update
** query will fail if the comment isn't owned by the current
** user.
*/
// Update the comment in the database. Note that the update
// query will fail if the comment isn't owned by the current
// user.
db_query("UPDATE {comments} SET subject = '%s', comment = '%s' WHERE cid = %d AND uid = '$user->uid'", $edit['subject'], $edit['comment'], $edit["cid"]);
/*
** Fire a hook
*/
module_invoke_all('comment', "update", $edit);
/*
** Add entry to the watchdog log:
*/
// Allow modules to respond to the updating of a comment.
module_invoke_all('comment', 'update', $edit);
watchdog('special', t('comment: updated "%comment-subject"', array('%comment-subject' => $edit["subject"])), l(t("view comment"), "node/view/". $edit["nid"], NULL, NULL, "comment-". $edit["cid"]));
// Add entry to the watchdog log.
watchdog('special', t('comment: updated "%comment-subject"', array('%comment-subject' => $edit['subject'])), l(t('view comment'), 'node/view/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
}
else {
/*
** Add the comment to database:
*/
$status = user_access("post comments without approval") ? 0 : 1;
$roles = variable_get("comment_roles", array());
// Add the comment to database.
$status = user_access('post comments without approval') ? 0 : 1;
$roles = variable_get('comment_roles', array());
$score = 0;
foreach (array_intersect(array_keys($roles), array_keys($user->roles)) as $rid) {
......@@ -376,16 +352,16 @@ function comment_post($edit) {
** in comment_render().
*/
if ($edit["pid"] == 0) {
if ($edit['pid'] == 0) {
/*
** This is a comment with no parent comment (depth 0): we start
** by retrieving the maximum thread level.
*/
$max = db_result(db_query("SELECT MAX(thread) FROM {comments} WHERE nid = %d", $edit["nid"]));
$max = db_result(db_query('SELECT MAX(thread) FROM {comments} WHERE nid = %d', $edit['nid']));
// Strip the "/" from the end of the thread
$max = rtrim($max, "/");
// Strip the "/" from the end of the thread.
$max = rtrim($max, '/');
/*
** Next, we increase this value by one. Note that we can't
......@@ -404,10 +380,10 @@ function comment_post($edit) {
}
if ($units == 10) {
$units = "90";
$units = '90';
}
// Finally build the thread field for this new comment
// Finally, build the thread field for this new comment.
$thread = "$decimals$units/";
}
else {
......@@ -417,25 +393,25 @@ function comment_post($edit) {
*/
// Get the parent comment:
$parent = db_fetch_object(db_query("SELECT * FROM {comments} WHERE cid = %d", $edit['pid']));
$parent = db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $edit['pid']));
// Strip the "/" from the end of the parent thread:
$parent->thread = (string)rtrim((string)$parent->thread, "/");
// Strip the "/" from the end of the parent thread.
$parent->thread = (string)rtrim((string)$parent->thread, '/');
// Get the max value in _this_ thread:
// Get the max value in _this_ thread.
$max = db_result(db_query("SELECT MAX(thread) FROM {comments} WHERE thread LIKE '%s.%%' AND nid = %d", $parent->thread, $edit['nid']));
if ($max == "") {
// First child of this parent
if ($max == '') {
// First child of this parent.
$thread = "$parent->thread.1/";
}
else {
// Strip the "/" at the end of the thread:
$max = rtrim($max, "/");
// Strip the "/" at the end of the thread.
$max = rtrim($max, '/');
// We need to get the value at the correct depth:
$parts = explode(".", $max);
$parent_depth = count(explode(".", $parent->thread));
// We need to get the value at the correct depth.
$parts = explode('.', $max);
$parent_depth = count(explode('.', $parent->thread));
$last = $parts[$parent_depth];
/*
......@@ -449,11 +425,11 @@ function comment_post($edit) {
$units = substr($last, -1, 1);
$units++;
if ($units == 10) {
$units = "90";
$units = '90';
}
// Finally build the thread field for this new comment:
$thread = "$parent->thread.". $decimals.$units ."/";
// Finally, build the thread field for this new comment.
$thread = "$parent->thread.". $decimals.$units .'/';
}
}
......@@ -462,25 +438,14 @@ function comment_post($edit) {
db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, hostname, timestamp, status, score, users, thread, name, mail, homepage) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", $edit["cid"], $edit["nid"], $edit["pid"], $user->uid, $edit['subject'], $edit['comment'], $_SERVER['REMOTE_ADDR'], time(), $status, $score, $users, $thread, $edit["name"], $edit['mail'], $edit["homepage"]);
/*
** Tell the other modules a new comment has been submitted:
*/
module_invoke_all('comment', "insert", $edit);
/*
** Add entry to the watchdog log:
*/
watchdog('special', t('comment: added "%comment-subject"', array('%comment-subject' => $edit["subject"])), l(t("view comment"), "node/view/". $edit["nid"], NULL, NULL, "comment-". $edit["cid"]));
// Tell the other modules a new comment has been submitted.
module_invoke_all('comment', 'insert', $edit);
// Add an entry to the watchdog log.
watchdog('special', t('comment: added "%comment-subject"', array('%comment-subject' => $edit['subject'])), l(t('view comment'), 'node/view/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
}
/*
** Clear the cache so an anonymous user can see his comment being
** added.
*/
// Clear the cache so an anonymous user can see his comment being added.
cache_clear_all();
/*
......@@ -500,7 +465,7 @@ function comment_post($edit) {
}
}
else {
watchdog('error', t('comment: unauthorized comment submitted or comment submitted to a closed node "%comment-subject"', array('%comment-subject' => $edit["subject"])));
watchdog('error', t('comment: unauthorized comment submitted or comment submitted to a closed node "%comment-subject"', array('%comment-subject' => $edit['subject'])));
}
}
......@@ -509,32 +474,29 @@ function comment_links($comment, $return = 1) {
$links = array();
/*
** If we are viewing just this comment, we link back to the node
*/
// If we are viewing just this comment, we link back to the node.
if ($return) {
$links[] = l(t("parent"), comment_node_url(), NULL, NULL, "comment-$comment->cid");
$links[] = l(t('parent'), comment_node_url(), NULL, NULL, "comment-$comment->cid");
}
if (node_comment_mode($comment->nid) == 2) {
if (user_access("administer comments") && user_access("access administration pages")) {
$links[] = l(t("delete comment"), "admin/comment/delete/$comment->cid");
$links[] = l(t("edit comment"), "admin/comment/edit/$comment->cid");
$links[] = l(t("reply to this comment"), "comment/reply/$comment->nid/$comment->cid");
if (user_access('administer comments') && user_access('access administration pages')) {
$links[] = l(t('delete comment'), "admin/comment/delete/$comment->cid");
$links[] = l(t('edit comment'), "admin/comment/edit/$comment->cid");
$links[] = l(t('reply to this comment'), "comment/reply/$comment->nid/$comment->cid");
}
else if (user_access("post comments")) {
if (comment_access("edit", $comment)) {
$links[] = l(t("edit your comment"), "comment/edit/$comment->cid");
else if (user_access('post comments')) {
if (comment_access('edit', $comment)) {
$links[] = l(t('edit your comment'), "comment/edit/$comment->cid");
}
$links[] = l(t("reply to this comment"), "comment/reply/$comment->nid/$comment->cid");
$links[] = l(t('reply to this comment'), "comment/reply/$comment->nid/$comment->cid");
}
else {
$links[] = theme("comment_post_forbidden");
$links[] = theme('comment_post_forbidden');
}
}
if ($moderation = theme("comment_moderation_form", $comment)) {
if ($moderation = theme('comment_moderation_form', $comment)) {
$links[] = $moderation;
}
......@@ -544,51 +506,44 @@ function comment_links($comment, $return = 1) {
function comment_render($node, $cid = 0) {
global $user;
$mode = $_GET["mode"];
$order = $_GET["order"];
$threshold = $_GET["threshold"];
$comments_per_page = $_GET["comments_per_page"];
$comment_page = $_GET["comment_page"];
$mode = $_GET['mode'];
$order = $_GET['order'];
$threshold = $_GET['threshold'];
$comments_per_page = $_GET['comments_per_page'];
$comment_page = $_GET['comment_page'];
$output = "";
if (user_access("access comments")) {
/*
** Pre-process variables:
*/
$output = '';
if (user_access('access comments')) {
// Pre-process variables.
$nid = $node->nid;
if (empty($nid)) {
$nid = 0;
}
if (empty($mode)) {
$mode = $user->mode ? $user->mode : ($_SESSION["comment_mode"] ? $_SESSION["comment_mode"] : variable_get("comment_default_mode", 4));
$mode = $user->mode ? $user->mode : ($_SESSION['comment_mode'] ? $_SESSION['comment_mode'] : variable_get('comment_default_mode', 4));
}
if (empty($order)) {
$order = $user->sort ? $user->sort : ($_SESSION["comment_sort"] ? $_SESSION["comment_sort"] : variable_get("comment_default_order", 1));
$order = $user->sort ? $user->sort : ($_SESSION['comment_sort'] ? $_SESSION['comment_sort'] : variable_get('comment_default_order', 1));
}