Permalink
Browse files

Comment classes and some other files.

  • Loading branch information...
1 parent 90e2b91 commit 5851d650fce98543d5773d9e3ef5aa8ec8923d2e @rosslagerwall committed Jul 10, 2011
Showing with 143 additions and 3 deletions.
  1. +17 −0 class.Forum.php
  2. +14 −0 class.PM.php
  3. +18 −0 class.Poll.php
  4. +13 −0 class.Post.php
  5. +30 −0 class.Topic.php
  6. +29 −0 class.User.php
  7. +4 −0 common.php
  8. +15 −3 function.OnlineList.php
  9. +3 −0 logout.php
View
@@ -1,4 +1,21 @@
<?php
+
+/* A class representing a single Forum. Each Forum contains a number of topics.
+In other words, it is the largest category.
+
+Each forum has a forumId, a forum name, a description, a number of posts and a
+number of topics.
+
+The noOfTopics and noOfPosts are cached here for performance reasons instead of
+recounting the number of posts each time it is required.
+
+The object is constructed from a string in the following format:
+forumId~forumName~description~noOfTopics~noOfPosts
+
+Each forum is a line in a file:
+db/forumList.dat
+
+*/
class Forum
{
private $forumId;
View
@@ -1,5 +1,18 @@
<?php
+/* A class representing a single private message. Each message belongs to a
+user.
+
+Each message has a sender, a recipient, a date, a boolean variable indicating
+whether it is read or not, a subject, a message and a message id.
+
+The object is constructed from a string in the following format:
+sender~recipient~date~isRead~subject~message~messageId
+
+Each message is a line in a file in db/PMs based on the recipient's username:
+db/PMs/<username>.dat
+
+*/
class PM
{
private $sender;
@@ -32,6 +45,7 @@ public function getMessage()
return $this->message;
}
+ /* Loads a User object of the user who created this message */
public function getSender()
{
return new User(file_get_contents("db/Users/".$this->sender.".dat"));
View
@@ -1,5 +1,23 @@
<?php
+/* A class representing a Poll. A Topic may have a Poll associated with it.
+
+Each poll has a forumId, a topicId, a join date, an array of users who have
+voted in the poll and a 2D array of option, no. of votes pairs and an end date.
+
+The object is constructed from a string in the following format:
+forumId
+topicId
+user1,user2,user3,...
+option1,noOfVotes
+option2,noOfVotes
+option3,noOfVotes
+...
+
+Each Poll has a file in the directory identified by the topicId:
+db/Topics/<topicId>/poll.dat
+
+*/
class Poll
{
private $forumId;
View
@@ -1,5 +1,17 @@
<?php
+/* A class representing a single post. Each message in a topic is a post.
+
+Each post has a postId, a topicId, a forumId, a userId, a dateTime and a
+message.
+
+The object is constructed from a string in the following format:
+forumId~topicId~postId~userId~dateTime~message
+
+Each post is a line in a file called posts.dat:
+db/Topics/<topicId>/posts.dat
+
+*/
class Post
{
private $postId;
@@ -45,6 +57,7 @@ public function getDateTime()
return $this->dateTime;
}
+ /* Loads a User object of the user who created this Post */
public function getUser()
{
return new User(file_get_contents("db/Users/".$this->userId.".dat"));
View
@@ -1,4 +1,30 @@
<?php
+
+/* A class representing a single topic. Each message in a topic is a post.
+
+Each topic has a topicId, a forumId, a userId, a dateTime, a total number of
+posts, a boolean variable indicating whether the topic is locked or not and a
+boolean variable indicating whether it is a "sticky" topic or not.
+
+The noOfPosts is cached here for performance reasons instead of recounting the
+number of posts each time it is required.
+
+The object is constructed from a string in the following format:
+forumId
+topicId
+userId
+dateTime
+noOfPosts
+topicName
+isLocked
+isSticky
+
+Each topic has a directory consisting of the topic string:
+db/Topics/<topicId>/topic.dat
+and the posts:
+db/Topics/<topicId>/posts.dat
+
+*/
class Topic
{
private $topicId;
@@ -33,6 +59,7 @@ public function getTopicId()
return $this->topicId;
}
+ /* Loads a User object of the user who created this Topic */
public function getUser()
{
return new User(file_get_contents("db/Users/".$this->userId.".dat"));
@@ -53,6 +80,9 @@ public function getTotalPosts()
return $this->posts;
}
+ /* Load a Post object of the most recent post in the Topic.
+ This is used to get the dateTime of the most recent post in this topic
+ for display in various places. */
public function getLatestPost()
{
$fileC = file("db/Topics/".$this->topicId."/posts.dat");
View
@@ -1,4 +1,33 @@
<?php
+
+/* A class representing a User.
+
+Each user has a userId, a password, a join date, a level, a signature, an email
+address, a boolean variable indicating whether their email address is visible
+or not, an URL to their avatar (if any), a boolean variable indicating whether
+they are banned or not, a number of topics and a number of posts.
+
+The noOfTopics and noOfPosts are cached here for performance reasons instead of
+recounting the number of posts each time it is required.
+
+The object is constructed from a string in the following format:
+userId
+password
+joinDate
+level
+sig
+email
+mustHideEmail
+avatar
+isBanned
+noOfTopics
+noOfPosts
+
+Each User has a file in the Users directory identified by the users' name,
+consisting of the user string:
+db/Users/<username>.dat
+
+*/
class User
{
private $userId;
View
@@ -1,4 +1,8 @@
<?php
+ /* This file provides includes and sets up sessions, certain variables,
+ remember me functionality and logins.
+ This file is included from many different pages. */
+
include_once("class.User.php");
include_once("class.Topic.php");
include_once("class.Post.php");
View
@@ -1,4 +1,7 @@
<?php
+
+ /* Add a logged in user to the list of users online (part of the statistics
+ * measuring code). The list is stored as a list of usernames. */
function addUser($userName)
{
$fileC = file("db/forumOnlineUsers.dat",FILE_IGNORE_NEW_LINES);
@@ -26,7 +29,9 @@ function addUser($userName)
}
file_put_contents("db/forumOnlineUsers.dat",$str);
}
-
+
+ /* Add a guest to the list of guests online (part of the statistics
+ * measuring code). The list is stored as a list of IP addresses. */
function addGuest($ip)
{
$fileC = file("db/forumOnlineGuests.dat",FILE_IGNORE_NEW_LINES);
@@ -55,6 +60,9 @@ function addGuest($ip)
file_put_contents("db/forumOnlineGuests.dat",$str);
}
+ /* This function is called before statistics are display on the index page
+ * to discard any people in the online lists who haven't been active within
+ * the last five minutes. */
function purge()
{
$fileC = file("db/forumOnlineGuests.dat",FILE_IGNORE_NEW_LINES);
@@ -93,7 +101,9 @@ function purge()
file_put_contents("db/forumOnlineUsers.dat","");
}
}
-
+
+ /* Called when a user logs out to forcibly remove them from the online
+ * users list. */
function removeUser($userName)
{
$fileC = file("db/forumOnlineUsers.dat",FILE_IGNORE_NEW_LINES);
@@ -114,7 +124,9 @@ function removeUser($userName)
file_put_contents("db/forumOnlineUsers.dat","");
}
}
-
+
+ /* Called when a user logs in to forcibly remove them from the online
+ * guests list. */
function removeGuest($ip)
{
$fileC = file("db/forumOnlineGuests.dat",FILE_IGNORE_NEW_LINES);
View
@@ -1,4 +1,7 @@
<?php
+ /* Logout, remove the user from the online list, reset cookies and return
+ to the index page. */
+
include_once("function.OnlineList.php");
include_once("class.User.php");
session_start();

0 comments on commit 5851d65

Please sign in to comment.