bbcode not working in custom page

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Slayer00
Translator
Posts: 19
Joined: Tue Sep 17, 2013 1:09 pm

bbcode not working in custom page

Post by Slayer00 » Wed Dec 05, 2018 7:22 pm

I am trying to create a custom page which displays recent posts in X forum and been looking into these tutorials so far;

https://wiki.phpbb.com/Practical.Displa ... rnal_pages
https://wiki.phpbb.com/Tutorial.Parsing_text
https://wiki.phpbb.com/Template.assign_vars

Here is my progress so far;

Code: Select all

<?php
/*
* home.php 
* Description: example file for displaying latest posts and topics
* by battye (for phpBB.com MOD Team)
* September 29, 2009
*/

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewforum');

/* create_where_clauses( int[] gen_id, String type )
* This function outputs an SQL WHERE statement for use when grabbing 
* posts and topics */

function create_where_clauses($gen_id, $type)
{
global $db, $auth;

    $size_gen_id = sizeof($gen_id);

        switch($type)
        {
            case 'forum':
                $type = 'forum_id';
                break;
            case 'topic':
                $type = 'topic_id';
                break;
            default:
                trigger_error('No type defined');
        }

    // Set $out_where to nothing, this will be used of the gen_id
    // size is empty, in other words "grab from anywhere" with
    // no restrictions
    $out_where = '';

    if( $size_gen_id > 0 )
    {
    // Get a list of all forums the user has permissions to read
    $auth_f_read = array_keys($auth->acl_getf('f_read', true));

        if( $type == 'topic_id' )
        {
            $sql     = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
                        WHERE ' .  $db->sql_in_set('topic_id', $gen_id) . '
                        AND ' .  $db->sql_in_set('forum_id', $auth_f_read);

            $result     = $db->sql_query($sql);

                while( $row = $db->sql_fetchrow($result) )
                {
                        // Create an array with all acceptable topic ids
                        $topic_id_list[] = $row['topic_id'];
                }

            unset($gen_id);

            $gen_id = $topic_id_list;
            $size_gen_id = sizeof($gen_id);
        }

    $j = 0;    

        for( $i = 0; $i < $size_gen_id; $i++ )
        {
        $id_check = (int) $gen_id[$i];

            // If the type is topic, all checks have been made and the query can start to be built
            if( $type == 'topic_id' )
            {
                $out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
            }

            // If the type is forum, do the check to make sure the user has read permissions
            else if( $type == 'forum_id' && $auth->acl_get('f_read', $id_check) )
            {
                $out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
            }    

        $j++;
        }
    }

    if( $out_where == '' && $size_gen_id > 0 )
    {
        trigger_error('A list of topics/forums has not been created');
    }

    return $out_where;
}



$search_limit = 5;

    $forum_id = array(31);
    $forum_id_where = create_where_clauses($forum_id, 'forum');

    $topic_id = array(93);
    $topic_id_where = create_where_clauses($topic_id, 'topic');



$posts_ary = array(
'SELECT' => 'p.*, t.*',

'FROM' => array(
POSTS_TABLE => 'p',
),

'LEFT_JOIN' => array(
array(
'FROM' => array(TOPICS_TABLE => 't'),
'ON' => 't.topic_first_post_id = p.post_id'
)
),

'WHERE' => str_replace( array('WHERE ', 'forum_id'), array('', 't.forum_id'), $forum_id_where) . '
AND t.topic_status <> ' . ITEM_MOVED . '
AND t.topic_visibility = 1',

'ORDER_BY' => 'p.post_id DESC',
);

$posts = $db->sql_build_query('SELECT', $posts_ary);

$posts_result = $db->sql_query_limit($posts, $search_limit);

while ($posts_row = $db->sql_fetchrow($posts_result))
{
$topic_title = $posts_row['topic_title'];
$topic_author = get_username_string('full', $posts_row['topic_poster'], $posts_row['topic_first_poster_name'], $posts_row['topic_first_poster_colour']);
$topic_date = $user->format_date($posts_row['topic_time']);
$topic_link = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=" . $posts_row['topic_id']);

$post_text = nl2br($posts_row['post_text']);

$bbcode = new bbcode(base64_encode($bbcode_bitfield));
$bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']);

$post_text = smiley_text($post_text);

$template->assign_block_vars('announcements', array(
'TOPIC_TITLE' => censor_text($topic_title),
'TOPIC_AUTHOR' => $topic_author,
'TOPIC_DATE' => $topic_date,
'TOPIC_LINK' => $topic_link,
'POST_TEXT' => censor_text($post_text),
));
}
      
page_header('Uutiset');

    $template->set_filenames(array(
        'body' => 'THE-FILE-NAME.html'
    ));

    page_footer();

Code: Select all

<!-- INCLUDE overall_header.html -->

<h2>Uutiset</h2>

<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>

   <div class="content">
        <div>
         <!-- BEGIN announcements -->
         <h2>{announcements.TOPIC_TITLE}</h2>
            <p><i>Kirjoittanut {announcements.TOPIC_AUTHOR} - {announcements.TOPIC_DATE}</i></p>
            <p>{announcements.POST_TEXT}</p>
            <p><a href="{announcements.TOPIC_LINK}">Kommentointi</a></p>
            <hr>
        <!-- END announcements -->
        </div>

   </div>

   <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->
bbcodestriked.png
I can see that bbcode is mentioned in the PHP part but why isn't it loaded on the page itself?
Where have I made a mistake to disable bbcode?

User avatar
GanstaZ
Jr. Extension Validator
Posts: 636
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: bbcode not working in custom page

Post by GanstaZ » Wed Dec 05, 2018 8:39 pm

Well.. try to change this:

Code: Select all

$post_text = nl2br($posts_row['post_text']);

$bbcode = new bbcode(base64_encode($bbcode_bitfield));
$bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']);
To this and see how it goes:

Code: Select all

	$bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
	$post_text = generate_text_for_display($posts_row['post_text'], $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield'], $bbcode_options, true);
"When answer lies in the question,.. question becomes redundant!"

User avatar
warmweer
Registered User
Posts: 1447
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: bbcode not working in custom page

Post by warmweer » Wed Dec 05, 2018 8:51 pm

I may be completely wrong about this but the tutorials you linked to date long before phpBB 3.2 (look at the history) , so I doubt everything in there is still valid.

edit: GanstaZ beat me to it easily - I didn't even have the time to try and find out what could have changed :oops:
A bug is a feature that hasn't made it to the manual (yet)

User avatar
GanstaZ
Jr. Extension Validator
Posts: 636
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: bbcode not working in custom page

Post by GanstaZ » Wed Dec 05, 2018 8:57 pm

Even that code can be changed a little, but it works)
"When answer lies in the question,.. question becomes redundant!"

User avatar
3Di
Registered User
Posts: 13097
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: bbcode not working in custom page

Post by 3Di » Wed Dec 05, 2018 9:04 pm

\phpbb\textformatter\s9e\renderer $renderer

Code: Select all

		$censor = censor_text($posts_row['post_text']);
		$text = $this->renderer->render($censor);
'POST_TEXT' => $text,

Should do.
:game_die: The new Dice Roller extension for phpBB 3.2 is out! :game_die:

Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

Slayer00
Translator
Posts: 19
Joined: Tue Sep 17, 2013 1:09 pm

Re: bbcode not working in custom page

Post by Slayer00 » Wed Dec 05, 2018 10:15 pm

GanstaZ wrote:
Wed Dec 05, 2018 8:39 pm
Well.. try to change this:

Code: Select all

$post_text = nl2br($posts_row['post_text']);

$bbcode = new bbcode(base64_encode($bbcode_bitfield));
$bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']);
To this and see how it goes:

Code: Select all

	$bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
	$post_text = generate_text_for_display($posts_row['post_text'], $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield'], $bbcode_options, true);
Thank you!

That fixed the issue. All bbcode gets rendered correctly now.

User avatar
GanstaZ
Jr. Extension Validator
Posts: 636
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: bbcode not working in custom page

Post by GanstaZ » Wed Dec 05, 2018 11:06 pm

No problems.. Your welcome!)
"When answer lies in the question,.. question becomes redundant!"

User avatar
3Di
Registered User
Posts: 13097
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: bbcode not working in custom page

Post by 3Di » Thu Dec 06, 2018 11:12 pm

Why not simply use the s9e's renderer since 3.2 doesn't use bbcodeuid and what not?
There is also the replacement for smiley_text() btw but I don't remember I am using it nor the former one.

viewtopic.php?p=15145846#p15145846
:game_die: The new Dice Roller extension for phpBB 3.2 is out! :game_die:

Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
ViolaF
Registered User
Posts: 1422
Joined: Tue Aug 14, 2012 11:52 pm

Re: bbcode not working in custom page

Post by ViolaF » Fri Dec 07, 2018 9:58 pm

The people love "old-school" (whyever) :lol:

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 7 guests