From 6f603e5ed007324c7edb7d3965850b2559979a16 Mon Sep 17 00:00:00 2001
From: Rasmus Fuhse <fuhse@data-quest.de>
Date: Sat, 15 Jul 2023 13:49:38 +0000
Subject: [PATCH] =?UTF-8?q?Resolve=20"Werkzeuge:=20Info-Dialoge=20f=C3=BCr?=
 =?UTF-8?q?=20Plugins=20zeigen=20keine=20Bilder=20an"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #2847

Merge request studip/studip!1934
---
 app/controllers/course/contentmodules.php | 28 +++++++++++++++++++++++
 app/views/course/contentmodules/info.php  | 12 +++++-----
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/app/controllers/course/contentmodules.php b/app/controllers/course/contentmodules.php
index 2e4907a7e25..06d46deab4c 100644
--- a/app/controllers/course/contentmodules.php
+++ b/app/controllers/course/contentmodules.php
@@ -231,6 +231,34 @@ class Course_ContentmodulesController extends AuthenticatedController
     {
         $this->plugin = PluginManager::getInstance()->getPluginById($plugin_id);
         $this->metadata = $this->plugin->getMetadata();
+        $this->screenshots = [];
+
+        if (isset($this->metadata['screenshot'])) {
+            $screenshots = explode('.', $this->metadata['screenshot']);
+            $ext = end($screenshots);
+            $title  = str_replace('_', ' ', basename($this->metadata['screenshot'], ".{$ext}"));
+            $source = "{$this->plugin->getPluginURL()}/{$this->metadata['screenshot']}";
+
+            $this->screenshots[] = compact('title', 'source');
+        }
+        if (isset($this->metadata['additionalscreenshots'])) {
+            foreach ($this->metadata['additionalscreenshots'] as $picture) {
+                $pictures = explode('.', $picture);
+                $ext = end($pictures);
+                $title  = str_replace('_', ' ', basename($picture, ".{$ext}"));
+                $source = "{$this->plugin->getPluginURL()}/{$picture}";
+
+                $this->screenshots[] = compact('title', 'source');
+            }
+        }
+        if (isset($this->metadata['screenshots'])) {
+            foreach ($this->metadata['screenshots']['pictures'] as $picture) {
+                $title  = $picture['title'];
+                $source = "{$this->plugin->getPluginURL()}/{$this->metadata['screenshots']['path']}/{$picture['source']}";
+                $this->screenshots[] = compact('title', 'source');
+            }
+        }
+
         PageLayout::setTitle(sprintf(_('Informationen über %s'), $this->metadata['displayname']));
     }
 
diff --git a/app/views/course/contentmodules/info.php b/app/views/course/contentmodules/info.php
index 5f536eb5e2a..18d7ccf7363 100644
--- a/app/views/course/contentmodules/info.php
+++ b/app/views/course/contentmodules/info.php
@@ -43,15 +43,15 @@
                 <?= formatReady($plugin->getPluginDescription()) ?>
             </div>
         </div>
-        <? if (isset($metadata['screenshots']) && count($metadata['screenshots']['pictures'])) : ?>
+        <? if (isset($screenshots) && count($screenshots)) : ?>
         <ul class="screenshots clean">
-            <? foreach ($metadata['screenshots']['pictures'] as $pictures) : ?>
+            <? foreach ($screenshots as $screenshot) : ?>
             <li>
-                <a href="<?= $plugin->getPluginURL().$metadata['screenshots']['path'].'/'.$pictures['source'] ?>"
+                <a href="<?= htmlReady($screenshot['source']) ?>"
                    data-lightbox="<?= htmlReady($metadata['displayname'] ?? $plugin->getPluginName()) ?>"
-                   data-title="<?= htmlReady($pictures['title']) ?>">
-                    <img src="<?= $plugin->getPluginURL() . ($plugin instanceof StudIPPlugin ? '/' : '') . $metadata['screenshots']['path'] . '/' . $pictures['source'] ?>" alt="">
-                    <?= htmlReady($pictures['title']) ?>
+                   data-title="<?= htmlReady($screenshot['title']) ?>">
+                    <img src="<?= htmlReady($screenshot['source']) ?>" alt="">
+                    <?= htmlReady($screenshot['title']) ?>
                 </a>
             </li>
             <? endforeach ?>
-- 
GitLab