. */ if( $rundaily!="yes" ) { // No access exit(); } for( $i=0; $i<=1; $i++ ) { switch( $i ) { case 0: $out.="\n\n=== Updating events from Calendar of Events ===\n"; $url = "/calendar.nsf/CurrentByDateBC?ReadViewEntries&count=500"; $eventtype="coe"; break; case 1: $out.="\n\n=== Updating events from Summer Universities ===\n"; $url = "/su.nsf/SUsByDateBC?ReadViewEntries&count=500"; $eventtype="su"; break; } if( !($fp=urlopen("www.karl.aegee.org", $url)) ) { //failed $out.="Failed opening $url\n"; }else { $xmlp = xml_parser_create(); xml_set_element_handler($xmlp, "xml_startElement", "xml_endElement"); xml_set_default_handler($xmlp, "xml_cdata"); while( $data = fread($fp, 4096) ) { if( !xml_parse($xmlp, $data, feof($fp)) ) { $out.="XML error: ".xml_error_string(xml_get_error_code($xmlp))." at line ".xml_get_current_line_number($xmlp)."\n"; } } xml_parser_free($xmlp); } } function xml_startElement($parser, $name, $attrs) { global $event; if( $name=="VIEWENTRY" ) { // We are at a new row/event $event=array(); $event['documentid']=$attrs['UNID']; }elseif( $name=="ENTRYDATA" ) { switch( strtolower($attrs['NAME']) ) { case "$42": $event['curelement']="datestart"; break; case "$45": $event['curelement']="dateend"; break; case "subject": $event['curelement']="title"; break; case "cities": $event['curelement']="location"; break; case "eventcode": case "calofficial": case "projectname": case "location": case "certainty": case "eventtype": case "topic": case "bodycode": case "bodycode2": case "area": case "eventrating": case "email": case "url": $event['curelement']=strtolower($attrs['NAME']); break; default: // Element we don't handle } }elseif( $name=="TEXT" ) { $event['textopened']=true; } } function xml_endElement($parser, $name) { global $event, $eventtype; if( $name=="VIEWENTRY" ) { // End of row/event, process it $event['curelement']=NULL; // Remove invalid elements from the array $event['textopened']=NULL; if( $eventtype=="su" ) { $event['projectname']="Summer University"; $event['area']="european"; $event['eventrating']="summer university"; $event['bodycode']=substr($event['eventcode'], 4, 3); } event_add($event); }elseif( $name=="ENTRYDATA" ) { $event['curelement']=NULL; }elseif( $name=="TEXT" ) { $event['textopened']=false; } } function xml_cdata($parser, $data) { global $event, $out; if( isset($event['curelement']) AND $event['textopened']==true ) { $event[ $event['curelement'] ].=$data; } } ?>