Subscribe to Grim's Projects        RSS Feed

How GrimBB Works

Icon Leave Comment
Alright so I'm going to try and explain the theory behind GrimBB in a conceptual sense and referring to what each file is responsible for. I won't expand on concepts such as formatting since that can vary. This will be more of a concise treatise on how the threads in GrimBB are created.

The page that should first be accessed by any user is portal.php. This page analyzes the contents of the include file and then generates the portal accordingly. However it's more important function is to create folders that will contain the threads for a particular forum. In order to do this accurately, we need to create folders with unique names and avoid the usage of certain characters. The reason we don't just use the titles as the folder names is because that might produce an error. Instead, we opt to take the CRC32 hash of the titles which will generate unique folder names (it is possible that you might generate the same hash twice, but the odds are high that you won't, you could also use another hash and achieve the same effect, such as MD5). Whenever the portal is loaded up it performs this check, tests to see if the folder already exists and if not it creates it. This way, if a new forum is added the folder is automatically created.

The second page that a user accesses varies because he/she could decide to register, login, or visit one of the forums. Let's assume the user chooses the latter. When a user loads the forum.php page into the browser window it looks within its corresponding folder and checks to see if there are any files within. If there are files contained within the folder it proceeds to open each one and retrieve the data from it. This data is parsed into an array by locating a character that separates each record (this character is the Record Separator character in ASCII, decimal 30, hex 1E). It then compares the timestamp (one of the records) of the last post in the thread to the current date. If the difference (in months) exceeds the number denoted by THREAD_LOCK (located in then the final character of the filename is changed to an 'l' to denote that the thread has been locked (take note that this check is only performed if the last character of the filename isn't already an 'l').

The user can now make the choice to navigate to a particular topic or start a new topic (along with register/login/logout and other such functions).
Option 1 - Viewing a Topic
If the user chooses to navigate to a topic the topic.php page is opened. This page does not perform any writing functions. It only reads the contents of threads. The way it knows which thread to read is because these are passed through the $_GET[] superglobal array in terms of a unique forum ID and a unique thread ID. It then composes a directory path of the forum ID (which we'll designate as fid) and the thread ID (which we'll designate as tid) in the following manner: fid/tid.txt. Now the page knows where to find the thread and it outputs it in the same manner as the forum.php page but ignoring the test for whether a thread is locked or opened.
Option 2 - Posting
When a user chooses to start a new topic or post a reply he is taken to the post.php page. If only a forum id is supplied in the $_GET[] superglobal array then it's assumed it's a new post. However, if both a forum id and a topic id are supplied then a reply is assumed. The post.php page then hands control over to the redirect.php page. Both pages perform checks to ensure that no errors are encountered. If no errors are encountered redirect.php creates a timestamp for the current date composed of the following year, month, day, hour, minute, second, dst flag. If it's a new topic the timestamp is used to create the file by appending an 'o' to this value and creating timestampo.txt. If however, it's a reply, then the topic id passed in the URL is used to open the particular topic and append the reply. The user is then redirected to the place where his new message appears.

That is essentially how GrimBB works. Obviously there are some minute details that have been overlooked but those should be apparent in the code. For instance, logging in and logging out simply involves setting or unsetting variables in the $_SESSION[] superglobal array. All pages check to be sure that URLs are properly formed. Invalid data checking is performed on usernames, passwords, topics, and posts. Style sheets control the look and feel of the board.

0 Comments On This Entry