New db version for events
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 12 Aug 2016 17:22:19 +0000 (13:22 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 12 Aug 2016 17:23:48 +0000 (13:23 -0400)
Adding two new fields for the ical_feed table.
Field: duration to store how long the import of the events is taking.
Field: events to store how many events were fetched in the last fetch.

index.php
models/admin/ajax/icalFeedImport.php [new file with mode: 0644]
models/front/events/icalFeedImport.php [new file with mode: 0644]
setup/databaseScripts/create_database_V0.0.19.sql [deleted file]
setup/databaseScripts/create_database_V0.0.20.sql [new file with mode: 0644]
setup/databaseScripts/dbVersions.php
setup/databaseScripts/update_database_V0.0.20.sql [new file with mode: 0644]
setup/frontHooks.php
setup/validActions.php
views/admin/management/events.html

index aa1579b..62c6dcf 100644 (file)
--- a/index.php
+++ b/index.php
@@ -39,7 +39,7 @@
  *  version from this plugin.
  */
 define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.3.0');
-define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.19');
+define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.20');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
 define('GLM_MEMBERS_EVENTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.58');
diff --git a/models/admin/ajax/icalFeedImport.php b/models/admin/ajax/icalFeedImport.php
new file mode 100644 (file)
index 0000000..ddc79a7
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * PDF Output by admin-ajax
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+require_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/models/front/events/icalFeedImport.php';
+/**
+ * Steve Note...
+ *
+ * You can get to this using the following URL.
+ *
+ *  {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=pdfOutput&mystuff=THIS
+ *
+ * You should be able to do this as POST or GET and should be able to add and read additional parameters.
+ * I added a "mystuff" parameter to the URL above and it does output from the code in the
+ * modelAction() function below.
+ *
+ * To add another model under models/admin/ajax all you need to do is create it and add it to the
+ * setup/validActions.php file.
+ *
+ */
+
+// Load Members data abstract
+// require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php');
+
+/**
+ * This class performs the work of handling images passed to it via
+ * an AJAX call that goes through the WorPress AJAX Handler.
+ *
+ */
+class GlmMembersAdmin_ajax_icalFeedImport
+    extends GlmMembersFront_events_icalFeedImport
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+}
diff --git a/models/front/events/icalFeedImport.php b/models/front/events/icalFeedImport.php
new file mode 100644 (file)
index 0000000..79d3761
--- /dev/null
@@ -0,0 +1,453 @@
+<?php
+/**
+ * detail.php
+ *
+ * This is the Member Event Plugin model for the front detail shortcode.
+ * Handles the view of the detail pages.
+ */
+require GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/classes/data/dataEvents.php';
+require GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/classes/data/dataCategories.php';
+require GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/classes/data/dataRecurrences.php';
+require GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/classes/data/dataLocations.php';
+
+/**
+ * GLmMembersFront_event_detail
+ *
+ * @uses      GlmDataEvents
+ * @package   GlmMemberEvents
+ * @version   0.0.1
+ * @copyright Copyright (c) 2010 All rights reserved.
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @license   PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}
+ */
+class GlmMembersFront_events_icalFeedImport
+{
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+    }
+
+    public function modelAction( $actionData = false ) {
+        if ( $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
+            echo $this->importIcalFeed( $id );
+        }
+        exit;
+    }
+    public function clearData()
+    {
+        $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" );
+    }
+    public function importIcalFeed( $feed_id )
+    {
+        $debug         = false;
+        $clear_data    = false;
+        $number_events = 0;
+        if ( $clear_data ) {
+            $this->clearData();
+        }
+        $feed_content = $out = '';
+        $event_data   = array();
+
+        $feed_url = $this->wpdb->get_var(
+            $this->wpdb->prepare(
+                "SELECT feed_url
+                   FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "feed_import
+                  WHERE id = %d",
+                $feed_id
+            )
+        );
+        // Set new updated date for feed
+        $this->wpdb->update(
+            GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'feed_import',
+            array( 'updated' => current_time( 'mysql' ) ),
+            array( 'id' => $feed_id ),
+            '%s',
+            '%d'
+        );
+
+        $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config);
+        require_once GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php';
+        $image_upload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config);
+
+        // Get the feed data
+        $filename = $this->fetchIcalFile( $feed_url );
+        require GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/classes/icalReader.php';
+        $ical = new ical($filename);
+        $events = $ical->events();
+        if ( $debug ) {
+             $out .= '<pre>$events: ' . print_r( $events, true ) . '</pre>';
+        }
+        if ( $events ) {
+            foreach ( $events as $event ) {
+                $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'] ) );
+                    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],
+                    );
+                } else {
+                    $contact = array(
+                        'name'  => '',
+                        'email' => '',
+                        'phone' => '',
+                    );
+                }
+                // check for this event record first to see if it can be
+                // updated instead of insert
+                $event_id = $this->wpdb->get_var(
+                    $this->wpdb->prepare(
+                        "SELECT id
+                           FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
+                          WHERE ical_uid = %s",
+                        $event['UID']
+                    )
+                );
+                $old_image = '';
+                if ( isset( $event['ATTACH'] ) ) {
+                    // See if we already have this image.
+                    $img_url = preg_replace( '%FMTTYPE=image/(jpeg|gif|png)[:]%', '', $event['ATTACH'] );
+                    if ( $img_url ) {
+                        if ( $event_id ) {
+                            $old_image = $this->wpdb->get_var(
+                                $this->wpdb->prepare(
+                                    "SELECT image
+                                       FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "
+                                      WHERE id = %d",
+                                    $event_id
+                                )
+                            );
+                            $image = $old_image;
+                        }
+                        if ( !$old_image ) {
+                            $res   = $image_upload->storeImage( $img_url );
+                            $image = $res['newFileName'];
+                        }
+                    }
+                }
+                $event_data   = array(
+                    'status'        => $this->config['status_numb']['Active'],
+                    'ref_type'      => 10,
+                    'created'       => $ical->iCalDateToUnixTimestamp( $event['CREATED'] ),
+                    'updated'       => $ical->iCalDateToUnixTimestamp( $event['CREATED'] ),
+                    'approved'      => null,
+                    'ical_uid'      => $event['UID'],
+                    'name'          => $event['SUMMARY'],
+                    'intro'         => $intro,
+                    'descr'         => $event['DESCRIPTION'],
+                    'image'         => $image,
+                    'url'           => ( isset( $event['URL'] ) ? $event['URL']: '' ),
+                    'contact_email' => $contact['name'],
+                    'contact_name'  => $contact['email'],
+                    'contact_phone' => $contact['phone'],
+                );
+                if ( $debug ) {
+                    //$out .= '<pre>$event_data: ' . print_r( $event_data, true ) . '</pre>';
+                }
+                $event_data_format = array(
+                    '%d',
+                    '%d',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%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'
+                    );
+                } else {
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
+                        $event_data,
+                        $event_data_format
+                    );
+                    $event_id  = $this->wpdb->insert_id;
+                }
+                if ( !$event_id ) {
+                    die('something is wrong no event_id');
+                }
+                // generate the slug name for this new event
+                $event_abstract = new GlmDataEvents( $this->wpdb, $this->config );
+                $event_abstract->updateSlug( $event_id );
+                // Location Data
+                if ( isset( $event['LOCATION'] ) ) {
+                    $location_data = explode( ',', str_replace( '\\', '', $event['LOCATION'] ) );
+                    $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]: '');
+                    $zip           = ( isset( $location_data[4] ) ? $location_data[4]: '');
+                    $location      = array(
+                        'event'   => $event_id,
+                        'name'    => $place,
+                        'address' => $address,
+                        'city'    => $this->getCityId( $city ),
+                        'state'   => $state,
+                        'zip'     => $zip,
+                    );
+                    $location_format = array(
+                        '%d', '%s', '%s', '%d', '%s', '%s'
+                    );
+                    if ( isset( $event['GEO'] ) ) {
+                        $geo_data = explode( ';', $event['GEO'] );
+                        $location['lat'] = $geo_data[0];
+                        $location['lon'] = $geo_data[1];
+                        $location_format[] = '%s';
+                        $location_format[] = '%s';
+                    }
+                    // Remove any old location data for this event_id.
+                    $this->wpdb->delete(
+                        GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations',
+                        array( 'event' => $event_id ),
+                        '%d'
+                    );
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations',
+                        $location,
+                        $location_format
+                    );
+                }
+                // Remove any old recurrences data for this event_id.
+                $this->wpdb->delete(
+                    GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
+                    array( 'event' => $event_id ),
+                    '%d'
+                );
+                // Remove any old times data for this event_id.
+                $this->wpdb->delete(
+                    GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'times',
+                    array( 'event' => $event_id ),
+                    '%d'
+                );
+                $serialized_times  = null;
+                $day_of_week       =
+                $day_of_month      =
+                $month_of_year     =
+                $week_of_month     =
+                $by_day_of_month   =
+                $last_day_of_month = null;
+                $start_time_only   =
+                $all_day           =
+                $recurring_event   = 0;
+                $day_of_week       = 127;
+                $month_of_year     = 4095;
+                $week_of_month     = 63;
+                $starting          = $ical->iCalDateToUnixTimestamp( $event['DTSTART'] );
+                $ending            = $ical->iCalDateToUnixTimestamp( $event['DTEND'] );
+                $from_date         = date( 'Y-m-d', $starting );
+                $to_date           = date( 'Y-m-d', $ending );
+                $btime             = date( 'H:i', $starting );
+                $etime             = date( 'H:i', $ending );
+                $freq = $byday = $until = '';
+                if ( isset( $event['RRULE'] ) ) {
+                    $recurring_event = 1;
+                    $rrule_data = explode( ';', $event['RRULE'] );
+                    //echo '<pre>$rrule_data: ' . print_r( $rrule_data, true ) . '</pre>';
+                    if ( $rrule_data ) {
+                        foreach ( $rrule_data as $rule ) {
+                            if ( preg_match( '%FREQ=(.*)%', $rule, $matches ) ) {
+                                $freq = trim( $matches[1] );
+                            }
+                            if ( preg_match( '%BYDAY=(.*)%', $rule, $matches ) ) {
+                                $byday = trim( $matches[1] );
+                            }
+                            if ( preg_match( '%UNTIL=(.*)%', $rule, $matches ) ) {
+                                $until = trim( $matches[1] );
+                            }
+                        }
+                    }
+                    if ( $freq === 'WEEKLY' && $byday ) {
+                        // separated by commas
+                        $days = explode( ',',$byday );
+                        //echo '<pre>$days: ' . print_r( $days, true ) . '</pre>';
+                        if ( $days ) {
+                            $day_of_week = 0;
+                            foreach ( $days as $day ) {
+                                if ( preg_match( '%([0-9])?([A-Z]{2})%', $day, $d_matches ) ) {
+                                    //echo '<pre>$d_matches: ' . print_r( $d_matches, true ) . '</pre>';
+                                    if ( $d_matches[1] ) {
+                                        $week_of_month = pow(2, $d_matches[1] );
+                                    }
+                                    switch ( $d_matches[2] ) {
+                                    case "SU":
+                                        $day_of_week += pow(2, 0);
+                                        break;
+                                    case "MO":
+                                        $day_of_week += pow(2, 1);
+                                        break;
+                                    case "TU":
+                                        $day_of_week += pow(2, 2);
+                                        break;
+                                    case "WE":
+                                        $day_of_week += pow(2, 3);
+                                        break;
+                                    case "TH":
+                                        $day_of_week += pow(2, 4);
+                                        break;
+                                    case "FR":
+                                        $day_of_week += pow(2, 5);
+                                        break;
+                                    case "SA":
+                                        $day_of_week += pow(2, 6);
+                                        break;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    if ( $until != '' ) {
+                        //echo '<pre>$until: ' . print_r( $until, true ) . '</pre>';
+                        $test_date = $ical->iCalDateToUnixTimestamp( $until );
+                        if ( $test_date ) {
+                            $to_date = date( 'Y-m-d', $test_date );
+                        }
+                        //echo '<pre>$test_date: ' . print_r( date( 'm/d/Y', $test_date), true ) . '</pre>';
+                    }
+                }
+                if ( $btime === $etime ) {
+                    if ( $btime === '00:00' ) {
+                        $all_day = true;
+                    } else {
+                        $start_time_only = true;
+                    }
+                }
+                if ( $btime && $etime && $etime === '00:00' ) {
+                    $start_time_only = true;
+                }
+                // for the recurrences part
+                $recur_data = array(
+                    'event'             => $event_id,
+                    'name'              => 'Imported',
+                    'start_time'        => $btime,
+                    'end_time'          => $etime,
+                    'start_time_only'   => $start_time_only,
+                    'from_date'         => $from_date,
+                    'to_date'           => $to_date,
+                    'all_day'           => $all_day,
+                    'recurring'         => $recurring_event,
+                    'month_of_year'     => $month_of_year,
+                    'week_of_month'     => $week_of_month,
+                    'day_of_week'       => $day_of_week,
+                    'day_of_month'      => $day_of_month,
+                    'by_day_of_month'   => $by_day_of_month,
+                    'last_day_of_month' => $last_day_of_month,
+                    'specific_dates'    => $serialized_times
+                );
+                $this->wpdb->insert(
+                    GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
+                    $recur_data,
+                    array(
+                         '%d',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%s'
+                    )
+                );
+                $recurr_id    = $this->wpdb->insert_id;
+                $Recurrences->createRecurrenceTimesEntries( $recurr_id, true, true );
+                ++$number_events;
+            }
+        }
+        if ( !$debug ) {
+            $out = $number_events . ' events imported';
+        }
+        return $out;
+    }
+    public function fetchIcalFile( $url )
+    {
+        $path = '/tmp';
+        $filename = tempnam( $path, "ICAL" );
+        $fp = fopen( $filename, 'w+' );
+        $ch = curl_init( $url );
+        curl_setopt( $ch, CURLOPT_TIMEOUT, 50 );
+        curl_setopt( $ch, CURLOPT_FILE, $fp );
+        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
+        $fileData = curl_exec( $ch );
+        $httpCode = curl_getinfo( $ch );
+        curl_close( $ch );
+        fclose( $fp );
+        // Set correct file permissions
+        $oldUmask = umask( 0 );
+        chmod( $filename, 0660 );
+        umask( $oldUmask );
+        return $filename;
+    }
+    /**
+     * getCityId
+     *
+     * Given a city name find and return the id of the city.
+     * If a city cannot be found then create city with that name.
+     *
+     * @param mixed $city_name Name of the city
+     *
+     * @access public
+     * @return id of city
+     */
+    public function getCityId($city_name)
+    {
+        if ( !$city_name ) {
+            return false;
+        }
+        $sql = "
+        SELECT id
+          FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities
+         WHERE name like '" . esc_sql( trim( $city_name ) ) . "'";
+        $cityId = $this->wpdb->get_row($sql, ARRAY_A);
+        if ( !$cityId ) {
+            // then add the city to the city table
+            $this->wpdb->insert(
+                GLM_MEMBERS_PLUGIN_DB_PREFIX . 'cities',
+                array( 'name' => trim( $city_name ) ),
+                array( '%s' )
+            );
+            return $this->wpdb->insert_id;
+        } else {
+            return $cityId['id'];
+        }
+    }
+
+
+}
diff --git a/setup/databaseScripts/create_database_V0.0.19.sql b/setup/databaseScripts/create_database_V0.0.19.sql
deleted file mode 100644 (file)
index 56d1eba..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
--- Gaslight Media Members Database - Events Add-On
--- File Created: 12/02/15 15:27:15
--- Database Version: 0.0.19
--- Database Creation Script
---
--- This file is called to create a new set of tables for this
--- add-on for the most recent database version for this add-on.
---
--- There should only be one such file in this directory
---
--- To permit each query below to be executed separately,
--- all queries must be separated by a line with four dashes
-
--- Categories - Categories for events
-CREATE TABLE {prefix}categories (
-  id INT NOT NULL AUTO_INCREMENT,
-  name TINYTEXT NULL,                                   -- Name of event category
-  descr TINYTEXT NULL,                                  -- Description of this category
-  parent INT NULL,                                      -- Parent category, null or 0 if this is a top level category
-  PRIMARY KEY (id),
-  INDEX(parent)
-);
-
-----
-
--- Event-Category - Categories for specific event records
-CREATE TABLE {prefix}event_categories (
-  id INT NOT NULL AUTO_INCREMENT,
-  event INT NULL,                                       -- Pointer to the event
-  category INT NULL,                                    -- Pointer to the category
-  PRIMARY KEY (id),
-  INDEX(event),
-  INDEX(category)
-);
-
-----
-
--- Event Recurrence - Defines how an event recurs
-CREATE TABLE {prefix}recurrences (
-  id INT NOT NULL AUTO_INCREMENT,
-  event INTEGER NULL,                                   -- Pointer to event
-  name TINYTEXT NULL,                                   -- Name of this recurrence schedule - used on admin calendar
-  start_time TIME NULL,                                 -- Start time of day for event
-  start_time_only BOOLEAN NULL,                         -- Use end of first occurrence flag
-  end_time TIME NULL,                                   -- End time of day for event - If less than start time, assume a date boundry
-  all_day BOOLEAN NULL,                                 -- Flag indicating if this is an all-day event (informational only)
-  start_date DATE NULL,                                 -- Starting Date (if all_day is selected) Used instead of start_time
-  from_date DATE NULL,                                  -- From Date for recurrences
-  to_date DATE NULL,                                    -- To Date for recurrences
-  recurring BOOLEAN NULL,                               -- Flag indicating that event recurs on a schedule rather than all dates
-  month_of_year SMALLINT UNSIGNED NULL,                 -- Month of year (bitmap)
-  week_of_month TINYINT UNSIGNED NULL,                  -- Week of the month (bitmap)
-  day_of_week TINYINT UNSIGNED NULL,                    -- Day of the week (bitmap)
-  by_day_of_month BOOLEAN NULL,                         -- Flag indicating if selecting by days of the month
-  day_of_month INTEGER UNSIGNED NULL,                   -- Day of the month (bitmap)
-  last_day_of_month BOOLEAN NULL,                       -- Last day of the month
-  specific_dates TEXT NULL,                             -- Serialized array of specific dates added to the recurrence
-  holiday INT NULL,                                     -- Pointer to holidays list (for future development)
-  holiday_offset TINYINT,                               -- Offset from holiday (from -128 to +127 days)
-  PRIMARY KEY (id),
-  INDEX(event)
-);
-
-----
-
--- Times - List of actual event times for single and recurring events
-CREATE TABLE {prefix}times (
-  id INT NOT NULL AUTO_INCREMENT,
-  event INT NULL,                                       -- Pointer to the primary record for the event
-  custom_event INT NULL,                                -- Pointer to a customized copy of the event record (if set)
-  recur_id INT NULL,                                    -- Pointer to recurrence entry
-  active BOOLEAN NULL,                                  -- Active flag - normally set but used to temporarily disable a specific date
-  start_time DATETIME NULL,                             -- Date and time event starts
-  end_time DATETIME NULL,                               -- Date and time event ends
-  all_day BOOLEAN NULL,                                 -- All Day flag
-  PRIMARY KEY (id),
-  INDEX(event),
-  INDEX(start_time),
-  INDEX(end_time)
-);
-
-----
-
--- Locations - Locations for event - If there's no location pointing to an event try to use the referenced entity in events table
-CREATE TABLE {prefix}locations (
-  id INT NOT NULL AUTO_INCREMENT,
-  event INT NULL,                                       -- Pointer to the primary or custom event record
-  name TINYTEXT NULL,                                   -- Name of location
-  address TINYTEXT NULL,                                -- Street Address
-  city INT NULL,                                        -- Pointer to city - references main plugin city table
-  state TINYTEXT NULL,                                  -- Two character state abbreviation
-  zip TINYTEXT NULL,                                    -- ZIP/Postal code
-  country TINYTEXT NULL,                                -- Country Code
-  lat FLOAT NULL,                                       -- Latitude of location
-  lon FLOAT NULL,                                       -- Longitude of location
-  region INT NULL,                                      -- Pointer to Region - references main plugin region table
-  phone TINYTEXT NULL,                                  -- Location Phone #
-  url TINYTEXT NULL,                                    -- Location URL
-  email TINYTEXT NULL,                                  -- Location E-Mail Address
-  contact_addon_id INT NULL,                            -- ID of Contact from contact add-on (optional and if available)
-  contact_fname TINYTEXT NULL,                          -- Contact first name for this location (optional)
-  contact_lname TINYTEXT NULL,                          -- Contact last name for this location (optional)
-  contact_phone TINYTEXT NULL,                          -- Contact phone for this location (optional)
-  contact_email TINYTEXT NULL,                          -- Contact E-Mail address (optional)
-  PRIMARY KEY (id)
-);
-
-----
-
--- Events - Base event information - May also be entries here referenced by the "times" table for a custom date.
-CREATE TABLE {prefix}events (
-  id INT NOT NULL AUTO_INCREMENT,
-  status INT NULL,                                      -- Status for this event, see config['status']
-  custom_time INT NULL,                                 -- If this is a custom record for a specific instance (date) this points to that times table entry
-  root_event INT NULL,                                  -- Root event pointer if this is a custom record for a specific instance (date) (if custom_time is set)
-  created DATETIME NULL,                                -- Date/Time event was created or date custom event record was created if custom record
-  updated DATETIME NULL,                                -- Date/Time this event record was last updated
-  approved DATETIME NULL,                               -- Date/Ttime this event record was approved
-  ref_type INT NULL,                                    -- Type of entity this contact is associated with - See config['ref_type']
-  ref_dest INT NULL,                                    -- Pointer to the specific entity of ref_type this contact is associated with
-  hide_address BOOLEAN NULL,                            -- Option to hide address on front-end
-  featured BOOLEAN NULL,                                -- Option to mark as featured event
-  slideshow BOOLEAN NULL,                               -- Option to mark for use in slide show
-  major BOOLEAN NULL,                                   -- Option to mark as a major event
-  name TINYTEXT NULL,                                   -- Name of this event
-  name_slug TINYTEXT NULL,                              -- Slug for this event
-  header TINYTEXT NULL,                                 -- Header text for front-end display - NOT CURRENTLY USED
-  intro TINYTEXT NULL,                                  -- Intro text for front-end display
-  descr TEXT NULL,                                      -- Full description text
-  image TINYTEXT NULL,                                  -- Image file name
-  file1 TINYTEXT NULL,                                  -- File name for a single uploaded file #1
-  file1_descr TINYTEXT NULL,                            -- Description for file uploaded in field "file" #1
-  file2 TINYTEXT NULL,                                  -- File name for a single uploaded file #2
-  file2_descr TINYTEXT NULL,                            -- Description for file uploaded in field "file" #2
-  file3 TINYTEXT NULL,                                  -- File name for a single uploaded file #3
-  file3_descr TINYTEXT NULL,                            -- Description for file uploaded in field "file" #3
-  url TINYTEXT NULL,                                    -- Event URL
-  ticket_url TINYTEXT NULL,                             -- Ticket URL
-  cost TINYTEXT NULL,                                   -- Description of event cost
-  admin_ref_type INT NULL,                              -- Type of admin contact if using a member contact
-  admin_ref_dest INT NULL,                              -- Pointer to admin contact record if using a member contact
-  admin_name TINYTEXT NULL,                             -- Admin Contact Name if not using a member contact
-  admin_org TINYTEXT NULL,                              -- Admin Contact Organization if not using a member contact
-  admin_email TINYTEXT NULL,                            -- Admin Contact E-Mail if not using a member contact
-  admin_phone TINYTEXT NULL,                            -- Admin Contact Phone if not using a member contact
-  free BOOLEAN NULL,                                    -- Event is Free
-  contact_email TINYTEXT NULL,                          -- Contact E-mail address
-  contact_name TINYTEXT NULL,                           -- Contact name
-  contact_phone TINYTEXT NULL,                          -- Event Phone
-  use_member_location BOOLEAN NULL,                     -- Use location of the member (if provided) rather than location table data
-  old_event_id INT NULL,                                -- ID of event from old site for reference
-  ical_uid TINYTEXT NULL,                               -- The ical UID for this event.
-  notes TEXT NULL,                                      -- Internal notes for this event
-  PRIMARY KEY (id),
-  INDEX(custom_time),
-  INDEX(root_event),
-  INDEX(ref_type),
-  INDEX(ref_dest),
-  INDEX(featured),
-  INDEX(slideshow),
-  INDEX(major)
-);
-
-----
-
--- Event Management Settings
-CREATE TABLE {prefix}management (
-  id INT NOT NULL AUTO_INCREMENT,
-  canonical_event_page TINYTEXT NULL, -- Canonical page slug for event detail
-  pdf_logo TINYTEXT NULL,             -- Image for the Top of the PDF
-  footer_text TINYTEXT NULL,          -- Image for the Top of the PDF
-  to_email TINYTEXT NULL,             -- Email address of the recipient
-  from_email TINYTEXT NULL,           -- Email address of the sender
-  email_notification TEXT NULL,       -- Email notification message
-  PRIMARY KEY (id)
-);
-
-----
-
--- Set default event management entry
-INSERT INTO {prefix}management
-    ( id, canonical_event_page )
-   VALUES
-    ( 1, 'event-detail' )
-;
-
-----
-
--- Event iCal Feed imports
-CREATE TABLE {prefix}feed_import (
-  id INT NOT NULL AUTO_INCREMENT,
-  feed_url TEXT NOT NULL,            -- The ical feed url to import
-  created DATETIME NULL,             -- The date this feed was created
-  updated DATETIME NULL,             -- Last time this feed was updated
-  PRIMARY KEY (id)
-);
diff --git a/setup/databaseScripts/create_database_V0.0.20.sql b/setup/databaseScripts/create_database_V0.0.20.sql
new file mode 100644 (file)
index 0000000..96f0160
--- /dev/null
@@ -0,0 +1,198 @@
+-- Gaslight Media Members Database - Events Add-On
+-- File Created: 12/02/15 15:27:15
+-- Database Version: 0.0.19
+-- Database Creation Script
+--
+-- This file is called to create a new set of tables for this
+-- add-on for the most recent database version for this add-on.
+--
+-- There should only be one such file in this directory
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+-- Categories - Categories for events
+CREATE TABLE {prefix}categories (
+  id INT NOT NULL AUTO_INCREMENT,
+  name TINYTEXT NULL,                                   -- Name of event category
+  descr TINYTEXT NULL,                                  -- Description of this category
+  parent INT NULL,                                      -- Parent category, null or 0 if this is a top level category
+  PRIMARY KEY (id),
+  INDEX(parent)
+);
+
+----
+
+-- Event-Category - Categories for specific event records
+CREATE TABLE {prefix}event_categories (
+  id INT NOT NULL AUTO_INCREMENT,
+  event INT NULL,                                       -- Pointer to the event
+  category INT NULL,                                    -- Pointer to the category
+  PRIMARY KEY (id),
+  INDEX(event),
+  INDEX(category)
+);
+
+----
+
+-- Event Recurrence - Defines how an event recurs
+CREATE TABLE {prefix}recurrences (
+  id INT NOT NULL AUTO_INCREMENT,
+  event INTEGER NULL,                                   -- Pointer to event
+  name TINYTEXT NULL,                                   -- Name of this recurrence schedule - used on admin calendar
+  start_time TIME NULL,                                 -- Start time of day for event
+  start_time_only BOOLEAN NULL,                         -- Use end of first occurrence flag
+  end_time TIME NULL,                                   -- End time of day for event - If less than start time, assume a date boundry
+  all_day BOOLEAN NULL,                                 -- Flag indicating if this is an all-day event (informational only)
+  start_date DATE NULL,                                 -- Starting Date (if all_day is selected) Used instead of start_time
+  from_date DATE NULL,                                  -- From Date for recurrences
+  to_date DATE NULL,                                    -- To Date for recurrences
+  recurring BOOLEAN NULL,                               -- Flag indicating that event recurs on a schedule rather than all dates
+  month_of_year SMALLINT UNSIGNED NULL,                 -- Month of year (bitmap)
+  week_of_month TINYINT UNSIGNED NULL,                  -- Week of the month (bitmap)
+  day_of_week TINYINT UNSIGNED NULL,                    -- Day of the week (bitmap)
+  by_day_of_month BOOLEAN NULL,                         -- Flag indicating if selecting by days of the month
+  day_of_month INTEGER UNSIGNED NULL,                   -- Day of the month (bitmap)
+  last_day_of_month BOOLEAN NULL,                       -- Last day of the month
+  specific_dates TEXT NULL,                             -- Serialized array of specific dates added to the recurrence
+  holiday INT NULL,                                     -- Pointer to holidays list (for future development)
+  holiday_offset TINYINT,                               -- Offset from holiday (from -128 to +127 days)
+  PRIMARY KEY (id),
+  INDEX(event)
+);
+
+----
+
+-- Times - List of actual event times for single and recurring events
+CREATE TABLE {prefix}times (
+  id INT NOT NULL AUTO_INCREMENT,
+  event INT NULL,                                       -- Pointer to the primary record for the event
+  custom_event INT NULL,                                -- Pointer to a customized copy of the event record (if set)
+  recur_id INT NULL,                                    -- Pointer to recurrence entry
+  active BOOLEAN NULL,                                  -- Active flag - normally set but used to temporarily disable a specific date
+  start_time DATETIME NULL,                             -- Date and time event starts
+  end_time DATETIME NULL,                               -- Date and time event ends
+  all_day BOOLEAN NULL,                                 -- All Day flag
+  PRIMARY KEY (id),
+  INDEX(event),
+  INDEX(start_time),
+  INDEX(end_time)
+);
+
+----
+
+-- Locations - Locations for event - If there's no location pointing to an event try to use the referenced entity in events table
+CREATE TABLE {prefix}locations (
+  id INT NOT NULL AUTO_INCREMENT,
+  event INT NULL,                                       -- Pointer to the primary or custom event record
+  name TINYTEXT NULL,                                   -- Name of location
+  address TINYTEXT NULL,                                -- Street Address
+  city INT NULL,                                        -- Pointer to city - references main plugin city table
+  state TINYTEXT NULL,                                  -- Two character state abbreviation
+  zip TINYTEXT NULL,                                    -- ZIP/Postal code
+  country TINYTEXT NULL,                                -- Country Code
+  lat FLOAT NULL,                                       -- Latitude of location
+  lon FLOAT NULL,                                       -- Longitude of location
+  region INT NULL,                                      -- Pointer to Region - references main plugin region table
+  phone TINYTEXT NULL,                                  -- Location Phone #
+  url TINYTEXT NULL,                                    -- Location URL
+  email TINYTEXT NULL,                                  -- Location E-Mail Address
+  contact_addon_id INT NULL,                            -- ID of Contact from contact add-on (optional and if available)
+  contact_fname TINYTEXT NULL,                          -- Contact first name for this location (optional)
+  contact_lname TINYTEXT NULL,                          -- Contact last name for this location (optional)
+  contact_phone TINYTEXT NULL,                          -- Contact phone for this location (optional)
+  contact_email TINYTEXT NULL,                          -- Contact E-Mail address (optional)
+  PRIMARY KEY (id)
+);
+
+----
+
+-- Events - Base event information - May also be entries here referenced by the "times" table for a custom date.
+CREATE TABLE {prefix}events (
+  id INT NOT NULL AUTO_INCREMENT,
+  status INT NULL,                                      -- Status for this event, see config['status']
+  custom_time INT NULL,                                 -- If this is a custom record for a specific instance (date) this points to that times table entry
+  root_event INT NULL,                                  -- Root event pointer if this is a custom record for a specific instance (date) (if custom_time is set)
+  created DATETIME NULL,                                -- Date/Time event was created or date custom event record was created if custom record
+  updated DATETIME NULL,                                -- Date/Time this event record was last updated
+  approved DATETIME NULL,                               -- Date/Ttime this event record was approved
+  ref_type INT NULL,                                    -- Type of entity this contact is associated with - See config['ref_type']
+  ref_dest INT NULL,                                    -- Pointer to the specific entity of ref_type this contact is associated with
+  hide_address BOOLEAN NULL,                            -- Option to hide address on front-end
+  featured BOOLEAN NULL,                                -- Option to mark as featured event
+  slideshow BOOLEAN NULL,                               -- Option to mark for use in slide show
+  major BOOLEAN NULL,                                   -- Option to mark as a major event
+  name TINYTEXT NULL,                                   -- Name of this event
+  name_slug TINYTEXT NULL,                              -- Slug for this event
+  header TINYTEXT NULL,                                 -- Header text for front-end display - NOT CURRENTLY USED
+  intro TINYTEXT NULL,                                  -- Intro text for front-end display
+  descr TEXT NULL,                                      -- Full description text
+  image TINYTEXT NULL,                                  -- Image file name
+  file1 TINYTEXT NULL,                                  -- File name for a single uploaded file #1
+  file1_descr TINYTEXT NULL,                            -- Description for file uploaded in field "file" #1
+  file2 TINYTEXT NULL,                                  -- File name for a single uploaded file #2
+  file2_descr TINYTEXT NULL,                            -- Description for file uploaded in field "file" #2
+  file3 TINYTEXT NULL,                                  -- File name for a single uploaded file #3
+  file3_descr TINYTEXT NULL,                            -- Description for file uploaded in field "file" #3
+  url TINYTEXT NULL,                                    -- Event URL
+  ticket_url TINYTEXT NULL,                             -- Ticket URL
+  cost TINYTEXT NULL,                                   -- Description of event cost
+  admin_ref_type INT NULL,                              -- Type of admin contact if using a member contact
+  admin_ref_dest INT NULL,                              -- Pointer to admin contact record if using a member contact
+  admin_name TINYTEXT NULL,                             -- Admin Contact Name if not using a member contact
+  admin_org TINYTEXT NULL,                              -- Admin Contact Organization if not using a member contact
+  admin_email TINYTEXT NULL,                            -- Admin Contact E-Mail if not using a member contact
+  admin_phone TINYTEXT NULL,                            -- Admin Contact Phone if not using a member contact
+  free BOOLEAN NULL,                                    -- Event is Free
+  contact_email TINYTEXT NULL,                          -- Contact E-mail address
+  contact_name TINYTEXT NULL,                           -- Contact name
+  contact_phone TINYTEXT NULL,                          -- Event Phone
+  use_member_location BOOLEAN NULL,                     -- Use location of the member (if provided) rather than location table data
+  old_event_id INT NULL,                                -- ID of event from old site for reference
+  ical_uid TINYTEXT NULL,                               -- The ical UID for this event.
+  notes TEXT NULL,                                      -- Internal notes for this event
+  PRIMARY KEY (id),
+  INDEX(custom_time),
+  INDEX(root_event),
+  INDEX(ref_type),
+  INDEX(ref_dest),
+  INDEX(featured),
+  INDEX(slideshow),
+  INDEX(major)
+);
+
+----
+
+-- Event Management Settings
+CREATE TABLE {prefix}management (
+  id INT NOT NULL AUTO_INCREMENT,
+  canonical_event_page TINYTEXT NULL, -- Canonical page slug for event detail
+  pdf_logo TINYTEXT NULL,             -- Image for the Top of the PDF
+  footer_text TINYTEXT NULL,          -- Image for the Top of the PDF
+  to_email TINYTEXT NULL,             -- Email address of the recipient
+  from_email TINYTEXT NULL,           -- Email address of the sender
+  email_notification TEXT NULL,       -- Email notification message
+  PRIMARY KEY (id)
+);
+
+----
+
+-- Set default event management entry
+INSERT INTO {prefix}management
+    ( id, canonical_event_page )
+   VALUES
+    ( 1, 'event-detail' )
+;
+
+----
+
+-- Event iCal Feed imports
+CREATE TABLE {prefix}feed_import (
+  id INT NOT NULL AUTO_INCREMENT,
+  feed_url TEXT NOT NULL,            -- The ical feed url to import
+  created DATETIME NULL,             -- The date this feed was created
+  updated DATETIME NULL,             -- Last time this feed was updated
+  duration INT NULL,                 -- The time it took to fetch the feed
+  events INT NULL,                   -- The number of events last fetched
+  PRIMARY KEY (id)
+);
index c49c6d0..a64504a 100644 (file)
@@ -31,5 +31,6 @@ $glmMembersEventsDbVersions = array(
     '0.0.17' => array('version' => '0.0.17', 'tables' => 7, 'date' => '5/5/2016'),
     '0.0.18' => array('version' => '0.0.18', 'tables' => 7, 'date' => '5/26/2016'),
     '0.0.19' => array('version' => '0.0.19', 'tables' => 8, 'date' => '8/05/2016'),
+    '0.0.20' => array('version' => '0.0.20', 'tables' => 8, 'date' => '8/12/2016'),
 );
 
diff --git a/setup/databaseScripts/update_database_V0.0.20.sql b/setup/databaseScripts/update_database_V0.0.20.sql
new file mode 100644 (file)
index 0000000..bd70fd3
--- /dev/null
@@ -0,0 +1,14 @@
+-- Gaslight Media Members Database  - Events Add-On
+-- File Created: 12/09/14 15:27:15
+-- Database Version: 0.0.18
+-- Database Update From Previous Version Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+
+ALTER TABLE {prefix}feed_import ADD duration INT NULL;  -- The time it took to fetch the feed
+
+----
+
+ALTER TABLE {prefix}feed_import ADD events INT NULL;    -- The number of events last fetched
index 972d85d..333bebe 100644 (file)
@@ -135,8 +135,17 @@ if (isset($this->config['addOns']['glm-member-db'])) {
 add_action(
     GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT,
     function( $id ) {
-        echo '<pre>$id: ' . print_r( $id, true ) . '</pre>';
-        //$this->controller( 'cron', 'icalFeed' );
+        if ( $id ) {
+            $admin_url                   = admin_url();
+            $ical_feed_import_url        = $admin_url
+                . 'admin-ajax.php?action=glm_members_admin_ajax&glm_action=icalFeedImport&id=' . $id;
+            echo '<pre>$ical_feed_import_url: ' . print_r( $ical_feed_import_url, true ) . '</pre>';
+            $response                    = wp_remote_get( $ical_feed_import_url );
+            $response_headers            = wp_remote_retrieve_headers( $response );
+            $response_body               = wp_remote_retrieve_body( $response );
+            echo '<pre>$response_headers: ' . print_r( $response_headers, true ) . '</pre>';
+            echo '<pre>$response_body: ' . print_r( $response_body, true ) . '</pre>';
+        }
     },
     10,
     1
index 9912088..aba3399 100644 (file)
 $glmMembersEventsAddOnValidActions = array(
     'adminActions' => array(
         'ajax' => array(
-            'pdfOutput'  => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
-            'nameSearch' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
-            'icalFeed'   => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
-            'rssFeed'   => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
+            'pdfOutput'          => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
+            'nameSearch'         => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
+            'icalFeed'           => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
+            'rssFeed'            => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
             'eventsCalMonthAJAX' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
+            'icalFeedImport'     => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
         ),
         'member' => array(
             'events' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
index 9b43bde..29be050 100644 (file)
                             <td>{$feed.feed_url}</td>
                             <td>{$feed.created}</td>
                             <td>{$feed.updated}</td>
-                            <td>{$feed.next_runtime}</td>
+                            <td>{$feed.next_runtime|date_format:"%F %T"}</td>
                             <td><a href="{$thisUrl}?page={$thisPage}&glm_action=events&option=icalfeed&option2=delete&id={$feed.id}"
                                    onClick="return confirm('This cannot be undone!\nAre you sure?')" class="button">Delete</a></td>
                         </tr>