Example #1
0
 /**
  * Updates the ICalendar-formatted object 
  * 
  * @param string $calendarData 
  * @return void 
  */
 public function put($calendarData)
 {
     if (is_resource($calendarData)) {
         $calendarData = stream_get_contents($calendarData);
     }
     $supportedComponents = $this->calendarInfo['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set']->getValue();
     Sabre_CalDAV_ICalendarUtil::validateICalendarObject($calendarData, $supportedComponents);
     $this->caldavBackend->updateCalendarObject($this->calendarInfo['id'], $this->objectData['uri'], $calendarData);
     $this->objectData['calendardata'] = $calendarData;
 }
Example #2
0
 /**
  * @expectedException Sabre_CalDAV_Exception_InvalidICalendarObject
  * @depends testValidateICalendarObjectValid
  */
 function testValidateICalendarObjectHasMethodProperty()
 {
     $in = array('BEGIN:VCALENDAR', 'VERSION:2.0', 'METHOD:blabla', 'PRODID:-//hacksw/handcal//NONSGML v1.0//EN', 'BEGIN:VEVENT', 'SUMMARY;LANGUAGE=nl-NL:meeting', 'X-SABRE;att1=val1;att2=val2:This is the property content', 'END:VEVENT', 'END:VCALENDAR');
     Sabre_CalDAV_ICalendarUtil::validateICalendarObject(implode("\n", $in), array('VEVENT'));
 }
Example #3
0
 /**
  * Verify if a list of filters applies to the calendar data object 
  *
  * The calendarData object must be a valid iCalendar blob. The list of 
  * filters must be formatted as parsed by Sabre_CalDAV_Plugin::parseCalendarQueryFilters
  *
  * @param string $calendarData 
  * @param array $filters 
  * @return bool 
  */
 public function validateFilters($calendarData, $filters)
 {
     // We are converting the calendar object to an XML structure
     // This makes it far easier to parse
     $xCalendarData = Sabre_CalDAV_ICalendarUtil::toXCal($calendarData);
     $xml = simplexml_load_string($xCalendarData);
     $xml->registerXPathNamespace('c', 'urn:ietf:params:xml:ns:xcal');
     foreach ($filters as $xpath => $filter) {
         // if-not-defined comes first
         if (isset($filter['is-not-defined'])) {
             if (!$xml->xpath($xpath)) {
                 continue;
             } else {
                 return false;
             }
         }
         $elem = $xml->xpath($xpath);
         if (!$elem) {
             return false;
         }
         $elem = $elem[0];
         if (isset($filter['time-range'])) {
             switch ($elem->getName()) {
                 case 'vevent':
                     $result = $this->validateTimeRangeFilterForEvent($xml, $xpath, $filter);
                     if ($result === false) {
                         return false;
                     }
                     break;
                 case 'vtodo':
                     $result = $this->validateTimeRangeFilterForTodo($xml, $xpath, $filter);
                     if ($result === false) {
                         return false;
                     }
                     break;
                 case 'vjournal':
                 case 'vfreebusy':
                 case 'valarm':
                     // TODO: not implemented
                     break;
                     /*
                     
                                         case 'vjournal' :
                                             $result = $this->validateTimeRangeFilterForJournal($xml,$xpath,$filter);
                                             if ($result===false) return false;
                                             break;
                                         case 'vfreebusy' :
                                             $result = $this->validateTimeRangeFilterForFreeBusy($xml,$xpath,$filter);
                                             if ($result===false) return false;
                                             break;
                                         case 'valarm' :
                                             $result = $this->validateTimeRangeFilterForAlarm($xml,$xpath,$filter);
                                             if ($result===false) return false;
                                             break;
                     */
             }
         }
         if (isset($filter['text-match'])) {
             $currentString = (string) $elem;
             $isMatching = Sabre_DAV_StringUtil::textMatch($currentString, $filter['text-match']['value'], $filter['text-match']['collation']);
             if ($filter['text-match']['negate-condition'] && $isMatching) {
                 return false;
             }
             if (!$filter['text-match']['negate-condition'] && !$isMatching) {
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * Updates the ICalendar-formatted object 
  * 
  * @param string $calendarData 
  * @return void 
  */
 public function put($calendarData)
 {
     if (is_resource($calendarData)) {
         $calendarData = stream_get_contents($calendarData);
     }
     // Converting to UTF-8, if needed
     $calendarData = Sabre_DAV_StringUtil::ensureUTF8($calendarData);
     $supportedComponents = $this->calendarInfo['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set'];
     if ($supportedComponents) {
         $supportedComponents = $supportedComponents->getValue();
     } else {
         $supportedComponents = null;
     }
     Sabre_CalDAV_ICalendarUtil::validateICalendarObject($calendarData, $supportedComponents);
     $this->caldavBackend->updateCalendarObject($this->calendarInfo['id'], $this->objectData['uri'], $calendarData);
     $this->objectData['calendardata'] = $calendarData;
 }
Example #5
0
 /**
  * Creates a new file
  *
  * The contents of the new file must be a valid ICalendar string.
  * 
  * @param string $name 
  * @param resource $calendarData 
  * @return void
  */
 public function createFile($name, $calendarData = null)
 {
     if (!$this->hasPrivilege()) {
         throw new Sabre_DAV_Exception_Forbidden('Permission denied to access this calendar');
     }
     $calendarData = stream_get_contents($calendarData);
     $supportedComponents = $this->calendarInfo['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set']->getValue();
     Sabre_CalDAV_ICalendarUtil::validateICalendarObject($calendarData, $supportedComponents);
     $this->caldavBackend->createCalendarObject($this->calendarInfo['id'], $name, $calendarData);
 }
Example #6
0
 /**
  * Creates a new file
  *
  * The contents of the new file must be a valid ICalendar string.
  * 
  * @param string $name 
  * @param resource $calendarData 
  * @return void
  */
 public function createFile($name, $calendarData = null)
 {
     $calendarData = stream_get_contents($calendarData);
     $supportedComponents = $this->calendarInfo['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set']->getValue();
     Sabre_CalDAV_ICalendarUtil::validateICalendarObject($calendarData, $supportedComponents);
     $this->caldavBackend->createCalendarObject($this->calendarInfo['id'], $name, $calendarData);
 }
Example #7
0
 /**
  * Creates a new file
  *
  * The contents of the new file must be a valid ICalendar string.
  * 
  * @param string $name 
  * @param resource $calendarData 
  * @return void
  */
 public function createFile($name, $calendarData = null)
 {
     $calendarData = stream_get_contents($calendarData);
     // Converting to UTF-8, if needed
     $calendarData = Sabre_DAV_StringUtil::ensureUTF8($calendarData);
     $supportedComponents = $this->calendarInfo['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set'];
     if ($supportedComponents) {
         $supportedComponents = $supportedComponents->getValue();
     } else {
         $supportedComponents = null;
     }
     Sabre_CalDAV_ICalendarUtil::validateICalendarObject($calendarData, $supportedComponents);
     $this->caldavBackend->createCalendarObject($this->calendarInfo['id'], $name, $calendarData);
 }
Example #8
0
 /**
  * Updates the VCard-formatted object
  *
  * @param string $cardData
  * @return void
  */
 public function put($cardData)
 {
     if (get_class($this->_converter) == 'Calendar_Convert_Event_VCalendar_Generic') {
         if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " update by generic client not allowed. See Calendat_Convert_Event_VCalendar_Factory for supported clients.");
         }
         throw new Sabre_DAV_Exception_Forbidden('Update denied for unknow client');
     }
     if (is_resource($cardData)) {
         $cardData = stream_get_contents($cardData);
     }
     // Converting to UTF-8, if needed
     $cardData = Sabre_DAV_StringUtil::ensureUTF8($cardData);
     Sabre_CalDAV_ICalendarUtil::validateICalendarObject($cardData, array('VEVENT', 'VFREEBUSY'));
     $vobject = Calendar_Convert_Event_VCalendar_Abstract::getVcal($cardData);
     foreach ($vobject->children() as $component) {
         if (isset($component->{'X-TINE20-CONTAINER'})) {
             $xContainerId = $component->{'X-TINE20-CONTAINER'};
             break;
         }
     }
     // keep old record for reference
     $recordBeforeUpdate = clone $this->getRecord();
     $event = $this->_converter->toTine20Model($vobject, $this->getRecord());
     // iCal does sends back an old value, because it does not refresh the vcalendar after
     // update. Therefor we must reapply the value of last_modified_time after the convert
     $event->last_modified_time = $recordBeforeUpdate->last_modified_time;
     $currentContainer = Tinebase_Container::getInstance()->getContainerById($this->getRecord()->container_id);
     $ownAttendee = Calendar_Model_Attender::getOwnAttender($this->getRecord()->attendee);
     // event 'belongs' current user -> allow container move
     if ($currentContainer->isPersonalOf(Tinebase_Core::getUser())) {
         $event->container_id = $this->_container->getId();
     } else {
         if (isset($xContainerId)) {
             if ($xContainerId == $currentContainer->getId()) {
                 $event->container_id = $this->_container->getId();
             } else {
                 // @TODO allow organizer to move original cal when he edits the displaycal event?
                 if ($ownAttendee && $this->_container->type == Tinebase_Model_Container::TYPE_PERSONAL) {
                     $ownAttendee->displaycontainer_id = $this->_container->getId();
                 }
             }
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " X-TINE20-CONTAINER not present -> restrict container moves");
             }
             if ($ownAttendee && $this->_container->type == Tinebase_Model_Container::TYPE_PERSONAL) {
                 if ($ownAttendee->displaycontainer_id == $currentContainer->getId()) {
                     $event->container_id = $this->_container->getId();
                 }
                 $ownAttendee->displaycontainer_id = $this->_container->getId();
             }
         }
     }
     self::enforceEventParameters($event);
     // don't allow update of alarms for non organizer if oganizer is Tine 2.0 user
     if ($event->organizer !== Tinebase_Core::getUser()->contact_id) {
         $organizerContact = Addressbook_Controller_Contact::getInstance()->get($event->organizer);
         // reset alarms if organizer is Tine 2.0 user
         if (!empty($organizerContact->account_id)) {
             $this->_resetAlarms($event, $recordBeforeUpdate);
         }
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " " . print_r($event->toArray(), true));
     }
     try {
         $this->_event = Calendar_Controller_MSEventFacade::getInstance()->update($event);
     } catch (Tinebase_Timemachine_Exception_ConcurrencyConflict $ttecc) {
         throw new Sabre_DAV_Exception_PreconditionFailed('An If-Match header was specified, but none of the specified the ETags matched.', 'If-Match');
     }
     // avoid sending headers during unit tests
     if (php_sapi_name() != 'cli') {
         // @todo this belong to DAV_Server, but it currently not supported
         header('ETag: ' . $this->getETag());
     }
 }