public function addadminAction() { $this->doNotRender(); $email = $this->getParam('email'); $user = \Entity\User::getOrCreate($email); $user->podcasts->add($this->podcast); $user->save(); \DF\Messenger::send(array('to' => $user->email, 'subject' => 'Access Granted to Podcast Center', 'template' => 'newperms', 'vars' => array('areas' => array('Podcast Center: ' . $this->podcast->name)))); return $this->redirectFromHere(array('action' => 'index', 'id' => NULL, 'email' => NULL)); }
public function forgotAction() { $form = new \DF\Form($this->current_module_config->forms->forgot); if ($_POST && $form->isValid($_POST)) { $data = $form->getValues(); $user = User::getRepository()->findOneBy(array('email' => $data['contact_email'])); if ($user instanceof User) { $user->generateAuthRecoveryCode(); $user->save(); \DF\Messenger::send(array('to' => $user->email, 'subject' => 'Password Recovery Code', 'template' => 'forgotpw', 'vars' => array('record' => $user))); } $this->alert('<b>A password recovery link has been sent to your e-mail address.</b><br>Click the link in the e-mail to reset your password.', 'green'); $this->redirectHome(); return; } $this->view->setVar('title', 'Forgot My Password'); $this->renderForm($form); }
public function indexAction() { // Assemble list of stations. $all_stations = $this->em->createQuery('SELECT s, u FROM Entity\\Station s LEFT JOIN s.managers u WHERE s.is_active = 1')->getArrayResult(); $station_select = array(); $station_contacts = array(); foreach ($all_stations as $station) { $station_id = $station['id']; $station_contact = array(); if (!empty($station['contact_email'])) { $station_contact[] = strtolower($station['contact_email']); } if (!empty($station['managers'])) { foreach ($station['managers'] as $manager) { $station_contact[] = strtolower($manager['email']); } } if (!empty($station_contact)) { $station_text = $station['name']; } else { $station_text = '<span class="text-disabled" title="No e-mail addresses on file!">' . $station['name'] . '</span>'; } $station_select[$station_id] = $station_text; $station_contacts[$station_id] = array_unique($station_contact); } // Assemble list of podcasts. $all_podcasts = $this->em->createQuery('SELECT p, u FROM Entity\\Podcast p LEFT JOIN p.managers u WHERE p.is_approved = 1')->getArrayResult(); $podcast_select = array(); $podcast_contacts = array(); foreach ($all_podcasts as $podcast) { $podcast_id = $podcast['id']; $podcast_contact = array(); if (!empty($podcast['contact_email'])) { $podcast_contact[] = strtolower($podcast['contact_email']); } if (!empty($podcast['managers'])) { foreach ($podcast['managers'] as $manager) { $podcast_contact[] = strtolower($podcast['email']); } } if (!empty($podcast_contact)) { $podcast_text = $podcast['name']; } else { $podcast_text = '<span class="text-disabled" title="No e-mail addresses on file!">' . $podcast['name'] . '</span>'; } $podcast_select[$podcast_id] = $podcast_text; $podcast_contacts[$podcast_id] = array_unique($podcast_contact); } // Assemble contact form. $form_info = $this->current_module_config->forms->contact->form->toArray(); $form_info['groups']['recipients']['elements']['stations'][1]['multiOptions'] = $station_select; $form_info['groups']['recipients']['elements']['podcasts'][1]['multiOptions'] = $podcast_select; $form = new \DF\Form($form_info); if ($_POST && $form->isValid($_POST)) { $data = $form->getValues(); $email_to = array(); foreach ((array) $data['stations'] as $station_id) { $email_to = array_merge($email_to, $station_contacts[$station_id]); } foreach ((array) $data['podcasts'] as $podcast_id) { $email_to = array_merge($email_to, $podcast_contacts[$podcast_id]); } $email_to = array_unique($email_to); \DF\Messenger::send(array('to' => $email_to, 'subject' => $data['subject'], 'template' => 'bulkcontact', 'vars' => array('body' => nl2br($data['body'])))); $this->alert('<b>Message sent to ' . count($email_to) . ' recipient(s)!</b>', 'green'); return $this->redirectHere(); } $this->view->form = $form; }
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'); }