PageRenderTime 60ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/nacridan/forum/extern.php

https://gitlab.com/nacridan/Nacridan
PHP | 547 lines | 343 code | 105 blank | 99 comment | 97 complexity | ad2286f82a72d1d4e1368fc3e54f829e MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright (C) 2008-2012 FluxBB
  4. * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
  5. * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  6. */
  7. /*-----------------------------------------------------------------------------
  8. INSTRUCTIONS
  9. This script is used to include information about your board from
  10. pages outside the forums and to syndicate news about recent
  11. discussions via RSS/Atom/XML. The script can display a list of
  12. recent discussions, a list of active users or a collection of
  13. general board statistics. The script can be called directly via
  14. an URL, from a PHP include command or through the use of Server
  15. Side Includes (SSI).
  16. The scripts behaviour is controlled via variables supplied in the
  17. URL to the script. The different variables are: action (what to
  18. do), show (how many items to display), fid (the ID or IDs of
  19. the forum(s) to poll for topics), nfid (the ID or IDs of forums
  20. that should be excluded), tid (the ID of the topic from which to
  21. display posts) and type (output as HTML or RSS). The only
  22. mandatory variable is action. Possible/default values are:
  23. action: feed - show most recent topics/posts (HTML or RSS)
  24. online - show users online (HTML)
  25. online_full - as above, but includes a full list (HTML)
  26. stats - show board statistics (HTML)
  27. type: rss - output as RSS 2.0
  28. atom - output as Atom 1.0
  29. xml - output as XML
  30. html - output as HTML (<li>'s)
  31. fid: One or more forum IDs (comma-separated). If ignored,
  32. topics from all readable forums will be pulled.
  33. nfid: One or more forum IDs (comma-separated) that are to be
  34. excluded. E.g. the ID of a a test forum.
  35. tid: A topic ID from which to show posts. If a tid is supplied,
  36. fid and nfid are ignored.
  37. show: Any integer value between 1 and 50. The default is 15.
  38. order: last_post - show topics ordered by when they were last
  39. posted in, giving information about the reply.
  40. posted - show topics ordered by when they were first
  41. posted, giving information about the original post.
  42. -----------------------------------------------------------------------------*/
  43. define('PUN_QUIET_VISIT', 1);
  44. if (!defined('PUN_ROOT'))
  45. define('PUN_ROOT', dirname(__FILE__).'/');
  46. require PUN_ROOT.'include/common.php';
  47. // The length at which topic subjects will be truncated (for HTML output)
  48. if (!defined('FORUM_EXTERN_MAX_SUBJECT_LENGTH'))
  49. define('FORUM_EXTERN_MAX_SUBJECT_LENGTH', 30);
  50. // If we're a guest and we've sent a username/pass, we can try to authenticate using those details
  51. if ($pun_user['is_guest'] && isset($_SERVER['PHP_AUTH_USER']))
  52. authenticate_user($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
  53. if ($pun_user['g_read_board'] == '0')
  54. {
  55. http_authenticate_user();
  56. exit($lang_common['No view']);
  57. }
  58. $action = isset($_GET['action']) ? strtolower($_GET['action']) : 'feed';
  59. // Handle a couple old formats, from FluxBB 1.2
  60. switch ($action)
  61. {
  62. case 'active':
  63. $action = 'feed';
  64. $_GET['order'] = 'last_post';
  65. break;
  66. case 'new':
  67. $action = 'feed';
  68. $_GET['order'] = 'posted';
  69. break;
  70. }
  71. //
  72. // Sends the proper headers for Basic HTTP Authentication
  73. //
  74. function http_authenticate_user()
  75. {
  76. global $pun_config, $pun_user;
  77. if (!$pun_user['is_guest'])
  78. return;
  79. header('WWW-Authenticate: Basic realm="'.$pun_config['o_board_title'].' External Syndication"');
  80. header('HTTP/1.0 401 Unauthorized');
  81. }
  82. //
  83. // Output $feed as RSS 2.0
  84. //
  85. function output_rss($feed)
  86. {
  87. global $lang_common, $pun_config;
  88. // Send XML/no cache headers
  89. header('Content-Type: application/xml; charset=utf-8');
  90. header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
  91. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  92. header('Pragma: public');
  93. echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
  94. echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'."\n";
  95. echo "\t".'<channel>'."\n";
  96. echo "\t\t".'<atom:link href="'.pun_htmlspecialchars(get_current_url()).'" rel="self" type="application/rss+xml" />'."\n";
  97. echo "\t\t".'<title><![CDATA['.escape_cdata($feed['title']).']]></title>'."\n";
  98. echo "\t\t".'<link>'.pun_htmlspecialchars($feed['link']).'</link>'."\n";
  99. echo "\t\t".'<description><![CDATA['.escape_cdata($feed['description']).']]></description>'."\n";
  100. echo "\t\t".'<lastBuildDate>'.gmdate('r', count($feed['items']) ? $feed['items'][0]['pubdate'] : time()).'</lastBuildDate>'."\n";
  101. if ($pun_config['o_show_version'] == '1')
  102. echo "\t\t".'<generator>FluxBB '.$pun_config['o_cur_version'].'</generator>'."\n";
  103. else
  104. echo "\t\t".'<generator>FluxBB</generator>'."\n";
  105. foreach ($feed['items'] as $item)
  106. {
  107. echo "\t\t".'<item>'."\n";
  108. echo "\t\t\t".'<title><![CDATA['.escape_cdata($item['title']).']]></title>'."\n";
  109. echo "\t\t\t".'<link>'.pun_htmlspecialchars($item['link']).'</link>'."\n";
  110. echo "\t\t\t".'<description><![CDATA['.escape_cdata($item['description']).']]></description>'."\n";
  111. 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";
  112. echo "\t\t\t".'<pubDate>'.gmdate('r', $item['pubdate']).'</pubDate>'."\n";
  113. echo "\t\t\t".'<guid>'.pun_htmlspecialchars($item['link']).'</guid>'."\n";
  114. echo "\t\t".'</item>'."\n";
  115. }
  116. echo "\t".'</channel>'."\n";
  117. echo '</rss>'."\n";
  118. }
  119. //
  120. // Output $feed as Atom 1.0
  121. //
  122. function output_atom($feed)
  123. {
  124. global $lang_common, $pun_config;
  125. // Send XML/no cache headers
  126. header('Content-Type: application/atom+xml; charset=utf-8');
  127. header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
  128. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  129. header('Pragma: public');
  130. echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
  131. echo '<feed xmlns="http://www.w3.org/2005/Atom">'."\n";
  132. echo "\t".'<title type="html"><![CDATA['.escape_cdata($feed['title']).']]></title>'."\n";
  133. echo "\t".'<link rel="self" href="'.pun_htmlspecialchars(get_current_url()).'"/>'."\n";
  134. echo "\t".'<link href="'.pun_htmlspecialchars($feed['link']).'"/>'."\n";
  135. echo "\t".'<updated>'.gmdate('Y-m-d\TH:i:s\Z', count($feed['items']) ? $feed['items'][0]['pubdate'] : time()).'</updated>'."\n";
  136. if ($pun_config['o_show_version'] == '1')
  137. echo "\t".'<generator version="'.$pun_config['o_cur_version'].'">FluxBB</generator>'."\n";
  138. else
  139. echo "\t".'<generator>FluxBB</generator>'."\n";
  140. echo "\t".'<id>'.pun_htmlspecialchars($feed['link']).'</id>'."\n";
  141. $content_tag = ($feed['type'] == 'posts') ? 'content' : 'summary';
  142. foreach ($feed['items'] as $item)
  143. {
  144. echo "\t".'<entry>'."\n";
  145. echo "\t\t".'<title type="html"><![CDATA['.escape_cdata($item['title']).']]></title>'."\n";
  146. echo "\t\t".'<link rel="alternate" href="'.pun_htmlspecialchars($item['link']).'"/>'."\n";
  147. echo "\t\t".'<'.$content_tag.' type="html"><![CDATA['.escape_cdata($item['description']).']]></'.$content_tag.'>'."\n";
  148. echo "\t\t".'<author>'."\n";
  149. echo "\t\t\t".'<name><![CDATA['.escape_cdata($item['author']['name']).']]></name>'."\n";
  150. if (isset($item['author']['email']))
  151. echo "\t\t\t".'<email><![CDATA['.escape_cdata($item['author']['email']).']]></email>'."\n";
  152. if (isset($item['author']['uri']))
  153. echo "\t\t\t".'<uri>'.pun_htmlspecialchars($item['author']['uri']).'</uri>'."\n";
  154. echo "\t\t".'</author>'."\n";
  155. echo "\t\t".'<updated>'.gmdate('Y-m-d\TH:i:s\Z', $item['pubdate']).'</updated>'."\n";
  156. echo "\t\t".'<id>'.pun_htmlspecialchars($item['link']).'</id>'."\n";
  157. echo "\t".'</entry>'."\n";
  158. }
  159. echo '</feed>'."\n";
  160. }
  161. //
  162. // Output $feed as XML
  163. //
  164. function output_xml($feed)
  165. {
  166. global $lang_common, $pun_config;
  167. // Send XML/no cache headers
  168. header('Content-Type: application/xml; charset=utf-8');
  169. header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
  170. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  171. header('Pragma: public');
  172. echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
  173. echo '<source>'."\n";
  174. echo "\t".'<url>'.pun_htmlspecialchars($feed['link']).'</url>'."\n";
  175. $forum_tag = ($feed['type'] == 'posts') ? 'post' : 'topic';
  176. foreach ($feed['items'] as $item)
  177. {
  178. echo "\t".'<'.$forum_tag.' id="'.$item['id'].'">'."\n";
  179. echo "\t\t".'<title><![CDATA['.escape_cdata($item['title']).']]></title>'."\n";
  180. echo "\t\t".'<link>'.pun_htmlspecialchars($item['link']).'</link>'."\n";
  181. echo "\t\t".'<content><![CDATA['.escape_cdata($item['description']).']]></content>'."\n";
  182. echo "\t\t".'<author>'."\n";
  183. echo "\t\t\t".'<name><![CDATA['.escape_cdata($item['author']['name']).']]></name>'."\n";
  184. if (isset($item['author']['email']))
  185. echo "\t\t\t".'<email><![CDATA['.escape_cdata($item['author']['email']).']]></email>'."\n";
  186. if (isset($item['author']['uri']))
  187. echo "\t\t\t".'<uri>'.pun_htmlspecialchars($item['author']['uri']).'</uri>'."\n";
  188. echo "\t\t".'</author>'."\n";
  189. echo "\t\t".'<posted>'.gmdate('r', $item['pubdate']).'</posted>'."\n";
  190. echo "\t".'</'.$forum_tag.'>'."\n";
  191. }
  192. echo '</source>'."\n";
  193. }
  194. //
  195. // Output $feed as HTML (using <li> tags)
  196. //
  197. function output_html($feed)
  198. {
  199. // Send the Content-type header in case the web server is setup to send something else
  200. header('Content-type: text/html; charset=utf-8');
  201. header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
  202. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  203. header('Pragma: public');
  204. foreach ($feed['items'] as $item)
  205. {
  206. if (utf8_strlen($item['title']) > FORUM_EXTERN_MAX_SUBJECT_LENGTH)
  207. $subject_truncated = pun_htmlspecialchars(pun_trim(utf8_substr($item['title'], 0, (FORUM_EXTERN_MAX_SUBJECT_LENGTH - 5)))).' …';
  208. else
  209. $subject_truncated = pun_htmlspecialchars($item['title']);
  210. echo '<li><a href="'.pun_htmlspecialchars($item['link']).'" title="'.pun_htmlspecialchars($item['title']).'">'.$subject_truncated.'</a></li>'."\n";
  211. }
  212. }
  213. // Show recent discussions
  214. if ($action == 'feed')
  215. {
  216. require PUN_ROOT.'include/parser.php';
  217. // Determine what type of feed to output
  218. $type = isset($_GET['type']) ? strtolower($_GET['type']) : 'html';
  219. if (!in_array($type, array('html', 'rss', 'atom', 'xml')))
  220. $type = 'html';
  221. $show = isset($_GET['show']) ? intval($_GET['show']) : 15;
  222. if ($show < 1 || $show > 50)
  223. $show = 15;
  224. // Was a topic ID supplied?
  225. if (isset($_GET['tid']))
  226. {
  227. $tid = intval($_GET['tid']);
  228. // Fetch topic subject
  229. $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());
  230. if (!$db->num_rows($result))
  231. {
  232. http_authenticate_user();
  233. exit($lang_common['Bad request']);
  234. }
  235. $cur_topic = $db->fetch_assoc($result);
  236. if ($pun_config['o_censoring'] == '1')
  237. $cur_topic['subject'] = censor_words($cur_topic['subject']);
  238. // Setup the feed
  239. $feed = array(
  240. 'title' => $pun_config['o_board_title'].$lang_common['Title separator'].$cur_topic['subject'],
  241. 'link' => get_base_url(true).'/viewtopic.php?id='.$tid,
  242. 'description' => sprintf($lang_common['RSS description topic'], $cur_topic['subject']),
  243. 'items' => array(),
  244. 'type' => 'posts'
  245. );
  246. // Fetch $show posts
  247. $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());
  248. while ($cur_post = $db->fetch_assoc($result))
  249. {
  250. $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
  251. $item = array(
  252. 'id' => $cur_post['id'],
  253. 'title' => $cur_topic['first_post_id'] == $cur_post['id'] ? $cur_topic['subject'] : $lang_common['RSS reply'].$cur_topic['subject'],
  254. 'link' => get_base_url(true).'/viewtopic.php?pid='.$cur_post['id'].'#p'.$cur_post['id'],
  255. 'description' => $cur_post['message'],
  256. 'author' => array(
  257. 'name' => $cur_post['poster'],
  258. ),
  259. 'pubdate' => $cur_post['posted']
  260. );
  261. if ($cur_post['poster_id'] > 1)
  262. {
  263. if ($cur_post['email_setting'] == '0' && !$pun_user['is_guest'])
  264. $item['author']['email'] = $cur_post['email'];
  265. $item['author']['uri'] = get_base_url(true).'/profile.php?id='.$cur_post['poster_id'];
  266. }
  267. else if ($cur_post['poster_email'] != '' && !$pun_user['is_guest'])
  268. $item['author']['email'] = $cur_post['poster_email'];
  269. $feed['items'][] = $item;
  270. }
  271. $output_func = 'output_'.$type;
  272. $output_func($feed);
  273. }
  274. else
  275. {
  276. $order_posted = isset($_GET['order']) && strtolower($_GET['order']) == 'posted';
  277. $forum_name = '';
  278. $forum_sql = '';
  279. // Were any forum IDs supplied?
  280. if (isset($_GET['fid']) && is_scalar($_GET['fid']) && $_GET['fid'] != '')
  281. {
  282. $fids = explode(',', pun_trim($_GET['fid']));
  283. $fids = array_map('intval', $fids);
  284. if (!empty($fids))
  285. $forum_sql .= ' AND t.forum_id IN('.implode(',', $fids).')';
  286. if (count($fids) == 1)
  287. {
  288. // Fetch forum name
  289. $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());
  290. if ($db->num_rows($result))
  291. $forum_name = $lang_common['Title separator'].$db->result($result);
  292. }
  293. }
  294. // Any forum IDs to exclude?
  295. if (isset($_GET['nfid']) && is_scalar($_GET['nfid']) && $_GET['nfid'] != '')
  296. {
  297. $nfids = explode(',', pun_trim($_GET['nfid']));
  298. $nfids = array_map('intval', $nfids);
  299. if (!empty($nfids))
  300. $forum_sql .= ' AND t.forum_id NOT IN('.implode(',', $nfids).')';
  301. }
  302. // Only attempt to cache if caching is enabled and we have all or a single forum
  303. if ($pun_config['o_feed_ttl'] > 0 && ($forum_sql == '' || ($forum_name != '' && !isset($_GET['nfid']))))
  304. $cache_id = 'feed'.sha1($pun_user['g_id'].'|'.$lang_common['lang_identifier'].'|'.($order_posted ? '1' : '0').($forum_name == '' ? '' : '|'.$fids[0]));
  305. // Load cached feed
  306. if (isset($cache_id) && file_exists(FORUM_CACHE_DIR.'cache_'.$cache_id.'.php'))
  307. include FORUM_CACHE_DIR.'cache_'.$cache_id.'.php';
  308. $now = time();
  309. if (!isset($feed) || $cache_expire < $now)
  310. {
  311. // Setup the feed
  312. $feed = array(
  313. 'title' => $pun_config['o_board_title'].$forum_name,
  314. 'link' => '/index.php',
  315. 'description' => sprintf($lang_common['RSS description'], $pun_config['o_board_title']),
  316. 'items' => array(),
  317. 'type' => 'topics'
  318. );
  319. // Fetch $show topics
  320. $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());
  321. while ($cur_topic = $db->fetch_assoc($result))
  322. {
  323. if ($pun_config['o_censoring'] == '1')
  324. $cur_topic['subject'] = censor_words($cur_topic['subject']);
  325. $cur_topic['message'] = parse_message($cur_topic['message'], $cur_topic['hide_smilies']);
  326. $item = array(
  327. 'id' => $cur_topic['id'],
  328. 'title' => $cur_topic['subject'],
  329. 'link' => '/viewtopic.php?id='.$cur_topic['id'].($order_posted ? '' : '&action=new'),
  330. 'description' => $cur_topic['message'],
  331. 'author' => array(
  332. 'name' => $order_posted ? $cur_topic['poster'] : $cur_topic['last_poster']
  333. ),
  334. 'pubdate' => $order_posted ? $cur_topic['posted'] : $cur_topic['last_post']
  335. );
  336. if ($cur_topic['poster_id'] > 1)
  337. {
  338. if ($cur_topic['email_setting'] == '0' && !$pun_user['is_guest'])
  339. $item['author']['email'] = $cur_topic['email'];
  340. $item['author']['uri'] = '/profile.php?id='.$cur_topic['poster_id'];
  341. }
  342. else if ($cur_topic['poster_email'] != '' && !$pun_user['is_guest'])
  343. $item['author']['email'] = $cur_topic['poster_email'];
  344. $feed['items'][] = $item;
  345. }
  346. // Output feed as PHP code
  347. if (isset($cache_id))
  348. {
  349. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  350. require PUN_ROOT.'include/cache.php';
  351. $content = '<?php'."\n\n".'$feed = '.var_export($feed, true).';'."\n\n".'$cache_expire = '.($now + ($pun_config['o_feed_ttl'] * 60)).';'."\n\n".'?>';
  352. fluxbb_write_cache_file('cache_'.$cache_id.'.php', $content);
  353. }
  354. }
  355. // If we only want to show a few items but due to caching we have too many
  356. if (count($feed['items']) > $show)
  357. $feed['items'] = array_slice($feed['items'], 0, $show);
  358. // Prepend the current base URL onto some links. Done after caching to handle http/https correctly
  359. $feed['link'] = get_base_url(true).$feed['link'];
  360. foreach ($feed['items'] as $key => $item)
  361. {
  362. $feed['items'][$key]['link'] = get_base_url(true).$item['link'];
  363. if (isset($item['author']['uri']))
  364. $feed['items'][$key]['author']['uri'] = get_base_url(true).$item['author']['uri'];
  365. }
  366. $output_func = 'output_'.$type;
  367. $output_func($feed);
  368. }
  369. exit;
  370. }
  371. // Show users online
  372. else if ($action == 'online' || $action == 'online_full')
  373. {
  374. // Load the index.php language file
  375. require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php';
  376. // Fetch users online info and generate strings for output
  377. $num_guests = $num_users = 0;
  378. $users = array();
  379. $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());
  380. while ($pun_user_online = $db->fetch_assoc($result))
  381. {
  382. if ($pun_user_online['user_id'] > 1)
  383. {
  384. $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']);
  385. ++$num_users;
  386. }
  387. else
  388. ++$num_guests;
  389. }
  390. // Send the Content-type header in case the web server is setup to send something else
  391. header('Content-type: text/html; charset=utf-8');
  392. header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
  393. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  394. header('Pragma: public');
  395. echo sprintf($lang_index['Guests online'], forum_number_format($num_guests)).'<br />'."\n";
  396. if ($action == 'online_full' && !empty($users))
  397. echo sprintf($lang_index['Users online'], implode(', ', $users)).'<br />'."\n";
  398. else
  399. echo sprintf($lang_index['Users online'], forum_number_format($num_users)).'<br />'."\n";
  400. exit;
  401. }
  402. // Show board statistics
  403. else if ($action == 'stats')
  404. {
  405. // Load the index.php language file
  406. require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php';
  407. // Collect some statistics from the database
  408. if (file_exists(FORUM_CACHE_DIR.'cache_users_info.php'))
  409. include FORUM_CACHE_DIR.'cache_users_info.php';
  410. if (!defined('PUN_USERS_INFO_LOADED'))
  411. {
  412. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  413. require PUN_ROOT.'include/cache.php';
  414. generate_users_info_cache();
  415. require FORUM_CACHE_DIR.'cache_users_info.php';
  416. }
  417. $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());
  418. list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);
  419. // Send the Content-type header in case the web server is setup to send something else
  420. header('Content-type: text/html; charset=utf-8');
  421. header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
  422. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  423. header('Pragma: public');
  424. echo sprintf($lang_index['No of users'], forum_number_format($stats['total_users'])).'<br />'."\n";
  425. 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";
  426. echo sprintf($lang_index['No of topics'], forum_number_format($stats['total_topics'])).'<br />'."\n";
  427. echo sprintf($lang_index['No of posts'], forum_number_format($stats['total_posts'])).'<br />'."\n";
  428. exit;
  429. }
  430. // If we end up here, the script was called with some wacky parameters
  431. exit($lang_common['Bad request']);