2 function sendPodcast($path)
4 global $varDir, $host1, $enablePodcastProxy;
6 $file = urldecode($path);
7 if (strpos($file, '..') !== false) {
12 $fullPath = $varDir . $path;
13 if (!file_exists($fullPath)) {
14 return sendMessage('File does not exist: ' . $path);
17 $url = trim(file_get_contents($fullPath));
19 $cacheFile = '/tmp/podcast-' . md5($path) . '.xml';
20 downloadIfNewer($url, $cacheFile);
22 $sx = simplexml_load_file($cacheFile);
25 $urlHandler = $host1 . 'deredirect.php';
26 if ($enablePodcastProxy) {
27 $urlHandler = $host1 . 'proxy.php';
30 foreach ($sx->channel->item as $item) {
31 $title = (string) $item->title;
32 $desc = (string) $item->description;
33 $url = $item->enclosure['url'];
35 $listItems[] = getEpisodeItem(
37 $urlHandler . '?url=' . urlencode($url),
42 sendListItems($listItems, buildPreviousItem($path));
46 function downloadIfNewer($url, $file)
49 if (file_exists($file)) {
50 $lastModified = filemtime($file);
53 $ctx = stream_context_create(
56 'header' => 'If-Modified-Since: ' . date('r', $lastModified)
60 $content = file_get_contents($url, false, $ctx);
61 //unfortunately, redirects require manual parsing of this array
62 for ($n = count($http_response_header) - 1; $n >= 0; --$n) {
63 if (substr($http_response_header[$n], 0, 5) == 'HTTP/') {
64 list(, $code) = explode(' ', $http_response_header[$n]);
69 file_put_contents($file, $content);