aboutsummaryrefslogtreecommitdiff
path: root/lib/navigation/FooterNavigation.php
blob: 4319c971ae0f01bdad95f6fe0a6ff64a170ea171 (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
<?php
/*
 * FooterNavigation.php - navigation for the footer on every page
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @author      Michael Riehemann <michael.riehemann@uni-oldenburg.de>
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 * @since       2.1
 */

class FooterNavigation extends Navigation
{
    /**
     * Initialize a new Navigation instance.
     */
    public function __construct()
    {
        parent::__construct(_('Footer'));
    }

    public function initSubNavigation()
    {
        parent::initSubNavigation();

        // imprint
        $this->addSubNavigation('siteinfo', new Navigation(_('Impressum'), 'dispatch.php/siteinfo/show?cancel_login=1'));

        // sitemap
        if (is_object($GLOBALS['user']) && $GLOBALS['user']->id !== 'nobody') {
            $this->addSubNavigation('sitemap', new Navigation(_('Sitemap'), 'dispatch.php/sitemap/'));
        }

        //studip
        $this->addSubNavigation('studip', new Navigation(_('Stud.IP'), 'http://www.studip.de/'));

        // Datenschutzerklärung

        $privacy_url = Config::get()->PRIVACY_URL;
        if ($this->checkSiteinfoURL($privacy_url)) {
            $this->addSubNavigation(
                'privacy',
                new Navigation(
                    _('Datenschutzerklärung'),
                    URLHelper::getURL($privacy_url, ['cancel_login' => 1], true)
                )
            );
        }

        $a11yurl = Config::get()->ACCESSIBILITY_DISCLAIMER_URL;
        if ($this->checkSiteinfoURL($a11yurl)) {
            $this->addSubNavigation(
                'a11ydisclaimer',
                new Navigation(
                    _('Barrierefreiheitserklärung'),
                    URLHelper::getURL($a11yurl, ['cancel_login' => 1], true)
                )
            );
        }

        if (
            Config::get()->REPORT_BARRIER_MODE === 'on'
            || (
                Config::get()->REPORT_BARRIER_MODE === 'logged-in'
                && User::findCurrent()
            )
        ) {
            $url = Request::url();

            // Remove 'page' parameter if the page links to itself
            if (str_contains($url, 'dispatch.php/accessibility/forms/report_barrier')) {
                $url = URLHelper::getURL($url, ['page' => null], true);
            }

            $this->addSubNavigation(
                'report_barrier',
                new Navigation(
                    _('Barriere melden'),
                    URLHelper::getURL(
                        'dispatch.php/accessibility/forms/report_barrier',
                        ['page' => $url, 'cancel_login' => '1']
                    )
                )
            );
        }

        $easy_read_url = Config::get()->EASY_READ_URL;
        if ($this->checkSiteinfoURL($easy_read_url)) {
            $this->addSubNavigation(
                'easy_read',
                new Navigation(
                    _('Leichte Sprache'),
                    URLHelper::getURL($easy_read_url, ['cancel_login' => 1], true)
                )
            );
        }
    }

    private function checkSiteinfoURL($url)
    {
        if (str_starts_with($url, 'dispatch.php/siteinfo')) {
            $url_parts = explode('/', $url);
            $detail_id = $url_parts[4];
            $si = new Siteinfo();
            $detail = $si->get_detail($detail_id);
            if (empty($detail) || !empty($detail['draft_status']) || (!empty($detail['page_disabled_nobody']) && $GLOBALS['user']->id === 'nobody')) {
                return '';
            }
        }
        return $url;
    }
}