示例#1
0
 /**
  * This function handles the calendar-query REPORT
  *
  * This report is used by clients to request calendar objects based on
  * complex conditions.
  * 
  * @param DOMNode $dom 
  * @return void
  */
 public function calendarQueryReport($dom)
 {
     $requestedProperties = array_keys(Sabre_DAV_XMLUtil::parseProperties($dom->firstChild));
     $filterNode = $dom->getElementsByTagNameNS('urn:ietf:params:xml:ns:caldav', 'filter');
     if ($filterNode->length !== 1) {
         throw new Sabre_DAV_Exception_BadRequest('The calendar-query report must have a filter element');
     }
     $filters = Sabre_CalDAV_XMLUtil::parseCalendarQueryFilters($filterNode->item(0));
     $requestedCalendarData = true;
     if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar-data', $requestedProperties)) {
         // We always retrieve calendar-data, as we need it for filtering.
         $requestedProperties[] = '{urn:ietf:params:xml:ns:caldav}calendar-data';
         // If calendar-data wasn't explicitly requested, we need to remove
         // it after processing.
         $requestedCalendarData = false;
     }
     // These are the list of nodes that potentially match the requirement
     $candidateNodes = $this->server->getPropertiesForPath($this->server->getRequestUri(), $requestedProperties, $this->server->getHTTPDepth(0));
     $verifiedNodes = array();
     foreach ($candidateNodes as $node) {
         // If the node didn't have a calendar-data property, it must not be a calendar object
         if (!isset($node[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) {
             continue;
         }
         if ($this->validateFilters($node[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'], $filters)) {
             if (!$requestedCalendarData) {
                 unset($node[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
             }
             $verifiedNodes[] = $node;
         }
     }
     $this->server->httpResponse->sendStatus(207);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->sendBody($this->server->generateMultiStatus($verifiedNodes));
 }
示例#2
0
文件: Plugin.php 项目: jtietema/Fizzy
 protected function principalPropertySearchReport($dom)
 {
     $searchableProperties = array('{DAV:}displayname' => 'display name');
     list($searchProperties, $requestedProperties) = $this->parsePrincipalPropertySearchReportRequest($dom);
     $uri = $this->server->getRequestUri();
     $result = array();
     $lookupResults = $this->server->getPropertiesForPath($uri, array_keys($searchProperties), 1);
     // The first item in the results is the parent, so we get rid of it.
     array_shift($lookupResults);
     $matches = array();
     foreach ($lookupResults as $lookupResult) {
         foreach ($searchProperties as $searchProperty => $searchValue) {
             if (!isset($searchableProperties[$searchProperty])) {
                 throw new Sabre_DAV_Exception_BadRequest('Searching for ' . $searchProperty . ' is not supported');
             }
             if (isset($lookupResult[200][$searchProperty]) && mb_stripos($lookupResult[200][$searchProperty], $searchValue, 0, 'UTF-8') !== false) {
                 $matches[] = $lookupResult['href'];
             }
         }
     }
     $matchProperties = array();
     foreach ($matches as $match) {
         list($result) = $this->server->getPropertiesForPath($match, $requestedProperties, 0);
         $matchProperties[] = $result;
     }
     $xml = $this->server->generateMultiStatus($matchProperties);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->sendStatus(207);
     $this->server->httpResponse->sendBody($xml);
 }
示例#3
0
 /**
  * principalPropertySearchReport
  *
  * This method is responsible for handing the
  * {DAV:}principal-property-search report. This report can be used for
  * clients to search for groups of principals, based on the value of one
  * or more properties.
  *
  * @param DOMDocument $dom
  * @return void
  */
 protected function principalPropertySearchReport(DOMDocument $dom)
 {
     list($searchProperties, $requestedProperties, $applyToPrincipalCollectionSet) = $this->parsePrincipalPropertySearchReportRequest($dom);
     $uri = null;
     if (!$applyToPrincipalCollectionSet) {
         $uri = $this->server->getRequestUri();
     }
     $result = $this->principalSearch($searchProperties, $requestedProperties, $uri);
     $xml = $this->server->generateMultiStatus($result);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->sendStatus(207);
     $this->server->httpResponse->sendBody($xml);
 }
 /**
  * This method handles the PROPFIND method.
  *
  * It's a very lazy method, it won't bother checking the request body
  * for which properties were requested, and just sends back a default
  * set of properties.
  *
  * @param string $tempLocation
  * @param string $uri
  * @return bool
  */
 public function httpPropfind($tempLocation, $uri)
 {
     if (!file_exists($tempLocation)) {
         return true;
     }
     $hR = $this->server->httpResponse;
     $hR->setHeader('X-Sabre-Temp', 'true');
     $hR->sendStatus(207);
     $hR->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->parsePropFindRequest($this->server->httpRequest->getBody(true));
     $properties = array('href' => $uri, 200 => array('{DAV:}getlastmodified' => new Sabre_DAV_Property_GetLastModified(filemtime($tempLocation)), '{DAV:}getcontentlength' => filesize($tempLocation), '{DAV:}resourcetype' => new Sabre_DAV_Property_ResourceType(null), '{' . Sabre_DAV_Server::NS_SABREDAV . '}tempFile' => true));
     $data = $this->server->generateMultiStatus(array($properties));
     $hR->sendBody($data);
     return false;
 }
示例#5
0
 /**
  * principalPropertySearchReport
  *
  * This method is reponsible for handing the 
  * {DAV:}principal-property-search report. This report can be used for 
  * clients to search for groups of principals, based on the value of one
  * or more properties.
  * 
  * @param DOMDocument $dom 
  * @return void
  */
 protected function principalPropertySearchReport(DOMDocument $dom)
 {
     $searchableProperties = array('{DAV:}displayname' => 'display name');
     list($searchProperties, $requestedProperties, $applyToPrincipalCollectionSet) = $this->parsePrincipalPropertySearchReportRequest($dom);
     $result = array();
     if ($applyToPrincipalCollectionSet) {
         $uris = array();
     } else {
         $uris = array($this->server->getRequestUri());
     }
     $lookupResults = array();
     foreach ($uris as $uri) {
         $p = array_keys($searchProperties);
         $p[] = '{DAV:}resourcetype';
         $r = $this->server->getPropertiesForPath($uri, $p, 1);
         // The first item in the results is the parent, so we get rid of it.
         array_shift($r);
         $lookupResults = array_merge($lookupResults, $r);
     }
     $matches = array();
     foreach ($lookupResults as $lookupResult) {
         // We're only looking for principals
         if (!isset($lookupResult[200]['{DAV:}resourcetype']) || !$lookupResult[200]['{DAV:}resourcetype'] instanceof Sabre_DAV_Property_ResourceType || !$lookupResult[200]['{DAV:}resourcetype']->is('{DAV:}principal')) {
             continue;
         }
         foreach ($searchProperties as $searchProperty => $searchValue) {
             if (!isset($searchableProperties[$searchProperty])) {
                 // If a property is not 'searchable', the spec dictates
                 // this is not a match.
                 continue;
             }
             if (isset($lookupResult[200][$searchProperty]) && mb_stripos($lookupResult[200][$searchProperty], $searchValue, 0, 'UTF-8') !== false) {
                 $matches[] = $lookupResult['href'];
             }
         }
     }
     $matchProperties = array();
     foreach ($matches as $match) {
         list($result) = $this->server->getPropertiesForPath($match, $requestedProperties, 0);
         $matchProperties[] = $result;
     }
     $xml = $this->server->generateMultiStatus($matchProperties);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->sendStatus(207);
     $this->server->httpResponse->sendBody($xml);
 }
示例#6
0
 /**
  * This function handles the addressbook-query REPORT
  *
  * This report is used by the client to filter an addressbook based on a
  * complex query.
  *
  * @param DOMNode $dom
  * @return void
  */
 protected function addressbookQueryReport($dom)
 {
     $query = new Sabre_CardDAV_AddressBookQueryParser($dom);
     $query->parse();
     $depth = $this->server->getHTTPDepth(0);
     if ($depth == 0) {
         $candidateNodes = array($this->server->tree->getNodeForPath($this->server->getRequestUri()));
     } else {
         $candidateNodes = $this->server->tree->getChildren($this->server->getRequestUri());
     }
     $validNodes = array();
     foreach ($candidateNodes as $node) {
         if (!$node instanceof Sabre_CardDAV_ICard) {
             continue;
         }
         $blob = $node->get();
         if (is_resource($blob)) {
             $blob = stream_get_contents($blob);
         }
         if (!$this->validateFilters($blob, $query->filters, $query->test)) {
             continue;
         }
         $validNodes[] = $node;
         if ($query->limit && $query->limit <= count($validNodes)) {
             // We hit the maximum number of items, we can stop now.
             break;
         }
     }
     $result = array();
     foreach ($validNodes as $validNode) {
         if ($depth == 0) {
             $href = $this->server->getRequestUri();
         } else {
             $href = $this->server->getRequestUri() . '/' . $validNode->getName();
         }
         list($result[]) = $this->server->getPropertiesForPath($href, $query->requestedProperties, 0);
     }
     $prefer = $this->server->getHTTPPRefer();
     $this->server->httpResponse->sendStatus(207);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
     $this->server->httpResponse->sendBody($this->server->generateMultiStatus($result, $prefer['return-minimal']));
 }
示例#7
0
 /**
  * This function handles the calendar-query REPORT
  *
  * This report is used by clients to request calendar objects based on
  * complex conditions.
  *
  * @param DOMNode $dom
  * @return void
  */
 public function calendarQueryReport($dom)
 {
     $parser = new Sabre_CalDAV_CalendarQueryParser($dom);
     $parser->parse();
     $requestedCalendarData = true;
     $requestedProperties = $parser->requestedProperties;
     if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar-data', $requestedProperties)) {
         // We always retrieve calendar-data, as we need it for filtering.
         $requestedProperties[] = '{urn:ietf:params:xml:ns:caldav}calendar-data';
         // If calendar-data wasn't explicitly requested, we need to remove
         // it after processing.
         $requestedCalendarData = false;
     }
     // These are the list of nodes that potentially match the requirement
     $candidateNodes = $this->server->getPropertiesForPath($this->server->getRequestUri(), $requestedProperties, $this->server->getHTTPDepth(0));
     $verifiedNodes = array();
     $validator = new Sabre_CalDAV_CalendarQueryValidator();
     foreach ($candidateNodes as $node) {
         // If the node didn't have a calendar-data property, it must not be a calendar object
         if (!isset($node[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) {
             continue;
         }
         $vObject = Sabre_VObject_Reader::read($node[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
         if ($validator->validate($vObject, $parser->filters)) {
             if (!$requestedCalendarData) {
                 unset($node[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
             }
             if ($parser->expand) {
                 $vObject->expand($parser->expand['start'], $parser->expand['end']);
                 $node[200]['{' . self::NS_CALDAV . '}calendar-data'] = $vObject->serialize();
             }
             $verifiedNodes[] = $node;
         }
     }
     $this->server->httpResponse->sendStatus(207);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->sendBody($this->server->generateMultiStatus($verifiedNodes));
 }
示例#8
0
 /**
  * This function handles the calendar-query REPORT
  *
  * This report is used by clients to request calendar objects based on
  * complex conditions.
  *
  * @param DOMNode $dom
  * @return void
  */
 public function calendarQueryReport($dom)
 {
     $parser = new Sabre_CalDAV_CalendarQueryParser($dom);
     $parser->parse();
     $node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
     $depth = $this->server->getHTTPDepth(0);
     // The default result is an empty array
     $result = array();
     // The calendarobject was requested directly. In this case we handle
     // this locally.
     if ($depth == 0 && $node instanceof Sabre_CalDAV_ICalendarObject) {
         $requestedCalendarData = true;
         $requestedProperties = $parser->requestedProperties;
         if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar-data', $requestedProperties)) {
             // We always retrieve calendar-data, as we need it for filtering.
             $requestedProperties[] = '{urn:ietf:params:xml:ns:caldav}calendar-data';
             // If calendar-data wasn't explicitly requested, we need to remove
             // it after processing.
             $requestedCalendarData = false;
         }
         $properties = $this->server->getPropertiesForPath($this->server->getRequestUri(), $requestedProperties, 0);
         // This array should have only 1 element, the first calendar
         // object.
         $properties = current($properties);
         // If there wasn't any calendar-data returned somehow, we ignore
         // this.
         if (isset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) {
             $validator = new Sabre_CalDAV_CalendarQueryValidator();
             $vObject = Sabre_VObject_Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
             if ($validator->validate($vObject, $parser->filters)) {
                 // If the client didn't require the calendar-data property,
                 // we won't give it back.
                 if (!$requestedCalendarData) {
                     unset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
                 } else {
                     if ($parser->expand) {
                         $vObject->expand($parser->expand['start'], $parser->expand['end']);
                         $properties[200]['{' . self::NS_CALDAV . '}calendar-data'] = $vObject->serialize();
                     }
                 }
                 $result = array($properties);
             }
         }
     }
     // If we're dealing with a calendar, the calendar itself is responsible
     // for the calendar-query.
     if ($node instanceof Sabre_CalDAV_ICalendar && ($depth = 1)) {
         $nodePaths = $node->calendarQuery($parser->filters);
         foreach ($nodePaths as $path) {
             list($properties) = $this->server->getPropertiesForPath($this->server->getRequestUri() . '/' . $path, $parser->requestedProperties);
             if ($parser->expand) {
                 // We need to do some post-processing
                 $vObject = Sabre_VObject_Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
                 $vObject->expand($parser->expand['start'], $parser->expand['end']);
                 $properties[200]['{' . self::NS_CALDAV . '}calendar-data'] = $vObject->serialize();
             }
             $result[] = $properties;
         }
     }
     $this->server->httpResponse->sendStatus(207);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->sendBody($this->server->generateMultiStatus($result));
 }