public static function getElementFromCode($string)
 {
     if (strstr($string, "c")) {
         return Category::getByID(intval(str_replace("c", "", $string)));
     } else {
         if (strstr($string, "b")) {
             return Board::getByID(intval(str_replace("b", "", $string)));
         } else {
             if (strstr($string, "t")) {
                 return Thread::getByID(intval(str_replace("t", "", $string)));
             } else {
                 if (strstr($string, "p")) {
                     return Post::getByID(intval(str_replace("p", "", $string)));
                 }
             }
         }
     }
     return null;
 }
Exemple #2
0
<?php

require_once "forum/config.php";
$printContent = "";
/**
 * Takes the user to a specific page on the forum.
 */
if (!empty($_GET["p"])) {
    if (strstr($_GET["p"], "p")) {
        $post = Post::getByID(intval(str_replace("p", "", $_GET["p"])));
        $_GET["p"] = "t" . $post->fields["Parent"];
    }
    if (strstr($_GET["p"], "b")) {
        $board = Board::getByID(intval(str_replace("b", "", $_GET["p"])));
        if ($board != null) {
            if ($_GET["a"] == "new") {
                if ($currentUser != null) {
                    if ($currentUser->id > 0) {
                        if (!empty($_POST["title"]) && !empty($_POST["editableContent"])) {
                            $thread = $board->createThread($currentUser, clean($_POST["title"], true), clean($_POST["editableContent"]), time(), $con);
                            $successes[] = "Created forum thread!";
                        } else {
                            if ($_POST["board_name"] || $_POST["editableContent"]) {
                                $board->createBoard($currentUser, clean($_POST["board_name"]), clean($_POST["editableContent"]))->save($con);
                            }
                        }
                    }
                }
            }
            $printContent .= $board->printNewThreadForm();
            $printContent .= $board->printBoardContent($currentUser, $con);
Exemple #3
0
 function __construct($user, $elementID, $data, $con)
 {
     parent::__construct($user, Board::getByID(intval($elementID)), $data, $con);
 }
Exemple #4
0
 public function getParent()
 {
     return $this->fields["SubBoard"] == "yes" ? Board::getByID($this->fields["Parent"]) : Category::getByID($this->fields["Parent"]);
 }
Exemple #5
0
 /**
  * @param ForumUser $user - The current user
  * @param Integer $currentPage - The curent page
  * @return string The HTML content.
  */
 public function printThreadContent($user, $con, $currentPage = 1)
 {
     global $permission, $posts_per_page;
     if ($currentPage <= 0) {
         $currentPage = 1;
     }
     if ($this != null) {
         $printContent .= "\r\n\t\t\t<div class='thread'>\r\n\t\t\t\r\n            <div class=\"forum_menu\">";
         if ($user->hasPermission($permission["thread_sticky"], Board::getByID($this->fields["Parent"]))) {
             $stick = "<span class='hidden_field'>Stick: <input type='checkbox' id='sticky_{$this->getID()}' " . ($this->fields["Sticky"] == "yes" ? "checked='checked'" : "") . "></span>";
         }
         if ($user->hasPermission($permission["thread_lock"], $this)) {
             $lock = "<span class='hidden_field'>Lock: <input type='checkbox' id='lock_{$this->getID()}' " . ($this->fields["LockThread"] == "yes" ? "checked='checked'" : "") . "></span>";
         }
         if ($user->hasPermission($permission["thread_move"], Board::getByID($this->fields["Parent"]))) {
             $move = "<span class='hidden_field'>Move:<select id='move_{$this->getID()}'>";
             $move .= "<option value='-1'>--</option>";
             $categories = Category::getAll($con);
             foreach ($categories as $category) {
                 if ($category != null) {
                     foreach ($category->getChildren() as $board) {
                         $move .= "<option value='{$board->getID()}'>{$board->name}</option>";
                         foreach ($board->getAllSubBoards($con) as $subBoard) {
                             $indent = "";
                             foreach ($subBoard->getAllParents($con) as $parent) {
                                 $indent .= " -";
                             }
                             $move .= "<option value='{$subBoard->getID()}'>{$indent} {$subBoard->name}</option>";
                         }
                     }
                 }
             }
             $move .= "</select></span>";
         }
         if ($user->hasPermission($permission["thread_edit"], $this)) {
             $printContent .= "<a href=\"javascript:void(0)\" data-forum-target='{$this->getID()}' class='thread_edit btn_small btn_silver btn_flat'>Edit</a> ";
         }
         if ($user->hasPermission($permission["thread_watch"], $this)) {
             $printContent .= "<a href=\"javascript:void(0)\" data-forum-target='{$this->getID()}'class='thread_watch btn_small btn_silver btn_flat'>" . ($user->isWatching($this) ? "Unwatch" : "Watch") . " Thread (" . count($this->getWatching($con)) . ")</a> ";
         }
         if ($user->hasPermission($permission["post_create"], $this) && $this->fields["LockThread"] != "yes") {
             $printContent .= "<a href = \"javascript:\$('html, body').animate({scrollTop:  \$(document).height()})\" class='btn_small btn_silver btn_flat'>+ Post</a>";
         }
         $printContent .= "\r\n\t\t\t</div>\r\n\t\t\t<div>\r\n\t\t\t\t<h2 id='thread_title_{$this->getID()}' class='editable_title'>{$this->name}</h2>\r\n\t\t\t\t{$stick} {$lock} {$move}\r\n\t\t\t</div>\r\n\t\t\t<div class='clear'></div><div class='elements_container'>" . $this->getTreeAsString();
         if (count($this->getChildren()) > 0) {
             $posts = $this->getChildren();
             //Each page will contain 10 posts.
             $pages = array_chunk($posts, $posts_per_page);
             $i = 1;
             $pagination = "\r\n                    <ul class='pagination'>\r\n                    <li><a href='{$_SERVER['PHP_SELF']}?p=t{$this->getID()}&page=1' class='first'>First</a></li>\r\n                    <li><a href='{$_SERVER['PHP_SELF']}?p=t{$this->getID()}&page=" . max($currentPage - 1, 1) . "' class='previous'>Previous</a></li>";
             foreach ($pages as $page) {
                 if ($i == $currentPage) {
                     /**
                      * Print out each and every post.
                      */
                     foreach ($page as $post) {
                         $printContent .= $post->printPost($user, getUserByID($post->fields["User"]));
                     }
                     $pagination .= "<li><a href='#' class='current'>" . $i . "</a></li>";
                 } else {
                     if ($currentPage < $i && $currentPage > $i - 3 || $currentPage > $i && $currentPage < $i + 3) {
                         $pagination .= "<li><a href='{$_SERVER['PHP_SELF']}?p=t{$this->getID()}&page={$i}'>" . $i . "</a></li>";
                     }
                 }
                 $i++;
             }
             $pagination .= "\r\n                    <li><a href='{$_SERVER['PHP_SELF']}?p=t{$this->getID()}&page=" . max(min($currentPage + 1, $i - 1), 1) . "' class='next'>Next</a></li>\r\n                    <li><a href='{$_SERVER['PHP_SELF']}?p=t{$this->getID()}&page=" . ($i - 1) . "' class='last'>Last</a></li>\r\n                    </ul>";
             /**
              * Print out add new post form.
              */
             if ($user->hasPermission($permission["post_create"], $this) && $this->fields["LockThread"] != "yes") {
                 $printContent .= $this->printNewPostForm($user, $currentPage);
             }
         } else {
             $printContent .= "No posts avaliable.";
         }
         $printContent .= "<div class='page_numbers'>" . $pagination . "</div>" . $this->getTreeAsString() . "</div></div>";
         return $printContent;
     }
 }