define('EVENTOR_API_KEY', "INSERT YOUR KEY HERE");
define('EVENTOR_API_BASE_URL', "https://eventor.orientering.no/api/");
# Caching
$cache = dirname(__FILE__) . '/cache/liste';
$oldness=60*60; # Cache time
$maxentries=20; # Max number of entries to show
$orgID=8; # Organization ID. 8 = Hordaland
$data="";
# Use cache depending on how old cache data is
if(filemtime($cache) < (time() - $oldness))
{
$data="
";
# Get data from Eventor
$fromDate=date("Y-m-d"); # From today
$toDate=date("Y-m-d",time()+86400*60); # Next 60 days
$url = EVENTOR_API_BASE_URL . "events?fromDate=".$fromDate."&toDate=".$toDate."&organisationIds=$orgID";
$xml = eventorApiCall($url);
$doc=simplexml_load_string($xml);
$ii=0;
$eventNodes = $doc->xpath("//Event");
# Sort events on date
function sort_events($t1, $t2) {
$d1=$t1->xpath('StartDate/Date');
$d2=$t2->xpath('StartDate/Date');
return strcmp($d1[0], $d2[0]);
}
usort($eventNodes, 'sort_events');
# Go through each event, and print it out
foreach($eventNodes as $eventNode)
{
$EventId=$eventNode->xpath("EventId");
$Name=$eventNode->xpath("Name");
$Date=$eventNode->xpath("StartDate/Date");
$Clock=$eventNode->xpath("StartDate/Clock");
$OrgID=$eventNode->xpath("Organiser/OrganisationId");
$ii++;
if ($ii<=$maxentries)
{
list ($hour,$min,$sec)=split(":",$Clock[0]);
if ($hour=="00" && $min=="00")
{ $starttime="";}
else
{ $starttime=" (".$hour.":".$min.")";}
list($year,$mon,$day)=explode('-',$Date[0]);
$link="http://eventor.orientering.no/Events/Show/".$EventId[0];
$data.= "