aboutsummaryrefslogtreecommitdiff
path: root/bridges/NiceMatinBridge.php
blob: dd90dbfe187b9786990e02001321903664beec13 (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
<?php

class NiceMatinBridge extends FeedExpander
{
    const MAINTAINER = 'pit-fgfjiudghdf';
    const NAME = 'NiceMatin';
    const URI = 'https://www.nicematin.com/';
    const DESCRIPTION = 'Returns the 10 newest posts from NiceMatin (full text)';

    public function collectData()
    {
        $this->collectExpandableDatas(self::URI . 'derniere-minute/rss', 10);
    }

    protected function parseItem(array $item)
    {
        $item['content'] = $this->extractContent($item['uri']);
        return $item;
    }

    private function extractContent($url)
    {
        $html = getSimpleHTMLDOMCached($url);
        if (!$html) {
            return 'Could not acquire content from url: ' . $url . '!';
        }

        $content = $html->find('article', 0);
        if (!$content) {
            return 'Could not find \'section\'!';
        }

        $text = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content->innertext);
        $text = strip_tags($text, '<p><a><img>');
        return $text;
    }
}