source: branches/rsr.v5.1.dev/web/punbb/extern.php @ 3

Last change on this file since 3 was 3, checked in by dj3c1t, 12 years ago

passage a Fluxbb 1.4.7

File size: 20.8 KB
RevLine 
[1]1<?php
2
[3]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 */
[1]8
[3]9/*-----------------------------------------------------------------------------
[1]10
[3]11  INSTRUCTIONS
[1]12
[3]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).
[1]20
[3]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:
[1]28
[3]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)
[1]33
[3]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)
[1]38
[3]39        fid:    One or more forum IDs (comma-separated). If ignored,
40                        topics from all readable forums will be pulled.
[1]41
[3]42        nfid:   One or more forum IDs (comma-separated) that are to be
43                        excluded. E.g. the ID of a a test forum.
[1]44
[3]45        tid:    A topic ID from which to show posts. If a tid is supplied,
46                        fid and nfid are ignored.
[1]47
[3]48        show:   Any integer value between 1 and 50. The default is 15.
[1]49
[3]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.
[1]54
[3]55-----------------------------------------------------------------------------*/
[1]56
[3]57define('PUN_QUIET_VISIT', 1);
[1]58
[3]59if (!defined('PUN_ROOT'))
60        define('PUN_ROOT', dirname(__FILE__).'/');
61require PUN_ROOT.'include/common.php';
[1]62
[3]63// The length at which topic subjects will be truncated (for HTML output)
64if (!defined('FORUM_EXTERN_MAX_SUBJECT_LENGTH'))
65        define('FORUM_EXTERN_MAX_SUBJECT_LENGTH', 30);
[1]66
[3]67// If we're a guest and we've sent a username/pass, we can try to authenticate using those details
68if ($pun_user['is_guest'] && isset($_SERVER['PHP_AUTH_USER']))
69        authenticate_user($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
[1]70
[3]71if ($pun_user['g_read_board'] == '0')
72{
73        http_authenticate_user();
74        exit($lang_common['No view']);
75}
[1]76
[3]77$action = isset($_GET['action']) ? strtolower($_GET['action']) : 'feed';
[1]78
[3]79// Handle a couple old formats, from FluxBB 1.2
80switch ($action)
81{
82        case 'active':
83                $action = 'feed';
84                $_GET['order'] = 'last_post';
85                break;
[1]86
[3]87        case 'new':
88                $action = 'feed';
89                $_GET['order'] = 'posted';
90                break;
91}
[1]92
[3]93//
94// Sends the proper headers for Basic HTTP Authentication
95//
96function http_authenticate_user()
97{
98        global $pun_config, $pun_user;
[1]99
[3]100        if (!$pun_user['is_guest'])
101                return;
[1]102
[3]103        header('WWW-Authenticate: Basic realm="'.$pun_config['o_board_title'].' External Syndication"');
104        header('HTTP/1.0 401 Unauthorized');
105}
[1]106
107
[3]108//
109// Output $feed as RSS 2.0
110//
111function output_rss($feed)
112{
113        global $lang_common, $pun_config;
[1]114
[3]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');
[1]120
[3]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";
[1]129
[3]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";
[1]134
[3]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";
[1]144
[3]145                echo "\t\t".'</item>'."\n";
146        }
[1]147
[3]148        echo "\t".'</channel>'."\n";
149        echo '</rss>'."\n";
150}
[1]151
152
[3]153//
154// Output $feed as Atom 1.0
155//
156function output_atom($feed)
157{
158        global $lang_common, $pun_config;
[1]159
[3]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');
[1]165
[3]166        echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
167        echo '<feed xmlns="http://www.w3.org/2005/Atom">'."\n";
[1]168
[3]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";
[1]173
[3]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";
[1]178
[3]179        echo "\t".'<id>'.pun_htmlspecialchars($feed['link']).'</id>'."\n";
[1]180
[3]181        $content_tag = ($feed['type'] == 'posts') ? 'content' : 'summary';
[1]182
[3]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";
[1]191
[3]192                if (isset($item['author']['email']))
193                        echo "\t\t\t".'<email><![CDATA['.escape_cdata($item['author']['email']).']]></email>'."\n";
[1]194
[3]195                if (isset($item['author']['uri']))
196                        echo "\t\t\t".'<uri>'.pun_htmlspecialchars($item['author']['uri']).'</uri>'."\n";
[1]197
[3]198                echo "\t\t".'</author>'."\n";
199                echo "\t\t".'<updated>'.gmdate('Y-m-d\TH:i:s\Z', $item['pubdate']).'</updated>'."\n";
[1]200
[3]201                echo "\t\t".'<id>'.pun_htmlspecialchars($item['link']).'</id>'."\n";
202                echo "\t".'</entry>'."\n";
203        }
[1]204
[3]205        echo '</feed>'."\n";
[1]206}
207
208
[3]209//
210// Output $feed as XML
211//
212function output_xml($feed)
213{
214        global $lang_common, $pun_config;
[1]215
[3]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');
[1]221
[3]222        echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
223        echo '<source>'."\n";
224        echo "\t".'<url>'.pun_htmlspecialchars($feed['link']).'</url>'."\n";
[1]225
[3]226        $forum_tag = ($feed['type'] == 'posts') ? 'post' : 'topic';
[1]227
[3]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";
[1]251}
252
253
254//
[3]255// Output $feed as HTML (using <li> tags)
[1]256//
[3]257function output_html($feed)
[1]258{
259
[3]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)
[1]267        {
[3]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']);
[1]272
[3]273                echo '<li><a href="'.pun_htmlspecialchars($item['link']).'" title="'.pun_htmlspecialchars($item['title']).'">'.$subject_truncated.'</a></li>'."\n";
[1]274        }
[3]275}
[1]276
[3]277// Show recent discussions
278if ($action == 'feed')
279{
280        require PUN_ROOT.'include/parser.php';
[1]281
[3]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';
[1]286
[3]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']))
[1]293        {
[3]294                $tid = intval($_GET['tid']);
[1]295
[3]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                }
[1]303
[3]304                $cur_topic = $db->fetch_assoc($result);
[1]305
[3]306                if ($pun_config['o_censoring'] == '1')
307                        $cur_topic['subject'] = censor_words($cur_topic['subject']);
[1]308
[3]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))
[1]321                {
[3]322                        $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
[1]323
[3]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;
[1]346                }
347
[3]348                $output_func = 'output_'.$type;
349                $output_func($feed);
[1]350        }
351        else
352        {
[3]353                $order_posted = isset($_GET['order']) && strtolower($_GET['order']) == 'posted';
354                $forum_name = '';
355                $forum_sql = '';
[1]356
[3]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);
[1]362
[3]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'] != '')
[1]377                {
[3]378                        $nfids = explode(',', pun_trim($_GET['nfid']));
379                        $nfids = array_map('intval', $nfids);
[1]380
[3]381                        if (!empty($nfids))
382                                $forum_sql .= ' AND t.forum_id NOT IN('.implode(',', $nfids).')';
383                }
[1]384
[3]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                        }
[1]452                }
[3]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);
[1]471        }
472
[3]473        exit;
[1]474}
475
476// Show users online
[3]477else if ($action == 'online' || $action == 'online_full')
[1]478{
479        // Load the index.php language file
480        require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php';
[3]481
[1]482        // Fetch users online info and generate strings for output
483        $num_guests = $num_users = 0;
484        $users = array();
485
[3]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());
487
[1]488        while ($pun_user_online = $db->fetch_assoc($result))
489        {
490                if ($pun_user_online['user_id'] > 1)
491                {
[3]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']);
[1]493                        ++$num_users;
494                }
495                else
496                        ++$num_guests;
497        }
498
[3]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');
[1]504
[3]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";
[1]509        else
[3]510                echo sprintf($lang_index['Users online'], forum_number_format($num_users)).'<br />'."\n";
[1]511
[3]512        exit;
[1]513}
514
515// Show board statistics
[3]516else if ($action == 'stats')
[1]517{
518        // Load the index.php language file
519        require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php';
520
521        // Collect some statistics from the database
[3]522        if (file_exists(FORUM_CACHE_DIR.'cache_users_info.php'))
523                include FORUM_CACHE_DIR.'cache_users_info.php';
[1]524
[3]525        if (!defined('PUN_USERS_INFO_LOADED'))
526        {
527                if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
528                        require PUN_ROOT.'include/cache.php';
[1]529
[3]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());
[1]535        list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);
536
[3]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');
[1]542
[3]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;
[1]549}
550
[3]551// If we end up here, the script was called with some wacky parameters
552exit($lang_common['Bad request']);
Note: See TracBrowser for help on using the repository browser.