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

namespace App\Http\Controllers;

5
use App;
6
use App\MetaGer;
7
use Illuminate\Http\Request;
Phil Höfer's avatar
Phil Höfer committed
8
use LaravelLocalization;
Dominik Hebeler's avatar
Dominik Hebeler committed
9
10
11

class MetaGerSearch extends Controller
{
12
    public function search(Request $request, MetaGer $metager)
13
    {
14
        $focus = $request->input("focus", "web");
15
16
17
18
19
20
        
        if ($focus === "maps") {
            $searchinput = $request->input('eingabe', '');
            return redirect()->to('https://maps.metager.de/map/' . $searchinput . '/1240908.5493525574,6638783.2192695495,6');
        }

21
        /*if ($focus !== "angepasst" && $this->startsWith($focus, "focus_")) {
22
23
            $metager->parseFormData($request);
            return $metager->createView();
24
25
        }*/

26
        #die($request->header('User-Agent'));
27
        $time = microtime();
28
29
        # Mit gelieferte Formulardaten parsen und abspeichern:
        $metager->parseFormData($request);
30

31
32
        # Nach Spezialsuchen überprüfen:
        $metager->checkSpecialSearches($request);
33

34
35
        # Alle Suchmaschinen erstellen
        $metager->createSearchEngines($request);
36

37
38
39
        # Alle Ergebnisse vor der Zusammenführung ranken:
        $metager->rankAll();

40
        # Ergebnisse der Suchmaschinen kombinieren:
Phil Höfer's avatar
Phil Höfer committed
41
        $metager->prepareResults();
42

43
44
        # Die Ausgabe erstellen:
        return $metager->createView();
Dominik Hebeler's avatar
Dominik Hebeler committed
45
46
    }

47
48
49
50
51
52
53
54
    public function botProtection($redirect)
    {
        $hash = md5(date('YmdHi'));
        return view('botProtection')
            ->with('hash', $hash)
            ->with('r', $redirect);
    }

55
56
    public function get($url)
    {
57
58
	   $ctx = stream_context_create(array('http'=>array('timeout' => 2,)));
        return file_get_contents($url, false, $ctx);
59
    }
60
61
62
63
64
65

    private function startsWith($haystack, $needle)
    {
        $length = strlen($needle);
        return (substr($haystack, 0, $length) === $needle);
    }
66
}