StartpageController.php 4.85 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
        $optionParams = ['param_sprueche', 'param_newtab', 'param_maps', 'param_autocomplete', 'param_lang', 'param_key'];
        $option_values = [];

        foreach ($optionParams as $param) {
            $value = $request->input($param);
            if ($value) {
                $option_values[$param] = $value;
            }
        }

        $autocomplete = 'on';
        if(in_array('autocomplete', array_keys($option_values))) {
            $autocomplete = $option_values['autocomplete'];
        }

40
        foreach ($request->all() as $key => $value) {
41
            if ($value === 'on' && !in_array($key, $optionParams)) {
42
                $focusPages[] = str_replace('param_', '', $key);
karl's avatar
karl committed
43
            }
44
45
            if ($key === 'param_theme') {
                $theme = str_replace('param_', '', $key);
46
            }
karl's avatar
karl committed
47
48
        }

49
50
51
52
53
        $lang = LaravelLocalization::getCurrentLocale();
        if ($lang === 'de') {
            $lang = 'all';
        }

karl's avatar
karl committed
54
55
56
        return view('index')
            ->with('title', trans('titles.index'))
            ->with('homeIcon')
57
58
59
60
            ->with('focusPages', $focusPages)
            ->with('browser', (new Agent())->browser())
            ->with('navbarFocus', 'suche')
            ->with('theme', $theme)
karl's avatar
karl committed
61
            ->with('focus', $request->input('focus', 'web'))
62
            ->with('time', $request->input('param_time', '1500'))
63
64
65
            ->with('request', $request->input('request', 'GET'))
            ->with('option_values', $option_values)
            ->with('autocomplete', $autocomplete);
66
67
    }

karl's avatar
karl committed
68
    public function loadPage($subpage)
69
    {
karl's avatar
karl committed
70
71
        /* TODO CSS und Titel laden
        $css = array(
72
        'datenschutz' => 'privacy.css',
karl's avatar
karl committed
73
74
75
        );

        if (in_array($subpage, $css)) {
76
        return view($subpage, [ 'title' => 'Datenschutz Richtlinien', 'css' => $css[$subpage]]);
karl's avatar
karl committed
77
        } else {
78
        return view($subpage, [ 'title' => 'Datenschutz Richtlinien']);
79
80
        }*/
        return view($subpage, ['title' => 'Datenschutz Richtlinien']);
81
82
83
84
85
86
    }

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

89
    public function loadPlugin($params, $locale = "de")
90
    {
91
        $params   = unserialize(base64_decode($params));
92
        $requests = $params;
93
94
95
96
        $params   = [];
        foreach ($requests as $key => $value) {
            if (strpos($key, "param_") === 0) {
                $key = substr($key, strpos($key, "param_") + 6);
97
98
99
100
            }
            $params[$key] = $value;
        }

101
        if (!isset($params['focus'])) {
102
            $params['focus'] = 'web';
103
104
105
        }

        if (!isset($params['encoding'])) {
106
            $params['encoding'] = 'utf8';
107
108
109
        }

        if (!isset($params['lang'])) {
110
            $params['lang'] = 'all';
111
112
113
114
115
116
117
118
        }

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

119
120
121
        array_forget($params, 'eingabe');
        array_forget($params, 'out');
        array_forget($params, 'page');
122
        array_forget($params, 'request');
123
124
125
        $link = action('MetaGerSearch@search', $params);

        $response = Response::make(
126
127
128
            view('plugin')
                ->with('link', $link)
                ->with('request', $request), "200");
129
130
131
        $response->header('Content-Type', "application/xml");
        return $response;
    }
132

133
    public function loadSettings(Request $request)
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
    {
        return view('settings')
            ->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);
    }
158
}