MixCloudBridge.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. class MixCloudBridge extends BridgeAbstract {
  3. const MAINTAINER = 'Alexis CHEMEL';
  4. const NAME = 'MixCloud';
  5. const URI = 'https://mixcloud.com/';
  6. const CACHE_TIMEOUT = 3600; // 1h
  7. const DESCRIPTION = 'Returns latest musics on user stream';
  8. const PARAMETERS = array(array(
  9. 'u' => array(
  10. 'name' => 'username',
  11. 'required' => true,
  12. )
  13. ));
  14. public function getName(){
  15. if(!is_null($this->getInput('u'))) {
  16. return 'MixCloud - ' . $this->getInput('u');
  17. }
  18. return parent::getName();
  19. }
  20. public function collectData(){
  21. $html = getSimpleHTMLDOM(self::URI . $this->getInput('u'))
  22. or returnServerError('Could not request MixCloud.');
  23. foreach($html->find('section.card') as $element) {
  24. $item = array();
  25. $item['uri'] = self::URI . $element->find('hgroup.card-title h1 a', 0)->getAttribute('href');
  26. $item['title'] = html_entity_decode(
  27. $element->find('hgroup.card-title h1 a span', 0)->getAttribute('title'),
  28. ENT_QUOTES
  29. );
  30. $image = $element->find('a.album-art img', 0);
  31. if($image) {
  32. $item['content'] = '<img src="' . $image->getAttribute('src') . '" />';
  33. }
  34. $item['author'] = trim($element->find('hgroup.card-title h2 a', 0)->innertext);
  35. $this->items[] = $item;
  36. }
  37. }
  38. }