Openclipart.php 2.09 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

5
use App\Models\Searchengine;
6
use Log;
7

8
class Openclipart extends Searchengine
9
{
10
11
12
13
14
15
    public $results = [];

    public function __construct(\SimpleXMLElement $engine, \App\MetaGer $metager)
    {
        parent::__construct($engine, $metager);
    }
16

17
18
19
20
21
    public function loadResults($result)
    {
        $result = preg_replace("/\r\n/si", "", $result);
        try {
            $content = json_decode($result);
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
            if (!$content) {
                return;
            }

            $results = $content->payload;
            foreach ($results as $result) {
                $title       = $result->title;
                $link        = $result->detail_link;
                $anzeigeLink = $link;
                $descr       = $result->description;
                $image       = $result->svg->png_thumb;
                $this->counter++;
                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $anzeigeLink,
                    $descr,
                    $this->gefVon,
                    $this->counter,
                    false,
                    $image
                );
            }
46
        } catch (\Exception $e) {
47
            Log::error("A problem occurred parsing results from $this->name");
48
            return;
49
50
        }
    }
51
52
53

    public function getNext(\App\MetaGer $metager, $result)
    {
54
55
        try {
            $content = json_decode($result);
56
57
58
59
60
61
62
63
64
65
66
            if (!$content) {
                return;
            }

            if ($content->info->current_page > $content->info->pages) {
                return;
            }
            $next = new Openclipart(simplexml_load_string($this->engine), $metager);
            $next->getString .= "&page=" . ($metager->getPage() + 1);
            $next->hash = md5($next->host . $next->getString . $next->port . $next->name);
            $this->next = $next;
67
        } catch (\Exception $e) {
68
            Log::error("A problem occurred parsing results from $this->name");
69
70
            return;
        }
71
    }
72
}