コード例 #1
0
ファイル: Plugin.php プロジェクト: pkdevboxy/webmail-lite
 /**
  * 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;
 }
コード例 #2
0
ファイル: Plugin.php プロジェクト: samj1912/repo
 /**
  * Adds all CardDAV-specific properties
  *
  * @param DAV\PropFind $propFind
  * @param DAV\INode $node
  * @return void
  */
 function propFindEarly(DAV\PropFind $propFind, DAV\INode $node)
 {
     $ns = '{' . self::NS_CARDDAV . '}';
     if ($node instanceof IAddressBook) {
         $propFind->handle($ns . 'max-resource-size', $this->maxResourceSize);
         $propFind->handle($ns . 'supported-address-data', function () {
             return new Property\SupportedAddressData();
         });
         $propFind->handle($ns . 'supported-collation-set', function () {
             return new Property\SupportedCollationSet();
         });
     }
     if ($node instanceof DAVACL\IPrincipal) {
         $path = $propFind->getPath();
         $propFind->handle('{' . self::NS_CARDDAV . '}addressbook-home-set', function () use($path) {
             return new DAV\Property\Href($this->getAddressBookHomeForPrincipal($path) . '/');
         });
         if ($this->directories) {
             $propFind->handle('{' . self::NS_CARDDAV . '}directory-gateway', function () {
                 return 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.
         $propFind->handle('{' . self::NS_CARDDAV . '}address-data', function () use($node) {
             $val = $node->get();
             if (is_resource($val)) {
                 $val = stream_get_contents($val);
             }
             return $val;
         });
     }
     if ($node instanceof UserAddressBooks) {
         $propFind->handle('{http://calendarserver.org/ns/}me-card', function () use($node) {
             $props = $this->server->getProperties($node->getOwner(), ['{http://sabredav.org/ns}vcard-url']);
             if (isset($props['{http://sabredav.org/ns}vcard-url'])) {
                 return new DAV\Property\Href($props['{http://sabredav.org/ns}vcard-url']);
             }
         });
     }
 }
コード例 #3
0
 /**
  * This event is triggered when properties are requested for a certain
  * node.
  *
  * This allows us to inject any properties early.
  *
  * @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 IShareableCalendar) {
         if (($index = array_search('{' . Plugin::NS_CALENDARSERVER . '}invite', $requestedProperties)) !== false) {
             unset($requestedProperties[$index]);
             $returnedProperties[200]['{' . Plugin::NS_CALENDARSERVER . '}invite'] = new Property\Invite($node->getShares());
         }
     }
     if ($node instanceof ISharedCalendar) {
         if (($index = array_search('{' . Plugin::NS_CALENDARSERVER . '}shared-url', $requestedProperties)) !== false) {
             unset($requestedProperties[$index]);
             $returnedProperties[200]['{' . Plugin::NS_CALENDARSERVER . '}shared-url'] = new DAV\Property\Href($node->getSharedUrl());
         }
         // The 'invite' property is slightly different for the 'shared'
         // instance of the calendar, as it also contains the owner
         // information.
         if (($index = array_search('{' . Plugin::NS_CALENDARSERVER . '}invite', $requestedProperties)) !== false) {
             unset($requestedProperties[$index]);
             // Fetching owner information
             $props = $this->server->getPropertiesForPath($node->getOwner(), array('{http://sabredav.org/ns}email-address', '{DAV:}displayname'), 1);
             $ownerInfo = array('href' => $node->getOwner());
             if (isset($props[0][200])) {
                 // We're mapping the internal webdav properties to the
                 // elements caldav-sharing expects.
                 if (isset($props[0][200]['{http://sabredav.org/ns}email-address'])) {
                     $ownerInfo['href'] = 'mailto:' . $props[0][200]['{http://sabredav.org/ns}email-address'];
                 }
                 if (isset($props[0][200]['{DAV:}displayname'])) {
                     $ownerInfo['commonName'] = $props[0][200]['{DAV:}displayname'];
                 }
             }
             $returnedProperties[200]['{' . Plugin::NS_CALENDARSERVER . '}invite'] = new Property\Invite($node->getShares(), $ownerInfo);
         }
     }
 }
コード例 #4
0
ファイル: SharingPlugin.php プロジェクト: pageer/sabre-dav
 /**
  * This event is triggered when properties are requested for a certain
  * node.
  *
  * This allows us to inject any properties early.
  *
  * @param DAV\PropFind $propFind
  * @param DAV\INode $node
  * @return void
  */
 function propFindEarly(DAV\PropFind $propFind, DAV\INode $node)
 {
     if ($node instanceof IShareableCalendar) {
         $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}invite', function () use($node) {
             return new Xml\Property\Invite($node->getShares());
         });
     }
     if ($node instanceof ISharedCalendar) {
         $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}shared-url', function () use($node) {
             return new Href($node->getSharedUrl());
         });
         $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}invite', function () use($node) {
             // Fetching owner information
             $props = $this->server->getPropertiesForPath($node->getOwner(), ['{http://sabredav.org/ns}email-address', '{DAV:}displayname'], 0);
             $ownerInfo = ['href' => $node->getOwner()];
             if (isset($props[0][200])) {
                 // We're mapping the internal webdav properties to the
                 // elements caldav-sharing expects.
                 if (isset($props[0][200]['{http://sabredav.org/ns}email-address'])) {
                     $ownerInfo['href'] = 'mailto:' . $props[0][200]['{http://sabredav.org/ns}email-address'];
                 }
                 if (isset($props[0][200]['{DAV:}displayname'])) {
                     $ownerInfo['commonName'] = $props[0][200]['{DAV:}displayname'];
                 }
             }
             return new Xml\Property\Invite($node->getShares(), $ownerInfo);
         });
     }
 }
コード例 #5
0
ファイル: filesplugin.php プロジェクト: robinkanters/core
 /**
  * Adds all ownCloud-specific properties
  *
  * @param PropFind $propFind
  * @param \Sabre\DAV\INode $node
  * @return void
  */
 public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
 {
     if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
         $propFind->handle(self::FILEID_PROPERTYNAME, function () use($node) {
             return $node->getFileId();
         });
         $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function () use($node) {
             return $node->getInternalFileId();
         });
         $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function () use($node) {
             $perms = $node->getDavPermissions();
             if ($this->isPublic) {
                 // remove mount information
                 $perms = str_replace(['S', 'M'], '', $perms);
             }
             return $perms;
         });
         $propFind->handle(self::GETETAG_PROPERTYNAME, function () use($node) {
             return $node->getEtag();
         });
     }
     if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
         $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function () use($node) {
             /** @var $node \OCA\DAV\Connector\Sabre\File */
             $directDownloadUrl = $node->getDirectDownload();
             if (isset($directDownloadUrl['url'])) {
                 return $directDownloadUrl['url'];
             }
             return false;
         });
     }
     if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
         $propFind->handle(self::SIZE_PROPERTYNAME, function () use($node) {
             return $node->getSize();
         });
     }
     $propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use($node) {
         $owner = $node->getOwner();
         return $owner->getUID();
     });
     $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use($node) {
         $owner = $node->getOwner();
         $displayName = $owner->getDisplayName();
         return $displayName;
     });
 }
コード例 #6
0
ファイル: FilesPlugin.php プロジェクト: GitHubUser4234/core
 /**
  * Adds all ownCloud-specific properties
  *
  * @param PropFind $propFind
  * @param \Sabre\DAV\INode $node
  * @return void
  */
 public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
 {
     $httpRequest = $this->server->httpRequest;
     if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
         $propFind->handle(self::FILEID_PROPERTYNAME, function () use($node) {
             return $node->getFileId();
         });
         $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function () use($node) {
             return $node->getInternalFileId();
         });
         $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function () use($node) {
             $perms = $node->getDavPermissions();
             if ($this->isPublic) {
                 // remove mount information
                 $perms = str_replace(['S', 'M'], '', $perms);
             }
             return $perms;
         });
         $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function () use($node, $httpRequest) {
             return $node->getSharePermissions($httpRequest->getRawServerValue('PHP_AUTH_USER'));
         });
         $propFind->handle(self::GETETAG_PROPERTYNAME, function () use($node) {
             return $node->getETag();
         });
         $propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use($node) {
             $owner = $node->getOwner();
             return $owner->getUID();
         });
         $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use($node) {
             $owner = $node->getOwner();
             $displayName = $owner->getDisplayName();
             return $displayName;
         });
         $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () use($node) {
             if ($node->getPath() === '/') {
                 return $this->config->getSystemValue('data-fingerprint', '');
             }
         });
     }
     if ($node instanceof \OCA\DAV\Files\FilesHome) {
         $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () use($node) {
             return $this->config->getSystemValue('data-fingerprint', '');
         });
     }
     if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
         $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function () use($node) {
             /** @var $node \OCA\DAV\Connector\Sabre\File */
             try {
                 $directDownloadUrl = $node->getDirectDownload();
                 if (isset($directDownloadUrl['url'])) {
                     return $directDownloadUrl['url'];
                 }
             } catch (StorageNotAvailableException $e) {
                 return false;
             } catch (ForbiddenException $e) {
                 return false;
             }
             return false;
         });
         $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function () use($node) {
             $checksum = $node->getChecksum();
             if ($checksum === NULL || $checksum === '') {
                 return null;
             }
             return new ChecksumList($checksum);
         });
     }
     if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
         $propFind->handle(self::SIZE_PROPERTYNAME, function () use($node) {
             return $node->getSize();
         });
     }
 }
コード例 #7
0
ファイル: Plugin.php プロジェクト: mattes/sabre-dav
 /**
  * This method is called before a new node is created.
  *
  * @param string $path path to new object.
  * @param string|resource $data Contents of new object.
  * @param \Sabre\DAV\INode $parentNode Parent object
  * @param bool $modified Wether or not the item's data was modified/
  * @return bool|null
  */
 function beforeCreateFile($path, &$data, $parentNode, &$modified)
 {
     if (!$parentNode instanceof ICalendar) {
         return;
     }
     if (!$this->scheduleReply($this->server->httpRequest)) {
         return;
     }
     // It's a calendar, so the contents are most likely an iCalendar
     // object. It's time to start processing this.
     //
     // This step also ensures that $data is re-propagated with a string
     // version of the object.
     if (is_resource($data)) {
         $data = stream_get_contents($data);
     }
     $vObj = Reader::read($data);
     $addresses = $this->getAddressesForPrincipal($parentNode->getOwner());
     $this->processICalendarChange(null, $vObj, $addresses);
     // After all this exciting action we set $data to the updated event
     // that contains all the new status information (if any).
     $newData = $vObj->serialize();
     if ($newData !== $data) {
         $data = $newData;
         // Setting $modified tells sabredav that the object has changed,
         // and that no ETag must be sent back.
         $modified = true;
     }
 }