コード例 #1
0
ファイル: Plugin.php プロジェクト: helsaba/rainloop-webmail
 /**
  * beforeGetProperties
  *
  * This method handler is invoked before any after properties for a
  * resource are fetched. This allows us to add in any CalDAV specific
  * properties.
  *
  * @param string $path
  * @param DAV\INode $node
  * @param array $requestedProperties
  * @param array $returnedProperties
  * @return void
  */
 public function beforeGetProperties($path, DAV\INode $node, &$requestedProperties, &$returnedProperties)
 {
     if ($node instanceof DAVACL\IPrincipal) {
         // calendar-home-set property
         $calHome = '{' . self::NS_CALDAV . '}calendar-home-set';
         if (in_array($calHome, $requestedProperties)) {
             $principalId = $node->getName();
             $calendarHomePath = self::CALENDAR_ROOT . '/' . $principalId . '/';
             unset($requestedProperties[array_search($calHome, $requestedProperties)]);
             $returnedProperties[200][$calHome] = new DAV\Property\Href($calendarHomePath);
         }
         // schedule-outbox-URL property
         $scheduleProp = '{' . self::NS_CALDAV . '}schedule-outbox-URL';
         if (in_array($scheduleProp, $requestedProperties)) {
             $principalId = $node->getName();
             $outboxPath = self::CALENDAR_ROOT . '/' . $principalId . '/outbox';
             unset($requestedProperties[array_search($scheduleProp, $requestedProperties)]);
             $returnedProperties[200][$scheduleProp] = new DAV\Property\Href($outboxPath);
         }
         // calendar-user-address-set property
         $calProp = '{' . self::NS_CALDAV . '}calendar-user-address-set';
         if (in_array($calProp, $requestedProperties)) {
             $addresses = $node->getAlternateUriSet();
             $addresses[] = $this->server->getBaseUri() . DAV\URLUtil::encodePath($node->getPrincipalUrl() . '/');
             unset($requestedProperties[array_search($calProp, $requestedProperties)]);
             $returnedProperties[200][$calProp] = new DAV\Property\HrefList($addresses, false);
         }
         // These two properties are shortcuts for ical to easily find
         // other principals this principal has access to.
         $propRead = '{' . self::NS_CALENDARSERVER . '}calendar-proxy-read-for';
         $propWrite = '{' . self::NS_CALENDARSERVER . '}calendar-proxy-write-for';
         if (in_array($propRead, $requestedProperties) || in_array($propWrite, $requestedProperties)) {
             $aclPlugin = $this->server->getPlugin('acl');
             $membership = $aclPlugin->getPrincipalMembership($path);
             $readList = array();
             $writeList = array();
             foreach ($membership as $group) {
                 $groupNode = $this->server->tree->getNodeForPath($group);
                 // If the node is either ap proxy-read or proxy-write
                 // group, we grab the parent principal and add it to the
                 // list.
                 if ($groupNode instanceof Principal\IProxyRead) {
                     list($readList[]) = DAV\URLUtil::splitPath($group);
                 }
                 if ($groupNode instanceof Principal\IProxyWrite) {
                     list($writeList[]) = DAV\URLUtil::splitPath($group);
                 }
             }
             if (in_array($propRead, $requestedProperties)) {
                 unset($requestedProperties[$propRead]);
                 $returnedProperties[200][$propRead] = new DAV\Property\HrefList($readList);
             }
             if (in_array($propWrite, $requestedProperties)) {
                 unset($requestedProperties[$propWrite]);
                 $returnedProperties[200][$propWrite] = new DAV\Property\HrefList($writeList);
             }
         }
         // notification-URL property
         $notificationUrl = '{' . self::NS_CALENDARSERVER . '}notification-URL';
         if (($index = array_search($notificationUrl, $requestedProperties)) !== false) {
             $principalId = $node->getName();
             $calendarHomePath = 'calendars/' . $principalId . '/notifications/';
             unset($requestedProperties[$index]);
             $returnedProperties[200][$notificationUrl] = new DAV\Property\Href($calendarHomePath);
         }
     }
     // instanceof IPrincipal
     if ($node instanceof Notifications\INode) {
         $propertyName = '{' . self::NS_CALENDARSERVER . '}notificationtype';
         if (($index = array_search($propertyName, $requestedProperties)) !== false) {
             $returnedProperties[200][$propertyName] = $node->getNotificationType();
             unset($requestedProperties[$index]);
         }
     }
     // instanceof Notifications_INode
     if ($node instanceof ICalendarObject) {
         // The calendar-data property is not supposed to be a 'real'
         // property, but in large chunks of the spec it does act as such.
         // Therefore we simply expose it as a property.
         $calDataProp = '{' . Plugin::NS_CALDAV . '}calendar-data';
         if (in_array($calDataProp, $requestedProperties)) {
             unset($requestedProperties[$calDataProp]);
             $val = $node->get();
             if (is_resource($val)) {
                 $val = stream_get_contents($val);
             }
             // Taking out \r to not screw up the xml output
             $returnedProperties[200][$calDataProp] = str_replace("\r", "", $val);
         }
     }
 }
コード例 #2
0
ファイル: Plugin.php プロジェクト: helsaba/rainloop-webmail
 /**
  * This event is triggered when a PROPPATCH method is executed
  *
  * @param array $mutations
  * @param array $result
  * @param DAV\INode $node
  * @return bool
  */
 public function updateProperties(&$mutations, &$result, DAV\INode $node)
 {
     if (!$node instanceof UserAddressBooks) {
         return true;
     }
     $meCard = '{http://calendarserver.org/ns/}me-card';
     // The only property we care about
     if (!isset($mutations[$meCard])) {
         return true;
     }
     $value = $mutations[$meCard];
     unset($mutations[$meCard]);
     if ($value instanceof DAV\Property\IHref) {
         $value = $value->getHref();
         $value = $this->server->calculateUri($value);
     } elseif (!is_null($value)) {
         $result[400][$meCard] = null;
         return false;
     }
     $innerResult = $this->server->updateProperties($node->getOwner(), array('{http://sabredav.org/ns}vcard-url' => $value));
     $closureResult = false;
     foreach ($innerResult as $status => $props) {
         if (is_array($props) && array_key_exists('{http://sabredav.org/ns}vcard-url', $props)) {
             $result[$status][$meCard] = null;
             $closureResult = $status >= 200 && $status < 300;
         }
     }
     return $result;
 }
コード例 #3
0
ファイル: Plugin.php プロジェクト: helsaba/rainloop-webmail
 /**
  * This method intercepts PROPPATCH methods and make sure the
  * group-member-set is updated correctly.
  *
  * @param array $propertyDelta
  * @param array $result
  * @param DAV\INode $node
  * @return bool
  */
 public function updateProperties(&$propertyDelta, &$result, DAV\INode $node)
 {
     if (!array_key_exists('{DAV:}group-member-set', $propertyDelta)) {
         return;
     }
     if (is_null($propertyDelta['{DAV:}group-member-set'])) {
         $memberSet = array();
     } elseif ($propertyDelta['{DAV:}group-member-set'] instanceof DAV\Property\HrefList) {
         $memberSet = array_map(array($this->server, 'calculateUri'), $propertyDelta['{DAV:}group-member-set']->getHrefs());
     } else {
         throw new DAV\Exception('The group-member-set property MUST be an instance of SabreForRainLoop\\DAV\\Property\\HrefList or null');
     }
     if (!$node instanceof IPrincipal) {
         $result[403]['{DAV:}group-member-set'] = null;
         unset($propertyDelta['{DAV:}group-member-set']);
         // Returning false will stop the updateProperties process
         return false;
     }
     $node->setGroupMemberSet($memberSet);
     // We must also clear our cache, just in case
     $this->principalMembershipCache = array();
     $result[200]['{DAV:}group-member-set'] = null;
     unset($propertyDelta['{DAV:}group-member-set']);
 }
コード例 #4
0
 /**
  * This method is trigged when a user attempts to update a node's
  * properties.
  *
  * A previous draft of the sharing spec stated that it was possible to use
  * PROPPATCH to remove 'shared-owner' from the resourcetype, thus unsharing
  * the calendar.
  *
  * Even though this is no longer in the current spec, we keep this around
  * because OS X 10.7 may still make use of this feature.
  *
  * @param array $mutations
  * @param array $result
  * @param DAV\INode $node
  * @return void
  */
 public function updateProperties(array &$mutations, array &$result, DAV\INode $node)
 {
     if (!$node instanceof IShareableCalendar) {
         return;
     }
     if (!isset($mutations['{DAV:}resourcetype'])) {
         return;
     }
     // Only doing something if shared-owner is indeed not in the list.
     if ($mutations['{DAV:}resourcetype']->is('{' . Plugin::NS_CALENDARSERVER . '}shared-owner')) {
         return;
     }
     $shares = $node->getShares();
     $remove = array();
     foreach ($shares as $share) {
         $remove[] = $share['href'];
     }
     $node->updateShares(array(), $remove);
     // We're marking this update as 200 OK
     $result[200]['{DAV:}resourcetype'] = null;
     // Removing it from the mutations list
     unset($mutations['{DAV:}resourcetype']);
 }