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