StartpageController.php 4.96 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 LaravelLocalization;
9
use Response;
10
11
use DB;
use Log;
Dominik Hebeler's avatar
Dominik Hebeler committed
12
13
14
15
16
17
18
19
20

class StartpageController extends Controller
{
    /**
     * Load Startpage accordingly to the given URL-Parameter and Mobile
     *
     * @param  int  $id
     * @return Response
     */
karl's avatar
karl committed
21

22
    public function loadStartPage(Request $request)
karl's avatar
karl committed
23
24
    {
        $focusPages = [];
25
        $theme = "default";
26

27
28
29
30
31
32
33
34
35
36
37
        $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';
38
        if (in_array('autocomplete', array_keys($option_values))) {
39
40
41
            $autocomplete = $option_values['autocomplete'];
        }

42
        $lang = LaravelLocalization::getCurrentLocale();
43
        if ($lang === 'de' || $lang === "en") {
44
45
            $lang = 'all';
        }
46
47
48
49
50
51
52
53
        
        # Sponsorenlinks
        $sponsors = [];
        try{
            $sponsors = DB::table('sponsorenlinks')->where('langcode', 'de')->orderByRaw('LENGTH(linktext)', 'ASC')->get();
        } catch(\Illuminate\Database\QueryException $e){
            Log::info($e);
        }
54

karl's avatar
karl committed
55
56
57
        return view('index')
            ->with('title', trans('titles.index'))
            ->with('homeIcon')
58
59
            ->with('browser', (new Agent())->browser())
            ->with('navbarFocus', 'suche')
karl's avatar
karl committed
60
            ->with('focus', $request->input('focus', 'web'))
61
            ->with('time', $request->input('param_time', '1500'))
62
63
            ->with('request', $request->input('request', 'GET'))
            ->with('option_values', $option_values)
64
            ->with('autocomplete', $autocomplete)
65
            ->with('sponsors', $sponsors)
66
            ->with('pluginmodal', $request->input('plugin-modal', 'off'));
67
68
    }

karl's avatar
karl committed
69
    public function loadPage($subpage)
70
    {
karl's avatar
karl committed
71
72
        /* TODO CSS und Titel laden
        $css = array(
73
        'datenschutz' => 'privacy.css',
karl's avatar
karl committed
74
75
76
        );

        if (in_array($subpage, $css)) {
77
        return view($subpage, [ 'title' => 'Datenschutz Richtlinien', 'css' => $css[$subpage]]);
karl's avatar
karl committed
78
        } else {
79
        return view($subpage, [ 'title' => 'Datenschutz Richtlinien']);
80
81
        }*/
        return view($subpage, ['title' => 'Datenschutz Richtlinien']);
82
83
84
85
86
87
    }

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

90
    public function loadPlugin($params, $locale = "de")
91
    {
92
        $params = unserialize(base64_decode($params));
93
        $requests = $params;
94
        $params = [];
95
96
97
        foreach ($requests as $key => $value) {
            if (strpos($key, "param_") === 0) {
                $key = substr($key, strpos($key, "param_") + 6);
98
99
100
101
            }
            $params[$key] = $value;
        }

102
        if (!isset($params['focus'])) {
103
            $params['focus'] = 'web';
104
105
106
        }

        if (!isset($params['encoding'])) {
107
            $params['encoding'] = 'utf8';
108
109
110
        }

        if (!isset($params['lang'])) {
111
            $params['lang'] = 'all';
112
113
114
115
116
117
118
119
        }

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

120
121
122
        array_forget($params, 'eingabe');
        array_forget($params, 'out');
        array_forget($params, 'page');
123
        array_forget($params, 'request');
124
        $link = action('MetaGerSearch@search', []);
125
126

        $response = Response::make(
127
128
            view('plugin')
                ->with('link', $link)
129
                ->with('params', $params)
130
                ->with('hostname', gethostname())
131
                ->with('request', $request), "200");
132
133
134
        $response->header('Content-Type', "application/xml");
        return $response;
    }
135

136
    public function loadSettings(Request $request)
137
138
139
140
141
142
143
144
145
146
147
148
    {
        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)
    {
149
        $link = "";
150
        $password = "";
Dominik Hebeler's avatar
Dominik Hebeler committed
151
        if ($request->filled('eingabe')) {
152
153
            $password = getenv('berlin');
            $password = md5($request->input('eingabe') . " -host:userpage.fu-berlin.de" . $password);
154
            $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";
155
156
157
158
159
160
        }
        return view('berlin')
            ->with('title', 'Testseite für die FU-Berlin')
            ->with('link', $link)
            ->with('password', $password);
    }
161
}