diff --git a/src/Controller/User/ThemeSettingsController.php b/src/Controller/User/ThemeSettingsController.php index 5dbc73566..e94efc5e3 100644 --- a/src/Controller/User/ThemeSettingsController.php +++ b/src/Controller/User/ThemeSettingsController.php @@ -168,13 +168,21 @@ public function __invoke(string $key, string $value, Request $request): Response ); } - public static function getShowUserFullName(Request $request): bool + public static function getShowUserFullName(?Request $request): bool { + if (null === $request) { + return false; + } + return self::TRUE === $request->cookies->get(self::MBIN_SHOW_USER_DOMAIN, 'false'); } - public static function getShowMagazineFullName(Request $request): bool + public static function getShowMagazineFullName(?Request $request): bool { + if (null === $request) { + return false; + } + return self::TRUE === $request->cookies->get(self::MBIN_SHOW_MAGAZINE_DOMAIN, 'false'); } } diff --git a/src/Markdown/CommonMark/ExternalLinkRenderer.php b/src/Markdown/CommonMark/ExternalLinkRenderer.php index d1b4306fc..417a4726f 100644 --- a/src/Markdown/CommonMark/ExternalLinkRenderer.php +++ b/src/Markdown/CommonMark/ExternalLinkRenderer.php @@ -91,17 +91,20 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): H ]); } - $apActivity = $this->activityRepository->findByObjectId($node->getUrl()); - if (!$isApRequest && null !== $apActivity && Message::class !== $apActivity['type']) { - $this->logger->debug('Found activity with url {u}: {t} - {id}', [ - 'u' => $node->getUrl(), - 't' => $apActivity['type'], - 'id' => $apActivity['id'], - ]); - /** @var Entry|EntryComment|Post|PostComment $entity */ - $entity = $this->entityManager->getRepository($apActivity['type'])->find($apActivity['id']); - - return new HtmlElement('div', contents: $this->renderInlineEntity($entity)); + $url = $node->getUrl(); + if (filter_var($url, FILTER_VALIDATE_URL)) { + $apActivity = $this->activityRepository->findByObjectId($url); + if (!$isApRequest && null !== $apActivity && Message::class !== $apActivity['type']) { + $this->logger->debug('Found activity with url {u}: {t} - {id}', [ + 'u' => $node->getUrl(), + 't' => $apActivity['type'], + 'id' => $apActivity['id'], + ]); + /** @var Entry|EntryComment|Post|PostComment $entity */ + $entity = $this->entityManager->getRepository($apActivity['type'])->find($apActivity['id']); + + return new HtmlElement('div', contents: $this->renderInlineEntity($entity)); + } } $renderTarget = $this->config->get('kbin')[MarkdownConverter::RENDER_TARGET]; diff --git a/src/Markdown/Event/BuildCacheContext.php b/src/Markdown/Event/BuildCacheContext.php index 8e7222129..b175e9b45 100644 --- a/src/Markdown/Event/BuildCacheContext.php +++ b/src/Markdown/Event/BuildCacheContext.php @@ -17,7 +17,7 @@ class BuildCacheContext public function __construct( private readonly ConvertMarkdown $convertMarkdownEvent, - private readonly Request $request, + private readonly ?Request $request, ) { $this->addToContext('content', $convertMarkdownEvent->getMarkdown()); $this->addToContext('target', $convertMarkdownEvent->getRenderTarget()->name); diff --git a/src/Utils/UrlUtils.php b/src/Utils/UrlUtils.php index 2e9ceb37c..b3750b20e 100644 --- a/src/Utils/UrlUtils.php +++ b/src/Utils/UrlUtils.php @@ -8,8 +8,11 @@ class UrlUtils { - public static function isActivityPubRequest(Request $request): bool + public static function isActivityPubRequest(?Request $request): bool { + if (null === $request) { + return true; + } $acceptValue = $request->headers->get('Accept', default: 'html'); return str_contains($acceptValue, 'application/activity+json')