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-04-20 22:19:22 +02:00
|
|
|
$list = $html->find('div[class=actu_col1]', 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);
|
|
|
|
|
|
|
|
// Initialise arrays
|
|
|
|
$item = array();
|
|
|
|
$audio = array();
|
|
|
|
$picture = array();
|
|
|
|
|
|
|
|
// Get the Main picture URL
|
|
|
|
$picture[] = $this->rewriteImage($article->find('img[id=picturearticle]', 0)->src);
|
|
|
|
$audioHTML = $article->find('div[class=sm2-playlist-wrapper]');
|
|
|
|
|
|
|
|
// Remove the audio placeholder under the Audio player with an <audio>
|
|
|
|
// element and add the audio element to the enclosure
|
|
|
|
foreach($audioHTML as $audioElement) {
|
|
|
|
$audioURL = $audioElement->find('a', 0)->href;
|
|
|
|
$audio[] = $audioURL;
|
|
|
|
$audioElement->outertext = '<audio controls src="' . $audioURL . '"></audio>';
|
|
|
|
$article->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rewrite pictures URL
|
|
|
|
$imgs = $article->find('img[src^="https://www.radiomelodie.com/image.php]');
|
|
|
|
foreach($imgs as $img) {
|
|
|
|
$img->src = $this->rewriteImage($img->src);
|
|
|
|
$article->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove inline audio player HTML
|
|
|
|
$inlinePlayers = $article->find('div[class*=sm2-main-controls]');
|
|
|
|
foreach($inlinePlayers as $inlinePlayer) {
|
|
|
|
$inlinePlayer->outertext = '';
|
|
|
|
$article->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove Google Ads
|
|
|
|
$ads = $article->find('div[style^=margin:25px 0; position:relative; height:auto;]');
|
|
|
|
foreach($ads as $ad) {
|
|
|
|
$ad->outertext = '';
|
|
|
|
$article->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
$author = $article->find('div[id=author]', 0)->find('span', 0)->plaintext;
|
|
|
|
|
|
|
|
$item['enclosures'] = array_merge($picture, $audio);
|
|
|
|
$item['author'] = $author;
|
|
|
|
$item['uri'] = $articleURL;
|
|
|
|
$item['title'] = $article->find('meta[property=og:title]', 0)->content;
|
|
|
|
$date_category = $article->find('div[class*=date]', 0)->plaintext;
|
|
|
|
$header = $article->find('a[class=fancybox]', 0)->innertext;
|
|
|
|
$textDOM = $article->find('div[class=text_content]', 0);
|
|
|
|
$textDOM->find('div[id=author]', 0)->outertext = '';
|
|
|
|
$article->save();
|
|
|
|
$text = $textDOM->innertext;
|
|
|
|
$item['content'] = '<h1>' . $item['title'] . '</h1>' . $date_category . $header . $text;
|
|
|
|
$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);
|
|
|
|
parse_str($parts[1], $params);
|
|
|
|
return self::URI . '/' . $params['image'];
|
|
|
|
|
|
|
|
}
|
2018-03-11 15:38:07 +01:00
|
|
|
}
|