} break; case 'downvote': $post = new Post(); $PostID = sanitize_id($data['id']); // check if question exists $QNA = new QNA($PostID); if (!is_object($QNA->get_question()) && !is_array($post->get_post($PostID, true))) { die(json_encode(['status' => false, 'err' => 'Question was not found.'])); } // check if user has not upvoted the question $voted = QNA::has_voted($PostID, USER_ID); if (!$voted) { die(json_encode(['status' => false, 'err' => 'You haven\'t upvoted this question.'])); } $remove = QNA::downvote($PostID, USER_ID); if ($remove === true) { die(json_encode(['status' => true])); } break; case 'publish': $PostID = sanitize_id($data['id']); $QNA = new QNA($PostID); // check if question exists $question = $QNA->get_question(); if (!is_object($question)) { die(json_encode(['status' => false, 'err' => 'Question was not found.'])); } if (USER_ID !== $question->uid) { die(json_encode(['status' => false, 'id' => $PostID, 'err' => 'Authentication error.'])); }