aboutsummaryrefslogtreecommitdiff
path: root/bridges/VideoCardzBridge.php
blob: 84796c203fa0329afe79853f708ff940afe1876d (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

class VideoCardzBridge extends BridgeAbstract
{
    const NAME = 'VideoCardz';
    const URI = 'https://videocardz.com/';
    const DESCRIPTION = 'Returns news from VideoCardz.com';
    const MAINTAINER = 'rmscoelho';
    const CACHE_TIMEOUT = 3600;
    const PARAMETERS = [
        [
            'feed' => [
                'name' => 'News Feed',
                'type' => 'list',
                'title' => 'Feeds from VideoCardz.com',
                'values' => [
                    'News' => 'sections/news',
                    'Featured' => 'sections/featured',
                    'Leaks' => 'sections/leaks',
                    'Press Releases' => 'sections/press-releases',
                    'Preview Roundup' => 'sections/review-roundup',
                    'Rumour' => 'sections/rumor',
                ]
            ]
        ]
    ];

    public function getIcon()
    {
        return 'https://videocardz.com/favicon-32x32.png?x66580';
    }

    public function getName()
    {
        return !is_null($this->getKey('feed')) ? self::NAME . ' | ' . $this->getKey('feed') : self::NAME;
    }

    public function getURI()
    {
        return self::URI . $this->getInput('feed');
    }

    public function collectData()
    {
        $url = sprintf('https://videocardz.com/%s', $this->getInput('feed'));
        $dom = getSimpleHTMLDOM($url);
        $dom = $dom->find('.subcategory-news', 0);
        if (!$dom) {
            throw new \Exception(sprintf('Unable to find css selector on `%s`', $url));
        }
        $dom = defaultLinkTo($dom, $this->getURI());

        foreach ($dom->find('article') as $article) {
            $title = preg_replace('/\(PR\) /i', '', $article->find('h2', 0)->plaintext);
            //Get thumbnail
            $image = $article->style;
            $image = preg_replace('/background-image:url\(/i', '', $image);
            $image = substr_replace($image, '', -3);
            //Get date and time of publishing
            $datetime = date_parse($article->find('.main-index-article-datetitle-date > a', 0)->plaintext);
            $year = $datetime['year'];
            $month = $datetime['month'];
            $day = $datetime['day'];
            $hour = $datetime['hour'];
            $minute = $datetime['minute'];
            $timestamp = mktime($hour, $minute, 0, $month, $day, $year);
            $content = '<img src="' . $image . '" alt="' . $article->find('h2', 0)->plaintext . ' thumbnail" />';
            $this->items[] = [
                'title' => $title,
                'uri' => $article->find('p.main-index-article-datetitle-date > a', 0)->href,
                'content' => $content,
                'timestamp' => $timestamp,
            ];
        }
    }
}