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

class StartpageController extends Controller
{
    /**
     * Load Startpage accordingly to the given URL-Parameter and Mobile
     *
     * @param  int  $id
     * @return Response
     */
karl's avatar
karl committed
17
    /* public function loadStartPage($locale = "de")
Dominik Hebeler's avatar
Dominik Hebeler committed
18
    {
19
20
21
22
    \App::setLocale($locale);
    return view('index', [
    'title' => 'MetaGer: Sicher suchen & finden, Privatsphäre schützen',
    'homeIcon']);
karl's avatar
karl committed
23
24
    } */

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

38
        $agent   = new Agent();
39
40
        $browser = $agent->browser();

karl's avatar
karl committed
41
42
43
44
45
46
47
48
        return view('index')
            ->with('title', trans('titles.index'))
            ->with('homeIcon')
            ->with('focus', $request->input('focus', 'web'))
            ->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'))
49
            ->with('tab', $request->input('param_tab', 'off'))
50
            ->with('focusPages', $focusPages)
51
            ->with('browser', $browser)
52
            ->with('navbarFocus', 'suche')
53
            ->with('theme', $theme)
54
            ->with('css', 'index.css');
55
56
    }

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

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

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

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

90
        if (!isset($params['focus'])) {
91
            $params['focus'] = 'web';
92
93
94
        }

        if (!isset($params['encoding'])) {
95
            $params['encoding'] = 'utf8';
96
97
98
        }

        if (!isset($params['lang'])) {
99
            $params['lang'] = 'all';
100
101
102
103
104
105
106
107
        }

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

108
109
110
        array_forget($params, 'eingabe');
        array_forget($params, 'out');
        array_forget($params, 'page');
111
        array_forget($params, 'request');
112
113
114
        $link = action('MetaGerSearch@search', $params);

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

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

131
        $xml   = simplexml_load_file($sumaFile);
132
133
134
        $sumas = $xml->xpath("suma");

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

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

        return $xml->saveXML();
    }
161
}