
phpBBex is an enhanced version of phpBB 3, which was
previously announced on Habré. The project is gradually developing, there are new useful features. Today we have an official
forum and a
new version of our fork has been released.
As you know, the code phpBB 3 was laid back in 2002. Here everything is as before. There are no complicated abstractions, the code is simple and linear. For small projects this is not a problem. But the engine has acquired functionality, and now it’s not always easy to change the huge mass of code to achieve the desired result. Ignoring modern patterns hinders further development. It is clear that the developers of phpBB, it is important to monitor the compatibility of the code with the old mods, so no major architectural improvements can be expected. The solution to this situation should be phpBB 4 based on symfony 2, but have not yet taken it up. Obviously, rewriting such a monster is not so easy, so in the near future there will be no miracle.
Since phpBBex plans many changes related to the interface translation on AJAX, it would be logical to implement a convenient mechanism for adding new AJAX request handlers. The standard way for phpBB today is to create a php file in the root with its own logic for each modification. This is not the case. We tried to add something like a controller. Handlers are grouped into “controller classes”, there is a single entry point that creates an instance of the required “controller” and calls the appropriate handler. Based on this, we have created a system for anonymous evaluation of comments (almost like on Habré).
Autoload classes
And we will start from the beginning. Class autoloading is one of those nice things that we can add quite painlessly. What we did. The autoloader class (
source code ) is very simple and portable, it can be used in any other project. Requires PHP 5.2+.
')
Example of use:
require('./classes/autoloader.php');
The class file lookup scheme is fairly typical, with some innovations. The search is conducted in a shared directory with classes, or in a special directory (if the class name has some special prefix, for example, module_). There can be a lot of common and special directories for one prefix. They are bypassed in the order in which paths are added by the static add_path method.
The dereferencing of the class name to the file path is as follows. The name of the class being loaded is broken down by “_” (the checked prefix is ​​discarded). Then while there are directories with names that match the received parts of the class name, the path is generated as follows: part1 / part2 / part3 /. If the subdirectories have run out, the remainder is used as the file name (for example, the db_select_query class may correspond to the /classes/db/select/query.php file). Moreover, unlike other autoloaders, there may well remain several parts that will be combined via "_" (in the previous example, if the select directory does not exist, the file /classes/db/select_query.php will be used, but if there is no directory db, this is what happens /classes/db_select_query.php). If all parts were used as directory names, the last part matching the name of the last directory is used as the file name (for example, the db class if there is a db directory will correspond to the /classes/db/db.php file).
Service Classes
Once the autoloader appeared, it would be foolish not to create a small class library with useful functions. The following
classes were
implemented: arr (work with arrays), str (work with strings), request (work with request data), response (response creation), cookie (work with cookies). It even implemented its own router (class route) - to create and configure human urls in phpBB. Unfortunately, he is not involved yet. But in the future, we hope everything will be. Detailed documentation on these classes is also planned. When naming classes, methods and variables, the phpBB coding standard is used (everywhere lower case, underscore as a separator).
Implementing AJAX Request Handlers
What is commonly called “controllers” in modern systems, we called “modules” because phpBB does not have a model, and our handlers directly work with data. Perhaps this is no way out of phpBB 3.
All modules are in the modules directory, module class names are of the form module_something. Every action that a module can do is a method that has the prefix "action_". At the moment, it is used only for handling AJAX requests, so the entry point for requests to modules is the
ajax.php file, which accepts the module and action parameters and transfers control to the
core class, which loads the requested module and performs the necessary action.
Post rating
New classes really wanted to try in business. The implementation of the message evaluation function is a great opportunity to do this. One
class , a couple of methods - and here it is, the result!
Appearance:

Settings:

Statistics who got how many advantages, who put how much, etc. it is calculated and available in template variables, but by default it is not displayed anywhere. This was done intentionally so that the assessments would have a neutral effect on the atmosphere of the forum, and users would not try to “wind up” this indicator. But if someone does not agree - if desired, all the numbers are easy to withdraw.
What's next?
A developed router will be bolted to the resulting module system, the only index.php file will become the entry point. All existing scripts such as viewtopic.php and others will be designed as action s of the corresponding modules. The result is a flexible system for customizing the appearance of beautiful URLs on the forum.