aboutsummaryrefslogtreecommitdiff
path: root/bridges/CorreioDaFeiraBridge.php
blob: 2cb42edef4134104e7d80728f5236b6f15ec6b3e (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
<?php

class CorreioDaFeiraBridge extends BridgeAbstract
{
    const NAME = 'Correio da Feira';
    const URI = 'https://www.correiodafeira.pt/';
    const DESCRIPTION = 'Returns news from the Portuguese local newspaper Correio da Feira';
    const MAINTAINER = 'rmscoelho';
    const CACHE_TIMEOUT = 86400;
    const PARAMETERS = [
        [
            'feed' => [
                'name' => 'News Feed',
                'type' => 'list',
                'title' => 'Feeds from the Portuguese sports newspaper A BOLA.PT',
                'values' => [
                    'Cultura' => 'cultura',
                    'Desporto' => 'desporto',
                    'Economia' => 'economia',
                    'Entrevista' => 'entrevista',
                    'Freguesias' => 'freguesias',
                    'Justiça' => 'justica',
                    'Opinião' => 'opiniao',
                    'Política' => 'politica',
                    'Reportagem' => 'reportagem',
                    'Sociedade' => 'sociedade',
                    'Tecnologia' => 'tecnologia',
                ]
            ]
        ]
    ];

    public function getIcon()
    {
        return 'https://www.correiodafeira.pt/wp-content/uploads/base_reporter-200x200.jpg';
    }

    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://www.correiodafeira.pt/categoria/%s', $this->getInput('feed'));
        $dom = getSimpleHTMLDOM($url);
        $dom = $dom->find('main', 0);
        if (!$dom) {
            throw new \Exception(sprintf('Unable to find css selector on `%s`', $url));
        }
        $dom = defaultLinkTo($dom, $this->getURI());
        foreach ($dom->find('div.post') as $article) {
            $a = $article->find('div.blog-box', 0);
            //Get date and time of publishing
            $time = $a->find('.post-date > :nth-child(2)', 0)->plaintext;
            $datetime = explode('/', $time);
            $year = $datetime[2];
            $month = $datetime[1];
            $day = $datetime[0];
            $timestamp = mktime(0, 0, 0, $month, $day, $year);
            $this->items[] = [
                'title' => $a->find('h2.entry-title > a', 0)->plaintext,
                'uri' => $a->find('h2.entry-title > a', 0)->href,
                'author' => $a->find('li.post-author > a', 0)->plaintext,
                'content' => $a->find('.entry-content > p', 0)->plaintext,
                'timestamp' => $timestamp,
            ];
        }
    }
}