From e3f61de1f8d1188e233ca5d0e6a6bd3728f8cd4b Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Tue, 14 Feb 2023 08:58:09 +0000
Subject: [PATCH] fix display of portal plugins for nobody and set function as
 deprecated, fixes #2051

Closes #2051

Merge request studip/studip!1330
---
 public/index.php                              | 38 +++++++++----------
 resources/assets/stylesheets/scss/index.scss  | 26 ++++++++-----
 .../assets/stylesheets/scss/responsive.scss   |  5 +--
 templates/index_nobody.php                    | 22 +++++++++--
 templates/shared/index_box.php                | 24 +++++++-----
 5 files changed, 69 insertions(+), 46 deletions(-)

diff --git a/public/index.php b/public/index.php
index c36681d413b..4cc7a8721f3 100644
--- a/public/index.php
+++ b/public/index.php
@@ -77,6 +77,23 @@ PageLayout::setTabNavigation(NULL); // disable display of tabs
 include 'lib/include/html_head.inc.php'; // Output of html head
 include 'lib/include/header.php';
 
+// Prüfen, ob PortalPlugins vorhanden sind.
+// TODO: Remove for Stud.IP 6.0
+/** @deprecated */
+$portalplugins = PluginEngine::getPlugins('PortalPlugin');
+$layout = $GLOBALS['template_factory']->open('shared/index_box');
+
+$plugin_contents = [];
+foreach ($portalplugins as $portalplugin) {
+    $template = $portalplugin->getPortalTemplate();
+
+    if ($template) {
+        $plugin_contents[] = $template->render(NULL, $layout);
+        $layout->clear_attributes();
+    }
+}
+
+
 $index_nobody_template = $GLOBALS['template_factory']->open('index_nobody');
 $cache = StudipCacheFactory::getCache();
 $stat = $cache->read('LOGINFORM_STATISTICS');
@@ -88,29 +105,12 @@ if (!is_array($stat)) {
 }
 $index_nobody_template->set_attributes(array_merge($stat, [
     'num_online_users' => get_users_online_count(),
+    'plugin_contents'  => $plugin_contents,
+    'logout'           =>  Request::bool('logout'),
 ]));
 
-if (Request::get('logout'))
-{
-    $index_nobody_template->set_attribute('logout', true);
-}
-
 echo $index_nobody_template->render();
 
-$layout = $GLOBALS['template_factory']->open('shared/index_box');
-
-// Prüfen, ob PortalPlugins vorhanden sind.
-$portalplugins = PluginEngine::getPlugins('PortalPlugin');
-
-foreach ($portalplugins as $portalplugin) {
-    $template = $portalplugin->getPortalTemplate();
-
-    if ($template) {
-        echo $template->render(NULL, $layout);
-        $layout->clear_attributes();
-    }
-}
-
 page_close();
 
 include 'lib/include/html_end.inc.php';
diff --git a/resources/assets/stylesheets/scss/index.scss b/resources/assets/stylesheets/scss/index.scss
index c5e00599e49..b260e4ed041 100644
--- a/resources/assets/stylesheets/scss/index.scss
+++ b/resources/assets/stylesheets/scss/index.scss
@@ -2,6 +2,9 @@ body {
     min-height: 100%;
 }
 
+$login-page-margin: 50px;
+$gap-between-boxes: ($login-page-margin / 2);
+
 #main-header {
     grid-column: 1 / 3;
     grid-row: 1 / 1;
@@ -26,11 +29,16 @@ body {
     z-index: -1;
 }
 
+#index,
+#login {
+    #content {
+        padding: $login-page-margin;
+    }
+}
+
 #loginbox {
     background-color: rgba(255, 255, 255, 0.8);
     box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.5);
-    margin-left: 50px;
-    margin-top: 50px;
     padding: 20px;
     width: 450px;
 
@@ -91,12 +99,6 @@ body {
 
             a {
                 text-decoration: underline;
-                color: $base-color;
-
-                &:hover, &:focus {
-                    font-size: 1em;
-                    color: $red;
-                }
             }
         }
 
@@ -113,12 +115,16 @@ body {
                 }
             }
         }
-        & > a {
+        > a {
             margin-left: 12px;
         }
     }
 }
 
+#login-plugin-contents {
+    margin-top: $gap-between-boxes;
+}
+
 #index,
 #login {
 
@@ -127,7 +133,7 @@ body {
     }
 
     .messagebox {
-        margin: 50px 0 -25px 50px;
+        margin-bottom: $gap-between-boxes;
         width: 418px;
     }
 }
diff --git a/resources/assets/stylesheets/scss/responsive.scss b/resources/assets/stylesheets/scss/responsive.scss
index 9267c8dd016..f52c1d6be09 100644
--- a/resources/assets/stylesheets/scss/responsive.scss
+++ b/resources/assets/stylesheets/scss/responsive.scss
@@ -859,10 +859,9 @@ html:not(.responsive-display):not(.fullscreen-mode) {
                 display: none;
             }
 
-            main {
+            #content {
                 margin: 0;
                 padding: 0;
-                width: calc(100% - 10px);
 
                 .messagebox {
                     margin: 0;
@@ -951,5 +950,3 @@ html:not(.responsive-display):not(.fullscreen-mode) {
         max-width: 100vw;
     }
 }
-
-
diff --git a/templates/index_nobody.php b/templates/index_nobody.php
index b922822c2c5..c528d47b4e0 100644
--- a/templates/index_nobody.php
+++ b/templates/index_nobody.php
@@ -1,5 +1,11 @@
 <?php
-# Lifter010: TODO
+/**
+ * @var int $num_active_courses
+ * @var int $num_registered_users
+ * @var int $num_online_users
+ * @var bool $logout
+ * @var string[] $plugin_contents
+ */
 
 // Get background images (this should be resolved differently since mobile
 // browsers might still download the desktop background)
@@ -18,9 +24,9 @@ if ($bg_mobile) {
 ?>
 <!-- Startseite (nicht eingeloggt) -->
 <main id="content">
-    <? if (!empty($logout)) : ?>
-        <?= MessageBox::success(_('Sie sind nun aus dem System abgemeldet.'), array_filter([$GLOBALS['UNI_LOGOUT_ADD']])) ?>
-    <? endif; ?>
+<? if ($logout): ?>
+    <?= MessageBox::success(_('Sie sind nun aus dem System abgemeldet.'), array_filter([$GLOBALS['UNI_LOGOUT_ADD']])) ?>
+<? endif; ?>
 
     <div id="background-desktop" style="background: url(<?= $bg_desktop ?>) no-repeat top left/cover;"></div>
     <div id="background-mobile" style="background: url(<?= $bg_mobile ?>) no-repeat top left/cover;"></div>
@@ -103,4 +109,12 @@ if ($bg_mobile) {
             </div>
         </footer>
     </article>
+
+<? if (count($plugin_contents) > 0): ?>
+    <div id="login-plugin-contents">
+    <? foreach ($plugin_contents as $content): ?>
+        <?= $content ?>
+    <? endforeach; ?>
+    </div>
+<? endif; ?>
 </main>
diff --git a/templates/shared/index_box.php b/templates/shared/index_box.php
index 3e93488c898..34300564f01 100644
--- a/templates/shared/index_box.php
+++ b/templates/shared/index_box.php
@@ -1,9 +1,13 @@
-<?
-# Lifter010: TODO
+<?php
+/**
+ * @var string $content_for_layout
+ * @var string|null $icon_url
+ * @var string $title
+ * @var string|null $admin_url
+ * @var string|null $admin_title
+ */
 ?>
 <? if ($content_for_layout != ''): ?>
-    <? if (!isset($admin_title)) $admin_title = _('Administration') ?>
-
     <table class="index_box">
         <tr>
             <td class="table_header_bold" style="font-weight: bold;">
@@ -14,11 +18,13 @@
             </td>
 
             <td class="table_header_bold" style="text-align: right;">
-                <? if (isset($admin_url)): ?>
-                    <a href="<?= URLHelper::getLink($admin_url) ?>" title="<?= htmlReady($admin_title) ?>">
-                        <?= Icon::create('admin', 'info_alt')->asImg(16, ["alt" => htmlReady($admin_title)]) ?>
-                    </a>
-                <? endif ?>
+            <? if (isset($admin_url)): ?>
+                <a href="<?= URLHelper::getLink($admin_url) ?>" title="<?= htmlReady($admin_title ?? _('Administration')) ?>">
+                    <?= Icon::create('admin', Icon::ROLE_INFO_ALT)->asImg([
+                        'alt' => $admin_title ??  ('Administration'),
+                    ]) ?>
+                </a>
+            <? endif ?>
             </td>
         </tr>
 
-- 
GitLab