forked from JeDaYoshi/Blargboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss.php
94 lines (73 loc) · 2.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
<?php
define('BLARG', 1);
function fixyoutube($m)
{
$url = $m[1];
if (substr($url,0,4) != 'http')
$url = 'http://www.youtube.com/watch?v='.$url;
return '<a href=\"'.htmlspecialchars($url).'\">(video)</a>';
}
require(__DIR__.'/lib/common.php');
$fid = Settings::get('newsForum');
if(!HasPermission('forum.viewforum', $fid))
die("You aren't allowed to access this forum.");
$rFora = Query("select * from {forums} where id = {0}",$fid);
if(NumRows($rFora))
$forum = Fetch($rFora);
else
die("Unknown forum ID.");
header('Content-type: application/rss+xml');
$title = Settings::get('rssTitle');
$desc = Settings::get('rssDesc');
$url = "http".($ishttps?'s':'')."://{$_SERVER['SERVER_NAME']}{$serverport}";
$fullurl = getServerURLNoSlash($ishttps);
print '<?xml version="1.0" encoding="UTF-8"?>';
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title><?php echo htmlspecialchars($title); ?></title>
<link><?php echo htmlspecialchars($url); ?></link>
<description><?php echo htmlspecialchars($desc); ?></description>
<atom:link href="<?php echo htmlspecialchars($fullurl); ?>/rss.php" rel="self" type="application/rss+xml" />
<?php
$entries = Query(" SELECT
t.id, t.title,
p.date,
pt.text,
su.name uname, su.displayname udname
FROM
{threads} t
LEFT JOIN {posts} p ON p.thread=t.id AND p.id=t.firstpostid
LEFT JOIN {posts_text} pt ON pt.pid=p.id AND pt.revision=p.currentrevision
LEFT JOIN {users} su ON su.id=t.user
WHERE t.forum={0} AND p.deleted=0
ORDER BY p.date DESC LIMIT 5", $fid);
while($entry = Fetch($entries))
{
$tags = ParseThreadTags($entry['title']);
$title = htmlspecialchars($entry['title']);
$username = $entry['udname'] ? $entry['udname'] : $entry['uname'];
$rfcdate = htmlspecialchars(gmdate(DATE_RFC1123, $entry['date']));
$entryurl = htmlspecialchars($url.actionLink('thread', $entry['id'], '', $tags[0]));
$text = $entry['text'];
$text = preg_replace_callback('@\[youtube\](.*?)\[/youtube\]@si', 'fixyoutube', $text);
$text = preg_replace('@\[spoiler.*?\].*?\[/spoiler\]@si', '(spoiler)', $text);
$text = CleanUpPost($text, $username, true);
$text = preg_replace('@<img[^>]+?src\s*=\s*(["\'])(.*?)\\1[^>]*?>@si', '<a href="$2">(image)</a>', $text);
$text = preg_replace('@<img[^>]+?src\s*=\s*([^\s>]+?)(\s+[^>]*?)?>@si', '<a href="$1">(image)</a>', $text);
$text = preg_replace('@([="\'])\?page=@si', '$1'.$fullurl.'/?page=', $text);
$text = str_replace(']]>', ']]>', $text);
$username = htmlspecialchars($username);
echo "
<item>
<title>{$title} -- posted by {$username}</title>
<link>{$entryurl}</link>
<pubDate>{$rfcdate}</pubDate>
<description><![CDATA[{$text}]]></description>
<guid>{$entryurl}</guid>
</item>
";
}
?>
</channel>
</rss>