2014-11-20 17:22:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Application_Common_HTTPHelper
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns start and end DateTime vars from given
|
|
|
|
* HTTP Request object
|
|
|
|
*
|
|
|
|
* @param Request
|
|
|
|
* @return array(start DateTime, end DateTime)
|
|
|
|
*/
|
|
|
|
public static function getStartEndFromRequest($request)
|
|
|
|
{
|
|
|
|
return Application_Common_DateHelper::getStartEnd(
|
|
|
|
$request->getParam("start", null),
|
|
|
|
$request->getParam("end", null),
|
|
|
|
$request->getParam("timezone", null)
|
|
|
|
);
|
|
|
|
}
|
2015-02-20 20:27:16 +01:00
|
|
|
|
2015-11-17 23:23:21 +01:00
|
|
|
/**
|
|
|
|
* Construct the base station URL
|
|
|
|
*
|
|
|
|
* @param boolean $secured whether or not to use HTTPS
|
|
|
|
*
|
|
|
|
* @return string the station URL
|
|
|
|
*/
|
|
|
|
public static function getStationUrl($secured = true)
|
2015-02-20 20:27:16 +01:00
|
|
|
{
|
|
|
|
$CC_CONFIG = Config::getConfig();
|
|
|
|
$baseUrl = $CC_CONFIG['baseUrl'];
|
|
|
|
$baseDir = $CC_CONFIG['baseDir'];
|
|
|
|
$basePort = $CC_CONFIG['basePort'];
|
|
|
|
if (empty($baseDir)) {
|
|
|
|
$baseDir = "/";
|
|
|
|
}
|
2015-03-24 15:11:25 +01:00
|
|
|
if ($baseDir[0] != "/") {
|
2015-02-25 22:09:08 +01:00
|
|
|
$baseDir = "/" . $baseDir;
|
|
|
|
}
|
2015-02-25 22:19:01 +01:00
|
|
|
|
|
|
|
$scheme = "http";
|
2015-11-17 23:23:21 +01:00
|
|
|
if ($secured && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
|
2015-02-25 22:19:01 +01:00
|
|
|
$scheme = "https";
|
|
|
|
$basePort = "443"; //Airtime Pro compatibility hack
|
|
|
|
}
|
|
|
|
|
2015-11-17 23:50:16 +01:00
|
|
|
$portStr = "";
|
|
|
|
if (!(($scheme == "http" && $basePort == "80")
|
|
|
|
|| ($scheme == "https" && $basePort == "443"))) {
|
|
|
|
$portStr = ":${basePort}";
|
|
|
|
}
|
|
|
|
$stationUrl = "$scheme://${baseUrl}${portStr}${baseDir}";
|
2015-02-20 20:27:16 +01:00
|
|
|
|
|
|
|
return $stationUrl;
|
|
|
|
}
|
2014-11-20 17:22:53 +01:00
|
|
|
}
|
2015-06-05 17:55:06 +02:00
|
|
|
|
|
|
|
class ZendActionHttpException extends Exception {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Zend_Controller_Action $action
|
|
|
|
* @param int $statusCode
|
|
|
|
* @param string $message
|
|
|
|
* @param int $code
|
|
|
|
* @param Exception $previous
|
|
|
|
*
|
|
|
|
* @throws Zend_Controller_Response_Exception
|
|
|
|
*/
|
|
|
|
public function __construct(Zend_Controller_Action $action, $statusCode, $message,
|
|
|
|
$code = 0, Exception $previous = null) {
|
2015-07-07 19:54:19 +02:00
|
|
|
Logging::error("Error in action " . $action->getRequest()->getActionName()
|
2015-06-05 17:55:06 +02:00
|
|
|
. " with status code $statusCode: $message");
|
|
|
|
$action->getResponse()
|
|
|
|
->setHttpResponseCode($statusCode)
|
|
|
|
->appendBody($message);
|
|
|
|
parent::__construct($message, $code, $previous);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|