Update the ical feed and ical feed imort
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 2 Mar 2017 18:54:17 +0000 (13:54 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 2 Mar 2017 18:54:17 +0000 (13:54 -0500)
Adding the ability to pass the custom dates and deal with our new event
ical feed in the import for feeds.

index.php
models/front/events/icalFeed.php
models/front/events/icalFeedImport.php

index 978da17..b922db5 100644 (file)
--- a/index.php
+++ b/index.php
@@ -3,7 +3,7 @@
  * Plugin Name: GLM Members Database Events
  * Plugin URI: http://www.gaslightmedia.com/
  * Description: Gaslight Media Members Database.
- * Version: 1.6.11
+ * Version: 1.6.12
  * Author: Chuck Scott
  * Author URI: http://www.gaslightmedia.com/
  * License: GPL2
@@ -20,7 +20,7 @@
  * @package glmMembersDatabaseEventsAddOn
  * @author Chuck Scott <cscott@gaslightmedia.com>
  * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 1.6.11
+ * @version 1.6.12
  */
 
 /*
@@ -38,7 +38,7 @@
  *  so that we're sure the other add-ons see an up to date
  *  version from this plugin.
  */
-define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.6.11');
+define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.6.12');
 define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.1.1');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
index 4fd0a83..fe3b7e6 100644 (file)
@@ -259,6 +259,17 @@ EOD;
                 }
                 $output .=  "\nRRULE:" . $freq .";BYDAY=" . $daysInWeek . ";UNTIL="
                     . $this->icalDateFormat($event['ending_timestamp']);
+                // Check now for the Specific dates
+                if ( isset( $event['recurrences'][0]['specific_dates'] ) && is_array( $event['recurrences'][0]['specific_dates'] ) ) {
+                    $rDates = array();
+                    foreach ( $event['recurrences'][0]['specific_dates'] as $eDate ) {
+                        $rDates[] = str_replace( '-', '', $eDate );
+                    }
+                    if ( !empty( $rDates ) ) {
+                        $output .= "\nRDATE;VALUE=DATE:";
+                        $output .= implode( ',',$rDates );
+                    }
+                }
             }
         }
         $output .= $eventTemplateEnd;
index 3fa8f81..f386bc6 100644 (file)
@@ -95,6 +95,9 @@ class GlmMembersFront_events_icalFeedImport
                 $feed_id
             )
         );
+        if ( $debug ) {
+            $out .= '<pre>$feed_url: ' . print_r( $feed_url, true ) . '</pre>';
+        }
         // Set new updated date for feed
         $this->wpdb->update(
             GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'feed_import',
@@ -118,21 +121,44 @@ class GlmMembersFront_events_icalFeedImport
         }
         if ( $events ) {
             foreach ( $events as $event ) {
+                if ( $debug ) {
+                    $out .= '<pre>$event: ' . print_r( $event, true ) . '</pre>';
+                }
                 $contact = array();
                 $image   = '';
                 $event['DESCRIPTION']
                     = str_replace( '\n', "<br>", $event['DESCRIPTION'] );
                 $intro        = substr( strip_tags( $event['DESCRIPTION'] ), 0 ,150);
                 if ( isset( $event['CONTACT'] ) ) {
-                    $contact_data = explode( ',', str_replace( '\\', '', $event['CONTACT'] ) );
+                    // Remove the backslashes
+                    $eventContact = str_replace( '\\', '', $event['CONTACT'] );
                     if ( $debug ) {
-                        //$out .= '<pre>$contact_data: ' . print_r( $contact_data, true ) . '</pre>';
+                        $out .= '<pre>$eventContact: ' . print_r( $eventContact, true ) . '</pre>';
+                    }
+
+                    // Check if the event CONTACT has semi colons in it.
+                    // If it does then the CONTACT string hold the contact email phone and name.
+                    if ( strpos( $eventContact, ';' ) !== false ) {
+                        $contact_data = explode( ';', $eventContact );
+                        if ( $debug ) {
+                            $out .= '<pre>' . __LINE__ . '$contact_data: ' . print_r( $contact_data, true ) . '</pre>';
+                        }
+                        $contact = array(
+                            'email' => $contact_data[0],
+                            'phone' => $contact_data[2],
+                            'name'  => $contact_data[3],
+                        );
+                    } else {
+                        $contact_data = explode( ',', $eventContact );
+                        if ( $debug ) {
+                            $out .= '<pre>$contact_data: ' . print_r( $contact_data, true ) . '</pre>';
+                        }
+                        $contact = array(
+                            'name'  => $contact_data[0],
+                            'email' => $contact_data[1],
+                            'phone' => $contact_data[2],
+                        );
                     }
-                    $contact = array(
-                        'name'  => $contact_data[0],
-                        'email' => $contact_data[1],
-                        'phone' => $contact_data[2],
-                    );
                 } else {
                     $contact = array(
                         'name'  => '',
@@ -189,7 +215,7 @@ class GlmMembersFront_events_icalFeedImport
                     'contact_phone' => $contact['phone'],
                 );
                 if ( $debug ) {
-                    //$out .= '<pre>$event_data: ' . print_r( $event_data, true ) . '</pre>';
+                    $out .= '<pre>$event_data: ' . print_r( $event_data, true ) . '</pre>';
                 }
                 $event_data_format = array(
                     '%d',
@@ -207,21 +233,25 @@ class GlmMembersFront_events_icalFeedImport
                     '%s',
                     '%s',
                 );
-                if ( $event_id ) {
-                    $this->wpdb->update(
-                        GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
-                        $event_data,
-                        array( 'id' => $event_id ),
-                        $event_data_format,
-                        '%d'
-                    );
+                if ( !$debug ) {
+                    if ( $event_id ) {
+                        $this->wpdb->update(
+                            GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
+                            $event_data,
+                            array( 'id' => $event_id ),
+                            $event_data_format,
+                            '%d'
+                        );
+                    } else {
+                        $this->wpdb->insert(
+                            GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
+                            $event_data,
+                            $event_data_format
+                        );
+                        $event_id  = $this->wpdb->insert_id;
+                    }
                 } else {
-                    $this->wpdb->insert(
-                        GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
-                        $event_data,
-                        $event_data_format
-                    );
-                    $event_id  = $this->wpdb->insert_id;
+                    continue;
                 }
                 if ( !$event_id ) {
                     continue;
@@ -375,6 +405,18 @@ class GlmMembersFront_events_icalFeedImport
                         }
                     }
                 }
+                if ( isset( $event['RDATE'] ) && preg_match( '%VALUE=DATE:(.*)%', $event['RDATE'], $matches ) ) {
+                    $rDates = explode( ',', $matches[1] );
+                    foreach ( $rDates as $key => &$rDate ) {
+                        if ( preg_match( '%([0-9]{4})([0-9]{2})([0-9]{2})%', $rDate, $rDateMatches )  ) {
+                            $rDate = $rDateMatches[1].'-'.$rDateMatches[2].'-'.$rDateMatches[3];
+                        }
+                    }
+                    $serialized_times = serialize($rDates);
+                    $recurring_event  = 1;
+                    $month_of_year    = 0;
+                    $week_of_month    = 0;
+                }
                 if ( $btime === $etime ) {
                     if ( $btime === '00:00' ) {
                         $all_day = true;