Witch.php 1.53 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

5
6
use App\Models\Searchengine;

7
class Witch extends Searchengine
8
9
10
{
    public $results = [];

Dominik Hebeler's avatar
Dominik Hebeler committed
11
    public function __construct($name, \stdClass $engine, \App\MetaGer $metager)
12
    {
Dominik Hebeler's avatar
Dominik Hebeler committed
13
        parent::__construct($name, $engine, $metager);
14
15
    }

16
    public function loadResults($result)
17
    {
18
        $result = html_entity_decode(trim(utf8_encode($result)));
19

20
21
        $results = explode("\n", $result);
        array_shift($results);
22
23
        foreach ($results as $res) {

24
            $res = explode(";", $res);
25
            if (sizeof($res) !== 4 || $res[3] === "'Kein Ergebnis'") {
26
27
                continue;
            }
Dominik Hebeler's avatar
Dominik Hebeler committed
28
29
            $title = trim($res[0], "'");
            $link = trim($res[2], "'");
30
            $anzeigeLink = $link;
Dominik Hebeler's avatar
Dominik Hebeler committed
31
            $descr = trim($res[1], "'");
32
33
34

            $this->counter++;
            $this->results[] = new \App\Models\Result(
35
                $this->engine,
36
37
38
39
                $title,
                $link,
                $anzeigeLink,
                $descr,
Dominik Hebeler's avatar
Dominik Hebeler committed
40
                $this->engine->{"display-name"}, $this->engine->homepage,
41
42
43
44
45
                $this->counter
            );
        }

    }
46
47
48
49
50
51
52

    public function getNext(\App\MetaGer $metager, $result)
    {
        if (count($this->results) <= 0) {
            return;
        }

Dominik Hebeler's avatar
Dominik Hebeler committed
53
54
55
56
57
        $offset = $metager->getPage() * 10;
        $newEngine = unserialize(serialize($this->engine));
        $newEngine->{"get-parameter"}->cn = "$offset";
        $next = new Witch($this->name, $newEngine, $metager);
        $this->next = $next;
58
    }
59
}