StartpageController.php 6.35 KB
Newer Older
Dominik Hebeler's avatar
Dominik Hebeler committed
1
2
3
4
<?php

namespace App\Http\Controllers;

5
use App;
karl's avatar
karl committed
6
use Illuminate\Http\Request;
7
use Jenssegers\Agent\Agent;
8
use Response;
9
use LaravelLocalization;
Dominik Hebeler's avatar
Dominik Hebeler committed
10
11
12
13
14
15
16
17
18

class StartpageController extends Controller
{
    /**
     * Load Startpage accordingly to the given URL-Parameter and Mobile
     *
     * @param  int  $id
     * @return Response
     */
karl's avatar
karl committed
19

20
    public function loadStartPage(Request $request)
karl's avatar
karl committed
21
22
    {
        $focusPages = [];
Phil Höfer's avatar
Phil Höfer committed
23
        $theme      = "default";
24

25
        foreach ($request->all() as $key => $value) {
26
            if ($value === 'on' && $key != 'param_sprueche' && $key != 'param_newtab' && $key !== 'param_maps' && $key !== 'param_autocomplete') {
27
                $focusPages[] = str_replace('param_', '', $key);
karl's avatar
karl committed
28
            }
29
30
            if ($key === 'param_theme') {
                $theme = str_replace('param_', '', $key);
31
            }
karl's avatar
karl committed
32
33
        }

34
35
36
37
38
        $lang = LaravelLocalization::getCurrentLocale();
        if ($lang === 'de') {
            $lang = 'all';
        }

karl's avatar
karl committed
39
40
41
        return view('index')
            ->with('title', trans('titles.index'))
            ->with('homeIcon')
42
43
44
45
46
47
            ->with('focusPages', $focusPages)
            ->with('browser', (new Agent())->browser())
            ->with('navbarFocus', 'suche')
            ->with('theme', $theme)
            ->with('autocomplete', $request->input('param_autocomplete', 'on'))
            ->with('foki', $this->loadFoki())
karl's avatar
karl committed
48
            ->with('focus', $request->input('focus', 'web'))
49
            ->with('lang', $lang)
50
            ->with('resultCount', $request->input('param_resultCount', '20'))
51
52
            ->with('time', $request->input('param_time', '1500'))
            ->with('sprueche', $request->input('param_sprueche', 'on'))
53
            ->with('newtab', $request->input('param_newtab', 'on'))
Karl Hasselbring's avatar
   
Karl Hasselbring committed
54
55
            ->with('maps', $maps = $request->input('param_maps', 'off'))
            ->with('key', $request->input('param_key', ''));
56
57
    }

karl's avatar
karl committed
58
    public function loadPage($subpage)
59
    {
karl's avatar
karl committed
60
61
        /* TODO CSS und Titel laden
        $css = array(
62
        'datenschutz' => 'privacy.css',
karl's avatar
karl committed
63
64
65
        );

        if (in_array($subpage, $css)) {
66
        return view($subpage, [ 'title' => 'Datenschutz Richtlinien', 'css' => $css[$subpage]]);
karl's avatar
karl committed
67
        } else {
68
        return view($subpage, [ 'title' => 'Datenschutz Richtlinien']);
69
70
        }*/
        return view($subpage, ['title' => 'Datenschutz Richtlinien']);
71
72
73
74
75
76
    }

    public function loadLocalPage($locale = "de", $subpage = "datenschutz")
    {
        \App::setLocale($locale);
        return loadPage($subpage);
Dominik Hebeler's avatar
Dominik Hebeler committed
77
    }
78

79
    public function loadPlugin($params, $locale = "de")
80
    {
81
        $params   = unserialize(base64_decode($params));
82
        $requests = $params;
83
84
85
86
        $params   = [];
        foreach ($requests as $key => $value) {
            if (strpos($key, "param_") === 0) {
                $key = substr($key, strpos($key, "param_") + 6);
87
88
89
90
            }
            $params[$key] = $value;
        }

91
        if (!isset($params['focus'])) {
92
            $params['focus'] = 'web';
93
94
95
        }

        if (!isset($params['encoding'])) {
96
            $params['encoding'] = 'utf8';
97
98
99
        }

        if (!isset($params['lang'])) {
100
            $params['lang'] = 'all';
101
102
103
104
105
106
107
108
        }

        if (isset($params['request']) && ($params['request'] === "GET" || $params['request'] === "POST")) {
            $request = $params['request'];
        } else {
            $request = "GET";
        }

109
110
111
        array_forget($params, 'eingabe');
        array_forget($params, 'out');
        array_forget($params, 'page');
112
        array_forget($params, 'request');
113
114
115
        $link = action('MetaGerSearch@search', $params);

        $response = Response::make(
116
117
118
            view('plugin')
                ->with('link', $link)
                ->with('request', $request), "200");
119
120
121
        $response->header('Content-Type', "application/xml");
        return $response;
    }
122

123
    public function loadSettings(Request $request)
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    {
        $foki = $this->loadFoki();

        return view('settings')
            ->with('foki', $foki)
            ->with('title', 'Einstellungen')
            ->with('js', ['settings.js'])
            ->with('navbarFocus', 'suche');
        die(var_dump($foki));

        return $xml->saveXML();
    }

    public function berlin(Request $request)
    {
        $link     = "";
        $password = "";
        if ($request->has('eingabe')) {
            $password = getenv('berlin');
            $password = md5($request->input('eingabe') . " -host:userpage.fu-berlin.de" . $password);
            $link     = "/meta/meta.ger3?eingabe=" . $request->input('eingabe') . " -host:userpage.fu-berlin.de&focus=web&password=" . $password . "&encoding=utf8&lang=all&site=fu-berlin.de&quicktips=off&out=results-with-style";
        }
        return view('berlin')
            ->with('title', 'Testseite für die FU-Berlin')
            ->with('link', $link)
            ->with('password', $password);
    }

    private function loadFoki()
153
154
    {
        $sumaFile = "";
155
        if (App::isLocale('en')) {
156
            $sumaFile = config_path() . "/sumas.xml";
157
        } else {
158
            $sumaFile = config_path() . "/sumas.xml";
159
        }
160

161
        $xml   = simplexml_load_file($sumaFile);
162
163
164
        $sumas = $xml->xpath("suma");

        $foki = [];
165
166
167
        foreach ($sumas as $suma) {
            if ((!isset($suma['disabled']) || $suma['disabled'] === "") && (!isset($suma['userSelectable']) || $suma['userSelectable']->__toString() === "1")) {
                if (isset($suma['type'])) {
168
                    $f = explode(",", $suma['type']->__toString());
169
170
171
172
                    foreach ($f as $tmp) {
                        $displayName                             = $suma['displayName']->__toString();
                        $url                                     = isset($suma['homepage']) ? $suma['homepage']->__toString() : "https://metager.de";
                        $foki[$tmp][$suma['name']->__toString()] = ['displayName' => $displayName, 'url' => $url];
173
                    }
174
175
176
177
                } else {
                    $displayName                                 = $suma['displayName']->__toString();
                    $url                                         = isset($suma['homepage']) ? $suma['homepage']->__toString() : "https://metager.de";
                    $foki["andere"][$suma['name']->__toString()] = ['displayName' => $displayName, 'url' => $url];
178
179
180
181
                }
            }
        }

182
        return $foki;
183
    }
184
}