예제 #1
0
 /**
  * Adds all CardDAV-specific properties
  *
  * @param string $path
  * @param DAV\INode $node
  * @param array $requestedProperties
  * @param array $returnedProperties
  * @return void
  */
 public function beforeGetProperties($path, DAV\INode $node, array &$requestedProperties, array &$returnedProperties)
 {
     if ($node instanceof DAVACL\IPrincipal) {
         // calendar-home-set property
         $addHome = '{' . self::NS_CARDDAV . '}addressbook-home-set';
         if (in_array($addHome, $requestedProperties)) {
             $principalId = $node->getName();
             $addressbookHomePath = self::ADDRESSBOOK_ROOT . '/' . $principalId . '/';
             unset($requestedProperties[array_search($addHome, $requestedProperties)]);
             $returnedProperties[200][$addHome] = new DAV\Property\Href($addressbookHomePath);
         }
         $directories = '{' . self::NS_CARDDAV . '}directory-gateway';
         if ($this->directories && in_array($directories, $requestedProperties)) {
             unset($requestedProperties[array_search($directories, $requestedProperties)]);
             $returnedProperties[200][$directories] = new DAV\Property\HrefList($this->directories);
         }
     }
     if ($node instanceof ICard) {
         // The address-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.
         $addressDataProp = '{' . self::NS_CARDDAV . '}address-data';
         if (in_array($addressDataProp, $requestedProperties)) {
             unset($requestedProperties[$addressDataProp]);
             $val = $node->get();
             if (is_resource($val)) {
                 $val = stream_get_contents($val);
             }
             $returnedProperties[200][$addressDataProp] = $val;
         }
     }
     if ($node instanceof UserAddressBooks) {
         $meCardProp = '{http://calendarserver.org/ns/}me-card';
         if (in_array($meCardProp, $requestedProperties)) {
             $props = $this->server->getProperties($node->getOwner(), array('{http://sabredav.org/ns}vcard-url'));
             if (isset($props['{http://sabredav.org/ns}vcard-url'])) {
                 $returnedProperties[200][$meCardProp] = new DAV\Property\Href($props['{http://sabredav.org/ns}vcard-url']);
                 $pos = array_search($meCardProp, $requestedProperties);
                 unset($requestedProperties[$pos]);
             }
         }
     }
 }