pagination = 50;
$this->searchterms = array('name', 'country', 'state', 'language', 'tag');
$this->page = 0;
}
public function parseParams() {
$this->page = $_REQUEST['page'];
$this->country = array_key_exists('country', $_REQUEST) ? $_REQUEST['country'] : '';
$this->language = array_key_exists('language', $_REQUEST) ? $_REQUEST['language'] : '';
$this->tag = array_key_exists('tag', $_REQUEST) ? $_REQUEST['tag'] : '';
$this->listby = $_REQUEST['listby'];
$this->order = $_REQUEST['order'];
}
public function doHeader() {
print '
';
}
public function doDropdownHeader() {
global $prefs;
directoryControlHeader('communityradiolist', get_int_text('label_communityradio'));
print 'List By:
';
$d = new url_downloader(array('url' => 'http://www.radio-browser.info/webservice/json/countries'));
if ($d->get_data_to_string()) {
$countries = json_decode($d->get_data(), true);
$this->makeSelector($countries, 'country', $this->country);
}
$d = new url_downloader(array('url' => 'http://www.radio-browser.info/webservice/json/languages'));
if ($d->get_data_to_string()) {
$langs = json_decode($d->get_data(), true);
$this->makeSelector($langs, 'language', $this->language);
}
$d = new url_downloader(array('url' => 'http://www.radio-browser.info/webservice/json/tags'));
if ($d->get_data_to_string()) {
$tags = json_decode($d->get_data(), true);
$this->makeSelector($tags, 'tag', $this->tag);
}
print 'Search All Stations:
';
print '';
foreach ($this->searchterms as $term) {
print '
';
print '
'.ucfirst($term).'
';
print '
';
print '';
print '
';
print '
';
}
print '
';
print '
';
print '
';
print '
';
print '
';
print 'Order By:
';
print '';
print '
';
print '';
print '
';
print '
';
print '';
}
// -- Private Functions -- //
private function doStation($station, $index) {
print albumHeader(array(
'id' => 'communityradio_'.$index,
'Image' => $this->comm_radio_get_image($station),
'Searched' => 1,
'AlbumUri' => null,
'Year' => null,
'Artistname' => preg_replace('/,/', ', ', htmlspecialchars($station['tags'])),
'Albumname' => htmlspecialchars($station['name']),
'why' => 'whynot',
'ImgKey' => 'none',
'streamuri' => $station['playurl'],
'streamname' => $station['name'],
'streamimg' => $this->comm_radio_get_stream_image($station),
'class' => 'radiochannel'
));
print '';
}
private function makeSelector($json, $which, $setting) {
print '';
$this->comm_radio_make_list_button($which);
print '
';
print '';
print '
';
print '
';
}
private function comm_radio_make_list_button($which) {
print '';
print '';
print 'listby == $which) {
print ' checked';
}
print ' />';
print '';
print '';
print '
';
}
private function comm_radio_get_image($station) {
if ($station['favicon']) {
if (substr($station['favicon'], 0, 10) == 'data:image') {
return $station['favicon'];
} else {
return 'getRemoteImage.php?url='.$station['favicon'].'&rompr_backup_type=stream';
}
} else {
return 'newimages/broadcast.svg';
}
}
private function comm_radio_get_stream_image($station) {
if ($station['favicon']) {
if (substr($station['favicon'], 0, 10) == 'data:image') {
// Sadly we can't handle base64 data as a stream image in this way. The URLs are too long
return '';
} else {
return 'getRemoteImage.php?url='.$station['favicon'];
}
} else {
return '';
}
}
private function comm_radio_do_page_buttons($page, $count, $per_page) {
print '';
$firstpage = max(0, $page-4);
$lastpage = min($firstpage+9, round(($count/$per_page), 0, PHP_ROUND_HALF_DOWN));
print '';
print '
';
}
private function comm_radio_sanitise_station($station) {
global $prefs;
$blank_station = array(
'tags' => '',
'name' => ROMPR_UNKNOWN_STREAM,
'state' => '',
'country' => '',
'votes' => 0,
'negativevotes' => 0,
'codec' => 'Unknown Codec',
'bitrate' => 'Unknown ',
'favicon' => null,
'homepage' => null
);
$result = array_merge($blank_station, $station);
if ($result['state'] && $result['country']) {
$result['state'] .= ', ';
}
if ($result['bitrate'] == 0) {
$result['bitrate'] = 'Unknown ';
}
// No real idea whay one works for one player but not the other. MPD won't load the M3U files,
// Mopidy won't load the PLS files. All I do is send a load/add and a URL.....
if ($prefs['player_backend'] == 'mpd') {
$result['playurl'] = 'http://www.radio-browser.info/webservice/v2/pls/url/'.$station['id'];
} else {
$result['playurl'] = 'http://www.radio-browser.info/webservice/v2/m3u/url/'.$station['id'];
}
return $result;
}
}
if (array_key_exists('populate', $_REQUEST)) {
chdir('..');
include ("includes/vars.php");
include ("includes/functions.php");
include ("international.php");
include ("skins/".$skin."/ui_elements.php");
foreach ($_REQUEST as $i => $r) {
logger::log("COMMRADIO", $i,":",$r);
}
$commradio = new commradioplugin();
$commradio->parseParams();
if ($_REQUEST['populate'] == 1) {
$commradio->doDropdownHeader();
}
$commradio->doRequest();
if ($_REQUEST['populate'] == 1) {
$commradio->closeDropdown();
}
} else {
$commradio = new commradioplugin();
$commradio->doHeader();
}
?>