1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- declare(strict_types=1);
- namespace OCA\DAV\CardDAV;
- use Sabre\CardDAV\Card;
- use Sabre\DAV\INode;
- use Sabre\DAV\PropFind;
- use Sabre\DAV\Server;
- use Sabre\DAV\ServerPlugin;
- use Sabre\VObject\Component\VCard;
- use Sabre\VObject\Reader;
- class HasPhotoPlugin extends ServerPlugin {
-
- protected $server;
-
- public function initialize(Server $server) {
- $server->on('propFind', [$this, 'propFind']);
- }
-
- public function propFind(PropFind $propFind, INode $node) {
- $ns = '{http://nextcloud.com/ns}';
- if ($node instanceof Card) {
- $propFind->handle($ns . 'has-photo', function () use ($node) {
- $vcard = Reader::read($node->get());
- return $vcard instanceof VCard
- && $vcard->PHOTO
-
- && (!str_starts_with($vcard->PHOTO->getValue(), 'data:')
- || str_starts_with($vcard->PHOTO->getValue(), 'data:image/'))
- ;
- });
- }
- }
-
- public function getPluginName() {
- return 'vcard-has-photo';
- }
-
- public function getPluginInfo() {
- return [
- 'name' => $this->getPluginName(),
- 'description' => 'Return a boolean stating if the vcard have a photo property set or not.'
- ];
- }
- }
|