Skip to content

NBBC Library Wrapper

Derek Jones edited this page Jul 4, 2012 · 4 revisions

Category:Helper::Text

This is the method I used to incorporate the NBBC BB code library into my CI forum.

First, I packaged the http://nbbc.sourceforge.net/ into a library in my application. I was cheating, and just copied and pasted the contents, and as such had to name the library "bbcode".

Here are the steps I followed:

[b]1. Download the package from http://nbbc.sourceforge.net/[/b] [b]2. Decompress it. Copy and rename the file nbbc.php to bbcode.php and move it into your 'application/libraries' folder[/b] [b]3. Move 'smileys' folder somewhere public on your webserver[/b] [b]4. In your configuration file, you will need something like those as follows:[/b]

/*
|--------------------------------------------------------------------------
| BBCode Smiley Paths
|--------------------------------------------------------------------------
|
| Directory and URL paths to smileys. Full paths without trailing slashes.
|
*/
$config['bbcode_smiley_dir'] = '/path/to/smileys';
$config['bbcode_smiley_url'] = 'http://example.com/images/smileys';

/*
|--------------------------------------------------------------------------
| BBCode Smiley Paths
|--------------------------------------------------------------------------
|
| Directory and URL paths to smileys. Full paths without trailing slashes.
|
*/
$config['bbcode_url_detection'] = TRUE;

[b]5. Then, in your controller, you'll need the following lines for setting the library up (I use it in the constructor of my forum controllers)[/b]

        $this->load->library('bbcode');
        
        $this->bbcode->SetSmileyDir( $this->config->item('bbcode_smiley_dir') );
        $this->bbcode->SetSmileyURL( $this->config->item('bbcode_smiley_url') );
        $this->bbcode->SetDetectURLs( $this->config->item('bbcode_url_detection') );
        $this->bbcode->SetAllowAmpersand(true);

[b]6. Finally, you can then call the bbcode parser on content:[/b]

$messagehtml = $this->bbcode->Parse($message);

[b]Final thoughts[/b]

It would be possible to change the smiley images for those of your own, or even provide a switch between smiley folders. Potentially, you could even map the library to use CI's built in smiley system.

The library is a large and powerful one, probably bigger than most forums need. I would suggest that you also look at the library written by a contributor BBCode_Helper at CI first. If you do stick with NBBC, there is a good documentation set for it included in the download and at http://nbbc.sourceforge.net/readme.php.

Clone this wiki locally