338 CHAPTER 11 MODIFYING PHPBB Listing 11-3.
338 CHAPTER 11 MODIFYING PHPBB Listing 11-3. Retrieving a Post s Information Using the phpBB Abstraction Layer sql_query($sql)) { message_die(”Problem querying the database.”); } else { $postdata = $db->sql_fetchrow($result); echo “The post’s title is ” . $postdata[’subject’] . “.”; } ?> Notice that these two versions are essentially the same. In most cases, the main differences are the names of the functions. The convenience here is that you will be able to perform the query with whatever database driver is available, not just MySQL. You may also have noticed the use of the message_die() function in Listing 11-3 versus echo in Listing 11-2. message_die() is the standard, template-safe method of displaying error messages in phpBB, which is discussed next. Using phpBB s Template System When writing hacks for phpBB, interfacing with the template engine is about as inevitable as death and taxes. While this chapter will not specifically detail the creation of templates (a Chapter 12 topic), your modifications will need to perform some operations to properly integrate with the templating engine. Therefore, you should have some idea of how the template engine works. When a phpBB page is started, all output is directed to an output buffer, which holds all output until the end of the page. At that point, the template engine dumps the buffer, and thus the page, into your web browser. In between, the programmer performs the various operations the page is to undertake, and writes all intended output to typical PHP variables. In most cases, when the main page s processing is finished, the page title variable is set, the page header file is included, and the page header processing is started. The page header then loads its specific template file, assigns its PHP output variables to special template variables, and parses the overall header to HTML. After returning control to the main page, the main page calls its template file, assigns its own PHP output variables to template variables, and tells the template engine to parse its template file into HTML. Finally, the page footer is included, and it is parsed into HTML. Shortly thereafter, the output buffer is dumped onto the screen, and you have a fully built phpBB forum page. The template engine uses a few public methods to permit programmers to work with templates. Table 11-4 list the most common ones.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.