Minisucher.php 2.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

namespace App\Models\parserSkripte;

use App\Models\Searchengine;

class Minisucher extends Searchengine
{

10
11
12
13
    public function __construct(\SimpleXMLElement $engine, \App\MetaGer $metager)
    {
        parent::__construct($engine, $metager);
    }
14

15
16
17
18
19
20
21
22
23
24
25
    public function loadResults($content)
    {
        try {
            $content = simplexml_load_string($content);
        } catch (\Exception $e) {
            return;
        }
        if (!$content) {
            return;
        }
        $results = $content->xpath('//response/result/doc');
26

27
        $string = "";
28

29
30
31
32
33
34
        $counter         = 0;
        $providerCounter = [];
        foreach ($results as $result) {
            try {
                $counter++;
                $result = simplexml_load_string($result->saveXML());
35

36
37
38
39
40
41
42
43
44
45
                $title        = $result->xpath('//doc/arr[@name="title"]/str')[0]->__toString();
                $link         = $result->xpath('//doc/str[@name="url"]')[0]->__toString();
                $anzeigeLink  = $link;
                $descr        = "";
                $descriptions = $content->xpath("//response/lst[@name='highlighting']/lst[@name='$link']/arr[@name='content']/str");
                foreach ($descriptions as $description) {
                    $descr .= $description->__toString();
                }
                $descr    = strip_tags($descr);
                $provider = $result->xpath('//doc/str[@name="subcollection"]')[0]->__toString();
46

47
48
49
50
51
52
                if (isset($providerCounter[$provider]) && $providerCounter[$provider] > 10) {
                    continue;
                } else {
                    if (!isset($providerCounter[$provider])) {
                        $providerCounter[$provider] = 0;
                    }
53

54
55
                    $providerCounter[$provider] += 1;
                }
56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
                if (isset($provider)) {
                    $gefVon = "<a href=\"https://metager.de\" target=\"_blank\">Minisucher: $provider</a>";
                } else {
                    $gefVon = $this->gefVon;
                }

                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $link,
                    $descr,
                    $gefVon,
                    $counter
                );
            } catch (\ErrorException $e) {
                continue;
            }
        }

    }

}