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

namespace App\Http\Controllers;

5
use App;
Karl Hasselbring's avatar
Karl Hasselbring committed
6
use Illuminate\Http\Request;
7
use Jenssegers\Agent\Agent;
8
use Response;
9
use LaravelLocalization;
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

20
    public function loadStartPage(Request $request)
Karl Hasselbring's avatar
Karl Hasselbring committed
21 22
    {
        $focusPages = [];
Phil Höfer's avatar
Phil Höfer committed
23
        $theme      = "default";
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
        $optionParams = ['param_sprueche', 'param_newtab', 'param_maps', 'param_autocomplete', 'param_lang', 'param_key'];
        $option_values = [];

        foreach ($optionParams as $param) {
            $value = $request->input($param);
            if ($value) {
                $option_values[$param] = $value;
            }
        }

        $autocomplete = 'on';
        if(in_array('autocomplete', array_keys($option_values))) {
            $autocomplete = $option_values['autocomplete'];
        }

40 41 42 43 44
        $lang = LaravelLocalization::getCurrentLocale();
        if ($lang === 'de') {
            $lang = 'all';
        }

Karl Hasselbring's avatar
Karl Hasselbring committed
45 46 47
        return view('index')
            ->with('title', trans('titles.index'))
            ->with('homeIcon')
48 49
            ->with('browser', (new Agent())->browser())
            ->with('navbarFocus', 'suche')
Karl Hasselbring's avatar
Karl Hasselbring committed
50
            ->with('focus', $request->input('focus', 'web'))
51
            ->with('time', $request->input('param_time', '1500'))
52 53 54
            ->with('request', $request->input('request', 'GET'))
            ->with('option_values', $option_values)
            ->with('autocomplete', $autocomplete);
55 56
    }

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

        if (in_array($subpage, $css)) {
65
        return view($subpage, [ 'title' => 'Datenschutz Richtlinien', 'css' => $css[$subpage]]);
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
        $link = action('MetaGerSearch@search', []);
113 114

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

123
    public function loadSettings(Request $request)
124 125 126 127 128 129 130 131 132 133 134 135 136 137
    {
        return view('settings')
            ->with('title', 'Einstellungen')
            ->with('js', ['settings.js'])
            ->with('navbarFocus', 'suche');
        die(var_dump($foki));

        return $xml->saveXML();
    }

    public function berlin(Request $request)
    {
        $link     = "";
        $password = "";
Dominik Hebeler's avatar
Dominik Hebeler committed
138
        if ($request->filled('eingabe')) {
139 140 141 142 143 144 145 146 147
            $password = getenv('berlin');
            $password = md5($request->input('eingabe') . " -host:userpage.fu-berlin.de" . $password);
            $link     = "/meta/meta.ger3?eingabe=" . $request->input('eingabe') . " -host:userpage.fu-berlin.de&focus=web&password=" . $password . "&encoding=utf8&lang=all&site=fu-berlin.de&quicktips=off&out=results-with-style";
        }
        return view('berlin')
            ->with('title', 'Testseite für die FU-Berlin')
            ->with('link', $link)
            ->with('password', $password);
    }
148
}