2016-12-06 12:12:42 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class MixCloudBridge extends BridgeAbstract {
|
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
const MAINTAINER = 'Alexis CHEMEL';
|
|
|
|
const NAME = 'MixCloud';
|
|
|
|
const URI = 'https://mixcloud.com/';
|
2016-12-06 12:12:42 +01:00
|
|
|
const CACHE_TIMEOUT = 3600; // 1h
|
2017-02-11 16:16:56 +01:00
|
|
|
const DESCRIPTION = 'Returns latest musics on user stream';
|
2016-12-06 12:12:42 +01:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
const PARAMETERS = array(array(
|
|
|
|
'u' => array(
|
|
|
|
'name' => 'username',
|
|
|
|
'required' => true,
|
|
|
|
)
|
|
|
|
));
|
2016-12-06 12:12:42 +01:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
public function getName(){
|
2017-07-29 19:28:00 +02:00
|
|
|
if(!is_null($this->getInput('u'))) {
|
2017-02-14 22:20:55 +01:00
|
|
|
return 'MixCloud - ' . $this->getInput('u');
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getName();
|
2017-02-11 16:16:56 +01:00
|
|
|
}
|
2016-12-06 12:12:42 +01:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
public function collectData(){
|
2016-12-06 12:12:42 +01:00
|
|
|
|
2017-03-19 12:04:59 +01:00
|
|
|
$html = getSimpleHTMLDOM(self::URI . $this->getInput('u'))
|
2017-02-11 16:16:56 +01:00
|
|
|
or returnServerError('Could not request MixCloud.');
|
2016-12-06 12:12:42 +01:00
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
foreach($html->find('section.card') as $element) {
|
2016-12-06 12:12:42 +01:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
$item = array();
|
2016-12-06 12:12:42 +01:00
|
|
|
|
2017-03-19 12:04:59 +01:00
|
|
|
$item['uri'] = self::URI . $element->find('hgroup.card-title h1 a', 0)->getAttribute('href');
|
2017-02-11 16:16:56 +01:00
|
|
|
$item['title'] = html_entity_decode(
|
2017-03-19 12:04:59 +01:00
|
|
|
$element->find('hgroup.card-title h1 a span', 0)->getAttribute('title'),
|
2017-02-11 16:16:56 +01:00
|
|
|
ENT_QUOTES
|
|
|
|
);
|
2016-12-06 12:12:42 +01:00
|
|
|
|
2017-03-19 12:04:59 +01:00
|
|
|
$image = $element->find('a.album-art img', 0);
|
2016-12-06 12:12:42 +01:00
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
if($image) {
|
2017-02-11 16:16:56 +01:00
|
|
|
$item['content'] = '<img src="' . $image->getAttribute('src') . '" />';
|
|
|
|
}
|
2016-12-06 12:12:42 +01:00
|
|
|
|
2017-03-19 12:04:59 +01:00
|
|
|
$item['author'] = trim($element->find('hgroup.card-title h2 a', 0)->innertext);
|
2016-12-06 12:12:42 +01:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2016-12-06 12:12:42 +01:00
|
|
|
}
|