63 lines
1.5 KiB
PHP
63 lines
1.5 KiB
PHP
<?php
|
|
header('Content-type: text/xml');
|
|
/*
|
|
Runs from a directory containing files to provide an
|
|
RSS 2.0 feed that contains the list and modification times for all the
|
|
files. Thanks to vsoch on GitHub!
|
|
*/
|
|
$feedName = "dym's random audio finds";
|
|
$feedDesc = "feed of audio files";
|
|
$feedURL = "https://web.dym.sh/audio/rss.xml";
|
|
$feedBaseURL = "https://web.dym.sh/audio/"; // must end in trailing forward slash (/).
|
|
|
|
// $allowed_ext = ".mp4,.mp3,.webm,.ogg,.flac";
|
|
|
|
echo '<?xml version="1.0" ?>';
|
|
?>
|
|
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
|
<channel>
|
|
<title><?= $feedName ?></title>
|
|
<link><?= $feedURL ?></link>
|
|
<description><?= $feedDesc ?></description>
|
|
<?php
|
|
$items = [];
|
|
$sub = "";
|
|
$dir = opendir("./");
|
|
|
|
while( $file = readdir($dir) )
|
|
{
|
|
$ext = strtolower( pathinfo($sub.$file, PATHINFO_EXTENSION) );
|
|
if( '.' !== $file
|
|
&& '..' !== $file
|
|
&& 'index.php' !== $file
|
|
&& 'index.html' !== $file
|
|
&& !is_dir($file)
|
|
// && 0 < strpos($allowed_ext, $ext)
|
|
) {
|
|
$item['name'] = $sub.$file;
|
|
$item['timestamp'] = filectime($sub.$file);
|
|
$item['size'] = filesize($sub.$file);
|
|
$items[] = $item;
|
|
}
|
|
}
|
|
closedir($dir);
|
|
// natcasesort($items);
|
|
|
|
foreach($items as $item) {
|
|
if (!empty($item['name'])) {
|
|
$title = $item['name'];
|
|
$link = $feedBaseURL . urlencode( $item['name'] );
|
|
$dt = date( DATE_RSS, $item['timestamp'] );
|
|
echo <<<__item__
|
|
<item>
|
|
<title><![CDATA[$title]]></title>
|
|
<link>$link</link>
|
|
<guid>$link</guid>
|
|
<pubDate>$dt</pubDate>
|
|
</item>
|
|
__item__;
|
|
}
|
|
}
|
|
?>
|
|
</channel>
|
|
</rss>
|