Error of BBCode in External Page

Discussion forum for MOD Writers regarding MOD Development.
Locked
Kenetix
Registered User
Posts: 10
Joined: Mon Aug 10, 2009 6:49 am

Error of BBCode in External Page

Post by Kenetix »

It says as it the subject I have a small error in bbcode when I visualize the news in an external page, here script that eh used

Code: Select all

<h1>&raquo; Noticias</h1>

<div align="justify">
<?php
//
// Configuration
//
$forum_id = 1;        //Forum ID to pull posts from
$num_posts = 7;        //Number of posts to display

//
// Auth
//
$can_read_forum = $auth->acl_getf('f_read');    //Get the forums the user can read from
$forum_id_ary = array_keys($can_read_forum);    //Rework the array some
unset($can_read_forum);

//
// Recent posts
//
if(array_key_exists($forum_id, $forum_id_ary))    //See if the user is authed to read from that forum
{
    $sql = 'SELECT p.post_id, t.topic_id, t.topic_replies, t.topic_views, p.post_subject, p.post_text, p.post_time, p.bbcode_bitfield, p.bbcode_uid, u.username
            FROM ' . TOPICS_TABLE . ' t 
                INNER JOIN ' . POSTS_TABLE . ' p ON (t.topic_id = p.topic_id)
                    INNER JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id)
                        WHERE t.topic_approved = 1
                            AND p.post_approved = 1
                            AND p.forum_id = ' . $forum_id . ' 
                            AND p.post_id = t.topic_first_post_id
                        ORDER BY p.post_time DESC';

    $result = $db->sql_query_limit($sql, $num_postsn);
    $row = $db->sql_fetchrowset($result);

    for($i = 0; $i < $num_posts; $i++)
    {
        $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&t=' . $row[$i]['topic_id'] . '&p=' . $row[$i]['post_id'] . 'p' . $row[$i]['post_id']);

//-----------------+
      $views = $row[$i]['topic_views'];
      $reply = $row[$i]['topic_replies'];
//-----------------+
        $uid = $bitfield = $options = '';
        $allow_bbcode = $allow_smilies = $allow_urls = true;
        $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);


        $message = generate_text_for_display($row[$i]['post_text'], $row[$i]['bbcode_uid'], $row[$i]['bbcode_bitfield'], $flags);
//        $reply = generate_text_for_display( $row[$i]['topic_replies'], $flags);

        echo '<div width="90%"><span class="titulo">&nbsp;&nbsp;' . censor_text($row[$i]['post_subject']) . '</span>
              <br><span class="subtitulo">&nbsp;&nbsp;Escrito por <b><u><span title="' . $row[$i]['username'] . '">' . $row[$i]['username'] . '</span></u></b> el ' . date('d/m/Y [G:i]', $row[$i]['post_time']) . '</span><br>
              <div class="contenido">' . $message . '</div><br>&nbsp;&nbsp;<a href="' . $post_url . '"  target=\"_blank\">Leer todo</a> | ' . $reply .' Comentarios | '. $views .' Visitas<br>
<hr size=1>
                </div>';
    }

    $db->sql_freeresult($result); 
}
?>
<p align="center"><a href="foros/viewforum.php?f=1" target="_blank">Ver Todas Las Noticias</a></p>      
</div>
but in specific bbcode that does not work to me he is the one of the osseous URL when I put the direct link if that goes but when I put for example

Code: Select all

[url=http://www.mywebsite.com]My website[/url] 
does not visualize the Link, because it gives that error?

User avatar
m157y
Registered User
Posts: 482
Joined: Mon Apr 30, 2007 9:39 am
Location: Russia, Moscow, Khimki
Contact:

Re: Error of BBCode in External Page

Post by m157y »

And why it must it shows? You don't called bbcode parser:

Code: Select all

$bbcode->bbcode_second_pass($message, $bbcode_uid, $bbcode_bitfield);
don't forget a checker

Code: Select all

if ($bbcode_bitfield) { // bbcode routine here }
also you need init your bbcode class

Code: Select all

$bbcode = new bbcode(base64_encode($bbcode_bitfield));
and finally, you forgot to include bbcode class

Code: Select all

include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
m157y aka Misty
NO SUPPORT VIA PM
KarmaMOD for phpBB 3.0.x | bbAJAX
Follow me on twitter

Kenetix
Registered User
Posts: 10
Joined: Mon Aug 10, 2009 6:49 am

Re: Error of BBCode in External Page

Post by Kenetix »

thanks for the reply, but where it is exactly where would have to modify?, in which line I must put what you have given me, pardon but my English is terrible since it is first you see that I request support in the official Web of phpbb

User avatar
m157y
Registered User
Posts: 482
Joined: Mon Apr 30, 2007 9:39 am
Location: Russia, Moscow, Khimki
Contact:

Re: Error of BBCode in External Page

Post by m157y »

Try this..

Code: Select all

<h1>&raquo; Noticias</h1>

<div align="justify">
<?php
//
// Configuration
//
$forum_id = 1;        //Forum ID to pull posts from
$num_posts = 7;        //Number of posts to display

//
// Auth
//
$can_read_forum = $auth->acl_getf('f_read');    //Get the forums the user can read from
$forum_id_ary = array_keys($can_read_forum);    //Rework the array some
unset($can_read_forum);

//
// BBCode
//
require_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);

//
// Recent posts
//
if(array_key_exists($forum_id, $forum_id_ary))    //See if the user is authed to read from that forum
{
    $sql = 'SELECT p.post_id, t.topic_id, t.topic_replies, t.topic_views, p.post_subject, p.post_text, p.post_time, p.bbcode_bitfield, p.bbcode_uid, u.username
            FROM ' . TOPICS_TABLE . ' t 
                INNER JOIN ' . POSTS_TABLE . ' p ON (t.topic_id = p.topic_id)
                    INNER JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id)
                        WHERE t.topic_approved = 1
                            AND p.post_approved = 1
                            AND p.forum_id = ' . $forum_id . ' 
                            AND p.post_id = t.topic_first_post_id
                        ORDER BY p.post_time DESC';

    $result = $db->sql_query_limit($sql, $num_posts);

    while ($row = $db->sql_fetchrow($result))
    {
        $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&t=' . $row['topic_id'] . '&p=' . $row['post_id'] . 'p' . $row['post_id']);

//-----------------+
      $views = $row['topic_views'];
      $reply = $row['topic_replies'];
//-----------------+
        $message = censor_text($row['post_text']);

        if ($row['bbcode_bitfield'])
        {
          $bbcode = new bbcode(base64_encode($row[$i]['bbcode_bitfield']));
          $bbcode->bbcode_second_pass($message, $row[$i]['bbcode_uid'], $row[$i]['bbcode_bitfield']);
        }

        $message = bbcode_nl2br($message);
        $message = smiley_text($message, !$config['allow_smilies']);

        echo '<div width="90%"><span class="titulo">&nbsp;&nbsp;' . censor_text($row['post_subject']) . '</span>
              <br><span class="subtitulo">&nbsp;&nbsp;Escrito por <b><u><span title="' . $row['username'] . '">' . $row['username'] . '</span></u></b> el ' . date('d/m/Y [G:i]', $row['post_time']) . '</span><br>
              <div class="contenido">' . $message . '</div><br>&nbsp;&nbsp;<a href="' . $post_url . '"  target=\"_blank\">Leer todo</a> | ' . $reply .' Comentarios | '. $views .' Visitas<br>
<hr size=1>
                </div>';
    }
}
?>
<p align="center"><a href="foros/viewforum.php?f=1" target="_blank">Ver Todas Las Noticias</a></p>      
</div>
I also deleted your for-loop, this while-statement will be faster and w/o error on empty result from db and also i fixed little typo $num_postsn to $num_posts.. and finally, i don't know which functions of phpbb you're included at this file, but if user's functions are here, parse date by this function:
$user->format_date($row['post_time'], 'd/m/Y [G:i]')
m157y aka Misty
NO SUPPORT VIA PM
KarmaMOD for phpBB 3.0.x | bbAJAX
Follow me on twitter

Kenetix
Registered User
Posts: 10
Joined: Mon Aug 10, 2009 6:49 am

Re: Error of BBCode in External Page

Post by Kenetix »

I do not work myself, seems does not explain to me well so better I add some images so that you see alo that I talk about

thus it leaves in the Web

Image

and I want thus that she sees herself just as the forum.

Image

and when I add the code that you left me, appears thus

Image

any idea?

Kenetix
Registered User
Posts: 10
Joined: Mon Aug 10, 2009 6:49 am

Re: Error of BBCode in External Page

Post by Kenetix »

Any idea people? than me it can be happening?

Kenetix
Registered User
Posts: 10
Joined: Mon Aug 10, 2009 6:49 am

Re: Error of BBCode in External Page

Post by Kenetix »

only bbcode that does not work to me is the one of the URL

Code: Select all

[url]http://www.website.com[/url]

Code: Select all

[url=http://www.website.com]website[/url]
Any Idea???

Locked

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