aboutsummaryrefslogtreecommitdiff
path: root/bridges/ExplosmBridge.php
blob: 0312a4c48283980f891d8644ae474f3fa8f3eed7 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

class ExplosmBridge extends BridgeAbstract
{
    const NAME = 'Explosm: Cyanide & Happiness';
    const URI = 'https://explosm.net/';
    const DESCRIPTION = 'A Webcomic by Kris Wilson, Rob DenBleyker, and Dave McElfatrick.';
    const MAINTAINER = 'sal0max, bockiii';
    const CACHE_TIMEOUT = 60 * 60 * 2; // 2 hours
    const PARAMETERS = [[
            'limit' => [
                'name' => 'Limit',
                'type' => 'number',
                'title' => 'The number of recent comics to get.',
                'defaultValue' => 5
            ]
        ]
    ];

    public function getIcon()
    {
        return self::URI . 'favicon-32x32.png';
    }

    public function getURI()
    {
        return self::URI . 'comics/latest#comic';
    }

    public function collectData()
    {
        $limit = $this->getInput('limit');
        $url = $this->getUri();

        for ($i = 0; $i < $limit; $i++) {
            $html = getSimpleHTMLDOM($url);

            $element = $html->find('[class*=ComicImage]', 0);
            $date    = $element->find('[class^=Author__Right] p', 0)->plaintext;
            $author  = str_replace('by ', '', $element->find('[class^=Author__Right] p', 1)->plaintext);
            $image   = $element->find('img', 0)->src;
            $link    = $html->find('[rel=canonical]', 0)->href;

            $item = [
                'uid'       => $link,
                'author'    => $author,
                'title'     => $date,
                'uri'       => $link . '#comic',
                'timestamp' => str_replace('.', '-', $date) . 'T00:00:00Z',
                'content'   => "<img src=\"$image\" />"
            ];
            $this->items[] = $item;

            // get next url
            $url = self::URI . $html->find('[class*=ComicSelector]>a', 0)->href;
        }
    }
}