示例#1
0
文件: Tree.php 项目: jtietema/Fizzy
 /**
  * copyNode 
  * 
  * @param Sabre_DAV_INode $source 
  * @param Sabre_DAV_ICollection $destination 
  * @return void
  */
 protected function copyNode(Sabre_DAV_INode $source, Sabre_DAV_ICollection $destinationParent, $destinationName = null)
 {
     if (!$destinationName) {
         $destinationName = $source->getName();
     }
     if ($source instanceof Sabre_DAV_IFile) {
         $data = $source->get();
         // If the body was a string, we need to convert it to a stream
         if (is_string($data)) {
             $stream = fopen('php://temp', 'r+');
             fwrite($stream, $data);
             rewind($stream);
             $data = $stream;
         }
         $destinationParent->createFile($destinationName, $data);
         $destination = $destinationParent->getChild($destinationName);
     } elseif ($source instanceof Sabre_DAV_ICollection) {
         $destinationParent->createDirectory($destinationName);
         $destination = $destinationParent->getChild($destinationName);
         foreach ($source->getChildren() as $child) {
             $this->copyNode($child, $destination);
         }
     }
     if ($source instanceof Sabre_DAV_IProperties && $destination instanceof Sabre_DAV_IProperties) {
         $props = $source->getProperties(array());
         $destination->updateProperties($props);
     }
 }
示例#2
0
 /**
  * Adds all CardDAV-specific properties
  *
  * @param string $path
  * @param Sabre_DAV_INode $node
  * @param array $requestedProperties
  * @param array $returnedProperties
  * @return void
  */
 public function beforeGetProperties($path, Sabre_DAV_INode $node, array &$requestedProperties, array &$returnedProperties)
 {
     if ($node instanceof Sabre_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 Sabre_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 Sabre_DAV_Property_HrefList($this->directories);
         }
     }
     if ($node instanceof Sabre_CardDAV_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);
             }
             // Taking out \r to not screw up the xml output
             $returnedProperties[200][$addressDataProp] = str_replace("\r", "", $val);
         }
     }
     if ($node instanceof Sabre_CardDAV_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 Sabre_DAV_Property_Href($props['{http://sabredav.org/ns}vcard-url']);
                 $pos = array_search($meCardProp, $requestedProperties);
                 unset($requestedProperties[$pos]);
             }
         }
     }
 }
示例#3
0
 /**
  * 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 Sabre_DAV_INode $node
  * @param array $requestedProperties
  * @param array $returnedProperties
  * @return void
  */
 public function beforeGetProperties($path, Sabre_DAV_INode $node, &$requestedProperties, &$returnedProperties)
 {
     if ($node instanceof Sabre_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[$calHome]);
             $returnedProperties[200][$calHome] = new Sabre_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[$scheduleProp]);
             $returnedProperties[200][$scheduleProp] = new Sabre_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() . $node->getPrincipalUrl();
             unset($requestedProperties[$calProp]);
             $returnedProperties[200][$calProp] = new Sabre_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)) {
             $membership = $node->getGroupMembership();
             $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 Sabre_CalDAV_Principal_ProxyRead) {
                     list($readList[]) = Sabre_DAV_URLUtil::splitPath($group);
                 }
                 if ($groupNode instanceof Sabre_CalDAV_Principal_ProxyWrite) {
                     list($writeList[]) = Sabre_DAV_URLUtil::splitPath($group);
                 }
             }
             if (in_array($propRead, $requestedProperties)) {
                 unset($requestedProperties[$propRead]);
                 $returnedProperties[200][$propRead] = new Sabre_DAV_Property_HrefList($readList);
             }
             if (in_array($propWrite, $requestedProperties)) {
                 unset($requestedProperties[$propWrite]);
                 $returnedProperties[200][$propWrite] = new Sabre_DAV_Property_HrefList($writeList);
             }
         }
     }
     // instanceof IPrincipal
     if ($node instanceof Sabre_CalDAV_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 = '{' . Sabre_CalDAV_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);
         }
     }
 }