Yandex.php 2.16 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

5
6
use App\Models\Searchengine;

7
class Yandex extends Searchengine
8
{
9
10
11
12
13
14
    public $results = [];

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

16
17
18
19
20
21
22
23
    public function loadResults($result)
    {
        $result = preg_replace("/\r\n/si", "", $result);
        try {
            $content = simplexml_load_string($result);
        } catch (\Exception $e) {
            abort(500, "$result is not a valid xml string");
        }
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
        if (!$content) {
            return;
        }
        $results = $content;
        try {
            $results = $results->xpath("//yandexsearch/response/results/grouping/group");
        } catch (\ErrorException $e) {
            return;
        }
        foreach ($results as $result) {
            $title       = strip_tags($result->{"doc"}->{"title"}->asXML());
            $link        = $result->{"doc"}->{"url"}->__toString();
            $anzeigeLink = $link;
            $descr       = strip_tags($result->{"doc"}->{"headline"}->asXML());
            if (!$descr) {
                $descr = strip_tags($result->{"doc"}->{"passages"}->asXML());
            }
            $this->counter++;
            $this->results[] = new \App\Models\Result(
                $this->engine,
                $title,
                $link,
                $anzeigeLink,
                $descr,
                $this->gefVon,
                $this->counter
            );
        }
    }
54
55
56
57
58

    public function getLast(\App\MetaGer $metager, $result)
    {
        if( $metager->getPage() <= 1 )
            return;
Dominik Hebeler's avatar
Dominik Hebeler committed
59
60
61
        $last            = new Yandex(simplexml_load_string($this->engine), $metager);
        $last->getString .= "&page=" . ($metager->getPage() -1 );
        $this->last = $last;
62
63
64
65
66
67
68
    }

    public function getNext(\App\MetaGer $metager, $result)
    {
        if( count($this->results) <= 0 )
            return;
        $next            = new Yandex(simplexml_load_string($this->engine), $metager);
69
        $next->getString .= "&page=" . ($metager->getPage() + 1);
Dominik Hebeler's avatar
Dominik Hebeler committed
70
        print( $next->getString);
71
72
        $this->next = $next;
    }
Dominik Hebeler's avatar
Dominik Hebeler committed
73
}