public static function api($row_obj, $include_episodes = TRUE) { if ($row_obj instanceof self) { $row = $row_obj->toArray(); $row['stations'] = array(); if ($row_obj->stations) { foreach ($row_obj->stations as $station) { $row['stations'][] = Station::api($station); } } $row['episodes'] = array(); if ($include_episodes && $row_obj->episodes) { foreach ($row_obj->episodes as $episode) { $row['episodes'][] = $episode; } } } else { $row = $row_obj; if (isset($row['stations'])) { $stations_raw = array(); foreach ($row['stations'] as $station) { $stations_raw[] = Station::api($station); } $row['stations'] = $stations_raw; } else { $row['stations'] = array(); } if (!isset($row['episodes'])) { $row['episodes'] = array(); } } $api_row = array('id' => (int) $row['id'], 'name' => $row['name'], 'country' => $row['country'], 'description' => $row['description'], 'image_url' => \PVL\Url::upload(self::getArtistImage($row['image_url'])), 'banner_url' => \PVL\Url::upload($row['banner_url']), 'stations' => (array) $row['stations'], 'is_adult' => (bool) $row['is_adult']); if ($include_episodes) { $api_row['episodes'] = array(); $i = 1; foreach ((array) $row['episodes'] as $ep) { if (is_int($include_episodes) && $i > $include_episodes) { break; } $api_row['episodes'][] = PodcastEpisode::api($ep); $i++; } } $social_types = array_keys(self::getSocialTypes()); foreach ($social_types as $type_key) { $api_row[$type_key] = $row[$type_key]; } return $api_row; }
public static function api($row_raw) { if (empty($row_raw)) { return array(); } if ($row_raw instanceof self) { $row_raw = $row_raw->toArray(); } $row = array('id' => (int) $row_raw['id'], 'station_id' => (int) $row_raw['station_id'], 'guid' => $row_raw['guid'], 'start_time' => (int) $row_raw['start_time'], 'end_time' => (int) $row_raw['end_time'], 'is_all_day' => (bool) $row_raw['is_all_day'], 'title' => $row_raw['title'], 'location' => $row_raw['location'], 'body' => $row_raw['body'], 'banner_url' => $row_raw['banner_url'], 'web_url' => $row_raw['web_url'], 'range' => $row_raw['range'] ?: self::getRangeText($row_raw['start_time'], $row_raw['end_time'], $row_raw['is_all_day']), 'image_url' => \PVL\Url::upload(self::getRowImageUrl($row_raw))); if (isset($row_raw['minutes_until'])) { $row['minutes_until'] = (int) $row_raw['minutes_until']; } // Add station shortcode. if (isset($row_raw['station'])) { $row['station'] = Station::api($row_raw['station']); $shortcode = Station::getStationShortName($row_raw['station']['name']); $row['station_shortcode'] = $shortcode; } return $row; }
public function renderView() { if (empty($this->_previous_value)) { return ''; } $file_rows = array(); $i = 1; foreach ((array) $this->_previous_value as $file) { $file_url = \PVL\Url::upload($file); $file_rows[] = '<div><img class="thumbnail" src="' . $file_url . '" alt="Image #' . $i . '" style="max-width: 300px;"></div>'; $i++; } return implode('', $file_rows); }
public function render($attributes = null) { $return = ''; if (!empty($this->_previous_value)) { $return .= '<div>New uploads will replace your existing files. View existing files: '; $existing_files = array(); foreach ((array) $this->_previous_value as $file) { $file_url = \PVL\Url::upload($file); $existing_files[] = '<a href="' . $file_url . '" target="_blank">Download</a>'; } $return .= implode(', ', $existing_files) . '</div>'; } $return .= parent::render($attributes); return $return; }
public static function api($row) { $coverage_levels = self::getCoverageLevels(); $con = array('id' => $row['id'], 'name' => $row['name'], 'location' => $row['location'], 'coverage' => $row['coverage_level'], 'coverage_details' => $coverage_levels[$row['coverage_level']], 'date_range' => self::getDateRange($row['start_date'], $row['end_date']), 'start_date' => $row['start_date'], 'end_date' => $row['end_date'], 'web_url' => $row['web_url']); if (!empty($row['image_url'])) { $con['image_url'] = \PVL\Url::upload($row['image_url']); } if (!empty($row['thumbnail_url'])) { $con['thumbnail_url'] = \PVL\Url::upload($row['thumbnail_url']); } return $con; }
/** * Process a single audio stream's NowPlaying info. * * @param StationStream $stream * @param Station $station * @return array Structured NowPlaying Data */ public static function processAudioStream(StationStream $stream, Station $station, $force = false) { $current_np_data = (array) $stream->nowplaying_data; // Only process non-default streams on odd-numbered "segments" to improve performance. if (!$stream->is_default && !$force && NOWPLAYING_SEGMENT % 2 == 0 && !empty($current_np_data)) { return $current_np_data; } $np = StationStream::api($stream); $custom_class = Station::getStationClassName($station->name); $custom_adapter = '\\PVL\\RadioAdapter\\' . $custom_class; if (class_exists($custom_adapter)) { $np_adapter = new $custom_adapter($stream, $station); } elseif ($stream->type == "icecast") { $np_adapter = new \PVL\RadioAdapter\IceCast($stream, $station); } elseif ($stream->type == "icebreath") { $np_adapter = new \PVL\RadioAdapter\IceBreath($stream, $station); } elseif ($stream->type == "shoutcast2") { $np_adapter = new \PVL\RadioAdapter\ShoutCast2($stream, $station); } elseif ($stream->type == "shoutcast1") { $np_adapter = new \PVL\RadioAdapter\ShoutCast1($stream, $station); } else { return array(); } Debug::log('Adapter Class: ' . get_class($np_adapter)); $stream_np = $np_adapter->process(); $np = array_merge($np, $stream_np['meta']); $np['listeners'] = $stream_np['listeners']; // Pull from current NP data if song details haven't changed. $current_song_hash = Song::getSongHash($stream_np['current_song']); if (strcmp($current_song_hash, $current_np_data['current_song']['id']) == 0) { $np['current_song'] = $current_np_data['current_song']; $np['song_history'] = $current_np_data['song_history']; } else { if (empty($stream_np['current_song']['text'])) { $np['current_song'] = array(); $np['song_history'] = $station->getRecentHistory($stream); } else { // Register a new item in song history. $np['current_song'] = array(); $np['song_history'] = $station->getRecentHistory($stream); // Determine whether to log this song play for analytics. $log_radio_play = $stream->is_default && $station->category == 'audio'; $song_obj = Song::getOrCreate($stream_np['current_song'], $log_radio_play); $sh_obj = SongHistory::register($song_obj, $station, $stream, $np); // Compose "current_song" object for API. $current_song = Song::api($song_obj); $current_song['sh_id'] = $sh_obj->id; $current_song['score'] = SongVote::getScoreForStation($song_obj, $station); $vote_urls = array(); $vote_functions = array('like', 'dislike', 'clearvote'); foreach ($vote_functions as $vote_function) { $vote_urls[$vote_function] = \PVL\Url::api(array('module' => 'api', 'controller' => 'song', 'action' => $vote_function, 'sh_id' => $sh_obj->id)); } $current_song['vote_urls'] = $vote_urls; $external = $song_obj->getExternal(); if ($external) { $current_song['external'] = $song_obj->getExternal(); } $np['current_song'] = $current_song; } } $stream->nowplaying_data = $np; return $np; }
public function nowplayingAction() { $this->redirect(\PVL\Url::upload('api/nowplaying.json')); return; }
public static function _runScheduleItems(\Phalcon\DiInterface $di) { $news_items = array(); $em = $di->get('em'); // Pull promoted schedule items. $events_raw = $em->createQuery('SELECT st, s FROM \\Entity\\Schedule s JOIN s.station st WHERE (s.end_time >= :current AND s.start_time <= :future) AND (st.banner_url != \'\' AND st.banner_url IS NOT NULL) AND s.is_promoted = 1 ORDER BY s.start_time ASC')->setParameter('current', time())->setParameter('future', strtotime('+1 week'))->getArrayResult(); $promoted_stations = array(); foreach ($events_raw as $event) { $station_id = $event['station_id']; if (isset($promoted_stations[$station_id])) { continue; } else { $promoted_stations[$station_id] = true; } $range = Schedule::getRangeText($event['start_time'], $event['end_time'], $event['is_all_day']); $description = array(); $description[] = 'Coming up on ' . $event['station']['name']; $description[] = $range; if (!empty($event['body'])) { $description[] = $event['body']; } // Manually adjust the sorting timestamp for the event if it is in the future. $sort_timestamp = $event['start_time']; if ($sort_timestamp >= time()) { $sort_timestamp = time() - ($sort_timestamp - time()); } $news_items[] = array('id' => 'schedule_' . $event['guid'], 'title' => trim($event['title']), 'source' => 'station', 'body' => implode('<br>', $description), 'image_url' => \PVL\Url::upload($event['station']['banner_url']), 'web_url' => $event['station']['web_url'], 'layout' => 'vertical', 'tags' => array($event['station']['name'], 'Events'), 'sort_timestamp' => $sort_timestamp, 'display_timestamp' => $event['start_time']); break; } return $news_items; }
public static function api($row) { if ($row instanceof self) { $row = $row->toArray(); } $api = array('id' => (int) $row['id'], 'name' => $row['name'], 'shortcode' => self::getStationShortName($row['name']), 'genre' => $row['genre'], 'category' => $row['category'], 'affiliation' => $row['affiliation'], 'image_url' => \PVL\Url::upload($row['image_url']), 'web_url' => $row['web_url'], 'twitter_url' => $row['twitter_url'], 'irc' => $row['irc'], 'sort_order' => (int) $row['weight']); if (isset($row['streams'])) { $api['streams'] = array(); foreach ((array) $row['streams'] as $stream) { $api['streams'][] = StationStream::api($stream); // Set first stream as default, override if a later stream is explicitly default. if ($stream['is_default'] || !isset($api['default_stream_id'])) { $api['default_stream_id'] = (int) $stream['id']; $api['stream_url'] = $stream['stream_url']; } } } $api['player_url'] = ShortUrl::stationUrl($api['shortcode']); if ($row['requests_enabled']) { $api['request_url'] = \DF\Url::route(array('module' => 'default', 'controller' => 'station', 'action' => 'request', 'id' => $row['id'])); } else { $api['request_url'] = ''; } return $api; }