StartpageController.php 6.31 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
     */
18
19
20
21
22
23
24
    /* public function loadStartPage($locale = "de")
    {
    \App::setLocale($locale);
    return view('index', [
    'title' => 'MetaGer: Sicher suchen & finden, Privatsphäre schützen',
    'homeIcon']);
    } */
karl's avatar
karl committed
25

26
    public function loadStartPage(Request $request)
karl's avatar
karl committed
27
28
    {
        $focusPages = [];
Phil Höfer's avatar
Phil Höfer committed
29
        $theme      = "default";
30
        foreach ($request->all() as $key => $value) {
31
            if ($value === 'on' && $key != 'param_sprueche' && $key != 'param_newtab' && $key !== 'param_maps' && $key !== 'param_autocomplete') {
32
                $focusPages[] = str_replace('param_', '', $key);
karl's avatar
karl committed
33
            }
34
35
            if ($key === 'param_theme') {
                $theme = str_replace('param_', '', $key);
36
            }
karl's avatar
karl committed
37
38
        }

Dominik Hebeler's avatar
Dominik Hebeler committed
39
40
41
42
43
        $maps = $request->input('param_maps', 'on');

        $agent   = new Agent();
        $browser = $agent->browser();

karl's avatar
karl committed
44
45
46
47
        return view('index')
            ->with('title', trans('titles.index'))
            ->with('homeIcon')
            ->with('focus', $request->input('focus', 'web'))
48
49
50
51
            ->with('lang', $request->input('param_lang', 'all'))
            ->with('resultCount', $request->input('param_resultCount', '20'))
            ->with('time', $request->input('param_time', '1000'))
            ->with('sprueche', $request->input('param_sprueche', 'off'))
52
            ->with('newtab', $request->input('param_newtab', 'on'))
Dominik Hebeler's avatar
Dominik Hebeler committed
53
54
55
56
57
58
            ->with('focusPages', $focusPages)
            ->with('browser', $browser)
            ->with('navbarFocus', 'suche')
            ->with('theme', $theme)
            ->with('maps', $maps)
            ->with('autocomplete', $request->input('param_autocomplete', 'on'));
59
60
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

Dominik Hebeler's avatar
Dominik Hebeler committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
        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);
179
    }
180
}