示例#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);
     }
 }
 /**
  * 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) {
         // schedule-inbox-URL property
         $scheduleInboxURL = '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}schedule-inbox-URL';
         if (in_array($scheduleInboxURL, $requestedProperties)) {
             $principalId = $node->getName();
             $properties = $node->getProperties(array($scheduleInboxURL));
             if (isset($properties[$scheduleInboxURL])) {
                 $calendarPath = Sabre_CalDAV_Plugin::CALENDAR_ROOT . '/' . $principalId . '/' . $properties[$scheduleInboxURL];
                 unset($requestedProperties[$scheduleInboxURL]);
                 $returnedProperties[200][$scheduleInboxURL] = new Sabre_DAV_Property_Href($calendarPath);
             }
         }
         // schedule-outbox-URL property
         $scheduleOutboxURL = '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}schedule-outbox-URL';
         if (in_array($scheduleOutboxURL, $requestedProperties)) {
             $principalId = $node->getName();
             $properties = $node->getProperties(array($scheduleOutboxURL));
             if (isset($properties[$scheduleOutboxURL])) {
                 $calendarPath = Sabre_CalDAV_Plugin::CALENDAR_ROOT . '/' . $principalId . '/' . $properties[$scheduleOutboxURL];
                 unset($requestedProperties[$scheduleOutboxURL]);
                 $returnedProperties[200][$scheduleOutboxURL] = new Sabre_DAV_Property_Href($calendarPath);
             }
         }
     }
 }
 /**
  * Adds all ownCloud-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 OC_Connector_Sabre_Node) {
         $fileid_propertyname = '{' . self::NS_OWNCLOUD . '}id';
         if (array_search($fileid_propertyname, $requestedProperties)) {
             unset($requestedProperties[array_search($fileid_propertyname, $requestedProperties)]);
         }
         /** @var $node OC_Connector_Sabre_Node */
         $fileId = $node->getFileId();
         if (!is_null($fileId)) {
             $returnedProperties[200][$fileid_propertyname] = $fileId;
         }
     }
 }
示例#4
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 || $node instanceof Sabre_CalDAV_UserCalendars) {
         // schedule-inbox-URL property
         $inboxProp = '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}schedule-inbox-URL';
         if (in_array($inboxProp, $requestedProperties)) {
             $principalId = $node->getName();
             $inboxPath = Sabre_CalDAV_Plugin::CALENDAR_ROOT . '/' . $principalId . '/schedule-inbox';
             unset($requestedProperties[$inboxProp]);
             $returnedProperties[200][$inboxProp] = new Sabre_DAV_Property_Href($inboxPath);
         }
         // schedule-outbox-URL property
         $outboxProp = '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}schedule-outbox-URL';
         if (in_array($outboxProp, $requestedProperties)) {
             $principalId = $node->getName();
             $outboxPath = Sabre_CalDAV_Plugin::CALENDAR_ROOT . '/' . $principalId . '/schedule-outbox';
             unset($requestedProperties[$outboxProp]);
             $returnedProperties[200][$outboxProp] = new Sabre_DAV_Property_Href($outboxPath);
         }
     }
 }
示例#5
0
 /**
  * This event is triggered when a PROPPATCH method is executed
  *
  * @param array $mutations
  * @param array $result
  * @param Sabre_DAV_INode $node
  * @return void
  */
 public function updateProperties(&$mutations, &$result, $node)
 {
     if (!$node instanceof Sabre_CardDAV_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 Sabre_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;
 }
 /**
  * Adds a new childnode to this collection 
  * 
  * @param Sabre_DAV_INode $child 
  * @return void
  */
 public function addChild(Sabre_DAV_INode $child)
 {
     $this->children[$child->getName()] = $child;
 }
 /**
  * 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 Sabre_DAV_INode $node
  * @return void
  */
 public function updateProperties(array &$mutations, array &$result, Sabre_DAV_INode $node)
 {
     if (!$node instanceof Sabre_CalDAV_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('{' . Sabre_CalDAV_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']);
 }
示例#8
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);
         }
     }
 }
示例#9
0
 /**
  * This method intercepts PROPPATCH methods and make sure the 
  * group-member-set is updated correctly. 
  * 
  * @param array $propertyDelta 
  * @param array $result 
  * @param Sabre_DAV_INode $node 
  * @return void
  */
 public function updateProperties(&$propertyDelta, &$result, Sabre_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 Sabre_DAV_Property_HrefList) {
         $memberSet = $propertyDelta['{DAV:}group-member-set']->getHrefs();
     } else {
         throw new Sabre_DAV_Exception('The group-member-set property MUST be an instance of Sabre_DAV_Property_HrefList or null');
     }
     if (!$node instanceof Sabre_DAVACL_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);
     $result[200]['{DAV:}group-member-set'] = null;
     unset($propertyDelta['{DAV:}group-member-set']);
 }
 /**
  * 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);
         }
     }
 }