Extending phpBB3
January 27, 2009 at 2:36 pm | In Blog, Website Development | 4 CommentsTags: architecture, drupal, error, forum, php, phpbb, phpbb3, rss, template, website
Introduction
Following my dumping of drupal I had to go back to the drawing board in terms of managing the content for my homepage. I wanted to have my own stories and aggregated RSS feeds displayed, integrated into the phpBB forum on the site.
Armed with no knowledge of php but some of html, sql and general programming skills (I was a professional developer about 10 years ago) I decided to look into extending phpBB to be the architecture of my entire site! This idea was further encouraged by my analysis of the available image galleries that were available off the shelf (for free obviously I didn’t want to actually pay for anything).
Extending phpBB
It is possible to create a blank phpBB page very simply and because of phpBB’s templating system it’s really easy to setup pages with the same header, look and feel as the main site. And you get to take advantage of loads of cool phpBB features like user and session management, security, caching etc. In fact I soon came to realise that I could use it for Content Management as well…
To make a new page on your website that extends phpBB you do the following:
Create a new php file with the following content, the first bit sets it up as part of phpBB and so needs to know where the forum is. On my site the custom page as at the root of www.dirtmind.com and the forum lives in www.dirtmind.com/forum if you have a different structure you’ll have to edit the second proper line of code to tell if your PHPBB_ROOT_PATH.
<?php
/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ?
PHPBB_ROOT_PATH : './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session
$user->session_begin();
$auth->acl($user->data);
$user->setup();
page_header($user->lang['PAGE_TITLE']);
//Custom code goes here
//Tell phpBB which template to use for the output:
$template->set_filenames(array(
'body' => 'output_template.html'
));
page_footer();
?>
One of what I soon came to realise was one of the most common mistakes with doing this (and was my most common mistake) was to accidentally include blank lines before or after the tags this leads an error similar to:
[phpBB Debug] PHP Notice: in file /includes/session.php on line 990: Cannot modify header information - headers already sent by (output started at /includes/auth.php:1040)
So this php page doesn’t actually have any output or display stuff in it, it’s just doing functional things so here I could do my RSS processing or whatever. To link up the page to an ouput template you can see a line that maps “body” to “output_template.html” and this file lives in your forum templates directory which in my case would be “./forum/styles/mystyle/template/output_template.html“. Here’s what a very simple output template could look like:
<!-- INCLUDE overall_header.html --> <p>Your HTML goes here</p> <!-- INCLUDE overall_footer.html -->
That’s it! So now you’ve got a new page on your website that’s hooked into the phpBB system.
To see this in action just look at any page on DirtMind that isn’t part of the forum like the homepage
Conclusion
Even with no php knowledge it’s really easy to make pages of your website have the same look and feel as your forum, and the amount of functionality that phpBB provides means that it’s an excellent architecture for making a web app.
4 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.
[...] I looked at were ok, but didn’t integrate deeply into my site (which was now based on the phpBB architecture) so I set about (armed with no php skill but a bit of general programming skills) to write my [...]
Pingback by Creating an image gallery for phpBB « — January 27, 2009 #
[...] is then fed through into a phpbb3 HTML template in the normal way. Finally I wanted a “comment now” button or similar so that people [...]
Pingback by RSS Aggregation and Post to Forum links « — January 28, 2009 #
Hiya all of youz!..
How are yaz doing?
Comment by hoppiemochie — May 20, 2009 #
[...] requirements, sign in with twitter, twitter I’ve previously blogged about how I extended the architecture of phpbb3 to my entire website. This got me great advantages in terms of security, session management etc. [...]
Pingback by phpbb3 Sign in with twitter « — July 21, 2009 #