How to: Integrate Invision Power Board in Kohana (and possibly every other forum)
After integrating a blog in my Kohana install, I wanted a forum.
Many, if not all, websites that ‘integrate’ professional forum software such as PhpBB, vBulletin or Invision Power Board (IPB) by setting up a separate page or subdomain to host the new environment, and try to mimic their own website header in the header of the forum. This should give the feeling that the forum is just another page because the header is the same. However, I wanted a tight integration between Kohana and the forum software so I wanted to (again) integrate the forum into Kohana.
The result of the integration will look like this: (the example shows IPB integrated in a fixed-width website of mine)
Note that the board in the image has no styling whatsoever applied to it beyond the default skin.
Here’s a list of what we are going to do:
- install IPB installation
- configure installation
- create Kohana view
- create Kohana controller
- setup routing
- create custom Kohana router
Let’s start.
First, install IPB in a folder in your Kohana project folder, this should not be much of a problem. I installed it in a folder called ‘ipb’. By now, my Kohana project folder looks something like this:
- application
- system
- wordpress (the integrated WordPress installation)
- ipb (the to be integrated installation of IPB)
The installation has to be configured to work with Kohana, let’s do this now.
Proceed to the admin panel of your forum and do the following:
- disable gzipped compression in System Settings -> Server Settings
- enable the use of .htaccess using Apache Mod_Rewrite
The code
I have a Kohana view called ‘forum’ which is basically a copy of IPB’s index.php in a Kohana view. This view loads the IPB environment. It looks something like this:
<?php define( 'IPB_THIS_SCRIPT', 'public' ); require_once( './ipb/initdata.php' ); require_once( IPS_ROOT_PATH . 'sources/base/ipsRegistry.php' ); require_once( IPS_ROOT_PATH . 'sources/base/ipsController.php' ); ipsController::run(); //exit();
Note that the exit command was commented out because the Kohana environment should not be terminated after processing this view.
IPB has another built-in exit command that makes sure the environment unloads after each request that should be disabled. This exit command can be found in the following file: {ipb root directory}/admin/sources/classes/output/publicOutput.php at the end of function sendOutput() on line 2183. Just comment it out.
Now we should create a controller that accepts parameters and URIs and forwards them to the IPB environment. The following code is based on the controller we created when integrating WordPress with Kohana.
Here’s the controller:
<?php defined('SYSPATH') OR die('No direct access allowed.');
class Forum_Controller extends Page_Controller {
// laad IPB view
public function index()
{
// haal request op
$url = url::current(TRUE);
if (strpos($url, 'forum/public') !== FALSE)
{
$url = str_replace('forum/public', 'ipb/public', $url);
url::redirect($url);
}
// admin area
if (strpos($url, 'forum/admin') !== FALSE)
{
echo new View('forum');
exit;
}
Kohana::log('info', 'Forum request caught: ' . $url);
$this->template->content = new View('forum');
}
public function params($param1, $param2='', $param3='', $param4='', $param5='', $param6='')
{
$this->index();
}
}
Next, we need to route the forum requests to our controller. Append this to your routing configuration file:
$config['forum/([A-Za-z0-9-_\./=\?&,]+)'] = 'forum/params/$1';
Now, open the file conf_global.php in the IPB root directory and change the ‘board_url’ setting from the name of the name of the IPB root foler to the name of the forum controller, like this:
$INFO['board_url'] = 'http://localhost/forum';
There’s only one step left, which is a custom Router class.
Copy Kohana’s Router.php file from system/libraries/Router.php to application/libraries/MY_Router.php. Open the copied file and change the class declaration to this:
class Router extends Router_Core {
Find the following line:
Router::$current_uri = (string) substr(Router::$current_uri, $strpos_fc + strlen(KOHANA));
and modify the line to this:
if (strpos(Router::$current_uri, '/forum') !== 0)
{
Router::$current_uri = (string) substr(Router::$current_uri, $strpos_fc + strlen(KOHANA));
}
That’s it for the code!
The explanation
So, how does this little puzzle work? When loading the /forum page, the content of IPB’s index.php page inside your forum view loads the forum and renders it inside the view. Rendering the page at all succeeds because we turned off the gzip compression from within IPB. The admin area is rendered without the website template because we echo the view directly. Kohana’s page rendering process won’t get interrupted because we prevented IPB from terminating the PHP environment by disabling the exit statements. IPB ‘thinks’ it’s root folder is named ‘forum’ because we changed the ‘board_url’ option in IPB’s configuration. The consequence of this is that every forum url get’s routed through our forum controller. Our controller merely accepts the parameters, starts the forum software and renders the board. The forum software itself fetches the parameters from the url and generates the corresponding page. There was one problem though: other files such as javascript and css files were routed through the controller as well and were left to the View to figure out what to do with them, which wouldn’t work. Therefore, the controller had to do some routing on it’s own, so we rerouted every file to IPB’s ‘public’ folder (where the CSS files reside) and the ‘admin’ folder to the corresponding folders in our IPB installation directory instead of the view. So why did we need to customize Kohana’s Router? With clean urls enabled in Kohana, Kohana tries to remove the index.php from the url. However, Kohana screws up when the links generated by IPB contain an index.php by itself. The default behaviour performed by the Router was to route every IPB url that contained an index.php to the frontpage of your site, so we had to modify it to disable the removal of index.php from urls targeted at /forum.
That’s basically it. As you can see, the method is quite similar to the method we used to integrate WordPress in Kohana.

Nice job!
…but I wonder why you used Kohana PHP 2.xx instead of 3.xx
is there any reason to it?
Well, I’m building this website that I’ll launch in a few months, which needed a forum integration. However, when I started the project, 2.x was still the recommended version of Kohana to use.
This article something certainly worth reading. There are lots of websites that merely make no sense. Please keep up the good work and many more visitors will keep coming back.
Привет!
Я конечно, прошу прощения, но, по-моему, эта тема уже не актуальна.
Так бывает. Можем пообщаться на эту тему. Здесь или в PM.
смешные видео приколы смотреть бесплатно
[url=http://xn--c1aeb8eua.xn--p1ai/pics/26566-prikoly-v-obschestvennom-transporte-24-foto.html][img]http://xn--c1aeb8eua.xn--p1ai/uploads/girl/530.jpg[/img] [/url] [url=http://xn--c1aeb8eua.xn--p1ai/pics/26565-metallicheskie-skulptury-17-foto.html][img]http://xn--c1aeb8eua.xn--p1ai/uploads/girl/389.jpg[/img] [/url]
[url=http://xn--c1aeb8eua.xn--p1ai/pics/26564-udivitelnyy-vodopad-iguasu-16-foto.html]секс с невестой[/url] секс услуги [i]секс фото[/i]
[url=http://xn--c1aeb8eua.xn--p1ai/pics/26563-kreativnye-tufli-27-foto.html][img]http://xn--c1aeb8eua.xn--p1ai/uploads/girl2/309.jpg[/img] [/url] [url=http://xn--c1aeb8eua.xn--p1ai/pics/26562-neizvestnye-internet-terminy-9-kartinok.html][img]http://xn--c1aeb8eua.xn--p1ai/uploads/girl2/186.jpg[/img] [/url]
[url=http://xn--c1aeb8eua.xn--p1ai/pics/26561-umnyy-pes-5-foto.html]сексуальная[/url] [i]сексуальные девушки[/i] семейная эротика
[url=http://xn--c1aeb8eua.xn--p1ai/pics/26560-v-nuzhnyy-moment-chast-11-37-foto.html][img]http://xn--c1aeb8eua.xn--p1ai/uploads/girl/513.jpg[/img] [/url] [url=http://xn--c1aeb8eua.xn--p1ai/pics/26559-redkie-i-unikalnye-snimki-avgustovskogo-putcha-100-foto.html][img]http://xn--c1aeb8eua.xn--p1ai/uploads/girl/435.jpg[/img] [/url]
[url=http://xn--c1aeb8eua.xn--p1ai/pics/26558-ucelel-posle-draki-2-foto.html]сергей лазарев голый[/url] сессия картинки приколы [i]симс 2 переезд в квартиру[/i]
смешно [b]смешные видео приколы смотреть бесплатно[/b] смешные картинки
[i]смешные приколы[/i] смешные рассказы [b]смешные рисунки[/b]
эротические фото девушек [b]ню видео [/b] девушки плейбоя [b]секретарша секс [/b] смотреть смешные приколы