Archive for October, 2007

Sri lanka web server - 340 CHAPTER 11 MODIFYING PHPBB Using the

Wednesday, October 31st, 2007

340 CHAPTER 11 MODIFYING PHPBB Using the template code in Listing 11-5, the values 1, 2, and 3 will display accordingly. If you were to run Listing 11-5 through the template engine, it would look a little something like this: I can count! 1 2 3 Working with phpBB Sessions phpBB provides several facilities for working with sessions. A lot of these facilities are automatically called during the script execution and rarely need manipulation. However, you may need to work with these functions if your modifications use custom pages. While browsing the phpBB code, you may have noticed the existence of an append_sid() function surrounding every hyperlink URI, like this: $foo_uri = ““; If you ever code a hyperlink in the phpBB source code, this is a necessary evil. The append_sid() function, when used around a URI, adds a session ID to the end of that URI to facilitate a continuous session for users who elect not to accept cookies in their browser. Typically, this session ID an MD5 hash of a hashed version of the user s IP address is passed via cookies from page to page, not requiring the passing of a session ID between URIs. It is good practice to make sure append_sid() is used consistently whenever you create a new hyperlink, as forgetting to use this function can cause continuity issues with users who are logged in without cookies. If they click a link on your site that does not have the session ID built in, this can cause phpBB to generate a new session, which may result in problems with topic marking and other related functions. Note The phpBB developers heard the call of its community, and they have dropped the append_sid() requirement in phpBB 3.0. Getting User Information phpBB offers some functions for getting user information. Two particularly useful ones are get_userdata() and auth(). If you do a lot of work with users, you will find the get_userdata() function immensely helpful. You can pass either the username or user ID number of the user whose data you wish to retrieve to the function. phpBB will figure it out and return a value. If you wish, you can also pass a second, optional parameter called force_str. If you pass true in as the second parameter, it will force a username check. If the user ID or username was found, the function will return the user s data. If the user does not exist, the function returns false. You are also able to retrieve permissions for a user or group by using the auth() function, which is the programming interface to the permissions system. This can help you write hacks that are dependent on the rights of a user. auth() takes four parameters:
Please visit
Domain Name Hosting services for high quality webhost to host and run your jsp applications.

CHAPTER 11 MODIFYING PHPBB 339 Table 11-4. (Free php web host)

Wednesday, October 31st, 2007

CHAPTER 11 MODIFYING PHPBB 339 Table 11-4. Common Template Engine Methods phpBB Method Description assign_vars([array]) Assigns an array of template variables for use in your page. These variables are, in turn, inserted in your templates and display content onscreen. assign_block_vars([array]) Similar to assign_vars(), except this function is used in loops (such as in the Forum Index, View Topic, and View Forum pages, to name a few). set_filenames([array]) Takes an array of filenames and associated identifiers that represent the files that make up the template. pparse($identifier) Parses the template file associated with the identifier that is passed in to HTML. This helps to produce the final output. In developing your modifications, you will most likely be working with the assign_vars() and assign_block_vars() methods the most, as these create the necessary template variables for output. Listing 11-4 demonstrates how to assign template variables. Listing 11-4. Assigning Template Variables assign_vars(array(’UNO’ => $one, ‘DOS’ => $two, ‘TRES’ => $three) ); ?> As you can see, Listing 11-4 defines three PHP variables and assigns them the template variable names UNO, DOS, and TRES, using PHP s in-line array definition. Now, you can write a template calling these variables, as shown in the snippet of template code in Listing 11-5. Listing 11-5. Using Template Variables

I am counting!
{UNO}
{DOS}
{TRES}

In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

338 CHAPTER 11 MODIFYING PHPBB Listing 11-3.

Tuesday, October 30th, 2007

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.

CHAPTER 11 MODIFYING PHPBB 337 The abstraction

Monday, October 29th, 2007

CHAPTER 11 MODIFYING PHPBB 337 The abstraction layer provides all the functionality you need to get data to and from your database. Many methods are available to you to manipulate your data. Table 11-3 lists the functions you ll most commonly use when writing modifications, with their PHP equivalents. Table 11-3. Common Database Abstraction Layer Methods phpBB Method PHP Equivalent Description sql_query($sql) mysql_query() Runs a query on your database using SQL statements defined in $sql. Returns the result of the query if it is successful, and falseif a failure occurred. sql_fetchrow($query_id) mysql_fetch_array() Returns a row of data as requested in the result of sql_query(), or false if a failure occurred. Use this function when you expect only one row of results. The data returned by sql_fetchrow() is an array indexed by field name. For example, to access the field user_name in the returned variable foo, use the notation $foo[’user_name’]. sql_fetchrowset($query_id) Multiple calls to Works just like sql_fetchrow(), except it returns a mysql_fetch_array() multidimensional array containing multiple rows of data. Access the data returned by sql_fetchrowset() by using the notation $foo[$i][’field_name’], where $i is the number (starting with zero) of the result you wish to access. For example, to access the third result of a query on usernames, use the notation $foo[2][’user_name’]. sql_freeresult($query_id) mysql_free_result() Clears out the result of a query and enables you to start fresh. This is a good cleanup method to use, particularly after a large query, to help free memory and keep things running smoothly. Simply pass a result from sql_query() into the function to make it work. Returns true if successful, and false if a failure occurred. The mechanics of these functions are not much different from those of the built-in PHP equivalents. For example, Listing 11-2 shows how to get a post title in PHP format, and Listing 11-3 shows how to use the phpBB abstraction layer to retrieve the same information. Listing 11-2. Retrieving a Post s Information Using Standard PHP
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Web hosting domain names - 336 CHAPTER 11 MODIFYING PHPBB Listing 11-1.

Sunday, October 28th, 2007

336 CHAPTER 11 MODIFYING PHPBB Listing 11-1. Defining SQL for Different Database Systems switch(SQL_LAYER) { case ‘postgresql’: $sql . . . break; case ‘oracle’: $sql . . . break; case ‘mysql’: case ‘mysql4′: default: $sql . . . break; } This ability to check the SQL_LAYER is quite useful if you need to define SQL statements that vary from database to database. Table 11-2 lists the various possible SQL_LAYER values supported by phpBB 2.0. Table 11-2. Supported SQL_LAYER Values in phpBB 2.0 SQL_LAYER Value Corresponding Database mysql MySQL 3.x mysql4 MySQL 4.x postgres PostgreSQL mssql Microsoft SQL Server, no ODBC oracle Oracle msaccess Microsoft Access database mssql-odbc Microsoft SQL Server using an ODBC connection In most cases, modified SQL is not necessary. Most people do not have access to testing their SQL code against all the databases phpBB supports; this is why a lot of hacks only claim to work on MySQL, as they are largely untested on other systems. The hacks presented here are tested only on MySQL, which is the database you have been using for the examples in this book.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

CHAPTER 11 MODIFYING PHPBB 335 Getting Ready

Saturday, October 27th, 2007

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.

334 CHAPTER 11 (Web hosting top) MODIFYING PHPBB PREHACKED BOARDS

Friday, October 26th, 2007

334 CHAPTER 11 MODIFYING PHPBB PREHACKED BOARDS AND WHY YOU SHOULD AVOID THEM Some groups independent of phpBB take the phpBB codebase, add a lot of modifications to it, and re-release it in a package commonly known as a prehacked board. These can be the pinnacle of convenience, adding in just about any feature you could ever want bolted onto your phpBB software in one easy-to-install package, with no code to sweat over. However, these prehacked boards have some serious disadvantages that outweigh their advantages. For starters, prehacked boards typically come with a plethora of additional features that you may never need. With additional features comes additional bloat. Considering that the modifications applied probably have not had much mainstream performance testing, loading the package on your server when traffic is high could be quite a challenge. (Of course, this varies depending on who packaged the distribution.) Another problem is that prehacked boards may or may not be totally secure. Some boards may use older phpBB codebases, which may be vulnerable to attack. If a critical update is made available by the phpBB team, there s no telling when that same update will be available for your prehacked package, as applying the official phpBB update may break your board. Finally, distributions can come and go. If your prehacked phpBB maintainers decide to abandon their project, you could be stuck out in the cold with limited support and no updates, which is not safe when vulnerabilities strike. You are better off sticking with an official phpBB release that will be updated and supported. With an official release, you have total control over the modifications the freedom to add and remove features at will. With the prehacked packages, you are not necessarily afforded such flexibility. Creating Modifications Sometimes, the hacks out there just don t cut it you can t find one that does exactly what you want. Some people (like myself) are incessant tweakers, who feel the need to change more of the board than typically is modified. In these cases, the alternative is to create your own modifications. This is a task for the self-motivated with enough time to thoroughly test the effects of the modification. This section covers the basics of working with phpBB s various subsystems the guts of phpBB, if you will programmatically to create your own modifications, as well as how to package and submit them to the community. This section requires a fair amount of competency with PHP, object-oriented programming, and MySQL syntax. If you have any qualms about these topics, you should review a tutorial or consider purchasing a book such as Beginning PHP and MySQL by W. Jason Gilmore (Apress, 2004) before you start coding a hack. Note Before you start coding your hack, do a thorough search of the hacks sites listed in Table 11-1, and make sure that your desired hack doesn t already exist. If it does, it may be better for you to install that existing hack, rather than trying to reinvent the wheel. Additionally, if you will be submitting your work to the community, this cuts down on the number of duplicate hacks and other potential issues that may arise between the original author of the hack and yourself. You can save yourself a lot of work and trouble by making sure you aren t duplicating someone else s work.
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

1 on 1 web hosting - CHAPTER 11 MODIFYING PHPBB 333 If you

Thursday, October 25th, 2007

CHAPTER 11 MODIFYING PHPBB 333 If you see something reasonably close to Figure 11-2, you ve successfully installed the Quick Reply hack, and congratulations are in order. Feel free to give the box a try. Chances are, you ll like it. Be sure to back up your newly hacked files, in case you decide to go for more modifications and they don t work out. This way, you can restore from a recent point if something goes wrong, so you won t lose all your work. This is excellent practice for each modification you install. Once you know that everything is working properly, you can feel free to clean up some of these developmental backup copies. Go ahead and check out my recommendations on additional modifications (listed earlier in Table 11-1) for more phpBB hacking fun! If you see something other than Figure 11-2, don t panic. I ve got some troubleshooting ideas for you. Troubleshooting Hack Installation So you went through all those steps, but instead of the modification, you got a cryptic PHP error message, or perhaps there s no sign of any changes. In that case, review the following troubleshooting steps: Did you upload it? In the heat of the moment, it s easy to forget to upload. Make sure you uploaded the modification, and it s in the right place. Did you insert template code? Most phpBB 2.0 hacks require work to be done on your template. If you are not using the subSilver template on your site, make sure you edit the templates that your site uses. If you don t, you likely won t see any result from any of your hacks. Is all the code in the right place? Make sure all your code is properly placed within your files. Placement can be critical. Sometimes, the instructions are not as clear as they should be about where to put the code (it does happen). Is all the code right? Rarely, bad code makes its way into a hack. While people test hacks before they go into the databases, sometimes something slips. Check with the hack author or the distributor before continuing. Is there a version incompatibility? Sometimes, phpBB updates break existing hacks. If you have reason to believe this is a problem, contact the distributor of your hack or the hack author. If you continue to encounter problems, you will probably want to restore your file from a backup (particularly if there is a parse error or other unsightly problem that PHP reports) and wait to see if a fix is released. Also, feel free to use the support forums located at the various hack sites. They are there to help!
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

332 CHAPTER 11 MODIFYING PHPBB Caution When (Virtual web hosting)

Wednesday, October 24th, 2007

332 CHAPTER 11 MODIFYING PHPBB Caution When editing your phpBB files, make sure you use a plain text editor, and not something like Microsoft Word, which could damage your files. While Notepad is adequate for the job, for Windows users, something like EditPlus (shareware available from http://www.editplus.com, $30 registration) is better. EditPlus (and editors like it) is very handy for its color-coding abilities, which can help prevent a lot of common coding mistakes that simple editors such as Notepad can t point out to you. Making the Changes With the hack open on your desktop (in Notepad, EditPlus, or a similar text editor), start by navigating to the proper file in this case, viewtopic.php and following the instructions on where to insert code. The instructions are fairly straightforward. Look toward the end of the file to insert a large block of code. (For the sake of brevity, and acknowledging the changing nature of modifications, the code is not reprinted here.) After making the prescribed changes, save and close viewtopic.php. Next, open lang_main.php, which will reside under language/lang_english for our purposes. These language lines will contain two strings used by this hack. In this instance, you re looking for a comment marked That s All Folks at the very end of the file. Above that, you ll insert the language lines specified in the next section of the hack. In the version of the hack available at the time of this writing, two lines are specified. Note Feel free to substitute for other languages in which you have translations of phpBB. However, note that the text supplied with this particular hack is in English, so you will need to translate to your other desired language (or obtain a translation of the hack, if one is available). Finally, open the viewtopic_body.tpl template file, which will place the form on the bottom of the View Topic page. Chapter 12 will delve into the details of working with template files, but for now, you ll be editing just this one file. If you have multiple active templates, you will need to edit the viewtopic_body.tpl file for each additional template as well, in order for the feature to be properly enabled across all templates. Look for the line {S_TOPIC_ADMIN}, and insert the final line specified in the hack below it. Don t worry about the meaning of these lines right now; Chapter 12 will educate you on the available template variables. The final instruction is to save and close all files. Yes, that s right you re finished! Upload your changes to the server, open your board, and go view a topic (while logged in, of course). With any luck, you ll have a new Figure 11-2. The expected results of addition to your View Topic page, as illusinstalling the Quick Reply hack: a trated in Figure 11-2. Quick Reply box
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Adelphia web hosting - CHAPTER 11 MODIFYING PHPBB 331 You ll want

Tuesday, October 23rd, 2007

CHAPTER 11 MODIFYING PHPBB 331 You ll want to open the text file that came with the hack (in this case, it will be Quick Reply with Quote Mod.txt). This contains the steps for installing the hack. Figure 11-1 shows a Note- pad window with this hack open. Figure 11-1. The Quick Reply with Quote modification, opened in Notepad Note the format of this hack. Most hacks authored in the past few years will be presented in this same format, so each hack you install will look similar. The header is quite straightforward, giving the title of the hack, the author s name (usually with contact information as well), a description of what the hack does, the difficulty level along with the installation time, a list of files that need to be opened, and a list of files included. Make sure you heed the warning to back up your files! The next section of the file contains the main instructions: which files to open, what to search for, and what to do with the piece of modified code (whether to add it somewhere, replace a line, and so on).
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.