From 0e5db4432a7cd1e122b0d5a17bc083c4d9baf624 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Thu, 8 Jul 2010 00:02:06 +0200 Subject: [PATCH] Make sure the Kronolith::getDriver() reloads the calendar parameters when re-using an existing Ical driver. Don't re-use the HTTP client if opening another calendar. Fix caching of error messages. Remote calendar user names are not encrypted. --- kronolith/lib/Driver.php | 10 ++++++++++ kronolith/lib/Driver/Ical.php | 17 ++++++++++++++--- kronolith/lib/Kronolith.php | 20 +++++++------------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/kronolith/lib/Driver.php b/kronolith/lib/Driver.php index f57461e57..28ebbdebc 100644 --- a/kronolith/lib/Driver.php +++ b/kronolith/lib/Driver.php @@ -91,6 +91,16 @@ class Kronolith_Driver } /** + * Sets all configuration parameters for this driver. + * + * @param string $params A parameters hash. + */ + public function setParams($params) + { + $this->_params = $params; + } + + /** * Selects a calendar as the currently opened calendar. * * @param string $calendar A calendar identifier. diff --git a/kronolith/lib/Driver/Ical.php b/kronolith/lib/Driver/Ical.php index 3bac00f9c..23d866457 100644 --- a/kronolith/lib/Driver/Ical.php +++ b/kronolith/lib/Driver/Ical.php @@ -38,6 +38,17 @@ class Kronolith_Driver_Ical extends Kronolith_Driver private $_client; /** + * Selects a calendar as the currently opened calendar. + * + * @param string $calendar A calendar identifier. + */ + public function open($calendar) + { + parent::open($calendar); + $this->_client = null; + } + + /** * Returns the background color of the current calendar. * * @return string The calendar color. @@ -222,7 +233,7 @@ class Kronolith_Driver_Ical extends Kronolith_Driver } catch (Horde_Http_Exception $e) { Horde::logMessage($e, 'INFO'); if ($cache) { - $cacheOb->set($signature, $e->getMessage()); + $cacheOb->set($signature, serialize($e->getMessage())); } throw new Kronolith_Exception($e); } @@ -231,7 +242,7 @@ class Kronolith_Driver_Ical extends Kronolith_Driver $url, $response->code), 'INFO'); $error = sprintf(_("Could not open %s."), $url); if ($cache) { - $cacheOb->set($signature, $error); + $cacheOb->set($signature, serialize($error)); } throw new Kronolith_Exception($error, $response->code); } @@ -244,7 +255,7 @@ class Kronolith_Driver_Ical extends Kronolith_Driver $ical = new Horde_iCalendar(); $result = $ical->parsevCalendar($data); if ($cache) { - $cacheOb->set($signature, $ical); + $cacheOb->set($signature, serialize($ical)); } if ($result instanceof PEAR_Error) { throw new Kronolith_Exception($result); diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index d34f6379e..e855d8515 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -564,12 +564,8 @@ class Kronolith } /* Remote Calendars. */ - $driver = self::getDriver('Ical'); foreach ($GLOBALS['display_remote_calendars'] as $url) { - $driver->open($url); - foreach (self::getRemoteParams($url) as $param => $value) { - $driver->setParam($param, $value); - } + $driver = self::getDriver('Ical', $url); $events = $driver->listEvents($startDate, $endDate, $showRecurrence); self::mergeEvents($results, $events); } @@ -2642,7 +2638,6 @@ class Kronolith } if (!isset(self::$_instances[$driver])) { - $params = array(); switch ($driver) { case 'Sql': case 'Resource': @@ -2654,11 +2649,7 @@ class Kronolith break; case 'Ical': - $params = self::getRemoteParams($calendar); - /* Check for HTTP proxy configuration */ - if (!empty($GLOBALS['conf']['http']['proxy']['proxy_host'])) { - $params['proxy'] = $GLOBALS['conf']['http']['proxy']; - } + $params = array(); break; case 'Horde': @@ -2682,6 +2673,10 @@ class Kronolith if (!is_null($calendar)) { self::$_instances[$driver]->open($calendar); + /* Remote calendar parameters are per calendar. */ + if ($driver == 'Ical') { + self::$_instances[$driver]->setParams(self::getRemoteParams($calendar)); + } } return self::$_instances[$driver]; @@ -2702,9 +2697,8 @@ class Kronolith $user = isset($cal['user']) ? $cal['user'] : ''; $password = isset($cal['password']) ? $cal['password'] : ''; $key = $GLOBALS['registry']->getAuthCredential('password'); - if ($key && $user) { + if ($key && $password) { $secret = $GLOBALS['injector']->getInstance('Horde_Secret'); - $user = $secret->read($key, base64_decode($user)); $password = $secret->read($key, base64_decode($password)); } if (!empty($user)) { -- 2.11.0