| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
function comment_admin($type = 'new') {
|
| 13 |
$edit = $_POST;
|
| 14 |
|
| 15 |
if (isset($edit['operation']) && ($edit['operation'] == 'delete') && isset($edit['comments']) && $edit['comments']) {
|
| 16 |
return drupal_get_form('comment_multiple_delete_confirm');
|
| 17 |
}
|
| 18 |
|
| 19 |
return drupal_get_form('comment_admin_overview', $type, arg(4));
|
| 20 |
|
| 21 |
}
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
function comment_admin_overview($type = 'new', $arg) {
|
| 38 |
|
| 39 |
$form['options'] = array(
|
| 40 |
'#type' => 'fieldset',
|
| 41 |
'#title' => t('Update options'),
|
| 42 |
'#prefix' => '<div class="container-inline">',
|
| 43 |
'#suffix' => '</div>',
|
| 44 |
|
| 45 |
$options = array();
|
| 46 |
foreach (comment_operations($arg == 'approval' ? 'publish' : 'unpublish') as $key => $value) {
|
| 47 |
$options[$key] = $value[0];
|
| 48 |
}
|
| 49 |
$form['options']['operation'] = array(
|
| 50 |
'#type' => 'select',
|
| 51 |
'#options' => $options,
|
| 52 |
'#default_value' => 'publish',
|
| 53 |
|
| 54 |
$form['options']['submit'] = array(
|
| 55 |
'#type' => 'submit',
|
| 56 |
'#value' => t('Update'),
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
$status = ($arg == 'approval') ? COMMENT_NOT_PUBLISHED : COMMENT_PUBLISHED;
|
| 61 |
|
| 62 |
'subject' => array('data' => t('Subject'), 'field' => 'subject'),
|
| 63 |
'author' => array('data' => t('Author'), 'field' => 'name'),
|
| 64 |
'posted_in' => array('data' => t('Posted in'), 'field' => 'node_title'),
|
| 65 |
'time' => array('data' => t('Time'), 'field' => 'timestamp', 'sort' => 'desc'),
|
| 66 |
'operations' => array('data' => t('Operations')),
|
| 67 |
);
|
| 68 |
|
| 69 |
$query = db_select('comment', 'c')->extend('PagerDefault')->extend('TableSort');
|
| 70 |
$query->join('users', 'u', 'u.uid = c.uid');
|
| 71 |
$query->join('node', 'n', 'n.nid = c.nid');
|
| 72 |
$query->addField('u', 'name', 'registered_name');
|
| 73 |
$query->addField('n', 'title', 'node_title');
|
| 74 |
|
| 75 |
->fields('c', array('subject', 'nid', 'cid', 'comment', 'timestamp', 'status', 'name', 'homepage'))
|
| 76 |
->fields('u', array('uid'))
|
| 77 |
->condition('c.status', $status)
|
| 78 |
->limit(50)
|
| 79 |
->orderByHeader($header)
|
| 80 |
->execute();
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
$options = array();
|
| 85 |
$destination = drupal_get_destination();
|
| 86 |
|
| 87 |
foreach ($result as $comment) {
|
| 88 |
$options[$comment->cid] = array(
|
| 89 |
'subject' => l($comment->subject, 'comment/' . $comment->cid, array('attributes' => array('title' => truncate_utf8($comment->comment, 128)), 'fragment' => 'comment-' . $comment->cid)),
|
| 90 |
'author' => theme('username', $comment),
|
| 91 |
'posted_in' => l($comment->node_title, 'node/' . $comment->nid),
|
| 92 |
'time' => format_date($comment->timestamp, 'small'),
|
| 93 |
'operations' => l(t('edit'), 'comment/edit/' . $comment->cid, array('query' => $destination)),
|
| 94 |
|
| 95 |
}
|
| 96 |
|
| 97 |
$form['comments'] = array(
|
| 98 |
'#type' => 'tableselect',
|
| 99 |
'#header' => $header,
|
| 100 |
'#options' => $options,
|
| 101 |
'#empty' => t('No comments available.'),
|
| 102 |
|
| 103 |
|
| 104 |
$form['pager'] = array('#theme' => 'pager');
|
| 105 |
|
| 106 |
return $form;
|
| 107 |
}
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
function comment_admin_overview_validate($form, &$form_state) {
|
| 113 |
$form_state['values']['comments'] = array_diff($form_state['values']['comments'], array(0));
|
| 114 |
|
| 115 |
if (count($form_state['values']['comments']) == 0) {
|
| 116 |
form_set_error('', t('Please select one or more comments to perform the update on.'));
|
| 117 |
drupal_goto('admin/content/comment');
|
| 118 |
}
|
| 119 |
}
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
function comment_admin_overview_submit($form, &$form_state) {
|
| 128 |
$operations = comment_operations();
|
| 129 |
if ($operations[$form_state['values']['operation']][1]) {
|
| 130 |
|
| 131 |
$query = $operations[$form_state['values']['operation']][1];
|
| 132 |
foreach ($form_state['values']['comments'] as $cid => $value) {
|
| 133 |
if ($value) {
|
| 134 |
|
| 135 |
|
| 136 |
->condition('cid', $cid )
|
| 137 |
->execute();
|
| 138 |
$comment = comment_load($cid);
|
| 139 |
_comment_update_node_statistics($comment->nid);
|
| 140 |
|
| 141 |
module_invoke_all('comment_' . $form_state['values']['operation'], $comment);
|
| 142 |
|
| 143 |
watchdog('content', 'Comment: updated %subject.', array('%subject' => $comment->subject), WATCHDOG_NOTICE, l(t('view'), 'node/' . $comment->nid, array('fragment' => 'comment-' . $comment->cid)));
|
| 144 |
}
|
| 145 |
}
|
| 146 |
cache_clear_all();
|
| 147 |
drupal_set_message(t('The update has been performed.'));
|
| 148 |
$form_state['redirect'] = 'admin/content/comment';
|
| 149 |
}
|
| 150 |
}
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
function comment_multiple_delete_confirm(&$form_state) {
|
| 163 |
$edit = $form_state['input'];
|
| 164 |
|
| 165 |
$form['comments'] = array(
|
| 166 |
'#prefix' => '<ul>',
|
| 167 |
'#suffix' => '</ul>',
|
| 168 |
'#tree' => TRUE,
|
| 169 |
|
| 170 |
|
| 171 |
$comment_counter = 0;
|
| 172 |
foreach (array_filter($edit['comments']) as $cid => $value) {
|
| 173 |
$comment = comment_load($cid);
|
| 174 |
if (is_object($comment) && is_numeric($comment->cid)) {
|
| 175 |
$subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField();
|
| 176 |
$form['comments'][$cid] = array('#type' => 'hidden', '#value' => $cid, '#prefix' => '<li>', '#suffix' => check_plain($subject) . '</li>');
|
| 177 |
$comment_counter++;
|
| 178 |
}
|
| 179 |
}
|
| 180 |
$form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
|
| 181 |
|
| 182 |
if (!$comment_counter) {
|
| 183 |
drupal_set_message(t('There do not appear to be any comments to delete, or your selected comment was deleted by another administrator.'));
|
| 184 |
drupal_goto('admin/content/comment');
|
| 185 |
}
|
| 186 |
|
| 187 |
return confirm_form($form,
|
| 188 |
t('Are you sure you want to delete these comments and all their children?'),
|
| 189 |
'admin/content/comment', t('This action cannot be undone.'),
|
| 190 |
t('Delete comments'), t('Cancel'));
|
| 191 |
|
| 192 |
}
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
function comment_multiple_delete_confirm_submit($form, &$form_state) {
|
| 198 |
if ($form_state['values']['confirm']) {
|
| 199 |
comment_delete_multiple(array_keys($form_state['values']['comments']));
|
| 200 |
cache_clear_all();
|
| 201 |
$count = count($form_state['values']['comments']);
|
| 202 |
watchdog('content', 'Deleted @count comments.', array('@count' => $count));
|
| 203 |
drupal_set_message(t('Deleted @count comments.', array('@count' => $count)));
|
| 204 |
}
|
| 205 |
$form_state['redirect'] = 'admin/content/comment';
|
| 206 |
}
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
function comment_delete_page($cid = NULL) {
|
| 215 |
$comment = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comment} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.cid = :cid', array(':cid' => $cid))->fetch();
|
| 216 |
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
|
| 217 |
$output = '';
|
| 218 |
|
| 219 |
if (is_object($comment) && is_numeric($comment->cid)) {
|
| 220 |
$output = drupal_get_form('comment_confirm_delete', $comment);
|
| 221 |
}
|
| 222 |
|
| 223 |
drupal_set_message(t('The comment no longer exists.'));
|
| 224 |
|
| 225 |
|
| 226 |
return $output;
|
| 227 |
}
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
function comment_confirm_delete(&$form_state, $comment) {
|
| 236 |
$form = array();
|
| 237 |
$form['#comment'] = $comment;
|
| 238 |
return confirm_form(
|
| 239 |
$form,
|
| 240 |
t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject)),
|
| 241 |
'node/' . $comment->nid,
|
| 242 |
t('Any replies to this comment will be lost. This action cannot be undone.'),
|
| 243 |
t('Delete'),
|
| 244 |
t('Cancel'),
|
| 245 |
'comment_confirm_delete');
|
| 246 |
}
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
function comment_confirm_delete_submit($form, &$form_state) {
|
| 252 |
$comment = $form['#comment'];
|
| 253 |
|
| 254 |
comment_delete($comment->cid);
|
| 255 |
drupal_set_message(t('The comment and all its replies have been deleted.'));
|
| 256 |
watchdog('content', t('Deleted comment @cid and its replies.', array('@cid' => $comment->cid)));
|
| 257 |
|
| 258 |
cache_clear_all();
|
| 259 |
|
| 260 |
$form_state['redirect'] = "node/$comment->nid";
|
| 261 |
}
|
| 262 |
|