This repository has been archived by the owner on Aug 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrss.php
371 lines (277 loc) · 12.9 KB
/
rss.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<?php
/*
Copyright (C) 2003-2012 UseBB Team
http://www.usebb.net
$Id$
This file is part of UseBB.
UseBB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
UseBB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UseBB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* RSS feed
*
* Parses RSS 2.0 feeds
*
* @author UseBB Team
* @link http://www.usebb.net
* @license GPL-2
* @version $Revision$
* @copyright Copyright (C) 2003-2012 UseBB Team
* @package UseBB
*/
define('INCLUDED', true);
define('ROOT_PATH', './');
//
// Don't use gzip for the feed
//
define('NO_GZIP', true);
//
// Include usebb engine
//
require(ROOT_PATH.'sources/common.php');
//
// Fetch the language array
//
$lang = $functions->fetch_language();
//
// Set the xml content type and only parse the xml templates
//
$template->content_type = 'application/rss+xml';
$template->parse_special_templates_only = true;
//
// Error page for the RSS feed
// Don't use the templated pages for RSS readers
//
function usebb_rss_error($num) {
switch ( $num ) {
case 403:
header(HEADER_403);
die('<h1>403 Forbidden</h1>');
break;
case 404:
header(HEADER_404);
die('<h1>404 Not Found</h1>');
}
}
function usebb_check_rss_access() {
global $session, $functions;
//
// Make a Forbidden header when the RSS feed cannot be requested
//
if ( $session->sess_info['ip_banned'] || $functions->get_config('board_closed') || ( !$functions->get_config('guests_can_access_board') && $functions->get_user_level() == LEVEL_GUEST ) )
usebb_rss_error(403);
}
$pubDate = $functions->make_date(time(), 'D, d M Y H:i:s', true, false).' GMT';
//
// Absolute template gfx directory
//
$template->add_global_vars(array('img_dir' => $functions->get_config('board_url').str_replace('./', '', ROOT_PATH).'templates/'.$functions->get_config('template').'/gfx/'));
//
// Figure out what feed to show
//
if ( !empty($_GET['forum']) && valid_int($_GET['forum']) ) {
//
// Show a feed for a forum
//
$session->update('rss-forum:'.$_GET['forum']);
usebb_check_rss_access();
if ( !$functions->get_config('enable_rss_per_forum') )
usebb_rss_error(404);
//
// Get information about the forum
//
$result = $db->query("SELECT id, name, descr, auth FROM ".TABLE_PREFIX."forums WHERE id = ".$_GET['forum']);
$forumdata = $db->fetch_result($result);
//
// Forum does not exist
//
if ( !$forumdata['id'] )
usebb_rss_error(404);
//
// Forum is not accessible
//
if ( !$functions->auth($forumdata['auth'], 'view', $_GET['forum']) )
usebb_rss_error(403);
$forum_name = unhtml(stripslashes($forumdata['name']), true);
$forum_link = $functions->get_config('board_url').$functions->make_url('forum.php', array('id' => $_GET['forum']), true, false);
$header_vars = array(
'board_name' => unhtml($functions->get_config('board_name').': '.stripslashes($forumdata['name']), true),
// Stripping tags, Firefox doesn't show the description when it has tags.
'board_descr' => named_entities_to_numeric(strip_tags(stripslashes($forumdata['descr']))),
'board_url' => $forum_link,
'pubDate' => $pubDate,
'link_rss' => $functions->get_config('board_url').$functions->make_url('rss.php', array('forum' => $_GET['forum']), true, false),
);
$template->parse('header', 'rss', $header_vars, true);
//
// Get the topics
//
if ( $functions->auth($forumdata['auth'], 'read', $_GET['forum']) ) {
$can_read = true;
$add_to_query = array("p.content", "p.enable_bbcode", "p.enable_smilies", "p.enable_html", "m.level AS poster_level", "m.active");
} else {
$can_read = false;
$add_to_query = array();
}
$add_to_query = count($add_to_query) ? ', '.implode(', ', $add_to_query) : '';
$result = $db->query("SELECT t.id, t.topic_title, p.poster_id, p.poster_guest, p.post_time, m.displayed_name".$add_to_query." FROM ".TABLE_PREFIX."topics t LEFT JOIN ".TABLE_PREFIX."posts p ON t.first_post_id = p.id LEFT JOIN ".TABLE_PREFIX."members m ON p.poster_id = m.id WHERE t.forum_id = ".$_GET['forum']." ORDER BY p.post_time DESC LIMIT ".$functions->get_config('rss_items_count'));
while ( $topicdata = $db->fetch_result($result) ) {
$link = $functions->get_config('board_url').$functions->make_url('topic.php', array('id' => $topicdata['id']), true, false);
$can_post_links = $can_read && $functions->antispam_can_post_links($topicdata);
$template->parse('topic', 'rss', array(
'title' => unhtml($functions->replace_badwords(stripslashes($topicdata['topic_title'])), true),
'description' => $can_read ? $functions->markup($functions->replace_badwords(stripslashes($topicdata['content'])), $topicdata['enable_bbcode'], $topicdata['enable_smilies'], $topicdata['enable_html'], true, $can_post_links) : '',
// <author> was renamed to <dc:creator> in the default template to keep validity.
'author' => unhtml(stripslashes( ( !empty($topicdata['poster_id']) ) ? $topicdata['displayed_name'] : $topicdata['poster_guest']), true),
'link' => $link,
// <comments> was removed from the default template because it was used incorrectly (not for posting comments).
'comments' => $link,
'category' => $forum_name,
'category_domain' => $forum_link,
'pubDate' => $functions->make_date($topicdata['post_time'], 'D, d M Y H:i:s', true, false).' GMT',
'guid' => $link
), true);
}
$template->parse('footer', 'rss', $header_vars, true);
} elseif ( !empty($_GET['topic']) && valid_int($_GET['topic']) ) {
//
// Show a feed for a topic
//
$session->update('rss-topic:'.$_GET['topic']);
usebb_check_rss_access();
if ( !$functions->get_config('enable_rss_per_topic') )
usebb_rss_error(404);
//
// Get information about the topic and forum
//
$result = $db->query("SELECT t.id, t.forum_id, t.topic_title, t.first_post_id, f.name AS forum_name, f.auth FROM ".TABLE_PREFIX."forums f, ".TABLE_PREFIX."topics t WHERE f.id = t.forum_id AND t.id = ".$_GET['topic']);
$topicdata = $db->fetch_result($result);
//
// Topic does not exist
//
if ( !$topicdata['id'] )
usebb_rss_error(404);
//
// Topic is not accessible
//
if ( !$functions->auth($topicdata['auth'], 'read', $topicdata['forum_id']) )
usebb_rss_error(403);
$topic_name = unhtml(stripslashes($topicdata['topic_title']), true);
$topic_link = $functions->get_config('board_url').$functions->make_url('topic.php', array('id' => $_GET['topic']), true, false);
$header_vars = array(
'board_name' => unhtml($functions->get_config('board_name'), true).': '.unhtml(stripslashes($topicdata['topic_title']), true),
'board_descr' => '',
'board_url' => $topic_link,
'pubDate' => $pubDate,
'link_rss' => $functions->get_config('board_url').$functions->make_url('rss.php', array('topic' => $_GET['topic']), true, false),
);
$template->parse('header', 'rss', $header_vars, true);
//
// Get the posts
//
$result = $db->query("SELECT p.id, p.poster_id, p.poster_guest, p.content, p.post_time, p.enable_bbcode, p.enable_smilies, p.enable_html, m.displayed_name, m.level AS poster_level, m.active FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."members m ON p.poster_id = m.id WHERE p.topic_id = ".$_GET['topic']." ORDER BY p.post_time DESC LIMIT ".$functions->get_config('rss_items_count'));
while ( $postdata = $db->fetch_result($result) ) {
$title = unhtml($functions->replace_badwords(stripslashes($topicdata['topic_title'])), true);
$title = ( ( $postdata['id'] != $topicdata['first_post_id'] ) ? $lang['Re'].' ' : '' ) . $title;
$link = $functions->get_config('board_url').$functions->make_url('topic.php', array('post' => $postdata['id']), true, false).'#post'.$postdata['id'];
$can_post_links = $functions->antispam_can_post_links($postdata);
$template->parse('topic', 'rss', array(
'title' => $title,
'description' => $functions->markup($functions->replace_badwords(stripslashes($postdata['content'])), $postdata['enable_bbcode'], $postdata['enable_smilies'], $postdata['enable_html'], true, $can_post_links),
// <author> was renamed to <dc:creator> in the default template to keep validity.
'author' => unhtml(stripslashes( ( !empty($postdata['poster_id']) ) ? $postdata['displayed_name'] : $postdata['poster_guest']), true),
'link' => $link,
// <comments> was removed from the default template because it was used incorrectly (not for posting comments).
'comments' => $link,
'category' => $topic_name,
'category_domain' => $topic_link,
'pubDate' => $functions->make_date($postdata['post_time'], 'D, d M Y H:i:s', true, false).' GMT',
'guid' => $link
), true);
}
$template->parse('footer', 'rss', $header_vars, true);
} else {
//
// Show a regular active topics feed
//
$session->update('rss');
usebb_check_rss_access();
if ( !$functions->get_config('enable_rss') )
usebb_rss_error(404);
//
// Excluded forums
//
$exclude_forums = $functions->get_config('exclude_forums_rss');
$exclude_forums_query_part = ( is_array($exclude_forums) && count($exclude_forums) ) ? " WHERE id NOT IN (".join(', ', $exclude_forums).")" : '';
//
// Get a list of forums
//
$result = $db->query("SELECT id, name, auth FROM ".TABLE_PREFIX."forums".$exclude_forums_query_part);
$forum_ids = $forum_names = array();
while ( $forumdata = $db->fetch_result($result) ) {
//
// Place permitted forums into the arrays
//
if ( $functions->auth($forumdata['auth'], 'read', $forumdata['id']) ) {
$forum_ids[] = $forumdata['id'];
$forum_names[$forumdata['id']] = $forumdata['name'];
}
}
//
// No viewable forums
//
if ( !count($forum_ids) )
usebb_rss_error(403);
$header_vars = array(
'board_name' => unhtml($functions->get_config('board_name'), true),
'board_descr' => unhtml($functions->get_config('board_descr'), true),
'board_url' => $functions->get_config('board_url'),
'pubDate' => $pubDate,
'link_rss' => $functions->get_config('board_url').$functions->make_url('rss.php', null, true, false),
);
$template->parse('header', 'rss', $header_vars, true);
$result = $db->query("SELECT p.id AS post_id, p.topic_id, t.forum_id, t.topic_title, t.count_replies, p.content, p.enable_bbcode, p.enable_smilies, p.enable_html, p.poster_id, m.displayed_name AS last_poster_name, m.level AS poster_level, m.active, p.poster_guest AS last_poster_guest, p.post_time FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."members m ON p.poster_id = m.id, ".TABLE_PREFIX."topics t WHERE t.forum_id IN(".join(', ', $forum_ids).") AND t.id = p.topic_id ORDER BY p.post_time DESC LIMIT ".$functions->get_config('rss_items_count'));
$reply_counts = array();
while ( $topicdata = $db->fetch_result($result) ) {
if ( !array_key_exists($topicdata['topic_id'], $reply_counts) )
$reply_counts[$topicdata['topic_id']] = $topicdata['count_replies'];
else
$reply_counts[$topicdata['topic_id']]--;
$title = unhtml($functions->replace_badwords(stripslashes($topicdata['topic_title'])), true);
if ( $reply_counts[$topicdata['topic_id']] )
$title = $lang['Re'].' '.$title;
$link = $functions->get_config('board_url').$functions->make_url('topic.php', array('post' => $topicdata['post_id']), true, false).'#post'.$topicdata['post_id'];
$can_post_links = $functions->antispam_can_post_links($topicdata);
//
// Parse the topic template
//
$template->parse('topic', 'rss', array(
'title' => $title,
'description' => $functions->markup($functions->replace_badwords(stripslashes($topicdata['content'])), $topicdata['enable_bbcode'], $topicdata['enable_smilies'], $topicdata['enable_html'], true, $can_post_links),
// <author> was renamed to <dc:creator> in the default template to keep validity.
'author' => unhtml(stripslashes( ( !empty($topicdata['poster_id']) ) ? $topicdata['last_poster_name'] : $topicdata['last_poster_guest']), true),
'link' => $link,
// <comments> was removed from the default template because it was used incorrectly (not for posting comments).
'comments' => $functions->get_config('board_url').$functions->make_url('post.php', array('topic' => $topicdata['topic_id'], 'quotepost' => $topicdata['post_id']), true, false),
'category' => unhtml(stripslashes($forum_names[$topicdata['forum_id']]), true),
'category_domain' => $functions->get_config('board_url').$functions->make_url('forum.php', array('id' => $topicdata['forum_id']), true, false),
'pubDate' => $functions->make_date($topicdata['post_time'], 'D, d M Y H:i:s', true, false).' GMT',
'guid' => $link
), true);
}
$template->parse('footer', 'rss', $header_vars, true);
}
//
// Include the page footer
//
require(ROOT_PATH.'sources/page_foot.php');
?>