1
0
Fork 0
chickadee/rss_gen.php

52 lines
1.2 KiB
PHP

<?php
// Bounce if not logged in
include_once( 'logcheck.php' );
include_once( 'common.php' );
include_once( 'config.php' );
function build_feed() {
$files = array_values( array_diff( scandir( "./posts" ), array('..', '.')));
if ( !count( $files ) ) {
return;
}
$siteName = SITE_NAME;
$siteLang = SITE_LANG;
$siteRoot = $root = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
$buildDate = date( DATE_RSS );
$header = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>$siteName</title>
<link>$siteRoot</link>
<description>$siteName RSS Feed</description>
<lastBuildDate>$buildDate</lastBuildDate>
<language>$siteLang</language>
XML;
$item = <<<'XML'
<item>
<title>%s</title>
<guid>%s</guid>
<link>%s</link>
<pubDate>%s</pubDate>
</item>
XML;
foreach ( array_reverse( $files ) as $f ) {
$fn = split_filename( $f, DATE_RSS );
$root = $siteRoot . 'post.php?f=';
$t = title_from_filename( $f );
$header .= sprintf( $item, $fn['title'], $fn['encoded'], $root . $fn['encoded'], $fn['time'] );
}
$header .= " </channel>\n</rss>";
file_put_contents( "./rssFeed.xml", $header );
}