/* apodgen.php5: Convert The Astronomy Photo of the day RSS feed into a feed with media enclosures. Copyright (C) 2008 Sean P. Reiser This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The GNU Public LIcense is available here: http://www.gnu.org/licenses/. */ '); fwriteln ($output,''); fwriteln($output,''); fwriteln($output,''); fwriteln($output,'APOD'); fwriteln($output,'http://antwrp.gsfc.nasa.gov/'); fwriteln($output,'Astronomy Picture of the Day'); fwriteln($output,'en-us'); fwriteln($output,''); fwriteln($output,'APOD'); fwriteln($output,'http://antwrp.gsfc.nasa.gov/apod/apod.gif'); fwriteln($output,'http://antwrp.gsfc.nasa.gov/'); fwriteln($output,''); foreach ($inXML->channel->item as $item){ fwriteln($output,""); fwriteln($output,"$item->title"); fwriteln($output,"$item->link"); // http://antwrp.gsfc.nasa.gov/apod/ap080119.html fwriteln($output,"".strip_tags($item->description).""); $hrurl = getHRUrl($item); $extension = substr($hrurl,strrpos($hrurl,'.')+1); switch ($extension){ case "jpg": case "jpeg": case "jpe": case "jfif": case "pjpeg": case "pjp": $mimetype = "image/jpeg"; break; case "png": $mimetype = "image/png"; break; case "gif": $mimetype = "image/gif"; break; case "bmp": $mimetype = "image/bmp"; break; } fwriteln($output,''); fwriteln($output,""); } fwriteln($output,''); fwriteln($output,''); fclose($output); function getHRUrl($item) { $ch = curl_init($item->link); $input = fopen("temp.html", "w"); $continue = true; $output = "not Found"; $nCtr = 0; curl_setopt($ch, CURLOPT_FILE, $input); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($input); $buffer= file_get_contents("temp.html",FILE_BINARY); $pos = strpos(strtoupper($buffer),'IMG'); if ($pos > 0) { $temp = substr($buffer,$pos-60,100); $tmp2 = strpos($temp,"a href"); $temp = substr($temp,$tmp2+7,100); $end = strpos($temp,'IMG') - 5; $output = substr($temp,1, $end); } return "http://apod.nasa.gov/apod/".$output; } function fwriteln($output,$String){ fwrite($output,$String."\r\n"); } function getrss($SourceFile,$TargetFile) { $ch = curl_init($SourceFile); $input = fopen($TargetFile, "w"); curl_setopt($ch, CURLOPT_FILE, $input); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($input); } ?>