PDA

View Full Version : VBCode outside of vbulletin


RGSerge
10-01-2003, 09:38 AM
I am writing a news page for my website, it collects topics from a news forum and displays them on the homepage.

This works fine, except for one issue. If our news editors use vbcode, it doesnt parse (this is not using a portal and does not include any vb files, its all done via making queries to vb's database).

Question is, how would I be able to parse the vbcode if its entered. This is totally standalone to the vbulletin, and for efficiency reasons I dont want to start integrating with vb core files.

Help here would be greatly appreciated. Heres the function (un-optimised at this time)

global $db_name;

// Get the news articles from the database
$news_array = mysql_query("select * from $db_forum.vb3_thread where forumid = '5' order by threadid DESC LIMIT 15");

if (mysql_num_rows($news_array) > 0)
{
while($news = mysql_fetch_array($news_array))
{

// Assign the data into variables
$article_name = $news['title'];
$article_poster = $news['postusername'];
$poster_id = $news['postuserid'];
$threadid = $news['threadid'];
$comments = $news['replycount'];
$views = $news['views'];

// Sore the language to be used (singular or plural)
$personorpeople = $views == 1 ? 'person' : 'people';
$hasorhave = $views == 1 ? 'has' : 'have';

// Get the article content from the database
$post_array = mysql_query("select * from $db_forum.vb3_post where threadid = '$threadid' order by postid ASC LIMIT 1");

if (mysql_num_rows($post_array) > 0)
{
while($posts = mysql_fetch_array($post_array))
{
$article_body = $posts['pagetext'];
$article_date = $posts['dateline'];
$article_date = getdate($article_date);


$month = $article_date['month'];
$day = $article_date['mday'];
$year = $article_date['year'];
$hour = $article_date['hours'];
$minute = $article_date['minutes'];

$article_date = "$month $day, $year";
$article_body = nl2br($article_body);

$content.=<<<end_cont
<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td bgcolor="#828282">
<table width="100%" cellspacing="1" cellpadding="2" border="0">
<tr bgcolor="#3A3A3A"><td class="table_heading"><b>$article_date - $article_name</b></td></tr>
<tr bgcolor="#525252">
<td class="table_content">
$article_body
<br /><br />
<hr>
There $hasorhave been $comments comments to this article<br />
$views $personorpeople have viewed the complete article<br />
<a href="http://forums.rgamers.com/showthread.php?t=$threadid">Click Here to view the complete article</a>
</td>
</tr>
</table>
</td></tr></table>
end_cont;

}
}
}
}

return $content;


Thats how it does it, but I need to add the ability to parse smileys and vbcode etc. Anyone know how?

* Smileys is not top priority, vbcode however is.


Thanks for any help on this one.

Xenon
10-01-2003, 05:09 PM
well, you ahve to require global.php of vb and then use bbcodeparse2 function.

RGSerge
10-01-2003, 06:14 PM
Is that function portable, as in, could I life it from global.php and copy it into the main site source and it work (with slight code modification of the function for obvious reasons) i.e. variables and the likes, or would that be a complete pain?

assassingod
10-01-2003, 06:24 PM
The code looks like it's for vB3 :confused:
(Technically vB3 hacking isn't allowed, but since this isn't edited any vB3 files, i'll go ahead and post it)

Use this code in your while loop


$article_body= parse_bbcode($posts['pagetext']);


But if it's for vB2, use:

$article_body=censortext(bbcodeparse($posts[pagetext],0,1));

Xenon
10-02-2003, 11:03 PM
Is that function portable, as in, could I life it from global.php and copy it into the main site source and it work (with slight code modification of the function for obvious reasons) i.e. variables and the likes, or would that be a complete pain?
well, as the bbcode is stored into the database, and bbcodeparse2 also uses some vb variables, it would be really hard to make it stand alone.

of course it would be possible, but it would be much easier to require global.php :)