Adding BBCode

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

Hmmm, yeah good idea using phpbb2, most of the work is already done that way :D

although.. getting an error

Fatal error: Call to a member function on a non-object in /data/hosted/Gappa/phpBB2/includes/bbcode.php on line 46

not sure if this means a problem with the bbcode.php or my file...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

define('IN_PHPBB', true);
/**
TODO: set $phpbb_root_path
*/
$phpbb_root_path = 'phpBB2/';

include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);

/**
might be you have to change this depending on your config-data
if you see the smilie image filenames instead of the images...
*/
$board_config['smilies_path'] = $phpbb_root_path . $board_config['smilies_path'];
did you copy all of this?
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

yeah the whole lot....
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

strange, I tested it here and it worked - but had only phpBB 2.0.4 at hand.
Which version do you use?
What happens if you put

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('mysql.trace_mode', true);
ini_set('display_errors', true);
?>
at the beginning of the main-script?
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

hmm yeah im using phpBB 2.0.4 aswell

with that extra bit you told me to include i get:

Fatal error: Call to a member function on a non-object in /data/hosted/Gappa/phpBB2/includes/bbcode.php on line 46

Warning: (null)(): 1 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query() in Unknown on line 0

hmmm?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:oops: I've tested without any bbcode within the posts displayed :oops:

Code: Select all

<?php
define('IN_PHPBB', true);
/**
   TODO: set $phpbb_root_path
*/
$phpbb_root_path = 'phpBB2/';

include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);

$forumId = 3;
$user_ip = '127.0.0.1';
/** calling init_userprefs will instantiate $template */
$userdata = session_pagestart($user_ip, $forumId);
init_userprefs($userdata);

/**
   might be you have to change this depending on your config-data
   if you see the smilie image filenames instead of the images...
*/
$board_config['smilies_path'] = $phpbb_root_path . $board_config['smilies_path'];


$query = 'SELECT topic_title, topic_id, FROM_UNIXTIME(topic_time,"%W the %D %M @ %r") AS Topic_Date, post_text, bbcode_uid, username FROM phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id JOIN phpbb_users WHERE forum_id='.$forumId.' AND topic_poster=user_id ORDER BY topic_time DESC';
$result = $db->sql_query($query);

?>
<html>
   <head>
      <style tye="text/css">
         body { background-color: #333333; }
      </style>
   </head>
   <body>
<?php   
while($row = $db->sql_fetchrow($result))
{
   // this field is in <prefix_>posts, I'm skipping it for now and enable all smilies
   $row['enable_smilies'] = true;
   // enable_bbcode (always true) and enable_html (always false) are ignored as well

   $row['post_text'] = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $row['post_text']);   
   if ( isset($row['bbcode_uid']) && $row['bbcode_uid'] != '' )
      $row['post_text'] = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($row['post_text'], $row['bbcode_uid']) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $row['post_text']);
   if ($row['enable_smilies'])
      $row['post_text'] = smilies_pass($row['post_text']);
?>
   <b>
      <FONT FACE="Arial" SIZE="-1" COLOR="#FF9900">
         <?php echo $row['topic_title']; ?>
      </FONT>
   </b>
   <br />
   <FONT FACE="Arial" SIZE="-2" COLOR="#999999">
      posted by: <b><?php echo $row['username']; ?></b>
      on:   <?php echo $row['Topic_Date']; ?>
   </FONT>
   <br /><hr /><br />
   <FONT FACE="Arial" SIZE="-1" COLOR="#FFFFFF"><?php echo $row['post_text']; ?></FONT>
   <br /><br />
   <FONT FACE="Arial" SIZE="-2">
      <a href="http://www.hostultra.com/~Gappa/phpBB2/viewtopic.php?t=<?php echo $row['topic_id']; ?>">
         <b><FONT COLOR="#FF9900">Read comments</FONT></b>
      </a>
   </FONT>
   <br /><br /><br />
<?php
}
?>
   </body>
</html>
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

Ahhh yeah working great :) , even the smiles ! more than what i wanted THANKS! :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

in fact the previous version only processed smilies ;)
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

ahhh hehe ok :)... now all i need to to is get line breaks to work and try get it into flash then yay! :D
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

good luck ;)
Post Reply