/** * Responsible for any logic needed before the event is saved. Called for * EVERY component in the iCalendar object. Returning false from this method * will cause the current component to be ignored. Returning true causes it * to be processed. * * @param Horde_Icalendar $component The iCalendar component. * * @return boolean True to continue processing, false to ignore. */ protected function _preSave($component) { // Short circuit if we know we don't pass the parent test. if (!parent::_preSave($component)) { return false; } // Ensure we start with a fresh state. $this->_existingEvent = null; $this->_oldAttendees = new Kronolith_Attendee_List(); $this->_noItips = array(); // Get the internal id of the existing copy of the event, if it exists. try { $existing_id = $this->_dav->getInternalObjectId($this->_params['object'], $this->_calendar) ?: preg_replace('/\\.ics$/', '', $this->_params['object']); } catch (Horde_Dav_Exception $e) { $existing_id = $this->_params['object']; } // Check that we don't have newer information already on the server. try { // Exception event, so we can't compare timestamps using ids. // Instead look for baseid/recurrence-id. $rid = $component->getAttribute('RECURRENCE-ID'); $uid = $component->getAttribute('UID'); if (!empty($rid) && !empty($uid)) { $search = new stdClass(); $search->baseid = $uid; $search->recurrenceid = $rid; $results = $this->_driver->search($search); foreach ($results as $days) { foreach ($days as $exception) { // Should only be one... $modified = $exception->modified ?: $exception->created; } } } } catch (Horde_Icalendar_Exception $e) { // Base event or event with no recurrence. try { $this->_existingEvent = $this->_driver->getEvent($existing_id); $this->_existingEvent->loadHistory(); $modified = $this->_existingEvent->modified ?: $this->_existingEvent->created; // Get list of existing attendees. $this->_oldAttendees = $this->_existingEvent->attendees; } catch (Horde_Exception_NotFound $e) { $this->_existingEvent = null; } } try { if (!empty($modified) && $component->getAttribute('LAST-MODIFIED') < $modified->timestamp()) { /* LAST-MODIFIED timestamp of existing entry is newer: * don't replace it. */ return false; } } catch (Horde_Icalendar_Exception $e) { } try { $organizer = $component->getAttribute('ORGANIZER'); $organizer_params = $component->getAttribute('ORGANIZER', true); if (!empty($organizer_params[0]['SCHEDULE-AGENT']) && ($organizer_params[0]['SCHEDULE-AGENT'] == 'CLIENT' || $organizer_params[0]['SCHEDULE-AGENT'] == 'NONE')) { $tmp = str_replace(array('MAILTO:', 'mailto:'), '', $organizer); $tmp = new Horde_Mail_Rfc822_Address($tmp); $this->_noItips[] = $tmp->bare_address; } } catch (Horde_Icalendar_Exception $e) { } try { $attendee = $component->getAttribute('ATTENDEE'); $params = $component->getAttribute('ATTENDEE', true); for ($i = 0; $i < count($attendee); ++$i) { if (!empty($params[$i]['SCHEDULE-AGENT']) && ($params[$i]['SCHEDULE-AGENT'] == 'CLIENT' || $params[$i]['SCHEDULE-AGENT'] == 'NONE')) { $tmp = str_replace(array('MAILTO:', 'mailto:'), '', $attendee[$i]); $tmp = new Horde_Mail_Rfc822_Address($tmp); $this->_noItips[] = $tmp->bare_address; } } } catch (Horde_Icalendar_Exception $e) { } return true; }