forked from RSS-Bridge/rss-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VieDeMerdeBridge] Add new bridge for quotes from Vie de Merde (RSS-B…
…ridge#1313) * Add new bridge for quotes from Vie de Merde
- Loading branch information
1 parent
126dfd0
commit 7364695
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
class VieDeMerdeBridge extends BridgeAbstract { | ||
|
||
const MAINTAINER = 'floviolleau'; | ||
const NAME = 'VieDeMerde Bridge'; | ||
const URI = 'https://viedemerde.fr'; | ||
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; | ||
} | ||
|
||
$html = getSimpleHTMLDOM(self::URI, array()) | ||
or returnServerError('Could not request VieDeMerde.'); | ||
|
||
$quotes = $html->find('article.article-panel'); | ||
if(sizeof($quotes) === 0) { | ||
return; | ||
} | ||
|
||
foreach($quotes as $quote) { | ||
$item = array(); | ||
$item['uri'] = self::URI . $quote->find('.article-contents a', 0)->href; | ||
$titleContent = $quote->find('.article-contents a h2.classic-title', 0); | ||
|
||
if($titleContent) { | ||
$item['title'] = html_entity_decode($titleContent->plaintext, ENT_QUOTES); | ||
} else { | ||
continue; | ||
} | ||
|
||
$quote->find('.article-contents a h2.classic-title', 0)->outertext = ''; | ||
$item['content'] = $quote->find('.article-contents a', 0)->innertext; | ||
$item['author'] = $quote->find('.article-topbar', 0)->innertext; | ||
$item['uid'] = hash('sha256', $item['title']); | ||
|
||
$this->items[] = $item; | ||
|
||
if (count($this->items) >= $limit) { | ||
break; | ||
} | ||
} | ||
} | ||
} |