Skip to content

Instantly share code, notes, and snippets.

@mdb
Created April 10, 2011 20:51
Show Gist options
  • Save mdb/912711 to your computer and use it in GitHub Desktop.
Save mdb/912711 to your computer and use it in GitHub Desktop.
Grabs And Displays a Public Google Calendar's Atom Feed
<?php
//Used to fetch Google Calendar Atom feed
function getShortCalFeed($feed_url) {
$feed_content = file_get_contents($feed_url);
$feed = new SimpleXMLElement($feed_content);
$namespaces = $feed->getNamespaces(true);
//set max entries to loop through and a count var
$maxLoop = 4;
$count = 0;
foreach ($feed->entry as $entry) {
$gd = $entry->children($namespaces['gd']);
$location = $gd->where->attributes()->valueString;
foreach($gd->when->attributes() as $k => $v) {
$show_time[$k] = $v;
$start_timestamp = strtotime($show_time['startTime']);
$start_date = date("F d, Y", $start_timestamp);
$start_time = date("g:i A", $start_timestamp);
$end_timestamp = strtotime($show_time['endTime']);
$end_date = date("F d, Y", $end_timestamp);
$end_time = date("g:i A", $end_timestamp);
}
echo "<div class=\"event content-section\"><small class=\"pre-title\">Hosted by " . $entry->author->name . "</small><h3><a href=\"" . $entry->link[0]->attributes()->href . "\">" . $entry->title . "</a></h3><small class=\"event-date\">" . $start_date . " &ndash; " . $end_date . "</small><small class=\"event-time\">" . $start_time . " &ndash; " . $end_time . "</small><address>" . $location . "</address><p>" . $entry->content . "</p><a class=\"read-more\" href=\"" . "\">View event details &raquo;</a></div>";
$count++;
if($count == $maxLoop) break;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment