-
Notifications
You must be signed in to change notification settings - Fork 1
/
rss.php
226 lines (199 loc) · 11.8 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
<?php
/**
* BLOG:CMS: PHP/MySQL Personal Content Management System
* http://blogcms.com/
* http://forum.blogcms.com/
*
* 2003-2004, (c) Radek HULAN
* http://hulan.cz/
*
* Mod by Bert Garcia for PunBB 1.2.1
* http://nupusi.com
*
* Additional changes Copyright 2005 by Alex King
* Now creates feeds for categories, forums, topics
* http://www.alexking.org/software/
*
* Please see the enclosed readme.txt file for usage
*
* This program 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.
// **********************************************************************
// This program 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.
// *****************************************************************
**/
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
@include PUN_ROOT.'config.php';
// If PUN isn't defined, config.php is missing or corrupt
if (!defined('PUN'))
exit('The file \'config.php\' doesn\'t exist or is corrupt. Please run install.php to install PunBB first.');
// Disable error reporting for uninitialized variables
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Turn off magic_quotes_runtime
//set_magic_quotes_runtime(0);
if (get_magic_quotes_runtime()) set_magic_quotes_runtime(0);
// Load the functions script
//require PUN_ROOT.'include/functions.php';
require PUN_ROOT.'include/parser.php';
// Load DB abstraction layer and try to connect
//require PUN_ROOT.'include/dblayer/common_db.php';
// Get the forum config
$result = $db->query('SELECT * FROM '.$db->prefix.'config') or error('Unable to fetch forum config', __FILE__, __LINE__, $db->error());
while ($cur_config_item = $db->fetch_row($result))
$pun_config[$cur_config_item[0]] = $cur_config_item[1];
// Make sure we (guests) have permission to read the forums
$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());
if ($db->result($result) == '0')
exit('No permission');
// Attempt to load the common language file
@include PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/common.php';
if (!isset($lang_common)) exit('There is no valid language pack \''.$pun_config['o_default_lang'].'\' installed. Please reinstall a language of that name.');
// parse RSS
ob_start();
// make feed
/* original query
$result = $db->query(
"select p.id as id, p.message as message, p.posted as postposted, t.subject as subject ".
"from ".$db->prefix."posts as p, ".$db->prefix."topics as t ".
"where p.topic_id=t.id ".
"order by postposted desc ".
"limit 0,15")
or error('Unable to fetch forum posts', __FILE__, __LINE__, $db->error());;
*/
if (!empty($_GET["cid"])) {
$where = " AND c.id = '".intval($_GET['cid'])."'";
$title = 'cid';
}
else if (!empty($_GET["fid"])) {
$where = " AND f.id = '".intval($_GET['fid'])."'";
$title = 'fid';
}
else if (!empty($_GET["tid"])) {
$where = " AND t.id = '".intval($_GET['tid'])."'";
$title = 'tid';
}
else {
$where = '';
$title = '';
}
$result = $db->query("
SELECT p.id AS id, p.poster AS poster, p.message AS message, p.posted AS postposted, t.subject AS subject, f.forum_name, c.cat_name
FROM ".$db->prefix."posts p
LEFT JOIN ".$db->prefix."topics t
ON p.topic_id=t.id
INNER JOIN ".$db->prefix."forums AS f
ON f.id=t.forum_id
LEFT JOIN ".$db->prefix."categories AS c
ON f.cat_id = c.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
)
$where
ORDER BY postposted DESC
LIMIT 0,15
") or error('Unable to fetch forum posts', __FILE__, __LINE__, $db->error());;
$i = 0;
while ($cur = $db->fetch_assoc($result)) {
if ($i == 0) {
putHeader($cur, $title);
$i++;
}
putPost($cur);
}
putEnd();
// get feed into $feed
$feed = ob_get_contents();
ob_end_clean();
// create ETAG (hash of feed)
$eTag = '"'.md5($feed).'"';
header('Etag: '.$eTag);
// compare Etag to what we got
if ($eTag == $_SERVER['HTTP_IF_NONE_MATCH']) {
header("HTTP/1.0 304 Not Modified");
header('Content-Length: 0');
} else {
// dump feed
header ("Content-type: text/xml");
echo $feed;
}
/* entity to unicode decimal value */
function entity_to_decimal_value($string){
static $entities_dec = false;
if (!is_array($entities_dec)) {
$entities_named = array(" ","¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯","°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿","À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï","Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß","à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï","ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ","ƒ","Α","Β","Γ","Δ","Ε","Ζ","Η","Θ","Ι","Κ","Λ","Μ","Ν","Ξ","Ο","Π","Ρ","Σ","Τ","Υ","Φ","Χ","Ψ","Ω","α","β","γ","δ","ε","ζ","η","θ","ι","κ","λ","μ","ν","ξ","ο","π","ρ","ς","σ","τ","υ","φ","χ","ψ","ω","ϑ","ϒ","ϖ","•","…","′","″","‾","⁄","℘","ℑ","ℜ","™","ℵ","←","↑","→","↓","↔","↵","⇐","⇑","⇒","⇓","⇔","∀","∂","∃","∅","∇","∈","∉","∋","∏","∑","−","∗","√","∝","∞","∠","∧","∨","∩","∪","∫","∴","∼","≅","≈","≠","≡","≤","≥","⊂","⊃","⊄","⊆","⊇","⊕","⊗","⊥","⋅","⌈","⌉","⌊","⌋","⟨","⟩","◊","♠","♣","♥","♦",""","&","<",">","Œ","œ","Š","š","Ÿ","ˆ","˜"," "," "," ","‌","‍","‎","‏","–","—","‘","’","‚","“","”","„","†","‡","‰","‹","›","€","'");
$entities_decimal = array(" ","¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯","°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿","À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï","Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß","à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï","ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ","ƒ","Α","Β","Γ","Δ","Ε","Ζ","Η","Θ","Ι","Κ","Λ","Μ","Ν","Ξ","Ο","Π","Ρ","Σ","Τ","Υ","Φ","Χ","Ψ","Ω","α","β","γ","δ","ε","ζ","η","θ","ι","κ","λ","μ","ν","ξ","ο","π","ρ","ς","σ","τ","υ","φ","χ","ψ","ω","ϑ","ϒ","ϖ","•","…","′","″","‾","⁄","℘","ℑ","ℜ","™","ℵ","←","↑","→","↓","↔","↵","⇐","⇑","⇒","⇓","⇔","∀","∂","∃","∅","∇","∈","∉","∋","∏","∑","−","∗","√","∝","∞","∠","∧","∨","∩","∪","∫","∴","∼","≅","≈","≠","≡","≤","≥","⊂","⊃","⊄","⊆","⊇","⊕","⊗","⊥","⋅","⌈","⌉","⌊","⌋","〈","〉","◊","♠","♣","♥","♦",""","&","<",">","Œ","œ","Š","š","Ÿ","ˆ","˜"," "," "," ","‌","‍","‎","‏","–","—","‘","’","‚","“","”","„","†","‡","‰","‹","›","€","'");
if (function_exists('array_combine'))
$entities_dec=array_combine($entities_named,$entities_decimal);
else {
$i=0;
foreach ($entities_named as $_entities_named) $entities_dec[$_entities_named]=$entities_decimal[$i++];
}
}
return preg_replace( "/&[A-Za-z]+;/", " ", strtr($string,$entities_dec) );
}
function encode_xml($data){
// line breaks
$data=str_replace('<br(.*?)>',"\n",$data);
// ending html tags into line breaks
$data=preg_replace("/<\/(pre|ul|li|p|table|tr)>/","\n",$data);
// remove other html tags
$data=preg_replace("/<(.*?)>/","",$data);
// remove multiple newlines
$data=preg_replace("/\n\n+/","\n\n",$data);
return entity_to_decimal_value($data);
}
function putHeader($cur, $title) {
switch ($title) {
case "cid":
$title = ' : '.$cur['cat_name'];
break;
case "fid":
$title = ' : '.$cur['cat_name'].' : '.$cur['forum_name'];
break;
case "tid":
$title = ' : '.$cur['cat_name'].' : '.$cur['forum_name'].' : '.$cur['subject'];
break;
default:
$title = '';
break;
}
global $lang_common,$pun_config;
echo "<?xml version='1.0' encoding='".$lang_common['lang_encoding']."' ?>\n";
echo "<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:content='http://purl.org/rss/1.0/modules/content/'>\n";
echo "<channel>\n";
echo "<title>".entity_to_decimal_value(htmlspecialchars($pun_config['o_board_title'].$title))."</title>\n";
echo "<link>".$pun_config['o_base_url']."</link>\n";
echo "<description>".entity_to_decimal_value(htmlspecialchars($rss_description.' '.$pun_config['o_board_title']))."</description>\n";
echo "<language>en</language>\n";
echo "<docs>http://backend.userland.com/rss</docs>\n";
}
function putPost($cur) {
global $pun_config;
echo "<item>\n";
echo "<title>".entity_to_decimal_value(htmlspecialchars($cur['subject'].' in '.$cur['cat_name'].' : '.$cur['forum_name']))."</title>\n";
$link = $pun_config['o_base_url'].'/viewtopic.php?pid='.strval($cur['id']).'#p'.strval($cur['id']);
echo "<link>".entity_to_decimal_value(htmlspecialchars($link))."</link>\n";
echo '<guid isPermaLink="false">'.strval($cur['id']).'@'.$pun_config['o_base_url'].'</guid>'."\n";
$data = "Topic: ".parse_message($cur['subject'],0)."\n\nMessage: ".parse_message($cur['message'],0);
echo "<dc:creator>".$cur['poster']."</dc:creator>";
echo "<description>".encode_xml($data)."</description>\n";
// echo "<content:encoded><![CDATA[".$data."]]></content:encoded>\n";
echo "<pubDate>".strval(date("r",$cur['postposted']))."</pubDate>\n";
echo "</item>\n";
}
function putEnd() {
echo "</channel>\n";
echo "</rss>\n";
}
?>