aboutsummaryrefslogtreecommitdiff
path: root/templates/layouts/base.php
blob: f3e0ae398fcbd71aa9d6c6dc986da000abee0d29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
NotificationCenter::postNotification('PageWillRender', PageLayout::getBodyElementId());
$getInstalledLanguages = function () {
    $languages = [];
    foreach ($GLOBALS['INSTALLED_LANGUAGES'] as $key => $value) {
        $languages[$key] = array_merge(
            $value,
            ['selected' => $_SESSION['_language'] === $key]
        );
    }

    return $languages;
};

$getJsonApiSchemas = function () {
    return array_values(
        array_unique(
            array_map(
                fn($class) => $class::TYPE,
                app('json-api-integration-schemas')
            )
        )
    );
};

$htmlAttributes = HTMLAttributes::from([
    'lang'              => str_replace('_', '-', $_SESSION['_language']),
    'class'             => 'no-js',
    'data--a11y-motion' => match (User::findCurrent()?->getConfiguration()->getValue('A11Y_USER_REDUCE_ANIMATIONS')) {
        'yes' => 'reduce',
        'no'  => 'allow',
        default => 'no-preference',
    }
]);
?>
<!DOCTYPE html>
<html <?= $htmlAttributes ?>>
<head>
    <meta charset="utf-8">
    <title data-original="<?= htmlReady(PageLayout::getTitle()) ?>">
        <?= htmlReady(PageLayout::getTitle() . ' - ' . Config::get()->UNI_NAME_CLEAN) ?>
    </title>
    <script>
        CKEDITOR_BASEPATH = "<?= Assets::url('javascripts/ckeditor/') ?>";
        String.locale = "<?= htmlReady(strtr($_SESSION['_language'], '_', '-')) ?>";

        document.querySelector('html').classList.replace('no-js', 'js');

        window.STUDIP = {
            ABSOLUTE_URI_STUDIP: "<?= $GLOBALS['ABSOLUTE_URI_STUDIP'] ?>",
            ASSETS_URL: "<?= $GLOBALS['ASSETS_URL'] ?>",
            CSRF_TOKEN: {
                name: '<?=CSRFProtection::TOKEN?>',
                value: '<? try {echo CSRFProtection::token();} catch (SessionRequiredException $e){}?>'
            },
            INSTALLED_LANGUAGES: <?= json_encode($getInstalledLanguages()) ?>,
            CONTENT_LANGUAGES: <?= json_encode(array_keys($GLOBALS['CONTENT_LANGUAGES'])) ?>,
            STUDIP_SHORT_NAME: "<?= htmlReady(Config::get()->STUDIP_SHORT_NAME) ?>",
            URLHelper: {
                base_url: "<?= $GLOBALS['ABSOLUTE_URI_STUDIP'] ?>",
                parameters: <?= json_encode(URLHelper::getLinkParams(), JSON_FORCE_OBJECT) ?>
            },
            USER_ID: <?= json_encode($GLOBALS['user']->id) ?>,
            jsupdate_enable: <?= json_encode(
                             is_object($GLOBALS['perm']) &&
                             $GLOBALS['perm']->have_perm('autor')) ?>,
            server_timestamp: <?= time() ?>,
            config: <?= json_encode([
                'ACTIONMENU_THRESHOLD' => Config::get()->ACTION_MENU_THRESHOLD,
                'ENTRIES_PER_PAGE'     => Config::get()->ENTRIES_PER_PAGE,
                'OPENGRAPH_ENABLE'     => Config::get()->OPENGRAPH_ENABLE,
                'COURSEWARE_CERTIFICATES_ENABLE' => Config::get()->COURSEWARE_CERTIFICATES_ENABLE,
                'ENABLE_COURSESET_FCFS' => (bool) Config::get()->ENABLE_COURSESET_FCFS
            ]) ?>,
            jsonapi_schemas: <?= json_encode($getJsonApiSchemas()) ?>,
        }
    </script>

    <?= PageLayout::getHeadElements() ?>

    <script>
        setTimeout(() => {
            // This needs to be put in a timeout since otherwise it will not match
            if (STUDIP.Responsive.isResponsive()) {
                document.querySelector('html').classList.add('responsive-display');
            }
        }, 0);
    </script>
</head>

<body id="<?= PageLayout::getBodyElementId() ?>" <? if (!PageLayout::isSidebarEnabled()) echo 'class="no-sidebar"'; ?>>
    <nav id="skip_link_navigation" aria-busy="true"></nav>
    <?= PageLayout::getBodyElements() ?>

    <? include 'lib/include/header.php' ?>

    <? if (PageLayout::isSidebarEnabled()): ?>
        <?= Sidebar::get()->render() ?>
    <? endif; ?>

    <!-- Start main page content -->
    <main id="content-wrapper">
        <? SkipLinks::addIndex(_('Hauptinhalt'), 'content', 100) ?>
        <div id="content">
            <h1 class="sr-only"><?= htmlReady(PageLayout::getTitle()) ?></h1>
            <? if (PageLayout::isFullscreenModeAllowed()): ?>
                <button hidden class="fullscreen-toggle unfullscreen" aria-label="<?= _('Vollbildmodus verlassen') ?>" title="<?= _('Vollbildmodus verlassen') ?>">
                    <?= Icon::create('zoom-out2')->asSvg(24) ?>
                </button>
            <? endif; ?>
            <?= implode(PageLayout::getMessages(QuestionBox::class)) ?>
            <?= $content_for_layout ?>
        </div>
        <?= Studip\VueApp::create('SystemNotificationManager')
            ->withProps([
                'id'            => 'system-notifications',
                'notifications' => PageLayout::getMessages(MessageBox::class),
                'placement'     => User::findCurrent()?->getConfiguration()->SYSTEM_NOTIFICATIONS_PLACEMENT ?? 'topcenter',
            ]) ?>
    </main>
    <!-- End main content -->

    <a id="scroll-to-top" class="hide" tabindex="0" title="<?= _('Zurück zum Seitenanfang') ?>">
        <?= Icon::create('arr_1up', 'info_alt')->asSvg(24, ['class' => '']) ?>
    </a>

    <?= $this->render_partial('footer', ['link_params' => $header_template->link_params ?? null]); ?>
    <?= SkipLinks::getHTML() ?>
    <section class="sr-only" id="notes_for_screenreader" aria-live="polite"></section>

<?php
if (Studip\Debug\DebugBar::isActivated()) {
    echo app()->get(\DebugBar\DebugBar::class)->getJavascriptRenderer()->render();
}
?>
</body>
</html>
<?php NotificationCenter::postNotification('PageDidRender', PageLayout::getBodyElementId());