Exemplo n.º 1
0
 public static function delete($thread_id, $post_id)
 {
     // begin
     if ($_SESSION[KEY_SESSION][Account::KEY_USERNAME] == "guest") {
         Utils::showNoPermissionPage();
         die;
     }
     // end
     $thread = new Thread();
     $thread->initWithId($thread_id);
     $post = $thread->getPostById($post_id);
     if (!empty($_GET["confirm"]) && $_GET["confirm"] == "true") {
         // delete post, if current person is thread's host, delete thread as well
         if ($post->getAuthor()->getId() == $_SESSION[KEY_SESSION][Account::KEY_ID]) {
             $redirect_to = "/thread/";
             // it means host thread
             if ($post->isHost()) {
                 $thread->delete();
                 $post->delete();
             } else {
                 $post->delete();
                 $latest_update = Post::getLastModifiedPost($thread_id)->getModifiedTime();
                 $dt = new DateTime();
                 $dt->setTimestamp($latest_update);
                 $update_time = $dt->format("g:iA");
                 $update_date = $dt->format("Y/m/d");
                 $thread->updateUpdateTime($update_time, $update_date, $latest_update);
                 $redirect_to .= $thread_id;
             }
             header("Location: " . $redirect_to);
             die;
         } else {
             // you are not the owner of the post, you don't have the permission to alter
             Utils::showNoPermissionPage();
             include VIEWS_PATH . "private-nav.php";
             include VIEWS_PATH . "thread/thread.php";
             die;
         }
     } else {
         // get request
         $thread->initWithId($thread_id);
         $post = $thread->getPostById($post_id);
     }
     $permission = $thread->getPermission();
     if (!self::checkingPermission($thread_id, $post_id, $permission) || !($_SESSION[KEY_SESSION][Account::KEY_ID] == $post->getAuthor()->getId())) {
         Utils::showNoPermissionPage();
         return;
     }
     $content = "delete.php";
     include VIEWS_PATH . "private-nav.php";
     include VIEWS_PATH . "thread/thread.php";
 }
Exemplo n.º 2
0
 public static function destroyThread($id)
 {
     $thread = new Thread(Thread::find($id));
     $thread->delete();
     Redirect::to('/thread', array('message' => 'Thread deleted.'));
 }
 public function delete($queryString)
 {
     Thread::delete($queryString);
     header("Location: index.php");
 }
Exemplo n.º 4
0
 public function delete()
 {
     $thread_id = Param::get('thread_id');
     authorize_user_request($thread_id, self::AUTH_THREAD_DELETE);
     $user_id = get_authenticated_user_id($_SESSION['userid']);
     try {
         Thread::delete($thread_id);
     } catch (PDOException $e) {
         $_SESSION['deleteHasError'] = true;
     }
     $page_to_go = Param::get('page');
     if ($page_to_go === self::PROFILE_PAGE) {
         redirect(PROFILE_PAGE, array("user_id" => $user_id));
     }
     redirect(THREAD_PAGE);
 }