diff --git a/rss.php b/rss.php
index f6c4bf7..6c21d44 100644
--- a/rss.php
+++ b/rss.php
@@ -5,18 +5,20 @@ require_once 'database.php';
$db = new Database ();
$db->connect ();
+// How should the feeds be sorted?
+$rss_sort = isset ($_GET['sort']) ? strtoupper ($_GET['sort']) : NULL;
+
// Retrieve the posts
-if (!isset ($_GET['sort']))
- exit();
+switch ($rss_sort)
+{
+ case 'NEW': $posts = $db->get_new_posts (); break;
+ default: $posts = $db->get_hot_posts ();
+}
-$rss_sort = strtoupper ($_GET['sort']);
-if ('HOT' == $rss_sort)
- $posts = $db->get_hot_posts ();
-elseif ('NEW' == $rss_sort)
- $posts = $db->get_new_posts ();
+/***** Create the XML (RSS) feed *****/
+
-// Create the XML object
$rss = new SimpleXMLElement ('');
$rss->addAttribute ("version", "2.0");
@@ -25,22 +27,37 @@ $channel = $rss->addChild ('channel');
$channel->addChild ('title', 'freepost');
$channel->addChild ('description', '');
-$channel->addChild ('link', 'http://freepo.st');
+$channel->addChild ('link', 'https://freepo.st');
$channel->addChild ('lastBuildDate', date ('r'));
-// Add items
+// Add our posts to the feed
foreach ($posts as $post)
{
$item = $channel->addChild ('item');
// The link of the the freepost submission
- $freepost_link = 'http://freepo.st/post/' . $post['hashId'];
+ $freepost_link = 'https://freepo.st/post/' . $post['hashId'];
- // Link submitted by the user
+ /* Link submitted by the user.
+ * If no URL was posted (only title/text), link to freepo.st
+ */
$link = strlen ($post['link']) > 0 ? $post['link'] : $freepost_link;
// Short description with username and comments count
- $description = 'by ' . $post['username'] . ' — ' . ($post['commentsCount'] > 0 ? $post['commentsCount'] . ' comments' : 'discuss') . '';
+ $description = 'by ' . $post['username'] . ' — ' . $post['vote'] . ' votes, ' . ($post['commentsCount'] > 0 ? $post['commentsCount'] . ' comments' : 'discuss') . '';
+
+ // Add post text if any
+ if (strlen ($post['text']) > 0)
+ {
+ // Cut text at 1024 chars
+ $description .= '
' . substr ($post['text'], 0, 1024);
+
+ // Add a [Read More] link if some text has been cut
+ if (strlen ($post['text']) > 1024)
+ $description .= '... [Read More]';
+
+ $description .= '
';
+ }
// 'r' » RFC 2822 formatted date (Example: Thu, 21 Dec 2000 16:01:07 +0200)
$date = date ('r', strtotime ($post['created']));