PhpBB3 : afficher les derniers messges du forum sur son site (solution inside)

WRInaute accro
Bonjour,

J'ai longtemps cherché l'équivalent de ce qui existait pour phpBB2 : topics anywhere pour afficher les derniers messages du forum n'importe où. Il n'existe plus pour phpbb3 et du coup je me sentais perdu :(
Après recherche, j'ai trouvé ceci qui devrait bien dépanner ceux qui cherchent la solution : afficher les derniers messages d'un forum phpbb3 sur son site

Par contre ça génère des URL non rewritée. Si quelqu'un sait comment injecter le nom des topcis qu'il le dise!

Bonne journée
 
WRInaute passionné
pour faire la même chose avec les url rewritées il suffit de parser un des flux RSS du forum. je ne sais pas si c'est très élégant mais ça fonctionne très bien!
 
WRInaute passionné
Ayant déjà eu le même problème j'ai réussi à trouver des scripts sur le web que j'ai adapté un peu pour mon forum :)

tu peux mettre le code ci-dessous dans un fichier nommé topics_anywhere.php à la racine de ton forum phpbb3 pour rester compatible avec ton code actuel.

voici le code (à adapter bien sure ):
Code:
<?
header("Content-type: text/xml; charset=utf-8");
?>
<channel>
<title></title>
<link></link>
<description>Votre portail sur Le maroc Oriental</description>
<language>fr</language>
<lastBuildDate><?echo date("r")?></lastBuildDate>
<pubDate><?echo date("r")?></pubDate>
<copyright></copyright>
<?php

define('IN_SITE', true);
define('IN_PHPBB', true);
$phpbb_root_path =  './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
 
// Sélection des 15 derniers posts
$sql = "SELECT t.topic_replies_real,t.topic_replies,t.topic_title,t.forum_id,t.topic_id,t.topic_type,t.topic_last_post_id,f.forum_name,t.topic_last_poster_name, t.topic_last_post_time
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
WHERE t.topic_approved = 1 
AND t.topic_status <> 2
AND t.forum_id = f.forum_id 
ORDER BY t.topic_last_post_time DESC 
LIMIT 15";
$result = $db->sql_query($sql);

// Boucle d'affichage du post
while($topic_data = $db->sql_fetchrow($result)) 
{
    // Données du topic
    $topic_title = $topic_data['topic_title'];
    $topic_replies = $topic_data['topic_replies'];
    $topic_replies_real = $topic_data['topic_replies_real'];
    $forum_id = $topic_data['forum_id'];
    $topic_id = $topic_data['topic_id'];
    $tid = $topic_data['topic_id'];
    $forum_name = $topic_data['forum_name'];
    $topic_last_post_id = $topic_data['topic_last_post_id'];
    $topic_last_post_time = date("d/m/Y", $topic_data['topic_last_post_time']);
    $topic_last_poster_name = $topic_data['topic_last_poster_name'];
       $replies = ($auth->acl_get('m_approve', $forum_id)) ? $topic_replies_real : $topic_replies; 
    $start = floor(($replies) / $config['posts_per_page']) * $config['posts_per_page']; 
    
    // www.phpBB-SEO.com SEO TOOLKIT BEGIN
    if ( empty($phpbb_seo->seo_url['topic'][$topic_id]) ) {
      if ($line[$i]['topic_type'] == POST_GLOBAL) {
         $phpbb_seo->seo_opt['topic_type'][$topic_id] = POST_GLOBAL;
      }
      $phpbb_seo->seo_censored[$topic_id] = $topic_title;
      $phpbb_seo->seo_url['topic'][$topic_id] = $phpbb_seo->format_url($phpbb_seo->seo_censored[$topic_id]);
    }
    if ( empty($phpbb_seo->seo_url['forum'][$forum_id]) ) {
      $phpbb_seo->seo_url['forum'][$forum_id] = $phpbb_seo->set_url($line[$i]['forum_name'], $forum_id, $phpbb_seo->seo_static['forum']);
    }
    // www.phpBB-SEO.com SEO TOOLKIT END 
   
    $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id . '&amp;f=' . $forum_id . '&amp;start=' . $start ) . '#p' . $topic_last_post_id; 
    $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id . '&amp;f=' . $forum_id ); 
    $topic_url = str_replace('.html', '-t'.$tid.'.html', $topic_url); 
?>
<item>
<title><?echo $topic_title?></title>

<link><?echo $topic_url?></link>
<description><?echo $topic_last_poster_name?>, <?echo $topic_last_post_time?> - <?echo $topic_replies?> Réponses</description>
</item>
<?
}
$db->sql_freeresult($result);

?>
</channel>


comme tu peux remarquer, tout est en dur, contrairement à topics_anywhere de phpBB2, mais c'est facilement modifiable pour prendre en compte des paramètres ;)
 
WRInaute accro
Non seulement cela fonctionne très bien, mais le fait qu'il y ait un flux par forum (comprendre: catégories) permet de répartir les flux des sujets à différents endroits d'une même page (hompage thématqiue par exemple) ou d'un site.

C'est très très efficace !
 
WRInaute accro
Exact, très intéressant mais deux soucis : mon flux ne propose pas les URL réécrites, et... Je ne sais pas comment afficher un flux sur mon site :mrgreen:
 
WRInaute passionné
le code que j'ai posté genère des URL compatibles phpBB SEO avec rewrite activé, mais tu peux toujours utiliser les variables au début du script comme bon te semble pour générer n'importequelle URL.

tu peux même utiliser le même script pour generer de l'html directement si tu ne sais pas integrer un flux RSS.
 
WRInaute passionné
sinon tu as une autre solution:

- créer un fichier last.php, à placer à la racine du domaine

Code:
   <?php
define('IN_PHPBB', TRUE);

// ici on définit le répertoire du forum si ce dernier est en répertoire
$phpbb_root_path = './repertoire-du-forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);


// Start session management



$sql = "SELECT topic_id, forum_id, topic_title, topic_type FROM " . TOPICS_TABLE . " where forum_id != 1 AND topic_approved = 1 ORDER BY  topic_last_post_time  DESC limit 10";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{     
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
         if ($row['topic_type'] == POST_GLOBAL) {
            $phpbb_seo->seo_opt['topic_type'][$row['topic_id']] = POST_GLOBAL;
         }
         if ( empty($phpbb_seo->seo_url['topic'][$row['topic_id']]) ) {
            $phpbb_seo->seo_url['topic'][$row['topic_id']] = $phpbb_seo->format_url($row['topic_title']);
         }
echo '<a href="'.append_sid($phpbb_root_path . 'viewtopic.php?f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']).'"   >' . $row['topic_title'] . "</a><br />";
         // www.phpBB-SEO.com SEO TOOLKIT END
}


?>

ensuite il suffit de faire un include de ce fichier last.php

Code:
<?php include('http://www.ton-domaine.fr/last.php'); ?>

à l'endroit où tu veux afficher les x derniers topics (les 10 derniers dans cet exemple). pareil, je ne sais pas si c'est élégant mais ça fonctionne très bien avec phpbb3 + mod rewrite avancé
 
WRInaute occasionnel
Sur ton forum création du fichier derniers-sujets.php placé ici en http://example.com/forum/derniers-sujets.php

Code:
<?php 
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);

// Sélection des 5 derniers posts 
$sql = "SELECT phpbb_topics.topic_id, phpbb_topics.topic_title, phpbb_posts.post_text, phpbb_posts.post_time, phpbb_posts.poster_id, phpbb_posts.post_username, phpbb_users.username 

FROM phpbb_topics, phpbb_posts, phpbb_users 

WHERE phpbb_posts.post_id = phpbb_topics.topic_first_post_id 
AND phpbb_users.user_id = phpbb_topics.topic_poster 
GROUP BY phpbb_topics.topic_id 
ORDER BY phpbb_topics.topic_id DESC 
LIMIT 5"; 
  
$req = mysql_query($sql) or die(mysql_error()); 
echo "<div class=\"forum\"><h2>Les 5 derniers sujets de TON FORUM sont :</h2>";

// Boucle d'affichage du post 
while($db_data = mysql_fetch_assoc($req)) { 

// Titre du post 
$post_title = "<a href=\"http://example.com/forum/". $phpbb_seo->format_url($db_data['topic_title']) . $phpbb_seo->seo_delim['topic'] . $db_data['topic_id'] . $phpbb_seo->seo_ext['topic'] ."\" target=\"_blank\">" . htmlentities(utf8_decode($db_data['topic_title'])) . "</a>"; 

// Extrait du post 
$post = $db_data['post_text']; 
$max_caracteres = 260; 
if (strlen($post)>$max_caracteres) { 
   $max_caracteres=strrpos(substr($post, 0, $max_caracteres), " "); 
   $post = substr($post, 0, $max_caracteres); 
   $post .= " (...)"; 
} 
     
$post = preg_replace("(\[.*\])U","",$post ); 
$post = htmlentities(utf8_decode($post));
$poster = htmlentities(utf8_decode($db_data['username'])); 
setlocale (LC_TIME, 'fr_FR','fra'); 
$post_time = strftime("%A %d %B %Y à %H:%M", $db_data['post_time']+(0)); 
$post_time = htmlentities($post_time);

echo "<p align=\"left\">$post_title par $poster - $post_time.<br />$post</p>"; 

} 
echo "</div>";
// on ferme la connexion à mysql 
garbage_collection();

?>

Puis dans la page où tu veux l'afficher :
Code:
include('http://example.com/forum/derniers-sujets.php');
Je pense que cela devrait fonctionner.
 
WRInaute accro
Carole : merci ça fonctionne à une chose prêt ! Ca me génère des URL type forum.monsite.com/titre-du-topic.html mais mes url sont du type forum.monsite.com/titre-du-topic-t11.html

Comment faire ?

Merci Protée mais ton script ne fonctionne pas chez moi.

En tout cas c'est vachement sympa :p
 
WRInaute occasionnel
Salut milkiway,
cette solution fonctionne chez moi : Phpbb3 version 3.06 - rewrite avancé.
Il s'agit sans doute de petits ajustements liés à l'emplacement de ton forum.
Courage, tu ne dois plus être loin du but ! :)
 
Nouveau WRInaute
carole heinz a dit:
sinon tu as une autre solution:

- créer un fichier last.php, à placer à la racine du domaine

Code:
   <?php
define('IN_PHPBB', TRUE);

// ici on définit le répertoire du forum si ce dernier est en répertoire
$phpbb_root_path = './repertoire-du-forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);


// Start session management



$sql = "SELECT topic_id, forum_id, topic_title, topic_type FROM " . TOPICS_TABLE . " where forum_id != 1 AND topic_approved = 1 ORDER BY  topic_last_post_time  DESC limit 10";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{     
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
         if ($row['topic_type'] == POST_GLOBAL) {
            $phpbb_seo->seo_opt['topic_type'][$row['topic_id']] = POST_GLOBAL;
         }
         if ( empty($phpbb_seo->seo_url['topic'][$row['topic_id']]) ) {
            $phpbb_seo->seo_url['topic'][$row['topic_id']] = $phpbb_seo->format_url($row['topic_title']);
         }
echo '<a href="'.append_sid($phpbb_root_path . 'viewtopic.php?f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']).'"   >' . $row['topic_title'] . "</a><br />";
         // www.phpBB-SEO.com SEO TOOLKIT END
}


?>

ensuite il suffit de faire un include de ce fichier last.php

Code:
<?php include('http://www.ton-domaine.fr/last.php'); ?>

à l'endroit où tu veux afficher les x derniers topics (les 10 derniers dans cet exemple). pareil, je ne sais pas si c'est élégant mais ça fonctionne très bien avec phpbb3 + mod rewrite avancé

Salut,

J'ai suivi tes conseils. Ca marche parfaitement à un détail près. Les accents ne s'affiche pas correctement dans les titres affichés sur la page. Peux-tu m'aider à corriger ce problème.

Exemples

Recherche de Volontaires pour ... été/hiver
Étudiante cherche ...été
Cherche Bénévole pour ... été / hiver 2010

Et cela me dérègle la suite des articles qui viennent après avec le même prob d'accent.

Merci de votre aide.

Cordialement
 
Nouveau WRInaute
YoyoS a dit:
utf8_decode / utf8_encode suivant le sens de conversion.

ok mais je le mets où et comment?

Code:
       <?php
    define('IN_PHPBB', TRUE);

    // ici on définit le répertoire du forum si ce dernier est en répertoire
    $phpbb_root_path = './forum/';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);


    // Start session management



    $sql = "SELECT topic_id, forum_id, topic_title, topic_type FROM " . TOPICS_TABLE . " where forum_id != 1 AND topic_approved = 1 ORDER BY  topic_last_post_time  DESC limit 7";
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result))
    {     
    // www.phpBB-SEO.com SEO TOOLKIT BEGIN
             if ($row['topic_type'] == POST_GLOBAL) {
                $phpbb_seo->seo_opt['topic_type'][$row['topic_id']] = POST_GLOBAL;
             }
             if ( empty($phpbb_seo->seo_url['topic'][$row['topic_id']]) ) {
                $phpbb_seo->seo_url['topic'][$row['topic_id']] = $phpbb_seo->format_url($row['topic_title']);
             }
    echo '<a href="'.append_sid($phpbb_root_path . 'viewtopic.php?f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']).'"   >' . $row['topic_title'] . "</a><br />";
             // www.phpBB-SEO.com SEO TOOLKIT END
    }


    ?>

merci
 
WRInaute accro
grolivier a dit:
ok mais je le mets où et comment?

Là où ton lien s'affiche au niveau du echo ""; , tu entoures le texte qui pose problème de utf8_decode().
Ou alors tu veux le code modifié tout cuit dans le bec ptet ? :mrgreen:

Code:
echo '<a href="'.append_sid($phpbb_root_path . 'viewtopic.php?f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']).'"   >' . utf8_decode($row['topic_title']) . "</a><br />"

Et voila :lol:
 
Nouveau WRInaute
YoyoS a dit:
grolivier a dit:
ok mais je le mets où et comment?

Là où ton lien s'affiche au niveau du echo ""; , tu entoures le texte qui pose problème de utf8_decode().
Ou alors tu veux le code modifié tout cuit dans le bec ptet ? :mrgreen:

Code:
echo '<a href="'.append_sid($phpbb_root_path . 'viewtopic.php?f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']).'"   >' . utf8_decode($row['topic_title']) . "</a><br />"

Et voila :lol:

Ok, ca marche sur les derniers posts du forum, mais cela ne marche pas avec la suite de mon texte. Les caractères restent affichés bizarrement genre un @ au lieu d'un é. Et pourtant avant de mettre cette include, cela marchait parfaitement. 8O
 
Discussions similaires
Haut