###TITLE### - ###DATE### at ###FROM### (add this)
###WHERE### (map)
###DESCRIPTION###

"; //Where your simplepie.inc is (mine's in the root for some reason) require_once($_SERVER['DOCUMENT_ROOT'].'/simplepie.inc'); // Cache location for your XML file $cache_location=$_SERVER['DOCUMENT_ROOT'].'../cache'; // Change this to 'true' to see lots of fancy debug code $debug_mode=false; // //End of configuration block ///////// if ($debug_mode) {echo "

Debug mode is on.

";} // Make sure that correct version of SimplePie is loaded if (SIMPLEPIE_VERSION<1) { echo "

Fatal error
You need to be running SimplePie v1.0 or above for this to work.

"; die; } // Form the XML address. $calendar_xml_address = "http://www.google.com/calendar/feeds/".$gmail."/public/full?max-results=2500&futureevents=true&orderby=starttime"; // If you only want a section of dates - today only, for example, then try the following, which sets a maximum date to return. I've set this for a day from now. // $calendar_xml_address = "http://www.google.com/calendar/feeds/".$gmail."/public/full?start-min=".date("Y-m-d")."&start-max=".date("Y-m-d",strtotime("+1 day")); // Let's create a new SimplePie object $feed = new SimplePie(); // Set the cache location $feed->set_cache_location($cache_location); if ($debug_mode) { $feed->enable_cache(false); echo "

We're going to go and grab this feed.

";} // This is the feed we'll use $feed->set_feed_url($calendar_xml_address); // Let's turn this off because we're just going to re-sort anyways, and there's no reason to waste CPU doing it twice. $feed->enable_order_by_date(false); // Initialize the feed so that we can use it. $feed->init(); // Make sure the content is being served out to the browser properly. $feed->handle_content_type(); // We'll use this for re-sorting the items based on the new date. $temp = array(); foreach ($feed->get_items() as $item) { // We want to grab the Google-namespaced tag. $when = $item->get_item_tags('http://schemas.google.com/g/2005', 'when'); // Now, let's grab the Google-namespaced tag. $gd_where = $item->get_item_tags('http://schemas.google.com/g/2005', 'where'); $location = $gd_where[0]['attribs']['']['valueString']; //and the status tag too, come to that $gd_status = $item->get_item_tags('http://schemas.google.com/g/2005', 'eventStatus'); $status = substr( $gd_status[0]['attribs']['']['value'], -8); $when = $item->get_item_tags('http://schemas.google.com/g/2005', 'when'); $date = $when[0]['attribs']['']['startTime']; $unixdate = SimplePie_Misc::parse_date($date); $where = $item->get_item_tags('http://schemas.google.com/g/2005', 'where'); $location = $where[0]['attribs']['']['valueString']; // If there's actually a title here (private events don't have titles) and it's not cancelled... if (strlen(trim($item->get_title()))>1 && $status != "canceled" && strlen(trim($date)) > 0) { $temp[] = array('date'=>$unixdate, 'where'=>$location, 'title'=>$item->get_title(), 'description'=>$item->get_description(), 'link'=>$item->get_link()); } } //Sort this sort($temp); // Loop through the (now sorted) array, and display what we wanted. foreach ($temp as $item) { // These are the dates we'll display $gCalDate = gmdate($dateformat, $item['date']); $gCalTime = gmdate($timeformat, $item['date']); // Now, let's run it through some str_replaces, and store it with the date for easy sorting later $temp_event=$event_display; $temp_event=str_replace("###TITLE###",$item['title'],$temp_event); $temp_event=str_replace("###DESCRIPTION###",$item['description'],$temp_event); $temp_event=str_replace("###DATE###",$gCalDate,$temp_event); $temp_event=str_replace("###FROM###",$gCalTime,$temp_event); $temp_event=str_replace("###WHERE###",$item['where'],$temp_event); $temp_event=str_replace("###LINK###",$item['link'],$temp_event); $temp_event=str_replace("###MAPLINK###","http://maps.google.com/?q=".urlencode($item['where']),$temp_event); // Accept and translate HTML $temp_event=str_replace("<","<",$temp_event); $temp_event=str_replace(">",">",$temp_event); $temp_event=str_replace(""","\"",$temp_event); echo $temp_event; } if ($debug_mode) { echo "

";
echo wordwrap(highlight_string(file_get_contents($calendar_xml_address),true),80);
echo "
"; } ?>