<?
header
('Content-Type: text/calendar; charset=UTF-8');
$thismonth = (time()-mktime(1,1,1,1,1,2000))/86400;
$nextmonth $thismonth+(86400*30);

$culverName 'edwardsville';


clearstatcache();
if (
time() - filemtime("culvers.txt") > 86400) {
$ch curl_init();
curl_setopt($chCURLOPT_URL"http://www.culvers.com/restaurants/".$culverName);

curl_setopt($chCURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($chCURLOPT_FOLLOWLOCATION,TRUE);

curl_setopt($chCURLOPT_COOKIEFILE$basedir."/widgets/cookies.txt");
curl_setopt($chCURLOPT_COOKIEJAR$basedir."/widgets/cookies.txt"); 
curl_setopt($chCURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");
 
curl_setopt($chCURLOPT_HEADERtrue); 
$current curl_exec($ch);
curl_close($ch);


file_put_contents("culvers.txt",serialize($current));
} else {
$current unserialize(file_get_contents("culvers.txt"));
}
$halves split('"monthView"',$current);
$current $halves[1];
preg_match_all  ('/class="date">([^<]+).*?href="[^"]+flavor-details\/([0-9]+)"\s+class="value">([^<]+)/'  $current  ,$matches );

?>BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//Culver's//Flavor of the Day Calendar//EN
X-WR-CALNAME:Culver's Flavor of the Day
X-WR-TIMEZONE:America/Chicago
VERSION:2.0
METHOD:PUBLISH
BEGIN:VTIMEZONE
TZID:America/Chicago
LAST-MODIFIED:<?= date("Ymd\T020000"); ?>

BEGIN:STANDARD
TZOFFSETFROM:-0500
TZOFFSETTO:-0600
TZNAME:CST
DTSTART:20071104T020000
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETFROM:-0600
TZOFFSETTO:-0500
TZNAME:CDT
DTSTART:20070311T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
END:DAYLIGHT
END:VTIMEZONE<? echo "\n"; for ($x 0$x count($matches[0]); $x ++) { ?>
<? 
echo "\n"?>BEGIN:VEVENT<? echo "\n"?>DTSTART;VALUE=DATE:<? echo date('Ymd',strtotime($matches[1][$x].", ".date("Y")))."\n"?>DTSTAMP:<? echo date('Ymd\THis',mktime(0,0,0,date("m"),1,date("Y")))."\n"?>UID:culvers0<? echo date('mdY',strtotime($matches[1][$x].", ".date("Y")))."\n"?>LAST-MODIFIED:<? echo date('Ymd\THis',mktime(0,0,0,date("m"),date("d"),date("Y")))."\n"?><? echo 'LOCATION:'.str_replace(',','\,',"Culvers of Edwardsville")."\n"?>SUMMARY:<? echo str_replace(',','\,',trim(html_entity_decode ($matches[3][$x], ENT_QUOTES'UTF-8')))."\n"?>DESCRIPTION:<? echo str_replace(',','\,',html_entity_decode($matches[3][$x], ENT_QUOTES'UTF-8'))." http://www.culvers.com/flavor-of-the-day/all-flavors/flavor-details/".$matches[2][$x]."\n"?>URL:<? echo "http://www.culvers.com/flavor-of-the-day/all-flavors/flavor-details/".$matches[2][$x]."\n"?>TRANSP:TRANSPARENT<? echo "\n"?>END:VEVENT<?  

echo 
"\n";?>END:VCALENDAR