| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Allow quick approval directly from an email.
|
| 5 |
*
|
| 6 |
* @param $cid
|
| 7 |
* Comment ID number of the comment to act upon.
|
| 8 |
* @param $op
|
| 9 |
* The operation to be performed.
|
| 10 |
*/
|
| 11 |
function commentmail_quick_approve($cid = NULL, $op = FALSE) {
|
| 12 |
global $user;
|
| 13 |
if (user_access('administer comments')) {
|
| 14 |
|
| 15 |
$comment = db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $cid));
|
| 16 |
if ($comment) {
|
| 17 |
if ($op == 'approve') {
|
| 18 |
if (isset($_GET['token']) && drupal_valid_token($_GET['token'], $comment->timestamp)) {
|
| 19 |
$comment->status = 0;
|
| 20 |
if (comment_save((array)$comment)) {
|
| 21 |
// Link to comment on page.
|
| 22 |
drupal_goto('node/'. $comment->nid, NULL, 'comment-'. $comment->cid);
|
| 23 |
}
|
| 24 |
else {
|
| 25 |
drupal_set_message(t('Comment not saved'), 'error');
|
| 26 |
}
|
| 27 |
}
|
| 28 |
else {
|
| 29 |
return drupal_access_denied();
|
| 30 |
}
|
| 31 |
}
|
| 32 |
$comment->comment = check_markup($comment->comment, $comment->format, FALSE);
|
| 33 |
$node = node_load($comment->nid);
|
| 34 |
$output = "<h2>". t('Comment on <em>%title</em>', array('%title' => $node->title)) ."</h2>";
|
| 35 |
$confirm_delete = "return confirm('". t('Are you sure you want to delete this comment?') ."');";
|
| 36 |
$confirm_deleteban = "return confirm('". t('Are you sure you want to delete this comment and ban the computer that posted it?') ."');";
|
| 37 |
if ($comment->status) {
|
| 38 |
$links[] = array('title' => t('approve'), 'href' => 'comment/qa/'. $cid .'/approve', 'query' => 'token='. drupal_get_token($comment->timestamp));
|
| 39 |
}
|
| 40 |
else {
|
| 41 |
$links[] = array('title' => t('approved'));
|
| 42 |
}
|
| 43 |
$links[] = array('title' => t('edit'), 'href' => 'comment/edit/'. $cid);
|
| 44 |
$links[] = array('title' => t('delete'), 'href' => 'comment/quickdelete/'. $cid, 'query' => 'token='. drupal_get_token($comment->timestamp), 'attributes' => array('onclick' => $confirm_delete));
|
| 45 |
$links[] = array('title' => t('delete and ban ip'), 'href' => 'comment/quickdeleteban/'. $cid, 'query' => 'token='. drupal_get_token($comment->timestamp), 'attributes' => array('onclick' => $confirm_deleteban));
|
| 46 |
$output .= theme('comment', $comment, $node ,$links);
|
| 47 |
}
|
| 48 |
else {
|
| 49 |
$output = t("Comment not found.");
|
| 50 |
}
|
| 51 |
}
|
| 52 |
elseif ($user->uid > 0) {
|
| 53 |
return drupal_access_denied();
|
| 54 |
}
|
| 55 |
else {
|
| 56 |
// User is not logged in so go to the user login page,
|
| 57 |
// then come back here.
|
| 58 |
drupal_goto('user/login', 'destination=comment/qa/'. $cid);
|
| 59 |
}
|
| 60 |
return $output;
|
| 61 |
}
|
| 62 |
|
| 63 |
/**
|
| 64 |
* Allow quick deletion of a comment directly from an email.
|
| 65 |
*
|
| 66 |
* @param $cid
|
| 67 |
* Comment ID of comment being acted upon.
|
| 68 |
*/
|
| 69 |
function commentmail_quick_delete($cid = NULL) {
|
| 70 |
if (is_numeric($cid) && $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))) {
|
| 71 |
|
| 72 |
if (isset($_GET['token']) && drupal_valid_token($_GET['token'], $comment->timestamp)) {
|
| 73 |
commentmail_delete($comment);
|
| 74 |
|
| 75 |
drupal_goto("node/$comment->nid");
|
| 76 |
}
|
| 77 |
else {
|
| 78 |
return drupal_access_denied();
|
| 79 |
}
|
| 80 |
}
|
| 81 |
else {
|
| 82 |
return drupal_not_found();
|
| 83 |
}
|
| 84 |
}
|
| 85 |
|
| 86 |
/**
|
| 87 |
* Allow quick deletion and banning of a comment directly from an email.
|
| 88 |
*
|
| 89 |
* @param $cid
|
| 90 |
* Comment ID of comment being acted upon.
|
| 91 |
*/
|
| 92 |
function commentmail_quick_deleteban($cid = NULL) {
|
| 93 |
if (is_numeric($cid) && $comment = db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $cid))) {
|
| 94 |
|
| 95 |
if (isset($_GET['token']) && drupal_valid_token($_GET['token'], $comment->timestamp)) {
|
| 96 |
commentmail_delete($comment);
|
| 97 |
|
| 98 |
$aid = db_last_insert_id('access','aid');
|
| 99 |
db_query("INSERT INTO {access} (aid, mask, type, status) VALUES ('%s', '%s', 'host', 0)", $aid, $comment->hostname);
|
| 100 |
|
| 101 |
drupal_set_message(t('The address <em>%ip</em> has been banned.', array('%ip' => $comment->hostname)));
|
| 102 |
|
| 103 |
drupal_goto("node/$comment->nid");
|
| 104 |
}
|
| 105 |
else {
|
| 106 |
return drupal_access_denied();
|
| 107 |
}
|
| 108 |
}
|
| 109 |
else {
|
| 110 |
return drupal_not_found();
|
| 111 |
}
|
| 112 |
}
|
| 113 |
|
| 114 |
/**
|
| 115 |
* Delete a comment.
|
| 116 |
*
|
| 117 |
* @param $comment
|
| 118 |
* Full comment object to be deleted.
|
| 119 |
*/
|
| 120 |
function commentmail_delete($comment) {
|
| 121 |
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
|
| 122 |
|
| 123 |
drupal_set_message(t('The comment and all its replies have been deleted.'));
|
| 124 |
module_load_include('inc', 'comment', 'comment.admin');
|
| 125 |
// Delete comment and its replies.
|
| 126 |
_comment_delete_thread($comment);
|
| 127 |
|
| 128 |
_comment_update_node_statistics($comment->nid);
|
| 129 |
|
| 130 |
// Clear the cache so an anonymous user sees that the comment was deleted.
|
| 131 |
cache_clear_all();
|
| 132 |
}
|
| 133 |
|
| 134 |
/**
|
| 135 |
* Approve a comment.
|
| 136 |
*
|
| 137 |
* @param $cid
|
| 138 |
* Comment ID of comment to be approved.
|
| 139 |
*/
|
| 140 |
function commentmail_approve($form, $cid) {
|
| 141 |
if ($comment = _comment_load($cid)) {
|
| 142 |
if ($comment->status == COMMENT_NOT_PUBLISHED) {
|
| 143 |
return confirm_form(
|
| 144 |
array('cid' => array('#type' => 'value', '#value' => $comment->cid)),
|
| 145 |
t('Are you sure you want to approve the comment %title?', array('%title' => $comment->subject)),
|
| 146 |
array('path' => 'node/'. $comment->nid, 'fragment' => 'comment-'. $comment->cid),
|
| 147 |
t('The comment will be visible to all users.'),
|
| 148 |
t('Approve'),
|
| 149 |
t('Cancel')
|
| 150 |
);
|
| 151 |
}
|
| 152 |
else {
|
| 153 |
drupal_set_message(t('The comment is already published.'));
|
| 154 |
drupal_goto('node/'. $comment->nid, NULL, 'comment-'. $comment->cid);
|
| 155 |
}
|
| 156 |
}
|
| 157 |
else {
|
| 158 |
drupal_set_message(t('The comment no longer exists.'));
|
| 159 |
}
|
| 160 |
}
|
| 161 |
|
| 162 |
/**
|
| 163 |
* Submission handler for comment approval.
|
| 164 |
*/
|
| 165 |
function commentmail_approve_submit($form, &$form_state) {
|
| 166 |
$comment = _comment_load($form_state['values']['cid']);
|
| 167 |
$comment->status = 0;
|
| 168 |
|
| 169 |
if (comment_save((array)$comment)) {
|
| 170 |
// Link to comment on page.
|
| 171 |
drupal_set_message(t('The comment has been approved.'));
|
| 172 |
drupal_goto('node/'. $comment->nid, NULL, 'comment-'. $comment->cid);
|
| 173 |
}
|
| 174 |
else {
|
| 175 |
drupal_set_message(t('There was an error during the comment approving process.'), 'error');
|
| 176 |
}
|
| 177 |
}
|
| 178 |
|
| 179 |
/**
|
| 180 |
* Delete a comment and ban the author.
|
| 181 |
*
|
| 182 |
* @param $cid
|
| 183 |
* Comment ID of comment to be deleted.
|
| 184 |
*/
|
| 185 |
function commentmail_deleteban($form, $cid) {
|
| 186 |
|
| 187 |
if ($comment = _comment_load($cid)) {
|
| 188 |
return confirm_form(
|
| 189 |
array('cid' => array('#type' => 'value', '#value' => $comment->cid)),
|
| 190 |
t('Are you sure you want to delete the comment %title and ban its author?', array('%title' => $comment->subject)),
|
| 191 |
array('path' => 'node/'. $comment->nid, 'fragment' => 'comment-'. $comment->cid),
|
| 192 |
t('Any replies to this comment will be lost. This action cannot be undone. In addition, the author of the comment is no longer allowed to post comments on your site.'),
|
| 193 |
t('Delete and ban'),
|
| 194 |
t('Cancel')
|
| 195 |
);
|
| 196 |
}
|
| 197 |
else {
|
| 198 |
drupal_set_message(t('The comment no longer exists.'));
|
| 199 |
}
|
| 200 |
}
|
| 201 |
|
| 202 |
/**
|
| 203 |
* Submission handler for comment delete/ban.
|
| 204 |
*/
|
| 205 |
function commentmail_deleteban_submit($form, &$form_state) {
|
| 206 |
$comment = _comment_load($form_state['values']['cid']);
|
| 207 |
|
| 208 |
module_load_include('inc', 'comment', 'comment.admin');
|
| 209 |
|
| 210 |
// Delete comment and its replies.
|
| 211 |
_comment_delete_thread($comment);
|
| 212 |
_comment_update_node_statistics($comment->nid);
|
| 213 |
|
| 214 |
drupal_set_message(t('The comment and all its replies have been deleted.'));
|
| 215 |
|
| 216 |
// Clear the cache so an anonymous user sees that his comment was deleted.
|
| 217 |
cache_clear_all();
|
| 218 |
|
| 219 |
// Now, ban the user.
|
| 220 |
$aid = db_last_insert_id('access','aid');
|
| 221 |
db_query("INSERT INTO {access} (aid, mask, type, status) VALUES ('%s', '%s', 'host', 0)", $aid, $comment->hostname);
|
| 222 |
|
| 223 |
drupal_set_message(t('The host %host has been banned.', array('%host' => $comment->hostname)));
|
| 224 |
|
| 225 |
drupal_goto('node/'. $comment->nid);
|
| 226 |
}
|