Make sure the Kronolith::getDriver() reloads the calendar parameters
authorJan Schneider <jan@horde.org>
Wed, 7 Jul 2010 22:02:06 +0000 (00:02 +0200)
committerJan Schneider <jan@horde.org>
Wed, 7 Jul 2010 22:05:31 +0000 (00:05 +0200)
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
kronolith/lib/Driver/Ical.php
kronolith/lib/Kronolith.php

index f57461e..28ebbde 100644 (file)
@@ -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.
index 3bac00f..23d8664 100644 (file)
@@ -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);
index d34f637..e855d85 100644 (file)
@@ -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)) {