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

namespace App\Http\Controllers;

5
use App;
6
use DB;
karl's avatar
karl committed
7
use Illuminate\Http\Request;
8
use Jenssegers\Agent\Agent;
9
use LaravelLocalization;
10
use Log;
11
use Response;
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
        $optionParams = ['param_sprueche', 'param_newtab', 'param_maps', 'param_autocomplete', 'param_lang', 'param_key'];
28
29
30
31
32
33
34
35
36
37
        $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
        # Sponsorenlinks
        $sponsors = [];
49
        try {
50
            $sponsors = DB::table('sponsorenlinks')->where('langcode', 'de')->orderByRaw('LENGTH(linktext)', 'ASC')->get();
Dominik Hebeler's avatar
Dominik Hebeler committed
51
            DB::disconnect('mysql');
52
        } catch (\Illuminate\Database\QueryException $e) {
53
54
            Log::info($e);
        }
55

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

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

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

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

91
    public function loadPlugin($locale = "de")
92
    {
93
        $link = action('MetaGerSearch@search', []);
94
95

        $response = Response::make(
96
97
            view('plugin')
                ->with('link', $link)
98
                ->with('hostname', gethostname())
99
            , "200");
100
        $response->header('Content-Type', "application/opensearchdescription+xml");
101
102
        return $response;
    }
103

104
105
    public function berlin(Request $request)
    {
106
        $link = "";
107
        $password = "";
Dominik Hebeler's avatar
Dominik Hebeler committed
108
        if ($request->filled('eingabe')) {
109
110
            $password = getenv('berlin');
            $password = md5($request->input('eingabe') . " -host:userpage.fu-berlin.de" . $password);
111
            $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";
112
113
114
115
116
117
        }
        return view('berlin')
            ->with('title', 'Testseite für die FU-Berlin')
            ->with('link', $link)
            ->with('password', $password);
    }
118
}