Overture.php 3.15 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

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

8
class Overture 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
22
    public function loadResults($result)
    {
        $result = preg_replace("/\r\n/si", "", $result);
        try {
            $content = simplexml_load_string($result);
        } catch (\Exception $e) {
23
24
            Log::error("Results from $this->name are not a valid json string");
            return;
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->xpath('//Results/ResultSet[@id="inktomi"]/Listing');
        foreach ($results as $result) {
            $title       = $result["title"];
            $link        = $result->{"ClickUrl"}->__toString();
            $anzeigeLink = $result["siteHost"];
            $descr       = $result["description"];
            $this->counter++;
            $this->results[] = new \App\Models\Result(
                $this->engine,
                $title,
                $link,
                $anzeigeLink,
                $descr,
                $this->gefVon,
                $this->counter
            );
        }
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
        # Nun noch die Werbeergebnisse:
        $ads = $content->xpath('//Results/ResultSet[@id="searchResults"]/Listing');
        foreach ($ads as $ad) {
            $title       = $ad["title"];
            $link        = $ad->{"ClickUrl"}->__toString();
            $anzeigeLink = $ad["siteHost"];
            $descr       = $ad["description"];
            $this->counter++;
            $this->ads[] = new \App\Models\Result(
                $this->engine,
                $title,
                $link,
                $anzeigeLink,
                $descr,
                $this->gefVon,
                $this->counter
            );
        }
    }
66
67
68
69
70
71
72
73

    public function getNext(\App\MetaGer $metager, $result)
    {
        # Auslesen der Argumente für die nächste Suchseite:
        $result = preg_replace("/\r\n/si", "", $result);
        try {
            $content = simplexml_load_string($result);
        } catch (\Exception $e) {
74
75
76
77
78
            Log::error("Results from $this->name are not a valid json string");
            return;
        }
        if (!$content) {
            return;
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
        }
        $nextArgs = $content->xpath('//Results/NextArgs');
        if (isset($nextArgs[0])) {
            $nextArgs = $nextArgs[0]->__toString();
        } else {
            $nextArgs = $content->xpath('//Results/ResultSet[@id="inktomi"]/NextArgs');
            if (isset($nextArgs[0])) {
                $nextArgs = $nextArgs[0]->__toString();
            } else {
                return;
            }
        }

        # Erstellen des neuen Suchmaschinenobjekts und anpassen des GetStrings:
        $next            = new Overture(simplexml_load_string($this->engine), $metager);
        $next->getString = preg_replace("/&Keywords=.*?&/si", "&", $next->getString) . "&" . $nextArgs;
95
        $next->hash      = md5($next->host . $next->getString . $next->port . $next->name);
96
97
        $this->next      = $next;
    }
98
}