Jump to content


PHPBB topic on index - [ Need Help ]


4 replies to this topic

#1 Download

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 29 April 2006 - 05:18 AM

Hii, i need some help.
I found this tutorial:
<?
#database info, or include a config.php file
$db_host = 'localhost'; #change to your host
$db_user = 'username'; #change to your user name
$db_password = 'password'; #change to your password
$db_name = 'database_name'; #change to your db name

mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());

/* To keep a forum secret (i.e. a mods only forum) find, AND t.forum_id != 1, and change 1 to the forums id (according to your database)
to select a specific forum (i.e. news forum), find AND t.forum_id != 1, and change it to t.forum_id = 1 (where 1 = the forums id) */
$result = mysql_query("SELECT DISTINCT t.topic_id, t.topic_title, t.topic_poster, t.topic_first_post_id, t.forum_id, t.topic_replies, u.user_id, u.username, s.post_id, s.post_text
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_posts_text s
WHERE p.topic_id = t.topic_id AND t.topic_poster = u.user_id AND t.topic_first_post_id = s.post_id AND t.forum_id != 1 AND u.user_id != -1
ORDER BY p.post_time desc LIMIT 10");

/* This function is used to limit the amount of text displayed, as well as replace any bbcode.
it also converts any new lines (enters/returns), to an acctual break for people to see
if you want bbcode displayed, remove the $text = preg_replace... line
ONLY KEEP IF YOU ARE GOING TO DISPLAY THE BODY TEXT OF A POST */
function text($text, $limit){
	$text = str_replace("\n", "<br>", $text);
	$text = preg_replace("#\[(.*?)\].*?\[/(.*?)\]#si", "<i>[bbcode]</i>", $text);
	if(strlen($text)>$limit){
		$text = substr($text, 0, $limit);
		$text = substr($text, 0, -(strlen(strrchr($text, ' '))))."...";
	}
	return $text;
}

while($r=mysql_fetch_array($result)){
/* Change 100, to the number of characters you want to show
you only need the following line if you kept the above function */
$text = text($r['post_text'], 100);

/* To change the display, edit this
also change both the <a> tags to the correct path to your forums, leave the part after /forum/ the same */
echo "<a href=/forum/viewtopic.php?t=".$r['topic_id']." target=_blank>".$r['topic_title']."</a><br>
by: <a href=/forum/profile.php?mode=viewprofile&u=".$r['user_id']." target=_blank>".$r['username']."</a><br>
$text
<div align=\"right\">Replies: ".$r['topic_replies']."</div>
<hr>";
}
?>

To add new topics on my index page from my website.
But there is a bug in it.
When i use this code, bbcode txt will be replaced by [bbcode] and no other text. Or it will be changed to something like this:
[b:c82d668aeb]TEST[/b:c82d668aeb]

I saw a treath like this before, right here.
But i have no idea what too do in the code that i'm using.

I don't want the replacment of [bbcode] txt or the [b:c82d668aeb] things.
I just want only txt.

I hope someone understands this,
And can help me !

Thx.

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 30 April 2006 - 11:15 AM

It's not a bug, it's expected behavior. But, since you're being so persistant, and i have a little bit of time finally, try changing the text function to this:
function text($text, $limit){
	$text = str_replace("\n", '<br>', $text);
	$text = preg_replace('#\[(.*?)\](.*?)\[/(.*?)\]#si', '\\2', $text);
	if(strlen($text) > $limit){
		$text = substr($text, 0, $limit);
		$text = substr($text, 0, -(strlen(strrchr($text, ' ')))).'...';
	}
	return $text;
}
I haven't tested it, but it should work for at least half the styles of BBcode that phpBB uses.

#3 Download

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 30 April 2006 - 01:13 PM

Ok, thx for this !
bold, italic, underline and color txt are changed to normal txt !
Thanks for this.

If you have more time maybe find something for the other bbcodes ?
Like, URL, size.. tags ??


Nyways !
Thx !

#4 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 30 April 2006 - 02:40 PM

i'm still interested in auto-parsing url's.... seems like nobody knows the answer

(eregi_* is obsolete)

#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 01 May 2006 - 04:51 PM

Coolaid, if you haven't already, please start a new thread if you want to ask a new question.

Also, Download, the flash bbcode mod is another reason why i simply removed bbcode altogether. If you want to correctly parse the remaning bbcode that isn't parsed out, then the thread i gave you is all the help i can provide (and this time, it would take more than a month to change that).

But either way, you're welcome.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users