public function jsonEventsToGEventObjects($jsonObject) { $json = json_decode($jsonObject); /** * Loop through each event in the json array * and create a gEvent object and add to our * array to return back to caller. * @var array */ $gEvents = array(); foreach ($json as $event) { $gEvent = new gEvent(); $gEvent->setInternal_Id($event->internal_Id); $gEvent->setExternal_Id($event->external_id); $gEvent->setDatasource($event->datasource); $gEvent->setEvent_external_url($event->event_external_url); $gEvent->setTitle($event->title); $gEvent->setDescription($event->description); $gEvent->setNotes($event->notes); $gEvent->setTimezone($event->timezone); $gEvent->setTimezone_abbr($event->timezone_abbr); $gEvent->setStart_time($event->start_time); $gEvent->setEnd_time($event->end_time); $gEvent->setStart_date_month($event->start_date_month); $gEvent->setStart_date_day($event->start_date_day); $gEvent->setStart_date_year($event->start_date_year); $gEvent->setStart_date_time($event->start_date_time); $gEvent->setEnd_date_month($event->end_date_month); $gEvent->setEnd_date_day($event->end_date_day); $gEvent->setEnd_date_year($event->end_date_year); $gEvent->setEnd_date_time($event->end_date_time); $gEvent->setVenue_external_id($event->venue_external_id); $gEvent->setVenue_external_url($event->venue_external_url); $gEvent->setVenue_name($event->venue_external_name); $gEvent->setVenue_display($event->venue_display); $gEvent->setVenue_address($event->venue_address); $gEvent->setState_name($event->state_name); $gEvent->setCity_name($event->city_name); $gEvent->setPostal_code($event->postal_code); $gEvent->setCountry_name($event->country_name); $gEvent->setAll_day($event->all_day); $gEvent->setPrice_range($event->price_range); $gEvent->setIs_free($event->is_free); $gEvent->setMajor_genre($event->major_genre); $gEvent->setMinor_genre($event->minor_genre); $gEvent->setLatitude($event->latitude); $gEvent->setLongitude($event->longitude); $performersArr = array(); foreach ($event->performers as $performer) { $gEventPerformer = new gEventPerformer(); $gEventPerformer->setPerformer_name($performer->name); $gEventPerformer->setPerformer_external_id($performer->external_id); $gEventPerformer->setPerformer_external_url($performer->external_url); $gEventPerformer->setPerformer_short_bio($performer->short_bio); $gEventPerformer->setPerformer_external_image_url($performer->external_image_url); array_push($performersArr, $gEventPerformer); } $gEvent->setPerformers($performersArr); $imagesArr = array(); foreach ($event->images as $image) { $gEventImage = new gEventImage(); $gEventImage->setImage_category($image->image_category); $gEventImage->setImage_height($image->image_height); $gEventImage->setImage_width($image->image_width); $gEventImage->setImage_external_url($image->image_external_url); array_push($imagesArr, $gEventImage); } $gEvent->setImages($imagesArr); // push event object onto event array stack array_push($gEvents, $gEvent); } return $gEvents; }
function stubhubAPI_findEvent($externalEventId, $optionsArray) { // Filter Parameters $q = urlencode($externalEventId); $id = $externalEventId; $userLat = $optionsArray['userLat']; $userLong = $optionsArray['userLng']; $endpoint_stubhub = "http://publicfeed.stubhub.com/listingCatalog/select/"; $url = "{$endpoint_stubhub}?q={$q}&wt=json&stubhubDocumentType=event&rows=1&id={$externalEventId}"; $data = get_data($url); $json = json_decode($data); $num = $json->response->numFound; $gEvents = array(); $i = 0; // Loop through Json Results from CURL resuest while ($i < $num) { $externalId = empty($json->response->docs[$i]->event_id) ? null : $json->response->docs[$i]->event_id; $city = empty($json->response->docs[$i]->city) ? null : $json->response->docs[$i]->city; $state = empty($json->response->docs[$i]->state) ? null : $json->response->docs[$i]->state; $date = empty($json->response->docs[$i]->event_date) ? null : substr($json->response->docs[$i]->event_date, 0, -10); $desc = empty($json->response->docs[$i]->description) ? null : $json->response->docs[$i]->description; $title = empty($json->response->docs[$i]->title) ? null : $json->response->docs[$i]->title; $venueExternalId = empty($json->response->docs[$i]->venue_config_id) ? null : $json->response->docs[$i]->venue_config_id; $venueName = empty($json->response->docs[$i]->venue_name) ? null : $json->response->docs[$i]->venue_name; $venueAddress = empty($json->response->docs[$i]->addr1) ? null : $json->response->docs[$i]->addr1; $country = empty($json->response->docs[$i]->country) ? null : $json->response->docs[$i]->country; $postalCode = empty($json->response->docs[$i]->zip) ? null : $json->response->docs[$i]->zip; $defaultDomain = empty($json->response->docs[$i]->defaultDomain) ? "http://stubhub.com" : $json->response->docs[$i]->defaultDomain; $venueExternalUrl = empty($json->response->docs[$i]->venueDetailUrlPath) ? null : "http://" . $defaultDomain . "/" . $json->response->docs[$i]->venueDetailUrlPath; $latitude = empty($json->response->docs[$i]->latitude) ? null : $json->response->docs[$i]->latitude; $longitude = empty($json->response->docs[$i]->longitude) ? null : $json->response->docs[$i]->longitude; $timezone = empty($json->response->docs[$i]->jdk_timezone) ? null : $json->response->docs[$i]->jdk_timezone; $startTime = empty($json->response->docs[$i]->event_date) ? null : str_replace("T", " ", substr($json->response->docs[$i]->event_date, 0, -1)); $minPrice = empty($json->response->docs[$i]->minPrice) ? null : $json->response->docs[$i]->minPrice; $maxPrice = empty($json->response->docs[$i]->maxPrice) ? null : $json->response->docs[$i]->maxPrice; $channel = empty($json->response->docs[$i]->channel) ? null : strtolower($json->response->docs[$i]->channel); $eventExternalUrl = empty($json->response->docs[$i]->urlpath) ? null : "http://" . $defaultDomain . "/" . $json->response->docs[$i]->urlpath; $imageExternalUrl = empty($json->response->docs[$i]->image_url) ? null : $json->response->docs[$i]->image_url; $geoParent = empty($json->response->docs[$i]->geography_parent) ? null : $json->response->docs[$i]->geography_parent; $imageExternalUrlLong = empty($json->response->docs[$i]->image_url) ? null : "http://cache1.stubhubstatic.com/data/venue_maps/" . $geoParent . "/" . $json->response->docs[$i]->image_url; if (null != $latitude && null != $longitude && null != $userLat && null != $userLong) { $distance = distanceInMiles($userLat, $userLong, $latitude, $longitude); } else { $distance = null; } $currentEvent = true; if (!empty($startTime)) { date_default_timezone_set($timezone); $currentUnixTime = strtotime("now"); $eventUnixTime = strtotime($startTime); $currentEvent = $currentUnixTime > $eventUnixTime ? false : true; } // If no externalId is set, don't pull record. Avoids empty // records from getting pulled. if (!empty($externalId) && $currentEvent) { if (empty($filterCity) || strtolower($filterCity) == strtolower($city)) { if (empty($filterState) || strtolower($filterState) == strtolower($state)) { if (empty($filterDate) || $filterDate == $date) { if (empty($filterDesc) || strpos(strtolower($desc), strtolower($filterDesc)) !== FALSE) { if (empty($filterRadius) || $distance <= $filterRadius && $distance > 0) { $gEvent = new gEvent(); $gEvent->setExternal_id($externalId); $gEvent->setDatasource("stubhub"); $gEvent->setTitle($title); $gEvent->setDescription($desc); $gEvent->setNotes(""); $gEvent->setVenue_external_id($venueExternalId); $gEvent->setVenue_name($venueName); $gEvent->setVenue_address($venueAddress); $gEvent->setCountry_name($country); $gEvent->setState_name($state); $gEvent->setCity_name($city); $gEvent->setPostal_code($postalCode); $gEvent->setVenue_external_url($venueExternalUrl); $gEvent->setLatitude($latitude); $gEvent->setLongitude($longitude); $gEvent->setDistance(number_format((double) $distance, 2, '.', '')); $gEvent->setTimezone($timezone); $gEvent->setTimezone_abbr(convertTimezoneToAbbr($timezone)); $gEvent->setStart_time($startTime); $gEvent->setEnd_time(""); $gEvent->setStart_date_month(convertDateToMonthOptions($startTime)); $gEvent->setStart_date_day(convertDateToDayOptions($startTime, $timezone)); $gEvent->setStart_date_year(convertDateToYearOptions($startTime)); $gEvent->setStart_date_time(convertDateToTimeOptions($startTime)); $gEvent->setPrice_range($minPrice . " - " . $maxPrice); if (substr($gEvent->getPrice_range(), 0, 2) === "0 ") { $gEvent->setIs_free(true); } else { if ($gEvent->getPrice_range() !== null) { $gEvent->setIs_free(false); } } $minorGenre = trim(str_replace("tickets", " ", $channel)); $majorGenre = trim(str_replace("tickets", " ", $channel)); $gEvent->setMinor_genre(array($minorGenre)); $gEvent->setMajor_genre(array($majorGenre)); $gEvent->setEvent_external_url($eventExternalUrl); // Populate image links found $gEventImages = array(); $gImage = new gEventImage(); $searchImageQuery = explode("[", $desc); $searchImageQuery = explode("-", $searchImageQuery[0]); $searchImageQuery = urlencode($searchImageQuery[0]); $searchImageUrl = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q={$searchImageQuery}"; $googleImageUrl = googleImageSearch($searchImageUrl); $gImage->setImage_external_url($googleImageUrl); //$gImage->setImage_external_url("https://cdn4.iconfinder.com/data/icons/small-n-flat/24/calendar-128.png"); $gImage->setImage_category("attraction"); array_push($gEventImages, $gImage); if (isset($imageExternalUrl)) { $gImage = new gEventImage(); $gImage->setImage_external_url($imageExternalUrlLong); $gImage->setImage_category("venue"); array_push($gEventImages, $gImage); } $gEvent->setImages($gEventImages); /* //Populate performers found $gEventPerformers = array(); if(isset($json->response->docs[$i]->AttractionName[0])){ $aI = 0; foreach ($json->response->docs[$i]->AttractionName as $performer) { if(isset($performer) && null != $performer && $performer != ""){ $gPerformer = new gEventPerformer; $gPerformer->setPerformer_name($performer); $gPerformer->setPerformer_external_image_url("http://s1.ticketm.net/tm/en-us".$json->response->docs[$i]->AttractionImage[$aI]); array_push($gEventPerformers, $gPerformer); } $aI++; } } $gEvent->setPerformers($gEventPerformers); */ // Push gEvent object onto arraylist of gEvent objects array_push($gEvents, $gEvent); } } } } } } $i++; } return $gEvents; }
function neo4j_findEvents($queryString, $optionsArray, $data) { // Function Filter Parameters $userLat = $optionsArray['userLat']; $userLong = $optionsArray['userLng']; $filterRadius = $optionsArray['radius']; //$dbNeo = new DbHandlerNeo(); $num = count($data); $json = json_encode($data, JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES); $json = json_decode($json); //echo $json[0]; $gEvents = array(); $i = 0; // Loop through Json Results from Neo4j resuest foreach ($json as $jObject) { $internal_id = empty($jObject->internal_id) ? null : $jObject->internal_id; $external_id = empty($jObject->external_id) ? null : $jObject->external_id; $datasource = empty($jObject->datasource) ? null : $jObject->datasource; $event_external_url = empty($jObject->event_external_url) ? null : $jObject->event_external_url; $title = empty($jObject->title) ? null : $jObject->title; $title = str_replace('"', "'", $title); $description = empty($jObject->description) ? null : $jObject->description; $description = str_replace('"', "'", $description); $notes = empty($jObject->notes) ? null : $jObject->notes; $notes = str_replace('"', "'", $notes); $timezone = empty($jObject->timezone) ? null : $jObject->timezone; $timezone_abbr = empty($jObject->timezone_abbr) ? null : $jObject->timezone_abbr; $start_time = empty($jObject->start_time) ? null : $jObject->start_time; $end_time = empty($jObject->end_time) ? null : $jObject->end_time; $start_date_month = empty($jObject->start_date_month) ? array() : json_decode($jObject->start_date_month, true); $start_date_day = empty($jObject->start_date_day) ? array() : json_decode($jObject->start_date_day, true); $start_date_year = empty($jObject->start_date_year) ? array() : json_decode($jObject->start_date_year, true); $start_date_time = empty($jObject->start_date_time) ? array() : json_decode($jObject->start_date_time, true); $end_date_month = empty($jObject->end_date_month) ? array() : json_decode($jObject->end_date_month, true); $end_date_day = empty($jObject->end_date_day) ? array() : json_decode($jObject->end_date_day, true); $end_date_year = empty($jObject->end_date_year) ? array() : json_decode($jObject->end_date_year, true); $end_date_time = empty($jObject->end_date_time) ? array() : json_decode($jObject->end_date_time, true); $venue_external_id = empty($jObject->venue_external_id) ? null : $jObject->venue_external_id; $venue_external_url = empty($jObject->venue_external_url) ? null : $jObject->venue_external_url; $venue_name = empty($jObject->venue_name) ? null : $jObject->venue_name; $venue_display = empty($jObject->venue_display) ? null : $jObject->venue_display; $venue_address = empty($jObject->venue_address) ? null : $jObject->venue_address; $state_name = empty($jObject->state_name) ? null : $jObject->state_name; $city_name = empty($jObject->city_name) ? null : $jObject->city_name; $postal_code = empty($jObject->postal_code) ? null : $jObject->postal_code; $country_name = empty($jObject->country_name) ? null : $jObject->country_name; $all_day = empty($jObject->all_day) ? null : $jObject->all_day; $price_range = empty($jObject->price_range) ? null : $jObject->price_range; $is_free = empty($jObject->is_free) ? null : $jObject->is_free; $major_genre = empty($jObject->major_genre) ? array() : json_decode($jObject->major_genre, true); $minor_genre = empty($jObject->minor_genre) ? array() : json_decode($jObject->minor_genre, true); $latitude = empty($jObject->latitude) ? null : $jObject->latitude; $longitude = empty($jObject->longitude) ? null : $jObject->longitude; $performers = empty($jObject->performers) ? array() : json_decode($jObject->performers, true); $images = empty($jObject->images) ? array() : json_decode($jObject->images, true); $currentEvent = true; $distance = 0.0; if (!empty($latitude) && !empty($longitude)) { if (null != $userLat && null != $userLong) { $distance = distanceInMiles($userLat, $userLong, $latitude, $longitude); } } if (!empty($start_time)) { date_default_timezone_set($timezone); $currentUnixTime = strtotime("now"); $eventUnixTime = strtotime($start_time); $currentEvent = $currentUnixTime > $eventUnixTime ? false : true; } // If no externalId is set, don't pull record. Avoids empty // records from getting pulled. if ($currentEvent) { if (empty($filterRadius) || $distance <= $filterRadius && $distance > 0) { $gEvent = new gEvent(); $gEvent->setExternal_id($external_id); $gEvent->setDatasource($datasource); $gEvent->setTitle($title); $gEvent->setDescription($description); $gEvent->setNotes($notes); $gEvent->setVenue_external_id($venue_external_id); $gEvent->setVenue_name($venue_name); $gEvent->setVenue_address($venue_address); $gEvent->setCountry_name($country_name); $gEvent->setState_name($state_name); $gEvent->setCity_name($city_name); $gEvent->setPostal_code($postal_code); $gEvent->setVenue_external_url($venue_external_url); if (!empty($latitude) && !empty($longitude)) { $gEvent->setLatitude((double) $latitude); $gEvent->setLongitude((double) $longitude); $gEvent->setDistance(number_format((double) $distance, 2, '.', '')); } $gEvent->setTimezone($timezone); $gEvent->setTimezone_abbr($timezone_abbr); $gEvent->setStart_time($start_time); $gEvent->setEnd_time($end_time); $gEvent->setStart_date_month($start_date_month); $gEvent->setStart_date_day($start_date_day); $gEvent->setStart_date_year($start_date_year); $gEvent->setStart_date_time($start_date_time); $gEvent->setEnd_date_month($end_date_month); $gEvent->setEnd_date_day($end_date_day); $gEvent->setEnd_date_year($end_date_year); $gEvent->setEnd_date_time($end_date_time); $gEvent->setPrice_range($price_range); $gEvent->setIs_free($is_free); $gEvent->setMinor_genre($minor_genre); $gEvent->setMajor_genre($major_genre); $gEvent->setEvent_external_url($event_external_url); // Populate image links found $gEvent->setImages($images); //Populate performers found $gEvent->setPerformers($performers); // Push gEvent object onto arraylist of gEvent objects array_push($gEvents, $gEvent); } } //$i++; } return $gEvents; }
function eventfulAPI_findEvents($queryString, $optionsArray) { $app_key = 'NzRqz6hgC5t3ZR8B'; // Filter Parameters $q = urlencode(strtolower($queryString)); $userLat = $optionsArray['userLat']; $userLong = $optionsArray['userLng']; $filterCity = $optionsArray['city']; $filterState = $optionsArray['state']; $filterDate = $optionsArray['date']; $filterRadius = $optionsArray['radius']; if ($q == $filterCity) { $q == null; } // Just do a simple lookup $ev_noauth = new Services_Eventful($app_key); $args = array('keywords' => "{$q}", 'location' => "{$filterCity}, {$filterState}", 'within' => "{$filterRadius}", 'units' => "mi", 'sort_order' => "date", 'page_size' => 100); $data = $ev_noauth->call('events/search', $args, "json"); $num = $data['page_size']; $gEvents = array(); $i = 0; // Loop through Json Results from CURL resuest while ($i < $num) { $externalId = empty($data['events']['event'][$i]['id']) ? null : $data['events']['event'][$i]['id']; $city = empty($data['events']['event'][$i]['city_name']) ? null : $data['events']['event'][$i]['city_name']; $state = empty($data['events']['event'][$i]['region_abbr']) ? null : $data['events']['event'][$i]['region_abbr']; $date = empty($data['events']['event'][$i]['start_time']) ? null : $data['events']['event'][$i]['start_time']; $desc = empty($data['events']['event'][$i]['description']) ? null : $data['events']['event'][$i]['description']; $title = empty($data['events']['event'][$i]['title']) ? null : $data['events']['event'][$i]['title']; $venueExternalId = empty($data['events']['event'][$i]['venue_id']) ? null : $data['events']['event'][$i]['venue_id']; $venueName = empty($data['events']['event'][$i]['venue_name']) ? null : $data['events']['event'][$i]['venue_name']; $venueAddress = empty($data['events']['event'][$i]['venue_address']) ? null : $data['events']['event'][$i]['venue_address']; $country = empty($data['events']['event'][$i]['country_abbr']) ? null : $data['events']['event'][$i]['country_abbr']; $postalCode = empty($data['events']['event'][$i]['postal_code']) ? null : $data['events']['event'][$i]['postal_code']; $defaultDomain = empty($data['events']['event'][$i]['default_domain']) ? "http://eventful.com" : $data['events']['event'][$i]['default_domain']; $venueExternalUrl = empty($data['events']['event'][$i]['venue_url']) ? null : $data['events']['event'][$i]['venue_url']; $latitude = empty($data['events']['event'][$i]['latitude']) ? null : $data['events']['event'][$i]['latitude']; $longitude = empty($data['events']['event'][$i]['longitude']) ? null : $data['events']['event'][$i]['longitude']; $timezone = empty($data['events']['event'][$i]['olson_path']) ? null : $data['events']['event'][$i]['olson_path']; $startTime = empty($data['events']['event'][$i]['start_time']) ? null : $data['events']['event'][$i]['start_time']; $endTime = empty($data['events']['event'][$i]['stop_time']) ? null : $data['events']['event'][$i]['stop_time']; $minPrice = null; $maxPrice = null; $channel = null; $eventExternalUrl = empty($data['events']['event'][$i]['url']) ? null : $data['events']['event'][$i]['url']; $imageExternalUrl = empty($data['events']['event'][$i]['image']) ? null : $data['events']['event'][$i]['image']; $geoParent = empty($data['events']['event'][$i]['geocode_type']) ? null : $data['events']['event'][$i]['geocode_type']; $currentEvent = true; if (!empty($startTime)) { date_default_timezone_set($timezone); $currentUnixTime = strtotime("now"); $eventUnixTime = strtotime($startTime); $currentEvent = $currentUnixTime > $eventUnixTime ? false : true; } if (null != $latitude && null != $longitude && null != $userLat && null != $userLong) { $distance = distanceInMiles($userLat, $userLong, $latitude, $longitude); } else { $distance = null; } if (!empty($externalId) && $currentEvent) { if (empty($filterRadius) || $distance <= $filterRadius && $distance > 0) { $gEvent = new gEvent(); $gEvent->setExternal_id($externalId); $gEvent->setDatasource("eventful"); $gEvent->setTitle($title); $gEvent->setDescription($title); $gEvent->setNotes($desc); $gEvent->setVenue_external_id($venueExternalId); $gEvent->setVenue_name($venueName); $gEvent->setVenue_address($venueAddress); $gEvent->setCountry_name($country); $gEvent->setState_name($state); $gEvent->setCity_name($city); $gEvent->setPostal_code($postalCode); $gEvent->setVenue_external_url($venueExternalUrl); $gEvent->setLatitude($latitude); $gEvent->setLongitude($longitude); $gEvent->setDistance(number_format((double) $distance, 2, '.', '')); $gEvent->setTimezone($timezone); $gEvent->setTimezone_abbr(convertTimezoneToAbbr($timezone)); $gEvent->setStart_time($startTime); $gEvent->setEnd_time($endTime); $gEvent->setStart_date_month(convertDateToMonthOptions($startTime)); $gEvent->setStart_date_day(convertDateToDayOptions($startTime, $timezone)); $gEvent->setStart_date_year(convertDateToYearOptions($startTime)); $gEvent->setStart_date_time(convertDateToTimeOptions($startTime)); $gEvent->setPrice_range($minPrice . " - " . $maxPrice); if (substr($gEvent->getPrice_range(), 0, 2) === "0 ") { $gEvent->setIs_free(true); } else { if ($gEvent->getPrice_range() !== null) { $gEvent->setIs_free(false); } } $minorGenre = array(); $majorGenre = array(); $gEvent->setMinor_genre($minorGenre); $gEvent->setMajor_genre($majorGenre); $gEvent->setEvent_external_url($eventExternalUrl); // Populate image links found $gEventImages = array(); if (isset($imageExternalUrl)) { $image = $data['events']['event'][$i]['image']['medium']; //var_dump($image); //if(!empty($image['medium'])){ $gImage = new gEventImage(); $gImage->setImage_external_url($image['url']); $gImage->setImage_height($image['height']); $gImage->setImage_width($image['width']); $gImage->setImage_category("attraction"); array_push($gEventImages, $gImage); //} } else { $gImage = new gEventImage(); $searchImageQuery = explode("[", $desc); $searchImageQuery = explode("-", $searchImageQuery[0]); $searchImageQuery = urlencode($searchImageQuery[0]); $searchImageUrl = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q={$searchImageQuery}"; $googleImageUrl = googleImageSearch($searchImageUrl); $gImage->setImage_external_url($googleImageUrl); //$gImage->setImage_external_url("https://cdn4.iconfinder.com/data/icons/small-n-flat/24/calendar-128.png"); $gImage->setImage_category("attraction"); array_push($gEventImages, $gImage); } $gEvent->setImages($gEventImages); //Populate performers found $gEventPerformers = array(); if (isset($data['events']['event'][$i]['performers']['performer'])) { foreach ($data['events']['event'][$i]['performers']['performer'] as $performer) { if (isset($performer) && isset($performer['id'])) { $gPerformer = new gEventPerformer(); $gPerformer->setPerformer_external_id($performer['id']); $gPerformer->setPerformer_name($performer['name']); $gPerformer->setPerformer_external_url($performer['url']); $gPerformer->setPerformer_short_bio($performer['short_bio']); array_push($gEventPerformers, $gPerformer); } } } $gEvent->setPerformers($gEventPerformers); // Push gEvent object onto arraylist of gEvent objects array_push($gEvents, $gEvent); } } $i++; } return $gEvents; }
function ticketmasterAPI_findEvent($eventId, $optionsArray) { // There is currently do way to search the ticketmaster API by event id // so we're going to scrape the vendor and artist id from the site // to be able to use it in the json search request $html = file_get_html("http://www.ticketmaster.com/event/{$eventId}"); $patternAID = '/"artistID":"(.*?)"/'; preg_match($patternAID, $html, $AIDmatches); if (isset($AIDmatches[0])) { $aid = explode(":", $AIDmatches[0]); $aid = $aid[1]; $aid = str_replace('"', '', $aid); } $patternVID = '/"venueID":"(.*?)"/'; preg_match($patternVID, $html, $VIDmatches); if (isset($VIDmatches[0])) { $vid = explode(":", $VIDmatches[0]); $vid = $vid[1]; $vid = str_replace('"', '', $vid); } // no match, return empty array if (!isset($aid) && !isset($vid)) { $gEvents = array(); return $gEvents; } // Filter Parameters $eid = $eventId; $vid = $vid; $aid = $aid; $userLat = $optionsArray['userLat']; $userLong = $optionsArray['userLng']; $endpoint_ticketmaster = "http://www.ticketmaster.com/json/search/event"; $url = isset($vid) ? "{$endpoint_ticketmaster}?vid={$vid}" : "{$endpoint_ticketmaster}?aid={$aid}"; $data = get_data($url); $json = json_decode($data); $num = $json->response->numFound; $gEvents = array(); $i = 0; // Loop through Json Results from CURL resuest while ($i < $num) { $externalId = empty($json->response->docs[$i]->Id) ? null : $json->response->docs[$i]->Id; $city = empty($json->response->docs[$i]->VenueCity) ? null : $json->response->docs[$i]->VenueCity; $state = empty($json->response->docs[$i]->VenueState) ? null : $json->response->docs[$i]->VenueState; $date = empty($json->response->docs[$i]->PostProcessedData->LocalEventDate) ? null : substr($json->response->docs[$i]->PostProcessedData->LocalEventDate, 0, -15); $desc = empty($json->response->docs[$i]->EventName) ? null : $json->response->docs[$i]->EventName; $title = empty($json->response->docs[$i]->EventName) ? null : $json->response->docs[$i]->EventName; $eventInfo = empty($json->response->docs[$i]->EventInfo) ? null : htmlspecialchars($json->response->docs[$i]->EventInfo . "\n\n", ENT_QUOTES); $eventNotes = empty($json->response->docs[$i]->EventNotes) ? null : htmlspecialchars($json->response->docs[$i]->EventNotes, ENT_QUOTES); $venueExternalId = empty($json->response->docs[$i]->VenueId) ? null : $json->response->docs[$i]->VenueId; $venueName = empty($json->response->docs[$i]->VenueName) ? null : $json->response->docs[$i]->VenueName; $venueAddress = empty($json->response->docs[$i]->VenueAddress) ? null : $json->response->docs[$i]->VenueAddress; $country = empty($json->response->docs[$i]->VenueCountry) ? null : $json->response->docs[$i]->VenueCountry; $postalCode = empty($json->response->docs[$i]->VenuePostalCode) ? null : $json->response->docs[$i]->VenuePostalCode; $defaultDomain = "http://ticketmaster.com"; $venueExternalUrl = empty($json->response->docs[$i]->VenueSEOLink) ? null : $defaultDomain . $json->response->docs[$i]->VenueSEOLink; $venueLatLongString = empty($json->response->docs[$i]->VenueLatLong) ? null : $json->response->docs[$i]->VenueLatLong; $timezone = empty($json->response->docs[$i]->Timezone) ? null : $json->response->docs[$i]->Timezone; $startTime = empty($json->response->docs[$i]->PostProcessedData->LocalEventDate) ? null : str_replace("T", " ", substr($json->response->docs[$i]->PostProcessedData->LocalEventDate, 0, -6)); $priceRange = empty($json->response->docs[$i]->PriceRange) ? null : $json->response->docs[$i]->PriceRange; $minPrice = empty($json->response->docs[$i]->minPrice) ? null : $json->response->docs[$i]->minPrice; $maxPrice = empty($json->response->docs[$i]->maxPrice) ? null : $json->response->docs[$i]->maxPrice; $genre = empty($json->response->docs[$i]->Genre[0]) ? null : $json->response->docs[$i]->Genre; $minorGenre = empty($json->response->docs[$i]->MinorGenre[0]) ? null : $json->response->docs[$i]->MinorGenre; $majorGenre = empty($json->response->docs[$i]->MajorGenre[0]) ? null : $json->response->docs[$i]->MajorGenre; $eventSEOName = empty($json->response->docs[$i]->EventSEOName) ? null : $json->response->docs[$i]->EventSEOName; $eventExternalUrl = $defaultDomain . "/" . $eventSEOName . "/event/" . $externalId; $eventExternalAttractionUrl = empty($json->response->docs[$i]->AttractionSEOLink[0]) ? null : "http://ticketmaster.com" . $json->response->docs[$i]->AttractionSEOLink[0]; $currentEvent = true; $distance = 0.0; if (!empty($venueLatLongString)) { $venueLatLong = explode(",", $venueLatLongString); if (null != $venueLatLong[0] && null != $venueLatLong[1] && null != $userLat && null != $userLong) { $distance = distanceInMiles($userLat, $userLong, $venueLatLong[0], $venueLatLong[1]); } } if (!empty($startTime)) { date_default_timezone_set($timezone); $currentUnixTime = strtotime("now"); $eventUnixTime = strtotime($startTime); $currentEvent = $currentUnixTime > $eventUnixTime ? false : true; } // If no externalId is set, don't pull record. Avoids empty // records from getting pulled. if (!empty($externalId) && $currentEvent && $externalId == $eid) { if (empty($filterCity) || strtolower($filterCity) == strtolower($city)) { if (empty($filterState) || strtolower($filterState) == strtolower($state)) { if (empty($filterDate) || $filterDate == $date) { if (empty($filterDesc) || strpos(strtolower($desc), strtolower($filterDesc)) !== FALSE) { if (empty($filterRadius) || $distance <= $filterRadius && $distance > 0) { $gEvent = new gEvent(); $gEvent->setExternal_id($externalId); $gEvent->setDatasource("ticketmaster"); $gEvent->setTitle($title); $gEvent->setDescription($desc); $gEvent->setNotes($eventInfo . $eventNotes); $gEvent->setVenue_external_id($venueExternalId); $gEvent->setVenue_name($venueName); $gEvent->setVenue_address($venueAddress); $gEvent->setCountry_name($country); $gEvent->setState_name($state); $gEvent->setCity_name($city); $gEvent->setPostal_code($postalCode); $gEvent->setVenue_external_url($venueExternalUrl); if (!empty($venueLatLongString)) { $venueLatLong = explode(",", $venueLatLongString); $gEvent->setLatitude((double) $venueLatLong[0]); $gEvent->setLongitude((double) $venueLatLong[1]); $gEvent->setDistance(number_format((double) $distance, 2, '.', '')); } $gEvent->setTimezone($timezone); $gEvent->setTimezone_abbr(convertTimezoneToAbbr($timezone)); $gEvent->setStart_time($startTime); $gEvent->setEnd_time(""); $gEvent->setStart_date_month(convertDateToMonthOptions($startTime)); $gEvent->setStart_date_day(convertDateToDayOptions($startTime, $timezone)); $gEvent->setStart_date_year(convertDateToYearOptions($startTime)); $gEvent->setStart_date_time(convertDateToTimeOptions($startTime)); $gEvent->setPrice_range($priceRange); if (substr($priceRange, 0, 2) === "0 ") { $gEvent->setIs_free(true); } else { if ($gEvent->getPrice_range() !== null) { $gEvent->setIs_free(false); } } $gEvent->setMinor_genre(array_merge($genre, $minorGenre)); $gEvent->setMajor_genre($majorGenre); $gEvent->setEvent_external_url($eventExternalUrl); // Populate image links found $gEventImages = array(); if (!empty($json->response->docs[$i]->AttractionImage[0])) { foreach ($json->response->docs[$i]->AttractionImage as $image) { if (isset($image) && null != $image && $image != "") { $gImage = new gEventImage(); $gImage->setImage_external_url("http://s1.ticketm.net/tm/en-us" . $image); $gImage->setImage_category("attraction"); array_push($gEventImages, $gImage); } } } if (!empty($json->response->docs[$i]->VenueImage)) { $gImage = new gEventImage(); $gImage->setImage_external_url("http://s1.ticketm.net/tm/en-us" . $json->response->docs[$i]->VenueImage); $gImage->setImage_category("venue"); array_push($gEventImages, $gImage); } $gEvent->setImages($gEventImages); //Populate performers found $gEventPerformers = array(); if (!empty($json->response->docs[$i]->AttractionName[0])) { $aI = 0; foreach ($json->response->docs[$i]->AttractionName as $performer) { if (!empty($performer)) { $gPerformer = new gEventPerformer(); $gPerformer->setPerformer_name($performer); $attractionImageUrl = empty($json->response->docs[$i]->AttractionImage[$aI]) ? null : $json->response->docs[$i]->AttractionImage[$aI]; if (!empty($attractionImageUrl)) { $gPerformer->setPerformer_external_image_url("http://s1.ticketm.net/tm/en-us" . $json->response->docs[$i]->AttractionImage[$aI]); } array_push($gEventPerformers, $gPerformer); } $aI++; } } $gEvent->setPerformers($gEventPerformers); // Push gEvent object onto arraylist of gEvent objects array_push($gEvents, $gEvent); } } } } } } $i++; } return $gEvents; }