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

namespace App\Http\Controllers;

5
use App;
Dominik Hebeler's avatar
Dominik Hebeler committed
6
use App\Http\Controllers\Controller;
karl's avatar
karl committed
7
use Illuminate\Http\Request;
8
use Jenssegers\Agent\Agent;
9
use Response;
Dominik Hebeler's avatar
Dominik Hebeler committed
10
11
12
13
14
15
16
17
18

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

27
    public function loadStartPage(Request $request)
karl's avatar
karl committed
28
29
    {
        $focusPages = [];
30
31
32
        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
33
34
35
            }
        }

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

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

52
53
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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