2016-05-10 13:23:43 +02:00
< ? php
class RTBFBridge extends BridgeAbstract {
2016-08-27 21:03:26 +02:00
public $name = " RTBF Bridge " ;
public $uri = " http://www.rtbf.be/auvio/emissions " ;
public $description = " Returns the newest RTBF videos by series ID " ;
public $maintainer = " Frenzie " ;
2016-05-10 13:23:43 +02:00
2016-08-27 21:03:26 +02:00
public $parameters = array ( array (
'c' => array (
2016-08-22 01:25:56 +02:00
'name' => 'series id' ,
'exampleValue' => 9500 ,
'required' => true
2016-08-27 21:03:26 +02:00
)
));
2016-05-10 13:23:43 +02:00
2016-08-25 01:24:53 +02:00
public function collectData (){
$param = $this -> parameters [ $this -> queriedContext ];
2016-05-10 13:23:43 +02:00
$html = '' ;
$limit = 10 ;
$count = 0 ;
2016-08-25 01:24:53 +02:00
if ( isset ( $param [ 'c' ][ 'value' ])) {
$html = $this -> getSimpleHTMLDOM ( 'http://www.rtbf.be/auvio/emissions/detail?id=' . $param [ 'c' ][ 'value' ]) or $this -> returnServerError ( 'Could not request RTBF.' );
2016-05-10 13:23:43 +02:00
2016-07-29 08:23:03 +02:00
foreach ( $html -> find ( 'section[id!=widget-ml-avoiraussi-] .rtbf-media-grid article' ) as $element ) {
2016-05-10 13:23:43 +02:00
if ( $count < $limit ) {
2016-08-22 18:55:59 +02:00
$item = array ();
$item [ 'id' ] = $element -> getAttribute ( 'data-id' );
$item [ 'uri' ] = 'http://www.rtbf.be/auvio/detail?id=' . $item [ 'id' ];
2016-05-10 13:23:43 +02:00
$thumbnailUriSrcSet = explode ( ',' , $element -> find ( 'figure .www-img-16by9 img' , 0 ) -> getAttribute ( 'data-srcset' ));
$thumbnailUriLastSrc = end ( $thumbnailUriSrcSet );
2016-08-09 15:50:25 +02:00
$thumbnailUri = explode ( ' ' , $thumbnailUriLastSrc )[ 0 ];
2016-08-22 18:55:59 +02:00
$item [ 'title' ] = trim ( $element -> find ( 'h3' , 0 ) -> plaintext ) . ' - ' . trim ( $element -> find ( 'h4' , 0 ) -> plaintext );
$item [ 'timestamp' ] = strtotime ( $element -> find ( 'time' , 0 ) -> getAttribute ( 'datetime' ));
$item [ 'content' ] = '<a href="' . $item [ 'uri' ] . '"><img src="' . $thumbnailUri . '" /></a>' ;
2016-05-10 13:23:43 +02:00
$this -> items [] = $item ;
$count ++ ;
}
}
}
else {
2016-08-17 14:45:08 +02:00
$this -> returnClientError ( 'You must specify a series id.' );
2016-05-10 13:23:43 +02:00
}
}
public function getName (){
return ( ! empty ( $this -> request ) ? $this -> request . ' - ' : '' ) . 'RTBF Bridge' ;
}
public function getCacheDuration (){
return 21600 ; // 6 hours
}
}