WhydBridge.php 2.2 KB

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