Mg_produkt2.php 1.89 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

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

class Mg_produkt2 extends Searchengine
9
{
10
11
    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)
    {
        $result = preg_replace("/\r\n/si", "", $result);
        try {
Dominik Hebeler's avatar
Dominik Hebeler committed
21
            $content = \simplexml_load_string($result);
22
23
24
            if (!$content) {
                return;
            }
25

26
            $results = $content->xpath('//response/result[@name="response"]/doc');
27

28
            foreach ($results as $result) {
29

Dominik Hebeler's avatar
Dominik Hebeler committed
30
31
32
                $result = \simplexml_load_string($result->saveXML());
                $title = $result->xpath('/doc/arr[@name="artikelName"]')[0]->{"str"}->__toString();
                $link = $result->xpath('/doc/arr[@name="artikelDeeplink"]')[0]->{"str"}->__toString();
33
34
                $anzeigeLink = parse_url($link);
                parse_str($anzeigeLink['query'], $query);
Aria Givi's avatar
Aria Givi committed
35
                $anzeigeLink = $query['diurl'];
Dominik Hebeler's avatar
Dominik Hebeler committed
36
37
                $descr = $result->xpath('/doc/arr[@name="artikelBeschreibung"]')[0]->{"str"}->__toString();
                $image = $result->xpath('/doc/arr[@name="artikelImageurl"]')[0]->{"str"}->__toString();
38
39
40
41
42
43
44
                $this->counter++;
                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $anzeigeLink,
                    $descr,
Dominik Hebeler's avatar
Dominik Hebeler committed
45
                    $this->engine->{"display-name"}, $this->engine->homepage,
46
                    $this->counter,
47
                    ['image' => $image]
48
49
50
                );
            }
        } catch (\Exception $e) {
51
52
            Log::error("A problem occurred parsing results from $this->name:");
            Log::error($e->getMessage());
53
54
55
            return;
        }
    }
56
}