You are here

function ajax_comments_instant_delete in AJAX Comments 6

Comments delete callback.

1 string reference to 'ajax_comments_instant_delete'
ajax_comments_menu in ./ajax_comments.module
Implementation of hook_menu().

File

./ajax_comments.pages.inc, line 224
AJAX comments form handling and callbacks.

Code

function ajax_comments_instant_delete($cid = 0) {
  $status = FALSE;

  // Check token to avoid CSRF attack.
  if ($cid && isset($_GET['token']) && drupal_valid_token($_GET['token'], $cid)) {
    drupal_set_header('Content-type: text/javascript; charset=utf-8');
    module_load_include('inc', 'comment', 'comment.admin');
    $comment = _comment_load($cid);

    // Delete comment and its replies.
    _comment_delete_thread($comment);
    _comment_update_node_statistics($comment->nid);

    // Clear the cache so an anonymous user sees that his comment was deleted.
    cache_clear_all();
    $status = TRUE;
  }
  $response = array(
    'status' => $status,
  );
  drupal_json($response);
}