Commit | Line | Data |
---|---|---|
c495c100 P |
1 | <?php |
2 | /*********************************************************************** | |
3 | ||
4 | Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org) | |
5 | ||
6 | This file is part of PunBB. | |
7 | ||
8 | PunBB is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU General Public License as published | |
10 | by the Free Software Foundation; either version 2 of the License, | |
11 | or (at your option) any later version. | |
12 | ||
13 | PunBB is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
21 | MA 02111-1307 USA | |
22 | ||
23 | ************************************************************************ | |
24 | ||
25 | ||
26 | INSTRUCTIONS | |
27 | ||
28 | Le script extern.php est utiliser pour inclure des informations à | |
29 | propos de vos forums sur des pages externes aux forums et pour | |
30 | syndiquer les discussions récentes via RSS. Le script peut afficher | |
31 | une liste de discussions récentes (triée par messages, dates ou | |
32 | derniers messages), une liste d\92utilisateurs actifs ou une | |
33 | collection de statistiques générales. Le script peut être appeler | |
34 | directement par l\92intermédiaire d\92une URL (pour RSS), de la | |
35 | commande inclue de PHP ou par l\92utilisation du Server Side | |
36 | Includes (SSI). | |
37 | ||
38 | Le comportement du script est commandé par l\92intermédiaire de | |
39 | variables fournies au script dans l\92URL. Les différentes variables | |
40 | sont : action (que faut-il afficher), show (combien de discussions | |
41 | afficher), forum (l\92ID du forum à sonder pour récupèrer les | |
42 | discussions) et type (sortie comme HTML ou RSS). La seule variable | |
43 | obligatoire est action. Les valeurs de possibles (par defaut) sont : | |
44 | ||
45 | action: | |
46 | active (affiche les discussions récemment actives) (HTML ou RSS) | |
47 | new (afficher les plus récentes discussions) (HTML ou RSS) | |
48 | online (afficher les utilisateurs en ligne) (HTML) | |
49 | online_full (idem, mais inclut une liste complète) (HTML) | |
50 | stats (afficher les statistiques des forums) (HTML) | |
51 | ||
52 | show: N\92importe qu\92elle valeur, nombre entier entre 1 et 50. | |
53 | Cette variable est ignorées pour la sortie RSS. 15 par | |
54 | défaut. | |
55 | ||
56 | fid: Un ou plusieurs ID de forum (séparés par des virgules). | |
57 | Si ignorée, des discussions de tous les forums lisibles | |
58 | par les invités seront récupérées. | |
59 | ||
60 | nfid: Un ou plusieurs ID de forum (séparés par des virgules) | |
61 | qui seront ignorés. Ex. l'ID d'un forum de test. | |
62 | ||
63 | type: RSS. Toute autre chose signifie une sortie en HTML. | |
64 | ||
65 | ||
66 | Voici quelques exemples en utilisant la fonction include() de PHP : | |
67 | ||
68 | Afficher les 15 discussions les plus récemment actives depuis tous les forums : | |
69 | include('http://host.com/forums/extern.php?action=active'); | |
70 | ||
71 | Afficher les 10 discussions les plus récentes depuis les forums d\92ID 5, 6 et 7 : | |
72 | include('http://host.com/forums/extern.php?action=new&show=10&fid=5,6,7'); | |
73 | ||
74 | Afficher les utilisateurs en ligne : | |
75 | include('http://host.com/forums/extern.php?action=online'); | |
76 | ||
77 | Afficher les utilisateurs en ligne avec une liste complète : | |
78 | include('http://host.com/forums/extern.php?action=online_full'); | |
79 | ||
80 | Afficher les statistiques des forums : | |
81 | include('http://host.com/forums/extern.php?action=stats'); | |
82 | ||
83 | ||
84 | Voici quelques exemples en utilisant SSI : | |
85 | ||
86 | Afficher les 5 discussions les plus récentes depuis les forums d\92ID 11 et 22: | |
87 | <!--#include virtual="forums/extern.php?action=new&show=5&fid=11,22" --> | |
88 | ||
89 | Afficher les statistiques des forums : | |
90 | <!--#include virtual="forums/extern.php?action=stats" --> | |
91 | ||
92 | ||
93 | Et finalement quelques exemples en utilisant extern.php pour produire un fil RSS 0.91 : | |
94 | ||
95 | Afficher les 15 discussions les plus récemment actives : | |
96 | http://host.com/extern.php?action=active&type=RSS | |
97 | ||
98 | Afficher les 15 discussions les plus récemment actives depuis le forum d\92ID 2: | |
99 | http://host.com/extern.php?action=active&type=RSS&fid=2 | |
100 | ||
101 | Ci-dessous vous trouverez des variables que vous pouvez modifier pour que le | |
102 | script se comporte selon vos besoins. | |
103 | ||
104 | /***********************************************************************/ | |
105 | ||
106 | // Le nombre maximum de discussions qui seront affichées | |
107 | $show_max_topics = 60; | |
108 | ||
109 | // La longueur à laquelle les sujets des discussions seront tronquées (pour HTML) | |
110 | $max_subject_length = 30; | |
111 | ||
112 | /***********************************************************************/ | |
113 | ||
114 | // NE MODIFIEZ RIEN AU-DESSOUS DE CETTE LIGNE ! (à moins que vous sachiez ce que vous faites) | |
115 | ||
116 | ||
117 | define('PUN_ROOT', './'); | |
118 | @include PUN_ROOT.'config.php'; | |
119 | ||
120 | // If PUN isn't defined, config.php is missing or corrupt | |
121 | if (!defined('PUN')) | |
122 | exit('Le fichier "config.php" n\'existe pas ou est endommagé. Veuillez lancer install.php pour installer FluxBB.'); | |
123 | ||
124 | ||
125 | // Make sure PHP reports all errors except E_NOTICE | |
126 | error_reporting(E_ALL ^ E_NOTICE); | |
127 | ||
128 | // Turn off magic_quotes_runtime | |
129 | set_magic_quotes_runtime(0); | |
130 | ||
131 | ||
132 | // Load the functions script | |
133 | require PUN_ROOT.'include/functions.php'; | |
134 | ||
135 | // Load DB abstraction layer and try to connect | |
136 | require PUN_ROOT.'include/dblayer/common_db.php'; | |
137 | ||
138 | // Load cached config | |
139 | @include PUN_ROOT.'cache/cache_config.php'; | |
140 | if (!defined('PUN_CONFIG_LOADED')) | |
141 | { | |
142 | require PUN_ROOT.'include/cache.php'; | |
143 | generate_config_cache(); | |
144 | require PUN_ROOT.'cache/cache_config.php'; | |
145 | } | |
146 | ||
147 | // Make sure we (guests) have permission to read the forums | |
148 | $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()); | |
149 | if ($db->result($result) == '0') | |
150 | exit('Vous n\'avez pas les permissions'); | |
151 | ||
152 | ||
153 | // Attempt to load the common language file | |
154 | @include PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/common.php'; | |
155 | if (!isset($lang_common)) | |
156 | 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.'); | |
157 | ||
158 | // Check if we are to display a maintenance message | |
159 | if ($pun_config['o_maintenance'] && !defined('PUN_TURN_OFF_MAINT')) | |
160 | maintenance_message(); | |
161 | ||
162 | if (!isset($_GET['action'])) | |
163 | exit('Aucun paramètre de fourni. Veuillez voir extern.php pour les instructions.'); | |
164 | ||
165 | ||
166 | // | |
167 | // Converts the CDATA end sequence ]]> into ]]> | |
168 | // | |
169 | function escape_cdata($str) | |
170 | { | |
171 | return str_replace(']]>', ']]>', $str); | |
172 | } | |
173 | ||
174 | ||
175 | // | |
176 | // Show recent discussions | |
177 | // | |
178 | if ($_GET['action'] == 'active' || $_GET['action'] == 'new') | |
179 | { | |
180 | $order_by = ($_GET['action'] == 'active') ? 't.last_post' : 't.posted'; | |
181 | $forum_sql = ''; | |
182 | ||
183 | // Was any specific forum ID's supplied? | |
184 | if (isset($_GET['fid']) && $_GET['fid'] != '') | |
185 | { | |
186 | $fids = explode(',', trim($_GET['fid'])); | |
187 | $fids = array_map('intval', $fids); | |
188 | ||
189 | if (!empty($fids)) | |
190 | $forum_sql = ' AND f.id IN('.implode(',', $fids).')'; | |
191 | } | |
192 | ||
193 | // Any forum ID's to exclude? | |
194 | if (isset($_GET['nfid']) && $_GET['nfid'] != '') | |
195 | { | |
196 | $nfids = explode(',', trim($_GET['nfid'])); | |
197 | $nfids = array_map('intval', $nfids); | |
198 | ||
199 | if (!empty($nfids)) | |
200 | $forum_sql = ' AND f.id NOT IN('.implode(',', $nfids).')'; | |
201 | } | |
202 | ||
203 | // Should we output this as RSS? | |
204 | if (isset($_GET['type']) && strtoupper($_GET['type']) == 'RSS') | |
205 | { | |
206 | $rss_description = ($_GET['action'] == 'active') ? $lang_common['RSS Desc Active'] : $lang_common['RSS Desc New']; | |
207 | $url_action = ($_GET['action'] == 'active') ? '&action=new' : ''; | |
208 | ||
209 | // Send XML/no cache headers | |
210 | header('Content-Type: text/xml'); | |
211 | header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); | |
212 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); | |
213 | header('Pragma: public'); | |
214 | ||
215 | // It's time for some syndication! | |
216 | echo '<?xml version="1.0" encoding="'.$lang_common['lang_encoding'].'"?>'."\r\n"; | |
217 | echo '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">'."\r\n"; | |
218 | echo '<rss version="0.91">'."\r\n"; | |
219 | echo '<channel>'."\r\n"; | |
220 | echo "\t".'<title>'.pun_htmlspecialchars($pun_config['o_board_title']).'</title>'."\r\n"; | |
221 | echo "\t".'<link>'.$pun_config['o_base_url'].'/</link>'."\r\n"; | |
222 | echo "\t".'<description>'.pun_htmlspecialchars($rss_description.' '.$pun_config['o_board_title']).'</description>'."\r\n"; | |
223 | echo "\t".'<language>en-us</language>'."\r\n"; | |
224 | ||
225 | // Fetch 15 topics | |
226 | $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('Unable to fetch topic list', __FILE__, __LINE__, $db->error()); | |
227 | ||
228 | while ($cur_topic = $db->fetch_assoc($result)) | |
229 | { | |
230 | if ($pun_config['o_censoring'] == '1') | |
231 | $cur_topic['subject'] = censor_words($cur_topic['subject']); | |
232 | ||
233 | echo "\t".'<item>'."\r\n"; | |
234 | echo "\t\t".'<title>'.pun_htmlspecialchars($cur_topic['subject']).'</title>'."\r\n"; | |
235 | echo "\t\t".'<link>'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].$url_action.'</link>'."\r\n"; | |
236 | echo "\t\t".'<description><![CDATA['.escape_cdata($lang_common['Forum'].': <a href="'.$pun_config['o_base_url'].'/viewforum.php?id='.$cur_topic['fid'].'">'.$cur_topic['forum_name'].'</a><br />'."\r\n".$lang_common['Author'].': '.$cur_topic['poster'].'<br />'."\r\n".$lang_common['Posted'].': '.date('r', $cur_topic['posted']).'<br />'."\r\n".$lang_common['Last post'].': '.date('r', $cur_topic['last_post'])).']]></description>'."\r\n"; | |
237 | echo "\t".'</item>'."\r\n"; | |
238 | } | |
239 | ||
240 | echo '</channel>'."\r\n"; | |
241 | echo '</rss>'; | |
242 | } | |
243 | ||
244 | ||
245 | // Output regular HTML | |
246 | else | |
247 | { | |
248 | $show = isset($_GET['show']) ? intval($_GET['show']) : 15; | |
249 | if ($show < 1 || $show > 50) | |
250 | $show = 15; | |
251 | ||
252 | // Fetch $show topics | |
253 | $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('Unable to fetch topic list', __FILE__, __LINE__, $db->error()); | |
254 | ||
255 | while ($cur_topic = $db->fetch_assoc($result)) | |
256 | { | |
257 | if ($pun_config['o_censoring'] == '1') | |
258 | $cur_topic['subject'] = censor_words($cur_topic['subject']); | |
259 | ||
260 | if (pun_strlen($cur_topic['subject']) > $max_subject_length) | |
261 | $subject_truncated = pun_htmlspecialchars(trim(substr($cur_topic['subject'], 0, ($max_subject_length-5)))).' ...'; | |
262 | else | |
263 | $subject_truncated = pun_htmlspecialchars($cur_topic['subject']); | |
264 | ||
265 | echo '<li><a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.$subject_truncated.'</a></li>'."\n"; | |
266 | } | |
267 | } | |
268 | ||
269 | return; | |
270 | } | |
271 | ||
272 | ||
273 | // | |
274 | // Show users online | |
275 | // | |
276 | else if ($_GET['action'] == 'online' || $_GET['action'] == 'online_full') | |
277 | { | |
278 | // Load the index.php language file | |
279 | require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php'; | |
280 | ||
281 | // Fetch users online info and generate strings for output | |
282 | $num_guests = $num_users = 0; | |
283 | $users = array(); | |
284 | $result = $db->query('SELECT user_id, ident FROM '.$db->prefix.'online WHERE idle=0 ORDER BY ident', true) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error()); | |
285 | ||
286 | while ($pun_user_online = $db->fetch_assoc($result)) | |
287 | { | |
288 | if ($pun_user_online['user_id'] > 1) | |
289 | { | |
290 | $users[] = '<a href="'.$pun_config['o_base_url'].'/profile.php?id='.$pun_user_online['user_id'].'">'.pun_htmlspecialchars($pun_user_online['ident']).'</a>'; | |
291 | ++$num_users; | |
292 | } | |
293 | else | |
294 | ++$num_guests; | |
295 | } | |
296 | ||
297 | echo $lang_index['Guests online'].': '.$num_guests.'<br />'; | |
298 | ||
299 | if ($_GET['action'] == 'online_full') | |
300 | echo $lang_index['Users online'].': '.implode(', ', $users).'<br />'; | |
301 | else | |
302 | echo $lang_index['Users online'].': '.$num_users.'<br />'; | |
303 | ||
304 | return; | |
305 | } | |
306 | ||
307 | ||
308 | // | |
309 | // Show board statistics | |
310 | // | |
311 | else if ($_GET['action'] == 'stats') | |
312 | { | |
313 | // Load the index.php language file | |
314 | require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php'; | |
315 | ||
316 | // Collect some statistics from the database | |
317 | $result = $db->query('SELECT COUNT(id)-1 FROM '.$db->prefix.'users') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error()); | |
318 | $stats['total_users'] = $db->result($result); | |
319 | ||
320 | $result = $db->query('SELECT id, username FROM '.$db->prefix.'users ORDER BY registered DESC LIMIT 1') or error('Unable to fetch newest registered user', __FILE__, __LINE__, $db->error()); | |
321 | $stats['last_user'] = $db->fetch_assoc($result); | |
322 | ||
323 | $result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Unable to fetch topic/post count', __FILE__, __LINE__, $db->error()); | |
324 | list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result); | |
325 | ||
326 | echo $lang_index['No of users'].': '.$stats['total_users'].'<br />'; | |
327 | echo $lang_index['Newest user'].': <a href="'.$pun_config['o_base_url'].'/profile.php?id='.$stats['last_user']['id'].'">'.pun_htmlspecialchars($stats['last_user']['username']).'</a><br />'; | |
328 | echo $lang_index['No of topics'].': '.$stats['total_topics'].'<br />'; | |
329 | echo $lang_index['No of posts'].': '.$stats['total_posts']; | |
330 | ||
331 | return; | |
332 | } | |
333 | ||
334 | ||
335 | else | |
336 | exit('Bad request'); |