Posted on: 01/27/06 06:28pm
By: mthomas
function phpblock_dailydilbert() { global $_CONF; /* Create a unique name for the Daily Dilbert comic file */ $dilbert_todayfile = 'images/comics/dilbert_'. strtotime(date('m/d/Y')) . '.gif'; $file = "{$_CONF['path_html']}$dilbert_todayfile"; /* Check if today's Dilbert comic already exists - if not retrieve it and create the image */ if (!file_exists($file)) { /* Setup the Web Service Client */ include ($_CONF['path_system'] .'nusoap.php'); $wsdl = "http://www.esynaps.com/WebServices/DailyDilbert.asmx?WSDL"; $client = new soapclient( $wsdl,"true"); /* Call the Web Service and decode the base64 contents back to a GIF file */ $image = @base64_decode($client->call('DailyDilbertImage', '')); /* Now write the raw image and create the image file */ $fp = fopen("{$_CONF['path_html']}$dilbert_todayfile",'w'); // Work around for failing downloads, this is dirty but works....for now. if (strlen($image)==0){ $Site = file_get_contents ("http://www.dilbert.com"); $A1 = '<IMG SRC="/comics/dilbert/archive/images/dilbert'; $A2 = '.gif" ALT="Today's Comic"'; $pos1 = stripos($Site,$A1); $pos2 = stripos($Site,$A2); $Gif = substr($Site, $pos1+strlen($A1)-7,($pos2-$pos1)-(strlen($A2)+12)); $image=file_get_contents ("http://www.dilbert.com/comics/dilbert/archive/images/{$Gif}"); } // End workaround fwrite($fp,$image); fclose($fp); } $imageurl = "{$_CONF['site_url']}/$dilbert_todayfile"; return ("<a href='{$_CONF['site_url']}/images/comics/'><img src='{$imageurl}' width='180' border='0'></a>"); }