/** * inserts a new comment * * @param $data array * * @return int(id)|string(error) */ public static function new_comment($data) { $database = new Database(); $post = new Post(); $PostID = $data['post_id']; $content = $data['content']; $token = $data['token']; if (empty(trim($content))) { die("Comment can't be empty"); } $qna = new QNA(); if (!is_object($qna->get_question($PostID)) && !is_array($post->get_post($PostID, true))) { die("Error! Post was not found."); } if (!Token::validateToken($token)) { die("Error! Please try again later"); } unset($data['token']); $data['uid'] = USER_ID; $insert = $database->insert_data(TABLE_COMMENTS, $data); if ($insert === true && $database->error === false) { // success return (int) $database->lastId; } else { return array_shift($database->errors); } }
public static function postDate($id) { $QNA = new QNA(); $type = Post::PorQ($id); if ($type == 'q' || $type == 'c') { $post = $QNA->get_question($id) ?: (object) Comment::getComment($id); $date = $post->created; $html = "<a href='" . self::pLink($id) . "' title='{$date} GMT" . Date('P') . "' class='datetime'>{$date}</a>"; } elseif ($type == 'p') { $post = Post::get_post($id, true); $date = $post['date']; $html = "<a href='" . self::pLink($id) . "' title='{$date} GMT" . Date('P') . "' class='datetime'>{$date}</a>"; } else { return false; } return $html; }
$question = $QNA->get_question(); if (!is_object($question)) { die(json_encode(['status' => false, 'err' => 'Question was not found.'])); } $save = $QNA->save_post(); if ($save === true) { die(json_encode(['status' => true])); } else { die(json_encode(['status' => false, 'err' => $save])); } break; case 'unsave': $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.'])); } $save = QNA::remove_saved($PostID); if ($save === true) { die(json_encode(['status' => true])); } else { die(json_encode(['status' => false, 'err' => $save])); } break; case 'post_delete': $PostID = sanitize_id($data['id']); $post = new Post(); // check if post exists $post = $post->get_post($PostID, true);
public static function PorQ($id) { $QNA = new QNA(); $post = new self(); if (is_object($QNA->get_question($id))) { return "q"; } elseif (is_array($post->get_post($id, true))) { return "p"; } elseif (is_array(Comment::getComment($id))) { return "c"; } else { return false; } }
if (USER_ID !== $comment['uid']) { die(json_encode(['status' => false, 'id' => $CommentID, 'err' => 'Authentication error.'])); } $update = Comment::edit_comment($CommentID, $content); if ($update === true) { die(json_encode(['status' => true, 'id' => $CommentID])); } else { die(json_encode(['status' => false, 'id' => $CommentID, 'err' => $update])); } break; case 'report': $PostID = sanitize_id($data['post_id']); $content = $data['content']; $user_id = USER_ID; if ($data['type'] == 'post') { $post = QNA::get_question($PostID); if (!is_object($post)) { die(json_encode(['status' => false, 'id' => $PostID, 'err' => 'Post was not found.'])); } $report = QNA::report($PostID, $content, $user_id); if ($report === true) { die(json_encode(['status' => true, 'id' => $PostID])); } else { if ($report[1] == 1062) { die(json_encode(['status' => false, 'id' => $PostID, 'err' => 1062])); } else { die(json_encode(['status' => false, 'id' => $PostID, 'err' => $report[2]])); } } } else { $comment = Comment::getComment($PostID);
$pageTitle = "Admin Control Panel"; $session->adminLock(); if (isset($_POST['rp_rm']) && $_POST['rp_rm'] == 'true') { $id = $_POST['id']; Admin::removeReport($id); echo "1"; exit; } $id = $_GET['id']; $type = Post::PorQ($id); if (!$type) { Redirect::redirectTo('404'); } if ($type == 'q') { $QNA = new QNA(); $post = $QNA->get_question($id); $reps = QNA::get_reports($id); } else { $post = (object) Comment::getComment($id); $reps = Comment::get_reports($id); } $sec = "staff"; include ROOT_PATH . 'inc/head.php'; ?> <body> <div class="main" id="admincp"> <div class="ui container section rep_mng"> <?php if ($type == 'q') { ?>
<?php // The view for the users $pageTitle = "Stories"; $id = sanitize_id($_GET['id']) ?: null; $QNA = new QNA(); if (!($q = $QNA->get_question($id))) { // if the id is not in the questions database, try to find it in the comment database. if ($q = Comment::getComment($id)) { $q = $q['post_id']; if ($q == $id) { Redirect::redirectTo('404'); } Redirect::redirectTo(BASE_URL . "questions/question.php?id={$q}#{$id}"); } else { Redirect::redirectTo('404'); } } if ($q->status != 1 && !($session->adminCheck() || $session->userCheck($q->uid))) { Redirect::redirectTo('404'); } $user = new User($q->uid); $user = $user->user; $self = $q->uid === USER_ID; $voted = QNA::has_voted($id, USER_ID); $votes_count = QNA::get_votes($id) ?: "0"; $post_date = $q->created; $post_modified_date = $q->last_modified; if ($q->last_modified > $q->created) { $edited = " (edited <span class='datetime' title=\"{$post_modified_date}\">{$post_modified_date}</span>)"; } else {