Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/CardDAV/IAddressBookObjectContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Sabre\CardDAV;

use Sabre\CardDAV\Xml\Request\AddressBookQueryReport;
use Sabre\DAV\ICollection;

/**
* This interface represents a node that may contain address book objects.
*
* This is the shared parent for both the Inbox collection and calendars
* resources.
*
* @license http://sabre.io/license/ Modified BSD License
*/
interface IAddressBookObjectContainer extends ICollection
{
/**
* Performs an addressbook-query on the contents of this calendar.
*
* This method should just return a list of (relative) urls that match this
* query.
*
* @see CalendarQueryValidator
* @return string[]
*/
public function addressBookQuery(AddressBookQueryReport $report): array;
}
55 changes: 31 additions & 24 deletions lib/CardDAV/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,37 @@ protected function addressbookQueryReport($report)
throw new ReportNotSupported('The addressbook-query report is not supported on this url with Depth: 0');
}
} else {
$candidateNodes = $this->server->tree->getChildren($this->server->getRequestUri());
$node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
if ($node instanceof IAddressBookObjectContainer) {
$candidateNodes = $node->addressBookQuery($report);
$validNodes = $this->server->tree->getMultipleNodes(array_map(function (string $path) {
return $this->server->getRequestUri() . '/' . $path;
}, $candidateNodes));
} else {
$candidateNodes = $this->server->tree->getChildren($this->server->getRequestUri());
$validNodes = [];
foreach ($candidateNodes as $node) {
if (!$node instanceof ICard) {
continue;
}

$blob = $node->get();
if (is_resource($blob)) {
$blob = stream_get_contents($blob);
}

if (!$this->validateFilters($blob, $report->filters, $report->test)) {
continue;
}

$validNodes[] = $node;

if ($report->limit && $report->limit <= count($validNodes)) {
// We hit the maximum number of items, we can stop now.
break;
}
}
}
}

$contentType = $report->contentType;
Expand All @@ -419,29 +449,6 @@ protected function addressbookQueryReport($report)
$contentType
);

$validNodes = [];
foreach ($candidateNodes as $node) {
if (!$node instanceof ICard) {
continue;
}

$blob = $node->get();
if (is_resource($blob)) {
$blob = stream_get_contents($blob);
}

if (!$this->validateFilters($blob, $report->filters, $report->test)) {
continue;
}

$validNodes[] = $node;

if ($report->limit && $report->limit <= count($validNodes)) {
// We hit the maximum number of items, we can stop now.
break;
}
}

$result = [];
foreach ($validNodes as $validNode) {
if (0 == $depth) {
Expand Down
Loading