chore(legacy): use Config::getPublicUrl helper

Replace Application_Common_HTTPHelper::getStationUrl with Config::getPublicUrl.
This commit is contained in:
jo 2022-07-07 23:32:43 +02:00 committed by Kyle Robbertze
parent 72960593c7
commit 829b9bcd5b
17 changed files with 23 additions and 51 deletions

View File

@ -82,7 +82,7 @@ class FileDataHelper
*/ */
public static function getArtworkData($file, $size, $filepath = false) public static function getArtworkData($file, $size, $filepath = false)
{ {
$baseUrl = Application_Common_HTTPHelper::getStationUrl(); $baseUrl = Config::getPublicUrl();
$default = $baseUrl . 'css/images/no-cover.jpg'; $default = $baseUrl . 'css/images/no-cover.jpg';
if ($filepath != false) { if ($filepath != false) {

View File

@ -1,7 +1,5 @@
<?php <?php
use League\Uri\Uri;
class Application_Common_HTTPHelper class Application_Common_HTTPHelper
{ {
/** /**
@ -22,29 +20,6 @@ class Application_Common_HTTPHelper
); );
} }
/**
* Construct the base station URL.
*
* @param bool $secured whether or not to use HTTPS
*
* @return string the station URL
*/
public static function getStationUrl($secured = true)
{
$CC_CONFIG = Config::getConfig();
$url = Uri::createFromComponents(
[
'scheme' => $CC_CONFIG['protocol'],
'host' => $CC_CONFIG['baseUrl'],
'port' => $CC_CONFIG['basePort'],
'path' => $CC_CONFIG['baseDir'],
]
);
return rtrim($url, '/') . '/';
}
/** /**
* Execute a cURL POST. * Execute a cURL POST.
* *

View File

@ -161,14 +161,11 @@ class WidgetHelper
*/ */
public static function findAndConvertPaths(&$arr) public static function findAndConvertPaths(&$arr)
{ {
$CC_CONFIG = Config::getConfig();
$baseDir = Application_Common_OsPath::formatDirectoryWithDirectorySeparators($CC_CONFIG['baseDir']);
foreach ($arr as &$a) { foreach ($arr as &$a) {
if (is_array($a)) { if (is_array($a)) {
if (array_key_exists('image_path', $a)) { if (array_key_exists('image_path', $a)) {
$a['image_path'] = $a['image_path'] && $a['image_path'] !== '' ? $a['image_path'] = $a['image_path'] && $a['image_path'] !== '' ?
Application_Common_HTTPHelper::getStationUrl() . 'api/show-logo?id=' . $a['id'] : ''; Config::getPublicUrl() . 'api/show-logo?id=' . $a['id'] : '';
} else { } else {
self::findAndConvertPaths($a); self::findAndConvertPaths($a);
} }

View File

@ -313,7 +313,7 @@ class ApiController extends Zend_Controller_Action
$this->returnJsonOrJsonp($request, []); $this->returnJsonOrJsonp($request, []);
} }
$stationUrl = Application_Common_HTTPHelper::getStationUrl(); $stationUrl = Config::getPublicUrl();
if (isset($result['previous'])) { if (isset($result['previous'])) {
if ( if (
@ -701,7 +701,7 @@ class ApiController extends Zend_Controller_Action
$request = $this->getRequest(); $request = $this->getRequest();
$result['name'] = Application_Model_Preference::GetStationName(); $result['name'] = Application_Model_Preference::GetStationName();
$result['logo'] = Application_Common_HTTPHelper::getStationUrl() . 'api/station-logo'; $result['logo'] = Config::getPublicUrl() . 'api/station-logo';
$result['description'] = Application_Model_Preference::GetStationDescription(); $result['description'] = Application_Model_Preference::GetStationDescription();
$result['timezone'] = Application_Model_Preference::GetDefaultTimezone(); $result['timezone'] = Application_Model_Preference::GetDefaultTimezone();
$result['locale'] = Application_Model_Preference::GetDefaultLocale(); $result['locale'] = Application_Model_Preference::GetDefaultLocale();

View File

@ -79,7 +79,7 @@ class EmbedController extends Zend_Controller_Action
$request = $this->getRequest(); $request = $this->getRequest();
$this->view->angular = Application_Common_HTTPHelper::getStationUrl() . 'js/libs/angular.min.js?' . $CC_CONFIG['airtime_version']; $this->view->angular = Config::getPublicUrl() . 'js/libs/angular.min.js?' . $CC_CONFIG['airtime_version'];
$widgetStyle = $request->getParam('style'); $widgetStyle = $request->getParam('style');
if ($widgetStyle == 'premium') { if ($widgetStyle == 'premium') {
$this->view->widgetStyle = 'premium'; $this->view->widgetStyle = 'premium';

View File

@ -46,7 +46,7 @@ class IndexController extends Zend_Controller_Action
$stationDescription = Application_Model_Preference::GetStationDescription(); $stationDescription = Application_Model_Preference::GetStationDescription();
$this->view->stationDescription = $stationDescription; $this->view->stationDescription = $stationDescription;
$this->view->stationUrl = Application_Common_HTTPHelper::getStationUrl(); $this->view->stationUrl = Config::getPublicUrl();
$displayRadioPageLoginButtonValue = Application_Model_Preference::getRadioPageDisplayLoginButton(); $displayRadioPageLoginButtonValue = Application_Model_Preference::getRadioPageDisplayLoginButton();
if ($displayRadioPageLoginButtonValue == '') { if ($displayRadioPageLoginButtonValue == '') {

View File

@ -99,7 +99,7 @@ class PreferenceController extends Zend_Controller_Action
// Append sharing token (download key) to Station podcast URL // Append sharing token (download key) to Station podcast URL
$stationPodcast = PodcastQuery::create()->findOneByDbId(Application_Model_Preference::getStationPodcastId()); $stationPodcast = PodcastQuery::create()->findOneByDbId(Application_Model_Preference::getStationPodcastId());
$key = Application_Model_Preference::getStationPodcastDownloadKey(); $key = Application_Model_Preference::getStationPodcastDownloadKey();
$url = Application_Common_HTTPHelper::getStationUrl() . $url = Config::getPublicUrl() .
(((int) $values->stationPodcastPrivacy) ? "feeds/station-rss?sharing_token={$key}" : 'feeds/station-rss'); (((int) $values->stationPodcastPrivacy) ? "feeds/station-rss?sharing_token={$key}" : 'feeds/station-rss');
$stationPodcast->setDbUrl($url)->save(); $stationPodcast->setDbUrl($url)->save();
Application_Model_Preference::setStationPodcastPrivacy($values->stationPodcastPrivacy); Application_Model_Preference::setStationPodcastPrivacy($values->stationPodcastPrivacy);

View File

@ -20,7 +20,7 @@ abstract class ThirdPartyController extends Zend_Controller_Action
*/ */
public function init() public function init()
{ {
$this->_baseUrl = Application_Common_HTTPHelper::getStationUrl(); $this->_baseUrl = Config::getPublicUrl();
$this->view->layout()->disableLayout(); // Don't inject the standard Now Playing header. $this->view->layout()->disableLayout(); // Don't inject the standard Now Playing header.
$this->_helper->viewRenderer->setNoRender(true); // Don't use (phtml) templates $this->_helper->viewRenderer->setNoRender(true); // Don't use (phtml) templates

View File

@ -70,7 +70,7 @@ class Application_Form_Player extends Zend_Form_SubForm
->setAttrib('rows', '4'); ->setAttrib('rows', '4');
$embedSrc->setLabel(_('Embeddable code:')); $embedSrc->setLabel(_('Embeddable code:'));
$embedSrc->setDescription(_("Copy this code and paste it into your website's HTML to embed the player in your site.")); $embedSrc->setDescription(_("Copy this code and paste it into your website's HTML to embed the player in your site."));
$embedSrc->setValue('<iframe frameborder="0" width="280" height="216" src="' . Application_Common_HTTPHelper::getStationUrl() . 'embed/player?stream=auto&title=Now Playing"></iframe>'); $embedSrc->setValue('<iframe frameborder="0" width="280" height="216" src="' . Config::getPublicUrl() . 'embed/player?stream=auto&title=Now Playing"></iframe>');
$this->addElement($embedSrc); $this->addElement($embedSrc);
$previewLabel = new Zend_Form_Element_Text('player_preview_label'); $previewLabel = new Zend_Form_Element_Text('player_preview_label');

View File

@ -626,7 +626,7 @@ class Application_Model_Preference
} }
// We return the Airtime logo if no logo is set in the database. // We return the Airtime logo if no logo is set in the database.
// airtime_logo.png is stored under the public directory // airtime_logo.png is stored under the public directory
$image = @file_get_contents(Application_Common_HTTPHelper::getStationUrl() . DEFAULT_LOGO_FILE); $image = @file_get_contents(Config::getPublicUrl() . DEFAULT_LOGO_FILE);
return base64_encode($image); return base64_encode($image);
} }

View File

@ -1050,7 +1050,7 @@ SQL;
$file = $storedFile->getPropelOrm(); $file = $storedFile->getPropelOrm();
// Even local files are downloaded through the REST API in case we need to transform // Even local files are downloaded through the REST API in case we need to transform
// their filenames (eg. in the case of a bad file extension, because Liquidsoap won't play them) // their filenames (eg. in the case of a bad file extension, because Liquidsoap won't play them)
$uri = Application_Common_HTTPHelper::getStationUrl() . 'rest/media/' . $media_id; $uri = Config::getPublicUrl() . 'rest/media/' . $media_id;
// $uri = $file->getAbsoluteFilePath(); // $uri = $file->getAbsoluteFilePath();
$filesize = $file->getFileSize(); $filesize = $file->getFileSize();

View File

@ -168,7 +168,7 @@ class CcFiles extends BaseCcFiles
$file->setDbHidden(true); $file->setDbHidden(true);
$file->save(); $file->save();
$callbackUrl = Application_Common_HTTPHelper::getStationUrl() . 'rest/media/' . $file->getPrimaryKey(); $callbackUrl = Config::getPublicUrl() . 'rest/media/' . $file->getPrimaryKey();
Application_Service_MediaService::importFileToLibrary( Application_Service_MediaService::importFileToLibrary(
$callbackUrl, $callbackUrl,

View File

@ -30,7 +30,7 @@ class PodcastEpisodes extends BasePodcastEpisodes
$ext = FileDataHelper::getAudioMimeTypeArray()[$file->getDbMime()]; $ext = FileDataHelper::getAudioMimeTypeArray()[$file->getDbMime()];
$key = Application_Model_Preference::getStationPodcastDownloadKey(); $key = Application_Model_Preference::getStationPodcastDownloadKey();
return Application_Common_HTTPHelper::getStationUrl() . "rest/media/{$fileId}/download/{$key}.{$ext}"; return Config::getPublicUrl() . "rest/media/{$fileId}/download/{$key}.{$ext}";
} }
return parent::getDbDownloadUrl(); return parent::getDbDownloadUrl();

View File

@ -181,7 +181,7 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
private function _download($id, $url, $title, $album_override, $track_title = null) private function _download($id, $url, $title, $album_override, $track_title = null)
{ {
$CC_CONFIG = Config::getConfig(); $CC_CONFIG = Config::getConfig();
$stationUrl = Application_Common_HTTPHelper::getStationUrl(); $stationUrl = Config::getPublicUrl();
$data = [ $data = [
'id' => $id, 'id' => $id,
'url' => $url, 'url' => $url,
@ -249,7 +249,7 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
public function publish($fileId) public function publish($fileId)
{ {
$id = Application_Model_Preference::getStationPodcastId(); $id = Application_Model_Preference::getStationPodcastId();
$url = $guid = Application_Common_HTTPHelper::getStationUrl() . "rest/media/{$fileId}/download"; $url = $guid = Config::getPublicUrl() . "rest/media/{$fileId}/download";
if (!PodcastEpisodesQuery::create() if (!PodcastEpisodesQuery::create()
->filterByDbPodcastId($id) ->filterByDbPodcastId($id)
->findOneByDbFileId($fileId)) { // Don't allow duplicate episodes ->findOneByDbFileId($fileId)) { // Don't allow duplicate episodes

View File

@ -199,14 +199,14 @@ class Application_Service_PodcastService
public static function createStationPodcast() public static function createStationPodcast()
{ {
$podcast = new Podcast(); $podcast = new Podcast();
$podcast->setDbUrl(Application_Common_HTTPHelper::getStationUrl() . 'feeds/station-rss'); $podcast->setDbUrl(Config::getPublicUrl() . 'feeds/station-rss');
$title = Application_Model_Preference::GetStationName(); $title = Application_Model_Preference::GetStationName();
$title = empty($title) ? "My Station's Podcast" : $title; $title = empty($title) ? "My Station's Podcast" : $title;
$podcast->setDbTitle($title); $podcast->setDbTitle($title);
$podcast->setDbDescription(Application_Model_Preference::GetStationDescription()); $podcast->setDbDescription(Application_Model_Preference::GetStationDescription());
$podcast->setDbLink(Application_Common_HTTPHelper::getStationUrl()); $podcast->setDbLink(Config::getPublicUrl());
$podcast->setDbLanguage(explode('_', Application_Model_Preference::GetLocale())[0]); $podcast->setDbLanguage(explode('_', Application_Model_Preference::GetLocale())[0]);
$podcast->setDbCreator(Application_Model_Preference::GetStationName()); $podcast->setDbCreator(Application_Model_Preference::GetStationName());
$podcast->setDbOwner(self::getOwnerId()); $podcast->setDbOwner(self::getOwnerId());
@ -430,15 +430,15 @@ class Application_Service_PodcastService
$xml->addAttribute('xmlns:xmlns:atom', 'http://www.w3.org/2005/Atom'); $xml->addAttribute('xmlns:xmlns:atom', 'http://www.w3.org/2005/Atom');
$atomLink = $channel->addChild('xmlns:atom:link'); $atomLink = $channel->addChild('xmlns:atom:link');
$atomLink->addAttribute('href', Application_Common_HTTPHelper::getStationUrl() . 'feeds/station-rss'); $atomLink->addAttribute('href', Config::getPublicUrl() . 'feeds/station-rss');
$atomLink->addAttribute('rel', 'self'); $atomLink->addAttribute('rel', 'self');
$atomLink->addAttribute('type', 'application/rss+xml'); $atomLink->addAttribute('type', 'application/rss+xml');
$imageUrl = Application_Common_HTTPHelper::getStationUrl() . 'api/station-logo'; $imageUrl = Config::getPublicUrl() . 'api/station-logo';
$image = $channel->addChild('image'); $image = $channel->addChild('image');
$image->addChild('title', htmlspecialchars($podcast->getDbTitle())); $image->addChild('title', htmlspecialchars($podcast->getDbTitle()));
self::addEscapedChild($image, 'url', $imageUrl); self::addEscapedChild($image, 'url', $imageUrl);
self::addEscapedChild($image, 'link', Application_Common_HTTPHelper::getStationUrl()); self::addEscapedChild($image, 'link', Config::getPublicUrl());
$xml->addAttribute('xmlns:xmlns:itunes', ITUNES_XML_NAMESPACE_URL); $xml->addAttribute('xmlns:xmlns:itunes', ITUNES_XML_NAMESPACE_URL);
self::addEscapedChild($channel, 'xmlns:itunes:author', $podcast->getDbItunesAuthor()); self::addEscapedChild($channel, 'xmlns:itunes:author', $podcast->getDbItunesAuthor());

View File

@ -16,7 +16,7 @@
<h3 style="padding-left: 0px"><?php echo _("Preview:") ?></h3> <h3 style="padding-left: 0px"><?php echo _("Preview:") ?></h3>
<div> <div>
<iframe width=800 height=800 src="<?php echo Application_Common_HTTPHelper::getStationUrl(); ?>/?facebook=1"></iframe> <iframe width=800 height=800 src="<?php echo Config::getPublicUrl(); ?>/?facebook=1"></iframe>
</div> </div>
</div> </div>

View File

@ -13,12 +13,12 @@
<div id="weekly-schedule-widget-preview" <?php if (isset($this->weekly_schedule_error_msg)) echo "style=display:none"; ?>> <div id="weekly-schedule-widget-preview" <?php if (isset($this->weekly_schedule_error_msg)) echo "style=display:none"; ?>>
<!-- <label><?php echo _("Preview:") ?></label> --> <!-- <label><?php echo _("Preview:") ?></label> -->
<div class="schedule_iframe_wrapper"> <div class="schedule_iframe_wrapper">
<iframe id="schedule_iframe" height="400px" width="550px" scrolling="no" frameborder="0" src="<?php echo Application_Common_HTTPHelper::getStationUrl() . "embed/weekly-program" ?>"></iframe> <iframe id="schedule_iframe" height="400px" width="550px" scrolling="no" frameborder="0" src="<?php echo Config::getPublicUrl() . "embed/weekly-program" ?>"></iframe>
</div> </div>
<div style="clear:both"></div> <div style="clear:both"></div>
<label><?php echo _("Embeddable code:") ?><br><br></label> <label><?php echo _("Embeddable code:") ?><br><br></label>
<textarea style="width:98%" rows="3" readonly="readonly"><iframe height="400px" width="550px" scrolling="no" frameborder="0" src="<?php echo Application_Common_HTTPHelper::getStationUrl() . "embed/weekly-program" ?>"></iframe> <textarea style="width:98%" rows="3" readonly="readonly"><iframe height="400px" width="550px" scrolling="no" frameborder="0" src="<?php echo Config::getPublicUrl() . "embed/weekly-program" ?>"></iframe>
</textarea> </textarea>
<div> <div>
<p> <p>