Tagged: ,

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #42587
    Anonymous
    Inactive

    Here’s my dilemma:

    I’m publishing a rehearsal schedule. It unfortunately changes frequently and often on the same day (illnesses). So I need to push changes out. We have a wide variety of technical abilities. I’ve published the RSS feed for the events and implemented PubSubHub to push the changes out quickly. But for those that don’t know about RSS feeds, but do use calendars like Outlook, Evolution, Google Calendar, and smartphone calendars – having the changes show up right in their calendar would be nice.

    So here’s my solution:

    I’ve created a public google calendar that people can add to their outlook or evolution or smartphone. And I got the API for the calendar from Google. So far I’ve been able to write a little script to add an event to the google calendar. My plan is to add an action when the save button is clicked in admin, that the google calendar will be immediately updated.

    So why don’t I just use the google calendar and feed it down into WordPress? Lots of plugins for that. Because the Google calendar can’t color code, can’t have the information laid out in an easy to use format, and I don’t want my admin to have to do some admin in WordPress and some in Google.

    So this really isn’t a feature request, more of a notice that I’m working on a feature that I’ll be happy to share when I get it working.

    #47020
    Franky
    Keymaster

    You have the possibility to subscribe to an ICAL feed if wanted.

    And also, read this: http://www.e-dynamics.be/bbpress/topic.php?id=180

    #47021
    Anonymous
    Inactive

    Thanks, I’ve done that already, but maybe I’m missing something…

    It works fabulously for doing an initial load of the whole schedule into another calendar (I’ve tried) and even loading one event – in fact I’m working on getting QR codes to work too so that someone could add an event right to their smartphone calendar, but the ical feed can’t update an existing event on the calendar, right? So if the event changed (time, location, details), an update won’t be sent to them. They’ll have to come get it and unless they delete all the events and reload the whole file, they won’t know which event changed.

    What I’m thinking is that people will subscribe to the Google Calendar, and it will automatically sync with their desktop or mobile calendar so they’ll have the latest changes right away (if they have their calendar refresh set often enough). If there is an easier way, I’d be happy to use it.

    #47022
    Franky
    Keymaster
    #47023
    Anonymous
    Inactive

    Well, that would be a nice solution if it updated sooner. Using the API’s, the event shows up immediately. I added the ICAL feed to a google calendar this morning, and now, 4.5 hours later, it still hasn’t loaded any of the events in the google calendar. I think I’m going to have to stick with the API.

    #47024
    Franky
    Keymaster

    Yeah, like in the link I provided: they only update once a day or so, not configurable.

    But don’t overdo the developing: there’s a hook when an event gets saved, so you can plug into that:

    http://www.e-dynamics.be/wordpress/?cat=41

    #47025
    Anonymous
    Inactive

    Well, I’ve got it working! Events sent immediately to the Google Calendar when an event is added, edited, deleted or duplicated. I need to make the return messages look nice yet and when there is a problem, give a better error message. But it’s working 🙂

    The hooks made it possible – thanks for those.

    #47026
    Anonymous
    Inactive

    Hi wputler – could you post the code you wrote to use the hooks? I’m looking in to using them and some working examples would be great.

    #47027
    Anonymous
    Inactive

    Here’s the code for the Google Calendar sync. Keep in mind that I still haven’t added much error checking yet (and I did have to make a couple of small changes to the core to get things working (I’m hoping they can be included in future releases):

    eme_events.php

    LINE 2811

    added event ID to array so that the google calendar edit URL can be added to the attributes for future updates/deletes

    $event = $event_ID;

    LINE 1405

    Remove Google URL from duplicated event

    Note, the code doesn’t handle recurring events at all yet. The hooks are at the end of the code. This code is in my child theme’s function.php.

    /**********************************************************************/
    // Event Manager Extended - Add Google update, insert and delete functions
    function createGoogleCalConnection() {
    $client = "";

    if (is_admin()) {
    set_include_path('/home/user/php/ZendGdata-1.11.3/library');

    require_once 'Zend/Loader.php';
    Zend_Loader::loadClass('Zend_Gdata');
    Zend_Loader::loadClass('Zend_Gdata_AuthSub');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
    Zend_Loader::loadClass('Zend_Gdata_Calendar');

    Zend_Loader::loadClass('Zend_Gdata_App_HttpException');
    Zend_Loader::loadClass('Zend_Http_Client_Exception');
    # Zend_Loader::loadClass('Zend_Http_Client');
    # Zend_Loader::loadClass('Zend_Http_Client_Adapter_Proxy');

    $user = 'user@domain.com';
    $pass = 'password';
    $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar

    //$pdd_google_client = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,$service);

    try {
    $client = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,$service);
    } catch (Zend_Gdata_App_AuthException $ae) {
    echo 'Problem authenticating: ' . $ae->exception() . "n";
    return FALSE;
    }
    $gdataCal = new Zend_Gdata_Calendar($client);
    return $gdataCal;
    }

    } // end createGoogleCalConnection

    function pdd_insertGoogleEvent($g_event) {

    $title = '';
    $desc='';
    $where = '';
    $startDate = '';
    $startTime = '';
    $endDate = '';
    $endTime = '';
    $tzOffset = '';

    $title = $g_event['title'];
    $startDate = $g_event['when']['startDate'];
    $endDate = $g_event['when']['endDate'];
    $startTime = $g_event['when']['startTime'];
    $endTime = $g_event['when']['endTime'];
    $desc = $g_event['desc'];
    $where = $g_event['where'];
    $tzOffset = $g_event['tzOffset'];

    echo "" . $title . ", " . $desc . ", " . $where . ", " . $startDate . ", " . $startTime . ", " . $endDate . ", " . $endTime . ", " . $tzOffset . "";

    $gdataCal = createGoogleCalConnection();
    $newEvent = $gdataCal->newEventEntry();

    $newEvent->title = $gdataCal->newTitle($title);
    $newEvent->where = array($gdataCal->newWhere($where));
    $newEvent->content = $gdataCal->newContent("$desc");

    $when = $gdataCal->newWhen();
    $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";

    echo "Start: " . $when->startTime . "";
    $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
    echo "End: " . $when->endTime . "";

    $newEvent->when = array($when);

    //print_r($newEvent);
    // Upload the event to the calendar server
    // A copy of the event as it is recorded on the server is returned
    $createdEvent = $gdataCal->insertEvent($newEvent);
    return $createdEvent->id->text;

    } // end function pdd_insertGoogleEvent

    function pdd_updateGoogleEvent($g_event) {

    //print_r($g_event);
    $gdataCal = createGoogleCalConnection();
    if ($gdataCal) {
    // check to see if update or insert
    if (!empty($g_event['google_url'])) {

    $title = '';
    $desc='';
    $where = '';
    $startDate = '';
    $startTime = '';
    $endDate = '';
    $endTime = '';
    $tzOffset = '';

    $title = $g_event['title'];
    $startDate = $g_event['when']['startDate'];
    $endDate = $g_event['when']['endDate'];
    $startTime = $g_event['when']['startTime'];
    $endTime = $g_event['when']['endTime'];
    $desc = $g_event['desc'];
    $where = $g_event['where'];
    $tzOffset = $g_event['tzOffset'];

    // update
    // retrieve event
    // set new event properties and update event
    try {
    $gEvent = $gdataCal->getCalendarEventEntry($g_event['google_url']);
    $gEvent->title = $gdataCal->newTitle($title);
    $gEvent->content = $gdataCal->newContent("$desc");

    $gEvent->where = array($gdataCal->newWhere($where));
    $when = $gdataCal->newWhen();

    if ($startTime == $endTime && $startDate == $endDate) {

    $when->startTime = "{$startDate}";
    unset($when->endTime);

    } else {

    $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
    $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
    }

    $gEvent->when = array($when);
    $gEvent->save();
    } catch (Zend_Gdata_App_Exception $e) {
    die("Error: " . $e->getResponse());
    }
    echo 'Event successfully modified!';

    }
    }

    } // end function pdd_insertupdateGoogleEvent

    function pdd_map_to_google($event) {
    // should only be called after standardizing the event variable
    // not expecting attributes to be serialized

    // Manipulate the data to fit Google's fields
    $g_event = array();

    // if this event has attriutes
    if (!empty($event['event_attributes'])) {
    $tmp_attributes = '';
    $all_day_event = FALSE;

    foreach($event['event_attributes'] as $key => $value) {
    if ($key != 'GOOGLE_URL' && $key != 'TIME') {
    $tmp_attributes .= " " . $key . ": " . $value . " | ";
    }
    // In the TIME attribute, TBA means that the event doesn't have a time yet
    // and a dash means that it is all day
    // in both cases it should appear as an all day event to google
    // so only the start date is needed
    if ($key == 'TIME') {
    if ($value != '') { $all_day_event = TRUE; }
    }
    if ($key == 'GOOGLE_URL') { $g_event['google_url'] = $value; }
    }
    }
    //$g_event['desc'] = $event['event_notes'] . $tmp_attributes;
    $g_event['desc'] = '';

    // TITLE
    $g_event['title'] = $event['event_name'] . " - " . $event['event_notes'] . $tmp_attributes;;
    $g_event['title'] = strip_html_tags($g_event['title']);
    // WHERE
    if ($event['location_id'] != 0 && !empty($event['location_id'])) {
    $tmp_location = eme_get_location($event['location_id']);
    $g_event['where'] = $tmp_location['location_name'];
    }

    // WHEN
    // SET ARIZONA TIME ZONE
    $g_event['tzOffset'] = '-07';
    $g_event['when']['allDay'] = FALSE;

    // check for all day event
    if (empty($event['event_end_date']) || ($event['event_start_time'] == $event['event_end_time'])
    || ($all_day_event)) {

    $g_event['when']['allDay'] = TRUE;

    }

    $g_event['when']['startTime'] = substr($event['event_start_time'],0,5);
    $g_event['when']['startDate'] = $event['event_start_date'];
    $g_event['when']['endTime'] = substr($event['event_end_time'],0,5);
    $g_event['when']['endDate'] = $event['event_end_date'];

    return $g_event;

    } // end function pdd_map_to_google

    /**********************************************************************/
    function pdd_standardize_event($event) {

    // sometimes event is returned with the attributes serialized and sometimes not
    // this will unserialize them

    $event_attributes = array();
    if (!empty($event['event_attributes']) && !is_array($event['event_attributes'])) {
    $event_attributes = unserialize($event['event_attributes']);
    $event['event_attributes'] = $event_attributes;
    }

    return $event;
    } // end function pdd_standardize_event

    /**********************************************************************/
    function pdd_insert_google_event($event) {

    // make sure the event is coming in a standard form
    $event = pdd_standardize_event($event);

    // change event to google_event
    $g_event = pdd_map_to_google($event);

    // add event to google and get the event ID back
    $google_saved_event_url = pdd_insertGoogleEvent($g_event);

    // add saved event url to Attributes
    $event_attributes = array();
    if (!empty($event['event_attributes']) && !is_array($event['event_attributes'])) {
    $event_attributes = unserialize($event['event_attributes']);
    }

    $event_attributes['GOOGLE_URL'] = $google_saved_event_url;
    $event['event_attributes'] = serialize($event_attributes);

    $where = array('event_id' => $event['event_id']);
    eme_db_update_event($event,$where);

    } // end function pdd_insert_google_event

    /**********************************************************************/
    function pdd_update_google_event($event) {

    print_r($event);

    // make sure the event is coming in a standard form
    $event = pdd_standardize_event($event);

    // change event to google_event
    $g_event = pdd_map_to_google($event);

    // add event to google and get the event ID back
    $google_saved_event_url = pdd_updateGoogleEvent($g_event);

    } // end function pdd_update_google_event

    /**********************************************************************/
    function pdd_delete_google_event($event) {

    // make sure the event is coming in a standard form
    $event = pdd_standardize_event($event);

    // connect to the calendar
    $gdataCal = createGoogleCalConnection();

    if ($gdataCal) {
    // Retrieve the edit URL for an event. When using this method, this URL
    // should already be available somewhere locally, such as in a database.
    // PDD - saved in attributes
    $google_saved_event_url = '';

    if (!empty($event['event_attributes']['GOOGLE_URL'])) {
    $google_saved_event_url = $event['event_attributes']['GOOGLE_URL'];

    // retrieve event
    // delete event
    try {
    $g_event = $gdataCal->getCalendarEventEntry($google_saved_event_url);
    $g_event->delete();
    } catch (Zend_Gdata_App_Exception $e) {
    return "Error: " . $e->getResponse();
    }
    return 'Event successfully deleted!';

    }
    } else { echo "http client not defined"; }

    } // end function pdd_delete_google_event

    add_action('eme_insert_event_action','pdd_insert_google_event');
    add_action('eme_update_event_action','pdd_update_google_event');
    add_action('eme_delete_event_action','pdd_delete_google_event');

    Hope that helps.

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Bug fixed or feature request implemented’ is closed to new topics and replies.
Scroll to Top