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;
Dominik Hebeler's avatar
Dominik Hebeler committed
6
use App\Http\Controllers\Controller;
Karl Hasselbring's avatar
Karl Hasselbring 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 Hasselbring's avatar
Karl Hasselbring 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 Hasselbring's avatar
Karl Hasselbring committed
25 26
    } */

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

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

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

59
    public function loadPage($subpage)
60
    {
61 62
        /* TODO CSS und Titel laden
        $css = array(
63
        'datenschutz' => 'privacy.css',
64 65 66
        );

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

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

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

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

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

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

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

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

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

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

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

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

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

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