Table of Contents

Advanced Features

Information for power users to enhance your existing PunBB installation.

Syndication

This script extern.php is used to include information about your board from pages outside the forums and to syndicate news about recent discussions via RSS. The script can display a list of recent discussions (sorted by post time or last post time), a list of active users or a collection of general board statistics. The script can be called directly via an URL (for RSS), from a PHP include command or through the use of Server Side Includes (SSI).

The scripts behaviour is controlled via variables supplied in the URL to the script. The different variables are: action (what to output), show (how many topics to display), forum (the ID of the forum to poll for topics) and type (output as HTML or RSS). The only mandatory variable is action.

Possible/default values are

Here are some examples using PHP include()

Here are some examples using SSI

And finally some examples using extern.php to output an RSS 0.91 feed.

Website Integration

Integrating PunBB into your website code is easy if you know a little PHP. By including PunBB's script common.php, you gain access to all PunBB global variables such as $db and $pun_user. However, in order to include this file, you need to define a constant called PUN_ROOT. This constant should be set to the relative path to your PunBB forum directory. For example, if your website front page is located in /home/user/public_html/ and your forums are located in /home/user/public_html/forums/, your PUN_ROOT should be './forums/'. The PHP code to accomplish this could look something like this:

define('PUN_ROOT', './forums/');
require PUN_ROOT.'include/common.php';

Once you've included common.php, you can access and utilize all of PunBB's global variables and functions. Typically, you will be most interested in the $pun_user array. This array holds information about the current user. Another interesting variable is the database object $db. How to use these variables in your own script is out of the scope of this document, but here's a small example showing you how to print a simple message greeting the current user on your website front page:

Hello <php echo pun_htmlspecialchars($pun_user['username']); >!

In addition to defining PUN_ROOT, you can define a number of other constants to alter the behaviour of PunBB when including common.php. The two most interesting of these constants are PUN_TURN_OFF_MAINT and PUN_QUIET_VISIT. If PUN_TURN_OFF_MAINT is defined when including common.php, PunBB will not exit and display the maintenance message if the forums are placed into maintenance mode. You generally don't want this message to appear on your website front page, so defining that constant is a good idea. The other constant, PUN_QUIET_VISIT, prevents PunBB from updating the current user's last visit data in the database so that a visit to the front page doesn't count as a visit in the forums. This is also desirable behaviour in most cases. It doesn't matter what value you set these constants to, but setting them to a value of 1 is probably a good idea. Example:</p>

define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);

Please note that these constants must be defined before common.php is included.

Plugins

Admin plugins are modules for the PunBB admin interface that can be installed by simply dropping the plugin script in the plugins/ directory. See the example plugin for information on how to write your own plugin. Here are a few notes of interest for aspiring plugin authors: