Modified widget: APOD 1.3
DOWNLOAD: APOD Widget Modified
As those who know me well my secret identity is a nerd. I love to tinker with websites and code.
Jared wanted to use a nice widget for his blog but found it wasn’t working. Not being able to help myself I popped the hood and found out what makes it tick.
APOD Widget pulls the latest space picture from a NASA site. Its pretty nifty.
Anyway, our host DreamHost (DH) does not support fopen so I needed to find out how I was going to make it work. DH does support cURL so I just made APOD support both.
Would be great to see this in future versions of APOD!
If you want to see the code then here it is with a before and after take. Or there is a download at the bottom with all the changes made.
BEFORE:
// All done, we're closed, get out!
fclose($RemoteFile);
}
}
// We didn't find the APOD page, set available bool to false
else {
$apodAvailable = false;
}
AFTER:
// All done, we're closed, get out!
fclose($RemoteFile);
}
// [START] Modified by James Turner 24/02/2008 http://www.jamesturner.co.nz
// If fopen is disabled on the server lets check if cURL is there (DreamHost specific)
} else if (function_exists('curl_init')) {
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $FullURL);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
} else if (function_exists('curl_int')) {
$ch = curl_init();
$lines = array();
$lines = explode("\n", $RemoteFile);
foreach($lines as $line_num => $line) {
// Check for the large image
if (eregi ($RegExStringBig, $line, $out))
$ImageSrcBig = $out[1];
// Check for the regular image
if (eregi ($RegExStringSmall, $line, $out)) {
$ImageSrcSmall = $out[1];
// We're found it, time to take a break
break;
}
}
}
}
// [END] Modification 24/02/2008
// We didn't find the APOD page, set available bool to false
else {
$apodAvailable = false;
}
I have commented in my change and made the modified file available for download.
DOWNLOAD: APOD Widget Modified
=-)
Yeah this is a very cool widget, its working alot better now, plus im looking forward to future mods
Thanks!