public function Propfind(&$arResources, $siteId, $account, $arPath, $id = null) { $collectionId = $this->GetCollectionId($siteId, $account, $arPath); if ($collectionId == null) { return '404 Not Found'; } $request = $this->groupdav->GetRequest(); $currentPrincipal = $request->GetPrincipal(); if (!$this->CheckPrivileges('DAV:read', $currentPrincipal, $collectionId)) { return '403 Forbidden'; } $requestDocument = $request->GetXmlDocument(); $path = CDav::CheckIfRightSlashAdded($request->GetPath()); $bAddressData = count($requestDocument->GetPath('/*/DAV::allprop')) > 0; if (!$bAddressData || $requestDocument->GetRoot()->GetXmlns() != CDavGroupDav::CARDDAV) { $arProp = $requestDocument->GetPath('/*/DAV::prop/*'); foreach ($arProp as $prop) { if ($prop->GetTag() == 'address-data') { $bAddressData = true; break; } } } $arFilter = array(); if (($id || $requestDocument->GetRoot() && $requestDocument->GetRoot()->GetTag() != 'propfind') && !$this->PrepareFilters($arFilter, $requestDocument, $id)) { return false; } $arContacts = CDavAccount::GetAddressbookContactsList($collectionId, $arFilter); foreach ($arContacts as $contact) { $resource = new CDavResource($path . $this->GetPath($contact)); $resource->AddProperty('getetag', $this->GetETag($collectionId, $contact)); $resource->AddProperty('getcontenttype', 'text/vcard'); $resource->AddProperty('getlastmodified', MakeTimeStamp($contact['TIMESTAMP_X'])); $resource->AddProperty('resourcetype', ''); if ($bAddressData) { $content = $this->GetVCardContent($contact); $resource->AddProperty('getcontentlength', strlen($content)); $resource->AddProperty('address-data', $content, CDavGroupDav::CARDDAV); } else { $resource->AddProperty('getcontentlength', ""); } $arResources[] = $resource; } return true; }
public function Propfind(&$arResources, $siteId, $account, $arPath, $id = null) { $calendarId = $this->GetCalendarId($siteId, $account, $arPath); if ($calendarId == null) { return '404 Not Found'; } $request = $this->groupdav->GetRequest(); $currentPrincipal = $request->GetPrincipal(); if (!$this->CheckPrivileges('urn:ietf:params:xml:ns:caldav:read-free-busy', $currentPrincipal, $calendarId)) { return '403 Forbidden'; } $requestDocument = $request->GetXmlDocument(); $path = CDav::CheckIfRightSlashAdded($request->GetPath()); if (!isset($calendarId[0], $calendarId[1])) { $arCalendarList = CCalendar::GetCalendarList($calendarId, array('skipExchange' => true)); foreach ($arCalendarList as $calendar) { $resource = new CDavResource($path . $calendar["ID"] . "/"); $this->GetCalendarProperties($resource, $siteId, $account, array($calendar["ID"]), 0); $arResources[] = $resource; } return true; } $bCalendarData = count($requestDocument->GetPath('/*/DAV::allprop')) > 0; if (!$bCalendarData || $requestDocument->GetRoot()->GetXmlns() != CDavGroupDav::CALDAV) { $arProp = $requestDocument->GetPath('/*/DAV::prop/*'); foreach ($arProp as $prop) { if ($prop->GetTag() == 'calendar-data') { $bCalendarData = true; break; } } } $arFilter = array('DATE_START' => ConvertTimeStamp(time() - 93 * 24 * 3600, "FULL"), 'DATE_END' => ConvertTimeStamp(time() + 365 * 24 * 3600, "FULL")); if (($id || $requestDocument->GetRoot() && $requestDocument->GetRoot()->GetTag() != 'propfind') && !$this->PrepareFilters($arFilter, $requestDocument, $id)) { return false; } if ($calendarId[0] > 0) { $arEvents = CCalendar::GetDavCalendarEventsList($calendarId, $arFilter); foreach ($arEvents as $event) { if (!$this->CheckPrivileges('DAV::read', $currentPrincipal, $calendarId)) { $this->ClearPrivateData($event); } $resource = new CDavResource($path . $this->GetPath($event)); $resource->AddProperty('getetag', $this->GetETag($calendarId, $event)); $resource->AddProperty('getcontenttype', $request->GetAgent() != 'kde' ? 'text/calendar; charset=utf-8; component=VEVENT' : 'text/calendar'); $resource->AddProperty('getlastmodified', MakeTimeStamp($event['TIMESTAMP_X'])); $resource->AddProperty('resourcetype', ''); if ($bCalendarData) { $content = $this->GetICalContent($event, $siteId); $resource->AddProperty('getcontentlength', strlen($content)); $resource->AddProperty('calendar-data', $content, CDavGroupDav::CALDAV); } else { $resource->AddProperty('getcontentlength', ""); } $arResources[] = $resource; } } return true; }
private function ConvertPropertiesToArray(array $props) { $request = $this->request; $response = $this->response; $arr = array(); foreach ($props as $prop) { switch ($prop['xmlns']) { case 'DAV:': $xmlns = 'DAV'; break; case self::CALDAV: $xmlns = 'CalDAV'; break; case self::CARDDAV: $xmlns = 'CardDAV'; break; case self::GROUPDAV: $xmlns = 'GroupDAV'; break; default: $xmlns = $prop['xmlns']; } $xmlnsDefs = ''; $xmlnsHash = array($prop['xmlns'] => $xmlns, 'DAV:' => 'D'); $arr[$xmlns . ':' . $prop['tagname']] = is_array($prop['content']) ? CDavResource::EncodeHierarchicalProp($prop['content'], $prop['xmlns'], $xmlnsDefs, $xmlnsHash, $response, $request) : $prop['content']; } return $arr; }
protected function AddGroup(&$arResources, $siteId, $arGroup) { $request = $this->groupdav->GetRequest(); $resource = new CDavResource('/principals/group/' . $arGroup['CODE'] . '/'); $resource->AddProperty('displayname', $arGroup["NAME"]); $resource->AddProperty('getetag', $this->GetETag($arGroup)); $resource->AddProperty('resourcetype', array(array('principal', '', CDavGroupDav::DAV))); $resource->AddProperty('alternate-URI-set', ''); $resource->AddProperty('calendar-home-set', array(array('href', $request->GetBaseUri() . "/" . $siteId . "/" . $arGroup["CODE"] . "/calendar/")), CDavGroupDav::CALDAV); $resource->AddProperty('record-type', 'group', CDavGroupDav::CALENDARSERVER); $resource->AddProperty('calendar-user-type', 'GROUP', CDavGroupDav::CALDAV); //$resource->AddProperty('group-member-set', $memberships); $arResources[] = $resource; }
protected function PROPPATCHWrapper() { /** @var CDavRequest $request */ $request = $this->request; $response = $this->response; if ($this->CheckLockStatus($request->GetPath())) { try { $requestDocument = $request->GetXmlDocument(); } catch (CDavXMLParsingException $e) { $response->GenerateError("400 Error", $e->getMessage()); return; } catch (Exception $e) { $response->SetHttpStatus("400 Error"); return; } $arResources = array(); $responseDescr = $this->PROPPATCH($arResources); $response->SetHttpStatus("207 Multi-Status"); $response->AddHeader('Content-Type: text/xml; charset="utf-8"'); $response->AddLine("<D:multistatus xmlns:D=\"DAV:\">"); foreach ($arResources as $resource) { /** @var CDavResource $resource */ $arResourceProps = $resource->GetProperties(); $xmlnsHash = array('DAV:' => 'D'); $xmlnsDefs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"'; $response->AddLine(" <D:response %s>", $xmlnsDefs); $href = $this->UrlEncode(rtrim($request->GetBaseUri(), '/') . "/" . ltrim($resource->GetPath(), '/')); $response->AddLine(" <D:href>%s</D:href>", $href); foreach ($arResourceProps as &$prop) { $response->AddLine(" <D:propstat>"); $response->AddLine(" <D:prop>"); CDavResource::RenderProperty($prop, $xmlnsHash, $response, $request); $response->AddLine(" </D:prop>"); $response->AddLine(" <D:status>HTTP/1.1 " . $prop['status'] . "</D:status>"); $response->AddLine(" </D:propstat>"); } if ($responseDescr) { echo "\t<D:responsedescription>" . $response->Encode(htmlspecialcharsbx($responseDescr)) . "</D:responsedescription>\n"; } $response->AddLine(" </D:response>"); } $response->AddLine("</D:multistatus>"); } else { $response->SetHttpStatus('423 Locked'); } }
/** * @param $path * @param File|Folder|Object $object * @return CDavResource */ protected function getResourceByObject($path, BaseObject $object) { $isFolder = $object instanceof Folder; $resource = new CDavResource($path . ($isFolder && substr($path, -1, 1) != "/" ? "/" : "")); $resource->AddProperty('name', $object->getName()); if ($object instanceof File) { $resource->AddProperty('getcontentlength', $object->getSize()); } $resource->AddProperty('creationdate', $object->getCreateTime()->getTimestamp()); $resource->AddProperty('getlastmodified', $object->getUpdateTime()->getTimestamp()); $resource->AddProperty('iscollection', $isFolder ? '1' : '0'); if ($isFolder) { $resource->AddProperty('resourcetype', array('collection', '')); $resource->AddProperty('getcontenttype', 'httpd/unix-directory'); } else { $resource->AddProperty('getcontenttype', ''); $resource->AddProperty('isreadonly', ''); $resource->AddProperty('ishidden', ''); $resource->AddProperty('resourcetype', ''); } $resource->AddProperty("supportedlock", "<D:lockentry><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry><D:lockentry><D:lockscope><D:shared/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry>"); return $resource; }
/** * @param $path * @param File|Folder|Object $object * @return CDavResource */ protected function getResourceByObject($path, BaseObject $object) { $isFolder = $object instanceof Folder; $resource = new CDavResource($path . ($isFolder && substr($path, -1, 1) != "/" ? "/" : "")); $resource->AddProperty('name', $object->getName()); if ($object instanceof File) { $resource->AddProperty('getcontentlength', $object->getSize()); } $resource->AddProperty('creationdate', $object->getCreateTime()->getTimestamp()); $resource->AddProperty('getlastmodified', $object->getUpdateTime()->getTimestamp()); $resource->AddProperty('iscollection', $isFolder ? '1' : '0'); $resource->AddProperty('Win32CreationTime', $object->getCreateTime()->getTimestamp(), "urn:schemas-microsoft-com:"); $resource->AddProperty('Win32LastModifiedTime', $object->getUpdateTime()->getTimestamp(), "urn:schemas-microsoft-com:"); if ($isFolder) { $resource->AddProperty('resourcetype', array('collection', '')); $resource->AddProperty('getcontenttype', 'httpd/unix-directory'); } else { $resource->AddProperty('getcontenttype', ''); $resource->AddProperty('isreadonly', ''); $resource->AddProperty('ishidden', ''); $resource->AddProperty('resourcetype', ''); } $resource->AddProperty("supportedlock", "<D:lockentry><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry><D:lockentry><D:lockscope><D:shared/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry>"); /* <D:response xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"> <D:href>/docs/shared/%D0%97%D0%B0%D0%B3%D1%80%D1%83%D0%B7%D0%BA%D0%B8</D:href> <D:propstat> <D:prop> <D:resourcetype><D:collection/></D:resourcetype> <D:getcontenttype>httpd/unix-directory</D:getcontenttype> <D:creationdate ns0:dt="dateTime.tz">2014-05-12T08:37:25Z</D:creationdate> <D:getlastmodified ns0:dt="dateTime.rfc1123">Mon, 12 May 2014 08:37:25 GMT</D:getlastmodified> <D:iscollection/> <D:supportedlock><D:lockentry> <D:lockscope><D:exclusive/></D:lockscope> <D:locktype><D:write/></D:locktype> </D:lockentry> <D:lockentry> <D:lockscope><D:shared/></D:lockscope> <D:locktype><D:write/></D:locktype> </D:lockentry></D:supportedlock> </D:prop> <D:status>HTTP/1.1 200 OK</D:status> </D:propstat> </D:response> <D:response xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"> <D:href>/docs/shared/%D0%90%D0%BD%D0%BA%D0%B5%D1%82%D0%B0.docx</D:href> <D:propstat> <D:prop> <D:creationdate ns0:dt="dateTime.tz">2014-05-12T08:26:30Z</D:creationdate> <D:getlastmodified ns0:dt="dateTime.rfc1123">Mon, 12 May 2014 08:26:31 GMT</D:getlastmodified> <D:creationdate ns0:dt="dateTime.tz">2014-05-12T08:26:30Z</D:creationdate> <D:getlastmodified ns0:dt="dateTime.rfc1123">Mon, 12 May 2014 08:26:31 GMT</D:getlastmodified> <D:getcontenttype/> <D:getcontentlength>86838</D:getcontentlength> <D:isreadonly>false</D:isreadonly> <D:ishidden>false</D:ishidden> <D:iscollection>0</D:iscollection> <D:resourcetype/> <D:supportedlock><D:lockentry> <D:lockscope><D:exclusive/></D:lockscope> <D:locktype><D:write/></D:locktype> </D:lockentry> <D:lockentry> <D:lockscope><D:shared/></D:lockscope> <D:locktype><D:write/></D:locktype> </D:lockentry></D:supportedlock> </D:prop> <D:status>HTTP/1.1 200 OK</D:status> </D:propstat> </D:response> */ return $resource; }