PDA

View Full Version : Problem with parsing BB codes in custom script


matkus
01-07-2009, 02:37 PM
Hello.
I'm trying to write custom script, that will read news from forum. I've used code, that used to work ling time ago for me, but it does not now, and i don't know why. Heres the code:

chdir('./forum');
require_once('./global.php');
require_once('./includes/class_bbcode.php');
chdir('./..');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
require_once('config.php');
require_once('common.php');
$db2=new class_db($config['forum_sql_host'],$config['forum_sql_user'],$config['forum_sql_pass'],$config['forum_sql_db']);

function parse_bb($tresc, $par1, $par2, $par3, $par4)
{
global $bbcode_parser;
$wynik=$bbcode_parser->do_parse($tresc, $par1, $par2, $par3, $par4,true,false);
$wynik=str_replace ('<img src="images/smilies/','<img src="http://forum.tibiaspy.com/images/smilies/',$wynik);
return $wynik;
}

function forum_read_news($dzial,$ilosc,$szablon="news",$separator='', $sort_order='threadid DESC')
{
global $config, $forum_path,$news,$db2,$tpl;
$query="SELECT threadid,title,postusername FROM ".$config['forum_tableprefix']."thread WHERE forumid=$dzial ORDER BY $sort_order LIMIT $ilosc";
$lista_q=$db2->query($query);
$wynik='';
while ($temat=mysql_fetch_array($lista_q))
{
$psql = $db2->query("SELECT pagetext , dateline FROM ".$config['forum_tableprefix']."post WHERE threadid=".$temat['threadid']." ORDER BY postid ASC LIMIT 1");
$post=mysql_fetch_array($psql);

$news['pagetext']=parse_bb($post['pagetext'], true, true, true, true);
$news['title'] = $temat['title'];
$news['threadid'] = $temat['threadid'];
$news['postusername'] =$temat['postusername'];
$news['date']=date ("d.m.y H:i" ,$post['dateline']);
$wynik1=$tpl->loadtpl($szablon);
if ($wynik!=''){$wynik.=$separator;};
$wynik.=$wynik1;
}
return $wynik;
}

$db2 and $tpl are my own classes for database and templates.
When i call forum_read_news function, it have strange effects.
It parses correctly bbcodes, that are in handled by plugins.
Sometimes it also handles default bbcides, but not always, usualy it leaves most bb unparsed (like lists, [B], [URL] etc).

Sorry, that some variable names are in polish, it's easier for me like this, but if it will be problem, i can change it in code aboce.

Can someone tell me whan am i doing wrong?

I'm using 3.8 beta 2 for testing. may it be some bug with it? But in forum everything is parsed correctly, so I don't think it's forum problem.



[Edit]
Ok, one thinkg i've found - In this function, if i read more than 1 news, only 1st is parsed, 2nd and more are not. What did i do wrong???


[edit2] OK, sorry. Problem solved. I've used now $bbcode_parser->parse($tresc) insted of $bbcode_parser->do_parse($tresc), and it works. But i'm sure do_parse worked fine some time ago in some older vB version.

Dismounted
01-08-2009, 02:19 AM
You should not run any do_* methods directly (in vBulletin, at least). Another method will use the do_ method after doing checks and minor processing. It is that "other" method you should use.