aboutsummaryrefslogtreecommitdiff
path: root/bridges/SpottschauBridge.php
blob: a2720274c7fe264cc9ea75cedbf8e413ffc2607a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php

class SpottschauBridge extends BridgeAbstract
{
    const NAME = 'Härringers Spottschau Bridge';
    const URI = 'https://spottschau.com/';
    const DESCRIPTION = 'Der Fußball-Comic';
    const MAINTAINER = 'sal0max';
    const PARAMETERS = [];

    const CACHE_TIMEOUT = 3600; // 1 hour

    public function collectData()
    {
        $html = getSimpleHTMLDOM(self::URI);

        $item = [];
        $item['uri'] = urljoin(self::URI, $html->find('div.strip>a', 0)->attr['href']);
        $item['title'] = $html->find('div.text>h2', 0)->innertext;

        $date = preg_replace('/.*, /', '', $item['title']);
        $date = preg_replace('/\\d\\d\\.\\//', '', $date);
        try {
            $item['timestamp'] = DateTime::createFromFormat('d.m.y', $date)
                ->setTimezone(new DateTimeZone('Europe/Berlin'))
                ->setTime(0, 0)
                ->getTimestamp();
        } catch (Throwable $ignored) {
            $item['timestamp'] = null;
        }

        $image = $html->find('div.strip>a>img', 0);
        $imageUrl = urljoin(self::URI, $image->attr['src']);
        $imageAlt = $image->attr['alt'];

        $item['content'] = <<<EOD
<img src="{$imageUrl}" alt="{$imageAlt}"/>
<br/>
EOD;
        $this->items[] = $item;
    }
}