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);
25 foreach ($sx->channel->item as $item) {
26 $title = (string) $item->title;
27 $desc = (string) $item->description;
28 $url = $item->enclosure['url'];
30 $listItems[] = getEpisodeItem(
32 $host1 . 'deredirect.php?url=' . urlencode($url),
37 sendListItems($listItems, buildPreviousItem($path));
41 function downloadIfNewer($url, $file)
44 if (file_exists($file)) {
45 $lastModified = filemtime($file);
48 $ctx = stream_context_create(
51 'header' => 'If-Modified-Since: ' . date('r', $lastModified)
55 $content = file_get_contents($url, false, $ctx);
56 //unfortunately, redirects require manual parsing of this array
57 for ($n = count($http_response_header) - 1; $n >= 0; --$n) {
58 if (substr($http_response_header[$n], 0, 5) == 'HTTP/') {
59 list(, $code) = explode(' ', $http_response_header[$n]);
64 file_put_contents($file, $content);