2018-03-11 15:38:07 +01:00
|
|
|
<?php
|
|
|
|
class RadioMelodieBridge extends BridgeAbstract {
|
|
|
|
const NAME = 'Radio Melodie Actu';
|
2019-04-20 22:19:22 +02:00
|
|
|
const URI = 'https://www.radiomelodie.com';
|
2018-03-11 15:38:07 +01:00
|
|
|
const DESCRIPTION = 'Retourne les actualités publiées par Radio Melodie';
|
|
|
|
const MAINTAINER = 'sysadminstory';
|
|
|
|
|
2018-10-26 18:07:34 +02:00
|
|
|
public function getIcon() {
|
2019-04-20 22:19:22 +02:00
|
|
|
return self::URI . '/img/favicon.png';
|
2018-10-26 18:07:34 +02:00
|
|
|
}
|
|
|
|
|
2018-03-11 15:38:07 +01:00
|
|
|
public function collectData(){
|
2019-04-20 22:19:22 +02:00
|
|
|
$html = getSimpleHTMLDOM(self::URI . '/actu/')
|
2018-03-11 15:38:07 +01:00
|
|
|
or returnServerError('Could not request Radio Melodie.');
|
2019-06-01 12:12:17 +02:00
|
|
|
$list = $html->find('div[class=displayList]', 0)->children();
|
2018-03-11 15:38:07 +01:00
|
|
|
foreach($list as $element) {
|
2019-04-20 22:19:22 +02:00
|
|
|
if($element->tag == 'a') {
|
|
|
|
$articleURL = self::URI . $element->href;
|
|
|
|
$article = getSimpleHTMLDOM($articleURL);
|
2019-06-01 12:12:17 +02:00
|
|
|
$textDOM = $article->find('article', 0);
|
2019-04-20 22:19:22 +02:00
|
|
|
|
|
|
|
// Initialise arrays
|
|
|
|
$item = array();
|
|
|
|
$audio = array();
|
|
|
|
$picture = array();
|
|
|
|
|
|
|
|
// Get the Main picture URL
|
2019-06-01 12:12:17 +02:00
|
|
|
$picture[] = $this->rewriteImage($article->find('div[id=pictureTitleSupport]', 0)->find('img', 0)->src);
|
|
|
|
$audioHTML = $article->find('audio');
|
2019-04-20 22:19:22 +02:00
|
|
|
|
2019-06-01 12:12:17 +02:00
|
|
|
// Add the audio element to the enclosure
|
2019-04-20 22:19:22 +02:00
|
|
|
foreach($audioHTML as $audioElement) {
|
2019-06-01 12:12:17 +02:00
|
|
|
$audioURL = $audioElement->src;
|
2019-04-20 22:19:22 +02:00
|
|
|
$audio[] = $audioURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rewrite pictures URL
|
2019-06-01 12:12:17 +02:00
|
|
|
$imgs = $textDOM->find('img[src^="http://www.radiomelodie.com/image.php]');
|
2019-04-20 22:19:22 +02:00
|
|
|
foreach($imgs as $img) {
|
|
|
|
$img->src = $this->rewriteImage($img->src);
|
2019-06-02 13:03:26 +02:00
|
|
|
$article->save();
|
2019-04-20 22:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove Google Ads
|
2019-06-01 12:12:17 +02:00
|
|
|
$ads = $article->find('div[class=adInline]');
|
2019-04-20 22:19:22 +02:00
|
|
|
foreach($ads as $ad) {
|
2019-06-02 13:03:26 +02:00
|
|
|
$ad->outertext = '';
|
|
|
|
$article->save();
|
2019-04-20 22:19:22 +02:00
|
|
|
}
|
|
|
|
|
2019-06-01 12:12:17 +02:00
|
|
|
// Remove Radio Melodie Logo
|
|
|
|
$logoHTML = $article->find('div[id=logoArticleRM]', 0);
|
2019-06-02 13:03:26 +02:00
|
|
|
$logoHTML->outertext = '';
|
|
|
|
$article->save();
|
2019-06-01 12:12:17 +02:00
|
|
|
|
|
|
|
$author = $article->find('p[class=AuthorName]', 0)->plaintext;
|
2019-04-20 22:19:22 +02:00
|
|
|
|
|
|
|
$item['enclosures'] = array_merge($picture, $audio);
|
|
|
|
$item['author'] = $author;
|
|
|
|
$item['uri'] = $articleURL;
|
|
|
|
$item['title'] = $article->find('meta[property=og:title]', 0)->content;
|
2019-06-01 12:12:17 +02:00
|
|
|
$date = $article->find('p[class*=date]', 0)->plaintext;
|
|
|
|
|
|
|
|
// Header Image
|
|
|
|
$header = '<img src="' . $picture[0] . '"/>';
|
|
|
|
|
|
|
|
// Remove the Date and Author part
|
2019-06-02 13:03:26 +02:00
|
|
|
$textDOM->find('div[class=AuthorDate]', 0)->outertext = '';
|
|
|
|
$article->save();
|
2019-04-20 22:19:22 +02:00
|
|
|
$text = $textDOM->innertext;
|
2019-06-01 12:12:17 +02:00
|
|
|
$item['content'] = '<h1>' . $item['title'] . '</h1>' . $date . '<br/>' . $header . $text;
|
2019-04-20 22:19:22 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2018-03-11 15:38:07 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-20 22:19:22 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function to rewrite image URL to use the real Image URL and not the resized one (which is very slow)
|
|
|
|
*/
|
|
|
|
private function rewriteImage($url)
|
|
|
|
{
|
|
|
|
$parts = explode('?', $url);
|
2019-06-01 12:12:17 +02:00
|
|
|
parse_str(html_entity_decode($parts[1]), $params);
|
2019-04-20 22:19:22 +02:00
|
|
|
return self::URI . '/' . $params['image'];
|
|
|
|
|
|
|
|
}
|
2018-03-11 15:38:07 +01:00
|
|
|
}
|