CHAPTER 11 MODIFYING PHPBB 335 Getting Ready

CHAPTER 11 MODIFYING PHPBB 335 Getting Ready to Code When coding for phpBB 2.0, the key is understanding the codebase and the conventions involved. The phpBB team developers envisioned phpBB 2.0 as an easily modified version of phpBB, with plenty of accessible methods to aid you in accomplishing your tasks. Grasping those is a good first step to being a successful phpBB 2.0 hacker. When writing your hacks, a test installation is a must. For writing hacks, I recommend using a separate database from your production database entirely. This way, if you are making sweeping database modifications, there is zero risk of your production database being wiped out in a freak accident. Caution Never, ever, under any circumstances, do active hack development on a live installation! Doing so can result in broken boards, frustrated administrators, and unhappy end users. Save yourself the grief and aspirin, and develop on only your test installation. Don t forget to have a backup handy, too. Using the phpBB Coding Conventions As I mentioned earlier, one of the keys to a successful phpBB installation is to adhere to the phpBB coding conventions. You can find the most recent updates to these on http:// www.phpbb.com/mods/. phpBB s built-in methods are, in a nutshell, designed to keep you from reinventing the wheel. They are also designed to provide a seamless experience for end users, which is important in terms of continuity and goes a long way toward professionalism. Writing hacks that don t use the built-in phpBB methods can cause strange problems, may not be easily ported between boards (an important consideration if you intend to release your work to the public), and may ultimately limit the usefulness of your modification. The following sections discuss the methods phpBB uses for accessing data, using templates, working with sessions, getting user information, and giving feedback to your users. Accessing the phpBB Database Abstraction Layer The database abstraction layer provided by phpBB helps to simplify support for major database systems. PHP has groups of functions, such as mysql_query(), that correspond to whichever database type it is accessing. This can prove painful when writing blocks of SQL to support different databases; you will not only need to define different SQL (which you typically must do in any case), but you will also must implement the query method for each different database system. Undoubtedly, this can prove tedious, tiring, and error-prone. In the phpBB world, you are provided with a $db object, which represents the database driver for your configured database type. This object is initialized every time you run phpBB and is globally available to you. The $dbobject eliminates the need to fumble through the different functions for different database systems; in other words, rather than using database-specific calls such as mysql_query()or postgres_query(), you only need to call $db->sql_query(). If necessary, you can check the loaded database driver using a switch(SQL_LAYER)construct, as demonstrated in Listing 11-1. This example depicts checking the SQL_LAYERand defining different SQL for each database system, if necessary. (For clarity, the SQL is omitted to better highlight the structure.)
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Leave a Reply