对Google日历Feed进行排序(使用DOM解析)

时间:2010-05-28 20:26:15

标签: php dom parsing

我将谷歌日历中的日期嵌入到网站中,除了排序外,它都可以正常工作。出于某种原因,它按逆时间顺序排序,当我真的喜欢它是正常的时间顺序(第一个事件第一)。

这是输出:

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 

我真的还在学习很多这样的东西 - 感谢您的帮助!

<?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 />";
}
}
?>

1 个答案:

答案 0 :(得分:1)

&sortorder=descending添加到您的Feed网址。您可以在FAQ

中找到相关文档