XF 2.1 Parse post's BBCode on a separate PHP page

Edman

Member
I'm looking to display Xenforo posts as news comments on my site.

I can get posts, usernames, avatars, but I also want to use XF to parse the BBCode for the posts.

I know you can parse HTML into BBCode by doing this

Code:
$message = \XF\Html\Renderer\BbCode::renderFromHtml( nl2br( $message ) );

Is there a reverse function?
 
Hi Edman,

I don't know if there is better way to do this, but I was looking for a similar solution and just came up with the following solution that it will actually help me. Perhaps it gives an idea to you as well.

Note: Make sure setting up $dir to point your forum folder.

PHP:
$dir = __DIR__ . '/forum';
require($dir . '/src/XF.php');

XF::start($dir);

$bbCode = '[list=1][*]line1 [*]line2[/list]';

$htmlCode = \XF::app()->templater()->fn('bb_code', [ $bbCode, null, 'escaped'] );

print $htmlCode;
 
Thanks!

In the end, I decided to do my own BBCode parsing without calling XenForo. It was taking too long to figure out and I had already written a BBCode parser class for a different project.
 
Oh, sure.

Actually I was almost about to give up and do the same, but I found your message and thought that I am not alone. Which ended up good this time, so I wanted to share just in case.

Thanks for posting this question in the first place!
 
Back
Top Bottom