WhydBridge.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. class WhydBridge extends BridgeAbstract{
  3. const MAINTAINER = "kranack";
  4. const NAME = "Whyd Bridge";
  5. const URI = "http://www.whyd.com/";
  6. const DESCRIPTION = "Returns 10 newest music from user profile";
  7. const PARAMETERS = array( array(
  8. 'u'=>array(
  9. 'name'=>'username/id',
  10. 'required'=>true
  11. )
  12. ));
  13. private $userName='';
  14. public function collectData(){
  15. $html = '';
  16. if (strlen(preg_replace("/[^0-9a-f]/",'', $this->getInput('u'))) == 24){
  17. // is input the userid ?
  18. $html = getSimpleHTMLDOM(
  19. self::URI.'u/'.preg_replace("/[^0-9a-f]/",'', $this->getInput('u'))
  20. ) or returnServerError('No results for this query.');
  21. } else { // input may be the username
  22. $html = getSimpleHTMLDOM(
  23. self::URI.'search?q='.urlencode($this->getInput('u'))
  24. ) or returnServerError('No results for this query.');
  25. for ($j = 0; $j < 5; $j++) {
  26. if (strtolower($html->find('div.user', $j)->find('a',0)->plaintext) == strtolower($this->getInput('u'))) {
  27. $html = getSimpleHTMLDOM(
  28. self::URI . $html->find('div.user', $j)->find('a', 0)->getAttribute('href')
  29. ) or returnServerError('No results for this query');
  30. break;
  31. }
  32. }
  33. }
  34. $this->userName = $html->find('div#profileTop', 0)->find('h1', 0)->plaintext;
  35. for($i = 0; $i < 10; $i++) {
  36. $track = $html->find('div.post', $i);
  37. $item = array();
  38. $item['author'] = $track->find('h2', 0)->plaintext;
  39. $item['title'] = $track->find('h2', 0)->plaintext;
  40. $item['content'] = $track->find('a.thumb',0) . '<br/>' . $track->find('h2', 0)->plaintext;
  41. $item['id'] = self::URI . $track->find('a.no-ajaxy',0)->getAttribute('href');
  42. $item['uri'] = self::URI . $track->find('a.no-ajaxy',0)->getAttribute('href');
  43. $this->items[] = $item;
  44. }
  45. }
  46. public function getName(){
  47. return (!empty($this->userName) ? $this->userName .' - ' : '') .'Whyd Bridge';
  48. }
  49. public function getCacheDuration(){
  50. return 600; // 10 minutes
  51. }
  52. }