Working on the ical feed for event profile
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 16 May 2016 21:25:17 +0000 (17:25 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 18 May 2016 14:55:22 +0000 (10:55 -0400)
Creating an ical feed for event profile.

models/admin/ajax/icalFeed.php [new file with mode: 0644]
models/front/events/icalFeed.php [new file with mode: 0644]
setup/validActions.php
views/front/events/detail.html

diff --git a/models/admin/ajax/icalFeed.php b/models/admin/ajax/icalFeed.php
new file mode 100644 (file)
index 0000000..e7db76c
--- /dev/null
@@ -0,0 +1,59 @@
+<?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/icalFeed.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_icalFeed extends GlmMembersFront_events_icalFeed
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+}
diff --git a/models/front/events/icalFeed.php b/models/front/events/icalFeed.php
new file mode 100644 (file)
index 0000000..468b2b2
--- /dev/null
@@ -0,0 +1,118 @@
+<?php
+/**
+ * detail.php
+ *
+ * This is the Member Event Plugin model for the front detail shortcode.
+ * Handles the view of the detail pages.
+ */
+
+require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataEvents.php';
+require_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/models/front/events/baseAction.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_icalFeed extends GlmMembersFront_events_baseAction
+{
+    /**
+     * modelAction
+     *
+     * @param bool $actionData Action Data passed to the modelAction
+     *
+     * @access public
+     * @return void
+     */
+    public function modelAction($actionData = false)
+    {
+        $action = '';
+        $fromDate = date('m/d/Y');
+        $this->dateRange = "start_time >= '{$fromDate}'";
+
+        if ( isset($_REQUEST['eventId']) && $eventId = filter_var($_REQUEST['eventId'], FILTER_VALIDATE_INT)) {
+            $search = true;
+            if ($ical = filter_var($_REQUEST['ical'], FILTER_VALIDATE_BOOLEAN)) {
+                $action = 'event-ical';
+            }
+        }
+
+        switch ($action) {
+        case 'event-ical':
+            $event = $this->getModelEventData($eventId);
+            echo '<pre>$event: ' . print_r($event, true) . '</pre>';
+$icalHeader = <<<EOD
+BEGIN:VCALENDAR
+PRODID:-//Gaslight Media Inc//Gaslight Events Calendar v2.0/EN
+VERSION:2.0
+CALSCALE:GREGORIAN
+METHOD:PUBLISH
+EOD;
+
+$icalFooter = <<<EOD
+\nEND:VCALENDAR
+EOD;
+
+$eventTemplateStart = <<<EOD
+\nBEGIN:VEVENT
+UID:%d@%s
+CREATED:%s
+DTSTAMP:%s
+DTSTART:%s
+DTEND:%s
+%s
+SUMMARY:%s
+STATUS:CONFIRMED
+EOD;
+$eventTemplateEnd = <<<EOD
+\nEND:VEVENT
+EOD;
+            $dateTimeFormat  = '%s %s:%s %s';
+            $dateFormat      = '%s';
+            $timeStampFormat = 'Ymd\THis';
+            $weekdays        =
+                array(1 => 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
+            //header('Content-type: text/calendar; charset=utf-8');
+            //header('Content-Disposition: inline; filename=event-' . $eventId . '.ics');
+            $output .= '<pre>';
+            $output .= $icalHeader;
+            // clean description
+            $description = 'DESCRIPTION:' . str_replace("\n", "\\n", strip_tags($event['descr']));
+            $description = str_replace("\r", '', $description);
+            $urlParts    = parse_url(get_bloginfo('url'), PHP_URL_HOST);
+            $urlHost     = str_replace('www.', '', $urlParts);
+            $eventDataStart = sprintf($eventTemplateStart,
+                $event['id'],
+                $urlHost,
+                $this->icalDateFormat($event['starting_timestamp']),
+                $this->icalDateFormat($event['starting_timestamp']),
+                $this->icalDateFormat($event['starting_timestamp']),
+                ($event['reacur'])
+                    ? $this->icalDateFormat($event['starting_timestamp'])
+                    : $this->icalDateFormat($event['ending_timestamp']),
+                $description,
+                $event['name']
+            );
+            $output .= $eventDataStart;
+            $output .= $eventTemplateEnd;
+            $output .= $icalFooter;
+            $output .= '</pre>';
+            echo $output;
+            exit;
+            break;
+        default:
+            die('should not reach this');
+            break;
+        }
+    }
+
+    function icalDateFormat($datetime)
+    {
+        return date('Ymd\THis', $datetime);
+    }
+}
index 9c4c97b..0a8f9c0 100644 (file)
@@ -33,8 +33,9 @@
 $glmMembersEventsAddOnValidActions = array(
     'adminActions' => array(
         'ajax' => array(
-            'pdfOutput' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
-            'nameSearch' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG
+            'pdfOutput'  => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
+            'nameSearch' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
+            'icalFeed'   => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
         ),
         'member' => array(
             'events' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
@@ -55,7 +56,7 @@ $glmMembersEventsAddOnValidActions = array(
             'list'     => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
             'detail'   => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
             'frontAdd' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
-            'pdf'      => GLM_MEMBERS_EVENTS_PLUGIN_SLUG
+            'pdf'      => GLM_MEMBERS_EVENTS_PLUGIN_SLUG,
         )
     )
 );
index 7a3cc5a..7c7426e 100644 (file)
@@ -1,6 +1,7 @@
 <div id="glm-event-wrapper" class="event-detail text-left"> 
     <div class="row">
         <button id="glm-event-detail-backtosearch">Back To Search</button>
+        <a style="float:right;" href="../../wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=icalFeed&eventId={$event.id}&ical=1">Ical Feed</a>
     </div>
     <div class="row">
         <div class="small-12 column eventTitle">