StartpageController.php 5.51 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
    /* public function loadStartPage($locale = "de")
Dominik Hebeler's avatar
Dominik Hebeler committed
19
    {
20
21
22
23
    \App::setLocale($locale);
    return view('index', [
    'title' => 'MetaGer: Sicher suchen & finden, Privatsphäre schützen',
    'homeIcon']);
karl's avatar
karl committed
24
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_tab' && $key !== 'param_maps') {
32
                $focusPages[] = str_replace('param_', '', $key);
karl's avatar
karl committed
33
            }
34
35
36
            if ($key === 'param_theme') {
                $theme = str_replace('param_', '', $key);
            }
karl's avatar
karl committed
37
38
        }

39
40
        $maps = $request->input('param_maps', 'on');

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

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