diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php index a5caaa83..920462c1 100644 --- a/plugins/calendar/calendar.php +++ b/plugins/calendar/calendar.php @@ -182,6 +182,12 @@ class calendar extends rcube_plugin $this->api->output->add_label('calendar.createfrommail'); } } + else if ($args['task'] == 'addressbook') { + if ($this->rc->config->get('calendar_contact_birthdays')) { + $this->add_hook('contact_update', array($this, 'contact_update')); + $this->add_hook('contact_create', array($this, 'contact_update')); + } + } // add hooks to display alarms $this->add_hook('pending_alarms', array($this, 'pending_alarms')); @@ -1004,6 +1010,18 @@ class calendar extends rcube_plugin $this->rc->output->send(); } + /** + * Hook triggered when a contact is saved + */ + function contact_update($p) + { + // clear birthdays calendar cache + if (!empty($p['record']['birthday'])) { + $cache = $this->rc->get_cache('calendar.birthdays', 'db'); + $cache->remove(); + } + } + /** * */ diff --git a/plugins/calendar/drivers/calendar_driver.php b/plugins/calendar/drivers/calendar_driver.php index 0eedf7fd..af8cb2fc 100644 --- a/plugins/calendar/drivers/calendar_driver.php +++ b/plugins/calendar/drivers/calendar_driver.php @@ -444,8 +444,8 @@ abstract class calendar_driver $cached = $cache->get($source['id']); // iterate over (cached) contacts - foreach ((array)($cached ?: $abook->list_records()) as $contact) { - if (!empty($contact['birthday'])) { + foreach (($cached ?: $abook->list_records()) as $contact) { + if (is_array($contact) && !empty($contact['birthday'])) { try { if (is_array($contact['birthday'])) $contact['birthday'] = reset($contact['birthday']); @@ -455,7 +455,7 @@ abstract class calendar_driver $birthyear = $bday->format('Y'); } catch (Exception $e) { - // console('BIRTHDAY PARSE ERROR: ' . $e); + console('BIRTHDAY PARSE ERROR: ' . $e); continue; }