From a569d2f3f58c32229ba6a642310c14193901661e Mon Sep 17 00:00:00 2001 From: Naomi Date: Wed, 22 May 2013 15:33:49 -0400 Subject: [PATCH 1/2] CC-5163 : Waveform - Hard coded api path will cause fail to open file when airtime is put under subfolder --- airtime_mvc/application/configs/conf.php | 1 + airtime_mvc/application/models/StoredFile.php | 53 +++++++------------ 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/airtime_mvc/application/configs/conf.php b/airtime_mvc/application/configs/conf.php index 937b91c75..13b4a06bd 100644 --- a/airtime_mvc/application/configs/conf.php +++ b/airtime_mvc/application/configs/conf.php @@ -26,6 +26,7 @@ class Config { $CC_CONFIG['webServerUser'] = $values['general']['web_server_user']; $CC_CONFIG['rabbitmq'] = $values['rabbitmq']; + $CC_CONFIG['baseDir'] = $values['general']['base_dir']; $CC_CONFIG['baseUrl'] = $values['general']['base_url']; $CC_CONFIG['basePort'] = $values['general']['base_port']; $CC_CONFIG['phpDir'] = $values['general']['airtime_dir']; diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 9169efaee..8d8615a1f 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -501,44 +501,25 @@ SQL; } /** - * Get the URL to access this file using the server name/address that - * this PHP script was invoked through. + * Get the URL to access this file */ public function getFileUrl() { - $serverName = $_SERVER['SERVER_NAME']; - $serverPort = $_SERVER['SERVER_PORT']; - - return $this->constructGetFileUrl($serverName, $serverPort); - } - - /** - * Get the URL to access this file using the server name/address that - * is specified in the airtime.conf config file. If either of these is - * not specified, then use values provided by the $_SERVER global variable. - */ - public function getFileUrlUsingConfigAddress() - { - $CC_CONFIG = Config::getConfig(); - - if (isset($CC_CONFIG['baseUrl'])) { - $serverName = $CC_CONFIG['baseUrl']; - } else { - $serverName = $_SERVER['SERVER_NAME']; - } - - if (isset($CC_CONFIG['basePort'])) { - $serverPort = $CC_CONFIG['basePort']; - } else { - $serverPort = $_SERVER['SERVER_PORT']; - } - - return $this->constructGetFileUrl($serverName, $serverPort); - } - - private function constructGetFileUrl($p_serverName, $p_serverPort) - { - return "http://$p_serverName:$p_serverPort/api/get-media/file/".$this->getId().".".$this->getFileExtension(); + $CC_CONFIG = Config::getConfig(); + + $protocol = empty($_SERVER['HTTPS']) ? "http" : "https"; + + $serverName = $_SERVER['SERVER_NAME']; + $serverPort = $_SERVER['SERVER_PORT']; + $subDir = $CC_CONFIG['baseDir']; + + if ($subDir[0] === "/") { + $subDir = substr($subDir, 1, strlen($subDir) - 1); + } + + $baseUrl = "{$protocol}://{$serverName}:{$serverPort}/{$subDir}"; + + return $this->getRelativeFileUrl($baseUrl); } /** @@ -547,6 +528,8 @@ SQL; */ public function getRelativeFileUrl($baseUrl) { + Logging::debug("Zend base url: $baseUrl"); + return $baseUrl."api/get-media/file/".$this->getId().".".$this->getFileExtension(); } From d82725cb54e1937dcd98ffaef76e67e578c7a747 Mon Sep 17 00:00:00 2001 From: Naomi Date: Wed, 22 May 2013 15:35:59 -0400 Subject: [PATCH 2/2] CLRF fix --- airtime_mvc/application/models/StoredFile.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 8d8615a1f..74e0a7a05 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -509,12 +509,12 @@ SQL; $protocol = empty($_SERVER['HTTPS']) ? "http" : "https"; - $serverName = $_SERVER['SERVER_NAME']; + $serverName = $_SERVER['SERVER_NAME']; $serverPort = $_SERVER['SERVER_PORT']; $subDir = $CC_CONFIG['baseDir']; - if ($subDir[0] === "/") { - $subDir = substr($subDir, 1, strlen($subDir) - 1); + if ($subDir[0] === "/") { + $subDir = substr($subDir, 1, strlen($subDir) - 1); } $baseUrl = "{$protocol}://{$serverName}:{$serverPort}/{$subDir}";