How to use Invision’s BBCode

Using Invision’s BBCode isn’t straight forward. Chances are that you need to invoke the BBCode parser if you want to create a plugin or hook for Invision Powered Board. Here’s the rough code to do so, with $topics being the array containing all the topics from the database to be parsed:

<?php

$classToLoadComposite = IPSLib::loadLibrary( IPS_ROOT_PATH . "sources/classes/editor/composite.php", "classes_editor_composite" );
$editor = new $classToLoadComposite();
#$editor->setAllowHtml( 1 );
//-----------------------------------------
// Return the data
//-----------------------------------------
foreach ($topics as &$topic) {
    $topic["formattedPost"] = $editor->process($topic["post"]);
    IPSText::getTextClass("bbcode")->parsing_section = "topics";
    IPSText::getTextClass("bbcode")->parse_smilies = TRUE;
    IPSText::getTextClass("bbcode")->parse_bbcode = TRUE;
    IPSText::getTextClass("bbcode")->parse_html = FALSE;
    IPSText::getTextClass("bbcode")->parse_nl2br = TRUE;
    IPSText::getTextClass("bbcode")->bypass_badwords = FALSE;
    $topic["formattedPost"] = IPSText::getTextClass("bbcode")->preDisplayParse( $topic["formattedPost"] );
}
?>

For the parsing_section, you should put a value that corresponds to the editor section. In my case, I need it to ‘topics’. To get the full list, you may need to look up Invision Powered Board’s source code which I cannot provide.

I wrote this down more as a personal note and I hope it benefits you as it did for me. If you have any questions, feel free to post and I can attempt answering.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>