Example #1
0
 /**
  * Prints out the board as a forum block.
  * @param ForumUser $user - The current user.
  * @return string To be printed.
  */
 public function printBoard($user)
 {
     global $posts_per_page, $permission;
     /**
      * Display the stats.
      */
     $stats = count($this->getPosts()) . " post(s) " . $this->getViews() . " view(s)";
     $printLatestPost = "No posts.";
     $latestPost = $this->getLatestPost();
     if ($latestPost != null) {
         $latestPostUser = getUserByID($latestPost->fields["User"]);
         $thread = Thread::getByID($latestPost->fields["Parent"]);
         if ($latestPostUser != null && $thread != null) {
             $printLatestPost = "Lastest: <a href='{$_SERVER['PHP_SELF']}?p=t" . $thread->getID() . "&page=" . ceil(count($thread->getPosts()) / $posts_per_page) . "#" . $latestPost->getID() . "'>" . limitString($latestPost->name) . "</a><br /> By: <b>" . limitString($latestPostUser->username, 20) . "</b>, " . $latestPost->getDate() . ".";
         }
     }
     $subBoards = "";
     foreach ($this->getChildren() as $child) {
         if ($child instanceof Board) {
             $subBoards .= "<li><a href='{$_SERVER['PHP_SELF']}?p=b{$child->getID()}'>{$child->name}</a></li>";
         }
     }
     if (!empty($subBoards)) {
         $subBoards = "<ul>Sub-Boards: " . $subBoards . "</ul>";
     }
     if ($user->hasPermission($permission['board_edit'], $this->getParent())) {
         $orderHTML = "<a href=\"{$_SERVER['PHP_SELF']}?&o=b{$this->getID()}\" class='btn_small btn_silver btn_flat'>&darr;</a>";
     }
     return "\r\n\t    \t<div class='board_box forum_element'>\r\n\t    \t\t<div class='two_third'>\r\n\t    \t\t\t<span class='" . ($this->isUnread($user) ? "icon_on" : "icon_off") . "'></span>\r\n\t    \t\t\t<div class='board_content'>\r\n\t    \t\t\t\t<h3 class='element_title'><a href='{$_SERVER['PHP_SELF']}?p=b{$this->getID()}'>{$this->name}</a> {$orderHTML}</h3>\r\n\t    \t\t\t\t<div class='element_text'>\r\n\t    \t\t\t\t\t<span>{$this->fields["Description"]}</span>\r\n\t    \t\t\t\t\t<div class='forum_element_info'>{$stats}</div>\r\n\t    \t\t\t\t</div>\r\n\t    \t\t\t</div>\r\n\t    \t\t</div>\r\n\t    \t\t<div class='board_info forum_element_info one_third column-last'>\r\n\t    \t\t\t<p>{$printLatestPost}</p>\r\n\t    \t\t\t<div class='sub_boards'>\r\n\t    \t\t\t\t{$subBoards}\r\n\t    \t\t\t\t<div class='clear'></div>\r\n\t    \t\t\t</div>\r\n\t    \t\t</div>\r\n                <div class='clear'></div>\r\n\t    \t</div>\r\n\t\t\t<div class='hrline_silver'></div>";
 }
Example #2
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;
     }
 }