Opencrawlpolitik.php 1.88 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

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

Dominik Hebeler's avatar
Dominik Hebeler committed
8
class Opencrawlpolitik extends Searchengine
9
{
10
11
    public $results = [];

12
    public function __construct($name, \StdClass $engine, \App\MetaGer $metager)
13
    {
14
        parent::__construct($name, $engine, $metager);
15
16
17
18
    }

    public function loadResults($result)
    {
19
        $result = preg_replace("/\r\n/si", "", $result);
20
        try {
Dominik Hebeler's avatar
Dominik Hebeler committed
21
            $content = \simplexml_load_string($result);
22
23
            if (!$content) {
                return;
24
25
            }

26
            $results = $content->xpath('//rss/channel/item');
Dominik Hebeler's avatar
Dominik Hebeler committed
27
            $count = 0;
28
29
30
31
32
            foreach ($results as $result) {
                if ($count > 10) {
                    break;
                }

33
34
35
36
37
38
39
40
                $dateString = $result->{"opencrawlDate"}->__toString();

                $date = date_create_from_format("Ymd-Hi", $dateString);

                $dateVal = $date->getTimestamp();

                $additionalInformation = ['date' => $dateVal];

Dominik Hebeler's avatar
Dominik Hebeler committed
41
42
                $title = $result->{"title"}->__toString();
                $link = $result->{"link"}->__toString();
43
                $anzeigeLink = $link;
Dominik Hebeler's avatar
Dominik Hebeler committed
44
                $descr = strip_tags(htmlspecialchars_decode($result->{"description"}->__toString()));
45
46
47
48
49
50
51
                $this->counter++;
                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $anzeigeLink,
                    $descr,
Dominik Hebeler's avatar
Dominik Hebeler committed
52
                    $this->engine->{"display-name"}, $this->engine->homepage,
53
54
                    $this->counter,
                    $additionalInformation
55
56
57
58
                );
                $count++;
            }
        } catch (\Exception $e) {
59
60
            Log::error("A problem occurred parsing results from $this->name:");
            Log::error($e->getMessage());
61
            return;
62
63
64
        }
    }
}