public function testNormalWebContentShouldHaveNoExtensionElements() { $this->webContent->url = "http://nowhere.invalid/"; $this->webContent->height = "100"; $this->webContent->width = "200"; $this->assertEquals($this->webContent->url, "http://nowhere.invalid/"); $this->assertEquals($this->webContent->height, "100"); $this->assertEquals($this->webContent->width, "200"); $this->assertEquals(count($this->webContent->extensionElements), 0); $newWebContent = new Zend_Gdata_Calendar_Extension_WebContent(); $newWebContent->transferFromXML($this->webContent->saveXML()); $this->assertEquals(count($newWebContent->extensionElements), 0); $newWebContent->extensionElements = array(new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar')); $this->assertEquals(count($newWebContent->extensionElements), 1); $this->assertEquals($newWebContent->url, "http://nowhere.invalid/"); $this->assertEquals($newWebContent->height, "100"); $this->assertEquals($newWebContent->width, "200"); /* try constructing using magic factory */ $cal = new Zend_Gdata_Calendar(); $newWebContent2 = $cal->newWebContent(); $newWebContent2->transferFromXML($newWebContent->saveXML()); $this->assertEquals(count($newWebContent2->extensionElements), 1); $this->assertEquals($newWebContent2->url, "http://nowhere.invalid/"); $this->assertEquals($newWebContent2->height, "100"); $this->assertEquals($newWebContent2->width, "200"); }
function getFeeds($startdate, $enddate) { global $dayinseconds; $feeds = array(); $calendars = array('*****@*****.**', '*****@*****.**', 'communityhigh.net_cqt4f59nci2gvtftuqseal396o%40group.calendar.google.com', 'communityhigh.net_5d3b9b97gj76hqmk9ir4s2usm8%40group.calendar.google.com'); foreach ($calendars as $user) { /* @var $service Zend_Gdata_Calendar */ $service = new Zend_Gdata_Calendar(); /* @var $query Zend_Gdata_Calendar_EventQuery */ $query = $service->newEventQuery(); $query->setUser($user); $query->setOrderby('starttime'); $query->setSortOrder('ascending'); $query->setMaxResults(100000); //get days events: event: name, description $query->setStartMin(date(DATE_RFC3339, $startdate)); $query->setStartMax(date(DATE_RFC3339, $enddate + 6 * $dayinseconds)); try { $feeds[] = $service->getCalendarEventFeed($query); //foreach($eventFeed as $event) // var_dump($event->when); } catch (Zend_Gdata_App_Exception $e) { echo "Error: " . $e->getMessage(); } } return $feeds; }
/** * Outputs an HTML unordered list (ul), with each list item representing a * calendar in the authenticated user's calendar list. * * @param Zend_Http_Client $client The authenticated client object * @return void */ function outputCalendarList($client) { $gdataCal = new Zend_Gdata_Calendar($client); $calFeed = $gdataCal->getCalendarListFeed(); echo "<h1>" . $calFeed->title->text . "</h1>\n"; echo "<ul>\n"; foreach ($calFeed as $calendar) { echo "\t<li>" . $calendar->title->text . "</li>\n"; } echo "</ul>\n"; }
function addEvent($title = 'Новый заказ', $desc = 'Описание заказа', $where = 'интернет-магазин', $startDate, $endDate, $sms_reminder) { try { set_include_path('.' . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . '/modules/gcalendar/' . PATH_SEPARATOR . get_include_path()); include_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_HttpClient'); Zend_Loader::loadClass('Zend_Gdata_Calendar'); $client = Zend_Gdata_ClientLogin::getHttpClient($this->_user, $this->_pass, "cl"); $gdataCal = new Zend_Gdata_Calendar($client); $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; $when->endTime = $endDate; if (intval($sms_reminder)) { $reminder = $gdataCal->newReminder(); $reminder->method = "sms"; $reminder->minutes = "0"; $when->reminders = array($reminder); } $newEvent->when = array($when); $createdEvent = $gdataCal->insertEvent($newEvent); return $createdEvent->id->text; } catch (Exception $ex) { // Report the exception to the user } }
public function setPlanning($startDate, $endDate, $title, $content) { // Parameters for ClientAuth authentication ProjectConfiguration::registerZend(); Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); Zend_Loader::loadClass('Zend_Gdata_Calendar'); $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; $user = sfConfig::get('app_gmail_user'); $pass = sfConfig::get('app_gmail_pwd'); // Create an authenticated HTTP client $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service); // Create an instance of the Calendar service $service = new Zend_Gdata_Calendar($client); // Create a new entry using the calendar service's magic factory method $event = $service->newEventEntry(); // Populate the event with the desired information // Note that each attribute is crated as an instance of a matching class $event->title = $service->newTitle($title); $event->where = array($service->newWhere("Paris, France")); $event->content = $service->newContent($content); // Set the date using RFC 3339 format. $tzOffset = "+02"; $when = $service->newWhen(); //$when->startTime = "{$start_date}.000{$tzOffset}:00"; //$when->endTime = "{$end_date}.000{$tzOffset}:00"; $when->startTime = "{$startDate}:00.000{$tzOffset}:00"; $when->endTime = "{$endDate}:00.000{$tzOffset}:00"; $event->when = array($when); // Upload the event to the calendar server // A copy of the event as it is recorded on the server is returned $newEvent = $service->insertEvent($event); }
public function testNormalQuickAddShouldHaveNoExtensionElements() { $this->quickAdd->value = false; $this->assertEquals($this->quickAdd->value, false); $this->assertEquals(count($this->quickAdd->extensionElements), 0); $newQuickAdd = new Zend_Gdata_Calendar_Extension_QuickAdd(); $newQuickAdd->transferFromXML($this->quickAdd->saveXML()); $this->assertEquals(count($newQuickAdd->extensionElements), 0); $newQuickAdd->extensionElements = array(new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar')); $this->assertEquals(count($newQuickAdd->extensionElements), 1); $this->assertEquals($newQuickAdd->value, false); /* try constructing using magic factory */ $cal = new Zend_Gdata_Calendar(); $newQuickAdd2 = $cal->newQuickAdd(); $newQuickAdd2->transferFromXML($newQuickAdd->saveXML()); $this->assertEquals(count($newQuickAdd2->extensionElements), 1); $this->assertEquals($newQuickAdd2->value, false); }
public function testNormalSendEventNotificationsShouldHaveNoExtensionElements() { $this->sendEventNotifications->value = true; $this->assertEquals($this->sendEventNotifications->value, true); $this->assertEquals(count($this->sendEventNotifications->extensionElements), 0); $newSendEventNotifications = new Zend_Gdata_Calendar_Extension_SendEventNotifications(); $newSendEventNotifications->transferFromXML($this->sendEventNotifications->saveXML()); $this->assertEquals(count($newSendEventNotifications->extensionElements), 0); $newSendEventNotifications->extensionElements = array(new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar')); $this->assertEquals(count($newSendEventNotifications->extensionElements), 1); $this->assertEquals($newSendEventNotifications->value, true); /* try constructing using magic factory */ $cal = new Zend_Gdata_Calendar(); $newSendEventNotifications2 = $cal->newSendEventNotifications(); $newSendEventNotifications2->transferFromXML($newSendEventNotifications->saveXML()); $this->assertEquals(count($newSendEventNotifications2->extensionElements), 1); $this->assertEquals($newSendEventNotifications2->value, true); }
public function testNormalColorShouldHaveNoExtensionElements() { $this->color->value = '#abcdef'; $this->assertEquals($this->color->value, '#abcdef'); $this->assertEquals(count($this->color->extensionElements), 0); $newColor = new Zend_Gdata_Calendar_Extension_Color(); $newColor->transferFromXML($this->color->saveXML()); $this->assertEquals(count($newColor->extensionElements), 0); $newColor->extensionElements = array(new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar')); $this->assertEquals(count($newColor->extensionElements), 1); $this->assertEquals($newColor->value, '#abcdef'); /* try constructing using magic factory */ $cal = new Zend_Gdata_Calendar(); $newColor2 = $cal->newColor(); $newColor2->transferFromXML($newColor->saveXML()); $this->assertEquals(count($newColor2->extensionElements), 1); $this->assertEquals($newColor2->value, '#abcdef'); }
public function testNormalTimezoneShouldHaveNoExtensionElements() { $this->timezone->value = "America/Chicago"; $this->assertEquals($this->timezone->value, "America/Chicago"); $this->assertEquals(count($this->timezone->extensionElements), 0); $newTimezone = new Zend_Gdata_Calendar_Extension_Timezone(); $newTimezone->transferFromXML($this->timezone->saveXML()); $this->assertEquals(count($newTimezone->extensionElements), 0); $newTimezone->extensionElements = array(new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar')); $this->assertEquals(count($newTimezone->extensionElements), 1); $this->assertEquals($newTimezone->value, "America/Chicago"); /* try constructing using magic factory */ $cal = new Zend_Gdata_Calendar(); $newTimezone2 = $cal->newTimezone(); $newTimezone2->transferFromXML($newTimezone->saveXML()); $this->assertEquals(count($newTimezone2->extensionElements), 1); $this->assertEquals($newTimezone2->value, "America/Chicago"); }
public function testNormalAccessLevelShouldHaveNoExtensionElements() { $this->accessLevel->value = 'freebusy'; $this->assertEquals($this->accessLevel->value, 'freebusy'); $this->assertEquals(count($this->accessLevel->extensionElements), 0); $newAccessLevel = new Zend_Gdata_Calendar_Extension_AccessLevel(); $newAccessLevel->transferFromXML($this->accessLevel->saveXML()); $this->assertEquals(count($newAccessLevel->extensionElements), 0); $newAccessLevel->extensionElements = array(new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar')); $this->assertEquals(count($newAccessLevel->extensionElements), 1); $this->assertEquals($newAccessLevel->value, 'freebusy'); /* try constructing using magic factory */ $cal = new Zend_Gdata_Calendar(); $newAccessLevel2 = $cal->newAccessLevel(); $newAccessLevel2->transferFromXML($newAccessLevel->saveXML()); $this->assertEquals(count($newAccessLevel2->extensionElements), 1); $this->assertEquals($newAccessLevel2->value, 'freebusy'); }
public function testNormalLinkShouldHaveNoExtensionElements() { $this->link->rel = "http://nowhere.invalid/"; $this->link->title = "Somewhere"; $this->link->href = "http://somewhere.invalid/"; $this->link->type = "text/plain"; $this->link->webContent = new Zend_Gdata_Calendar_Extension_WebContent("a", "1", "2"); $this->assertEquals($this->link->rel, "http://nowhere.invalid/"); $this->assertEquals($this->link->title, "Somewhere"); $this->assertEquals($this->link->href, "http://somewhere.invalid/"); $this->assertEquals($this->link->type, "text/plain"); $this->assertEquals($this->link->webcontent->url, "a"); $this->assertEquals($this->link->webcontent->height, "1"); $this->assertEquals($this->link->webcontent->width, "2"); $this->assertEquals(count($this->link->extensionElements), 0); $newLink = new Zend_Gdata_Calendar_Extension_Link(); $newLink->transferFromXML($this->link->saveXML()); $this->assertEquals(count($newLink->extensionElements), 0); $newLink->extensionElements = array(new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar')); $this->assertEquals(count($newLink->extensionElements), 1); $this->assertEquals($this->link->rel, "http://nowhere.invalid/"); $this->assertEquals($this->link->title, "Somewhere"); $this->assertEquals($this->link->href, "http://somewhere.invalid/"); $this->assertEquals($this->link->type, "text/plain"); $this->assertEquals($this->link->webcontent->url, "a"); $this->assertEquals($this->link->webcontent->height, "1"); $this->assertEquals($this->link->webcontent->width, "2"); /* try constructing using magic factory */ $cal = new Zend_Gdata_Calendar(); $newLink2 = $cal->newLink(); $newLink2->transferFromXML($newLink->saveXML()); $this->assertEquals(count($newLink2->extensionElements), 1); $this->assertEquals($this->link->rel, "http://nowhere.invalid/"); $this->assertEquals($this->link->title, "Somewhere"); $this->assertEquals($this->link->href, "http://somewhere.invalid/"); $this->assertEquals($this->link->type, "text/plain"); $this->assertEquals($this->link->webcontent->url, "a"); $this->assertEquals($this->link->webcontent->height, "1"); $this->assertEquals($this->link->webcontent->width, "2"); }
/** * Creates an event on the authenticated user's default calendar with the * specified event details. * * @param Zend_Http_Client $client The authenticated client object * @param string $title The event title * @param string $desc The detailed description of the event * @param string $where * @param string $startDate The start date of the event in YYYY-MM-DD format * @param string $startTime The start time of the event in HH:MM 24hr format * @param string $endDate The end date of the event in YYYY-MM-DD format * @param string $endTime The end time of the event in HH:MM 24hr format * @param string $tzOffset The offset from GMT/UTC in [+-]DD format (eg -08) * @return string The ID URL for the event. */ function createEvent($client, $title = 'Tennis with Beth', $desc = 'Meet for a quick lesson', $where = 'On the courts', $startDate = '2008-01-20', $startTime = '10:00', $endDate = '2008-01-20', $endTime = '11:00', $tzOffset = '-08') { $gc = new Zend_Gdata_Calendar($client); $newEntry = $gc->newEventEntry(); $newEntry->title = $gc->newTitle(trim($title)); $newEntry->where = array($gc->newWhere($where)); $newEntry->content = $gc->newContent($desc); $newEntry->content->type = 'text'; $when = $gc->newWhen(); $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00"; $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00"; $newEntry->when = array($when); $createdEntry = $gc->insertEvent($newEntry); return $createdEntry->id->text; }
function createEvent($client, $title = 'Tennis with Beth', $desc = 'Meet for a quick lesson', $startDate = '2012-01-20', $endDate = '2012-01-20') { $gdataCal = new Zend_Gdata_Calendar($client); $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}"; $when->endTime = "{$endDate}"; $newEvent->when = array($when); // 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; }
function updateEvent($recordid, $eventOld, $Data, $tzOffset = '+00:00') { set_include_path($this->root_directory . "modules/Calendar4You/"); $startDate = $Data["date_start"]; $endDate = $Data["due_date"]; $startTime = $Data["time_start"]; $endTime = $Data["time_end"]; $GCalClass = new Zend_Gdata_Calendar($this->gClient); $eventOld->title = $GCalClass->newTitle(trim($Data["subject"])); $eventOld->where = array($GCalClass->newWhere(trim($Data["location"]))); $eventOld->content = $GCalClass->newContent($Data["description"]); $when = $GCalClass->newWhen(); $when->startTime = $startDate . 'T' . $this->removeLastColon($startTime) . ':00.000' . $tzOffset; $when->endTime = $endDate . 'T' . $this->removeLastColon($endTime) . ':00.000' . $tzOffset; $eventOld->when = array($when); $whos = $this->getInvitedUsersEmails($GCalClass, $recordid); if (count($whos) > 0) { $eventOld->setWho($whos); } try { $eventOld->save(); $status = true; } catch (Zend_Gdata_App_Exception $e) { $status = null; } set_include_path($this->root_directory); return $status; }
// various copy includes require_once "../../config.gen.inc.php"; require_once "data/data.inc.php"; // records stats require_once "../page_builder/page_header.php"; // sets up google calendar classes require_once "lib/google_calendar.init.php"; // libs require_once "lib/calendar.lib.php"; require_once "lib/textformat.lib.php"; $search_terms = $_REQUEST['filter']; $search_options = SearchOptions::get_options(); $timeframe = isset($_REQUEST['timeframe']) ? $_REQUEST['timeframe'] : 0; $dates = SearchOptions::search_dates($timeframe); $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar $client = Zend_Gdata_ClientLogin::getHttpClient($username . '@gmail.com', $password, $service); $gdataCal = new Zend_Gdata_Calendar($client); $query = $gdataCal->newEventQuery(); $query->setUser($calendars['all']['user']); $query->setVisibility('private'); $query->setProjection('full'); $query->setOrderby('starttime'); $query->setSortorder('a'); $query->setStartMin($dates['start']); $query->setStartMax($dates['end']); $query->setmaxresults('50'); $query->setQuery($search_terms); $eventFeed = $gdataCal->getCalendarEventFeed($query); require "templates/{$prefix}/search.html"; $page->output();
/* */ /* Author: Anurup Raveendran, Herat Gandhi */ /* This program is free software. You can redistribute it and/or*/ /* modify it under the terms of the GNU General Public License */ /* as published by the Free Software Foundation. */ /****************************************************************/ /** * This file is used to reflect changes from ATutor to Google Calendar. */ $_user_location = 'public'; require_once 'includes/classes/googlecalendar.class.php'; define('AT_INCLUDE_PATH', '../../../include/'); require AT_INCLUDE_PATH . 'vitals.inc.php'; $gcalobj = new GoogleCalendar(); $client = $gcalobj->getAuthSubHttpClient(); $gdata_cal = new Zend_Gdata_Calendar($client); $event_url = $_GET['id']; $command = $_GET['cmd']; try { //Get the event object from its id. $event = $gdata_cal->getCalendarEventEntry($event_url); if (strcmp($command, 'delete') == 0) { //If event is deleted then call delete method. $event->delete(); } else { if (strcmp($command, 'update') == 0) { //Update event attributes and then save it in Google Calendar. $event->title = $gdata_cal->newTitle($_GET['title']); $when = $gdata_cal->newWhen(); $when->startTime = $_GET['start']; $when->endTime = $_GET['end'];
/** * Creates an event on the authenticated users default calendar with the * specified event details. * * @return string The id URL for the event. */ public function createEvent(TA_Model_Resource_Db_Table_Row_Abstract $values) { $values = $this->_modifyValues($values); $gc = new Zend_Gdata_Calendar($this->_client); $newEntry = $gc->newEventEntry(); // set event properties $newEntry->title = $gc->newTitle(trim($values['title'])); $newEntry->where = array($gc->newWhere($values['location'])); $newEntry->content = $gc->newContent($values['description']); $newEntry->content->type = 'text'; $when = $gc->newWhen(); $start = date_create($values['start']); $end = date_create($values['end']); $when->startTime = date_format($start, 'Y-m-d\\TH:i:s.000P'); $when->endTime = date_format($end, 'Y-m-d\\TH:i:s.000P'); $newEntry->when = array($when); $createdEntry = $gc->insertEvent($newEntry); return $createdEntry->id->text; }
/** * Get the user notes from Google calendar (Gdata Zend functions are necessary) */ public function gCalendar() { // Security check $this->throwForbiddenUnless(SecurityUtil::checkPermission('IWagendas::', '::', ACCESS_READ)); // get user uid $user = (UserUtil::getVar('uid') == '') ? '-1' : UserUtil::getVar('uid'); $usability = ModUtil::func('IWagendas', 'user', 'getGdataFunctionsUsability'); if ($usability !== true) { throw new Zikula_Exception_Forbidden(); } //Load required classes 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_HttpClient'); Zend_Loader::loadClass('Zend_Gdata_Calendar'); //@var string Location of AuthSub key file. include_path is used to find this $_authSubKeyFile = null; // Example value for secure use: 'mykey.pem' //@var string Passphrase for AuthSub key file. $_authSubKeyFilePassphrase = null; $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; $userSettings = ModUtil::func('IWagendas', 'user', 'getUserGCalendarSettings'); if (!isset($_SESSION['sessionToken']) && !isset($_GET['token'])) { try { $client = Zend_Gdata_ClientLogin::getHttpClient($userSettings['gUserName'], base64_decode($userSettings['gUserPass']), $service); } catch (exception $e) { $authSubUrl = ModUtil::func('IWagendas', 'user', 'getAuthSubUrl'); return System::redirect(ModUtil::url('IWwebbox', 'user', 'main', array('url' => str_replace('&', '*', str_replace('?', '**', $authSubUrl))))); } } else $client = ModUtil::func('IWagendas', 'user', 'getAuthSubHttpClient'); try { $gdataCal = new Zend_Gdata_Calendar($client); } catch (exception $e) { LogUtil::registerError($this->__('Connection with Google failed. Imposible to synchronize the agenda')); return false; } //get user calendars try { $calFeed = $gdataCal->getCalendarListFeed(); } catch (exception $e) { LogUtil::registerError($this->__('Connection with Google failed. Imposible to synchronize the agenda')); return false; } $gCalendarsIdsArray = array(); foreach ($calFeed as $calendar) { $gCalendarsIdsArray[] = $calendar->id; } // Get all existing google calendars stored in database. We need them to know if the received google calendars exists or not $gAgendas = ModUtil::apiFunc('IWagendas', 'user', 'getAllAgendas', array('gAgendas' => 1, 'gCalendarsIdsArray' => $gCalendarsIdsArray)); $gCalendarsIdsArray = array(); foreach ($gAgendas as $g) { $gIds[$g['gCalendarId']] = $g; } $existingCalendar = array(); // Create or edit the calendars if it were necessary foreach ($calFeed as $calendar) { //sincronize calendars $id = $calendar->id; $resp = '$' . $user . '$'; $accessLevel = '$' . substr($calendar->accessLevel->value, 0, 4) . '|' . $user . '$'; $color = '$' . $calendar->color->value . '|' . $user . '$'; // Create a calendar array based on the calendar id $existingCalendar["$id"] = 1; if (!array_key_exists("$id", $gIds)) { $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue'); $agenda = ModUtil::apiFunc('IWagendas', 'admin', 'create', array('nom_agenda' => $calendar->title, 'descriu' => $calendar->summary->text, 'c1' => $this->__('What'), 'c2' => $this->__('End'), 'c3' => $this->__('Where'), 'c4' => $this->__('Content'), 'c5' => $this->__('Author'), 'tc1' => 1, 'tc2' => 1, 'tc3' => 1, 'tc4' => 2, 'tc5' => 1, 'activa' => 1, 'adjunts' => 0, 'protegida' => 1, 'gColor' => '$' . $color, 'color' => '', 'gCalendarId' => $id, 'gAccessLevel' => '$' . $accessLevel, 'resp' => '$' . $resp, 'sv' => $sv)); // add new agenda into the array in case the agenda is created recently $gIds["$id"] = $agenda; } else { if ($gIds["$id"]['nom_agenda'] != $calendar->title || $gIds["$id"]['descriu'] != $calendar->summary->text || strpos($gIds["$id"]['gColor'], $color) === false || strpos($gIds["$id"]['resp'], $resp) === false || strpos($gIds["$id"]['gAccessLevel'], $accessLevel) === false) { if (strpos($gIds["$id"]['gAccessLeve l'], $accessLevel) === false) { // Change the gCalendar access level $pos = strpos($gIds["$id"]['gAccessLevel'], '|' . $user . '$'); $userAccessLevel = ($pos > 0) ? substr($gIds["$id"]['gAccessLevel'], $pos - 5, (int) strlen($user) + 7) : ''; $newAccessLevelString = ($pos > 0) ? str_replace($userAccessLevel, $accessLevel, $gIds["$id"]['gAccessLevel']) : $gIds["$id"]['gAccessLevel'] . $accessLevel; } if (strpos($gIds["$id"]['gColor'], $color) === false) { // Change the gCalendar access level $pos = strpos($gIds["$id"]['gColor'], '|' . $user . '$'); $userColor = ($pos > 0) ? substr($gIds["$id"]['gColor'], $pos - 8, (int) strlen($user) + 10) : ''; $newColorString = ($pos > 0) ? str_replace($userColor, $color, $gIds["$id"]['gColor']) : $gIds["$id"]['gColor'] . $color; } $resp = (strpos($gIds["$id"]['resp'], $resp) === false) ? $resp : ''; $items = array('nom_agenda' => $calendar->title, 'descriu' => $calendar->summary->text, 'gColor' => $newColorString, 'resp' => $gIds["$id"]['resp'] . $resp, 'gAccessLevel' => $newAccessLevelString); $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue'); ModUtil::apiFunc('IWagendas', 'admin', 'editAgenda', array('daid' => $gIds["$id"]['daid'], 'items' => $items, 'sv' => $sv)); } } } // Get data from google for 2 months ago and 4 future months more or less $time = time(); $beginDate = $time - 2 * 30 * 24 * 60 * 60; $endDate = $time + 4 * 30 * 24 * 60 * 60; $beginOndate = date('Y-m-d', $beginDate); $endOnDate = date('Y-m-d', $endDate); //get all the google notes $gCalendarNotes = ModUtil::apiFunc('IWagendas', 'user', 'getAllGCalendarNotes', array('beginDate' => $beginDate, 'endDate' => $endDate, 'gIds' => $gIds)); foreach ($calFeed as $calendar) { $id = $calendar->id; $query = $gdataCal->newEventQuery(); $calFeed = $gdataCal->getCalendarListFeed(); $gUser = str_replace(Zend_Gdata_Calendar::CALENDAR_FEED_URI . '/default/', "", $id); // kind of dirty way to get the info, nut it lokks working :) $query->setUser($gUser); $query->setVisibility('private'); $query->setProjection('full'); $query->setOrderby('starttime'); $query->setStartMin($beginOndate); $query->setStartMax($endOnDate); $eventFeed = array(); if ($calendar->accessLevel->value == 'owner' || $calendar->accessLevel->value == 'editor' || $calendar->accessLevel->value == 'read') { $eventFeed = $gdataCal->getCalendarEventFeed($query); } foreach ($eventFeed as $event) { foreach ($event->when as $when) { $startTime = $when->startTime; $day = substr($startTime, 8, 2); $month = substr($startTime, 5, 2); $year = substr($startTime, 0, 4); $hour = substr($startTime, 11, 2); $minute = substr($startTime, 14, 2); $startTime = gmmktime($hour, $minute, 0, $month, $day, $year); $day = date('d', $startTime); $month = date('m', $startTime); $year = date('Y', $startTime); $hour = date('H', $startTime); $minute = date('i', $startTime); $endTime = $when->endTime; $dayEnd = substr($endTime, 8, 2); $monthEnd = substr($endTime, 5, 2); $yearEnd = substr($endTime, 0, 4); $hourEnd = substr($endTime, 11, 2); $minuteEnd = substr($endTime, 14, 2); $endTime = gmmktime($hourEnd, $minuteEnd, 0, $monthEnd, $dayEnd, $yearEnd); $dayEnd = date('d', $endTime); $monthEnd = date('m', $endTime); $yearEnd = date('Y', $endTime); $hourEnd = date('H', $endTime); $minuteEnd = date('i', $endTime); $allDay = (($minute == '' || $minute == '00') && ($hour == '' || $hour == '23') && ($minuteEnd == '' || $minuteEnd == '00') && ($hourEnd == '' || $hourEnd == '00')) ? 1 : 0; $end = ($allDay == 0) ? $this->__('Foreseen time to finish') . ': ' . $hourEnd . ':' . $minuteEnd : $this->__('All day'); if (!array_key_exists("$event->id", $gCalendarNotes)) { //create item $lid = ModUtil::apiFunc('IWagendas', 'user', 'crear', array('dia' => $day, 'mes' => $month, 'any' => $year, 'c1' => $event->title, 'c2' => $end, 'c3' => $event->where[0]->valueString, 'c4' => $event->content, 'c5' => $event->author[0]->email->text, 'c6' => '', 'minut' => $minute, 'hora' => $hour, 'totdia' => $allDay, 'tasca' => 0, 'nivell' => 0, 'rid' => '-1', 'daid' => $gIds["$id"]['daid'], 'nova' => '$$' . $user . '$', 'oculta' => 0, 'fitxer' => '', 'origen' => '', 'gCalendarEventId' => $event->id, 'protegida' => 0)); } else { $existing["$event->id"] = 1; $item = $gCalendarNotes["$event->id"]; if ($allDay) { $hour = 23; $minute = 59; } $data = mktime($hour, $minute, 0, $month, $day, $year); //check if item has changed. If it has changed it is updated if ($item['c1'] != $event->title || $item['data'] != $data || $item['c2'] != $end || $item['c3'] != $event->where[0]->valueString || $item['c4'] != $event->content) { $items = array('c1' => $event->title, 'c2' => $end, 'c3' => $event->where[0]->valueString, 'c4' => $event->content, 'data' => $data, 'totdia' => $allDay, 'origen' => $calendar->title, 'totdia' => $allDay); //modify of a simple entry $lid = ModUtil::apiFunc('IWagendas', 'user', 'editNote', array('aid' => $item['aid'], 'items' => $items, 'daid' => $item['daid'])); } //delete event from gCalendar if it were necessary if ($item['deleted'] == 1) { //delete of a simple entry try { $event->delete(); } catch (Zend_Gdata_App_Exception $e) { return $this->__('You are not allowed to administrate the agendas'); } } } } } } // Delete the calendars where user can't access any more $diff = array_diff_key($gIds, $existingCalendar); foreach ($diff as $d) { if ($resp == '$') { // Nobody else needs the calendar and it is deleted $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue'); ModUtil::apiFunc('IWagendas', 'admin', 'delete', array('daid' => $d['daid'], 'sv' => $sv)); } else { // The user access to the calendar is deleted $items = array('gColor' => $newColorString, 'resp' => $resp, 'gAccessLevel' => $newAccessLevelString); $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue'); ModUtil::apiFunc('IWagendas', 'admin', 'editAgenda', array('daid' => $d['daid'], 'items' => $items, 'sv' => $sv)); } } // set as deleted the not existing gCalendar notes $diff = array_diff_key($gCalendarNotes, $existing); foreach ($diff as $d) { if (strpos($gAgendas[$d['daid']]['gAccessLevel'], '$free|' . $user . '$') === false) { $items = array('deleted' => 1, 'protegida' => 0); $lid = ModUtil::apiFunc('IWagendas', 'user', 'editNote', array('aid' => $d['aid'], 'daid' => $d['daid'], 'items' => $items)); } } //save that the sincronization has been made $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue'); ModUtil::func('IWmain', 'user', 'userSetVar', array('uid' => $user, 'name' => 'sincroGCalendar', 'module' => 'IWagendas', 'sv' => $sv, 'value' => '1', 'lifetime' => $userSettings['gRefreshTime'] * 60)); //get all notes from gCalendar that has been created without connexion and create them $notesNotInGCalendar = ModUtil::apiFunc('IWagendas', 'user', 'getAllGCalendarNotes', array('beginDate' => $beginDate, 'endDate' => $endDate, 'gIds' => $gIds, 'notInGCalendar' => 1)); foreach ($notesNotInGCalendar as $note) { $data = $note['data']; $data1 = $note['data1']; //Protect correct format for dateStart and dataEnd if ($data1 < $data) $data1 = $data; // Create a new entry using the calendar service's magic factory method $event = $gdataCal->newEventEntry(); // Populate the event with the desired information // Note that each attribute is crated as an instance of a matching class $event->title = $gdataCal->newTitle($note['c1']); $event->where = array($gdataCal->newWhere($note['c3'])); $event->content = $gdataCal->newContent($note['c4']); // Set the date using RFC 3339 format. $startDate = date('Y-m-d', $data); $endDate = date('Y-m-d', $data1); $when = $gdataCal->newWhen(); if ($note['totdia'] == 0) { $tzOffset = ($userSettings['tzOffset'] == '') ? '+02' : $userSettings['tzOffset']; //protect correct time format $startTime = date('H:i', $data); $endTime = date('H:i', $data1); $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00"; $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00"; } else { $when->startTime = "$startDate"; $when->endTime = "$endDate"; } $event->when = array($when); $calendarURL = str_replace(Zend_Gdata_Calendar::CALENDAR_FEED_URI . '/default/', "", $gAgendas[$note['daid']]['gCalendarId']); $calendarURL = 'http://www.google.com/calendar/feeds/' . $calendarURL . '/private/full'; // Upload the event to the calendar server // A copy of the event as it is recorded on the server is returned try { $newEvent = $gdataCal->insertEvent($event, $calendarURL); } catch (Zend_Gdata_App_Exception $e) { return $this->__('Error produced during gCalendar\'s event creation'); } $gCalendarEventId = $newEvent->id; // Edit note gCalendarEventId $items = array('gCalendarEventId' => $gCalendarEventId); //modify of a simple entry $lid = ModUtil::apiFunc('IWagendas', 'user', 'editNote', array('aid' => $note['aid'], 'items' => $items, 'daid' => $note['daid'])); } return true; }
/** * Deletes the event specified by calling the Zend_Gdata::delete() * method. The URL is typically in the format of: * http://www.google.com/calendar/feeds/default/private/full/<eventId> * * @param Zend_Http_Client $client The authenticated client object * @param string $url The url for the event to be deleted * @return void */ function deleteEventByUrl(Zend_Http_Client $client, $url) { $gdataCal = new Zend_Gdata_Calendar($client); $gdataCal->delete($url); }
/** * Display list of calendars in the sidemenu with * checkbox ahead of each calendar's title. * * @param Zend client object * * @return void */ public function outputCalendarList($client) { $gdataCal = new Zend_Gdata_Calendar($client); $calFeed = $gdataCal->getCalendarListFeed(); //Get calendar list from database $query = "SELECT * FROM %scalendar_google_sync WHERE userid=%d"; $rowval = queryDB($query, array(TABLE_PREFIX, $_SESSION['member_id']), TRUE); $prevval = $rowval['calids']; $selectd = ''; $i = 1; //Iterate through each calendar id foreach ($calFeed as $calendar) { //set state according to database and if changed then update database if (strpos($prevval, $calendar->id->text . ',') === false) { $selectd = ''; } else { $selectd = "checked='checked'"; } echo "\t <div class='fc-square fc-inline-block'\n style='background-color:" . $calendar->color->value . "' ></div>\n <input id='gcal" . $i . "' type='checkbox' name ='calid' value='" . $calendar->id->text . "' " . $selectd . " onclick='if(this.checked) \$.get(\"mods/_standard/calendar/google_calendar_db_sync.php\",\n { calid: this.value, mode: \"add\" },function (data){ refreshevents(); } );\n else \$.get(\"mods/_standard/calendar/google_calendar_db_sync.php\",\n { calid: this.value, mode: \"remove\" },function (data){ refreshevents(); } );'\n />\n <label for='gcal" . $i . "'>" . $calendar->title->text . "</label><br/>"; $i++; } }
function GoogleCalendarSync() { require_once 'modules/GoogleSync/GoogleSync.php'; global $timedate; GoogleSync::init(); $usr = new User(); $users = $usr->get_full_list(); foreach ($users as $user) { $client = GoogleSync::getClient($user); if ($client != false) { $service = new Zend_Gdata_Calendar($client); try { $listFeed = $service->getCalendarEventFeed(); foreach ($listFeed as $calendar) { $id = $calendar->id; $googleSync = new GoogleSync(); $list = $googleSync->get_list('', "{$googleSync->table_name}.google_id='{$id}'"); if ($list['row_count'] > 0) { $event = BeanFactory::getBean($list['list'][0]->parent_name); $event->retrieve($list['list'][0]->parent_id); $event->name = $calendar->title->text; if (!preg_match('/event.private$/', $calendar->visibility->value)) { $event->description = $calendar->content->text; } GoogleSync::setDates($event, $calendar->when[0]->startTime, 0); switch ($event->module_dir) { case 'Calls': $event->name = preg_replace('/^Звонок: /ui', '', $calendar->title->text); GoogleSync::setReminder($event, $calendar->when[0]->reminders[0]); GoogleSync::setDuration(&$event, $calendar->when[0]->startTime, $calendar->when[0]->endTime); break; case 'Meetings': $event->name = preg_replace('/^Звонок: /ui', '', $calendar->title->text); GoogleSync::setReminder($event, $calendar->when[0]->reminders[0]); GoogleSync::setDuration(&$event, $calendar->when[0]->startTime, $calendar->when[0]->endTime); $event->location = $calendar->where[0]->valueString; break; case 'Tasks': $event->name = preg_replace('/^Задача: /ui', '', $calendar->title->text); GoogleSync::setDates($event, $calendar->when[0]->endTime, 1); break; } $event->from_where = 'GOOGLE'; $event->save(); } else { if (preg_match('/^Звонок/ui', $calendar->title->text)) { $event = new Call(); $event->name = preg_replace('/^Звонок: /ui', '', $calendar->title->text); GoogleSync::setReminder($event, $calendar->when[0]->reminders[0]); GoogleSync::setDuration(&$event, $calendar->when[0]->startTime, $calendar->when[0]->endTime); } elseif (preg_match('/^Встреча/ui', $calendar->title->text)) { $event = new Meeting(); $event->name = preg_replace('/^Встреча: /ui', '', $calendar->title->text); GoogleSync::setReminder($event, $calendar->when[0]->reminders[0]); GoogleSync::setDuration(&$event, $calendar->when[0]->startTime, $calendar->when[0]->endTime); $event->location = $calendar->where[0]->valueString; } elseif (preg_match('/^Задача/ui', $calendar->title->text)) { $event = new Task(); $event->name = preg_replace('/^Задача: /ui', '', $calendar->title->text); GoogleSync::setDates($event, $calendar->when[0]->endTime, 1); } if (isset($event)) { if (!preg_match('/event.private$/', $calendar->visibility->value)) { $event->description = $calendar->content->text; } GoogleSync::setDates($event, $calendar->when[0]->startTime, 0); $event->from_where = 'GOOGLE'; $event->assigned_user_id = $user->id; $event_id = $event->save(); $googleSync->parent_name = $event->module_dir; $googleSync->parent_id = $event_id; $googleSync->google_id = $id; $googleSync->user_id = $user->id; $googleSync->save(); } } } } catch (Zend_Gdata_App_Exception $e) { } } } return true; }
/** * Method to get a calendar * @return object with data */ function getOnlineData() { $this->loadZendClasses(); $client = $this->getAuthSubHttpClient(); if (!$client) { $this->_data = array(); } else { $gdataCal = new Zend_Gdata_Calendar($client); $calFeed = $gdataCal->getCalendarListFeed(); $tmp = array(); JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_gcalendar' . DS . 'tables'); foreach ($calFeed as $calendar) { $table_instance =& $this->getTable('import'); $table_instance->id = 0; $cal_id = substr($calendar->id->text, strripos($calendar->id->text, '/') + 1); $table_instance->calendar_id = $cal_id; $table_instance->name = $calendar->title->text; if (strpos($calendar->color->value, '#') === 0) { $color = str_replace("#", "", $calendar->color->value); } $table_instance->color = $color; $tmp[] = $table_instance; } $this->_data = $tmp; } return $this->_data; }
/** * Deletes the event specified by calling the Zend_Gdata::delete() * method. The URL is typically in the format of: * http://www.google.com/calendar/feeds/default/private/full/<eventId> * * @param Zend_Http_Client $client The authenticated client object * @param string $url The url for the event to be deleted * @return void */ function deleteAtomEntryByUrl($client, $url) { $gdataCal = new Zend_Gdata_Calendar($client); $gdataCal->delete($url); }
?> "> <input type="submit" value="Copy"> </form> </p> <?php } ?> </td> <td valign="top"> <?php /** * Get my private calendar feed. */ $gdataCal = new Zend_Gdata_Calendar($client); $gdataCal->setVisibility(Zend_Gdata_Data::VIS_PRIVATE); $feed = $gdataCal->getCalendarFeed(); ?> <h3><?php echo $feed->title(); ?> </h3> <?php foreach ($feed as $item) { $href = $php_self; $deleteUri = urlencode($item->id()); ?> <p><?php echo $item->title(); ?>
* */ // various copy includes require_once "../../config.gen.inc.php"; require_once "data/data.inc.php"; // records stats require_once "../page_builder/page_header.php"; // libs require_once "lib/google_calendar.init.php"; require_once "lib/calendar.lib.php"; require_once "lib/textformat.lib.php"; $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar // the method of building a query based on newEventQuery() just didn't seem to want to work. this did though. $client = Zend_Gdata_ClientLogin::getHttpClient($username . '@gmail.com', $password, $service); $gdataCal = new Zend_Gdata_Calendar($client); $error = false; try { $url = 'http://www.google.com/calendar/feeds/' . $calendars[$_REQUEST['cal']]['user'] . '/private/full/_' . $_REQUEST['id']; $event = $gdataCal->getCalendarEventEntry($url); } catch (Exception $e) { $error = true; } if ($error == true) { // need to create an error handler class echo "<div class='error'>Error for details" . $url . "</div>" . $e; exit; } else { $when = $event->getWhen(); $startTime = $when[0]->startTime; $endTime = $when[0]->endTime;
/** * Create a quick event from string input. * * Should include time (am/pm), day of the week. * * Day of the week can be specified as "tomorrow" * * Can specify week as well with "next tuesday" * * A day without a modifier will default to that current week, * even if the day has already past * * @param String $client - Access token * @param String $quickAddText - Event description */ function createQuickEvent($client, $quickAddText) { $gdataCal = new Zend_Gdata_Calendar($client); $event = $gdataCal->newEventEntry(); $event->content = $gdataCal->newContent($quickAddText); $event->quickAdd = $gdataCal->newQuickAdd('true'); $newEvent = $gdataCal->insertEvent($event); }
/** * Do the plugin action * * @param array &$data selected data * @param object &$listModel list model * * @return number of records updated */ public function process(&$data, &$listModel) { $params = $this->getParams(); $gcal_url = $params->get('gcal_sync_gcal_url'); $matches = array(); /* This matches a standard GCal URL, found under the Google "Calender Details" tab, using the XML button. * It should match any form, for public or private ... * http://www.google.com/calendar/feeds/hugh.messenger%40gmail.com/public/basic * http://www.google.com/calendar/feeds/hugh.messenger%40gmail.com/private-3081eca2b0asdfasdf8f106ea6f63343056/basic */ if (preg_match('#feeds/(.*?)/(\\w+-\\w+|\\w+)/(\\w+)#', $gcal_url, $matches)) { // Grab the bits of the URL we need for the Zend framework call $gcal_user = $matches[1]; $gcal_visibility = $matches[2]; $gcal_projection = $matches[3]; $gcal_email = urldecode($gcal_user); // Grab the table model and find table name and PK $table = $listModel->getTable(); $table_name = $table->db_table_name; /* For now, we have to read the table ourselves. We can't rely on the $data passed to us * because it can be filtered, and we need to see all records to know if the GCal events * already exist in the table */ $mydata = array(); $db = FabrikWorker::getDbo(); $query = $db->getQuery(true); $query->select('*')->from($table_name); $db->setQuery($query); $mydata[0] = $db->loadObjectList(); // Grab all the field names to use $gcal_label_element_long = $params->get('gcal_sync_label_element'); $gcal_label_element = FabrikString::shortColName($gcal_label_element_long); $gcal_desc_element_long = $params->get('gcal_sync_desc_element'); $gcal_desc_element = FabrikString::shortColName($gcal_desc_element_long); $gcal_start_date_element_long = $params->get('gcal_sync_startdate_element'); $gcal_start_date_element = FabrikString::shortColName($gcal_start_date_element_long); $gcal_end_date_element_long = $params->get('gcal_sync_enddate_element'); $gcal_end_date_element = FabrikString::shortColName($gcal_end_date_element_long); $gcal_id_element_long = $params->get('gcal_sync_id_element'); $gcal_id_element = FabrikString::shortColName($gcal_id_element_long); $gcal_userid_element_long = $params->get('gcal_sync_userid_element'); $gcal_userid_element = FabrikString::shortColName($gcal_userid_element_long); // Sanity check, make sure required elements have been specified if (empty($gcal_label_element_long) || empty($gcal_start_date_element_long) || empty($gcal_end_date_element_long) || empty($gcal_id_element_long)) { return; } // If they selected a User ID element to use, see if we can find a J! user with matching email to this feed's owner $our_userid = 0; if ($gcal_userid_element_long) { $query = $db->getQuery(true); $query->select('id')->from('#__users')->whre('email = ' . $db->quote('$gcal_email')); $db->setQuery($query); $our_userid = $db->loadResult(); // Better make sure it's not NULL, in case underlying column is NOT NULL if (empty($our_userid)) { $our_userid = 0; } } // Include the Zend stuff $path = JPATH_SITE . '/libraries'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); $path = get_include_path(); require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata'); /* Won't need these loaded until we add sync'ing events back to Google * Zend_Loader::loadClass('Zend_Gdata_AuthSub'); * Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); */ Zend_Loader::loadClass('Zend_Gdata_Calendar'); // See if they want to sync to gcal, and provided a login $gcal_sync_upload = $params->get('gcal_sync_upload_events', 'from'); if ($gcal_sync_upload == 'both' || $gcal_sync_upload == 'to') { Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); $email = $params->get('gcal_sync_login', ''); $passwd = $params->get('gcal_sync_passwd', ''); try { $client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, 'cl'); } catch (Zend_Gdata_App_CaptchaRequiredException $cre) { echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n"; echo 'Token ID: ' . $cre->getCaptchaToken() . "\n"; return; } catch (Zend_Gdata_App_AuthException $ae) { echo 'Problem authenticating: ' . $ae->exception() . "\n"; return; } $gdataCal = new Zend_Gdata_Calendar($client); } else { $gdataCal = new Zend_Gdata_Calendar(); } // Set up and execute the call to grab the feed from google $query = $gdataCal->newEventQuery(); $query->setUser($gcal_user); $query->setVisibility($gcal_visibility); $query->setProjection($gcal_projection); $eventFeed = $gdataCal->getCalendarEventFeed($query); // Build an array of the events from the feed, indexed by the Google ID $event_ids = array(); foreach ($eventFeed as $key => $event) { $short_id = $this->_getGcalShortId($event->id->text); $gcal_event_ids[$short_id] = $eventFeed[$key]; } /* Run through our table data, and build an array of our events indexed by the Google ID * (of course not all events may have a Google ID) */ $our_event_ids = array(); $our_upload_ids = array(); foreach ($mydata as $gkey => $group) { if (is_array($group)) { foreach ($group as $rkey => $row) { if ($row->{$gcal_id_element}) { $our_event_ids[$row->{$gcal_id_element}] = $mydata[$gkey][$rkey]; } else { $our_upload_ids[] = $mydata[$gkey][$rkey]; } } } } // Now go through the google events id's, and process the ones which aren't in our table. $our_event_adds = array(); foreach ($gcal_event_ids as $id => $event) { if (!array_key_exists($id, $our_event_ids)) { // we don't have the ID, so add the event to our table $row = array(); $row[$gcal_start_date_element] = strftime('%Y-%m-%d %H:%M:%S', strtotime($event->when[0]->startTime)); $row[$gcal_end_date_element] = strftime('%Y-%m-%d %H:%M:%S', strtotime($event->when[0]->endTime)); $row[$gcal_label_element] = $event->title->text; $row[$gcal_desc_element] = $event->content->text; $row[$gcal_id_element] = $id; if ($gcal_userid_element_long) { $row[$gcal_userid_element] = $our_userid; } $listModel->storeRow($row, 0); } } // If upload syncing (from us to gcal) is enabled ... if ($gcal_sync_upload == 'both' || $gcal_sync_upload == 'to') { // Grab the tzOffset. Note that gcal want +/-XX (like -06) // but J! gives us +/-X (like -6) so we sprintf it to the right format $config = JFactory::getConfig(); $tzOffset = (int) $config->getValue('config.offset'); $tzOffset = sprintf('%+03d', $tzOffset); // Loop thru the array we built earlier of events we have that aren't in gcal foreach ($our_upload_ids as $id => $event) { // Skip if a userid element is specified, and doesn't match the owner of this gcal if ($gcal_userid_element_long) { if ($event->{$gcal_userid_element} != $our_userid) { continue; } } // Now start building the gcal event structure $newEvent = $gdataCal->newEventEntry(); $newEvent->title = $gdataCal->newTitle($event->{$gcal_label_element}); if ($gcal_desc_element_long) { $newEvent->content = $gdataCal->newContent($event->{$gcal_desc_element}); } else { $newEvent->content = $gdataCal->newContent($event->{$gcal_label_element}); } $when = $gdataCal->newWhen(); // Grab the start date, apply the tx offset, and format it for gcal $start_date = JFactory::getDate($event->{$gcal_start_date_element}); $start_date->setOffset($tzOffset); $start_fdate = $start_date->toFormat('%Y-%m-%d %H:%M:%S'); $date_array = explode(' ', $start_fdate); $when->startTime = "{$date_array[0]}T{$date_array[1]}.000{$tzOffset}:00"; /* We have to provide an end date for gcal, so if we don't have one, * default it to start date + 1 hour */ if ($event->{$gcal_end_date_element} == '0000-00-00 00:00:00') { $startstamp = strtotime($event->{$gcal_start_date_element}); $endstamp = $startstamp + 60 * 60; $event->{$gcal_end_date_element} = strftime('%Y-%m-%d %H:%M:%S', $endstamp); } // Grab the end date, apply the tx offset, and format it for gcal $end_date = JFactory::getDate($event->{$gcal_end_date_element}); $end_date->setOffset($tzOffset); $end_fdate = $end_date->toFormat('%Y-%m-%d %H:%M:%S'); $date_array = explode(' ', $end_fdate); $when->endTime = "{$date_array[0]}T{$date_array[1]}.000{$tzOffset}:00"; $newEvent->when = array($when); // Fire off the insertEvent to gcal, catch any errors try { $retEvent = $gdataCal->insertEvent($newEvent); } catch (Zend_Gdata_App_HttpException $he) { $errStr = 'Problem adding event: ' . $he->getRawResponseBody() . "\n"; continue; } /* So, insertEvent worked, grab the gcal ID from the returned event data, * and update our event record with the short version of the ID */ $gcal_id = $this->_getGcalShortId($retEvent->id->text); $our_id = $event->id; $query = $db->getQuery(true); $query->update($table_name)->set($gcal_id_element . ' = ' . $db->quote($gcal_id))->where('id = ' . $db->quote($our_id)); $db->setQuery($query); $db->query(); } } } }
function export_google_calendar() { ajx_current("empty"); 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'); $users = ExternalCalendarUsers::findByContactId(); if($users){ if($users->getSync() == 1){ $sql = "SELECT ec.* FROM `".TABLE_PREFIX."external_calendars` ec,`".TABLE_PREFIX."external_calendar_users` ecu WHERE ec.calendar_feng = 1 AND ecu.contact_id = ".logged_user()->getId(); $calendar_feng = DB::executeOne($sql); $events = ProjectEvents::findNoSync(); $user = $users->getAuthUser(); $pass = $users->getAuthPass(); $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; try { $client = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,$service); $gdataCal = new Zend_Gdata_Calendar($client); if ($calendar_feng){ foreach ($events as $event){ $calendarUrl = 'http://www.google.com/calendar/feeds/'.$calendar_feng['calendar_user'].'/private/full'; $newEvent = $gdataCal->newEventEntry(); $newEvent->title = $gdataCal->newTitle($event->getObjectName()); $newEvent->content = $gdataCal->newContent($event->getDescription()); $star_time = explode(" ",$event->getStart()->format("Y-m-d H:i:s")); $end_time = explode(" ",$event->getDuration()->format("Y-m-d H:i:s")); if($event->getTypeId() == 2){ $when = $gdataCal->newWhen(); $when->startTime = $star_time[0]; $when->endTime = $end_time[0]; $newEvent->when = array($when); }else{ $when = $gdataCal->newWhen(); $when->startTime = $star_time[0]."T".$star_time[1].".000-00:00"; $when->endTime = $end_time[0]."T".$end_time[1].".000-00:00"; $newEvent->when = array($when); } // insert event $createdEvent = $gdataCal->insertEvent($newEvent, $calendarUrl); $event_id = explode("/",$createdEvent->id->text); $special_id = end($event_id); $event->setSpecialID($special_id); $event->setUpdateSync(ProjectEvents::date_google_to_sql($createdEvent->updated)); $event->setExtCalId($calendar_feng['id']); $event->save(); } }else{ $appCalUrl = ''; $calFeed = $gdataCal->getCalendarListFeed(); foreach ($calFeed as $calF){ $instalation = explode("/", ROOT_URL); $instalation_name = end($instalation); if($calF->title->text == lang('feng calendar',$instalation_name)){ $appCalUrl = $calF->content->src; $t_calendario = $calF->title->text; } } if($appCalUrl != ""){ $title_cal = $t_calendario; }else{ $instalation = explode("/", ROOT_URL); $instalation_name = end($instalation); $appCal = $gdataCal -> newListEntry(); $appCal -> title = $gdataCal-> newTitle(lang('feng calendar',$instalation_name)); $own_cal = "http://www.google.com/calendar/feeds/default/owncalendars/full"; $new_cal = $gdataCal->insertEvent($appCal, $own_cal); $title_cal = $new_cal->title->text; $appCalUrl = $new_cal->content->src; } $cal_src = explode("/",$appCalUrl); array_pop($cal_src); $calendar_visibility = end($cal_src); array_pop($cal_src); $calendar_user = end($cal_src); $calendar = new ExternalCalendar(); $calendar->setCalendarUser($calendar_user); $calendar->setCalendarVisibility($calendar_visibility); $calendar->setCalendarName($title_cal); $calendar->setExtCalUserId($users->getId()); $calendar->setCalendarFeng(1); $calendar->save(); foreach ($events as $event){ $calendarUrl = 'http://www.google.com/calendar/feeds/'.$calendar->getCalendarUser().'/private/full'; $newEvent = $gdataCal->newEventEntry(); $newEvent->title = $gdataCal->newTitle($event->getObjectName()); $newEvent->content = $gdataCal->newContent($event->getDescription()); $star_time = explode(" ",$event->getStart()->format("Y-m-d H:i:s")); $end_time = explode(" ",$event->getDuration()->format("Y-m-d H:i:s")); if($event->getTypeId() == 2){ $when = $gdataCal->newWhen(); $when->startTime = $star_time[0]; $when->endTime = $end_time[0]; $newEvent->when = array($when); }else{ $when = $gdataCal->newWhen(); $when->startTime = $star_time[0]."T".$star_time[1].".000-00:00"; $when->endTime = $end_time[0]."T".$end_time[1].".000-00:00"; $newEvent->when = array($when); } // insert event $createdEvent = $gdataCal->insertEvent($newEvent, $calendarUrl); $event_id = explode("/",$createdEvent->id->text); $special_id = end($event_id); $event->setSpecialID($special_id); $event->setUpdateSync(ProjectEvents::date_google_to_sql($createdEvent->updated)); $event->setExtCalId($calendar->getId()); $event->save(); } } flash_success(lang('success add sync')); ajx_current("reload"); } catch(Exception $e) { Logger::log($e->getMessage()); flash_error(lang('could not connect to calendar')); ajx_current("empty"); } } } }
public function googleAction() { //$this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $my_calendar = 'http://www.google.com/calendar/feeds/default/private/full'; if (!isset($_SESSION['cal_token'])) { if (isset($_GET['token'])) { // You can convert the single-use token to a session token. $session_token = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']); // Store the session token in our session. $_SESSION['cal_token'] = $session_token; } else { // Display link to generate single-use token $googleUri = Zend_Gdata_AuthSub::getAuthSubTokenUri('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], $my_calendar, 0, 1); echo "Click <a href='{$googleUri}'>here</a> " . "to authorize this application."; exit; } } // Create an authenticated HTTP Client to talk to Google. $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['cal_token']); // Create a Gdata object using the authenticated Http Client $cal = new Zend_Gdata_Calendar($client); var_export($cal->getCalendarListFeed()->count()); }
function created_event_google_calendar($object, $event) { 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'); $users = ExternalCalendarUsers::findByContactId(); $calendar = ExternalCalendars::findById($event->getExtCalId()); $user = $users->getAuthUser(); $pass = $users->getAuthPass(); $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service); $calendarUrl = 'http://www.google.com/calendar/feeds/' . $calendar->getCalendarUser() . '/private/full'; $gdataCal = new Zend_Gdata_Calendar($client); $newEvent = $gdataCal->newEventEntry(); $newEvent->title = $gdataCal->newTitle($event->getObjectName()); $newEvent->content = $gdataCal->newContent($event->getDescription()); $star_time = explode(" ", $event->getStart()->format("Y-m-d H:i:s")); $end_time = explode(" ", $event->getDuration()->format("Y-m-d H:i:s")); if ($event->getTypeId() == 2) { $when = $gdataCal->newWhen(); $when->startTime = $star_time[0]; $when->endTime = $end_time[0]; $newEvent->when = array($when); } else { $when = $gdataCal->newWhen(); $when->startTime = $star_time[0] . "T" . $star_time[1] . ".000-00:00"; $when->endTime = $end_time[0] . "T" . $end_time[1] . ".000-00:00"; $newEvent->when = array($when); } // insert event $createdEvent = $gdataCal->insertEvent($newEvent, $calendarUrl); $event_id = explode("/", $createdEvent->id->text); $special_id = end($event_id); $event->setSpecialID($special_id); $event->setExtCalId($calendar->getId()); $event->save(); }