aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CardDAV/Converter.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/CardDAV/Converter.php')
-rw-r--r--apps/dav/lib/CardDAV/Converter.php68
1 files changed, 32 insertions, 36 deletions
diff --git a/apps/dav/lib/CardDAV/Converter.php b/apps/dav/lib/CardDAV/Converter.php
index 8ea75fbef74..30dba99839e 100644
--- a/apps/dav/lib/CardDAV/Converter.php
+++ b/apps/dav/lib/CardDAV/Converter.php
@@ -1,53 +1,31 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\DAV\CardDAV;
+use DateTimeImmutable;
use Exception;
use OCP\Accounts\IAccountManager;
use OCP\IImage;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
+use Psr\Log\LoggerInterface;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\Property\Text;
+use Sabre\VObject\Property\VCard\Date;
class Converter {
- /** @var IURLGenerator */
- private $urlGenerator;
- /** @var IAccountManager */
- private $accountManager;
- private IUserManager $userManager;
-
- public function __construct(IAccountManager $accountManager,
- IUserManager $userManager, IURLGenerator $urlGenerator) {
- $this->accountManager = $accountManager;
- $this->userManager = $userManager;
- $this->urlGenerator = $urlGenerator;
+ public function __construct(
+ private IAccountManager $accountManager,
+ private IUserManager $userManager,
+ private IURLGenerator $urlGenerator,
+ private LoggerInterface $logger,
+ ) {
}
public function createCardFromUser(IUser $user): ?VCard {
@@ -98,7 +76,7 @@ class Converter {
new Text(
$vCard,
'X-SOCIALPROFILE',
- $this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $user->getUID()]),
+ $this->urlGenerator->linkToRouteAbsolute('profile.ProfilePage.index', ['targetUserId' => $user->getUID()]),
[
'TYPE' => 'NEXTCLOUD',
'X-NC-SCOPE' => IAccountManager::SCOPE_PUBLISHED
@@ -134,6 +112,24 @@ class Converter {
case IAccountManager::PROPERTY_ROLE:
$vCard->add(new Text($vCard, 'TITLE', $property->getValue(), ['X-NC-SCOPE' => $scope]));
break;
+ case IAccountManager::PROPERTY_BIOGRAPHY:
+ $vCard->add(new Text($vCard, 'NOTE', $property->getValue(), ['X-NC-SCOPE' => $scope]));
+ break;
+ case IAccountManager::PROPERTY_BIRTHDATE:
+ try {
+ $birthdate = new DateTimeImmutable($property->getValue());
+ } catch (Exception $e) {
+ // Invalid date -> just skip the property
+ $this->logger->info("Failed to parse user's birthdate for the SAB: " . $property->getValue(), [
+ 'exception' => $e,
+ 'userId' => $user->getUID(),
+ ]);
+ break;
+ }
+ $dateProperty = new Date($vCard, 'BDAY', null, ['X-NC-SCOPE' => $scope]);
+ $dateProperty->setDateTime($birthdate);
+ $vCard->add($dateProperty);
+ break;
}
}