Created
April 10, 2011 20:51
-
-
Save mdb/912711 to your computer and use it in GitHub Desktop.
Grabs And Displays a Public Google Calendar's Atom Feed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 . " – " . $end_date . "</small><small class=\"event-time\">" . $start_time . " – " . $end_time . "</small><address>" . $location . "</address><p>" . $entry->content . "</p><a class=\"read-more\" href=\"" . "\">View event details »</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