Esempio n. 1
0
    // Generate view data
    $user = $comment->user;
    $date = date("F d, Y", $comment->creation_date);
    $text = $comment->text;
    // Return comment to client
    include '../../app/views/comments/show.php';
    exit;
}
if ($method == 'DELETE') {
    // Get form data
    parse_str($_SERVER['QUERY_STRING'], $post_vars);
    if (isset($post_vars['cid'])) {
        $comment_id = $post_vars['cid'];
        $comments = new CommentService();
        $comment = $comments->get_comment($comment_id);
        // Check existence
        if (!isset($comment)) {
            HttpService::return_not_found();
        }
        // Check permission
        if (!AuthenticationService::can_delete_comment($comment)) {
            HttpService::return_unauthorized();
        }
        // Delete article
        $comments->delete_comment($comment_id);
        HttpService::return_no_content();
    }
    HttpService::return_bad_request();
}
// Otherwise
HttpService::return_not_found();