/usr/share/horde/timeobjects/lib/Driver/FacebookEvents.php is in php-horde-timeobjects 2.1.1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | <?php
/**
* TimeObjects driver for exposing a user's Facebook Events via the
* listTimeObjects API.
*
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package TimeObjects
*/
class TimeObjects_Driver_FacebookEvents extends TimeObjects_Driver_Base
{
private $_fb_session;
public function ensure()
{
if (!$GLOBALS['conf']['facebook']['enabled']) {
return false;
}
$fbp = unserialize($GLOBALS['prefs']->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(Horde_Date $start = null, Horde_Date $time = null)
{
try {
$fb = $this->_getFacebook();
$events = $fb->events->get();
} catch (Horde_Service_Facebook_Exception $e) {
throw new TimeObjects_Exception($e->getMessage());
}
$cache = $GLOBALS['injector']->getInstance('Horde_Cache');
$key = 'timeobjects.facebook|' . $GLOBALS['registry']->getAuth() . '|' . (string)$start . '|' . (string)$time;
if ($data = $cache->get($key, 3600)) {
return json_decode($data, true);
}
$objects = array();
foreach ($events as $event) {
$start = new Horde_Date($event['start_time']);
$end = $event['end_time']
? new Horde_Date($event['end_time'])
: clone $start;
$title = $event['name'];
if (isset($event['tagline']) && strlen($event['tagline'])) {
$title .= ' - ' . $event['tagline'];
}
$objects[] = array(
'id' => $event['eid'],
'title' => $title,
'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,
'location' => $event['location'],
'description' => $event['description'],
'url' => 'http://www.facebook.com/event.php?eid=' . $event['eid'],
'status' => (empty($event['rsvp_status']) ? 'free' : $event['rsvp_status']),
'private' => $event['privacy'] == 'SECRET',
'icon' => $event['pic_square'],
'params' => array()
);
}
$cache->set($key, json_encode($objects));
return $objects;
}
private function _getFacebook()
{
if ((empty($this->_fb_session['uid']) ||
empty($this->_fb_session['sid'])) &&
!$this->ensure()) {
throw new TimeObjects_Exception('Cannot load Facebook object.');
}
return $GLOBALS['injector']->getInstance('Horde_Service_Facebook');
}
}
|