<?php header("Content-Type: application/rss+xml; charset=ISO-8859-1"); ?> <?xml version="1.0" encoding="ISO-8859-1"?> <rss version="2.0"> <channel> <title>9iron</title> <link>https://9iron.club/posts</link> <description>Ramblings of some dumb young admin guy</description> <language>en-us</language> <?php /* Generate feed */ $dir = $_SERVER['DOCUMENT_ROOT']."/posts/"; $posts = scandir($dir, 1); $ignore = array("index.php", "feed.php", ".", ".."); $extensions = array(".php", ".html", ".htm"); /* Create 25 entries */ foreach (array_slice($posts, 0, 26) as &$post) { /* Check against blacklist */ if (in_array($post, $ignore)) continue; $postlocation = $dir.$post; $posturl = "/posts/".$post; /* This is a date because I write all my posts as such */ $postdate = pathinfo($postlocation, PATHINFO_FILENAME); /* Fetch title and summary */ $title = "Title not available"; $summary = "Summary not available"; $dom = new DOMDocument(); if ($dom->loadHTMLFile($postlocation)) { $xpath_section = new DOMXpath($dom); /* Get title */ $list = $dom->getElementsByTagName("title"); if ($list->length > 0) $title = $list->item(0)->textContent; /* Get summary */ $list = $xpath_section->query('//div[@class="section"]//p'); if ($list->length > 0) $summary = $list->item(0)->nodeValue; } /* Mark up the data */ $rssfeed .=' <item> <title>'.$title.'</title> <description>'.$summary.'</description> <link>https://www.9iron.club'.$posturl.'</link> <pubDate>'.date('r', strtotime($postdate)).'</pubDate> </item>'; } /* List it */ echo $rssfeed; ?> </channel> </rss>