Afficher les statistiques des forums :
Et finalement quelques exemples en utilisant extern.php pour produire un fil RSS 0.91 :
Afficher les 15 discussions les plus récemment actives :
http://host.com/extern.php?action=active&type=RSS
Afficher les 15 discussions les plus récemment actives depuis le forum dID 2:
http://host.com/extern.php?action=active&type=RSS&fid=2
Ci-dessous vous trouverez des variables que vous pouvez modifier pour que le
script se comporte selon vos besoins.
/***********************************************************************/
// Le nombre maximum de discussions qui seront affichées
$show_max_topics = 60;
// La longueur à laquelle les sujets des discussions seront tronquées (pour HTML)
$max_subject_length = 30;
/***********************************************************************/
// NE MODIFIEZ RIEN AU-DESSOUS DE CETTE LIGNE ! (à moins que vous sachiez ce que vous faites)
define('PUN_ROOT', './');
@include PUN_ROOT.'config.php';
// If PUN isn't defined, config.php is missing or corrupt
if (!defined('PUN'))
exit('Le fichier "config.php" n\'existe pas ou est endommagé. Veuillez lancer install.php pour installer PunBB.');
// Make sure PHP reports all errors except E_NOTICE
error_reporting(E_ALL ^ E_NOTICE);
// Turn off magic_quotes_runtime
set_magic_quotes_runtime(0);
// Load the functions script
require PUN_ROOT.'include/functions.php';
// Load DB abstraction layer and try to connect
require PUN_ROOT.'include/dblayer/common_db.php';
// Load cached config
@include PUN_ROOT.'cache/cache_config.php';
if (!defined('PUN_CONFIG_LOADED'))
{
require PUN_ROOT.'include/cache.php';
generate_config_cache();
require PUN_ROOT.'cache/cache_config.php';
}
// Make sure we (guests) have permission to read the forums
$result = $db->query('SELECT g_read_board FROM '.$db->prefix.'groups WHERE g_id=3') or error('Unable to fetch group info', __FILE__, __LINE__, $db->error());
if ($db->result($result) == '0')
exit('Vous n\'avez pas les permissions');
// Attempt to load the common language file
@include PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/common.php';
if (!isset($lang_common))
exit('Il n\'y a pas de pack de langue \''.$pun_config['o_default_lang'].'\' d\'installé. Veuillez ré-installer une langue de ce nom.');
if (!isset($_GET['action']))
exit('Aucun paramètre de fourni. Veuillez voir extern.php pour les instructions.');
//
// Converts the CDATA end sequence ]]> into ]]>
//
function escape_cdata($str)
{
return str_replace(']]>', ']]>', $str);
}
//
// Show recent discussions
//
if ($_GET['action'] == 'active' || $_GET['action'] == 'new')
{
$order_by = ($_GET['action'] == 'active') ? 't.last_post' : 't.posted';
$forum_sql = '';
// Was any specific forum ID's supplied?
if (isset($_GET['fid']) && $_GET['fid'] != '')
{
$fids = explode(',', trim($_GET['fid']));
$fids = array_map('intval', $fids);
if (!empty($fids))
$forum_sql = ' AND f.id IN('.implode(',', $fids).')';
}
// Any forum ID's to exclude?
if (isset($_GET['nfid']) && $_GET['nfid'] != '')
{
$nfids = explode(',', trim($_GET['nfid']));
$nfids = array_map('intval', $nfids);
if (!empty($nfids))
$forum_sql = ' AND f.id NOT IN('.implode(',', $nfids).')';
}
// Should we output this as RSS?
if (isset($_GET['type']) && strtoupper($_GET['type']) == 'RSS')
{
$rss_description = ($_GET['action'] == 'active') ? $lang_common['RSS Desc Active'] : $lang_common['RSS Desc New'];
$url_action = ($_GET['action'] == 'active') ? '&action=new' : '';
// Send XML/no cache headers
header('Content-Type: text/xml');
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
// It's time for some syndication!
echo ''."\r\n";
echo ''."\r\n";
echo ''."\r\n";
echo ''."\r\n";
echo "\t".''.pun_htmlspecialchars($pun_config['o_board_title']).''."\r\n";
echo "\t".''.$pun_config['o_base_url'].'/'."\r\n";
echo "\t".''.pun_htmlspecialchars($rss_description.' '.$pun_config['o_board_title']).''."\r\n";
echo "\t".'en-us'."\r\n";
// Fetch 15 topics
$result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post, f.id AS fid, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL'.$forum_sql.' ORDER BY '.$order_by.' DESC LIMIT 15') or error('Impossible de retrouver la liste des discussions', __FILE__, __LINE__, $db->error());
while ($cur_topic = $db->fetch_assoc($result))
{
if ($pun_config['o_censoring'] == '1')
$cur_topic['subject'] = censor_words($cur_topic['subject']);
echo "\t".''."\r\n";
echo "\t\t".''.pun_htmlspecialchars($cur_topic['subject']).''."\r\n";
echo "\t\t".''.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].$url_action.''."\r\n";
echo "\t\t".''.$cur_topic['forum_name'].' '."\r\n".$lang_common['Author'].': '.$cur_topic['poster'].' '."\r\n".$lang_common['Posted'].': '.date('r', $cur_topic['posted']).' '."\r\n".$lang_common['Last post'].': '.date('r', $cur_topic['last_post'])).']]>'."\r\n";
echo "\t".''."\r\n";
}
echo ''."\r\n";
echo '';
}
// Output regular HTML
else
{
$show = isset($_GET['show']) ? intval($_GET['show']) : 15;
if ($show < 1 || $show > 50)
$show = 15;
// Fetch $show topics
$result = $db->query('SELECT t.id, t.subject FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL'.$forum_sql.' ORDER BY '.$order_by.' DESC LIMIT '.$show) or error('Impossible de retrouver la liste des discussions', __FILE__, __LINE__, $db->error());
while ($cur_topic = $db->fetch_assoc($result))
{
if ($pun_config['o_censoring'] == '1')
$cur_topic['subject'] = censor_words($cur_topic['subject']);
if (pun_strlen($cur_topic['subject']) > $max_subject_length)
$subject_truncated = pun_htmlspecialchars(trim(substr($cur_topic['subject'], 0, ($max_subject_length-5)))).' ...';
else
$subject_truncated = pun_htmlspecialchars($cur_topic['subject']);
echo '
'."\n";
}
}
return;
}
//
// Show users online
//
else if ($_GET['action'] == 'online' || $_GET['action'] == 'online_full')
{
// Load the index.php language file
require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php';
// Fetch users online info and generate strings for output
$num_guests = $num_users = 0;
$users = array();
$result = $db->query('SELECT user_id, ident FROM '.$db->prefix.'online WHERE idle=0 ORDER BY ident', true) or error('Impossible de retrouver la liste des utilisateurs en ligne', __FILE__, __LINE__, $db->error());
while ($pun_user_online = $db->fetch_assoc($result))
{
if ($pun_user_online['user_id'] > 1)
{
$users[] = ''.pun_htmlspecialchars($pun_user_online['ident']).'';
++$num_users;
}
else
++$num_guests;
}
echo $lang_index['Guests online'].': '.$num_guests.' ';
if ($_GET['action'] == 'online_full')
echo $lang_index['Users online'].': '.implode(', ', $users).' ';
else
echo $lang_index['Users online'].': '.$num_users.' ';
return;
}
//
// Show board statistics
//
else if ($_GET['action'] == 'stats')
{
// Load the index.php language file
require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php';
// Collect some statistics from the database
$result = $db->query('SELECT COUNT(id)-1 FROM '.$db->prefix.'users') or error('Impossible de retrouver le nombre total d\'utilisateurs', __FILE__, __LINE__, $db->error());
$stats['total_users'] = $db->result($result);
$result = $db->query('SELECT id, username FROM '.$db->prefix.'users ORDER BY registered DESC LIMIT 1') or error('Impossible de retrouver le dernier utilisateur inscrit', __FILE__, __LINE__, $db->error());
$stats['last_user'] = $db->fetch_assoc($result);
$result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Impossible de retrouver le total de discussions et de messages', __FILE__, __LINE__, $db->error());
list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);
echo $lang_index['No of users'].': '.$stats['total_users'].' ';
echo $lang_index['Newest user'].': '.pun_htmlspecialchars($stats['last_user']['username']).' ';
echo $lang_index['No of topics'].': '.$stats['total_topics'].' ';
echo $lang_index['No of posts'].': '.$stats['total_posts'];
return;
}
else
exit('Bad request');