From 595f52246a1093d282adfb7f49d91039b82b2a9f Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Wed, 12 Jan 2011 14:53:34 -0500 Subject: [PATCH] Use Horde 4 style class/file names --- kronolith/lib/Storage/Kolab.php | 74 +++++++++++++++++++++++++++++ kronolith/lib/Storage/Sql.php | 101 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 kronolith/lib/Storage/Kolab.php create mode 100644 kronolith/lib/Storage/Sql.php diff --git a/kronolith/lib/Storage/Kolab.php b/kronolith/lib/Storage/Kolab.php new file mode 100644 index 000000000..bba2be442 --- /dev/null +++ b/kronolith/lib/Storage/Kolab.php @@ -0,0 +1,74 @@ + + * @package Kronolith + */ +class Kronolith_Storage_Kolab extends Kronolith_Storage +{ + protected $_params = array(); + + function __construct($user, $params = array()) + { + $this->_user = $user; + $this->_params = $params; + } + + /** + * @throws Kronolith_Exception + */ + public function search($email, $private_only = false) + { + global $conf; + + if (class_exists('Horde_Kolab_Session')) { + $session = Horde_Kolab_Session::singleton(); + $server = $session->freebusy_server; + } else { + $server = sprintf('%s://%s:%d/freebusy/', + $conf['storage']['freebusy']['protocol'], + Kolab::getServer('imap'), + $conf['storage']['freebusy']['port']); + } + + $fb_url = sprintf('%s/%s.xfb', $server, $email); + + $options['method'] = 'GET'; + $options['timeout'] = 5; + $options['allowRedirects'] = true; + + if (!empty($GLOBALS['conf']['http']['proxy']['proxy_host'])) { + $options = array_merge($options, $GLOBALS['conf']['http']['proxy']); + } + + $http = new HTTP_Request($fb_url, $options); + $http->setBasicAuth($GLOBALS['registry']->getAuth(), $GLOBALS['registry']->getAuthCredential('password')); + @$http->sendRequest(); + if ($http->getResponseCode() != 200) { + throw new Horde_Exception_NotFound(); + } + $vfb_text = $http->getResponseBody(); + + $iCal = new Horde_Icalendar; + $iCal->parsevCalendar($vfb_text); + + $vfb = $iCal->findComponent('VFREEBUSY'); + if ($vfb === false) { + throw new Horde_Exception_NotFound(); + } + + return $vfb; + } + + public function store($email, $vfb, $public = false) + { + // We don't care about storing FB info at the moment; we rather let + // Kolab's freebusy.php script auto-generate it for us. + } + +} diff --git a/kronolith/lib/Storage/Sql.php b/kronolith/lib/Storage/Sql.php new file mode 100644 index 000000000..48e4340d7 --- /dev/null +++ b/kronolith/lib/Storage/Sql.php @@ -0,0 +1,101 @@ + + * @author Michael J Rubinsky + * @package Kronolith + */ +class Kronolith_Storage_Sql extends Kronolith_Storage +{ + /** + * Handle for the current database connection, used for reading. + * + * @var Horde_Db_Adapter + */ + protected $_db; + + /** + * Hash containing connection parameters. + * + * @var array + */ + protected $_params = array(); + + /** + * Constructs a new Kronolith_Storage SQL instance. + * + * @param array $params A hash containing connection parameters. + */ + public function __construct($user, $params = array()) + { + $this->_user = $user; + if (empty($params['db'])) { + throw new InvalidArgumentException(_("Missing required db parameter")); + } + + $this->_db = $params['db']; + $this->_params = $params; + $this->_params['table'] = isset($params['table']) ? $params['table'] : 'kronolith_storage'; + } + + /** + * Search for a user's free/busy information. + * + * @param string $email The email address to lookup + * @param boolean $private_only (optional) Only return free/busy + * information owned by this used. + * + * @return Horde_Icalendar_Vfreebusy + * @throws Kronolith_Exception + */ + public function search($email, $private_only = false) + { + /* Build the SQL query. */ + $query = sprintf('SELECT vfb_serialized FROM %s WHERE vfb_email = ? AND (vfb_owner = ?', + $this->_params['table']); + $values = array($email, $this->_user); + + if ($private_only) { + $query .= ')'; + } else { + $query .= " OR vfb_owner = '')"; + } + + /* Execute the query. */ + try { + $result = $this->_db->selectValue($query, $values); + if (empty($result)) { + throw new Horde_Exception_NotFound(); + } + return Horde_Serialize::unserialize($result, Horde_Serialize::BASIC); + } catch (Horde_Db_Exception $e) { + throw new Kronolith_Exception($e); + } + } + + /** + * Store the freebusy information for a given email address. + * + * @param string $email The email address to store fb info for. + * @param Horde_Icalendar_Vfreebusy $vfb TODO + * @param boolean $private_only (optional) TODO + * + * @throws Kronolith_Exception + */ + public function store($email, $vfb, $public = false) + { + /* Build the SQL query. */ + $query = sprintf('INSERT INTO %s (vfb_owner, vfb_email, vfb_serialized) VALUES (?, ?, ?)', + $this->_params['table']); + $values = array($public ? '' : $this->_user, $email, Horde_Serialize::serialize($vfb, Horde_Serialize::BASIC)); + + /* Execute the query. */ + try { + $result = $this->_db->insert($query, $values); + } catch (Horde_Db_Exception $e) { + throw new Kronolith_Exception($e); + } + } + +} -- 2.11.0