5
|
5
|
|
$db = new Database ();
|
6
|
6
|
|
$db->connect ();
|
7
|
7
|
|
|
|
8
|
+ |
// How should the feeds be sorted?
|
|
9
|
+ |
$rss_sort = isset ($_GET['sort']) ? strtoupper ($_GET['sort']) : NULL;
|
|
10
|
+ |
|
8
|
11
|
|
// Retrieve the posts
|
9
|
|
- |
if (!isset ($_GET['sort']))
|
10
|
|
- |
exit();
|
|
12
|
+ |
switch ($rss_sort)
|
|
13
|
+ |
{
|
|
14
|
+ |
case 'NEW': $posts = $db->get_new_posts (); break;
|
|
15
|
+ |
default: $posts = $db->get_hot_posts ();
|
|
16
|
+ |
}
|
11
|
17
|
|
|
12
|
|
- |
$rss_sort = strtoupper ($_GET['sort']);
|
13
|
18
|
|
|
14
|
|
- |
if ('HOT' == $rss_sort)
|
15
|
|
- |
$posts = $db->get_hot_posts ();
|
16
|
|
- |
elseif ('NEW' == $rss_sort)
|
17
|
|
- |
$posts = $db->get_new_posts ();
|
|
19
|
+ |
/***** Create the XML (RSS) feed *****/
|
|
20
|
+ |
|
18
|
21
|
|
|
19
|
|
- |
// Create the XML object
|
20
|
22
|
|
$rss = new SimpleXMLElement ('<rss/>');
|
21
|
23
|
|
$rss->addAttribute ("version", "2.0");
|
22
|
24
|
|
|
25
|
27
|
|
|
26
|
28
|
|
$channel->addChild ('title', 'freepost');
|
27
|
29
|
|
$channel->addChild ('description', '');
|
28
|
|
- |
$channel->addChild ('link', 'http://freepo.st');
|
|
30
|
+ |
$channel->addChild ('link', 'https://freepo.st');
|
29
|
31
|
|
$channel->addChild ('lastBuildDate', date ('r'));
|
30
|
32
|
|
|
31
|
|
- |
// Add items
|
|
33
|
+ |
// Add our posts to the feed
|
32
|
34
|
|
foreach ($posts as $post)
|
33
|
35
|
|
{
|
34
|
36
|
|
$item = $channel->addChild ('item');
|
35
|
37
|
|
|
36
|
38
|
|
// The link of the the freepost submission
|
37
|
|
- |
$freepost_link = 'http://freepo.st/post/' . $post['hashId'];
|
|
39
|
+ |
$freepost_link = 'https://freepo.st/post/' . $post['hashId'];
|
38
|
40
|
|
|
39
|
|
- |
// Link submitted by the user
|
|
41
|
+ |
/* Link submitted by the user.
|
|
42
|
+ |
* If no URL was posted (only title/text), link to freepo.st
|
|
43
|
+ |
*/
|
40
|
44
|
|
$link = strlen ($post['link']) > 0 ? $post['link'] : $freepost_link;
|
41
|
45
|
|
|
42
|
46
|
|
// Short description with username and comments count
|
43
|
|
- |
$description = 'by ' . $post['username'] . ' — <a href="' . $freepost_link . '">' . ($post['commentsCount'] > 0 ? $post['commentsCount'] . ' comments' : 'discuss') . '</a>';
|
|
47
|
+ |
$description = 'by ' . $post['username'] . ' — ' . $post['vote'] . ' votes, <a href="' . $freepost_link . '">' . ($post['commentsCount'] > 0 ? $post['commentsCount'] . ' comments' : 'discuss') . '</a>';
|
|
48
|
+ |
|
|
49
|
+ |
// Add post text if any
|
|
50
|
+ |
if (strlen ($post['text']) > 0)
|
|
51
|
+ |
{
|
|
52
|
+ |
// Cut text at 1024 chars
|
|
53
|
+ |
$description .= '<p>' . substr ($post['text'], 0, 1024);
|
|
54
|
+ |
|
|
55
|
+ |
// Add a [Read More] link if some text has been cut
|
|
56
|
+ |
if (strlen ($post['text']) > 1024)
|
|
57
|
+ |
$description .= '... [<a href="' . $freepost_link . '">Read More</a>]';
|
|
58
|
+ |
|
|
59
|
+ |
$description .= '</p>';
|
|
60
|
+ |
}
|
44
|
61
|
|
|
45
|
62
|
|
// 'r' » RFC 2822 formatted date (Example: Thu, 21 Dec 2000 16:01:07 +0200)
|
46
|
63
|
|
$date = date ('r', strtotime ($post['created']));
|