diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 715c90a2c..4d22bd95d 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -12,11 +12,13 @@ require_once 'Preference.php'; require_once 'Locale.php'; require_once "DateHelper.php"; require_once "LocaleHelper.php"; +require_once "HTTPHelper.php"; require_once "OsPath.php"; require_once "Database.php"; require_once "Timezone.php"; require_once "Auth.php"; require_once __DIR__.'/forms/helpers/ValidationTypes.php'; +require_once __DIR__.'/forms/helpers/CustomDecorators.php'; require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php'; require_once __DIR__.'/controllers/plugins/Maintenance.php'; require_once __DIR__.'/modules/rest/controllers/ShowController.php'; @@ -158,8 +160,12 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap && strpos($_SERVER['REQUEST_URI'], $baseUrl.'audiopreview/playlist-preview') === false && strpos($_SERVER['REQUEST_URI'], $baseUrl.'audiopreview/block-preview') === false) { if (Application_Model_Preference::GetLiveChatEnabled()) { - $client_id = Application_Model_Preference::GetClientId(); - $view->headScript()->appendScript("var livechat_client_id = '$client_id';"); + $client_id = strval(Application_Model_Preference::GetClientId()); + $plan_level = strval(Application_Model_Preference::GetPlanLevel()); + $station_url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; + $view->headScript()->appendScript("var livechat_client_id = '$client_id';\n". + "var livechat_plan_type = '$plan_level';\n". + "var livechat_station_url = 'http://$station_url';"); $view->headScript()->appendFile($baseUrl . 'js/airtime/common/livechat.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); } } diff --git a/airtime_mvc/application/common/CORSHelper.php b/airtime_mvc/application/common/CORSHelper.php index 6febb0f1b..fac6e3fdd 100644 --- a/airtime_mvc/application/common/CORSHelper.php +++ b/airtime_mvc/application/common/CORSHelper.php @@ -11,17 +11,19 @@ class CORSHelper $response = $response->setHeader('Access-Control-Allow-Origin', '*'); $origin = $request->getHeader('Origin'); if ((!(preg_match("/https?:\/\/localhost/", $origin) === 1)) && ($origin != "") && - (!in_array($origin, - array("http://www.airtime.pro", - "https://www.airtime.pro", - "https://account.sourcefabric.com", - "http://" . $_SERVER['SERVER_NAME'], - "https://" . $_SERVER['SERVER_NAME'] - )) - )) + (!in_array($origin, self::getAllowedOrigins()))) { //Don't allow CORS from other domains to prevent XSS. throw new Zend_Controller_Action_Exception('Forbidden', 403); } } + + public static function getAllowedOrigins() + { + return array("http://www.airtime.pro", + "https://www.airtime.pro", + "https://account.sourcefabric.com", + "http://" . $_SERVER['SERVER_NAME'], + "https://" . $_SERVER['SERVER_NAME']); + } } diff --git a/airtime_mvc/application/common/DateHelper.php b/airtime_mvc/application/common/DateHelper.php index ba280d285..354b8f3dc 100644 --- a/airtime_mvc/application/common/DateHelper.php +++ b/airtime_mvc/application/common/DateHelper.php @@ -443,5 +443,59 @@ class Application_Common_DateHelper return $res; } + + /** + * Returns date fields from give start and end teimstamp strings + * if no start or end parameter is passed start will be set to 1 + * in the past and end to now + * + * @param string startTimestamp Y-m-d H:i:s + * @param string endTImestamp Y-m-d H:i:s + * @param string timezone (ex UTC) of the start and end parameters + * @return array (start DateTime, end DateTime) in UTC timezone + */ + public static function getStartEnd($startTimestamp, $endTimestamp, $timezone) + { + $prefTimezone = Application_Model_Preference::GetTimezone(); + $utcTimezone = new DateTimeZone("UTC"); + $utcNow = new DateTime("now", $utcTimezone); + + if (empty($timezone)) { + $userTimezone = new DateTimeZone($prefTimezone); + } else { + $userTimezone = new DateTimeZone($timezone); + } + + // default to 1 day + if (empty($startTimestamp) || empty($endTimestamp)) { + $startsDT = clone $utcNow; + $startsDT->sub(new DateInterval("P1D")); + $endsDT = clone $utcNow; + } else { + + try { + $startsDT = new DateTime($startTimestamp, $userTimezone); + $startsDT->setTimezone($utcTimezone); + + $endsDT = new DateTime($endTimestamp, $userTimezone); + $endsDT->setTimezone($utcTimezone); + + if ($startsDT > $endsDT) { + throw new Exception("start greater than end"); + } + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + + $startsDT = clone $utcNow; + $startsDT->sub(new DateInterval("P1D")); + $endsDT = clone $utcNow; + } + + } + + return array($startsDT, $endsDT); + } } diff --git a/airtime_mvc/application/common/HTTPHelper.php b/airtime_mvc/application/common/HTTPHelper.php new file mode 100644 index 000000000..db314bb0b --- /dev/null +++ b/airtime_mvc/application/common/HTTPHelper.php @@ -0,0 +1,20 @@ +getParam("start", null), + $request->getParam("end", null), + $request->getParam("timezone", null) + ); + } +} diff --git a/airtime_mvc/application/configs/navigation.php b/airtime_mvc/application/configs/navigation.php index 5b7e4e049..e25fb7900 100644 --- a/airtime_mvc/application/configs/navigation.php +++ b/airtime_mvc/application/configs/navigation.php @@ -114,6 +114,11 @@ $pages = array( 'uri' => '#', 'resource' => 'dashboard', 'pages' => array( + array( + 'label' => _('Help Center'), + 'uri' => "http://help.sourcefabric.org/", + 'target' => "_blank" + ), array( 'label' => _('Getting Started'), 'module' => 'default', diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index dde86e8be..88f4495e1 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -5,8 +5,19 @@ class ApiController extends Zend_Controller_Action public function init() { - $ignoreAuth = array("live-info", "live-info-v2", "week-info", - "station-metadata", "station-logo", "show-logo"); + $ignoreAuth = array("live-info", + "live-info-v2", + "week-info", + "station-metadata", + "station-logo", + "show-history-feed", + "item-history-feed", + "shows", + "show-tracks", + "show-schedules", + "station-logo", + "show-logo" + ); $params = $this->getRequest()->getParams(); if (!in_array($params['action'], $ignoreAuth)) { @@ -274,10 +285,10 @@ class ApiController extends Zend_Controller_Action $utcTimeEnd = $end->format("Y-m-d H:i:s"); $result = array( - "env" => APPLICATION_ENV, - "schedulerTime" => $utcTimeNow, - "currentShow" => Application_Model_Show::getCurrentShow($utcTimeNow), - "nextShow" => Application_Model_Show::getNextShows($utcTimeNow, $limit, $utcTimeEnd) + "env" => APPLICATION_ENV, + "schedulerTime" => $utcTimeNow, + "currentShow" => Application_Model_Show::getCurrentShow($utcTimeNow), + "nextShow" => Application_Model_Show::getNextShows($utcTimeNow, $limit, $utcTimeEnd) ); } else { $result = Application_Model_Schedule::GetPlayOrderRangeOld($limit); @@ -487,9 +498,9 @@ class ApiController extends Zend_Controller_Action $shows, array("starts", "ends", "start_timestamp","end_timestamp"), $timezone - ); + ); - $result[$dow[$i]] = $shows; + $result[$dow[$i]] = $shows; } // XSS exploit prevention @@ -1225,9 +1236,10 @@ class ApiController extends Zend_Controller_Action } elseif ($djtype == "dj") { //check against show dj auth $showInfo = Application_Model_Show::getCurrentShow(); + // there is current playing show - if (isset($showInfo['id'])) { - $current_show_id = $showInfo['id']; + if (isset($showInfo[0]['id'])) { + $current_show_id = $showInfo[0]['id']; $CcShow = CcShowQuery::create()->findPK($current_show_id); // get custom pass info from the show @@ -1419,4 +1431,175 @@ class ApiController extends Zend_Controller_Action Application_Model_StreamSetting::SetListenerStatError($k, $v); } } + + /** + * display played items for a given time range and show instance_id + * + * @return json array + */ + public function itemHistoryFeedAction() + { + try { + $request = $this->getRequest(); + $params = $request->getParams(); + $instance = $request->getParam("instance_id", null); + + list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request); + + $historyService = new Application_Service_HistoryService(); + $results = $historyService->getPlayedItemData($startsDT, $endsDT, $params, $instance); + + $this->_helper->json->sendJson($results['history']); + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + } + } + + /** + * display show schedules for a given time range and show instance_id + * + * @return json array + */ + public function showHistoryFeedAction() + { + try { + $request = $this->getRequest(); + $params = $request->getParams(); + $userId = $request->getParam("user_id", null); + + list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request); + + $historyService = new Application_Service_HistoryService(); + $shows = $historyService->getShowList($startsDT, $endsDT, $userId); + + $this->_helper->json->sendJson($shows); + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + } + } + + /** + * display show info (without schedule) for given show_id + * + * @return json array + */ + public function showsAction() + { + try { + $request = $this->getRequest(); + $params = $request->getParams(); + $showId = $request->getParam("show_id", null); + $results = array(); + + if (empty($showId)) { + $shows = CcShowQuery::create()->find(); + foreach($shows as $show) { + $results[] = $show->getShowInfo(); + } + } else { + $show = CcShowQuery::create()->findPK($showId); + $results[] = $show->getShowInfo(); + } + + $this->_helper->json->sendJson($results); + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + } + } + + /** + * display show schedule for given show_id + * + * @return json array + */ + public function showSchedulesAction() + { + try { + $request = $this->getRequest(); + $params = $request->getParams(); + $showId = $request->getParam("show_id", null); + + list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request); + + if ((!isset($showId)) || (!is_numeric($showId))) { + //if (!isset($showId)) { + $this->_helper->json->sendJson( + array("jsonrpc" => "2.0", "error" => array("code" => 400, "message" => "missing invalid type for required show_id parameter. use type int.".$showId)) + ); + } + + $shows = Application_Model_Show::getShows($startsDT, $endsDT, FALSE, $showId); + + // is this a valid show? + if (empty($shows)) { + $this->_helper->json->sendJson( + array("jsonrpc" => "2.0", "error" => array("code" => 204, "message" => "no content for requested show_id")) + ); + } + + $this->_helper->json->sendJson($shows); + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + } + + } + + /** + * displays track listing for given instance_id + * + * @return json array + */ + public function showTracksAction() + { + $baseUrl = Application_Common_OsPath::getBaseDir(); + $prefTimezone = Application_Model_Preference::GetTimezone(); + + $instanceId = $this->_getParam('instance_id'); + + if ((!isset($instanceId)) || (!is_numeric($instanceId))) { + $this->_helper->json->sendJson( + array("jsonrpc" => "2.0", "error" => array("code" => 400, "message" => "missing invalid type for required instance_id parameter. use type int")) + ); + } + + $showInstance = new Application_Model_ShowInstance($instanceId); + $showInstanceContent = $showInstance->getShowListContent($prefTimezone); + + // is this a valid show instance with content? + if (empty($showInstanceContent)) { + $this->_helper->json->sendJson( + array("jsonrpc" => "2.0", "error" => array("code" => 204, "message" => "no content for requested instance_id")) + ); + } + + $result = array(); + $position = 0; + foreach ($showInstanceContent as $track) { + + $elementMap = array( + 'title' => isset($track['track_title']) ? $track['track_title'] : "", + 'artist' => isset($track['creator']) ? $track['creator'] : "", + 'position' => $position, + 'id' => ++$position, + 'mime' => isset($track['mime'])?$track['mime']:"", + 'starts' => isset($track['starts']) ? $track['starts'] : "", + 'length' => isset($track['length']) ? $track['length'] : "", + 'file_id' => ($track['type'] == 0) ? $track['item_id'] : $track['filepath'] + ); + + $result[] = $elementMap; + } + + $this->_helper->json($result); + + } + } diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index ca2f7594d..fd7f90c10 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -572,6 +572,7 @@ class BillingController extends Zend_Controller_Action { try { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); // WHMCS IP whitelist doesn't support IPv6 curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 5); //Aggressive 5 second timeout curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @@ -598,4 +599,4 @@ class BillingController extends Zend_Controller_Action { throw new Exception("Invalid client ID: " . Application_Model_Preference::GetClientId()); } } -} \ No newline at end of file +} diff --git a/airtime_mvc/application/controllers/ListenerstatController.php b/airtime_mvc/application/controllers/ListenerstatController.php index 5f5250b9c..6e2b93aee 100644 --- a/airtime_mvc/application/controllers/ListenerstatController.php +++ b/airtime_mvc/application/controllers/ListenerstatController.php @@ -10,49 +10,6 @@ class ListenerstatController extends Zend_Controller_Action ->initContext(); } - private function getStartEnd() - { - $request = $this->getRequest(); - - $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); - $utcTimezone = new DateTimeZone("UTC"); - $utcNow = new DateTime("now", $utcTimezone); - - $start = $request->getParam("start"); - $end = $request->getParam("end"); - - if (empty($start) || empty($end)) { - $startsDT = clone $utcNow; - $startsDT->sub(new DateInterval("P1D")); - $endsDT = clone $utcNow; - } - else { - - try { - $startsDT = new DateTime($start, $userTimezone); - $startsDT->setTimezone($utcTimezone); - - $endsDT = new DateTime($end, $userTimezone); - $endsDT->setTimezone($utcTimezone); - - if ($startsDT > $endsDT) { - throw new Exception("start greater than end"); - } - } - catch (Exception $e) { - Logging::info($e); - Logging::info($e->getMessage()); - - $startsDT = clone $utcNow; - $startsDT->sub(new DateInterval("P1D")); - $endsDT = clone $utcNow; - } - - } - - return array($startsDT, $endsDT); - } - public function indexAction() { $CC_CONFIG = Config::getConfig(); @@ -69,7 +26,7 @@ class ListenerstatController extends Zend_Controller_Action $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']); - list($startsDT, $endsDT) = $this->getStartEnd(); + list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request); $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); $startsDT->setTimezone($userTimezone); $endsDT->setTimezone($userTimezone); @@ -98,7 +55,7 @@ class ListenerstatController extends Zend_Controller_Action } public function getDataAction(){ - list($startsDT, $endsDT) = $this->getStartEnd(); + list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($this->getRequest()); $data = Application_Model_ListenerStat::getDataPointsWithinRange($startsDT->format("Y-m-d H:i:s"), $endsDT->format("Y-m-d H:i:s")); $this->_helper->json->sendJson($data); diff --git a/airtime_mvc/application/controllers/PlayouthistoryController.php b/airtime_mvc/application/controllers/PlayouthistoryController.php index 077cce0b2..7b82f7dfd 100644 --- a/airtime_mvc/application/controllers/PlayouthistoryController.php +++ b/airtime_mvc/application/controllers/PlayouthistoryController.php @@ -19,56 +19,13 @@ class PlayouthistoryController extends Zend_Controller_Action ->initContext(); } - private function getStartEnd() - { - $request = $this->getRequest(); - - $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); - $utcTimezone = new DateTimeZone("UTC"); - $utcNow = new DateTime("now", $utcTimezone); - - $start = $request->getParam("start"); - $end = $request->getParam("end"); - - if (empty($start) || empty($end)) { - $startsDT = clone $utcNow; - $startsDT->sub(new DateInterval("P1D")); - $endsDT = clone $utcNow; - } - else { - - try { - $startsDT = new DateTime($start, $userTimezone); - $startsDT->setTimezone($utcTimezone); - - $endsDT = new DateTime($end, $userTimezone); - $endsDT->setTimezone($utcTimezone); - - if ($startsDT > $endsDT) { - throw new Exception("start greater than end"); - } - } - catch (Exception $e) { - Logging::info($e); - Logging::info($e->getMessage()); - - $startsDT = clone $utcNow; - $startsDT->sub(new DateInterval("P1D")); - $endsDT = clone $utcNow; - } - - } - - return array($startsDT, $endsDT); - } - public function indexAction() { $CC_CONFIG = Config::getConfig(); $baseUrl = Application_Common_OsPath::getBaseDir(); - list($startsDT, $endsDT) = $this->getStartEnd(); - + list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($this->getRequest()); + $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); $startsDT->setTimezone($userTimezone); $endsDT->setTimezone($userTimezone); @@ -123,7 +80,7 @@ class PlayouthistoryController extends Zend_Controller_Action $params = $request->getParams(); $instance = $request->getParam("instance_id", null); - list($startsDT, $endsDT) = $this->getStartEnd(); + list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request); $historyService = new Application_Service_HistoryService(); $r = $historyService->getFileSummaryData($startsDT, $endsDT, $params); @@ -146,7 +103,7 @@ class PlayouthistoryController extends Zend_Controller_Action $params = $request->getParams(); $instance = $request->getParam("instance_id", null); - list($startsDT, $endsDT) = $this->getStartEnd(); + list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request); $historyService = new Application_Service_HistoryService(); $r = $historyService->getPlayedItemData($startsDT, $endsDT, $params, $instance); @@ -169,7 +126,7 @@ class PlayouthistoryController extends Zend_Controller_Action $params = $request->getParams(); $instance = $request->getParam("instance_id", null); - list($startsDT, $endsDT) = $this->getStartEnd(); + list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request); $historyService = new Application_Service_HistoryService(); $shows = $historyService->getShowList($startsDT, $endsDT); diff --git a/airtime_mvc/application/controllers/ShowbuilderController.php b/airtime_mvc/application/controllers/ShowbuilderController.php index 2de99ce52..c5633e369 100644 --- a/airtime_mvc/application/controllers/ShowbuilderController.php +++ b/airtime_mvc/application/controllers/ShowbuilderController.php @@ -244,49 +244,6 @@ class ShowbuilderController extends Zend_Controller_Action $this->view->dialog = $this->view->render('showbuilder/builderDialog.phtml'); } - private function getStartEnd() - { - $request = $this->getRequest(); - - $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); - $utcTimezone = new DateTimeZone("UTC"); - $utcNow = new DateTime("now", $utcTimezone); - - $start = $request->getParam("start"); - $end = $request->getParam("end"); - - if (empty($start) || empty($end)) { - $startsDT = clone $utcNow; - $startsDT->sub(new DateInterval("P1D")); - $endsDT = clone $utcNow; - } - else { - - try { - $startsDT = new DateTime($start, $userTimezone); - $startsDT->setTimezone($utcTimezone); - - $endsDT = new DateTime($end, $userTimezone); - $endsDT->setTimezone($utcTimezone); - - if ($startsDT > $endsDT) { - throw new Exception("start greater than end"); - } - } - catch (Exception $e) { - Logging::info($e); - Logging::info($e->getMessage()); - - $startsDT = clone $utcNow; - $startsDT->sub(new DateInterval("P1D")); - $endsDT = clone $utcNow; - } - - } - - return array($startsDT, $endsDT); - } - public function checkBuilderFeedAction() { $request = $this->getRequest(); @@ -295,7 +252,7 @@ class ShowbuilderController extends Zend_Controller_Action $timestamp = intval($request->getParam("timestamp", -1)); $instances = $request->getParam("instances", array()); - list($startsDT, $endsDT) = $this->getStartEnd(); + list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request); $opts = array("myShows" => $my_shows, "showFilter" => $show_filter); $showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts); @@ -315,7 +272,7 @@ class ShowbuilderController extends Zend_Controller_Action $show_instance_filter = intval($request->getParam("showInstanceFilter", 0)); $my_shows = intval($request->getParam("myShows", 0)); - list($startsDT, $endsDT) = $this->getStartEnd(); + list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request); $opts = array("myShows" => $my_shows, "showFilter" => $show_filter, @@ -439,6 +396,7 @@ class ShowbuilderController extends Zend_Controller_Action $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); // WHMCS IP whitelist doesn't support IPv6 curl_setopt($ch, CURLOPT_TIMEOUT, 5); //Aggressive 5 second timeout curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); diff --git a/airtime_mvc/application/controllers/WhmcsLoginController.php b/airtime_mvc/application/controllers/WhmcsLoginController.php index b8573c557..0b8a00a83 100644 --- a/airtime_mvc/application/controllers/WhmcsLoginController.php +++ b/airtime_mvc/application/controllers/WhmcsLoginController.php @@ -155,6 +155,7 @@ class WHMCS_Auth_Adapter implements Zend_Auth_Adapter_Interface { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, WHMCS_API_URL); + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); // WHMCS IP whitelist doesn't support IPv6 curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_FAILONERROR, 1); @@ -164,7 +165,8 @@ class WHMCS_Auth_Adapter implements Zend_Auth_Adapter_Interface { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $jsondata = curl_exec($ch); if (curl_error($ch)) { - die(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); + Logging::error("Failed to reach WHMCS server in " . __FUNCTION__ . ": " + . curl_errno($ch) . ' - ' . curl_error($ch) . ' - ' . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); //die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch)); } curl_close($ch); @@ -201,6 +203,7 @@ class WHMCS_Auth_Adapter implements Zend_Auth_Adapter_Interface { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, WHMCS_API_URL); + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); // WHMCS IP whitelist doesn't support IPv6 curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_FAILONERROR, 1); @@ -210,7 +213,8 @@ class WHMCS_Auth_Adapter implements Zend_Auth_Adapter_Interface { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $jsondata = curl_exec($ch); if (curl_error($ch)) { - die(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); + Logging::error("Failed to reach WHMCS server in " . __FUNCTION__ . ": " + . curl_errno($ch) . ' - ' . curl_error($ch) . ' - ' . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); //die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch)); } curl_close($ch); @@ -255,4 +259,4 @@ class WHMCS_Auth_Adapter implements Zend_Auth_Adapter_Interface { } return false; } -} \ No newline at end of file +} diff --git a/airtime_mvc/application/forms/GeneralPreferences.php b/airtime_mvc/application/forms/GeneralPreferences.php index c45437b08..fd1e00a7a 100644 --- a/airtime_mvc/application/forms/GeneralPreferences.php +++ b/airtime_mvc/application/forms/GeneralPreferences.php @@ -5,6 +5,8 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm public function init() { + $maxLens = Application_Model_Show::getMaxLengths(); + $notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator(); $rangeValidator = Application_Form_Helper_ValidationTypes::overrideBetweenValidator(0, 59.9); $this->setDecorators(array( @@ -13,104 +15,100 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm $defaultFadeIn = Application_Model_Preference::GetDefaultFadeIn(); $defaultFadeOut = Application_Model_Preference::GetDefaultFadeOut(); - + //Station name $this->addElement('text', 'stationName', array( - 'class' => 'input_text', - 'label' => _('Station Name'), - 'required' => false, - 'filters' => array('StringTrim'), + 'class' => 'input_text', + 'label' => _('Station Name'), + 'required' => false, + 'filters' => array('StringTrim'), 'value' => Application_Model_Preference::GetStationName(), - 'decorators' => array( - 'ViewHelper' - ) )); - - //Default station fade in + + // Station description + $stationDescription = new Zend_Form_Element_Textarea("stationDescription"); + $stationDescription->setLabel(_('Station Description')); + $stationDescription->setValue(Application_Model_Preference::GetStationDescription()); + $stationDescription->setRequired(false); + $stationDescription->setValidators(array(array('StringLength', false, array(0, $maxLens['description'])))); + $stationDescription->setAttrib('rows', 4); + $this->addElement($stationDescription); + + //Default station crossfade duration $this->addElement('text', 'stationDefaultCrossfadeDuration', array( - 'class' => 'input_text', - 'label' => _('Default Crossfade Duration (s):'), - 'required' => true, - 'filters' => array('StringTrim'), - 'validators' => array( - array( - $rangeValidator, - $notEmptyValidator, - 'regex', false, array('/^[0-9]{1,2}(\.\d{1})?$/', 'messages' => _('enter a time in seconds 0{.0}')) - ) - ), - 'value' => Application_Model_Preference::GetDefaultCrossfadeDuration(), - 'decorators' => array( - 'ViewHelper' - ) + 'class' => 'input_text', + 'label' => _('Default Crossfade Duration (s):'), + 'required' => true, + 'filters' => array('StringTrim'), + 'validators' => array( + $rangeValidator, + $notEmptyValidator, + array('regex', false, array('/^[0-9]+(\.\d+)?$/', 'messages' => _('Please enter a time in seconds (eg. 0.5)'))) + ), + 'value' => Application_Model_Preference::GetDefaultCrossfadeDuration(), )); //Default station fade in $this->addElement('text', 'stationDefaultFadeIn', array( - 'class' => 'input_text', - 'label' => _('Default Fade In (s):'), - 'required' => true, - 'filters' => array('StringTrim'), + 'class' => 'input_text', + 'label' => _('Default Fade In (s):'), + 'required' => true, + 'filters' => array('StringTrim'), 'validators' => array( - array( - $rangeValidator, - $notEmptyValidator, - 'regex', false, array('/^[0-9]{1,2}(\.\d{1})?$/', 'messages' => _('enter a time in seconds 0{.0}')) - ) + $rangeValidator, + $notEmptyValidator, + array('regex', false, array('/^[0-9]+(\.\d+)?$/', 'messages' => _('Please enter a time in seconds (eg. 0.5)'))) ), 'value' => $defaultFadeIn, - 'decorators' => array( - 'ViewHelper' - ) )); - + //Default station fade out $this->addElement('text', 'stationDefaultFadeOut', array( - 'class' => 'input_text', - 'label' => _('Default Fade Out (s):'), - 'required' => true, - 'filters' => array('StringTrim'), - 'validators' => array( - array( - $rangeValidator, - $notEmptyValidator, - 'regex', false, array('/^[0-9]{1,2}(\.\d{1})?$/', 'messages' => _('enter a time in seconds 0{.0}')) - ) - ), - 'value' => $defaultFadeOut, - 'decorators' => array( - 'ViewHelper' - ) + 'class' => 'input_text', + 'label' => _('Default Fade Out (s):'), + 'required' => true, + 'filters' => array('StringTrim'), + 'validators' => array( + $rangeValidator, + $notEmptyValidator, + array('regex', false, array('/^[0-9]+(\.\d+)?$/', 'messages' => _('Please enter a time in seconds (eg. 0.5)'))) + ), + 'value' => $defaultFadeOut, )); $third_party_api = new Zend_Form_Element_Radio('thirdPartyApi'); - $third_party_api->setLabel( - sprintf(_('Allow Remote Websites To Access "Schedule" Info?%s (Enable this to make front-end widgets work.)'), '
')); - $third_party_api->setMultiOptions(array(_("Disabled"), - _("Enabled"))); + $third_party_api->setLabel(_('Public Airtime API')); + $third_party_api->setDescription(_('Required for embeddable schedule widget.')); + $third_party_api->setMultiOptions(array( + _("Disabled"), + _("Enabled"), + )); $third_party_api->setValue(Application_Model_Preference::GetAllow3rdPartyApi()); - $third_party_api->setDecorators(array('ViewHelper')); + $third_party_api->setDescription(_('Enabling this feature will allow Airtime to provide schedule data + to external widgets that can be embedded in your website. Enable this + feature to reveal the embeddable code.')); + $third_party_api->setSeparator(' '); //No
between radio buttons + //$third_party_api->addDecorator(new Zend_Form_Decorator_Label(array('tag' => 'dd', 'class' => 'radio-inline-list'))); + $third_party_api->addDecorator('HtmlTag', array('tag' => 'dd', + 'id'=>"thirdPartyApi-element", + 'class' => 'radio-inline-list', + )); $this->addElement($third_party_api); - // - // Add the description element + + // Add the description element $this->addElement('textarea', 'widgetCode', array( - 'label' => 'Javascript Code:', - 'required' => false, - 'readonly' => true, - 'style' => 'font-family: Consolas, "Liberation Mono", Courier, + 'label' => 'Javascript Code:', + 'required' => false, + 'readonly' => true, + 'style' => 'font-family: Consolas, "Liberation Mono", Courier, monospace;', - 'class' => 'input_text_area', - 'value' => self::getWidgetCode(), //$_SERVER["SERVER_NAME"], - 'decorators' => array( - 'ViewHelper' - ) + 'value' => self::getWidgetCode(), )); $locale = new Zend_Form_Element_Select("locale"); - $locale->setLabel(_("Default Interface Language")); + $locale->setLabel(_("Default Language")); $locale->setMultiOptions(Application_Model_Locale::getLocales()); $locale->setValue(Application_Model_Preference::GetDefaultLocale()); - $locale->setDecorators(array('ViewHelper')); $this->addElement($locale); /* Form Element for setting the Timezone */ @@ -118,7 +116,6 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm $timezone->setLabel(_("Station Timezone")); $timezone->setMultiOptions(Application_Common_Timezone::getTimezones()); $timezone->setValue(Application_Model_Preference::GetDefaultTimezone()); - $timezone->setDecorators(array('ViewHelper')); $this->addElement($timezone); /* Form Element for setting which day is the start of the week */ @@ -126,7 +123,6 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm $week_start_day->setLabel(_("Week Starts On")); $week_start_day->setMultiOptions($this->getWeekStartDays()); $week_start_day->setValue(Application_Model_Preference::GetWeekStartDay()); - $week_start_day->setDecorators(array('ViewHelper')); $this->addElement($week_start_day); } @@ -134,10 +130,14 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm $host = $_SERVER['SERVER_NAME']; $code = << - - + + + + + +
@@ -159,6 +159,8 @@ $(document).ready(function() { sourceDomain:"http://$host", updatePeriod: 600 //seconds }); + var d = new Date().getDay(); + $('#scheduleTabs').tabs({selected: d === 0 ? 6 : d-1, fx: { opacity: 'toggle' }}); }); CODE; diff --git a/airtime_mvc/application/forms/LiveStreamingPreferences.php b/airtime_mvc/application/forms/LiveStreamingPreferences.php index 6dd14c40e..eae785bf3 100644 --- a/airtime_mvc/application/forms/LiveStreamingPreferences.php +++ b/airtime_mvc/application/forms/LiveStreamingPreferences.php @@ -10,9 +10,6 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm $isStreamConfigable = Application_Model_Preference::GetEnableStreamConf() == "true"; $defaultFade = Application_Model_Preference::GetDefaultTransitionFade(); - if ($defaultFade == "") { - $defaultFade = '00.000000'; - } // automatic trasition on source disconnection $auto_transition = new Zend_Form_Element_Checkbox("auto_transition"); @@ -32,8 +29,8 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm $transition_fade = new Zend_Form_Element_Text("transition_fade"); $transition_fade->setLabel(_("Switch Transition Fade (s)")) ->setFilters(array('StringTrim')) - ->addValidator('regex', false, array('/^[0-9]{1,2}(\.\d{1,6})?$/', - 'messages' => _('enter a time in seconds 00{.000000}'))) + ->addValidator('regex', false, array('/^[0-9]{1,2}(\.\d{1,3})?$/', + 'messages' => _('enter a time in seconds 0{.000}'))) ->setValue($defaultFade) ->setDecorators(array('ViewHelper')); $this->addElement($transition_fade); diff --git a/airtime_mvc/application/forms/Login.php b/airtime_mvc/application/forms/Login.php index b8d3989c2..623fa14fa 100644 --- a/airtime_mvc/application/forms/Login.php +++ b/airtime_mvc/application/forms/Login.php @@ -1,5 +1,7 @@ setMethod('post'); - $this->addElement('hash', 'csrf', array( - 'salt' => 'unique' - )); + //If the request comes from an origin we consider safe, we disable the CSRF + //token checking ONLY for the login page. We do this to allow logins from WHMCS to work. + $request = Zend_Controller_Front::getInstance()->getRequest(); + if ($request) { + $refererUrl = $request->getHeader('referer'); + $originIsSafe = false; + foreach (CORSHelper::getAllowedOrigins() as $safeOrigin) { + if (StringHelper::startsWith($safeOrigin, $refererUrl)) { + $originIsSafe = true; + break; + } + } + } + + if (!$originIsSafe) { + $this->addElement('hash', 'csrf', array( + 'salt' => 'unique' + )); + } $this->setDecorators(array( array('ViewScript', array('viewScript' => 'form/login.phtml')) diff --git a/airtime_mvc/application/forms/helpers/CustomDecorators.php b/airtime_mvc/application/forms/helpers/CustomDecorators.php new file mode 100644 index 000000000..f9ad02f8f --- /dev/null +++ b/airtime_mvc/application/forms/helpers/CustomDecorators.php @@ -0,0 +1,15 @@ +isSuperAdmin()) { + return $content; + } else { + return ""; + } + } +} \ No newline at end of file diff --git a/airtime_mvc/application/layouts/scripts/login.phtml b/airtime_mvc/application/layouts/scripts/login.phtml index 6a9879673..b12f00d34 100644 --- a/airtime_mvc/application/layouts/scripts/login.phtml +++ b/airtime_mvc/application/layouts/scripts/login.phtml @@ -21,9 +21,9 @@ $companySiteAnchor = "" . $company . ""; - echo sprintf(_('%1$s copyright © %2$s All rights reserved.%3$s' - . 'Maintained and distributed under the %4$s by %5$s'), - PRODUCT_NAME, $company, "
", + echo sprintf(_('%1$s copyright © %2$s All rights reserved.
' + . 'Maintained and distributed under the %3$s by %4$s'), + PRODUCT_NAME, $company, $licenseSiteAnchor, $companySiteAnchor); ?> diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index f3175f155..1ca0a7442 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -263,7 +263,7 @@ class Application_Model_Preference if ($fade === "") { // the default value of the fade is 00.5 - return "00.5"; + return "0.5"; } return $fade; @@ -279,8 +279,8 @@ class Application_Model_Preference $fade = self::getValue("default_fade_out"); if ($fade === "") { - // the default value of the fade is 00.5 - return "00.5"; + // the default value of the fade is 0.5 + return "0.5"; } return $fade; @@ -291,33 +291,6 @@ class Application_Model_Preference self::setValue("default_fade", $fade); } - public static function GetDefaultFade() - { - $fade = self::getValue("default_fade"); - - if ($fade === "") { - // the default value of the fade is 00.5 - return "00.5"; - } - - // we need this function to work with 2.0 version on default_fade value in cc_pref - // it has 00:00:00.000000 format where in 2.1 we have 00.000000 format - if (preg_match("/([0-9]{2}):([0-9]{2}):([0-9]{2}).([0-9]{6})/", $fade, $matches) == 1 && count($matches) == 5) { - $out = 0; - $out += intval($matches[1] * 3600); - $out += intval($matches[2] * 60); - $out += intval($matches[3]); - $out .= ".$matches[4]"; - $fade = $out; - } - - $fade = number_format($fade, 1, '.', ''); - //fades need 2 leading zeros for DateTime conversion - $fade = str_pad($fade, 4, "0", STR_PAD_LEFT); - - return $fade; - } - public static function SetDefaultTransitionFade($fade) { self::setValue("default_transition_fade", $fade); @@ -330,7 +303,7 @@ class Application_Model_Preference public static function GetDefaultTransitionFade() { $transition_fade = self::getValue("default_transition_fade"); - return ($transition_fade == "") ? "00.000000" : $transition_fade; + return ($transition_fade == "") ? "0.000" : $transition_fade; } public static function SetStreamLabelFormat($type) diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 05b55bdba..4208ff5c7 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -1119,6 +1119,7 @@ class Application_Model_Scheduler foreach ($removedItems as $removedItem) { $instance = $removedItem->getCcShowInstances($this->con); + $effectedInstanceIds[] = $instance->getDbId(); //check if instance is linked and if so get the schedule items //for all linked instances so we can delete them too diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index ba9afbeb7..73925fc65 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -862,9 +862,11 @@ SQL; * In UTC time. * @param unknown_type $excludeInstance * @param boolean $onlyRecord + * @param int $showId + * limits the results to instances of a given showId only * @return array */ - public static function getShows($start_timestamp, $end_timestamp, $onlyRecord=FALSE) + public static function getShows($start_timestamp, $end_timestamp, $onlyRecord=FALSE, $showId=null) { self::createAndFillShowInstancesPastPopulatedUntilDate($end_timestamp); @@ -898,13 +900,21 @@ SQL; //only want shows that are starting at the time or later. $start_string = $start_timestamp->format("Y-m-d H:i:s"); $end_string = $end_timestamp->format("Y-m-d H:i:s"); + + $params = array(); + + if ($showId) { + $sql .= " AND (si1.show_id = :show_id)"; + $params[':show_id'] = $showId; + } + if ($onlyRecord) { $sql .= " AND (si1.starts >= :start::TIMESTAMP AND si1.starts < :end::TIMESTAMP)"; $sql .= " AND (si1.record = 1)"; - return Application_Common_Database::prepareAndExecute( $sql, - array( ':start' => $start_string, - ':end' => $end_string ), 'all'); + $params[':start'] = $start_string; + $params[':end'] = $end_string; + return Application_Common_Database::prepareAndExecute( $sql, $params, 'all'); } else { $sql .= " ". <<= :start1::TIMESTAMP AND si1.starts < :end1::TIMESTAMP) OR (si1.starts <= :start3::TIMESTAMP AND si1.ends >= :end3::TIMESTAMP)) ORDER BY si1.starts SQL; - return Application_Common_Database::prepareAndExecute( $sql, - array( + $params = array_merge($params, array( 'start1' => $start_string, 'start2' => $start_string, 'start3' => $start_string, 'end1' => $end_string, 'end2' => $end_string, 'end3' => $end_string - ), 'all'); + ) + ); + return Application_Common_Database::prepareAndExecute( $sql, $params, 'all'); } } @@ -1016,10 +1027,10 @@ SQL; //for putting the now playing icon on the show. if ($now > $startsDT && $now < $endsDT) { - $event["nowPlaying"] = true; + $event["nowPlaying"] = true; } else { - $event["nowPlaying"] = false; + $event["nowPlaying"] = false; } //event colouring @@ -1048,9 +1059,9 @@ SQL; **/ private static function getPercentScheduled($p_starts, $p_ends, $p_time_filled) { - $utcTimezone = new DatetimeZone("UTC"); - $startDt = new DateTime($p_starts, $utcTimezone); - $endDt = new DateTime($p_ends, $utcTimezone); + $utcTimezone = new DatetimeZone("UTC"); + $startDt = new DateTime($p_starts, $utcTimezone); + $endDt = new DateTime($p_ends, $utcTimezone); $durationSeconds = intval($endDt->format("U")) - intval($startDt->format("U")); $time_filled = Application_Common_DateHelper::playlistTimeToSeconds($p_time_filled); if ($durationSeconds != 0) { //Prevent division by zero if the show duration somehow becomes zero. @@ -1311,7 +1322,6 @@ SQL; $results['nextShow'][0] = array( "id" => $rows[$i]['id'], "instance_id" => $rows[$i]['instance_id'], - "instance_description" => $rows[$i]['instance_description'], "name" => $rows[$i]['name'], "description" => $rows[$i]['description'], "url" => $rows[$i]['url'], @@ -1458,4 +1468,5 @@ SQL; return array($start, $end); } + } diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index c3b423af6..c15cdc631 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -555,7 +555,7 @@ SQL; } - public function getShowListContent() + public function getShowListContent($timezone = null) { $con = Propel::getConnection(); @@ -606,9 +606,14 @@ SQL; ':instance_id2' => $this->_instanceId )); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); - - $userTimezone = Application_Model_Preference::GetUserTimezone(); - $displayTimezone = new DateTimeZone($userTimezone); + + if (isset($timezone)) { + $displayTimezone = new DateTimeZone($timezone); + } else { + $userTimezone = Application_Model_Preference::GetUserTimezone(); + $displayTimezone = new DateTimeZone($userTimezone); + } + $utcTimezone = new DateTimeZone("UTC"); foreach ($results as &$row) { diff --git a/airtime_mvc/application/models/Webstream.php b/airtime_mvc/application/models/Webstream.php index 21c794b07..a7e7d82b1 100644 --- a/airtime_mvc/application/models/Webstream.php +++ b/airtime_mvc/application/models/Webstream.php @@ -309,7 +309,7 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable $media_url = self::getXspfUrl($url); } elseif (preg_match("/pls\+xml/", $mime) || preg_match("/x-scpls/", $mime)) { $media_url = self::getPlsUrl($url); - } elseif (preg_match("/(mpeg|ogg|audio\/aacp)/", $mime)) { + } elseif (preg_match("/(mpeg|ogg|audio\/aacp|audio\/aac)/", $mime)) { if ($content_length_found) { throw new Exception(_("Invalid webstream - This appears to be a file download.")); } diff --git a/airtime_mvc/application/models/airtime/CcShow.php b/airtime_mvc/application/models/airtime/CcShow.php index b9f140e3e..ee0c75454 100644 --- a/airtime_mvc/application/models/airtime/CcShow.php +++ b/airtime_mvc/application/models/airtime/CcShow.php @@ -304,4 +304,23 @@ class CcShow extends BaseCcShow { ->filterByDbId($instanceId, Criteria::NOT_EQUAL) ->find(); } + + public function getShowInfo() + { + $info = array(); + if ($this->getDbId() == null) { + return $info; + } else { + $info['name'] = $this->getDbName(); + $info['id'] = $this->getDbId(); + $info['url'] = $this->getDbUrl(); + $info['genre'] = $this->getDbGenre(); + $info['description'] = $this->getDbDescription(); + $info['color'] = $this->getDbColor(); + $info['background_color'] = $this->getDbBackgroundColor(); + $info['linked'] = $this->getDbLinked(); + return $info; + } + + } } // CcShow diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index e29402974..d0a015f16 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -79,35 +79,6 @@ class Rest_MediaController extends Zend_Rest_Controller $this->fileNotFoundResponse(); } } - - public function clearAction() - { - if (!$this->verifyAuth(true, true)) - { - return; - } - - //set file_exists flag to false for every file - $con = Propel::getConnection(CcFilesPeer::DATABASE_NAME); - $selectCriteria = new Criteria(); - $selectCriteria->add(CcFilesPeer::FILE_EXISTS, true); - $updateCriteria = new Criteria(); - $updateCriteria->add(CcFilesPeer::FILE_EXISTS, false); - BasePeer::doUpdate($selectCriteria, $updateCriteria, $con); - - //delete all files and directories under .../imported - $path = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."/srv/airtime/stor/imported/*" : "/srv/airtime/stor/imported/*"; - exec("rm -rf $path"); - - //update disk_usage value in cc_pref - $storDir = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."srv/airtime/stor" : "/srv/airtime/stor"; - $diskUsage = shell_exec("du -sb $storDir | awk '{print $1}'"); - Application_Model_Preference::setDiskUsage($diskUsage); - - $this->getResponse() - ->setHttpResponseCode(200) - ->appendBody("Library has been cleared"); - } public function getAction() { diff --git a/airtime_mvc/application/services/HistoryService.php b/airtime_mvc/application/services/HistoryService.php index 73821ce92..181e55a67 100644 --- a/airtime_mvc/application/services/HistoryService.php +++ b/airtime_mvc/application/services/HistoryService.php @@ -204,30 +204,34 @@ class Application_Service_HistoryService //------------------------------------------------------------------------ //Using Datatables parameters to sort the data. - $numOrderColumns = $opts["iSortingCols"]; - $orderBys = array(); + if (empty($opts["iSortingCols"])) { + $orderBys = array(); + } else { + $numOrderColumns = $opts["iSortingCols"]; + $orderBys = array(); - for ($i = 0; $i < $numOrderColumns; $i++) { + for ($i = 0; $i < $numOrderColumns; $i++) { - $colNum = $opts["iSortCol_".$i]; - $key = $opts["mDataProp_".$colNum]; - $sortDir = $opts["sSortDir_".$i]; + $colNum = $opts["iSortCol_".$i]; + $key = $opts["mDataProp_".$colNum]; + $sortDir = $opts["sSortDir_".$i]; - if (in_array($key, $required)) { + if (in_array($key, $required)) { - $orderBys[] = "history_range.{$key} {$sortDir}"; - } - else if (in_array($key, $filemd_keys)) { + $orderBys[] = "history_range.{$key} {$sortDir}"; + } + else if (in_array($key, $filemd_keys)) { - $orderBys[] = "file_info.{$key} {$sortDir}"; - } - else if (in_array($key, $general_keys)) { + $orderBys[] = "file_info.{$key} {$sortDir}"; + } + else if (in_array($key, $general_keys)) { - $orderBys[] = "{$key}_filter.{$key} {$sortDir}"; - } - else { - //throw new Exception("Error: $key is not part of the template."); - } + $orderBys[] = "{$key}_filter.{$key} {$sortDir}"; + } + else { + //throw new Exception("Error: $key is not part of the template."); + } + } } if (count($orderBys) > 0) { @@ -241,7 +245,7 @@ class Application_Service_HistoryService //--------------------------------------------------------------- //using Datatables parameters to add limits/offsets - $displayLength = intval($opts["iDisplayLength"]); + $displayLength = empty($opts["iDisplayLength"]) ? -1 : intval($opts["iDisplayLength"]); //limit the results returned. if ($displayLength !== -1) { $mainSqlQuery.= @@ -275,14 +279,14 @@ class Application_Service_HistoryService foreach ($fields as $index=>$field) { if ($field["type"] == TEMPLATE_BOOLEAN) { - $boolCast[] = $field["name"]; + $boolCast[] = $field; } } foreach ($rows as $index => &$result) { - foreach ($boolCast as $name) { - $result[$name] = (bool) $result[$name]; + foreach ($boolCast as $field) { + $result[$field['label']] = (bool) $result[$field['name']]; } //need to display the results in the station's timezone. @@ -311,7 +315,7 @@ class Application_Service_HistoryService } return array( - "sEcho" => intval($opts["sEcho"]), + "sEcho" => empty($opts["sEcho"]) ? null : intval($opts["sEcho"]), //"iTotalDisplayRecords" => intval($totalDisplayRows), "iTotalDisplayRecords" => intval($totalRows), "iTotalRecords" => intval($totalRows), @@ -445,9 +449,13 @@ class Application_Service_HistoryService ); } - public function getShowList($startDT, $endDT) + public function getShowList($startDT, $endDT, $userId = null) { - $user = Application_Model_User::getCurrentUser(); + if (empty($userId)) { + $user = Application_Model_User::getCurrentUser(); + } else { + $user = new Application_Model_User($userId); + } $shows = Application_Model_Show::getShows($startDT, $endDT); Logging::info($startDT->format("Y-m-d H:i:s")); @@ -456,7 +464,7 @@ class Application_Service_HistoryService Logging::info($shows); //need to filter the list to only their shows - if ($user->isHost()) { + if ((!empty($user)) && ($user->isHost())) { $showIds = array(); @@ -1524,4 +1532,4 @@ class Application_Service_HistoryService throw $e; } } -} \ No newline at end of file +} diff --git a/airtime_mvc/application/views/scripts/form/preferences.phtml b/airtime_mvc/application/views/scripts/form/preferences.phtml index f32167ea7..475f86928 100644 --- a/airtime_mvc/application/views/scripts/form/preferences.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences.phtml @@ -1,10 +1,5 @@
element->getElement('csrf') ?> element->getSubform('preferences_general') ?> - -

-
- element->getSubform('preferences_soundcloud') ?> -
- +
diff --git a/airtime_mvc/application/views/scripts/form/preferences_general.phtml b/airtime_mvc/application/views/scripts/form/preferences_general.phtml index c8ab6bdb8..2cbe40c78 100644 --- a/airtime_mvc/application/views/scripts/form/preferences_general.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences_general.phtml @@ -1,156 +1,25 @@
-
- -
-
- element->getElement('stationName') ?> - element->getElement('stationName')->hasErrors()) : ?> -
    - element->getElement('stationName')->getMessages() as $error): ?> -
  • - -
- -
-
- -
-
- element->getElement('stationDefaultFadeIn') ?> - element->getElement('stationDefaultFadeIn')->hasErrors()) : ?> -
    - element->getElement('stationDefaultFadeIn')->getMessages() as $error): ?> -
  • - -
- -
-
- -
-
- element->getElement('stationDefaultFadeOut') ?> - element->getElement('stationDefaultFadeOut')->hasErrors()) : ?> -
    - element->getElement('stationDefaultFadeOut')->getMessages() as $error): ?> -
  • - -
- -
-
- -
-
- element->getElement('stationDefaultCrossfadeDuration') ?> - element->getElement('stationDefaultCrossfadeDuration')->hasErrors()) : ?> -
    - element->getElement('stationDefaultCrossfadeDuration')->getMessages() as $error): ?> -
  • - -
- -
-
- - -
-
- element->getElement('thirdPartyApi')->getValue(); - ?> + element->getElement('stationName')->render() ?> - element->getElement('thirdPartyApi')->getMultiOptions() as $radio) : ?> - - - - element->getElement('thirdPartyApi')->hasErrors()) : ?> -
    - element->getElement('thirdPartyApi')->getMessages() as $error): ?> -
  • - -
- -
+ element->getElement('stationDescription')->render() ?> - - -
- -
-
- element->getElement('locale') ?> - element->getElement('locale')->hasErrors()) : ?> -
    - element->getElement('locale')->getMessages() as $error): ?> -
  • - -
- -
+ element->getElement('locale')->render() ?> -
- -
-
- element->getElement('timezone') ?> - element->getElement('timezone')->hasErrors()) : ?> -
    - element->getElement('timezone')->getMessages() as $error): ?> -
  • - -
- -
+ element->getElement('timezone')->render() ?> - -
- -
-
- element->getElement('weekStartDay')->getValue(); - ?> - + element->getElement('weekStartDay')->render() ?> + + element->getElement('stationDefaultFadeIn')->render() ?> + + element->getElement('stationDefaultFadeOut')->render() ?> + + element->getElement('stationDefaultCrossfadeDuration')->render() ?> + + element->getElement('thirdPartyApi')->render() ?> + + element->getElement('widgetCode')->render() ?> - element->getElement('weekStartDay')->hasErrors()) : ?> -
    - element->getElement('weekStartDay')->getMessages() as $error): ?> -
  • - -
- -
diff --git a/airtime_mvc/application/views/scripts/form/register-dialog.phtml b/airtime_mvc/application/views/scripts/form/register-dialog.phtml index 999eb045d..358cc692a 100644 --- a/airtime_mvc/application/views/scripts/form/register-dialog.phtml +++ b/airtime_mvc/application/views/scripts/form/register-dialog.phtml @@ -3,10 +3,10 @@
-
") ?> + " + ."Click the box below and we'll make sure the features you use are constantly improving."), + PRODUCT_NAME)?>