freepost codebase git repo

[[ 🗃 ^Avlxv freepost ]] :: [📥 Inbox] [📤 Outbox] [🐤 Followers] [🤝 Collaborators] [🛠 Commits]

Clone

HTTPS: git clone https://vervis.peers.community/repos/Avlxv

SSH: git clone USERNAME@vervis.peers.community:Avlxv

Branches

Tags

master ::

rss.php

<?php

require_once 'database.php';

$db = new Database ();
$db->connect ();

// Retrieve the posts
if (!isset ($_GET['sort']))
    exit();

$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 object
$rss = new SimpleXMLElement ('<rss/>');
$rss->addAttribute ("version", "2.0");

// <channel> info
$channel = $rss->addChild ('channel');

$channel->addChild ('title', 'freepost');
$channel->addChild ('description', '');
$channel->addChild ('link', 'http://freepo.st');
$channel->addChild ('lastBuildDate', date ('r'));

// Add items
foreach ($posts as $post)
{
    $item = $channel->addChild ('item');
    
    // The link of the the freepost submission
    $freepost_link = 'http://freepo.st/post/' . $post['hashId'];
    
    // Link submitted by the user
    $link = strlen ($post['link']) > 0 ? $post['link'] : $freepost_link;
    
    // Short description with username and comments count
    $description = 'by ' . $post['username'] . ' — <a href="' . $freepost_link . '">' . ($post['commentsCount'] > 0 ? $post['commentsCount'] . ' comments' : 'discuss') . '</a>';
    
    // 'r' » RFC 2822 formatted date (Example: Thu, 21 Dec 2000 16:01:07 +0200)
    $date = date ('r', strtotime ($post['created']));
    
    $item->addChild ('title',           $post['title']);
    $item->addChild ('description',     $description);
    $item->addChild ('link',            $link);
    $item->addChild ('freepostLink',    $freepost_link);
    $item->addChild ('pubDate',         $date);
    $item->addChild ('author',          $post['username']);
}

// Output RSS
header ('Content-Type: application/rss+xml; charset=UTF-8');
echo $rss->asXML ();
[See repo JSON]