MyBB Community Forums

Full Version: Post Parse
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a script that runs outside the forum which gets the most recent news post (in the news forum) and displays it on the homepage.

How do I get it to parse the bbcode correctly?
Well you could load up functions_post.php and do postify($text); or you could do this..

bb_code($text);

function bb_code(&$string) {
	$pattern = array('#\[list\](.*?)\[\/list\]#si','#\[\*\](.*?)(\r\n|\r|\n|<br>|<br />|<br/>)#si','#\[url\](.*?)\[\/(url)\]#si',
		'#\[url=(&quot;|"|\'|)(.*?)\\1\](.*?)\[\/url\]#si','#\[u\](.*?)\[/u\]#si','#\[i\](.*?)\[/i\]#si',
		'#\[b\](.*?)\[/b\]#si','#\[img\](.*?)\[\/img\]#si','#\[size=(&quot;|"|\'|)([0-9\+\-]+)\\1\](.*?)\[\/size\]#si','#(\r|\n|\r\n)#si');

	$replacement = array("\t\t<ul>$1</ul>\r\n","\t\t\t<li>$1</li>\r\n",'<a href="$1">$1</a>','<a href="$2">$3</a>',
		'<u>$1</u>','<em>$1</em>','<strong>$1</strong>','<img src="$1" title="User Posted Image" />','<font size="\2">\3</font>',"<br />");

	$string = preg_replace($pattern, $replacement, stripslashes($string));
	$string = str_replace('<br /><br />', "<p>\r\n\t\t</p>", $string);
}
however, it is only an small script, not fully compatible with everything.
Ok, I did the first "postify($text)" thing, but the default browser font is used. Do you have any idea how to get it so that it selects the theme of the forum?
Then you would need to load the css file from the forum.
and check how it is done in the templates for showthreads. Which css class it uses and so on.