3 commits - plugins/calendar plugins/libkolab

Thomas Brüderli bruederli at kolabsys.com
Wed Aug 6 10:34:39 CEST 2014


 plugins/calendar/drivers/calendar_driver.php          |   64 +++++++++++++++++-
 plugins/calendar/drivers/database/database_driver.php |    6 +
 plugins/calendar/drivers/kolab/kolab_driver.php       |    8 +-
 plugins/libkolab/lib/kolab_format_configuration.php   |    2 
 4 files changed, 75 insertions(+), 5 deletions(-)

New commits:
commit ca02fcbb37ea3f600e0b0bea15eaffebd6b3630e
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Aug 6 10:34:25 2014 +0200

    Cast relation object arguments into strings even if not set. This avoids fatal errors when calling the libkolabxml bindings with wrong function signatures

diff --git a/plugins/libkolab/lib/kolab_format_configuration.php b/plugins/libkolab/lib/kolab_format_configuration.php
index 44b7e92..11f934f 100644
--- a/plugins/libkolab/lib/kolab_format_configuration.php
+++ b/plugins/libkolab/lib/kolab_format_configuration.php
@@ -64,7 +64,7 @@ class kolab_format_configuration extends kolab_format
             break;
 
         case 'relation':
-            $relation = new Relation($object['name'], $object['category']);
+            $relation = new Relation(strval($object['name']), strval($object['category']));
 
             if ($object['color']) {
                 $relation->setColor($object['color']);


commit 46315c8ad587f3d6aac42111d81ef907472c504b
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Aug 6 09:34:08 2014 +0200

    Fix calendar_driver::get_event() for birthday calendar entries

diff --git a/plugins/calendar/drivers/calendar_driver.php b/plugins/calendar/drivers/calendar_driver.php
index e213a93..14b80c4 100644
--- a/plugins/calendar/drivers/calendar_driver.php
+++ b/plugins/calendar/drivers/calendar_driver.php
@@ -563,7 +563,11 @@ abstract class calendar_driver
             $birthyear = $bday->format('Y');
           }
           catch (Exception $e) {
-            console('BIRTHDAY PARSE ERROR: ' . $e);
+            rcube::raise_error(array(
+                'code' => 600, 'type' => 'php',
+                'file' => __FILE__, 'line' => __LINE__,
+                'message' => 'BIRTHDAY PARSE ERROR: ' . $e),
+              true, false);
             continue;
           }
 
@@ -598,7 +602,7 @@ abstract class calendar_driver
           if ($bday <= $end && $bday >= $start) {
             $age = $year - $birthyear;
             $event = array(
-              'id'          => md5('bday_' . $contact['ID'] . $year),
+              'id'          => rcube_ldap::dn_encode('bday:' . $source . ':' . $contact['ID'] . ':' . $year),
               'calendar'    => self::BIRTHDAY_CALENDAR_ID,
               'title'       => $event_title,
               'description' => $rcmail->gettext(array('name' => 'birthdayage', 'vars' => array('age' => $age)), 'calendar'),
@@ -625,6 +629,62 @@ abstract class calendar_driver
   }
 
   /**
+   * Get a single birthday calendar event
+   */
+  public function get_birthday_event($id)
+  {
+    // decode $id
+    list(,$source,$contact_id,$year) = explode(':', rcube_ldap::dn_decode($id));
+
+    $rcmail = rcmail::get_instance();
+
+    if ($source && $contact_id && ($abook = $rcmail->get_address_book($source))) {
+      $contact = $abook->get_record($contact_id, true);
+
+      if (is_array($contact) && !empty($contact['birthday'])) {
+        try {
+          if (is_array($contact['birthday']))
+            $contact['birthday'] = reset($contact['birthday']);
+
+          $bday = $contact['birthday'] instanceof DateTime ? $contact['birthday'] :
+                    new DateTime($contact['birthday'], new DateTimezone('UTC'));
+          $birthyear = $bday->format('Y');
+        }
+        catch (Exception $e) {
+          rcube::raise_error(array(
+              'code' => 600, 'type' => 'php',
+              'file' => __FILE__, 'line' => __LINE__,
+              'message' => 'BIRTHDAY PARSE ERROR: ' . $e),
+            true, false);
+
+          return null;
+        }
+
+        $display_name = rcube_addressbook::compose_display_name($contact);
+        $event_title = $rcmail->gettext(array('name' => 'birthdayeventtitle', 'vars' => array('name' => $display_name)), 'calendar');
+
+        $event = array(
+          'id'          => rcube_ldap::dn_encode('bday:' . $source . ':' . $contact['ID'] . ':' . $year),
+          'uid'         => rcube_ldap::dn_encode('bday:' . $source . ':' . $contact['ID'] . ':' . $birthyear),
+          'calendar'    => self::BIRTHDAY_CALENDAR_ID,
+          'title'       => $event_title,
+          'description' => '',
+          'allday'      => true,
+          'start'       => $bday,
+          'recurrence'  => array('FREQ' => 'YEARLY', 'INTERVAL' => 1),
+          'free_busy'   => 'free',
+        );
+        $event['end'] = clone $bday;
+        $event['end']->add(new DateInterval('PT1H'));
+
+        return $event;
+      }
+    }
+
+    return null;
+  }
+
+  /**
    * Handler for user_delete plugin hook
    *
    * @param array Hash array with hook arguments
diff --git a/plugins/calendar/drivers/database/database_driver.php b/plugins/calendar/drivers/database/database_driver.php
index 9ea7809..1d5f081 100644
--- a/plugins/calendar/drivers/database/database_driver.php
+++ b/plugins/calendar/drivers/database/database_driver.php
@@ -744,11 +744,17 @@ class database_driver extends calendar_driver
   public function get_event($event, $writeable = false, $active = false, $personal = false)
   {
     $id = is_array($event) ? ($event['id'] ? $event['id'] : $event['uid']) : $event;
+    $cal = is_array($event) ? $event['calendar'] : null;
     $col = is_array($event) && is_numeric($id) ? 'event_id' : 'uid';
 
     if ($this->cache[$id])
       return $this->cache[$id];
 
+    // get event from the address books birthday calendar
+    if ($cal == self::BIRTHDAY_CALENDAR_ID) {
+      return $this->get_birthday_event($id);
+    }
+
     if ($active) {
       $calendars = $this->calendars;
       foreach ($calendars as $idx => $cal) {
diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index fd93608..4f0bdfb 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -524,6 +524,10 @@ class kolab_driver extends calendar_driver
       if ($storage = $this->get_calendar($cal)) {
         return $storage->get_event($id);
       }
+      // get event from the address books birthday calendar
+      else if ($cal == self::BIRTHDAY_CALENDAR_ID) {
+        return $this->get_birthday_event($id);
+      }
     }
     // iterate over all calendar folders and search for the event ID
     else {


commit e7dfea1e035d3d290b551d92db40d1b442c63999
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Aug 6 08:52:56 2014 +0200

    Set default color for birthdays calendar

diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index 90ea084..fd93608 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -253,8 +253,8 @@ class kolab_driver extends calendar_driver
           'id'         => $id,
           'name'       => $this->cal->gettext('birthdays'),
           'listname'   => $this->cal->gettext('birthdays'),
-          'color'      => $prefs[$id]['color'],
-          'active'     => $prefs[$id]['active'],
+          'color'      => $prefs[$id]['color'] ?: '87CEFA',
+          'active'     => (bool)$prefs[$id]['active'],
           'showalarms' => (bool)$this->rc->config->get('calendar_birthdays_alarm_type'),
           'group'      => 'x-birthdays',
           'readonly'   => true,




More information about the commits mailing list