From: Steve Sutton Date: Mon, 18 Aug 2014 17:23:54 +0000 (-0400) Subject: Add file to import google feed X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=6078ca86b80f183cf4d1ebc04fe25d338f664a40;p=web%2FKeweenaw.git Add file to import google feed Using php import the xml feed from google into our Events --- diff --git a/Toolkit/Events/googleFeedReader.php b/Toolkit/Events/googleFeedReader.php new file mode 100644 index 0000000..44d4605 --- /dev/null +++ b/Toolkit/Events/googleFeedReader.php @@ -0,0 +1,128 @@ +entry as $event) { + // found in attribute of feed node + $gd_nodes = $event->children('http://schemas.google.com/g/2005'); + // found in attribute of feed node + $gcal_nodes = $event->children('http://schemas.google.com/gCal/2005'); + + $place = $address = $city = $state = $zip = ''; + + $id = (string) $gcal_nodes->uid->attributes()->value; + $title = (string) $event->title; + $description = (string) $event->content; + $location = (string) $gd_nodes->where->attributes()->valueString; + $startTime = (string) $gd_nodes->when->attributes()->startTime; + $endTime = (string) $gd_nodes->when->attributes()->endTime; + $btime = strtotime($startTime); + $etime = strtotime($endTime); + $events2[] = array( + 'id' => $id, + 'title' => $title, + 'description' => $description, + 'location' => $location, + 'startTime' => $startTime, + 'endTime' => $endTime + ); + if (strpos($location, ',')) { + $loc = explode(',', $location); + foreach ($loc as $key => $value) { + $loc[$key] = trim($value); + } + echo '
'.print_r($loc, true).'
'; + $size = count($loc); + switch ($size) { + case 1: + $place = $location; + break; + case 2: + $place = $loc[0]; + $address = $loc[2]; + break; + case 3: + if (in_array($loc[2], array('United States', 'USA'))) { + $place = ''; + $city = $loc[0]; + $state = $loc[1]; + } else { + $place = $loc[0]; + $address = $loc[1]; + $state = $loc[2]; + } + break; + case 5: + $place = $loc[0]; + $address = $loc[1]; + $city = $loc[2]; + $state = $loc[3]; + break; + case 6: + $place = $loc[0]; + $address = $loc[1]; + $city = $loc[2]; + $state = $loc[4]; + break; + } + } + $eventData = array( + 'created' => $currentDate, + 'approved' => $currentDate, + 'active' => true, + 'category' => null, + 'starting' => date('m/d/Y', $btime), + 'ending' => date('m/d/Y', $etime), + 'starthour' => (date('H:i A', $btime) == '00:00 AM') + ? null + : date('H:i A', $btime), + 'endhour' => (date('H:i A', $etime) == '00:00 AM') + ? null + : date('H:i A', $etime), + 'description' => $description, + 'header' => $title, + 'place' => $place, + 'address' => $address, + 'city' => $city, + 'state' => $state, + 'zip' => $zip + ); + if (MEMBERS_DB) { + $event = MemberEvent::createByValues($eventData); + } else { + $event = Event::createByValues($eventData); + } + $eventMapper->saveEvent($event); + $events[] = $event; +} +echo '
'.print_r($events2, true).'
'; +echo '
'.print_r($events, true).'
'; \ No newline at end of file