2014-07-18 13:19:02 +02:00
|
|
|
<?php
|
|
|
|
class WhydBridge extends BridgeAbstract{
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "kranack";
|
|
|
|
const NAME = "Whyd Bridge";
|
|
|
|
const URI = "http://www.whyd.com/";
|
|
|
|
const DESCRIPTION = "Returns 10 newest music from user profile";
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const PARAMETERS = array( array(
|
2016-08-27 21:03:26 +02:00
|
|
|
'u'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'username/id',
|
|
|
|
'required'=>true
|
2016-08-27 21:03:26 +02:00
|
|
|
)
|
|
|
|
));
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-30 00:07:22 +02:00
|
|
|
private $userName='';
|
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2014-07-18 13:19:02 +02:00
|
|
|
$html = '';
|
2016-08-28 01:25:33 +02:00
|
|
|
if (strlen(preg_replace("/[^0-9a-f]/",'', $this->getInput('u'))) == 24){
|
2016-08-27 18:25:24 +02:00
|
|
|
// is input the userid ?
|
2016-09-25 23:22:33 +02:00
|
|
|
$html = getSimpleHTMLDOM(
|
2016-08-30 11:23:55 +02:00
|
|
|
self::URI.'u/'.preg_replace("/[^0-9a-f]/",'', $this->getInput('u'))
|
2016-09-25 23:22:33 +02:00
|
|
|
) or returnServerError('No results for this query.');
|
2016-08-27 18:25:24 +02:00
|
|
|
} else { // input may be the username
|
2016-09-25 23:22:33 +02:00
|
|
|
$html = getSimpleHTMLDOM(
|
2016-08-30 11:23:55 +02:00
|
|
|
self::URI.'search?q='.urlencode($this->getInput('u'))
|
2016-09-25 23:22:33 +02:00
|
|
|
) or returnServerError('No results for this query.');
|
2016-08-27 18:25:24 +02:00
|
|
|
|
|
|
|
for ($j = 0; $j < 5; $j++) {
|
2016-08-28 01:25:33 +02:00
|
|
|
if (strtolower($html->find('div.user', $j)->find('a',0)->plaintext) == strtolower($this->getInput('u'))) {
|
2016-09-25 23:22:33 +02:00
|
|
|
$html = getSimpleHTMLDOM(
|
2016-08-30 11:23:55 +02:00
|
|
|
self::URI . $html->find('div.user', $j)->find('a', 0)->getAttribute('href')
|
2016-09-25 23:22:33 +02:00
|
|
|
) or returnServerError('No results for this query');
|
2016-08-27 18:25:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 00:07:22 +02:00
|
|
|
$this->userName = $html->find('div#profileTop', 0)->find('h1', 0)->plaintext;
|
2014-07-18 13:19:02 +02:00
|
|
|
|
|
|
|
for($i = 0; $i < 10; $i++) {
|
|
|
|
$track = $html->find('div.post', $i);
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
|
|
|
$item['author'] = $track->find('h2', 0)->plaintext;
|
|
|
|
$item['title'] = $track->find('h2', 0)->plaintext;
|
|
|
|
$item['content'] = $track->find('a.thumb',0) . '<br/>' . $track->find('h2', 0)->plaintext;
|
2016-08-30 11:23:55 +02:00
|
|
|
$item['id'] = self::URI . $track->find('a.no-ajaxy',0)->getAttribute('href');
|
|
|
|
$item['uri'] = self::URI . $track->find('a.no-ajaxy',0)->getAttribute('href');
|
2014-07-18 13:19:02 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function getName(){
|
2016-08-30 00:07:22 +02:00
|
|
|
return (!empty($this->userName) ? $this->userName .' - ' : '') .'Whyd Bridge';
|
2014-07-18 13:19:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
2014-07-18 15:41:33 +02:00
|
|
|
return 600; // 10 minutes
|
2014-07-18 13:19:02 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-18 15:41:33 +02:00
|
|
|
|
2014-07-23 13:11:55 +02:00
|
|
|
|