StartpageController.php 6.22 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;
Dominik Hebeler's avatar
Dominik Hebeler committed
9
10
11
12
13
14
15
16
17

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

19
    public function loadStartPage(Request $request)
karl's avatar
karl committed
20
21
    {
        $focusPages = [];
Phil Höfer's avatar
Phil Höfer committed
22
        $theme      = "default";
23
        foreach ($request->all() as $key => $value) {
24
25
26
27
28
29
30
31
            if ($value === 'on'
                && $key !== 'meta_sprueche'
                && $key !== 'meta_maps'
                && $key !== 'meta_newtab'
                && $key !== 'meta_lang'
                && $key !== 'request'
                && $key !== 'meta_autocomplete') {
                $focusPages[] = str_replace('meta_', '', $key);
karl's avatar
karl committed
32
            }
33
34
            if ($key === 'meta_theme') {
                $theme = str_replace('meta_', '', $key);
35
            }
karl's avatar
karl committed
36
37
        }

38
        $maps = $request->input('meta_maps', 'on');
39

40
        $agent   = new Agent();
41
42
        $browser = $agent->browser();

karl's avatar
karl committed
43
44
45
46
        return view('index')
            ->with('title', trans('titles.index'))
            ->with('homeIcon')
            ->with('focus', $request->input('focus', 'web'))
47
48
49
50
51
            ->with('lang', $request->input('meta_lang', 'all'))
            ->with('resultCount', $request->input('meta_resultCount', '20'))
            ->with('time', $request->input('meta_time', '1000'))
            ->with('sprueche', $request->input('meta_sprueche', 'off'))
            ->with('tab', $request->input('meta_tab', 'off'))
52
            ->with('focusPages', $focusPages)
53
            ->with('browser', $browser)
54
            ->with('navbarFocus', 'suche')
55
            ->with('theme', $theme)
56
            ->with('maps', $maps)
57
            ->with('autocomplete', $request->input('meta_autocomplete', 'on'));
58
59
    }

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

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

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

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

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

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

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

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

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

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

125
    public function loadSettings(Request $request)
126
127
    {
        $sumaFile = "";
128
        if (App::isLocale('en')) {
129
            $sumaFile = config_path() . "/sumas.xml";
130
        } else {
131
            $sumaFile = config_path() . "/sumas.xml";
132
        }
133

134
        $xml   = simplexml_load_file($sumaFile);
135
136
137
        $sumas = $xml->xpath("suma");

        $foki = [];
138
139
140
        foreach ($sumas as $suma) {
            if ((!isset($suma['disabled']) || $suma['disabled'] === "") && (!isset($suma['userSelectable']) || $suma['userSelectable']->__toString() === "1")) {
                if (isset($suma['type'])) {
141
                    $f = explode(",", $suma['type']->__toString());
142
143
144
145
                    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];
146
                    }
147
148
149
150
                } else {
                    $displayName                                 = $suma['displayName']->__toString();
                    $url                                         = isset($suma['homepage']) ? $suma['homepage']->__toString() : "https://metager.de";
                    $foki["andere"][$suma['name']->__toString()] = ['displayName' => $displayName, 'url' => $url];
151
152
153
154
                }
            }
        }

155
        return view('settings')
156
157
            ->with('foki', $foki)
            ->with('title', 'Einstellungen')
158
159
            ->with('js', ['settings.js'])
            ->with('navbarFocus', 'suche');
160
161
162
163
        die(var_dump($foki));

        return $xml->saveXML();
    }
164
165
166

    public function berlin(Request $request)
    {
Dominik Hebeler's avatar
Dominik Hebeler committed
167
168
        $link     = "";
        $password = "";
169
170
171
172
173
174
175
176
177
178
        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);
    }
179
}