diff options
author | deva <deva> | 2008-11-25 15:52:44 +0000 |
---|---|---|
committer | deva <deva> | 2008-11-25 15:52:44 +0000 |
commit | 21c12bfb323d5b078eb70c20be8ea18be081a936 (patch) | |
tree | 6b10eab35bbef4d67e63de4588e0da76bdb561eb | |
parent | 56b12d452c44374fc3f673578586387bd7840b36 (diff) |
Added post-to-google-calendar through Zend (when installed)
-rw-r--r-- | forum/utils/calendar.php | 6 | ||||
-rw-r--r-- | forum/utils/googlecalendar.php | 60 |
2 files changed, 65 insertions, 1 deletions
diff --git a/forum/utils/calendar.php b/forum/utils/calendar.php index 84ebe18..1cf8d4a 100644 --- a/forum/utils/calendar.php +++ b/forum/utils/calendar.php @@ -1,6 +1,7 @@ <?php include_once($UTIL_DIR . "/events.php"); include_once($UTIL_DIR . "/notify.php"); +if($ZEND_DIR != "") include_once($UTIL_DIR . "/googlecalendar.php"); $events = new Events($DATA_DIR . "/calendar.xml"); @@ -14,7 +15,10 @@ if($action=="addentry") { $eid = time(); $event = new Event($eid, $title, $time, $duration, $description, $current_user->uid); $events->add($event); - $events->write(); + $events->write(); + + if($ZEND_DIR != "") googleCalendarEvent($event); + notify("calendar", "New calendar entry:\n" . $title . "\n" . date("r", $time) . "\n" . $description . "\n" . $FORUM_URL . "/?mode=calendar&date=" . $time); diff --git a/forum/utils/googlecalendar.php b/forum/utils/googlecalendar.php new file mode 100644 index 0000000..e6305f8 --- /dev/null +++ b/forum/utils/googlecalendar.php @@ -0,0 +1,60 @@ +<?php + +include_once($UTIL_DIR . "/events.php"); + +function googleCalendarEvent($event) +{ + global $ZEND_DIR, $GOOGLE_CALENDAR_USER, $GOOGLE_CALENDAR_PASSWD; + + set_include_path(get_include_path() . PATH_SEPARATOR . $ZEND_DIR); + + // load classes + require_once 'Zend/Loader.php'; + Zend_Loader::loadClass('Zend_Gdata'); + Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); + Zend_Loader::loadClass('Zend_Gdata_Calendar'); + Zend_Loader::loadClass('Zend_Http_Client'); + + // connect to service + $gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; + $user = $GOOGLE_CALENDAR_USER; + $pass = $GOOGLE_CALENDAR_PASSWD; + $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal); + $gcal = new Zend_Gdata_Calendar($client); + + /* + // validate input + if (empty($_POST['title'])) { + die('ERROR: Missing title'); + } + + if (!checkdate($_POST['sdate_mm'], $_POST['sdate_dd'], $_POST['sdate_yy'])) { + die('ERROR: Invalid start date/time'); + } + + if (!checkdate($_POST['edate_mm'], $_POST['edate_dd'], $_POST['edate_yy'])) { + die('ERROR: Invalid end date/time'); + } + */ + $title = htmlentities(utf8_decode($event->title . "\n" . $event->description)); + $start = date(DATE_ATOM, $event->starttime); + $end = date(DATE_ATOM, $event->starttime + $event->duration); + + // construct event object + // save to server + + try { + $gevent = $gcal->newEventEntry(); + $gevent->title = $gcal->newTitle($title); + $when = $gcal->newWhen(); + $when->startTime = $start; + $when->endTime = $end; + $gevent->when = array($when); + $gcal->insertEvent($gevent); + } catch (Zend_Gdata_App_Exception $e) { + echo "Error: " . $e->getResponse(); + } + + // echo 'Event successfully added!'; +} +?> |