public static function userPage($id) { $user = new ForumUser(ForumUser::find($id)); $threads = Thread::findByUser($id); $messages = Message::findByUser($id); View::make('user/userpage.html', array('user' => $user, 'threads' => $threads, 'messages' => $messages)); }
public static function createAccount() { $params = $_POST; $time = date('Y-m-d G:i:s'); $params['userrole'] = 'USER'; $params['registered'] = $time; $user = new ForumUser($params); $errors = $user->errors(); if (count($errors) == 0) { $user->save(); $_SESSION['user'] = $user->id; Redirect::to('/', array('message' => 'Welcome ' . $user->username)); } else { View::make('register.html', array('errors' => $errors)); } }
public static function sandbox() { $postedTo1 = ForumUser::findPostedTo(1); $postedTo2 = ForumUser::findPostedTo(2); Kint::dump($postedTo1); Kint::dump($postedTo2); }
public static function get_user_logged_in() { if (isset($_SESSION['user'])) { $user_id = $_SESSION['user']; $user = ForumUser::find($user_id); return new ForumUser($user); } return null; }
public static function destroyMessage($id) { $message = new Message(Message::find($id)); $user_id = $message->user_id; $thread_id = $message->thread_id; $message->delete(); //Updating participants list ForumUser::changePostAmount($user_id, $thread_id, -1); Redirect::to('/thread/' . $message->thread_id, array('message' => 'Message deleted.')); }
public function getModerators($con) { $moderators = array(); $users = ForumUser::getAll($con); foreach ($users as $user) { if ($user->isModerating($this)) { $moderators[] = $user; } } if (!$this instanceof Category && $this->getParent() != null) { $moderators = array_merge($moderators, $this->getParent()->getModerators($con)); } return $moderators; }
<?php include 'noob.inc'; $user = new ForumUser(); if (preg_match("/^\\/[^\\/]*\\/([0-9]+)\\.phtml\$/", $script_name . $path_info, $regs)) { $uuser = new ForumUser($regs[1], false); } else { if (empty($path_info) || $path_info == "/") { $uuser = new ForumUser(); /* find by cookie */ if (!$uuser->valid()) { /* dont go to login page if user is invalid */ err_not_found("Unknown user"); } Header("Location: /account/{$uuser->aid}.phtml"); exit; } else { err_not_found("Unknown path"); } } if (!$uuser->valid()) { err_not_found("Unknown user"); } $stats = get_stats($uuser); if (array_key_exists('noob', $_GET)) { noob($_GET['noob'], $uuser->aid, $stats['active']); return; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>
/** * 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'>↓</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>"; }
$board = Board::getByID(intval(str_replace("b", "", $_GET["d"]))); if ($board != null) { if ($currentUser->hasPermission($delete_boards, $board)) { $board->delete($con); $successes[] = "Removed board: " . $board->name; } } } else { if (strstr($_GET["d"], "p")) { $post = Post::getByID(intval(str_replace("p", "", $_GET["d"]))); if ($post != null) { if ($currentUser->hasPermission($permission["post_delete"], $post)) { $thread = Thread::getByID($post->fields["Parent"]); if ($post->getID() == $thread->getFirstPost()->getID()) { $thread = Thread::getByID($post->fields["Parent"]); $users = ForumUser::getAll($con); foreach ($users as $user) { $user->unWatch($thread, $con); } $thread->delete($con); $successes[] = "Removed thread: " . $thread->name; } else { $successes[] = "Removed post from thread: " . $post->name; $post->delete($con); } } } } } } header("Location: " . $_SERVER['PHP_SELF']);
/** * @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; } }
$tpl->set_var("URL", $_url . $script_name . $path_info); /* Still needed for account templates */ if (isset($domain) && strlen($domain)) { $tpl->set_var("DOMAIN", $domain); } $scripts = array("" => "index.php", "preferences.phtml" => "preferences.php", "tracking.phtml" => "tracking.php", "directory.phtml" => "directory.php", "redirect.phtml" => "redirect.php", "gmessage.phtml" => "gmessage.php"); /* If you have your own account management routines */ if (!isset($dont_use_account)) { $account_scripts = array("login.phtml" => "account/login.php", "logout.phtml" => "account/logout.php", "forgotpassword.phtml" => "account/forgotpassword.php", "create.phtml" => "account/create.php", "acctedit.phtml" => "account/acctedit.php", "finish.phtml" => "account/finish.php", "f" => "account/finish.php"); foreach ($account_scripts as $virtual => $real) { $scripts[$virtual] = $real; } } $fscripts = array("" => "showforum.php", "tracking.phtml" => "showtracking.php", "post.phtml" => "post.php", "edit.phtml" => "edit.php", "delete.phtml" => "delete.php", "undelete.phtml" => "undelete.php", "track.phtml" => "track.php", "untrack.phtml" => "untrack.php", "markuptodate.phtml" => "markuptodate.php", "lock.phtml" => "lock.php", "unlock.phtml" => "unlock.php", "changestate.phtml" => "changestate.php", "sticky.phtml" => "sticky.php"); header("Cache-Control: private"); $user = new ForumUser(); $IPBAN = AclIpBanList::find_matching_ban_list($_SERVER["REMOTE_ADDR"]); function update_visits() { global $user, $_SERVER; $ip = "'" . addslashes($_SERVER['REMOTE_ADDR']) . "'"; $aid = -1; if ($user->valid()) { $aid = $user->aid; } $sql = "insert into f_visits ( aid, ip ) values ( ?, ? ) on duplicate key update tstamp=NOW()"; db_exec($sql, array($aid, $ip)); } function find_forum($shortname) { global $user, $forum, $indexes, $tthreads, $tthreads_by_tid, $down_for_maint;
public function validateUsername() { $errors = array(); if (!parent::validate_string_not_empty($this->username)) { $errors[] = 'Username must not be empty'; } if (!parent::validate_string_max($this->username, 20)) { $errors[] = 'Username must not be longer than 20 characters'; } $user = ForumUser::findByUsername($this->username); if ($user) { $errors[] = 'Username taken!'; } return $errors; }
<?php /* * Run this file to set up your database. * @author Calclavia */ require_once "config.php"; $con = mysql_connect($mysql_host, $mysql_username, $mysql_password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($db_name, $con); // Create table Category::setUp($con); Board::setUp($con); Thread::setUp($con); Post::setUp($con); ForumUser::setUp($con); mysql_close($con); die("Successfully set up databases!");
public static function participants($id) { $users = ForumUser::findParticipants($id); $thread = Thread::find($id); View::make('thread/thread_participants.html', array('thread' => $thread, 'users' => $users)); }