dcz m'a montré ce morceau de code afin d'afficher les derniers posts d'un forum sur une page externe.
<?php
// Last XX Active Topics outside phpBB - dcz - www.phpBB-SEO.com
// License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
//
// Basic Configuration
// How Many Topics you want to display?
$topicnumber = 30;
// Scrolling towards up or down?
$scroll = "up";
// Change this to your phpBB URL
$urlPath = "http://www.example.com/phpBB";
// Change this to your phpBB path
$phpbb_root_path = 'phpBB/';
// Exclude forums, forum id in this array will not be listed
$exclude_forum = array (
//1 => 31,
//2 => 5,
//3 => 10,
);
define('IN_PHPBB', true);
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
// Start session management
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
// End session management
// Let's do it now![]()
$sql = "SELECT t.topic_poster,t.topic_views,t.topic_replies,t.topic_id, t.topic_title, t.topic_last_post_id, t.forum_id, p.post_id, p.poster_id, p.post_time, u.user_id, u.username ,f.forum_name
FROM ".TOPICS_TABLE." t, ".FORUMS_TABLE." f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u
WHERE t.topic_id = p.topic_id
AND f.forum_id = t.forum_id
AND t.topic_status <> 2
AND p.post_id = t.topic_last_post_id
AND p.poster_id = u.user_id
ORDER BY p.post_id DESC LIMIT $topicnumber";
//Begin sql cache
if ( !($result = $db->sql_query($sql)) )
//if ( !($result = $db->sql_query($sql, false, 'posts_')) )
//End sql cache
{
message_die(GENERAL_ERROR, 'Could not obtain Last topics info', '', __LINE__, __FILE__, $sql);
}
$last_topic_data = array();
while( $row = $db->sql_fetchrow($result) )
{
$last_topic_data[] = $row;
}
$db->sql_freeresult($result);
unset($row);
// Handle the not topics case, if you want![]()
if ( !($total_topics = count($last_topic_data)) )
{
$message = 'Something you want to say here';
message_die(GENERAL_MESSAGE, $message);
}
//
// Find which forums are visible for this user
//
$is_auth_ary = array();
$is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata, $last_topic_data);
// here I keep the basic html output
// Outcome of the HTML
// Be carefull when you edit these!
echo "<marquee dir=\"rtl\" align=\"center\" id=\"recent_topics\" behavior=\"scroll\" direction=\"$scroll\" height=\"150\" width=\"100%\" scrolldelay=\"100\" scrollamount=\"2\" onMouseOver=\"stop()\" onMouseOut=\"start()\">";
echo "<div align=\"center\">";
echo "<table cellpadding='3' cellSpacing='2'";
for ($i = 0; $i < $total_topics; $i++ )
{
if ($is_auth_ary[$last_topic_data[$i]['forum_id']]['auth_view'] && !in_array($last_topic_data[$i]['forum_id'], $exclude_forum))
{
// phpBB-SEO.com SEO TOOLKIT BEGIN
$seo_forum_name = $last_topic_data[$i]['forum_name'];
$seo_topic_name = $last_topic_data[$i]['topic_title'];
// phpBB-SEO.com SEO TOOLKIT END
echo "<tr valign='top'>
<td><span class=\"nav\">".$lang['Last_Post']." :
<a href=\"".append_sid("$urlPath/viewtopic.php?t=".$last_topic_data[$i]['topic_id'])."\" class=\"nav\">" . $last_topic_data[$i]['topic_title'] ."</span></a></td>
<td><span class=\"nav\"> ".$lang['Forum']." :
<a href=\"".append_sid("$urlPath/viewforum.php?f=".$last_topic_data[$i]['forum_id'])."\" class=\"nav\">" . $last_topic_data[$i]["forum_name"] . "</a></span></td>
<td><span class=\"nav\"> ".$lang['Views']." : " . $row['topic_views'] . "</span></td>
<td><span class=\"nav\"> ".$lang['Replies']." : " . $last_topic_data[$i]['topic_replies'] . "</span></a></td>
<td><span class=\"nav\"> ".$lang['Poster']." :
<a href=\"".append_sid("$urlPath/profile.php?mode=viewprofile&u=".$last_topic_data[$i]['user_id'])."\" class=\"nav\" >" . $last_topic_data[$i]['username'] . "</a></td></tr>";
}
}
echo "</table></div></marquee>";
?>
Je voudrais la requête la plus simple possible afin de toucher le serveur le moins possible. Je voudrais afficher le titre du post, l'auteur, le nb de réponses, la date et une icone pour atteindre le dernier post du topic...et tout ceci avec une seule requête. Est-ce faisable ou juste dans mes rêves ?
Le MOD topic anywhere étant un bouffeur de ressource monstreux, je cherche le moyen de faire la même chose beaucoup plus léger.
Merci pour votre aide !

Français |
Anglais
News

