BBCode Parsing for Non-In-phpBB3 outputs.

Discussion forum for MOD Writers regarding MOD Development.
Locked
NetoBochas
Registered User
Posts: 6
Joined: Thu Jul 05, 2007 6:16 pm

BBCode Parsing for Non-In-phpBB3 outputs.

Post by NetoBochas » Sat Apr 19, 2008 5:41 am

Hi, I've been working on a site, coded from scratch, and the time has come to call news from phpBB3's DB to the site.

Well... I managed to get the news on the site called from a specific forum on phpBB3, but the problems came when they contained BBCode. It was being returned unparsed...

So my question is: Is there a way to parse a string called from the phpBB3's posts table with the default and custom BBCodes?

This is the PHP code of the script that needs the parsing:

Code: Select all

<div class="cstyle">

<?php

// Conectando a la Base de Datos

$mode = ('remote');
include ('modules/mysql_connect.php');


// Configuracion de Salida

$target_forum = ('78');		//Foro Destino del Script

$results_count = ('5');		//Maximo de Resultados de la Base de Datos

$p_truncate_limit = ('1024');	//Limite para Truncar los Posts

$u_avatar_width = ('100');	//Ancho del Avatar del Autor
$u_avatar_height = ('100');	//Alto del Avatar del Autor


// Consultando a la Base de Datos para Obtener el Tema

$t_sql = ('SELECT * FROM phpbb3_topics WHERE forum_id = ' . $target_forum . ' ORDER BY topic_time DESC LIMIT 0,' . $results_count);

$t_result = mysql_query($t_sql);


// Enunciando Repeticiones

for($x=1;$x<=$results_count;$x++){

    // Creando Sucesion de Datos para el Tema

    $t_row = mysql_fetch_array($t_result);


    // Consultando a la Base de Datos una vez mas para Obtener el Post

    if ($t_row[topic_first_post_id]) {
      $p_sql = ('SELECT * FROM phpbb3_posts WHERE post_id = ' . $t_row[topic_first_post_id] . ' LIMIT 0,' . $results_count);

      $p_result = mysql_query($p_sql);

      $p_row = mysql_fetch_array($p_result);
    }


    // Consultando a la Base de Datos una vez mas para Obtener el Usuario Autor

    if ($t_row[topic_poster]) {
      $u_sql = ('SELECT * FROM phpbb3_users WHERE user_id = ' . $t_row[topic_poster] . ' LIMIT 0,' . $results_count);

      $u_result = mysql_query($u_sql);

      $u_row = mysql_fetch_array($u_result);
    }


    // Variables de Repeticion

    $trc_post_text = Truncate($p_row['post_text'], $p_truncate_limit);


    // Imprimiendo la Salida

    if ($t_row[topic_title]){

     echo <<<HTML
<div style="margin-bottom: 100px;">

<span class="bigtext">&raquo; $t_row[topic_title]</span>

<hr class="title">

<a href="http://www.zekaiforos.uni.cc/foro/memberlist.php?mode=viewprofile&u=$t_row[topic_poster]" target="_blank" title="Ir al Perfil de $u_row[username]">
<img src="$u_row[user_avatar]" style="float: left; margin: 6px 6px 6px 0px;" width="$u_avatar_width" height="$u_avatar_height" border="0">
</a>

<span class="normaltext">$trc_post_text</span>

<br><br>

<div style="float: right;">
<a class="cnlink" href="http://www.zekaiforos.uni.cc/foro/viewtopic.php?f=$target_forum&t=$t_row[topic_id]" target="_blank" title="Ultima respuesta por: $t_row[topic_last_poster_name]">Ver Comentarios ($t_row[topic_replies])</a>
</div>

</div>

HTML;

    }
}

?>

</div>
The string that returns the post and the unparsed BBCodes is $p_row['post_text'].


Thanks in Advance.

cheechm
Registered User
Posts: 69
Joined: Mon Jan 15, 2007 10:28 pm

Re: BBCode Parsing for Non-In-phpBB3 outputs.

Post by cheechm » Sat Apr 19, 2008 11:38 am

Code: Select all

    <div class="cstyle">

    <?php

    // Conectando a la Base de Datos

    $mode = ('remote');
    include ('modules/mysql_connect.php');


    // Configuracion de Salida

    $target_forum = ('78');      //Foro Destino del Script

    $results_count = ('5');      //Maximo de Resultados de la Base de Datos

    $p_truncate_limit = ('1024');   //Limite para Truncar los Posts

    $u_avatar_width = ('100');   //Ancho del Avatar del Autor
    $u_avatar_height = ('100');   //Alto del Avatar del Autor


    // Consultando a la Base de Datos para Obtener el Tema

    $t_sql = ('SELECT * FROM phpbb3_topics WHERE forum_id = ' . $target_forum . ' ORDER BY topic_time DESC LIMIT 0,' . $results_count);

    $t_result = mysql_query($t_sql);


    // Enunciando Repeticiones

    for($x=1;$x<=$results_count;$x++){

        // Creando Sucesion de Datos para el Tema

        $t_row = mysql_fetch_array($t_result);


        // Consultando a la Base de Datos una vez mas para Obtener el Post

        if ($t_row[topic_first_post_id]) {
          $p_sql = ('SELECT * FROM phpbb3_posts WHERE post_id = ' . $t_row[topic_first_post_id] . ' LIMIT 0,' . $results_count);

          $p_result = mysql_query($p_sql);

          $p_row = mysql_fetch_array($p_result);
        }


        // Consultando a la Base de Datos una vez mas para Obtener el Usuario Autor

        if ($t_row[topic_poster]) {
          $u_sql = ('SELECT * FROM phpbb3_users WHERE user_id = ' . $t_row[topic_poster] . ' LIMIT 0,' . $results_count);

          $u_result = mysql_query($u_sql);

          $u_row = mysql_fetch_array($u_result);
        }


        // Variables de Repeticion

        $trc_post_text = Truncate($p_row['post_text'], $p_truncate_limit);


$row['bbcode_options'] = (($row['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) +
    (($row['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + 
    (($row['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);
$generated_text = generate_text_for_display($trc_post_text, $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']);


        // Imprimiendo la Salida

        if ($t_row[topic_title]){

         echo <<<HTML
    <div style="margin-bottom: 100px;">

    <span class="bigtext">&raquo; $t_row[topic_title]</span>

    <hr class="title">

    <a href="http://www.zekaiforos.uni.cc/foro/memberlist.php?mode=viewprofile&u=$t_row[topic_poster]" target="_blank" title="Ir al Perfil de $u_row[username]">
    <img src="$u_row[user_avatar]" style="float: left; margin: 6px 6px 6px 0px;" width="$u_avatar_width" height="$u_avatar_height" border="0">
    </a>

    <span class="normaltext">$generated_text</span>

    <br><br>

    <div style="float: right;">
    <a class="cnlink" href="http://www.zekaiforos.uni.cc/foro/viewtopic.php?f=$target_forum&t=$t_row[topic_id]" target="_blank" title="Ultima respuesta por: $t_row[topic_last_poster_name]">Ver Comentarios ($t_row[topic_replies])</a>
    </div>

    </div>

    HTML;

        }
    }

    ?>

    </div>
<img src="$u_row[user_avatar]" style="float: left; margin: 6px 6px 6px 0px;" width="$u_avatar_width" height="$u_avatar_height" border="0">
</a>

NetoBochas
Registered User
Posts: 6
Joined: Thu Jul 05, 2007 6:16 pm

Re: BBCode Parsing for Non-In-phpBB3 outputs.

Post by NetoBochas » Sat Apr 19, 2008 2:21 pm

Ok, tried it, but it seems you forgot to call the needed functions in order for the parsing to work...


Regards.

Locked

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