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 '
'; print albumHeader(array( 'id' => 'communityradiolist', 'Image' => 'newimages/broadcast.svg', 'Searched' => 1, 'AlbumUri' => null, 'Year' => null, 'Artistname' => '', 'Albumname' => get_int_text('label_communityradio'), 'why' => null, 'ImgKey' => 'none', 'class' => 'radio', 'expand' => true )); print '
'; print '
'.get_int_text('label_loading').'
'; 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 '
'; print '
'; print ''; print '
'; print '
'; print '
Order By:
'; print ''; print '
'; } public function doRequest() { $url = ''; switch ($this->listby) { case 'country': $url = 'http://www.radio-browser.info/webservice/json/stations/bycountryexact/'.rawurlencode($this->country).'?'; print '
Country - '.ucwords($this->country).'
'; break; case 'language': $url = 'http://www.radio-browser.info/webservice/json/stations/bylanguageexact/'.rawurlencode($this->language).'?'; print '
Language - '.ucwords($this->language).'
'; break; case 'tag': $url = 'http://www.radio-browser.info/webservice/json/stations/bytagexact/'.rawurlencode($this->tag).'?'; print '
Tag - '.ucwords($this->tag).'
'; break; case 'search': $url = 'http://www.radio-browser.info/webservice/json/stations/search?'; $ourterms = array(); foreach ($this->searchterms as $t) { if (array_key_exists($t, $_REQUEST) && $_REQUEST[$t] != '') { $ourterms[] = $t.'='.rawurlencode($_REQUEST[$t]); } } print '
'.get_int_text('button_search').' - '.rawurldecode(implode(', ', $ourterms)).'
'; $url .= implode('&', $ourterms).'&'; break; } $url .= 'order='.$this->order; switch ($this->order) { case 'bitrate': case 'votes': $url .= '&reverse=true'; break; } $d = new url_downloader(array('url' => $url)); if ($d->get_data_to_string()) { $stations = json_decode($d->get_data(), true); $this->comm_radio_do_page_buttons($this->page, count($stations), $this->pagination); for ($i = 0; $i < $this->pagination; $i++) { $index = $this->page * $this->pagination + $i; if ($index >= count($stations)) { break; } $this->doStation($this->comm_radio_sanitise_station($stations[$index]), $index); } $this->comm_radio_do_page_buttons($this->page, count($stations), $this->pagination); } } public function closeDropdown() { 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 '
'; trackControlHeader('','','communityradio_'.$index, array(array('Image' => $this->comm_radio_get_image($station)))); print '
Listen:
'; print ''; print '
'.utf8_encode($station['state']).utf8_encode($station['country']).'
'; print '
'.utf8_encode($station['votes']).' Upvotes, '.utf8_encode($station['negativevotes']).' Downvotes
'; if ($station['homepage']) { print ''; print ''; print ''; } print '
'; } private function makeSelector($json, $which, $setting) { 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(); } ?>