From d41c8835317d2450a6e10bc48be4607afeb74863 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 14 Aug 2018 11:18:07 -0400 Subject: [PATCH] Updating event ical import Deal with google location --- models/front/events/icalFeedImport.php | 138 +++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 9 deletions(-) diff --git a/models/front/events/icalFeedImport.php b/models/front/events/icalFeedImport.php index 7022835..5aee493 100644 --- a/models/front/events/icalFeedImport.php +++ b/models/front/events/icalFeedImport.php @@ -79,6 +79,8 @@ class GlmMembersFront_events_icalFeedImport } public function importIcalFeed( $feed_id ) { + $state_zip_reg = '%([A-Z]{2})([ ]{1,2})?([0-9]*)?%'; + $fake_city_reg = '%([0-9]+)%'; $start_timer = time(); $debug = false; $clear_data = false; @@ -275,6 +277,9 @@ class GlmMembersFront_events_icalFeedImport } ++$number_events; // generate the slug name for this new event + if ( $number_events > 30 ) { + // die('Stopping here'); + } $event_abstract = new GlmDataEvents( $this->wpdb, $this->config ); $event_abstract->updateSlug( $event_id ); @@ -306,15 +311,129 @@ class GlmMembersFront_events_icalFeedImport } // Location Data if ( isset( $event['LOCATION'] ) ) { - $location_data = explode( ',', str_replace( '\\', '', $event['LOCATION'] ) ); - // Place will be before the first dash - $placeParts = explode( ' - ', $location_data[0] ); - $place = ( isset( $placeParts[0] ) ? $placeParts[0]: ''); - $address = ( isset( $placeParts[1] ) ? $placeParts[1]: ''); - $city = ( isset( $location_data[1] ) ? $location_data[1]: ''); - $state = ( isset( $location_data[2] ) ? $location_data[2]: ''); - $zip = ( isset( $location_data[3] ) ? $location_data[3]: ''); - $location = array( + // Check to see if there's a dash (venue - address) normal + // if not then everything is separated by \, + if ( strpos( $event['LOCATION'], ' - ' ) ) { + $location_data = explode( ',', str_replace( '\\', '', $event['LOCATION'] ) ); + // Place will be before the first dash + $placeParts = explode( ' - ', $location_data[0] ); + $place = ( isset( $placeParts[0] ) ? $placeParts[0]: ''); + $address = ( isset( $placeParts[1] ) ? $placeParts[1]: ''); + $city = ( isset( $location_data[1] ) ? $location_data[1]: ''); + $state = ( isset( $location_data[2] ) ? $location_data[2]: ''); + $zip = ( isset( $location_data[3] ) ? $location_data[3]: ''); + } else { + // Remove USA or United States from the ending + $event['LOCATION'] = str_replace('\\, USA', '', $event['LOCATION'] ); + $event['LOCATION'] = str_replace('\\, United States', '', $event['LOCATION'] ); + $event['LOCATION'] = str_replace('\\, United States of America', '', $event['LOCATION'] ); + $location_data = explode( ',', str_replace( '\\', '', $event['LOCATION'] ) ); + $place = $address = $city = $state = $zip = ''; + + // echo '
$location_data: ' . print_r( $location_data, true ) . '
'; + $loc_count = count( $location_data ); + switch ( $loc_count ) { + case 1: + $place = ( isset( $location_data[0] ) ? $location_data[0]: ''); + break; + case 2: + $place = ( isset( $location_data[0] ) ? $location_data[0]: ''); + $city = ( isset( $location_data[1] ) ? $location_data[1]: ''); + // Check if they stuck the state and zip together (MI 49707) + if ( $city && preg_match( $state_zip_reg, $city, $matches ) ) { + // echo '
city $matches: ' . print_r( $matches, true ) . '
'; + $city = ''; + $address = ''; + $state = $matches[1]; + $zip = $matches[3]; + } else if ( $city && preg_match( $fake_city_reg, $city, $matched ) ) { + // If we find numbers in the city then this should goto the address field. + // echo '
$matched: ' . print_r( $matched, true ) . '
'; + $address = $city; + $city = ''; + } + break; + case 3: + $place = ( isset( $location_data[0] ) ? $location_data[0]: ''); + $address = ( isset( $location_data[1] ) ? $location_data[1]: ''); + $city = ( isset( $location_data[2] ) ? $location_data[2]: ''); + // Check if they stuck the state and zip together (MI 49707) + if ( $city && preg_match( $state_zip_reg, $city, $matches ) ) { + // echo '
$matches: ' . print_r( $matches, true ) . '
'; + $city = $address; + $address = ''; + $state = $matches[1]; + $zip = $matches[3]; + } else if ( $city && preg_match( $fake_city_reg, $city, $matched ) ) { + // If we find numbers in the city then this should goto the address field. + // echo '
$matched: ' . print_r( $matched, true ) . '
'; + $address = $city; + $city = ''; + } + break; + case 4: + $place = ( isset( $location_data[0] ) ? $location_data[0]: ''); + $address = ( isset( $location_data[1] ) ? $location_data[1]: ''); + $city = ( isset( $location_data[2] ) ? $location_data[2]: ''); + $state = ( isset( $location_data[3] ) ? $location_data[3]: ''); + + // Check if they stuck the state and zip together (MI 49707) + if ( $city && preg_match( $state_zip_reg, $city, $matches ) ) { + // echo '
$matches: ' . print_r( $matches, true ) . '
'; + $city = ''; + $address = ''; + $state = $matches[1]; + $zip = $matches[3]; + } else if ( $city && preg_match( $fake_city_reg, $city, $matched ) ) { + // If we find numbers in the city then this should goto the address field. + // echo '
$matched: ' . print_r( $matched, true ) . '
'; + $address = $city; + $city = ''; + } + // Check if they stuck the state and zip together (MI 49707) + if ( $state && preg_match( $state_zip_reg, $state, $matches ) ) { + // echo '
$matches: ' . print_r( $matches, true ) . '
'; + $state = $matches[1]; + $zip = $matches[3]; + } + break; + case 5: + echo '

5

'; + $place = ( isset( $location_data[0] ) ? $location_data[0]: ''); + $place .= ( isset( $location_data[1] ) ? ' ' . $location_data[1]: ''); + $address = ( isset( $location_data[2] ) ? $location_data[2]: ''); + $city = ( isset( $location_data[3] ) ? $location_data[3]: ''); + $state = ( isset( $location_data[4] ) ? $location_data[4]: ''); + + // echo '
$place: ' . print_r( $place, true ) . '
'; + // echo '
$address: ' . print_r( $address, true ) . '
'; + // echo '
$city: ' . print_r( $city, true ) . '
'; + // echo '
$state: ' . print_r( $state, true ) . '
'; + + // Check if they stuck the state and zip together (MI 49707) + if ( $city && preg_match( $state_zip_reg, $city, $matches ) ) { + // echo '
$matches: ' . print_r( $matches, true ) . '
'; + $city = ''; + $address = ''; + $state = $matches[1]; + $zip = $matches[3]; + } else if ( $city && preg_match( $fake_city_reg, $city, $city_matches ) ) { + // If we find numbers in the city then this should goto the address field. + // echo '
$city_matches: ' . print_r( $city_matches, true ) . '
'; + $address = $city; + $city = ''; + } + // Check if they stuck the state and zip together (MI 49707) + if ( $state && preg_match( $state_zip_reg, $state, $matches ) ) { + // echo '
$matches: ' . print_r( $matches, true ) . '
'; + $state = $matches[1]; + $zip = $matches[3]; + } + break; + } + } + + $location = array( 'event' => $event_id, 'name' => $place, 'address' => $address, @@ -322,6 +441,7 @@ class GlmMembersFront_events_icalFeedImport 'state' => $state, 'zip' => $zip, ); + // echo '
$location: ' . print_r( $location, true ) . '
'; $location_format = array( '%d', '%s', '%s', '%d', '%s', '%s' ); -- 2.17.1