Bug fix for time.ly import
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 29 Jul 2016 11:48:25 +0000 (07:48 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 29 Jul 2016 11:48:25 +0000 (07:48 -0400)
Need to place the array reset for address outside of this if hasLocation

index.php
models/admin/management/events.php

index 5b4d167..c72ae2c 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.2.21
+ * Version: 1.2.22
  * 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.2.21
+ * @version 1.2.22
  */
 
 /*
@@ -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.2.21');
+define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.2.22');
 define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.18');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
index 0022277..255ae0e 100644 (file)
@@ -617,10 +617,10 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
     }
 
     public function addTimelyCategories() {
-               $category_counter = 0;
+        $category_counter = 0;
         $categories = get_terms( 'events_categories' );
         foreach ( $categories as $category ) {
-                       ++$category_counter;
+            ++$category_counter;
             // first check to see if the category is already there
             $sql = "
             SELECT id
@@ -647,14 +647,14 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                 $this->oldCatMap[$category->term_id] = $found['id'];
             }
         }
-               // Store the oldCatMap for the next pages.
-               update_option( 'glm-member-event-old-cat-map', serialize( $this->oldCatMap ) );
-               return "<p>Adding $category_counter Categories</p>";
+        // Store the oldCatMap for the next pages.
+        update_option( 'glm-member-event-old-cat-map', serialize( $this->oldCatMap ) );
+        return "<p>Adding $category_counter Categories</p>";
+    }
+    public function getOldCatMap()
+    {
+        return unserialize( get_option('glm-member-event-old-cat-map') );
     }
-       public function getOldCatMap()
-       {
-               return unserialize( get_option('glm-member-event-old-cat-map') );
-       }
     /**
      * getTime
      *
@@ -1128,25 +1128,25 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
         return $return;
     }
     public function importFromTimely() {
-               $limit = 25;
-               $debug = false;
-               if ( isset( $_REQUEST['start'] ) ) {
-                       $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT );
-               } else {
-                       $start = 0;
-               }
-               if ( $start === 0 ) {
-                       // clear the events tables first.
-                       $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events" );
-                       $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences" );
-                       $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times" );
-                       $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories" );
-                       $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "locations" );
-                       // Add the Categories from Time.ly.
-                       $return_string = $this->addTimelyCategories();
-               } else {
-                       $this->oldCatMap = $this->getOldCatMap();
-               }
+        $limit = 25;
+        $debug = false;
+        if ( isset( $_REQUEST['start'] ) ) {
+            $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT );
+        } else {
+            $start = 0;
+        }
+        if ( $start === 0 ) {
+            // clear the events tables first.
+            $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events" );
+            $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences" );
+            $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times" );
+            $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories" );
+            $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "locations" );
+            // Add the Categories from Time.ly.
+            $return_string = $this->addTimelyCategories();
+        } else {
+            $this->oldCatMap = $this->getOldCatMap();
+        }
 
         $yearly_events =
         $daily_events =
@@ -1164,14 +1164,14 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
           FROM " . $this->wpdb->prefix . "posts
          WHERE post_type = 'ai1ec_event'
            AND post_status = 'publish'";
-               //$sql .= " AND ID IN ( SELECT post_id FROM " . $this->wpdb->prefix . "ai1ec_events
-               //WHERE end >= " . time() . " )";
+        //$sql .= " AND ID IN ( SELECT post_id FROM " . $this->wpdb->prefix . "ai1ec_events
+        //WHERE end >= " . time() . " )";
         //$sql .= " AND ID IN ( 1647 )";
-               $sql .= " LIMIT $limit OFFSET $start";
+        $sql .= " LIMIT $limit OFFSET $start";
         $results = $this->wpdb->get_results( $sql, ARRAY_A );
 
         //echo '<p>Total events: ' . count( $results ) . '</p>';
-               $event_counter = 0;
+        $event_counter = 0;
 
         if ( !empty( $results ) ) {
             foreach ( $results as $post ) {
@@ -1180,7 +1180,7 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                 if ( $debug ) {
                     echo '<div style="border:1px solid green;">';
                 }
-                               ++$event_counter;
+                ++$event_counter;
                 //echo '<pre>$post: ' . print_r($post, true) . '</pre>';
                 $sql        = "
                 SELECT *
@@ -1268,16 +1268,16 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                     $event_import_data,
                     $event_data_format
                 );
-                               if ( $debug ) {
-                                       var_dump( $is_insert );
-                               }
+                if ( $debug ) {
+                    var_dump( $is_insert );
+                }
                 $event_id  = $this->wpdb->insert_id;
-                               if ( $debug ) {
-                                       var_dump( $event_id );
-                               }
-                               if ( !$event_id ) {
-                                       $this->wpdb->print_error();
-                                       echo '<pre>$event_import_data: ' . print_r($event_import_data, true) . '</pre>';
+                if ( $debug ) {
+                    var_dump( $event_id );
+                }
+                if ( !$event_id ) {
+                    $this->wpdb->print_error();
+                    echo '<pre>$event_import_data: ' . print_r($event_import_data, true) . '</pre>';
                     echo '<pre>SQL Error: ' . $this->wpdb->last_error . '</pre>';
                     echo '<pre>SQL Error: ' . $this->wpdb->print_error() . '</pre>';
                     die('something is wrong no event_id');
@@ -1298,10 +1298,10 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                         )
                     );
                 }
-                               if ( $debug ) {
+                if ( $debug ) {
                     echo '<pre>$event_data: ' . print_r($event_data, true) . '</pre>';
-                                       echo '<pre>$categories: ' . print_r($categories, true) . '</pre>';
-                               }
+                    echo '<pre>$categories: ' . print_r($categories, true) . '</pre>';
+                }
 
                 $by_day_of_month =
                 $last_day_of_month = null;
@@ -1319,23 +1319,23 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
 
                 $custom_times = array();
                 $curZone = date_default_timezone_get();
-                               if ( $debug ) {
+                if ( $debug ) {
                     echo '<pre>$curZone: ' . print_r($curZone, true) . '</pre>';
-                               }
+                }
                 if ( $event_data['timezone_name'] ) {
                     date_default_timezone_set( $event_data['timezone_name'] );
                 }
                 $curZone = date_default_timezone_get();
-                               if ( $debug ) {
+                if ( $debug ) {
                     echo '<pre>$curZone: ' . print_r($curZone, true) . '</pre>';
-                               }
+                }
 
                 $from_date = date( 'Y-m-d', $event_data['start'] );
-                               if ( $debug ) {
-                                       echo '<pre>$from_date: ' . print_r($from_date, true) . '</pre>';
+                if ( $debug ) {
+                    echo '<pre>$from_date: ' . print_r($from_date, true) . '</pre>';
                     $from_date_time = date( 'Y-m-d H:m:s', $event_data['start'] );
                     echo '<pre>$from_date_time: ' . print_r($from_date_time, true) . '</pre>';
-                               }
+                }
                 $to_date   = date( 'Y-m-d', $event_data['end'] );
                 // check if the $to_date has 0 hr
                 // if the btime and etime are 00:00 then remove one day from $to_date
@@ -1344,27 +1344,27 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                     $ending_datetime->modify('- 1 day');
                     $to_date = $ending_datetime->format( 'Y-m-d' );
                 }
-                               if ( $debug ) {
-                                       echo '<pre>$to_date: ' . print_r($to_date, true) . '</pre>';
+                if ( $debug ) {
+                    echo '<pre>$to_date: ' . print_r($to_date, true) . '</pre>';
                     $to_date_time = date( 'Y-m-d H:m:s', $event_data['end'] );
                     echo '<pre>$to_date_time: ' . print_r($to_date_time, true) . '</pre>';
-                               }
+                }
                 $btime     = date( 'H:i', $event_data['start'] );
-                               if ( $debug ) {
-                                       echo '<pre>$btime: ' . print_r($btime, true) . '</pre>';
-                               }
+                if ( $debug ) {
+                    echo '<pre>$btime: ' . print_r($btime, true) . '</pre>';
+                }
                 $etime     = date( 'H:i', $event_data['end'] );
-                               if ( $debug ) {
-                                       echo '<pre>$etime: ' . print_r($etime, true) . '</pre>';
+                if ( $debug ) {
+                    echo '<pre>$etime: ' . print_r($etime, true) . '</pre>';
                 }
 
 
                 if ( $event_data['recurrence_rules'] ) {
                     $recurring_event = 1;
                     $recurrence_rules = explode( ';', $event_data['recurrence_rules'] );
-                                       if ( $debug ) {
-                                               echo '<pre>$recurrence_rules: ' . print_r($recurrence_rules, true) . '</pre>';
-                                       }
+                    if ( $debug ) {
+                        echo '<pre>$recurrence_rules: ' . print_r($recurrence_rules, true) . '</pre>';
+                    }
                     foreach ( $recurrence_rules as $rule ) {
                         // check for RDATE , which are the custom dates that need to be serialized
                         if(strpos($rule, 'RDATE') !== false){
@@ -1374,9 +1374,9 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                             $custom_times = explode(',', $rdate);
                         }
                         if ( preg_match( ';FREQ=(.*);', $rule, $matches ) ) {
-                                                       if ( $debug ) {
-                                                               echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
-                                                       }
+                            if ( $debug ) {
+                                echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
+                            }
                             switch ( $matches[1] ) {
                                 case "WEEKLY":
                                     $weekly_events++;
@@ -1533,9 +1533,9 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                                     break;
                             }
                         } else if ( preg_match( ';COUNT=(.*);', $rule, $matches ) ) {
-                                                       if ( $debug ) {
-                                                               echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
-                                                       }
+                            if ( $debug ) {
+                                echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
+                            }
                             // set the end date to COUNT days from start
                             try {
                                 $number_of_days    = (int)$matches[1] - 1;
@@ -1545,10 +1545,10 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                                 $to_date           = $ending_date->format( 'Y-m-d' );
                                 $recurring_event   = 0;
                             } catch (Exception $e) {
-                                                               if ( $debug ) {
-                                                                       echo '<pre>$e: ' . print_r($e, true) . '</pre>';
-                                                               }
-                                                               die();
+                                if ( $debug ) {
+                                    echo '<pre>$e: ' . print_r($e, true) . '</pre>';
+                                }
+                                die();
                             }
                         } else if ( preg_match( ';UNTIL=(.*);', $rule, $matches ) ) {
                             $to_date = date( 'Y-m-d', strtotime( $matches[1] ) );
@@ -1572,9 +1572,9 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
 
                         }else if ( preg_match( ';BYday=(.*);', $rule, $matches ) ) {
 
-                                                       if ( $debug ) {
-                                                               echo '<pre>1354 $matches: ' . print_r($matches, true) . '</pre>';
-                                                       }
+                            if ( $debug ) {
+                                echo '<pre>1354 $matches: ' . print_r($matches, true) . '</pre>';
+                            }
                             // check if the selection is the nth week with a selected day, if not parse the input as a list if selected days
                             if(strpos($matches[1], ",") == false){
                                 $week_number = substr($matches[1],0, 1);
@@ -1618,7 +1618,7 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                         date_default_timezone_set('UTC');
                         $serialized_custom_times = serialize($custom_times);
                         foreach($custom_times as $custom){
-                     
+
                             $convert = date('U',strtotime($custom));
                             $stamp[] = date('Y-m-d', $convert);
                         }
@@ -1627,14 +1627,14 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                     }
                     date_default_timezone_set($curZone);
                 }
-                               if ($recurring_event && $from_date == $to_date && empty( $custom_times ) ) {
-                                       // Add two years to the recurring event if dates match
-                                       $starting_datetime = new DateTime( $from_date );
-                                       $ending_date       = $starting_datetime->modify('2 years');
-                                       $to_date           = $ending_date->format( 'Y-m-d' );
-                               }
+                if ($recurring_event && $from_date == $to_date && empty( $custom_times ) ) {
+                    // Add two years to the recurring event if dates match
+                    $starting_datetime = new DateTime( $from_date );
+                    $ending_date       = $starting_datetime->modify('2 years');
+                    $to_date           = $ending_date->format( 'Y-m-d' );
+                }
                 $all_day       = $event_data['allday'];
-                
+
                 // instant event is an event with no end time
                 $start_time_only = $event_data['instant_event'];
                 if($start_time_only){
@@ -1660,9 +1660,9 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                     'last_day_of_month'    => $last_day_of_month,
                     'specific_dates'       => $serialized_custom_times
                 );
-                               if ( $debug ) {
-                                       echo '<pre>$recur_data: ' . print_r($recur_data, true) . '</pre>';
-                               }
+                if ( $debug ) {
+                    echo '<pre>$recur_data: ' . print_r($recur_data, true) . '</pre>';
+                }
                 $this->wpdb->insert(
                     GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
                     $recur_data,
@@ -1689,8 +1689,8 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                 $Recurrences->createRecurrenceTimesEntries( $recurr_id, true, true );
                 // location for the event
                 $has_location = ( $event_data['address'] || $event_data['venue'] );
+                $location_data = $location_format = array();
                 if ( $has_location ) {
-                    $location_data = $location_format = array();
                     $location_data['event'] = $event_id;
                     $location_format[] = '%d';
                     if ($event_data['venue']) {
@@ -1732,9 +1732,9 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                     );
                     $location_id = $this->wpdb->insert_id;
                     if ( !$location_id ) {
-                                               if ( $debug ) {
-                                                       echo '<pre>$location_data: ' . print_r($location_data, true) . '</pre>';
-                                               }
+                        if ( $debug ) {
+                            echo '<pre>$location_data: ' . print_r($location_data, true) . '</pre>';
+                        }
                         die('no return id for location');
                     }
                 }
@@ -1742,17 +1742,17 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                     echo '</div>';
                 }
             }
-                       $return_string .= "<p>Adding $event_counter Events</p>";
+            $return_string .= "<p>Adding $event_counter Events</p>";
         }
-               $return_string .= "<pre>
-                       Start: $start
-               </pre>";
-               $start += $limit;
-               $return_string .= "<p><a href=\""
-                       . GLM_MEMBERS_PLUGIN_CURRENT_URL
-                       . "?page=glm-members-admin-menu-management&glm_action=events&option=timelyImport&import=true"
-                       . "&start=$start\">Next</a></p>";
-               return $return_string;
+        $return_string .= "<pre>
+            Start: $start
+        </pre>";
+        $start += $limit;
+        $return_string .= "<p><a href=\""
+            . GLM_MEMBERS_PLUGIN_CURRENT_URL
+            . "?page=glm-members-admin-menu-management&glm_action=events&option=timelyImport&import=true"
+            . "&start=$start\">Next</a></p>";
+        return $return_string;
     }
 }