Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2022-08-28 21:54:21 +0300
committerJulius Härtl <jus@bitgrid.net>2022-08-31 17:24:33 +0300
commita392235e23c3b8af1d0eba4dbac18b18de826a1c (patch)
treec983c213d99937bb53463e759d703d85861fb631 /lib
parentbee8fd2408b053756e052a2b96899935c1adf872 (diff)
Cleanup
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php9
-rw-r--r--lib/composer/composer/autoload_static.php9
-rw-r--r--lib/private/Collaboration/Reference/FileReferenceProvider.php62
-rw-r--r--lib/private/Collaboration/Reference/LinkReferenceProvider.php23
-rw-r--r--lib/private/Collaboration/Reference/Reference.php12
-rw-r--r--lib/private/Collaboration/Reference/ReferenceManager.php17
-rw-r--r--lib/private/Server.php4
-rw-r--r--lib/public/Collaboration/Reference/IReference.php31
-rw-r--r--lib/public/Collaboration/Reference/IReferenceManager.php5
-rw-r--r--lib/public/Collaboration/Reference/IReferenceProvider.php2
-rw-r--r--lib/public/IURLGenerator.php10
11 files changed, 131 insertions, 53 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 5b8e057636c..2f5155d9c09 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -142,6 +142,9 @@ return array(
'OCP\\Collaboration\\Collaborators\\ISearchPlugin' => $baseDir . '/lib/public/Collaboration/Collaborators/ISearchPlugin.php',
'OCP\\Collaboration\\Collaborators\\ISearchResult' => $baseDir . '/lib/public/Collaboration/Collaborators/ISearchResult.php',
'OCP\\Collaboration\\Collaborators\\SearchResultType' => $baseDir . '/lib/public/Collaboration/Collaborators/SearchResultType.php',
+ 'OCP\\Collaboration\\Reference\\IReference' => $baseDir . '/lib/public/Collaboration/Reference/IReference.php',
+ 'OCP\\Collaboration\\Reference\\IReferenceManager' => $baseDir . '/lib/public/Collaboration/Reference/IReferenceManager.php',
+ 'OCP\\Collaboration\\Reference\\IReferenceProvider' => $baseDir . '/lib/public/Collaboration/Reference/IReferenceProvider.php',
'OCP\\Collaboration\\Resources\\CollectionException' => $baseDir . '/lib/public/Collaboration/Resources/CollectionException.php',
'OCP\\Collaboration\\Resources\\ICollection' => $baseDir . '/lib/public/Collaboration/Resources/ICollection.php',
'OCP\\Collaboration\\Resources\\IManager' => $baseDir . '/lib/public/Collaboration/Resources/IManager.php',
@@ -823,6 +826,10 @@ return array(
'OC\\Collaboration\\Collaborators\\Search' => $baseDir . '/lib/private/Collaboration/Collaborators/Search.php',
'OC\\Collaboration\\Collaborators\\SearchResult' => $baseDir . '/lib/private/Collaboration/Collaborators/SearchResult.php',
'OC\\Collaboration\\Collaborators\\UserPlugin' => $baseDir . '/lib/private/Collaboration/Collaborators/UserPlugin.php',
+ 'OC\\Collaboration\\Reference\\FileReferenceProvider' => $baseDir . '/lib/private/Collaboration/Reference/FileReferenceProvider.php',
+ 'OC\\Collaboration\\Reference\\LinkReferenceProvider' => $baseDir . '/lib/private/Collaboration/Reference/LinkReferenceProvider.php',
+ 'OC\\Collaboration\\Reference\\Reference' => $baseDir . '/lib/private/Collaboration/Reference/Reference.php',
+ 'OC\\Collaboration\\Reference\\ReferenceManager' => $baseDir . '/lib/private/Collaboration/Reference/ReferenceManager.php',
'OC\\Collaboration\\Resources\\Collection' => $baseDir . '/lib/private/Collaboration/Resources/Collection.php',
'OC\\Collaboration\\Resources\\Listener' => $baseDir . '/lib/private/Collaboration/Resources/Listener.php',
'OC\\Collaboration\\Resources\\Manager' => $baseDir . '/lib/private/Collaboration/Resources/Manager.php',
@@ -975,6 +982,8 @@ return array(
'OC\\Core\\Controller\\ProfileApiController' => $baseDir . '/core/Controller/ProfileApiController.php',
'OC\\Core\\Controller\\ProfilePageController' => $baseDir . '/core/Controller/ProfilePageController.php',
'OC\\Core\\Controller\\RecommendedAppsController' => $baseDir . '/core/Controller/RecommendedAppsController.php',
+ 'OC\\Core\\Controller\\ReferenceApiController' => $baseDir . '/core/Controller/ReferenceApiController.php',
+ 'OC\\Core\\Controller\\ReferenceController' => $baseDir . '/core/Controller/ReferenceController.php',
'OC\\Core\\Controller\\SearchController' => $baseDir . '/core/Controller/SearchController.php',
'OC\\Core\\Controller\\SetupController' => $baseDir . '/core/Controller/SetupController.php',
'OC\\Core\\Controller\\TwoFactorChallengeController' => $baseDir . '/core/Controller/TwoFactorChallengeController.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index dd3031d3a9b..d0e37c27f12 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -175,6 +175,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Collaboration\\Collaborators\\ISearchPlugin' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Collaborators/ISearchPlugin.php',
'OCP\\Collaboration\\Collaborators\\ISearchResult' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Collaborators/ISearchResult.php',
'OCP\\Collaboration\\Collaborators\\SearchResultType' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Collaborators/SearchResultType.php',
+ 'OCP\\Collaboration\\Reference\\IReference' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Reference/IReference.php',
+ 'OCP\\Collaboration\\Reference\\IReferenceManager' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Reference/IReferenceManager.php',
+ 'OCP\\Collaboration\\Reference\\IReferenceProvider' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Reference/IReferenceProvider.php',
'OCP\\Collaboration\\Resources\\CollectionException' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/CollectionException.php',
'OCP\\Collaboration\\Resources\\ICollection' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/ICollection.php',
'OCP\\Collaboration\\Resources\\IManager' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/IManager.php',
@@ -856,6 +859,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Collaboration\\Collaborators\\Search' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/Search.php',
'OC\\Collaboration\\Collaborators\\SearchResult' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/SearchResult.php',
'OC\\Collaboration\\Collaborators\\UserPlugin' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/UserPlugin.php',
+ 'OC\\Collaboration\\Reference\\FileReferenceProvider' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Reference/FileReferenceProvider.php',
+ 'OC\\Collaboration\\Reference\\LinkReferenceProvider' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Reference/LinkReferenceProvider.php',
+ 'OC\\Collaboration\\Reference\\Reference' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Reference/Reference.php',
+ 'OC\\Collaboration\\Reference\\ReferenceManager' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Reference/ReferenceManager.php',
'OC\\Collaboration\\Resources\\Collection' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Resources/Collection.php',
'OC\\Collaboration\\Resources\\Listener' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Resources/Listener.php',
'OC\\Collaboration\\Resources\\Manager' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Resources/Manager.php',
@@ -1008,6 +1015,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Controller\\ProfileApiController' => __DIR__ . '/../../..' . '/core/Controller/ProfileApiController.php',
'OC\\Core\\Controller\\ProfilePageController' => __DIR__ . '/../../..' . '/core/Controller/ProfilePageController.php',
'OC\\Core\\Controller\\RecommendedAppsController' => __DIR__ . '/../../..' . '/core/Controller/RecommendedAppsController.php',
+ 'OC\\Core\\Controller\\ReferenceApiController' => __DIR__ . '/../../..' . '/core/Controller/ReferenceApiController.php',
+ 'OC\\Core\\Controller\\ReferenceController' => __DIR__ . '/../../..' . '/core/Controller/ReferenceController.php',
'OC\\Core\\Controller\\SearchController' => __DIR__ . '/../../..' . '/core/Controller/SearchController.php',
'OC\\Core\\Controller\\SetupController' => __DIR__ . '/../../..' . '/core/Controller/SetupController.php',
'OC\\Core\\Controller\\TwoFactorChallengeController' => __DIR__ . '/../../..' . '/core/Controller/TwoFactorChallengeController.php',
diff --git a/lib/private/Collaboration/Reference/FileReferenceProvider.php b/lib/private/Collaboration/Reference/FileReferenceProvider.php
index 9a4bd65249f..358092ff508 100644
--- a/lib/private/Collaboration/Reference/FileReferenceProvider.php
+++ b/lib/private/Collaboration/Reference/FileReferenceProvider.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net>
*
@@ -22,11 +24,15 @@
namespace OC\Collaboration\Reference;
+use OC\User\NoUserException;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceProvider;
+use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
+use OCP\IPreview;
use OCP\IURLGenerator;
use OCP\IUserSession;
@@ -34,11 +40,13 @@ class FileReferenceProvider implements IReferenceProvider {
private IURLGenerator $urlGenerator;
private IRootFolder $rootFolder;
private ?string $userId;
+ private IPreview $previewManager;
- public function __construct(IURLGenerator $urlGenerator, IRootFolder $rootFolder, IUserSession $userSession) {
+ public function __construct(IURLGenerator $urlGenerator, IRootFolder $rootFolder, IUserSession $userSession, IPreview $previewManager) {
$this->urlGenerator = $urlGenerator;
$this->rootFolder = $rootFolder;
$this->userId = $userSession->getUser() ? $userSession->getUser()->getUID() : null;
+ $this->previewManager = $previewManager;
}
public function matchReference(string $referenceText): bool {
@@ -52,6 +60,7 @@ class FileReferenceProvider implements IReferenceProvider {
try {
$this->fetchReference($reference);
} catch (NotFoundException $e) {
+ $reference->setRichObject('file', null);
$reference->setAccessible(false);
}
return $reference;
@@ -61,10 +70,7 @@ class FileReferenceProvider implements IReferenceProvider {
}
/**
- * @throws \OCP\Files\NotPermittedException
- * @throws \OCP\Files\InvalidPathException
* @throws NotFoundException
- * @throws \OC\User\NoUserException
*/
private function fetchReference(Reference $reference) {
if ($this->userId === null) {
@@ -74,30 +80,34 @@ class FileReferenceProvider implements IReferenceProvider {
$fileId = str_replace($this->urlGenerator->getAbsoluteURL('/index.php/f/'), '', $reference->getId());
$fileId = str_replace($this->urlGenerator->getAbsoluteURL('/f/'), '', $fileId);
- $userFolder = $this->rootFolder->getUserFolder($this->userId);
- $files = $userFolder->getById((int)$fileId);
+ try {
+ $userFolder = $this->rootFolder->getUserFolder($this->userId);
+ $files = $userFolder->getById((int)$fileId);
+
+ if (empty($files)) {
+ throw new NotFoundException();
+ }
- if (empty($files)) {
+ /** @var Node $file */
+ $file = array_shift($files);
+
+ $reference->setTitle($file->getName());
+ $reference->setDescription($file->getMimetype());
+ $reference->setUrl($this->urlGenerator->getAbsoluteURL('/index.php/f/' . $fileId));
+ $reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 1600, 'y' => 630, 'fileId' => $fileId]));
+
+ $reference->setRichObject('file', [
+ 'id' => $file->getId(),
+ 'name' => $file->getName(),
+ 'size' => $file->getSize(),
+ 'path' => $file->getPath(),
+ 'link' => $reference->getUrl(),
+ 'mimetype' => $file->getMimetype(),
+ 'preview-available' => $this->previewManager->isAvailable($file)
+ ]);
+ } catch (InvalidPathException|NotFoundException|NotPermittedException|NoUserException $e) {
throw new NotFoundException();
}
-
- /** @var Node $file */
- $file = array_shift($files);
-
- $reference->setTitle($file->getName());
- $reference->setDescription($file->getMimetype());
- $reference->setUrl($this->urlGenerator->getAbsoluteURL('/index.php/f/' . $fileId));
- $reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 1600, 'y' => 630, 'fileId' => $fileId]));
-
- $reference->setRichObject('file', [
- 'id' => $file->getId(),
- 'name' => $file->getName(),
- 'size' => $file->getSize(),
- 'path' => $file->getPath(),
- 'link' => $reference->getUrl(),
- 'mimetype' => $file->getMimetype(),
- 'preview-available' => false
- ]);
}
public function isGloballyCacheable(): bool {
@@ -105,6 +115,6 @@ class FileReferenceProvider implements IReferenceProvider {
}
public function getCacheKey(string $referenceId): string {
- return $this->userId;
+ return $this->userId ?? '';
}
}
diff --git a/lib/private/Collaboration/Reference/LinkReferenceProvider.php b/lib/private/Collaboration/Reference/LinkReferenceProvider.php
index 74eb21b8785..7ac6aca5f89 100644
--- a/lib/private/Collaboration/Reference/LinkReferenceProvider.php
+++ b/lib/private/Collaboration/Reference/LinkReferenceProvider.php
@@ -27,6 +27,8 @@ namespace OC\Collaboration\Reference;
use Fusonic\OpenGraph\Consumer;
use GuzzleHttp\Psr7\LimitStream;
use GuzzleHttp\Psr7\Utils;
+use OC\Security\RateLimiting\Exception\RateLimitExceededException;
+use OC\Security\RateLimiting\Limiter;
use OC\SystemConfig;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceProvider;
@@ -37,7 +39,6 @@ use OCP\IURLGenerator;
use Psr\Log\LoggerInterface;
class LinkReferenceProvider implements IReferenceProvider {
- public const URL_PATTERN = '/(\s|^)(https?:\/\/)?((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|$)/i';
public const MAX_PREVIEW_SIZE = 1024 * 1024;
public const ALLOWED_CONTENT_TYPES = [
@@ -54,13 +55,15 @@ class LinkReferenceProvider implements IReferenceProvider {
private SystemConfig $systemConfig;
private IAppDataFactory $appDataFactory;
private IURLGenerator $urlGenerator;
+ private Limiter $limiter;
- public function __construct(IClientService $clientService, LoggerInterface $logger, SystemConfig $systemConfig, IAppDataFactory $appDataFactory, IURLGenerator $urlGenerator) {
+ public function __construct(IClientService $clientService, LoggerInterface $logger, SystemConfig $systemConfig, IAppDataFactory $appDataFactory, IURLGenerator $urlGenerator, Limiter $limiter) {
$this->clientService = $clientService;
$this->logger = $logger;
$this->systemConfig = $systemConfig;
$this->appDataFactory = $appDataFactory;
$this->urlGenerator = $urlGenerator;
+ $this->limiter = $limiter;
}
public function matchReference(string $referenceText): bool {
@@ -68,7 +71,7 @@ class LinkReferenceProvider implements IReferenceProvider {
return false;
}
- return (bool)preg_match(self::URL_PATTERN, $referenceText);
+ return (bool)preg_match(IURLGenerator::URL_REGEX, $referenceText);
}
public function resolveReference(string $referenceText): ?IReference {
@@ -82,6 +85,17 @@ class LinkReferenceProvider implements IReferenceProvider {
}
private function fetchReference(Reference $reference) {
+ try {
+ $user = \OC::$server->getUserSession()->getUser();
+ if ($user) {
+ $this->limiter->registerUserRequest('opengraph', 10, 120, $user);
+ } else {
+ $this->limiter->registerAnonRequest('opengraph', 10, 120, \OC::$server->getRequest()->getRemoteAddress());
+ }
+ } catch (RateLimitExceededException $e) {
+ return;
+ }
+
$client = $this->clientService->newClient();
try {
$response = $client->get($reference->getId(), [ 'timeout' => 10 ]);
@@ -118,12 +132,11 @@ class LinkReferenceProvider implements IReferenceProvider {
$contentType = $response->getHeader('Content-Type');
$contentLength = $response->getHeader('Content-Length');
-
if (in_array($contentType, self::ALLOWED_CONTENT_TYPES, true) && $contentLength < self::MAX_PREVIEW_SIZE) {
$stream = Utils::streamFor($response->getBody());
$bodyStream = new LimitStream($stream, self::MAX_PREVIEW_SIZE, 0);
$reference->setImageContentType($contentType);
- $folder->newFile(md5($reference->getId()), $bodyStream);
+ $folder->newFile(md5($reference->getId()), $bodyStream->getContents());
$reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Reference.preview', ['referenceId' => md5($reference->getId())]));
}
} catch (\Throwable $e) {
diff --git a/lib/private/Collaboration/Reference/Reference.php b/lib/private/Collaboration/Reference/Reference.php
index 69ce7fc9597..22dc57782d8 100644
--- a/lib/private/Collaboration/Reference/Reference.php
+++ b/lib/private/Collaboration/Reference/Reference.php
@@ -53,6 +53,10 @@ class Reference implements IReference {
$this->accessible = $accessible;
}
+ public function getAccessible(): bool {
+ return $this->accessible;
+ }
+
public function setTitle(string $title): void {
$this->title = $title;
}
@@ -93,20 +97,20 @@ class Reference implements IReference {
return $this->url;
}
- public function setRichObject(string $type, array $richObject): void {
+ public function setRichObject(string $type, ?array $richObject): void {
$this->richObjectType = $type;
$this->richObject = $richObject;
}
public function getRichObjectType(): string {
- if (!$this->richObjectType) {
+ if ($this->richObjectType === null) {
return 'open-graph';
}
return $this->richObjectType;
}
public function getRichObject(): array {
- if (!$this->richObject) {
+ if ($this->richObject === null) {
return $this->getOpenGraphObject();
}
return $this->richObject;
@@ -130,7 +134,7 @@ class Reference implements IReference {
'imageContentType' => $reference->getImageContentType(),
'description' => $reference->getDescription(),
'link' => $reference->getUrl(),
- 'accessible' => $reference->accessible,
+ 'accessible' => $reference->getAccessible(),
'richObjectType' => $reference->getRichObjectType(),
'richObject' => $reference->getRichObject(),
];
diff --git a/lib/private/Collaboration/Reference/ReferenceManager.php b/lib/private/Collaboration/Reference/ReferenceManager.php
index 1bd9bfac0b8..471f0efb3be 100644
--- a/lib/private/Collaboration/Reference/ReferenceManager.php
+++ b/lib/private/Collaboration/Reference/ReferenceManager.php
@@ -30,12 +30,12 @@ use OCP\Collaboration\Reference\IReferenceManager;
use OCP\Collaboration\Reference\IReferenceProvider;
use OCP\ICache;
use OCP\ICacheFactory;
+use OCP\IURLGenerator;
use Psr\Container\ContainerInterface;
+use Psr\Log\LoggerInterface;
use Throwable;
-use function OCP\Log\logger;
class ReferenceManager implements IReferenceManager {
- public const URL_PATTERN = '/(\s|\n|^)(https?:\/\/)?((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|\n|$)/mi';
public const CACHE_TTL = 60;
/** @var IReferenceProvider[]|null */
@@ -43,16 +43,19 @@ class ReferenceManager implements IReferenceManager {
private ICache $cache;
private Coordinator $coordinator;
private ContainerInterface $container;
+ private LinkReferenceProvider $linkReferenceProvider;
+ private LoggerInterface $logger;
- public function __construct(LinkReferenceProvider $linkReferenceProvider, ICacheFactory $cacheFactory, Coordinator $coordinator, ContainerInterface $container) {
+ public function __construct(LinkReferenceProvider $linkReferenceProvider, ICacheFactory $cacheFactory, Coordinator $coordinator, ContainerInterface $container, LoggerInterface $logger) {
$this->linkReferenceProvider = $linkReferenceProvider;
$this->cache = $cacheFactory->createDistributed('reference');
$this->coordinator = $coordinator;
$this->container = $container;
+ $this->logger = $logger;
}
public function extractReferences(string $text): array {
- preg_match_all(self::URL_PATTERN, $text, $matches);
+ preg_match_all(IURLGenerator::URL_REGEX, $text, $matches);
$references = $matches[0] ?? [];
return array_map(function ($reference) {
return trim($reference);
@@ -94,6 +97,9 @@ class ReferenceManager implements IReferenceManager {
$matchedProvider = null;
foreach ($this->getProviders() as $provider) {
$matchedProvider = $provider->matchReference($referenceId) ? $provider : null;
+ if ($matchedProvider !== null) {
+ break;
+ }
}
if ($matchedProvider === null && $this->linkReferenceProvider->matchReference($referenceId)) {
@@ -141,7 +147,7 @@ class ReferenceManager implements IReferenceManager {
/** @var IReferenceProvider $provider */
$provider = $this->container->get($registration->getService());
} catch (Throwable $e) {
- logger()->error('Could not load reference provider ' . $registration->getService() . ': ' . $e->getMessage(), [
+ $this->logger->error('Could not load reference provider ' . $registration->getService() . ': ' . $e->getMessage(), [
'exception' => $e,
]);
return null;
@@ -150,7 +156,6 @@ class ReferenceManager implements IReferenceManager {
return $provider;
}, $context->getReferenceProviders()));
- // TODO: Move to files app
$this->providers[] = $this->container->get(FileReferenceProvider::class);
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 09074e39046..f18ac7b6534 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -73,6 +73,7 @@ use OC\Collaboration\Collaborators\MailPlugin;
use OC\Collaboration\Collaborators\RemoteGroupPlugin;
use OC\Collaboration\Collaborators\RemotePlugin;
use OC\Collaboration\Collaborators\UserPlugin;
+use OC\Collaboration\Reference\ReferenceManager;
use OC\Command\CronBus;
use OC\Comments\ManagerFactory as CommentsManagerFactory;
use OC\Contacts\ContactsMenu\ActionFactory;
@@ -162,6 +163,7 @@ use OCP\App\IAppManager;
use OCP\Authentication\LoginCredentials\IStore;
use OCP\BackgroundJob\IJobList;
use OCP\Collaboration\AutoComplete\IManager;
+use OCP\Collaboration\Reference\IReferenceManager;
use OCP\Command\IBus;
use OCP\Comments\ICommentsManager;
use OCP\Contacts\ContactsMenu\IActionFactory;
@@ -1338,6 +1340,8 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
$this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
+ $this->registerAlias(IReferenceManager::class, ReferenceManager::class);
+
$this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
$this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
$this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
diff --git a/lib/public/Collaboration/Reference/IReference.php b/lib/public/Collaboration/Reference/IReference.php
index 2a7213983cf..0155ae86dd8 100644
--- a/lib/public/Collaboration/Reference/IReference.php
+++ b/lib/public/Collaboration/Reference/IReference.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net>
*
@@ -35,11 +37,20 @@ interface IReference extends JsonSerializable {
public function getId(): string;
/**
+ * Accessible flag indicates if the user has access to the provided reference
+ *
* @since 25.0.0
*/
public function setAccessible(bool $accessible): void;
/**
+ * Accessible flag indicates if the user has access to the provided reference
+ *
+ * @since 25.0.0
+ */
+ public function getAccessible(): bool;
+
+ /**
* @since 25.0.0
*/
public function setTitle(string $title): void;
@@ -90,32 +101,30 @@ interface IReference extends JsonSerializable {
public function getUrl(): ?string;
/**
+ * Set the reference specific rich object representation
+ *
* @since 25.0.0
*/
- public function setRichObject(string $type, array $richObject): void;
+ public function setRichObject(string $type, ?array $richObject): void;
/**
+ * Returns the type of the reference specific rich object
+ *
* @since 25.0.0
*/
public function getRichObjectType(): string;
/**
+ * Returns the reference specific rich object representation
+ *
* @since 25.0.0
*/
public function getRichObject(): array;
/**
+ * Returns the opengraph rich object representation
+ *
* @since 25.0.0
*/
public function getOpenGraphObject(): array;
-
- /**
- * @since 25.0.0
- */
- public static function toCache(IReference $reference): array;
-
- /**
- * @since 25.0.0
- */
- public static function fromCache(array $cache): IReference;
}
diff --git a/lib/public/Collaboration/Reference/IReferenceManager.php b/lib/public/Collaboration/Reference/IReferenceManager.php
index 8d2110911d3..e9a53e8a61a 100644
--- a/lib/public/Collaboration/Reference/IReferenceManager.php
+++ b/lib/public/Collaboration/Reference/IReferenceManager.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net>
*
@@ -38,7 +40,8 @@ interface IReferenceManager {
*
* This method has a fallback to always provide the open graph metadata,
* but may still return null in case this is disabled or the fetching fails
+ *
* @since 25.0.0
*/
- public function resolveReference(string $reference): ?IReference;
+ public function resolveReference(string $referenceId): ?IReference;
}
diff --git a/lib/public/Collaboration/Reference/IReferenceProvider.php b/lib/public/Collaboration/Reference/IReferenceProvider.php
index b7b2f187a65..d2f3601a475 100644
--- a/lib/public/Collaboration/Reference/IReferenceProvider.php
+++ b/lib/public/Collaboration/Reference/IReferenceProvider.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net>
*
diff --git a/lib/public/IURLGenerator.php b/lib/public/IURLGenerator.php
index 580536b8b5f..808ba66c862 100644
--- a/lib/public/IURLGenerator.php
+++ b/lib/public/IURLGenerator.php
@@ -35,6 +35,16 @@ namespace OCP;
* @since 6.0.0
*/
interface IURLGenerator {
+
+ /**
+ * Regex for matching http(s) urls
+ *
+ * This is a copy of the frontend regex in core/src/OCP/comments.js, make sure to adjust both when changing
+ *
+ * @since 25.0.0
+ */
+ public const URL_REGEX = '/(\s|\n|^)(https?:\/\/)?((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|\n|$)/mi';
+
/**
* Returns the URL for a route
* @param string $routeName the name of the route