2019-10-03 23:36:08 +03:00
|
|
|
<?php
|
|
|
|
class VieDeMerdeBridge extends BridgeAbstract {
|
|
|
|
|
|
|
|
const MAINTAINER = 'floviolleau';
|
|
|
|
const NAME = 'VieDeMerde Bridge';
|
2022-03-30 01:58:29 +03:00
|
|
|
const URI = 'https://www.viedemerde.fr';
|
2019-10-03 23:36:08 +03:00
|
|
|
const DESCRIPTION = 'Returns latest quotes from VieDeMerde.';
|
|
|
|
const CACHE_TIMEOUT = 7200;
|
|
|
|
|
|
|
|
const PARAMETERS = array(array(
|
|
|
|
'item_limit' => array(
|
|
|
|
'name' => 'Limit number of returned items',
|
|
|
|
'type' => 'number',
|
|
|
|
'defaultValue' => 20
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
public function collectData() {
|
|
|
|
$limit = $this->getInput('item_limit');
|
|
|
|
|
|
|
|
if ($limit < 1) {
|
|
|
|
$limit = 20;
|
|
|
|
}
|
|
|
|
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM(self::URI, array());
|
2022-03-30 01:58:29 +03:00
|
|
|
$quotes = $html->find('article.bg-white');
|
2019-10-03 23:36:08 +03:00
|
|
|
if(sizeof($quotes) === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($quotes as $quote) {
|
|
|
|
$item = array();
|
2022-03-30 01:58:29 +03:00
|
|
|
$item['uri'] = self::URI . $quote->find('a', 0)->href;
|
|
|
|
$titleContent = $quote->find('h2', 0);
|
2019-10-03 23:36:08 +03:00
|
|
|
|
|
|
|
if($titleContent) {
|
|
|
|
$item['title'] = html_entity_decode($titleContent->plaintext, ENT_QUOTES);
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-03-30 01:58:29 +03:00
|
|
|
$quoteText = $quote->find('a', 1)->plaintext;
|
|
|
|
$isAVDM = $quote->find('.vote-btn', 0)->plaintext;
|
|
|
|
$isNotAVDM = $quote->find('.vote-btn', 1)->plaintext;
|
|
|
|
$item['content'] = $quoteText . '<br>' . $isAVDM . '<br>' . $isNotAVDM;
|
|
|
|
$item['author'] = $quote->find('p', 0)->plaintext;
|
2019-10-03 23:36:08 +03:00
|
|
|
$item['uid'] = hash('sha256', $item['title']);
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
|
|
|
|
if (count($this->items) >= $limit) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|