Changeset 3 for branches/rsr.v5.1.dev/web/punbb/extern.php
- Timestamp:
- Nov 14, 2011, 11:17:15 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rsr.v5.1.dev/web/punbb/extern.php
r1 r3 1 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 2 3 /** 4 * Copyright (C) 2008-2011 FluxBB 5 * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB 6 * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher 7 */ 8 9 /*----------------------------------------------------------------------------- 25 10 26 11 INSTRUCTIONS 27 12 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Âutilisateurs actifs ou une 33 collection de statistiques générales. Le script peut être appeler 34 directement par lÂintermédiaire dÂune URL (pour RSS), de la 35 commande inclue de PHP ou par lÂutilisation du Server Side 36 Includes (SSI). 37 38 Le comportement du script est commandé par lÂintermédiaire de 39 variables fournies au script dans lÂURL. Les différentes variables 40 sont : action (que faut-il afficher), show (combien de discussions 41 afficher), forum (lÂID 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Âimporte quÂelle 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ÂID 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ÂID 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ÂID 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 PunBB.'); 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 if (!isset($_GET['action'])) 159 exit('Aucun paramÚtre de fourni. Veuillez voir extern.php pour les instructions.'); 160 161 162 // 163 // Converts the CDATA end sequence ]]> into ]]> 164 // 165 function escape_cdata($str) 166 { 167 return str_replace(']]>', ']]>', $str); 168 } 169 170 171 // 13 This script is used to include information about your board from 14 pages outside the forums and to syndicate news about recent 15 discussions via RSS/Atom/XML. The script can display a list of 16 recent discussions, a list of active users or a collection of 17 general board statistics. The script can be called directly via 18 an URL, from a PHP include command or through the use of Server 19 Side Includes (SSI). 20 21 The scripts behaviour is controlled via variables supplied in the 22 URL to the script. The different variables are: action (what to 23 do), show (how many items to display), fid (the ID or IDs of 24 the forum(s) to poll for topics), nfid (the ID or IDs of forums 25 that should be excluded), tid (the ID of the topic from which to 26 display posts) and type (output as HTML or RSS). The only 27 mandatory variable is action. Possible/default values are: 28 29 action: feed - show most recent topics/posts (HTML or RSS) 30 online - show users online (HTML) 31 online_full - as above, but includes a full list (HTML) 32 stats - show board statistics (HTML) 33 34 type: rss - output as RSS 2.0 35 atom - output as Atom 1.0 36 xml - output as XML 37 html - output as HTML (<li>'s) 38 39 fid: One or more forum IDs (comma-separated). If ignored, 40 topics from all readable forums will be pulled. 41 42 nfid: One or more forum IDs (comma-separated) that are to be 43 excluded. E.g. the ID of a a test forum. 44 45 tid: A topic ID from which to show posts. If a tid is supplied, 46 fid and nfid are ignored. 47 48 show: Any integer value between 1 and 50. The default is 15. 49 50 order: last_post - show topics ordered by when they were last 51 posted in, giving information about the reply. 52 posted - show topics ordered by when they were first 53 posted, giving information about the original post. 54 55 -----------------------------------------------------------------------------*/ 56 57 define('PUN_QUIET_VISIT', 1); 58 59 if (!defined('PUN_ROOT')) 60 define('PUN_ROOT', dirname(__FILE__).'/'); 61 require PUN_ROOT.'include/common.php'; 62 63 // The length at which topic subjects will be truncated (for HTML output) 64 if (!defined('FORUM_EXTERN_MAX_SUBJECT_LENGTH')) 65 define('FORUM_EXTERN_MAX_SUBJECT_LENGTH', 30); 66 67 // If we're a guest and we've sent a username/pass, we can try to authenticate using those details 68 if ($pun_user['is_guest'] && isset($_SERVER['PHP_AUTH_USER'])) 69 authenticate_user($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); 70 71 if ($pun_user['g_read_board'] == '0') 72 { 73 http_authenticate_user(); 74 exit($lang_common['No view']); 75 } 76 77 $action = isset($_GET['action']) ? strtolower($_GET['action']) : 'feed'; 78 79 // Handle a couple old formats, from FluxBB 1.2 80 switch ($action) 81 { 82 case 'active': 83 $action = 'feed'; 84 $_GET['order'] = 'last_post'; 85 break; 86 87 case 'new': 88 $action = 'feed'; 89 $_GET['order'] = 'posted'; 90 break; 91 } 92 93 // 94 // Sends the proper headers for Basic HTTP Authentication 95 // 96 function http_authenticate_user() 97 { 98 global $pun_config, $pun_user; 99 100 if (!$pun_user['is_guest']) 101 return; 102 103 header('WWW-Authenticate: Basic realm="'.$pun_config['o_board_title'].' External Syndication"'); 104 header('HTTP/1.0 401 Unauthorized'); 105 } 106 107 108 // 109 // Output $feed as RSS 2.0 110 // 111 function output_rss($feed) 112 { 113 global $lang_common, $pun_config; 114 115 // Send XML/no cache headers 116 header('Content-Type: application/xml; charset=utf-8'); 117 header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 118 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 119 header('Pragma: public'); 120 121 echo '<?xml version="1.0" encoding="utf-8"?>'."\n"; 122 echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'."\n"; 123 echo "\t".'<channel>'."\n"; 124 echo "\t\t".'<atom:link href="'.pun_htmlspecialchars(get_current_url()).'" rel="self" type="application/rss+xml" />'."\n"; 125 echo "\t\t".'<title><![CDATA['.escape_cdata($feed['title']).']]></title>'."\n"; 126 echo "\t\t".'<link>'.pun_htmlspecialchars($feed['link']).'</link>'."\n"; 127 echo "\t\t".'<description><![CDATA['.escape_cdata($feed['description']).']]></description>'."\n"; 128 echo "\t\t".'<lastBuildDate>'.gmdate('r', count($feed['items']) ? $feed['items'][0]['pubdate'] : time()).'</lastBuildDate>'."\n"; 129 130 if ($pun_config['o_show_version'] == '1') 131 echo "\t\t".'<generator>FluxBB '.$pun_config['o_cur_version'].'</generator>'."\n"; 132 else 133 echo "\t\t".'<generator>FluxBB</generator>'."\n"; 134 135 foreach ($feed['items'] as $item) 136 { 137 echo "\t\t".'<item>'."\n"; 138 echo "\t\t\t".'<title><![CDATA['.escape_cdata($item['title']).']]></title>'."\n"; 139 echo "\t\t\t".'<link>'.pun_htmlspecialchars($item['link']).'</link>'."\n"; 140 echo "\t\t\t".'<description><![CDATA['.escape_cdata($item['description']).']]></description>'."\n"; 141 echo "\t\t\t".'<author><![CDATA['.(isset($item['author']['email']) ? escape_cdata($item['author']['email']) : 'dummy@example.com').' ('.escape_cdata($item['author']['name']).')]]></author>'."\n"; 142 echo "\t\t\t".'<pubDate>'.gmdate('r', $item['pubdate']).'</pubDate>'."\n"; 143 echo "\t\t\t".'<guid>'.pun_htmlspecialchars($item['link']).'</guid>'."\n"; 144 145 echo "\t\t".'</item>'."\n"; 146 } 147 148 echo "\t".'</channel>'."\n"; 149 echo '</rss>'."\n"; 150 } 151 152 153 // 154 // Output $feed as Atom 1.0 155 // 156 function output_atom($feed) 157 { 158 global $lang_common, $pun_config; 159 160 // Send XML/no cache headers 161 header('Content-Type: application/atom+xml; charset=utf-8'); 162 header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 163 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 164 header('Pragma: public'); 165 166 echo '<?xml version="1.0" encoding="utf-8"?>'."\n"; 167 echo '<feed xmlns="http://www.w3.org/2005/Atom">'."\n"; 168 169 echo "\t".'<title type="html"><![CDATA['.escape_cdata($feed['title']).']]></title>'."\n"; 170 echo "\t".'<link rel="self" href="'.pun_htmlspecialchars(get_current_url()).'"/>'."\n"; 171 echo "\t".'<link href="'.pun_htmlspecialchars($feed['link']).'"/>'."\n"; 172 echo "\t".'<updated>'.gmdate('Y-m-d\TH:i:s\Z', count($feed['items']) ? $feed['items'][0]['pubdate'] : time()).'</updated>'."\n"; 173 174 if ($pun_config['o_show_version'] == '1') 175 echo "\t".'<generator version="'.$pun_config['o_cur_version'].'">FluxBB</generator>'."\n"; 176 else 177 echo "\t".'<generator>FluxBB</generator>'."\n"; 178 179 echo "\t".'<id>'.pun_htmlspecialchars($feed['link']).'</id>'."\n"; 180 181 $content_tag = ($feed['type'] == 'posts') ? 'content' : 'summary'; 182 183 foreach ($feed['items'] as $item) 184 { 185 echo "\t".'<entry>'."\n"; 186 echo "\t\t".'<title type="html"><![CDATA['.escape_cdata($item['title']).']]></title>'."\n"; 187 echo "\t\t".'<link rel="alternate" href="'.pun_htmlspecialchars($item['link']).'"/>'."\n"; 188 echo "\t\t".'<'.$content_tag.' type="html"><![CDATA['.escape_cdata($item['description']).']]></'.$content_tag.'>'."\n"; 189 echo "\t\t".'<author>'."\n"; 190 echo "\t\t\t".'<name><![CDATA['.escape_cdata($item['author']['name']).']]></name>'."\n"; 191 192 if (isset($item['author']['email'])) 193 echo "\t\t\t".'<email><![CDATA['.escape_cdata($item['author']['email']).']]></email>'."\n"; 194 195 if (isset($item['author']['uri'])) 196 echo "\t\t\t".'<uri>'.pun_htmlspecialchars($item['author']['uri']).'</uri>'."\n"; 197 198 echo "\t\t".'</author>'."\n"; 199 echo "\t\t".'<updated>'.gmdate('Y-m-d\TH:i:s\Z', $item['pubdate']).'</updated>'."\n"; 200 201 echo "\t\t".'<id>'.pun_htmlspecialchars($item['link']).'</id>'."\n"; 202 echo "\t".'</entry>'."\n"; 203 } 204 205 echo '</feed>'."\n"; 206 } 207 208 209 // 210 // Output $feed as XML 211 // 212 function output_xml($feed) 213 { 214 global $lang_common, $pun_config; 215 216 // Send XML/no cache headers 217 header('Content-Type: application/xml; charset=utf-8'); 218 header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 219 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 220 header('Pragma: public'); 221 222 echo '<?xml version="1.0" encoding="utf-8"?>'."\n"; 223 echo '<source>'."\n"; 224 echo "\t".'<url>'.pun_htmlspecialchars($feed['link']).'</url>'."\n"; 225 226 $forum_tag = ($feed['type'] == 'posts') ? 'post' : 'topic'; 227 228 foreach ($feed['items'] as $item) 229 { 230 echo "\t".'<'.$forum_tag.' id="'.$item['id'].'">'."\n"; 231 232 echo "\t\t".'<title><![CDATA['.escape_cdata($item['title']).']]></title>'."\n"; 233 echo "\t\t".'<link>'.pun_htmlspecialchars($item['link']).'</link>'."\n"; 234 echo "\t\t".'<content><![CDATA['.escape_cdata($item['description']).']]></content>'."\n"; 235 echo "\t\t".'<author>'."\n"; 236 echo "\t\t\t".'<name><![CDATA['.escape_cdata($item['author']['name']).']]></name>'."\n"; 237 238 if (isset($item['author']['email'])) 239 echo "\t\t\t".'<email><![CDATA['.escape_cdata($item['author']['email']).']]></email>'."\n"; 240 241 if (isset($item['author']['uri'])) 242 echo "\t\t\t".'<uri>'.pun_htmlspecialchars($item['author']['uri']).'</uri>'."\n"; 243 244 echo "\t\t".'</author>'."\n"; 245 echo "\t\t".'<posted>'.gmdate('r', $item['pubdate']).'</posted>'."\n"; 246 247 echo "\t".'</'.$forum_tag.'>'."\n"; 248 } 249 250 echo '</source>'."\n"; 251 } 252 253 254 // 255 // Output $feed as HTML (using <li> tags) 256 // 257 function output_html($feed) 258 { 259 260 // Send the Content-type header in case the web server is setup to send something else 261 header('Content-type: text/html; charset=utf-8'); 262 header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 263 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 264 header('Pragma: public'); 265 266 foreach ($feed['items'] as $item) 267 { 268 if (utf8_strlen($item['title']) > FORUM_EXTERN_MAX_SUBJECT_LENGTH) 269 $subject_truncated = pun_htmlspecialchars(pun_trim(utf8_substr($item['title'], 0, (FORUM_EXTERN_MAX_SUBJECT_LENGTH - 5)))).' âŠ'; 270 else 271 $subject_truncated = pun_htmlspecialchars($item['title']); 272 273 echo '<li><a href="'.pun_htmlspecialchars($item['link']).'" title="'.pun_htmlspecialchars($item['title']).'">'.$subject_truncated.'</a></li>'."\n"; 274 } 275 } 276 172 277 // Show recent discussions 173 // 174 if ($_GET['action'] == 'active' || $_GET['action'] == 'new') 175 { 176 $order_by = ($_GET['action'] == 'active') ? 't.last_post' : 't.posted'; 177 $forum_sql = ''; 178 179 // Was any specific forum ID's supplied? 180 if (isset($_GET['fid']) && $_GET['fid'] != '') 181 { 182 $fids = explode(',', trim($_GET['fid'])); 183 $fids = array_map('intval', $fids); 184 185 if (!empty($fids)) 186 $forum_sql = ' AND f.id IN('.implode(',', $fids).')'; 187 } 188 189 // Any forum ID's to exclude? 190 if (isset($_GET['nfid']) && $_GET['nfid'] != '') 191 { 192 $nfids = explode(',', trim($_GET['nfid'])); 193 $nfids = array_map('intval', $nfids); 194 195 if (!empty($nfids)) 196 $forum_sql = ' AND f.id NOT IN('.implode(',', $nfids).')'; 197 } 198 199 // Should we output this as RSS? 200 if (isset($_GET['type']) && strtoupper($_GET['type']) == 'RSS') 201 { 202 $rss_description = ($_GET['action'] == 'active') ? $lang_common['RSS Desc Active'] : $lang_common['RSS Desc New']; 203 $url_action = ($_GET['action'] == 'active') ? '&action=new' : ''; 204 205 // Send XML/no cache headers 206 header('Content-Type: text/xml'); 207 header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 208 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 209 header('Pragma: public'); 210 211 // It's time for some syndication! 212 echo '<?xml version="1.0" encoding="'.$lang_common['lang_encoding'].'"?>'."\r\n"; 213 echo '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">'."\r\n"; 214 echo '<rss version="0.91">'."\r\n"; 215 echo '<channel>'."\r\n"; 216 echo "\t".'<title>'.pun_htmlspecialchars($pun_config['o_board_title']).'</title>'."\r\n"; 217 echo "\t".'<link>'.$pun_config['o_base_url'].'/</link>'."\r\n"; 218 echo "\t".'<description>'.pun_htmlspecialchars($rss_description.' '.$pun_config['o_board_title']).'</description>'."\r\n"; 219 echo "\t".'<language>en-us</language>'."\r\n"; 220 221 // Fetch 15 topics 222 $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()); 223 224 while ($cur_topic = $db->fetch_assoc($result)) 225 { 226 if ($pun_config['o_censoring'] == '1') 227 $cur_topic['subject'] = censor_words($cur_topic['subject']); 228 229 echo "\t".'<item>'."\r\n"; 230 echo "\t\t".'<title>'.pun_htmlspecialchars($cur_topic['subject']).'</title>'."\r\n"; 231 echo "\t\t".'<link>'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].$url_action.'</link>'."\r\n"; 232 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"; 233 echo "\t".'</item>'."\r\n"; 234 } 235 236 echo '</channel>'."\r\n"; 237 echo '</rss>'; 238 } 239 240 241 // Output regular HTML 278 if ($action == 'feed') 279 { 280 require PUN_ROOT.'include/parser.php'; 281 282 // Determine what type of feed to output 283 $type = isset($_GET['type']) ? strtolower($_GET['type']) : 'html'; 284 if (!in_array($type, array('html', 'rss', 'atom', 'xml'))) 285 $type = 'html'; 286 287 $show = isset($_GET['show']) ? intval($_GET['show']) : 15; 288 if ($show < 1 || $show > 50) 289 $show = 15; 290 291 // Was a topic ID supplied? 292 if (isset($_GET['tid'])) 293 { 294 $tid = intval($_GET['tid']); 295 296 // Fetch topic subject 297 $result = $db->query('SELECT t.subject, t.first_post_id FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL AND t.id='.$tid) or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error()); 298 if (!$db->num_rows($result)) 299 { 300 http_authenticate_user(); 301 exit($lang_common['Bad request']); 302 } 303 304 $cur_topic = $db->fetch_assoc($result); 305 306 if ($pun_config['o_censoring'] == '1') 307 $cur_topic['subject'] = censor_words($cur_topic['subject']); 308 309 // Setup the feed 310 $feed = array( 311 'title' => $pun_config['o_board_title'].$lang_common['Title separator'].$cur_topic['subject'], 312 'link' => get_base_url(true).'/viewtopic.php?id='.$tid, 313 'description' => sprintf($lang_common['RSS description topic'], $cur_topic['subject']), 314 'items' => array(), 315 'type' => 'posts' 316 ); 317 318 // Fetch $show posts 319 $result = $db->query('SELECT p.id, p.poster, p.message, p.hide_smilies, p.posted, p.poster_id, u.email_setting, u.email, p.poster_email FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id WHERE p.topic_id='.$tid.' ORDER BY p.posted DESC LIMIT '.$show) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error()); 320 while ($cur_post = $db->fetch_assoc($result)) 321 { 322 $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']); 323 324 $item = array( 325 'id' => $cur_post['id'], 326 'title' => $cur_topic['first_post_id'] == $cur_post['id'] ? $cur_topic['subject'] : $lang_common['RSS reply'].$cur_topic['subject'], 327 'link' => get_base_url(true).'/viewtopic.php?pid='.$cur_post['id'].'#p'.$cur_post['id'], 328 'description' => $cur_post['message'], 329 'author' => array( 330 'name' => $cur_post['poster'], 331 ), 332 'pubdate' => $cur_post['posted'] 333 ); 334 335 if ($cur_post['poster_id'] > 1) 336 { 337 if ($cur_post['email_setting'] == '0' && !$pun_user['is_guest']) 338 $item['author']['email'] = $cur_post['email']; 339 340 $item['author']['uri'] = get_base_url(true).'/profile.php?id='.$cur_post['poster_id']; 341 } 342 else if ($cur_post['poster_email'] != '' && !$pun_user['is_guest']) 343 $item['author']['email'] = $cur_post['poster_email']; 344 345 $feed['items'][] = $item; 346 } 347 348 $output_func = 'output_'.$type; 349 $output_func($feed); 350 } 242 351 else 243 352 { 244 $show = isset($_GET['show']) ? intval($_GET['show']) : 15; 245 if ($show < 1 || $show > 50) 246 $show = 15; 247 248 // Fetch $show topics 249 $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()); 250 251 while ($cur_topic = $db->fetch_assoc($result)) 252 { 253 if ($pun_config['o_censoring'] == '1') 254 $cur_topic['subject'] = censor_words($cur_topic['subject']); 255 256 if (pun_strlen($cur_topic['subject']) > $max_subject_length) 257 $subject_truncated = pun_htmlspecialchars(trim(substr($cur_topic['subject'], 0, ($max_subject_length-5)))).' ...'; 258 else 259 $subject_truncated = pun_htmlspecialchars($cur_topic['subject']); 260 261 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"; 262 } 263 } 264 265 return; 266 } 267 268 269 // 353 $order_posted = isset($_GET['order']) && strtolower($_GET['order']) == 'posted'; 354 $forum_name = ''; 355 $forum_sql = ''; 356 357 // Were any forum IDs supplied? 358 if (isset($_GET['fid']) && is_scalar($_GET['fid']) && $_GET['fid'] != '') 359 { 360 $fids = explode(',', pun_trim($_GET['fid'])); 361 $fids = array_map('intval', $fids); 362 363 if (!empty($fids)) 364 $forum_sql .= ' AND t.forum_id IN('.implode(',', $fids).')'; 365 366 if (count($fids) == 1) 367 { 368 // Fetch forum name 369 $result = $db->query('SELECT f.forum_name FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$fids[0]) or error('Unable to fetch forum name', __FILE__, __LINE__, $db->error()); 370 if ($db->num_rows($result)) 371 $forum_name = $lang_common['Title separator'].$db->result($result); 372 } 373 } 374 375 // Any forum IDs to exclude? 376 if (isset($_GET['nfid']) && is_scalar($_GET['nfid']) && $_GET['nfid'] != '') 377 { 378 $nfids = explode(',', pun_trim($_GET['nfid'])); 379 $nfids = array_map('intval', $nfids); 380 381 if (!empty($nfids)) 382 $forum_sql .= ' AND t.forum_id NOT IN('.implode(',', $nfids).')'; 383 } 384 385 // Only attempt to cache if caching is enabled and we have all or a single forum 386 if ($pun_config['o_feed_ttl'] > 0 && ($forum_sql == '' || ($forum_name != '' && !isset($_GET['nfid'])))) 387 $cache_id = 'feed'.sha1($pun_user['g_id'].'|'.$lang_common['lang_identifier'].'|'.($order_posted ? '1' : '0').($forum_name == '' ? '' : '|'.$fids[0])); 388 389 // Load cached feed 390 if (isset($cache_id) && file_exists(FORUM_CACHE_DIR.'cache_'.$cache_id.'.php')) 391 include FORUM_CACHE_DIR.'cache_'.$cache_id.'.php'; 392 393 $now = time(); 394 if (!isset($feed) || $cache_expire < $now) 395 { 396 // Setup the feed 397 $feed = array( 398 'title' => $pun_config['o_board_title'].$forum_name, 399 'link' => '/index.php', 400 'description' => sprintf($lang_common['RSS description'], $pun_config['o_board_title']), 401 'items' => array(), 402 'type' => 'topics' 403 ); 404 405 // Fetch $show topics 406 $result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post, t.last_poster, p.message, p.hide_smilies, u.email_setting, u.email, p.poster_id, p.poster_email FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON p.id='.($order_posted ? 't.first_post_id' : 't.last_post_id').' INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL'.$forum_sql.' ORDER BY '.($order_posted ? 't.posted' : 't.last_post').' DESC LIMIT '.(isset($cache_id) ? 50 : $show)) or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error()); 407 while ($cur_topic = $db->fetch_assoc($result)) 408 { 409 if ($pun_config['o_censoring'] == '1') 410 $cur_topic['subject'] = censor_words($cur_topic['subject']); 411 412 $cur_topic['message'] = parse_message($cur_topic['message'], $cur_topic['hide_smilies']); 413 414 $item = array( 415 'id' => $cur_topic['id'], 416 'title' => $cur_topic['subject'], 417 'link' => '/viewtopic.php?id='.$cur_topic['id'].($order_posted ? '' : '&action=new'), 418 'description' => $cur_topic['message'], 419 'author' => array( 420 'name' => $order_posted ? $cur_topic['poster'] : $cur_topic['last_poster'] 421 ), 422 'pubdate' => $order_posted ? $cur_topic['posted'] : $cur_topic['last_post'] 423 ); 424 425 if ($cur_topic['poster_id'] > 1) 426 { 427 if ($cur_topic['email_setting'] == '0' && !$pun_user['is_guest']) 428 $item['author']['email'] = $cur_topic['email']; 429 430 $item['author']['uri'] = '/profile.php?id='.$cur_topic['poster_id']; 431 } 432 else if ($cur_topic['poster_email'] != '' && !$pun_user['is_guest']) 433 $item['author']['email'] = $cur_topic['poster_email']; 434 435 $feed['items'][] = $item; 436 } 437 438 // Output feed as PHP code 439 if (isset($cache_id)) 440 { 441 $fh = @fopen(FORUM_CACHE_DIR.'cache_'.$cache_id.'.php', 'wb'); 442 if (!$fh) 443 error('Unable to write feed cache file to cache directory. Please make sure PHP has write access to the directory \''.pun_htmlspecialchars(FORUM_CACHE_DIR).'\'', __FILE__, __LINE__); 444 445 fwrite($fh, '<?php'."\n\n".'$feed = '.var_export($feed, true).';'."\n\n".'$cache_expire = '.($now + ($pun_config['o_feed_ttl'] * 60)).';'."\n\n".'?>'); 446 447 fclose($fh); 448 449 if (function_exists('apc_delete_file')) 450 @apc_delete_file(FORUM_CACHE_DIR.'cache_'.$cache_id.'.php'); 451 } 452 } 453 454 // If we only want to show a few items but due to caching we have too many 455 if (count($feed['items']) > $show) 456 $feed['items'] = array_slice($feed['items'], 0, $show); 457 458 // Prepend the current base URL onto some links. Done after caching to handle http/https correctly 459 $feed['link'] = get_base_url(true).$feed['link']; 460 461 foreach ($feed['items'] as $key => $item) 462 { 463 $feed['items'][$key]['link'] = get_base_url(true).$item['link']; 464 465 if (isset($item['author']['uri'])) 466 $feed['items'][$key]['author']['uri'] = get_base_url(true).$item['author']['uri']; 467 } 468 469 $output_func = 'output_'.$type; 470 $output_func($feed); 471 } 472 473 exit; 474 } 475 270 476 // Show users online 271 // 272 else if ($_GET['action'] == 'online' || $_GET['action'] == 'online_full') 477 else if ($action == 'online' || $action == 'online_full') 273 478 { 274 479 // Load the index.php language file 275 480 require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php'; 276 481 277 482 // Fetch users online info and generate strings for output 278 483 $num_guests = $num_users = 0; 279 484 $users = array(); 280 $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()); 485 486 $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()); 281 487 282 488 while ($pun_user_online = $db->fetch_assoc($result)) … … 284 490 if ($pun_user_online['user_id'] > 1) 285 491 { 286 $users[] = '<a href="'.$pun_config['o_base_url'].'/profile.php?id='.$pun_user_online['user_id'].'">'.pun_htmlspecialchars($pun_user_online['ident']).'</a>';492 $users[] = ($pun_user['g_view_users'] == '1') ? '<a href="'.pun_htmlspecialchars(get_base_url(true)).'/profile.php?id='.$pun_user_online['user_id'].'">'.pun_htmlspecialchars($pun_user_online['ident']).'</a>' : pun_htmlspecialchars($pun_user_online['ident']); 287 493 ++$num_users; 288 494 } … … 291 497 } 292 498 293 echo $lang_index['Guests online'].': '.$num_guests.'<br />'; 294 295 if ($_GET['action'] == 'online_full') 296 echo $lang_index['Users online'].': '.implode(', ', $users).'<br />'; 499 // Send the Content-type header in case the web server is setup to send something else 500 header('Content-type: text/html; charset=utf-8'); 501 header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 502 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 503 header('Pragma: public'); 504 505 echo sprintf($lang_index['Guests online'], forum_number_format($num_guests)).'<br />'."\n"; 506 507 if ($action == 'online_full' && !empty($users)) 508 echo sprintf($lang_index['Users online'], implode(', ', $users)).'<br />'."\n"; 297 509 else 298 echo $lang_index['Users online'].': '.$num_users.'<br />'; 299 300 return; 301 } 302 303 304 // 510 echo sprintf($lang_index['Users online'], forum_number_format($num_users)).'<br />'."\n"; 511 512 exit; 513 } 514 305 515 // Show board statistics 306 // 307 else if ($_GET['action'] == 'stats') 516 else if ($action == 'stats') 308 517 { 309 518 // Load the index.php language file … … 311 520 312 521 // Collect some statistics from the database 313 $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()); 314 $stats['total_users'] = $db->result($result); 315 316 $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()); 317 $stats['last_user'] = $db->fetch_assoc($result); 318 319 $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()); 522 if (file_exists(FORUM_CACHE_DIR.'cache_users_info.php')) 523 include FORUM_CACHE_DIR.'cache_users_info.php'; 524 525 if (!defined('PUN_USERS_INFO_LOADED')) 526 { 527 if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) 528 require PUN_ROOT.'include/cache.php'; 529 530 generate_users_info_cache(); 531 require FORUM_CACHE_DIR.'cache_users_info.php'; 532 } 533 534 $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()); 320 535 list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result); 321 536 322 echo $lang_index['No of users'].': '.$stats['total_users'].'<br />'; 323 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 />'; 324 echo $lang_index['No of topics'].': '.$stats['total_topics'].'<br />'; 325 echo $lang_index['No of posts'].': '.$stats['total_posts']; 326 327 return; 328 } 329 330 331 else 332 exit('Bad request'); 537 // Send the Content-type header in case the web server is setup to send something else 538 header('Content-type: text/html; charset=utf-8'); 539 header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 540 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 541 header('Pragma: public'); 542 543 echo sprintf($lang_index['No of users'], forum_number_format($stats['total_users'])).'<br />'."\n"; 544 echo sprintf($lang_index['Newest user'], (($pun_user['g_view_users'] == '1') ? '<a href="'.pun_htmlspecialchars(get_base_url(true)).'/profile.php?id='.$stats['last_user']['id'].'">'.pun_htmlspecialchars($stats['last_user']['username']).'</a>' : pun_htmlspecialchars($stats['last_user']['username']))).'<br />'."\n"; 545 echo sprintf($lang_index['No of topics'], forum_number_format($stats['total_topics'])).'<br />'."\n"; 546 echo sprintf($lang_index['No of posts'], forum_number_format($stats['total_posts'])).'<br />'."\n"; 547 548 exit; 549 } 550 551 // If we end up here, the script was called with some wacky parameters 552 exit($lang_common['Bad request']);
Note: See TracChangeset
for help on using the changeset viewer.