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

namespace App\Http\Controllers;

karl's avatar
karl committed
5
use Illuminate\Http\Request;
6
use Jenssegers\Agent\Agent;
Dominik Hebeler's avatar
Dominik Hebeler committed
7
8
9
10
11
12
13
14
15

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

24
    public function loadStartPage(Request $request)
karl's avatar
karl committed
25
26
    {
        $focusPages = [];
27
        $theme      = "none";
28
29
30
        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
31
            }
32
33
34
            if ($key === 'param_theme') {
                $theme = str_replace('param_', '', $key);
            }
karl's avatar
karl committed
35
36
        }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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