diff options
Diffstat (limited to 'views/tools/ghrss/feed.php')
| -rw-r--r-- | views/tools/ghrss/feed.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/views/tools/ghrss/feed.php b/views/tools/ghrss/feed.php new file mode 100644 index 0000000..7276200 --- /dev/null +++ b/views/tools/ghrss/feed.php @@ -0,0 +1,47 @@ +<?php + +use DiDom\Document; +use Suin\RSSWriter\Channel; +use Suin\RSSWriter\Feed; +use Suin\RSSWriter\Item; + +require_once __DIR__ . '/ghrss.db.php'; +require_once __DIR__ . '/vendor/autoload.php'; + +header("content-type: application/rss+xml"); + +if ( isset($_REQUEST["l"]) && "" != $_REQUEST["l"] ) { + $stmt = $db->prepare("SELECT * FROM entry_view WHERE language = ? ORDER BY created_at DESC LIMIT 20;"); + $stmt->execute([$_REQUEST["l"]]); +} else { + $stmt = $db->prepare("SELECT * FROM entry_view WHERE created_at >= NOW() - INTERVAL 2 DAY ORDER BY created_at DESC;"); + $stmt->execute([$_REQUEST["l"]]); +} +$result = $stmt->fetchAll(); + +$feed = new Feed(); + +$channel = new Channel(); +$channel + ->title("GHRSS") + ->description("Trending Repos from Github") + ->url( "https://www.maximilianmoehring.com/tools/ghrss/" ) + ->pubDate(strtotime(date("r", time()))) + ->lastBuildDate(strtotime(date("r", time()))) + ->ttl(5) + ->appendTo($feed); + +foreach($result as $item) { + $item_out = new Item(); + + $item_out + ->title($item["title"]) + ->description( "<p>" . $item["synopsis"] . "<br><em>" . $item["language"] . " / " . $item["update_period"] . " / " . $item["stars"] . " Stars</em></p>" ) + ->url($item["url"]) + ->pubDate(strtotime(date($item["created_at"]))) + ->author($item["owner"]) + ->appendTo($channel); +} + +echo $feed; + |
