Exalead.php 2.61 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

5
6
use App\Models\Searchengine;

7
class Exalead extends Searchengine
8
{
9
10
11
12
13
14
15
16
17
18
19
20
21
    public $results = [];

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

    public function loadResults($result)
    {
        $result = preg_replace("/\r\n/si", "", $result);
        try {
            $content = simplexml_load_string($result);
        } catch (\Exception $e) {
Dominik Hebeler's avatar
Dominik Hebeler committed
22
            return;
23
        }
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
        if (!$content) {
            return;
        }
        $results   = $content;
        $prefix    = "";
        $namespace = "";
        foreach ($results->getDocNamespaces() as $strPrefix => $strNamespace) {
            if (strlen($strPrefix) == 0) {
                $prefix = "a"; //Assign an arbitrary namespace prefix.
            } else {
                $prefix = "a";
            }
            $namespace = $strNamespace;
        }
        $results->registerXPathNamespace($prefix, $namespace);
        try {
            $results = $results->xpath("//a:searchResult/a:item");
        } catch (\ErrorException $e) {
            return;
        }
        foreach ($results as $result) {
            try {
                $result->registerXPathNamespace($prefix, $namespace);
                $title       = $result->xpath("a:metas/a:Meta[@name='title']/a:MetaString[@name='value']")[0]->__toString();
                $link        = $result->xpath("a:metas/a:Meta[@name='url']/a:MetaString[@name='value']")[0]->__toString();
                $anzeigeLink = $link;
                $descr       = "";
                if (sizeOf($result->xpath("a:metas/a:Meta[@name='metadesc']/a:MetaString[@name='value']")) === 0 && sizeOf($result->xpath("a:metas/a:Meta[@name='summary']/a:MetaText[@name='value']")) !== 0) {
                    $tmp = $result->xpath("a:metas/a:Meta[@name='summary']/a:MetaText[@name='value']");
                    foreach ($tmp as $el) {
                        $descr .= strip_tags($el->asXML());
                    }
                } else {
                    $descr = $result->xpath("a:metas/a:Meta[@name='metadesc']/a:MetaString[@name='value']")[0]->__toString();
                }
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
                $this->counter++;
                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $anzeigeLink,
                    $descr,
                    $this->gefVon,
                    $this->counter
                );
            } catch (\ErrorException $e) {
                continue;
            }
        }
    }
Dominik Hebeler's avatar
Dominik Hebeler committed
76
}