<?php

/*************************************************************
**
** What The Duck PHP Script 1.1
** by WEBNERD (www.webnerd.com.au)
**
** Updated: 18th December 2008
**
** This script is free to use and may need some motifications
** for your specific needs.  Please send an email to
** jamesqh@webnerd.com.au if you find this script useful
** or have suggestions as to how to improve it.
**
*************************************************************/

function getWhatTheDuck() {
    
    
// The WTD RSS feed URL
    //$rss_url = 'http://feeds.feedburner.com/WhatTheDuckComic?format=xml';
    
$rss_url 'http://web.me.com/aaronandpatty/What_the_Duck/Comic_Strips/rss.xml';

    
// Grab RSS from What The Duck
    // Note: The URL is provided in $url
    
$ch curl_init();
    
curl_setopt ($chCURLOPT_URL$rss_url);
    
curl_setopt ($chCURLOPT_SSL_VERIFYPEERFALSE);
    
curl_setopt($chCURLOPT_HEADER1);
    
curl_setopt ($chCURLOPT_USERAGENT"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    
curl_setopt ($chCURLOPT_TIMEOUT20);
    
curl_setopt ($chCURLOPT_FOLLOWLOCATION,1);
    
curl_setopt ($chCURLOPT_RETURNTRANSFER1);
    
$data curl_exec ($ch);
    
curl_close($ch);
    
    
    
// Parse RSS
    //preg_match_all("#<item>(.*?)<title>(.*?)<\/title>(.*?)<link>(.*?)<\/link>(.*?)<description>(.*?)src=\"(.*?)\"(.*?)<\/description>(.*?)<pubDate>(.*?)<\/pubDate>(.*?)<\/item>#is", $data, $table);
    
preg_match_all("#<item>(.*?)<title>(.*?)<\/title>(.*?)<link>(.*?)<\/link>(.*?)<pubDate>(.*?)<\/pubDate>(.*?)<enclosure url=\"(.*?)\"(.*?)<\/item>#is"$data$table);
    
$result['title']    = $table[2];
    
$result['link']        = $table[4];
    
$result['image']    = $table[8];
    
$result['pubTime']    = $table[6];
    
//var_dump($table);

    // Change text time to time format
    
foreach($result['pubTime'] as $k=>$v) {
        
$result['pubTime'][$k] = strtotime($v);
    }

    return 
$result;

}

function 
outputWTD() {
    
    
// Get the WTD information as an array
    
$whattheduck getWhatTheDuck(); 
    
    
// Format the output
    
$output "";
    
    
// To output just the most recent strip, change the for line
    // below to:
    // 
    //if ($i = count($whattheduck['title']) - 1) {
    
    
for($i=count($whattheduck['title'])-1$i>=0$i--) {
        
$thistitle $whattheduck['title'][$i];
        
$thislink  $whattheduck['link'][$i];
        
$thisdate  date ("D, j F Y H:i:s"$whattheduck['pubTime'][$i]);
        
$thisimage $whattheduck['image'][$i];
        
$output .= "<div><b>$thistitle</b></div>\n";
        
$output .= "<div>Original article: <a href=\"$thislink\">CLICK HERE</a></div>\n";
        
$output .= "<div>Published: $thisdate</div>\n";
        
$output .= "<div><img src=\"$thisimage\" border=\"0\" /></div>\n";
        
$output .= "<hr>\n";
        
$output .= "<div>&nbsp</div>\n\n";
    }
    
    return 
$output;
    
}

echo 
outputWTD();

?>