Fix passing HTTP auth for remote calendars through Kronolith::listEvents().
authorJan Schneider <jan@horde.org>
Thu, 5 Mar 2009 15:02:49 +0000 (16:02 +0100)
committerJan Schneider <jan@horde.org>
Thu, 5 Mar 2009 15:02:49 +0000 (16:02 +0100)
Use higher timout value for remote calendars if retrieving events through
ajax, since events are being updated asynchronously.

kronolith/ajax.php
kronolith/lib/Driver.php
kronolith/lib/Kronolith.php

index 078d2d3..d50c956 100644 (file)
@@ -59,6 +59,9 @@ case 'ListEvents':
     $cal   = Util::getFormData('cal');
     list($driver, $calendar) = explode('|', $cal);
     $kronolith_driver = Kronolith::getDriver($driver, $calendar);
+    if ($driver == 'Ical') {
+        $kronolith_driver->setParam('timeout', 15);
+    }
     $events = $kronolith_driver->listEvents($start, $end, true, false, true);
     if (is_a($events, 'PEAR_Error')) {
         $notification->push($events, 'horde.error');
index a00e8a0..21bae88 100644 (file)
@@ -65,6 +65,17 @@ class Kronolith_Driver
         return isset($this->_params[$param]) ? $this->_params[$param] : null;
     }
 
+    /**
+     * Sets a configuration for this driver.
+     *
+     * @param string $param  A parameter name.
+     * @param mixed $value   The parameter value.
+     */
+    public function setParam($param, $value)
+    {
+        $this->_params[$param] = $value;
+    }
+
     public function open($calendar)
     {
         $this->_calendar = $calendar;
index 3c4506b..0ccc83d 100644 (file)
@@ -610,6 +610,9 @@ class Kronolith
             $driver = Kronolith::getDriver('Ical');
             foreach ($GLOBALS['display_remote_calendars'] as $url) {
                 $driver->open($url);
+                foreach (Kronolith::getRemoteParams($url) as $param => $value) {
+                    $driver->setParam($param, $value);
+                }
                 $events = $driver->listEvents($startDate, $endDate, true);
                 if (!is_a($events, 'PEAR_Error')) {
                     Kronolith::mergeEvents($results, $events);
@@ -1943,27 +1946,7 @@ class Kronolith
                 if (!empty($GLOBALS['conf']['http']['proxy']['proxy_host'])) {
                     $params['proxy'] = $GLOBALS['conf']['http']['proxy'];
                 }
-
-                /* Check for HTTP authentication credentials */
-                $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals'));
-                foreach ($cals as $cal) {
-                    if ($cal['url'] == $calendar) {
-                        $user = isset($cal['user']) ? $cal['user'] : '';
-                        $password = isset($cal['password']) ? $cal['password'] : '';
-                        $key = Auth::getCredential('password');
-                        if ($key && $user) {
-                            require_once 'Horde/Secret.php';
-                            $user = Secret::read($key, base64_decode($user));
-                            $password = Secret::read($key, base64_decode($password));
-                        }
-                        if (!empty($user)) {
-                            $params['user'] = $user;
-                            $params['password'] = $password;
-                        }
-                        break;
-                    }
-                }
-
+                $params = Kronolith::getRemoteParams($calendar);
                 break;
 
             case 'Horde':
@@ -1986,6 +1969,34 @@ class Kronolith
     }
 
     /**
+     * Check for HTTP authentication credentials
+     */
+    public static function getRemoteParams($calendar)
+    {
+        if (empty($calendar)) {
+            return array();
+        }
+
+        $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals'));
+        foreach ($cals as $cal) {
+            if ($cal['url'] == $calendar) {
+                $user = isset($cal['user']) ? $cal['user'] : '';
+                $password = isset($cal['password']) ? $cal['password'] : '';
+                $key = Auth::getCredential('password');
+                if ($key && $user) {
+                    $user = Horde_Secret::read($key, base64_decode($user));
+                    $password = Horde_Secret::read($key, base64_decode($password));
+                }
+                if (!empty($user)) {
+                    return array('user' => $user, 'password' => $password);
+                }
+            }
+        }
+
+        return array();
+    }
+
+    /**
      * Get a named Kronolith_View_* object and load it with the
      * appropriate date parameters.
      *