Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Feb 2, 2024
1 parent d85d799 commit f86305c
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 55 deletions.
1 change: 0 additions & 1 deletion legacy/application/common/FileDataHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ public static function renderImage($file)
{
if ($file && file_exists($file)) {
$im = @imagecreatefromjpeg($file);

$img = $im;

if ($im) {
Expand Down
12 changes: 2 additions & 10 deletions legacy/application/controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,7 @@ public function liveInfoAction()

// default to the station timezone
$timezone = Application_Model_Preference::GetDefaultTimezone();
if ($request->getParam('timezone')) {
$userDefinedTimezone = strtolower($request->getParam('timezone'));
} else {
$userDefinedTimezone = '';
}
$userDefinedTimezone = strtolower($request->getParam('timezone') ?? '');
$upcase = false; // only upcase the timezone abbreviations
$this->updateTimezone($userDefinedTimezone, $timezone, $upcase);

Expand Down Expand Up @@ -414,11 +410,7 @@ public function liveInfoV2Action()

// default to the station timezone
$timezone = Application_Model_Preference::GetDefaultTimezone();
if ($request->getParam('timezone')) {
$userDefinedTimezone = strtolower($request->getParam('timezone'));
} else {
$userDefinedTimezone = '';
}
$userDefinedTimezone = strtolower($request->getParam('timezone') ?? '');
$upcase = false; // only upcase the timezone abbreviations
$this->updateTimezone($userDefinedTimezone, $timezone, $upcase);

Expand Down
18 changes: 3 additions & 15 deletions legacy/application/controllers/AudiopreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,13 @@ public function audioPreviewAction()
$media = Application_Model_StoredFile::RecallById($audioFileID);
$uri = $baseUrl . 'api/get-media/file/' . $audioFileID;
$mime = $media->getPropelOrm()->getDbMime();
if ($media->getPropelOrm()->getDbArtistName()) {
$this->view->audioFileArtist = htmlspecialchars($media->getPropelOrm()->getDbArtistName());
} else {
$this->view->audioFileArtist = '';
}
if ($media->getPropelOrm()->getDbTrackTitle()) {
$this->view->audioFileTitle = htmlspecialchars($media->getPropelOrm()->getDbTrackTitle());
} else {
$this->view->audioFileTitle = '';
}
$this->view->audioFileArtist = htmlspecialchars($media->getPropelOrm()->getDbArtistName() ?? '');
$this->view->audioFileTitle = htmlspecialchars($media->getPropelOrm()->getDbTrackTitle() ?? '');
} elseif ($type == 'stream') {
$webstream = CcWebstreamQuery::create()->findPk($audioFileID);
$uri = $webstream->getDbUrl();
$mime = $webstream->getDbMime();
if ($webstream->getDbName()) {
$this->view->audioFileTitle = htmlspecialchars($webstream->getDbName());
} else {
$this->view->audioFileTitle = '';
}
$this->view->audioFileTitle = htmlspecialchars($webstream->getDbName() ?? '');
} else {
throw new Exception("Unknown type for audio preview!.Type={$type}");
}
Expand Down
12 changes: 2 additions & 10 deletions legacy/application/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,8 @@ public function indexAction()
$podcastEpisodesService = new Application_Service_PodcastEpisodeService();
$episodes = $podcastEpisodesService->getPodcastEpisodes($stationPodcastId, 0, 0, PodcastEpisodesPeer::PUBLICATION_DATE, 'DESC');
foreach ($episodes as $e => $v) {
if ($v['CcFiles']['track_title']) {
$episodes[$e]['CcFiles']['track_title'] = htmlspecialchars($v['CcFiles']['track_title'], ENT_QUOTES);
} else {
$episodes[$e]['CcFiles']['track_title'] = '';
}
if ($v['CcFiles']['artist_name']) {
$episodes[$e]['CcFiles']['artist_name'] = htmlspecialchars($v['CcFiles']['artist_name'], ENT_QUOTES);
} else {
$episodes[$e]['CcFiles']['artist_name'] = '';
}
$episodes[$e]['CcFiles']['track_title'] = htmlspecialchars($v['CcFiles']['track_title'] ?? '', ENT_QUOTES);
$episodes[$e]['CcFiles']['artist_name'] = htmlspecialchars($v['CcFiles']['artist_name'] ?? '', ENT_QUOTES);

$pubDate = explode(' ', $v['publication_date']);
$episodes[$e]['publication_date'] = $pubDate[0];
Expand Down
2 changes: 1 addition & 1 deletion legacy/application/controllers/ScheduleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public function showContentDialogAction()
$this->view->percentFilled = $show->getPercentScheduled();
$this->view->showContent = $show->getShowListContent();
$this->view->dialog = $this->view->render('schedule/show-content-dialog.phtml');
$this->view->showTitle = $show->getName() ? htmlspecialchars($show->getName()) : '';
$this->view->showTitle = htmlspecialchars($show->getName() ?? '');
unset($this->view->showContent);
}

Expand Down
4 changes: 2 additions & 2 deletions legacy/application/models/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ public function getContents($filterFiles = false)
$row['orig_length'] = $formatter->format();

// XSS exploit prevention
$row['track_title'] = $row['track_title'] ? htmlspecialchars($row['track_title']) : '';
$row['creator'] = $row['creator'] ? htmlspecialchars($row['creator']) : '';
$row['track_title'] = htmlspecialchars($row['track_title'] ?? '');
$row['creator'] = htmlspecialchars($row['creator'] ?? '');
}

return $rows;
Expand Down
4 changes: 2 additions & 2 deletions legacy/application/models/Playlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ public function getContents($filterFiles = false)
$row['orig_length'] = $formatter->format();

// XSS exploit prevention
$row['track_title'] = $row['track_title'] ? htmlspecialchars($row['track_title']) : '';
$row['creator'] = $row['creator'] ? htmlspecialchars($row['creator']) : '';
$row['track_title'] = htmlspecialchars($row['track_title'] ?? '');
$row['creator'] = htmlspecialchars($row['creator'] ?? '');
}

return $rows;
Expand Down
8 changes: 4 additions & 4 deletions legacy/application/models/ShowBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private function makeHeaderRow($p_item)
$row['endDate'] = $showEndDT->format('Y-m-d');
$row['endTime'] = $showEndDT->format('H:i');
$row['duration'] = floatval($showEndDT->format('U.u')) - floatval($showStartDT->format('U.u'));
$row['title'] = $p_item['show_name'] ? htmlspecialchars($p_item['show_name']) : '';
$row['title'] = htmlspecialchars($p_item['show_name'] ?? '');
$row['instance'] = intval($p_item['si_id']);
$row['image'] = '';

Expand Down Expand Up @@ -283,9 +283,9 @@ private function makeScheduledItemRow($p_item)
$formatter = new LengthFormatter(Application_Common_DateHelper::secondsToPlaylistTime($run_time));
$row['runtime'] = $formatter->format();

$row['title'] = $p_item['file_track_title'] ? htmlspecialchars($p_item['file_track_title']) : '';
$row['creator'] = $p_item['file_artist_name'] ? htmlspecialchars($p_item['file_artist_name']) : '';
$row['album'] = $p_item['file_album_title'] ? htmlspecialchars($p_item['file_album_title']) : '';
$row['title'] = htmlspecialchars($p_item['file_track_title'] ?? '');
$row['creator'] = htmlspecialchars($p_item['file_artist_name'] ?? '');
$row['album'] = htmlspecialchars($p_item['file_album_title'] ?? '');

$row['cuein'] = $p_item['cue_in'];
$row['cueout'] = $p_item['cue_out'];
Expand Down
2 changes: 1 addition & 1 deletion legacy/application/services/MediaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static function streamFileDownload($fileId, $inline = false)
*/
public static function areFilesStuckInPending()
{
$oneHourAgo = gmdate(DEFAULT_TIMESTAMP_FORMAT, intval(microtime(true)) - self::PENDING_FILE_TIMEOUT_SECONDS);
$oneHourAgo = gmdate(DEFAULT_TIMESTAMP_FORMAT, time() - self::PENDING_FILE_TIMEOUT_SECONDS);
self::$_pendingFiles = CcFilesQuery::create()
->filterByDbImportStatus(CcFiles::IMPORT_STATUS_PENDING)
->filterByDbUtime($oneHourAgo, Criteria::LESS_EQUAL)
Expand Down
4 changes: 2 additions & 2 deletions legacy/application/services/PodcastEpisodeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public function getPublishStatus($fileId)
*/
public static function getStuckPendingImports()
{
$timeout = gmdate(DEFAULT_TIMESTAMP_FORMAT, intval(microtime(true)) - self::PENDING_EPISODE_TIMEOUT_SECONDS);
$timeout = gmdate(DEFAULT_TIMESTAMP_FORMAT, time() - self::PENDING_EPISODE_TIMEOUT_SECONDS);
$episodes = PodcastEpisodesQuery::create()
->filterByDbFileId()
->find();
Expand Down Expand Up @@ -482,7 +482,7 @@ public function _getImportedPodcastEpisodeArray($podcast, $episodes)
// From the RSS spec best practices:
// 'An item's author element provides the e-mail address of the person who wrote the item'
'author' => $this->_buildAuthorString($item),
'description' => htmlspecialchars($itemdesc),
'description' => htmlspecialchars($item->get_description() ?? ''),
'pub_date' => $item->get_gmdate(),
'link' => $url,
'enclosure' => $enclosure,
Expand Down
14 changes: 7 additions & 7 deletions legacy/application/services/PodcastService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public static function createFromFeedUrl($feedUrl)
$podcastArray = [];
$podcastArray['url'] = $feedUrl;

$podcastArray['title'] = $rss->get_title() ? htmlspecialchars($rss->get_title()) : '';
$podcastArray['description'] = $rss->get_description() ? htmlspecialchars($rss->get_description()) : '';
$podcastArray['link'] = $rss->get_link() ? htmlspecialchars($rss->get_link()) : '';
$podcastArray['language'] = $rss->get_language() ? htmlspecialchars($rss->get_language()) : '';
$podcastArray['copyright'] = $rss->get_copyright() ? htmlspecialchars($rss->get_copyright()) : '';
$podcastArray['title'] = htmlspecialchars($rss->get_title() ?? '');
$podcastArray['description'] = htmlspecialchars($rss->get_description() ?? '');
$podcastArray['link'] = htmlspecialchars($rss->get_link() ?? '');
$podcastArray['language'] = htmlspecialchars($rss->get_language() ?? '');
$podcastArray['copyright'] = htmlspecialchars($rss->get_copyright() ?? '');

$author = $rss->get_author();
$name = empty($author) ? '' : $author->get_name();
$podcastArray['creator'] = $name ? htmlspecialchars($name) : '';
$podcastArray['creator'] = htmlspecialchars($name ?? '');

$categories = [];
if (is_array($rss->get_categories())) {
Expand Down Expand Up @@ -432,7 +432,7 @@ public static function createStationRssFeed()

$imageUrl = Config::getPublicUrl() . 'api/station-logo';
$image = $channel->addChild('image');
$image->addChild('title', htmlspecialchars($podcast->getDbTitle() ? $podcast->getDbTitle() : ''));
$image->addChild('title', htmlspecialchars($podcast->getDbTitle() ?? ''));
self::addEscapedChild($image, 'url', $imageUrl);
self::addEscapedChild($image, 'link', Config::getPublicUrl());

Expand Down

0 comments on commit f86305c

Please sign in to comment.