Skip to content

Instantly share code, notes, and snippets.

@dmdeller
Created August 21, 2010 18:14
Show Gist options
  • Save dmdeller/542657 to your computer and use it in GitHub Desktop.
Save dmdeller/542657 to your computer and use it in GitHub Desktop.
<?php echo '<?'; ?>xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>
<?php echo ucwords(basename(dirname($_SERVER['SCRIPT_NAME']))); ?><?php if (!empty($_GET['match'])): ?> : <?php echo ucwords($_GET['match']); ?><?php endif; ?>
</title>
<?php $files = scandir('.'); ?>
<?php $files = array_reverse($files); ?>
<?php foreach ($files as $file): ?>
<?php $pathinfo = pathinfo($file); ?>
<?php if (!in_array($pathinfo['extension'], array('mp3', 'm4a'))) continue; ?>
<?php
if (!empty($_GET['match']))
if (strpos(strtolower($file), strtolower($_GET['match'])) === false)
continue;
?>
<?php
// delete files over 1 week old
if (filemtime($file) < strtotime('now - 1 week'))
unlink($file);
?>
<?php $url = 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['SCRIPT_NAME']).'/'.rawurlencode($file); ?>
<item>
<title><?php echo $pathinfo['filename']; ?></title>
<enclosure
url="<?php echo $url; ?>"
length="<?php echo filesize($file); ?>"
<?php if ($pathinfo['extension'] == 'mp3'): ?>
type="audio/mpeg"
<?php elseif ($pathinfo['extension'] == 'm4a'): ?>
type="audio/mp4"
<?php endif; ?>
/>
<guid><?php echo $url; ?></guid>
<pubDate><?php echo date('r', filemtime($file)); ?></pubDate>
</item>
<?php endforeach; ?>
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment