开发者

Sorting a google calendar feed (parsing with DOM)

I'm embedding dates from google calendar into a website, and it's all working, with the exception of sorting. For some reason, it sorts into reverse-chronological order, when I'd really just like it to be normal chronological (first event first).

this is the output:

August 11th: Intern depart  
August 6th: Last Day of Summer Camp
July 7th: Ignore this 
July 6th: This is another example event 
July 5th: example 
June 28th: Summer Camp Starts 
June 24th: Summer Pool Party 
June 21st: Intern arrival date 
June 15th: Assistant Director Arrival Date 
June 14th: Director's training begins 
May 26th: Brainstorm day for directors 

I'm really still just learning a lot of this stuff- thanks for the help in advance!

<?php 
$confirmed = 'http://schemas.google.com/g/2005#event.confirmed';
$three_months_in_seconds = 60 * 60 * 24 * 28 * 3;
$three_months_ago = date("Y-m-d\Th:i:sP", time() - 172800);
$three_months_from_today = date("Y-m-d\Th:i:sP", time() + $three_months_in_seconds);
$feed = "http://www.google.com/calendar/feeds/qp6o02ka3iaoem2kr8odga6j7s%40group.calendar.google.com/" . 
"public/full?orderby=starttime&singleevents=true&" . 
"start-min=" . $three_months_ago . "&" .
"start-max=" . $three_months_from_today;
$doc = new DOMDocument(); 
$doc->load( $feed );
$entries = $doc->getElementsByTagName( "entry" ); 
foreach ( $entries as $entry ) { 
$status = $entry->getElementsByTagName( "eventStatus" ); 
$eventStatus = $status->item(0)->getAttributeNode("value")->value;
if ($eventStatus == $confirmed) {
$titles = $entry->getElementsByTagName( "title" ); 
$title = $titles->item(0)->nodeValue;
$times = $entry->getElementsByTagName( "when" ); 
$startTime = $times->item(0)->getAttributeNode("startTime")->开发者_如何学运维value;
$when = date( "F jS", strtotime( $startTime ) );
$whentime = date( "g:ia", strtotime ( $startTime ) );
$places = $entry->getElementsByTagName( "where" ); 
$where = $places->item(0)->getAttributeNode("valueString")->value;
$links = $entry->getElementsByTagName( "link" );
$link = $links->item(0)->nodeValue;
print $when;
if ($whentime == "12:00am"){
;
}
else{
echo " at ";
print $whentime;
}
echo ": ";
echo "<b>";
print $title . "\n";
echo "</b>";
echo " ";
if(empty($where)){;}else{
echo "<br />";
print $where . "\n"; 
}
print $link;
print "<br />";
}
}
?>


Add &sortorder=descending to your feed URL. You can find documentation for this in the FAQ

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜