StartpageController.php 4.62 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
41
42
43
44
        $lang = LaravelLocalization::getCurrentLocale();
        if ($lang === 'de') {
            $lang = 'all';
        }

karl's avatar
karl committed
45
46
47
        return view('index')
            ->with('title', trans('titles.index'))
            ->with('homeIcon')
48
49
            ->with('browser', (new Agent())->browser())
            ->with('navbarFocus', 'suche')
karl's avatar
karl committed
50
            ->with('focus', $request->input('focus', 'web'))
51
            ->with('time', $request->input('param_time', '1500'))
52
53
            ->with('request', $request->input('request', 'GET'))
            ->with('option_values', $option_values)
54
55
            ->with('autocomplete', $autocomplete)
            ->with('pluginmodal', $request->input('plugin-modal', 'off'));
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
        $link = action('MetaGerSearch@search', []);
114
115

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

125
    public function loadSettings(Request $request)
126
127
128
129
130
131
132
133
134
135
136
137
138
139
    {
        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 = "";
Dominik Hebeler's avatar
Dominik Hebeler committed
140
        if ($request->filled('eingabe')) {
141
142
143
144
145
146
147
148
149
            $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);
    }
150
}