2014-07-18 13:19:02 +02:00
< ? php
class WhydBridge extends BridgeAbstract {
2015-11-05 16:50:18 +01:00
2014-07-18 13:19:02 +02:00
private $request ;
2015-11-04 00:05:10 +01:00
public $name ;
2015-11-05 16:50:18 +01:00
public function loadMetadatas () {
$this -> maintainer = " kranack " ;
$this -> name = " Whyd Bridge " ;
$this -> uri = " http://www.whyd.com/ " ;
$this -> description = " Returns 10 newest music from user profile " ;
2016-08-22 01:25:56 +02:00
$this -> parameters [] = array (
'u' => array (
'name' => 'username/id' ,
'required' => true
)
);
2015-11-05 16:50:18 +01:00
}
2014-07-18 13:19:02 +02:00
public function collectData ( array $param ){
$html = '' ;
if ( isset ( $param [ 'u' ]))
{
$this -> request = $param [ 'u' ];
2014-07-18 15:41:33 +02:00
if ( strlen ( preg_replace ( " /[^0-9a-f]/ " , '' , $this -> request )) == 24 ) { // is input the userid ?
2016-07-08 19:06:35 +02:00
$html = $this -> getSimpleHTMLDOM ( 'http://www.whyd.com/u/' . preg_replace ( " /[^0-9a-f]/ " , '' , $this -> request )) or $this -> returnServerError ( 'No results for this query.' );
2014-07-18 15:41:33 +02:00
} else { // input may be the username
2016-07-08 19:06:35 +02:00
$html = $this -> getSimpleHTMLDOM ( 'http://www.whyd.com/search?q=' . urlencode ( $this -> request )) or $this -> returnServerError ( 'No results for this query.' );
2014-07-18 15:41:33 +02:00
for ( $j = 0 ; $j < 5 ; $j ++ ) {
if ( strtolower ( $html -> find ( 'div.user' , $j ) -> find ( 'a' , 0 ) -> plaintext ) == strtolower ( $this -> request )) {
2016-07-08 19:06:35 +02:00
$html = $this -> getSimpleHTMLDOM ( 'http://www.whyd.com' . $html -> find ( 'div.user' , $j ) -> find ( 'a' , 0 ) -> getAttribute ( 'href' )) or $this -> returnServerError ( 'No results for this query' );
2014-07-18 15:41:33 +02:00
break ;
}
}
}
2014-07-18 13:19:02 +02:00
$this -> name = $html -> find ( 'div#profileTop' , 0 ) -> find ( 'h1' , 0 ) -> plaintext ;
2016-07-08 19:06:35 +02:00
}
2014-07-18 13:19:02 +02:00
else
{
2016-08-17 14:45:08 +02:00
$this -> returnClientError ( 'You must specify username' );
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 ;
$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 13:19:02 +02:00
$this -> items [] = $item ;
}
}
public function getName (){
2014-07-18 13:31:40 +02:00
return ( ! empty ( $this -> name ) ? $this -> name . ' - ' : '' ) . '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