diff --git a/rss.php b/rss.php
new file mode 100644
index 0000000..e2d55ba
--- /dev/null
+++ b/rss.php
@@ -0,0 +1,118 @@
+
+ */
+
+ // Return source code
+ if(isset($_GET['source'])) {
+ header("Content-Type: text/plain");
+ die(file_get_contents(basename($_SERVER['PHP_SELF'])));
+ }
+
+ // See bbs.php for a description of vars.php
+ require_once('vars.php');
+
+ // Regex callback, makes >>quotes into links
+ function quote_link($match) {
+ $query = "SELECT post_id FROM posts WHERE post_id=$1";
+ $result = pg_query_params($query, [$match[1]]) or die('Query failed: ' . pg_last_error());
+ $row_count = pg_num_rows($result);
+ pg_free_result($result);
+ if($row_count > 0)
+ return "{$match[0]}";
+ else
+ return "{$match[0]}";
+ }
+
+ $dbc = pg_connect("host=$DB_HOST dbname=$DB_NAME user=$DB_USER password=$DB_PASSWORD")
+ or die('Could not connect: ' . pg_last_error());
+
+ // Get posts
+ $posts = [];
+
+ $query = "SELECT post_id, name, trip, email, comment, img, TO_CHAR(post_time, 'Dy, DD Mon YYYY HH24:MI:SS TZHTZM') AS ts "
+ . "FROM posts ORDER BY posts.post_time DESC LIMIT 10";
+ $result = pg_query($query) or die('Query failed: ' . pg_last_error());
+
+ while($row = pg_fetch_array($result)) {
+ // Process quotes, links, and newlines
+ $comment = NULL;
+ if(!empty($row['comment'])) {
+ $comment = $row['comment'];
+ $comment = preg_replace('/^>(?!>\d).+/m', '$0', $comment);
+ $comment = preg_replace('/(?:https?|mailto|tel|ftp):[^\s]+/m', '$0', $comment);
+ $comment = preg_replace_callback('/>>\s*(\d+)/', quote_link, $comment);
+ $comment = str_replace("\n", "
", $comment);
+ }
+
+ $name = $row['name'];
+ if(!empty($row['trip']))
+ $name .= '◆' . $row['trip'];
+ $comment = htmlspecialchars("
$comment
"); + $img = preg_replace('/\.(?:png|gif|bmp)$/', '.jpg', $row['img']); + + $posts[] = [ + 'title' => "New post by $name", + 'link' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . '/#p' . $row['post_id'], + 'description' => $comment, + 'author' => $name, + 'pubDate' => $row['ts'], + 'guid' => 'p' . $row['post_id'], + 'img' => empty($row['img']) ? NULL : [ + 'url' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . '/' . THUMB_PATH . $img, + 'length' => filesize(THUMB_PATH . $img), + 'type' => mime_content_type(THUMB_PATH . $img) + ] + ]; + } + + pg_close($dbc); + + header("Content-Type: application/rss+xml"); +?> + +