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

namespace App\Http\Controllers;

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

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

22
    public function loadStartPage(Request $request)
karl's avatar
karl committed
23
24
    {
        $focusPages = [];
25
        $theme = "default";
26

27
        $optionParams = ['param_sprueche', 'param_newtab', 'param_maps', 'param_autocomplete', 'param_lang', 'param_key'];
28
29
30
31
32
33
34
35
36
37
        $option_values = [];

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

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

42
        $lang = LaravelLocalization::getCurrentLocale();
43
        if ($lang === 'de' || $lang === "en") {
44
45
            $lang = 'all';
        }
46

47
48
        # Sponsorenlinks
        $sponsors = [];
49
        try {
50
            $sponsors = DB::table('sponsorenlinks')->where('langcode', 'de')->orderByRaw('LENGTH(linktext)', 'ASC')->get();
Dominik Hebeler's avatar
Dominik Hebeler committed
51
            DB::disconnect('mysql');
52
        } catch (\Illuminate\Database\QueryException $e) {
53
54
            Log::info($e);
        }
55

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

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

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

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

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

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

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

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

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

121
122
123
        array_forget($params, 'eingabe');
        array_forget($params, 'out');
        array_forget($params, 'page');
124
        array_forget($params, 'request');
125
126
127
128
        array_forget($params, 'focus');
        array_forget($params, 'encoding');
        array_forget($params, 'lang');

129
        $link = action('MetaGerSearch@search', []);
130
131

        $response = Response::make(
132
133
            view('plugin')
                ->with('link', $link)
134
                ->with('params', $params)
135
                ->with('hostname', gethostname())
136
                ->with('request', $request), "200");
137
        $response->header('Content-Type', "application/opensearchdescription+xml");
138
139
        return $response;
    }
140

141
    public function loadSettings(Request $request)
142
143
144
145
146
147
148
149
150
151
152
153
    {
        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)
    {
154
        $link = "";
155
        $password = "";
Dominik Hebeler's avatar
Dominik Hebeler committed
156
        if ($request->filled('eingabe')) {
157
158
            $password = getenv('berlin');
            $password = md5($request->input('eingabe') . " -host:userpage.fu-berlin.de" . $password);
159
            $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";
160
161
162
163
164
165
        }
        return view('berlin')
            ->with('title', 'Testseite für die FU-Berlin')
            ->with('link', $link)
            ->with('password', $password);
    }
166
}