So Peter and I were having this intelligent discussion on MSN Messenger discussing MyBB and how we could improve it. Peter was all like “Ooooooooooooppp” and I was like “Meeeeeeeeeh”. Then we were like “Weeeeeeeeeeeeeeeeeeee”. Okay, it didn’t really go like that at all.
Let’s face it; the code behind MyBB is crap. Well, a lot of it is crap. This is because MyBB has undergone numerous changes in coding standards and practices as well as development being underway in the past with no version control or collaboration tools in place.
Peter and I were actually discussing how we could improve the way MyBB performs validation on things such as threads, posts and users as well as the methods that MyBB uses when storing posts and other entities.
What we don’t have in MyBB is a standardised method for doing all of the above, code is repeated numerous times which makes it a pain when we’re adding in new features (or new database columns) to go back and make sure we updated other instances of the same, or similar code.
We wanted something to handle data. Enter data handlers. Data handlers will be our way of handling data in MyBB, as you may have already guessed. We’ll be developing several classes relating to different sections of the board (posting, poll voting and user account management) which deal with all of the different types of data that are used in them.
Think of it like a modular system for validation. Our validation classes extend upon an existing parent class called dataHandler. The dataHandler class provides standardised methods for setting and retrieving error messages. The validation classes, once extended upon the dataHandler then provide the actual methods for the type of validation we’ll be performing.
From validating new posts and registrations and determining what error messages to throw back to the user, right through to storing the actual post or user data in the database. Data handlers provide us with a standard API for storing information in MyBB as well as provide users with these APIs if they wish to easily extend upon them or use these features of MyBB in their existing projects.
Now, with our API in place (It’s not developed completely yet!), we’ll be able to do something like this to check if a new post is valid, if not then display the errors to the user, else insert the valid post into the database:
require_once "./inc/datahandlers/post.php";
$post_handler = new postHandler;
if(!$post_handler->validate_post(&$newpost))
{
foreach($post_handler->get_errors() as $error)
{
echo "$error\\n";
}
}
else
{
$post_handler->insert_post(&$newpost);
}
Along side our validate and insert methods, we’re going to have a verify method which will simply return true or false if say, a subject is valid, a username is valid or an email address is valid.
We’ve prototyped our error handling class which will allow either single errors to be set or multiple errors at a time. Multiple errors is particularly useful on pages such as the registration page where we supply a list of errors with the registration details along side the registration form again - inline error messages. Single error functionality was added in for those pages where we need to completely halt without further processing when a certain error is found.
Of course, it isn’t only data handlers we have planned. There are a lot of things which can be handled in different ways (Hey! - stop thinking like that!). We’re also talking permission handlers, to determine if a specific user or the current user has the permissions required to perform an action such as edit an event, edit a post, or edit their profile.
At the moment, most of this functionality exists in a prototype class that Peter has developed and we have both reviewed and discussed. Nothing has been implemented as of now - there is still a lot of planning we have to do in regards to how this system will work and exactly how we’ll deal with some of the more tedious parts of the system.
In short, we have lots of things being undertaken with MyBB at the moment, a lot of rewrites, extensions in both front end and code functionality as well as a few more little secrets we’re not going to let out of the bag yet.
I knew there was a reason why I wanted Peter to work with us on MyBB!