2 function sendPodcast($path)
4 global $varDir, $host1;
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);
24 addPreviousItem($listItems, $path);
26 foreach ($sx->channel->item as $item) {
27 $title = (string) $item->title;
28 $desc = (string) $item->description;
29 $url = $item->enclosure['url'];
31 $listItems[] = getEpisodeItem(
33 $host1 . 'play-url?url=' . urlencode($url),
38 sendListItems($listItems);
42 function downloadIfNewer($url, $file)
45 if (file_exists($file)) {
46 $lastModified = filemtime($file);
49 $ctx = stream_context_create(
52 'header' => 'If-Modified-Since: ' . date('r', $lastModified)
56 $content = file_get_contents($url, false, $ctx);
57 //unfortunately, redirects require manual parsing of this array
58 for ($n = count($http_response_header) - 1; $n >= 0; --$n) {
59 if (substr($http_response_header[$n], 0, 5) == 'HTTP/') {
60 list(, $code) = explode(' ', $http_response_header[$n]);
65 file_put_contents($file, $content);