Example #1
0
 public function indexAction()
 {
     $urls = $this->em->createQuery('SELECT su, s FROM Entity\\ShortUrl su LEFT JOIN su.station s ORDER BY su.station_id, su.short_url ASC')->getArrayResult();
     $global_custom_urls = array();
     $station_custom_urls = array();
     foreach ($urls as $url) {
         if ($url['station']) {
             $station_custom_urls[] = $url;
         } else {
             $global_custom_urls[] = $url;
         }
     }
     $this->view->station_custom_urls = $station_custom_urls;
     $this->view->global_custom_urls = $global_custom_urls;
     // Auto-Generated Station URLs.
     $station_details = Station::getShortNameLookup();
     $station_categories = Station::getCategories();
     $station_urls = array();
     foreach ($station_details as $short_name => $station) {
         $station['url'] = ShortUrl::getFullUrl($short_name);
         $station['icon'] = $station_categories[$station['category']]['icon'];
         $station_urls[$short_name] = $station;
     }
     $this->view->station_urls = $station_urls;
     // Auto-Generated Convention Archive URLs
     $convention_details = Convention::getShortNameLookup();
     $convention_urls = array();
     foreach ($convention_details as $short_name => $convention) {
         $convention['url'] = ShortUrl::getFullUrl($short_name);
         $convention_urls[$short_name] = $convention;
     }
     $this->view->convention_urls = $convention_urls;
 }
Example #2
0
 public static function generate()
 {
     set_time_limit(60);
     // Fix DF\URL // prefixing.
     \DF\Url::forceSchemePrefix(true);
     $nowplaying = self::loadNowPlaying();
     // Post statistics to official record (legacy for duplication, for now)
     // Analytics::post($nowplaying['api']);
     // Post statistics to InfluxDB.
     $influx = self::getInflux();
     $influx->setDatabase('pvlive_stations');
     $active_shortcodes = Station::getShortNameLookup();
     $total_overall = 0;
     foreach ($nowplaying['api'] as $short_code => $info) {
         $listeners = (int) $info['listeners']['current'];
         $station_id = $info['station']['id'];
         if (isset($active_shortcodes[$short_code])) {
             $total_overall += $listeners;
         }
         $influx->insert('station.' . $station_id . '.listeners', ['value' => $listeners]);
     }
     $influx->insert('all.listeners', ['value' => $total_overall]);
     // Clear any records that are not audio/video category.
     $api_categories = array('audio', 'video');
     foreach ($nowplaying['api'] as $station_shortcode => $station_info) {
         if (!in_array($station_info['station']['category'], $api_categories)) {
             unset($nowplaying['api'][$station_shortcode]);
             unset($nowplaying['legacy'][$station_shortcode]);
         }
     }
     // Generate PVL legacy nowplaying file.
     $nowplaying_feed = json_encode($nowplaying['legacy'], JSON_UNESCAPED_SLASHES);
     $pvl_file_path = \PVL\Service\AmazonS3::path('api/nowplaying.json');
     @file_put_contents($pvl_file_path, $nowplaying_feed);
     $legacy_file_path = DF_INCLUDE_STATIC . '/api/nowplaying.json';
     @file_put_contents($legacy_file_path, $nowplaying_feed);
     // Generate PVL API cache.
     $np_api = $nowplaying['api'];
     foreach ($np_api as $station => $np_info) {
         $np_api[$station]['cache'] = 'hit';
     }
     Cache::save($np_api, 'api_nowplaying_data', array('nowplaying'), 60);
     foreach ($np_api as $station => $np_info) {
         $np_api[$station]['cache'] = 'flatfile';
     }
     // Generate PVL API nowplaying file.
     $file_path_api = \PVL\Service\AmazonS3::path('api/nowplaying_api.json');
     $nowplaying_api = json_encode(array('status' => 'success', 'result' => $np_api), JSON_UNESCAPED_SLASHES);
     @file_put_contents($file_path_api, $nowplaying_api);
     // Push to live-update service.
     PvlNode::push('nowplaying', $nowplaying['api']);
     return $pvl_file_path;
 }
Example #3
0
 /**
  * Static Functions
  */
 public static function post($nowplaying)
 {
     $em = self::getEntityManager();
     $active_shortcodes = Station::getShortNameLookup();
     $total_overall = 0;
     foreach ($nowplaying as $short_code => $info) {
         $listeners = (int) $info['listeners']['current'];
         $station_id = $info['station']['id'];
         if (isset($active_shortcodes[$short_code])) {
             $total_overall += $listeners;
         }
         $record = new self();
         $record->fromArray(array('station_id' => $station_id, 'type' => 'second', 'timestamp' => time(), 'number_min' => $listeners, 'number_max' => $listeners, 'number_avg' => $listeners));
         $em->persist($record);
     }
     // Create "overall" statistic.
     $record = new self();
     $record->fromArray(array('type' => 'second', 'timestamp' => time(), 'number_min' => $total_overall, 'number_max' => $total_overall, 'number_avg' => $total_overall));
     $em->persist($record);
     $em->flush();
 }
Example #4
0
 public function indexAction()
 {
     $urls = $this->em->createQuery('SELECT su FROM Entity\\ShortUrl su WHERE su.station_id = :station_id ORDER BY su.timestamp ASC')->setParameter('station_id', $this->station->id)->execute();
     $this->view->urls = $urls;
     // Auto-Generated Station URLs.
     $station_details = Station::getShortNameLookup();
     $station_categories = Station::getCategories();
     $station_urls = array();
     foreach ($station_details as $short_name => $station) {
         $station['url'] = ShortUrl::getFullUrl($short_name);
         $station['icon'] = $station_categories[$station['category']]['icon'];
         $station_urls[$short_name] = $station;
     }
     $this->view->station_urls = $station_urls;
     // Auto-Generated Convention Archive URLs
     $convention_details = Convention::getShortNameLookup();
     $convention_urls = array();
     foreach ($convention_details as $short_name => $convention) {
         $convention['url'] = ShortUrl::getFullUrl($short_name);
         $convention_urls[$short_name] = $convention;
     }
     $this->view->convention_urls = $convention_urls;
 }
Example #5
0
 public function indexAction()
 {
     // Get calendar name.
     $short_names = Station::getShortNameLookup();
     $station_shortcode = $this->getParam('station', 'all');
     if ($station_shortcode != "all") {
         $station = $short_names[$station_shortcode];
         $calendar_name = $station['name'];
     } else {
         $calendar_name = 'Ponyville Live!';
     }
     // Get timestamp boundaries.
     if ($this->hasParam('month')) {
         $show = $this->getParam('month');
         $calendar = new \DF\Calendar($show);
         $timestamps = $calendar->getTimestamps();
         $start_timestamp = $timestamps['start'];
         $end_timestamp = $timestamps['end'];
         $use_cache = true;
         $cache_name = 'month_' . $show;
         $calendar_name .= ' - ' . date('F Y', $timestamps['mid']);
     } elseif ($this->hasParam('start')) {
         $start_timestamp = (int) $this->getParam('start');
         $end_timestamp = (int) $this->getParam('end');
         $use_cache = false;
         $cache_name = null;
         // $cache_name = 'range_'.$start_timestamp.'_'.$end_timestamp;
         $calendar_name .= ' - ' . date('F j, Y', $start_timestamp) . ' to ' . date('F j, Y', $end_timestamp);
     } else {
         $start_timestamp = time();
         $end_timestamp = time() + 86400 * 30;
         $use_cache = true;
         $cache_name = 'upcoming';
         $calendar_name .= ' - Upcoming';
     }
     // Load from cache or regenerate.
     if ($use_cache) {
         $cache_name = 'api_sched_' . $station_shortcode . '_' . $cache_name;
         $events = \DF\Cache::get($cache_name);
     } else {
         $events = null;
     }
     if (!$events) {
         if ($station_shortcode != "all") {
             $station = $short_names[$station_shortcode];
             $events_raw = $this->em->createQuery('SELECT s FROM Entity\\Schedule s WHERE (s.station_id = :sid) AND (s.start_time <= :end AND s.end_time >= :start) ORDER BY s.start_time ASC')->setParameter('sid', $station['id'])->setParameter('start', $start_timestamp)->setParameter('end', $end_timestamp)->getArrayResult();
         } else {
             $events_raw = $this->em->createQuery('SELECT s, st FROM Entity\\Schedule s LEFT JOIN s.station st WHERE (s.start_time <= :end AND s.end_time >= :start) ORDER BY s.start_time ASC')->setParameter('start', $start_timestamp)->setParameter('end', $end_timestamp)->getArrayResult();
         }
         $events = array();
         foreach ((array) $events_raw as $event) {
             $events[] = Schedule::api($event);
         }
         if ($use_cache) {
             \DF\Cache::save($events, $cache_name, array(), 300);
         }
     }
     $format = strtolower($this->getParam('format', 'json'));
     switch ($format) {
         case "ics":
         case "ical":
             return $this->_printCalendar($events, $calendar_name, $cache_name);
             break;
         case "json":
         default:
             return $this->returnSuccess($events);
             break;
     }
 }
Example #6
0
 public static function stationUrls()
 {
     $urls = array();
     $short_names = Station::getShortNameLookup();
     foreach ($short_names as $short_name => $record) {
         $urls[$short_name] = \DF\Url::route(array('module' => 'default', 'controller' => 'index', 'action' => 'index', 'id' => $record['id'], 'autoplay' => 'true'));
     }
     return $urls;
 }
Example #7
0
 public function songconfirmAction()
 {
     // Handle files submitted directly to page.
     $ignore_files = (int) $this->getParam('ignore_files');
     $request = $this->di->get('request');
     if ($request->hasFiles() && !$ignore_files) {
         $this->_processSongUpload();
     }
     // Validate song identifier token.
     $token = $this->_getSongHashToken();
     if (!$this->_validateSongHash($token)) {
         return $this->redirectFromHere(array('action' => 'song'));
     }
     // Check that any stations were selected
     if (!$this->hasParam('stations')) {
         throw new \DF\Exception\DisplayOnly('You did not specify any stations!');
     }
     // Check for uploaded songs.
     $temp_dir_name = 'song_uploads';
     $temp_dir = DF_INCLUDE_TEMP . DIRECTORY_SEPARATOR . $temp_dir_name;
     $all_files = glob($temp_dir . DIRECTORY_SEPARATOR . $token . '*.mp3');
     if (empty($all_files)) {
         throw new \DF\Exception\DisplayOnly('No files were uploaded!');
     }
     $songs = array();
     $getId3 = new GetId3();
     $getId3->encoding = 'UTF-8';
     foreach ($all_files as $song_file_base) {
         $song_file_path = $temp_dir . DIRECTORY_SEPARATOR . basename($song_file_base);
         // Attempt to analyze the MP3.
         $audio = $getId3->analyze($song_file_path);
         if (isset($audio['error'])) {
             @unlink($song_file_path);
             throw new \DF\Exception\DisplayOnly(sprintf('Error at reading audio properties with GetId3: %s.', $audio['error'][0]));
         }
         if (isset($audio['tags']['id3v1']['title'])) {
             $song_data = array('title' => $audio['tags']['id3v1']['title'][0], 'artist' => $audio['tags']['id3v1']['artist'][0]);
         } elseif (isset($audio['tags']['id3v2']['title'])) {
             $song_data = array('title' => $audio['tags']['id3v2']['title'][0], 'artist' => $audio['tags']['id3v2']['artist'][0]);
         } else {
             @unlink($song_file_path);
             continue;
         }
         // Check if existing submission exists.
         $song = Song::getOrCreate($song_data);
         $existing_submission = SongSubmission::getRepository()->findOneBy(array('hash' => $song->id));
         if ($existing_submission instanceof SongSubmission) {
             @unlink($song_file_path);
             continue;
         }
         // Create record in database.
         $metadata = array('File Format' => strtoupper($audio['fileformat']), 'Play Time' => $audio['playtime_string'], 'Bitrate' => round($audio['audio']['bitrate'] / 1024) . 'kbps', 'Bitrate Mode' => strtoupper($audio['audio']['bitrate_mode']), 'Channels' => $audio['audio']['channels'], 'Sample Rate' => $audio['audio']['sample_rate']);
         $record = new SongSubmission();
         $record->song = $song;
         $auth = $this->di->get('auth');
         $record->user = $auth->getLoggedInUser();
         $record->title = $song_data['title'];
         $record->artist = $song_data['artist'];
         $record->song_metadata = $metadata;
         $record->stations = $this->getParam('stations');
         $song_download_url = $record->uploadSong($song_file_path);
         $record->save();
         // Append information to e-mail to stations.
         $song_row = array('Download URL' => '<a href="' . $song_download_url . '" target="_blank">' . $song_download_url . '</a>', 'Title' => $song_data['title'], 'Artist' => $song_data['artist']) + $metadata;
         $songs[] = $song_row;
     }
     if (!empty($songs)) {
         // Notify all existing managers.
         $network_administrators = Action::getUsersWithAction('administer all');
         $email_to = Utilities::ipull($network_administrators, 'email');
         // Pull list of station managers for the specified stations.
         $station_managers = array();
         $short_names = Station::getShortNameLookup();
         foreach ($this->getParam('stations') as $station_key) {
             if (isset($short_names[$station_key])) {
                 $station_id = $short_names[$station_key]['id'];
                 $station = Station::find($station_id);
                 foreach ($station->managers as $manager) {
                     $station_managers[] = $manager->email;
                 }
             }
         }
         $email_to = array_merge($email_to, $station_managers);
         // Trigger e-mail notice.
         if (!empty($email_to)) {
             \DF\Messenger::send(array('to' => $email_to, 'subject' => 'New Song(s) Submitted to Station', 'template' => 'newsong', 'vars' => array('songs' => $songs)));
         }
     }
     // Have to manually call view because a view was already rendered (e-mail was sent).
     // TODO: Fix this. It's dumb.
     $this->view->songs = $songs;
     return $this->view->render('submit', 'songconfirm');
 }