-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrss.php
354 lines (293 loc) · 8.5 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
<?php
//******************************************************//
// ///////// //// /////
// // // // // //
// // ///// ////// //// ////
// // // //// // // // //
// ///////// ///// ////// ///// /////
//******************************************************//
// icebb.net // 1.0
//******************************************************//
// RSS module
// $Id: rss.php 825 2007-05-18 09:06:08Z daniel159 $
//******************************************************//
error_reporting(0);
define('IN_ICEBB' , 1);
define('PATH' , '');
define('PATH_TO_ICEBB' , '');
require(PATH.'config.php');
require(PATH.'includes/classes/timer.php');
require(PATH."includes/database/{$config['db_engine']}.db.php");
$engine = "db_{$config['db_engine']}";
$db = new $engine();
// WRAP IT UP
// ----------
// Wrap everything up in a nice reusable class here...
$icebb = new icebb();
class icebb
{
var $config;
var $skin;
var $skin_data;
var $html_global;
var $lang;
var $input;
var $html;
var $base_url = "index.php?";
var $debug_html;
var $cache;
var $hooks;
function icebb()
{
global $db,$std,$config,$input,$session;
$this->config = $config;
}
}
$cache_query = $db->query("SELECT * FROM icebb_cache");
while($cached_data = $db->fetch_row($cache_query))
{
$icebb->cache[$cached_data['name']]= unserialize(stripslashes($cached_data['content']));
}
$icebb->settings = $icebb->cache['settings'];
$icebb->forums = $icebb->cache['forums'];
require(PATH.'includes/functions.php');
$std = new std_func;
$icebb->input = $std->capture_input();
$icebb->client_ip = $icebb->input['ICEBB_USER_IP'];
$icebb->skin->skin_id = 'default';
require(PATH.'includes/classes/post_parser.php');
$post_parser = new post_parser();
require('includes/classes/hooks.inc.php');
$hooks = new hooks;
$icebb->hooks = $hooks;
require('includes/classes/sessions.inc.php');
$sessfunc = new sessions;
$session_id = empty($icebb->input['s']) ? $std->eatCookie('sessid') : $icebb->input['s'];
//print_r($session_id); die();
$icebb->user = $sessfunc->load($session_id);
$icebb->input = $std->capture_input();
// END WRAP IT UP
// --------------
$rss = new rss();
class rss
{
function rss()
{
global $icebb;
// limit
$this->limit = empty($icebb->input['limit']) ? 15 : intval($icebb->input['limit']);
if(!empty($icebb->input['forum']))
{
$this->where_clauses[] = "t.forum='{$icebb->input['forum']}'";
}
if(!empty($icebb->input['author']) && !empty($icebb->input['topic']))
{
$this->where_clauses[]= "p.pauthor_id=".intval($icebb->input['author']);
}
if(isset($icebb->input['topics_only']))
{
$this->where_clauses[] = "p.pis_firstpost=1";
}
if(!empty($this->where_clauses) && is_array($this->where_clauses))
{
$this->where_clause = " WHERE ".implode(' AND ',$this->where_clauses)." ";
}
if(!empty($icebb->input['topic']))
{
$this->topic($icebb->input['topic']);
}
else if(!empty($icebb->input['author']))
{
$this->author();
}
else {
$this->home();
}
@header("Content-type: text/xml");
echo <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<rss version='2.0'>
<channel>
<title>{$icebb->settings['board_name']}{$this->title_extra}</title>
<link>{$icebb->settings['board_url']}{$this->link_extra}</link>
<description>RSS 2.0 feed of {$icebb->settings['board_name']}</description>
<language>en</language>
<generator>IceBB</generator>
{$this->output}
</channel>
</rss>
EOF;
}
function topic($tid)
{
global $icebb,$db,$post_parser;
$ton = 0;
$db->query("SELECT p.*,u.username as pauthor2 FROM icebb_posts AS p LEFT JOIN icebb_users AS u ON p.pauthor_id=u.id WHERE ptopicid='{$tid}' ORDER BY pid DESC LIMIT {$this->limit}");
while($pdata = $db->fetch_row())
{
$p[] = $pdata;
if(empty($pdata['pauthor']))
{
$pdata['pauthor']= $pdata['pauthor2'];
}
$pubdate = date('R',$p['pdate']);
$pdata['ptext'] = $post_parser->parse($pdata['ptext']);
/*switch($icebb->input['type'])
{
case 'rss0.92': */
$datas .= <<<EOF
<item>
<title>Post #{$pdata['pid']} by {$pdata['pauthor']}</title>
<description>
<![CDATA[
{$pdata['ptext']}
]]>
</description>
<link>{$icebb->settings['board_url']}index.php?topic={$pdata['ptopicid']}&pid={$pdata['pid']}</link>
</item>
EOF;
/*break;
default:
$datas .= <<<EOF
<item>
<title>Post #{$pdata['pid']} by {$pdata['pauthor']}</title>
<description>
<![CDATA[
{$pdata['ptext']}
]]>
</description>
<link>{$icebb->settings['board_url']}index.php?topic={$pdata['ptopicid']}&pid={$pdata['pid']}</link>
<pubDate>{$pubdate}</pubdate>
<guid>{$pdata['pid']}</guid>
</item>
EOF;
break;
}*/
}
$db->query("SELECT t.*,f.perms FROM icebb_topics AS t LEFT JOIN icebb_forums AS f ON t.forum=f.fid WHERE tid='{$tid}'");
$t = $db->fetch_row();
$t['perms'] = unserialize($t['perms']);
if($t['perms'][$icebb->user['g_permgroup']]['read']==1)
{
$this->title_extra= " > {$t['title']}";
$this->link_extra= "&topic={$t['tid']}";
$this->output= $datas;
}
}
function author()
{
global $icebb,$db,$post_parser;
$ton = 0;
$db->query("SELECT p.*,u.username as pauthor2,t.tid,t.title,t.forum,f.perms FROM icebb_posts AS p LEFT JOIN icebb_users AS u ON u.id=p.pauthor_id LEFT JOIN icebb_topics AS t ON p.ptopicid=t.tid LEFT JOIN icebb_forums AS f ON t.forum=f.fid WHERE p.pauthor_id=".intval($icebb->input['author'])." ORDER BY p.pdate DESC LIMIT {$this->limit}");
while($r = $db->fetch_row())
{
$r['perms'] = unserialize($r['perms']);
if($r['perms'][$icebb->user['g_permgroup']]['read']==1)
{
$pubdate = date('r',$r['pdate']);
$p[$r['tid']]['ptext']= $post_parser->parse($p[$r['tid']]['ptext']);
$r['pauthor'] = empty($r['pauthor']) ? $r['pauthor2'] : $r['pauthor'];
if($r['pis_firstpost']!='1')
{
$r['title'] = "Re: {$r['title']}";
}
$this->output .= <<<EOF
<item>
<title>{$r['title']}</title>
<description>
<![CDATA[
{$r['ptext']}
]]>
</description>
<link>{$icebb->settings['board_url']}index.php?topic={$r['tid']}&pid={$r['pid']}</link>
<pubDate>{$pubdate}</pubDate>
<author>{$r['pauthor']}</author>
<guid isPermaLink='false'>{$r['pid']}</guid>
</item>
EOF;
$ton++;
}
}
}
function home()
{
global $icebb,$db,$post_parser;
$ton = 0;
if(!empty($icebb->input['alt']))
{
$favorite_forums = array();
$db->query("SELECT * FROM icebb_favorites WHERE favuser='{$icebb->user['id']}' AND favtype='forum'");
while($fav = $db->fetch_row())
{
$favorite_forums[] = $fav['favobjid'];
}
if(!empty($favorite_forums))
{
$this->where_clause = " WHERE f.fid IN(".join(',',$favorite_forums).")";
}
}
$db->query("SELECT p.*,t.tid,t.title,t.forum,f.perms,u.username AS pauthor2 FROM icebb_posts AS p LEFT JOIN icebb_topics AS t ON p.ptopicid=t.tid LEFT JOIN icebb_forums AS f ON t.forum=f.fid LEFT JOIN icebb_users AS u ON p.pauthor_id=u.id{$this->where_clause} ORDER BY p.pdate DESC LIMIT {$this->limit}");
while($r = $db->fetch_row())
{
$r['perms'] = unserialize($r['perms']);
if($r['perms'][$icebb->user['g_permgroup']]['read']==1)
{
$pubdate = date('r',$r['pdate']);
$r['pauthor'] = !empty($r['pauthor']) ? $r['pauthor'] : $r['pauthor2'];
$r['ptext'] = $post_parser->parse($r['ptext']);
if(empty($r['ptext']))
{
continue;
}
if($r['pis_firstpost']!='1')
{
$r['title'] = "Re: {$r['title']}";
}
switch($icebb->input['type'])
{
case 'rss0.92':
$this->output .= <<<EOF
<item>
<title>{$r['title']} by {$r['pauthor']}</title>
<description>
<![CDATA[
{$r['ptext']}
]]>
</description>
<pubdate>{$r['pdate']}</pubdate>
<link>{$icebb->settings['board_url']}index.php?topic={$r['tid']}&pid={$r['pid']}</link>
</item>
EOF;
break;
default:
$this->output .= <<<EOF
<item>
<title>{$r['title']}</title>
<description>
<![CDATA[
{$r['ptext']}
]]>
</description>
<link>{$icebb->settings['board_url']}index.php?topic={$r['tid']}&pid={$r['pid']}</link>
<pubDate>{$pubdate}</pubDate>
<author>{$r['pauthor']}</author>
<guid isPermaLink='false'>{$r['pid']}</guid>
</item>
EOF;
break;
}
$ton++;
}
}
}
// INTERNAL FUNCTIONS
function _parse($string)
{
if(preg_match('`[\[\]\|<>]`i',$string))
{
$string = "<![CDATA[{$string}]]>";
}
return $string;
}
}
?>