BBcode on non phpbb standard pages

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
kouhi
Registered User
Posts: 71
Joined: Sun Jun 26, 2005 11:08 am

BBcode on non phpbb standard pages

Post by kouhi » Sat Mar 29, 2008 9:25 pm

I have recently created a very effective Customisable Journal System which works well with my Custom Profiles Modification. This topic is not a Modification request, but a php support request which fucuses on phpbb.

I have come to the need of having phpbb's BBcode to be implemented into the journals, but I have no idea of how to get the str_replace to pull the bbcode. Could someone please advise me of how to do this. I have both used an include and require version of the BBcode inc line but I can not understand the phpbb files when it comes to working out what code I need to use.

Any help would be appreciated.

User avatar
Jim_UK
Former Team Member
Posts: 18478
Joined: Tue Oct 12, 2004 5:36 pm
Location: Darwen N.West UK

Re: BBcode on non phpbb standard pages

Post by Jim_UK » Mon Mar 31, 2008 5:21 pm

I have moved your topic to Mod Writers Discussion as that would seem a more appropriate forum.

Jim
The truth is out there.
Unfortunately they will not let you anywhere near it!

kouhi
Registered User
Posts: 71
Joined: Sun Jun 26, 2005 11:08 am

Re: BBcode on non phpbb standard pages

Post by kouhi » Mon Mar 31, 2008 6:36 pm

Thanks,I hope someone will help me with this.

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: BBcode on non phpbb standard pages

Post by RMcGirr83 » Mon Mar 31, 2008 7:37 pm

Here is a function written by evil <3 which should help

Code: Select all

if (!function_exists('bbcode_parse'))
{
   /**
    * Parse BBCode to display a text
    *
    * @author eviL<3
    * @copyright 2006 - 2007 eviL<3
    * @version 1.0.3
    * @param string $message
    * @param int $bbcode_uid
    * @param bool $smilies
    * @param bool $make_clickable
    * @return string message
    */
    function bbcode_parse($message, $bbcode_uid = false, $smilies = true, $make_clickable = true)
    {
        global $phpbb_root_path, $phpEx, $userdata;

        include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);


        $bbcode_uid = (!$bbcode_uid) ? make_bbcode_uid() : $bbcode_uid;

        $message = bbencode_first_pass($message, $bbcode_uid);
        $message = bbencode_second_pass($message, $bbcode_uid);


        if ($smilies)
        {
           $message = smilies_pass($message);
        }

    	if ($make_clickable)
        {
           make_clickable($message);
        }

        $message = str_replace("\n", '<br />', $message);

        return $message;
    }
}
will parse bbcode as well as smilie code. Hope it helps. :)
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

kouhi
Registered User
Posts: 71
Joined: Sun Jun 26, 2005 11:08 am

Re: BBcode on non phpbb standard pages

Post by kouhi » Mon Mar 31, 2008 10:47 pm

Didnt work, unless I missplaced it. It is supposed to be part of the submit data or display data?

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: BBcode on non phpbb standard pages

Post by RMcGirr83 » Mon Mar 31, 2008 11:24 pm

Display data.

Code: Select all


$some_var = bbcode_parse($row['whatever']);
So your submit data can be something like

Code: Select all

This is just a [b]test[/b]
and test should then show as bold when parsed.
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

kouhi
Registered User
Posts: 71
Joined: Sun Jun 26, 2005 11:08 am

Re: BBcode on non phpbb standard pages

Post by kouhi » Tue Apr 01, 2008 6:36 pm

Fatal error: Call to undefined function bbcode_parse() in /home/anitaria/public_html/anitaria/journal.php on line 115

Even with require / include bbcode

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: BBcode on non phpbb standard pages

Post by RMcGirr83 » Tue Apr 01, 2008 6:45 pm

The function should be used in your php page...or placed in bbcode.php with an include to bbcode.php in your file.
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

kouhi
Registered User
Posts: 71
Joined: Sun Jun 26, 2005 11:08 am

Re: BBcode on non phpbb standard pages

Post by kouhi » Tue Apr 01, 2008 6:55 pm

well, the bbcode file is the standard phpbb one, here is the current file

header first

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
include($phpbb_root_path . 'includes/functions_post.'.$phpEx);
// Start session management
$userdata = session_pagestart($user_ip, PAGE_MODS, $board_config['session_length']);
init_userprefs($userdata);
// End session management
Part dealing with the input and output

Code: Select all

if(isset($_POST['submit']) || isset($HTTP_POST_VARS['entry']))
{
$entry = (isset($_POST['entry'])) ? $_POST['entry'] : '';
$message = (isset($_POST['content'])) ? $_POST['content'] : '';

if (!function_exists('bbcode_parse'))
{
   /**
    * Parse BBCode to display a text
    *
    * @author eviL<3
    * @copyright 2006 - 2007 eviL<3
    * @version 1.0.3
    * @param string $message
    * @param int $bbcode_uid
    * @param bool $smilies
    * @param bool $make_clickable
    * @return string message
    */
    function bbcode_parse($message, $bbcode_uid = false, $smilies = true, $make_clickable = true)
    {
        global $phpbb_root_path, $phpEx, $userdata;

        include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);


        $bbcode_uid = (!$bbcode_uid) ? make_bbcode_uid() : $bbcode_uid;

        $message = bbencode_first_pass($message, $bbcode_uid);
        $message = bbencode_second_pass($message, $bbcode_uid);


        if ($smilies)
        {
           $message = smilies_pass($message);
        }

       if ($make_clickable)
        {
           make_clickable($message);
        }

        $message = str_replace("\n", '<br />', $message);

        return $message;
    }
}
if ( $entry )
{$title = $entry;}
else
{$title = "No Entry title";}
$date = date("F j, Y, g:i a");

$sql = "INSERT INTO phpbb_blog 
				( blog_id, entry, content, date )
				VALUES ('$blog_id' ,'$title' ,'$message' ,'$date' )";
			$result = $db->sql_query($sql);
			if( !$result )
			{
				message_die(GENERAL_MESSAGE, 'Could not insert Entry');
			}
}

$sql = $db->sql_query("SELECT * FROM phpbb_blog
WHERE blog_id = '$blog_id' ORDER BY id DESC LIMIT 10");
if(!$sql)
{
message_die(GENERAL_ERROR, 'Could not select Journal Data');
}
$itemrow = $db->sql_fetchrowset($sql);
if ( $itemrow )
{
foreach($itemrow as $item)
{
$users_id = $userdata['user_id'];
$newitem =  $item['item_name'];
if ($userdata['user_id'] == $blog_id)
{
$deltxt = "Delete";
}
else
{
$deltxt = "";
}


$message = bbcode_parse($item['content']);
$template->assign_block_vars('itemrow', array(
'entry' => $item['entry'],
      'content' => $message,
      'date' => $item['date'],
      'delete' => $deltxt,
      'id' => $item['id']
)
);


}
I dont want to display the rest as it is mostly sensetive customisability data handling. Something I dont want to spread around untill is perfected, but that has no effect on the bbcode at all.

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: BBcode on non phpbb standard pages

Post by RMcGirr83 » Tue Apr 01, 2008 7:07 pm

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
include($phpbb_root_path . 'includes/functions_post.'.$phpEx);
// Start session management
$userdata = session_pagestart($user_ip, PAGE_MODS, $board_config['session_length']);
init_userprefs($userdata);
// End session management
// function block..we want to parse bbcodes
if (!function_exists('bbcode_parse'))
{
   /**
    * Parse BBCode to display a text
    *
    * @author eviL<3
    * @copyright 2006 - 2007 eviL<3
    * @version 1.0.3
    * @param string $message
    * @param int $bbcode_uid
    * @param bool $smilies
    * @param bool $make_clickable
    * @return string message
    */
    function bbcode_parse($message, $bbcode_uid = false, $smilies = true, $make_clickable = true)
    {

        $bbcode_uid = (!$bbcode_uid) ? make_bbcode_uid() : $bbcode_uid;

        $message = bbencode_first_pass($message, $bbcode_uid);
        $message = bbencode_second_pass($message, $bbcode_uid);


        if ($smilies)
        {
           $message = smilies_pass($message);
        }

       if ($make_clickable)
        {
           make_clickable($message);
        }

        $message = str_replace("\n", '<br />', $message);

        return $message;
    }
}
and for the displaying

Code: Select all

if(isset($_POST['submit']) || isset($HTTP_POST_VARS['entry']))
{
$entry = (isset($_POST['entry'])) ? $_POST['entry'] : '';
$message = (isset($_POST['content'])) ? $_POST['content'] : '';

if ( $entry )
{$title = $entry;}
else
{$title = "No Entry title";}
$date = date("F j, Y, g:i a");

$sql = "INSERT INTO phpbb_blog
            ( blog_id, entry, content, date )
            VALUES ('$blog_id' ,'$title' ,'$message' ,'$date' )";
         $result = $db->sql_query($sql);
         if( !$result )
         {
            message_die(GENERAL_MESSAGE, 'Could not insert Entry');
         }
}

$sql = $db->sql_query("SELECT * FROM phpbb_blog
WHERE blog_id = '$blog_id' ORDER BY id DESC LIMIT 10");
if(!$sql)
{
message_die(GENERAL_ERROR, 'Could not select Journal Data');
}
$itemrow = $db->sql_fetchrowset($sql);
if ( $itemrow )
{
foreach($itemrow as $item)
{
$users_id = $userdata['user_id'];
$newitem =  $item['item_name'];
if ($userdata['user_id'] == $blog_id)
{
$deltxt = "Delete";
}
else
{
$deltxt = "";
}


$message = bbcode_parse($item['content']);
$template->assign_block_vars('itemrow', array(
'entry' => $item['entry'],
      'content' => $message,
      'date' => $item['date'],
      'delete' => $deltxt,
      'id' => $item['id']
)
);


}
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

kouhi
Registered User
Posts: 71
Joined: Sun Jun 26, 2005 11:08 am

Re: BBcode on non phpbb standard pages

Post by kouhi » Wed Apr 02, 2008 7:04 pm

It works perfect, thanks!

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: BBcode on non phpbb standard pages

Post by RMcGirr83 » Wed Apr 02, 2008 8:14 pm

Good to hear...good luck!! :)
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

Post Reply

Return to “[2.0.x] MOD Writers Discussion”