diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-08-12 17:59:18 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2022-08-31 16:20:06 +0200 |
commit | 9d9c7f4b7557f7fa8dc5c5ad3925261a1efb966c (patch) | |
tree | 484087d69e48abb2ea5d383924db2b660a9f8ec7 /lib/private | |
parent | de3e541fde5c1ac2f71368127474341e730e4030 (diff) | |
download | nextcloud-server-9d9c7f4b7557f7fa8dc5c5ad3925261a1efb966c.tar.gz nextcloud-server-9d9c7f4b7557f7fa8dc5c5ad3925261a1efb966c.zip |
Make reference fetching configurable
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Collaboration/Reference/LinkReferenceProvider.php | 11 | ||||
-rw-r--r-- | lib/private/Collaboration/Reference/ReferenceManager.php | 13 |
2 files changed, 14 insertions, 10 deletions
diff --git a/lib/private/Collaboration/Reference/LinkReferenceProvider.php b/lib/private/Collaboration/Reference/LinkReferenceProvider.php index 75d6717de10..b4c44344476 100644 --- a/lib/private/Collaboration/Reference/LinkReferenceProvider.php +++ b/lib/private/Collaboration/Reference/LinkReferenceProvider.php @@ -25,6 +25,7 @@ declare(strict_types=1); namespace OC\Collaboration\Reference; use Fusonic\OpenGraph\Consumer; +use OC\SystemConfig; use OCP\Collaboration\Reference\IReference; use OCP\Collaboration\Reference\IReferenceProvider; use OCP\Http\Client\IClientService; @@ -35,13 +36,19 @@ class LinkReferenceProvider implements IReferenceProvider { private IClientService $clientService; private LoggerInterface $logger; + private SystemConfig $systemConfig; - public function __construct(IClientService $clientService, LoggerInterface $logger) { + public function __construct(IClientService $clientService, LoggerInterface $logger, SystemConfig $systemConfig) { $this->clientService = $clientService; $this->logger = $logger; + $this->systemConfig = $systemConfig; } public function resolveReference(string $referenceText): ?IReference { + if ($this->systemConfig->getValue('reference_opengraph', true) !== true) { + return null; + } + if (preg_match(self::URL_PATTERN, $referenceText)) { $reference = new Reference($referenceText); $this->fetchReference($reference); @@ -51,7 +58,7 @@ class LinkReferenceProvider implements IReferenceProvider { return null; } - public function fetchReference(Reference $reference) { + private function fetchReference(Reference $reference) { $client = $this->clientService->newClient(); try { $response = $client->get($reference->getId()); diff --git a/lib/private/Collaboration/Reference/ReferenceManager.php b/lib/private/Collaboration/Reference/ReferenceManager.php index dc2f01416fe..6f0ef37198e 100644 --- a/lib/private/Collaboration/Reference/ReferenceManager.php +++ b/lib/private/Collaboration/Reference/ReferenceManager.php @@ -32,25 +32,22 @@ use OCP\ICacheFactory; class ReferenceManager implements IReferenceManager { public const URL_PATTERN = '/(\s|\n|^)(https?:\/\/)?((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|\n|$)/mi'; - public const REF_PATTERN = '/#[A-z0-9_]+\/[A-z0-9_]+/i'; /** @var IReferenceProvider[] */ private array $providers = []; private ICache $cache; + private LinkReferenceProvider $linkReferenceProvider; + public function __construct(LinkReferenceProvider $linkReferenceProvider, FileReferenceProvider $fileReferenceProvider, ICacheFactory $cacheFactory) { $this->registerReferenceProvider($fileReferenceProvider); - $this->registerReferenceProvider($linkReferenceProvider); + $this->linkReferenceProvider = $linkReferenceProvider; $this->cache = $cacheFactory->createDistributed('reference'); } public function extractReferences(string $text): array { - $matches = []; - preg_match_all(self::REF_PATTERN, $text, $matches); - $references = $matches[0] ?? []; - preg_match_all(self::URL_PATTERN, $text, $matches); - $references = array_merge($references, $matches[0] ?? []); + $references = $matches[0] ?? []; return array_map(function ($reference) { return trim($reference); }, $references); @@ -70,7 +67,7 @@ class ReferenceManager implements IReferenceManager { } } - return null; + return $this->linkReferenceProvider->resolveReference($referenceId); } public function registerReferenceProvider(IReferenceProvider $provider): void { |