Part of the EllisLab Network
x
 
Create New Page
 View Previous Changes    ( Last updated by kurucu )

NBBC Library Wrapper

Category:Helper -> Text

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

First, I packaged the NBBC library 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:

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

/*
|--------------------------------------------------------------------------
| 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

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)

$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); 

6. Finally, you can then call the bbcode parser on content:

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

Final thoughts

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 here 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.

Categories: