From: Michael J. Rubinsky Date: Mon, 8 Jun 2009 17:33:52 +0000 (-0400) Subject: Add a FacebookEvents driver for timeobjects. FB does some weird things X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=df1b377378af21ec5d729e919fe1788677f85725;p=horde.git Add a FacebookEvents driver for timeobjects. FB does some weird things with it's timestamps, so feedback on if the event times show up correctly for people in various timezones would be welcome... --- diff --git a/timeobjects/lib/Driver/FacebookEvents.php b/timeobjects/lib/Driver/FacebookEvents.php new file mode 100644 index 000000000..911da1d5e --- /dev/null +++ b/timeobjects/lib/Driver/FacebookEvents.php @@ -0,0 +1,94 @@ +getValue('facebook')); + if (empty($fbp['uid']) || empty($fbp['sid'])) { + return false; + } else { + $this->_fb_session = $fbp; + } + + return true; + } + + /** + * + * @param mixed $start The start time of the period + * @param mixed $time The end time of the period + * + * @return array of listTimeObjects arrays. + */ + public function listTimeObjects($start = null, $time = null) + { + $fb = $this->_getFacebook(); + $events = $fb->events->get(); + $objects = array(); + foreach ($events as $event) { + // FB s*cks. This may be right, or it may be wrong, or they may + // change it, who knows. + $event['start_time'] -= 21600; //60 * 60 * 6; + $start = new Horde_Date($event['start_time'], 'America/Los_Angeles'); + $start->setTimezone($GLOBALS['prefs']->getValue('timezone', date_default_timezone_get())); + $event['end_time'] -= 21600; + $end = new Horde_Date($event['end_time'], 'America/Los_Angeles'); + $end->setTimezone($GLOBALS['prefs']->getValue('timezone', date_default_timezone_get())); + + $objects[] = array('id' => $event['eid'], + 'title' => $event['name'] . ' - ' . $event['tagline'], + 'start' => sprintf('%d-%02d-%02dT%02d:%02d:00', + $start->year, + $start->month, + $start->mday, + $start->hour, + $start->min), + 'end' => sprintf('%d-%02d-%02dT%02d:%02d:00', + $end->year, + $end->month, + $end->mday, + $end->hour, + $end->min), + 'recurrence' => Horde_Date_Recurrence::RECUR_NONE, + 'params' => array(), + 'icon' => $event['pic_small'] + ); + } + + return $objects; + } + + private function _getFacebook() + { + global $conf; + + if (empty($this->_fb_session['uid']) || empty($this->_fb_session['sid'])) { + if (!$this->ensure()) { + throw new TimeObjects_Exception('Cannot load Facebook object.'); + } + } + + $context = array('http_client' => new Horde_Http_Client(), + 'http_request' => new Horde_Controller_Request_Http()); + $facebook = new Horde_Service_Facebook($conf['facebook']['key'], + $conf['facebook']['secret'], + $context); + $facebook->auth->setUser($this->_fb_session['uid'], + $this->_fb_session['sid'], + 0); + return $facebook; + + } +} \ No newline at end of file diff --git a/timeobjects/lib/api.php b/timeobjects/lib/api.php index e191a2401..203df4ab0 100644 --- a/timeobjects/lib/api.php +++ b/timeobjects/lib/api.php @@ -32,12 +32,19 @@ function _timeobjects_listTimeObjectCategories() // @TODO: Probably want to iterate the driver directory // and dynamically build this list and/or maybe provide // a $conf[] setting to explicitly disable certain drivers? + $drivers = array(); + $drv = TimeObjects_Driver::factory('Weatherdotcom'); if ($drv->ensure()) { - return array('Weatherdotcom' => _("Weather")); - } else { - return array(); + $drivers['Weatherdotcom'] = _("Weather"); } + + $drv = TimeObjects_Driver::factory('FacebookEvents'); + if ($drv->ensure()) { + $drivers['FacebookEvents'] = _("Facebook Events"); + } + + return $drivers; } /**