From b49f6aa3258bf3f629dfd951e60ac0e8a97f5468 Mon Sep 17 00:00:00 2001 From: Murtaza Sultani Date: Wed, 23 Jul 2025 12:00:18 +0200 Subject: Resolve "Forum 3/OpenGraph: Leere Objekte sollen nicht angezeigt werden" Closes #5744 Merge request studip/studip!4378 --- lib/classes/JsonApi/Schemas/Forum/ForumPosting.php | 2 +- lib/models/Forum/ForumPosting.php | 5 ++--- resources/vue/components/LinksPreview.vue | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/classes/JsonApi/Schemas/Forum/ForumPosting.php b/lib/classes/JsonApi/Schemas/Forum/ForumPosting.php index 5506f55..a03e75d 100644 --- a/lib/classes/JsonApi/Schemas/Forum/ForumPosting.php +++ b/lib/classes/JsonApi/Schemas/Forum/ForumPosting.php @@ -46,7 +46,7 @@ class ForumPosting extends SchemaProvider 'title' => $og['title'], 'description' => $og['description'], 'image' => $og['image'], - ], $posting->getOpenGraphURLs()->toArray()) + ], $posting->getOpenGraphURLs()) ]; } diff --git a/lib/models/Forum/ForumPosting.php b/lib/models/Forum/ForumPosting.php index 11be45d..b442046 100644 --- a/lib/models/Forum/ForumPosting.php +++ b/lib/models/Forum/ForumPosting.php @@ -2,7 +2,6 @@ namespace Forum; use OpenGraph; -use OpenGraphURLCollection; use SimpleORMap; use Forum\Service\PostingNotification; use User; @@ -102,10 +101,10 @@ class ForumPosting extends SimpleORMap ); } - public function getOpenGraphURLs(): OpenGraphURLCollection + public function getOpenGraphURLs(): array { $content = preg_replace("~(.*)~si", '', $this['content']); - return OpenGraph::extract($content); + return array_filter(OpenGraph::extract($content)->toArray(), fn($og) => $og['is_opengraph']); } public function onCreate(): void diff --git a/resources/vue/components/LinksPreview.vue b/resources/vue/components/LinksPreview.vue index 7946002..67988ad 100644 --- a/resources/vue/components/LinksPreview.vue +++ b/resources/vue/components/LinksPreview.vue @@ -8,11 +8,11 @@ const props = defineProps({ type: Array, required: true } -}) +}); -const currentIndex = ref(0) +const currentIndex = ref(0); -const currentLink = computed(() => props.links[currentIndex.value]) +const currentLink = computed(() => props.links[currentIndex.value]);