BingBilder.php 2.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
<?php

namespace app\Models\parserSkripte;

use App\Models\Searchengine;
use Log;

class BingBilder extends Searchengine
{
    public $results = [];

12
    public function __construct($name, \stdClass $engine, \App\MetaGer $metager)
13
    {
14
        parent::__construct($name, $engine, $metager);
15
16
17
18
19
20
    }

    public function loadResults($result)
    {
        try {
            $results = json_decode($result);
21
            $this->totalResults = $results->totalEstimatedMatches;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
            $results = $results->value;

            foreach ($results as $result) {
                $title = $result->name;
                $link = $result->hostPageUrl;
                $anzeigeLink = $link;
                $descr = "";
                $image = $result->thumbnailUrl;
                $this->counter++;
                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $anzeigeLink,
                    $descr,
37
38
                    $this->engine->{"display-name"},
                    $this->engine->homepage,
39
                    $this->counter,
40
41
42
43
44
45
46
                    [
                        'image' => $image,
                        'imagedimensions' => [
                            "width" => $result->width,
                            "height" => $result->height
                        ]
                    ]
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
                );
            }
        } catch (\Exception $e) {
            Log::error("A problem occurred parsing results from $this->name:");
            Log::error($e->getMessage());
            return;
        }
    }

    public function getNext(\App\MetaGer $metager, $result)
    {
        try {
            $results = json_decode($result);

            $totalMatches = $results->totalEstimatedMatches;
            $nextOffset = $results->nextOffset;

            if ($nextOffset >= $totalMatches) {
                return;
            }

68
69
70
            $newEngine = unserialize(serialize($this->engine));
            $newEngine->{"get-parameter"}->offset = $nextOffset;
            $next = new BingBilder($this->name, $newEngine, $metager);
71
72
73
74
75
76
            $this->next = $next;
        } catch (\Exception $e) {
            Log::error("A problem occurred parsing results from $this->name:");
            Log::error($e->getMessage());
            return;
        }
77
78
79
80
81
82
    }

    public static function generateThumbnailUrl(\App\Models\Result $result)
    {
        $url = $result->image;

Dominik Hebeler's avatar
Dominik Hebeler committed
83
        $newHeight = 150;
84
85
86
87
88
89
90

        $requestDataBing = [
            "h" => $newHeight,
        ];

        $requestDataBing = http_build_query($requestDataBing, "", "&", PHP_QUERY_RFC3986);
        $url .= "&" . $requestDataBing;
91

92
93
94
        $requestData = [];
        $requestData["url"] = $url;
        $link = action('Pictureproxy@get', $requestData);
Dominik Hebeler's avatar
Dominik Hebeler committed
95
        return $link;
96
97
    }
}