예제 #1
0
 /**
  * Retrieve the currently playing show as well as upcoming shows.
  * Number of shows returned and the time interval in which to
  * get the next shows can be configured as GET parameters.
  *
  * TODO: in the future, make interval length a parameter instead of hardcode to 48
  *
  * Possible parameters:
  * type - Can have values of "endofday" or "interval". If set to "endofday",
  *        the function will retrieve shows from now to end of day.
  *        If set to "interval", shows in the next 48 hours will be retrived.
  *        Default is "interval".
  * limit - How many shows to retrieve
  *         Default is "5".
  */
 public function liveInfoAction()
 {
     if (Application_Model_Preference::GetAllow3rdPartyApi()) {
         // disable the view and the layout
         $this->view->layout()->disableLayout();
         $this->_helper->viewRenderer->setNoRender(true);
         $utcTimeNow = gmdate("Y-m-d H:i:s");
         $utcTimeEnd = "";
         // if empty, getNextShows will use interval instead of end of day
         $request = $this->getRequest();
         $type = $request->getParam('type');
         /* This is some *extremely* lazy programming that needs to bi fixed. For some reason
          * we are using two entirely different codepaths for very similar functionality (type = endofday
          * vs type = interval). Needs to be fixed for 2.3 - MK */
         if ($type == "endofday") {
             $limit = $request->getParam('limit');
             if ($limit == "" || !is_numeric($limit)) {
                 $limit = "5";
             }
             // make getNextShows use end of day
             $end = Application_Common_DateHelper::getTodayStationEndDateTime();
             $end->setTimezone(new DateTimeZone("UTC"));
             $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));
         } else {
             $result = Application_Model_Schedule::GetPlayOrderRange();
             // XSS exploit prevention
             $result["previous"]["name"] = htmlspecialchars($result["previous"]["name"]);
             $result["current"]["name"] = htmlspecialchars($result["current"]["name"]);
             $result["next"]["name"] = htmlspecialchars($result["next"]["name"]);
         }
         // XSS exploit prevention
         foreach ($result["currentShow"] as &$current) {
             $current["name"] = htmlspecialchars($current["name"]);
         }
         foreach ($result["nextShow"] as &$next) {
             $next["name"] = htmlspecialchars($next["name"]);
         }
         //For consistency, all times here are being sent in the station timezone, which
         //seems to be what we've normalized everything to.
         //Convert the UTC scheduler time ("now") to the station timezone.
         $result["schedulerTime"] = Application_Common_DateHelper::UTCStringToStationTimezoneString($result["schedulerTime"]);
         $result["timezone"] = Application_Common_DateHelper::getStationTimezoneAbbreviation();
         $result["timezoneOffset"] = Application_Common_DateHelper::getStationTimezoneOffset();
         //Convert from UTC to station time for Web Browser.
         Application_Common_DateHelper::convertTimestamps($result["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp"), "station");
         Application_Common_DateHelper::convertTimestamps($result["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"), "station");
         //used by caller to determine if the airtime they are running or widgets in use is out of date.
         $result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION;
         header("Content-Type: application/json");
         // If a callback is not given, then just provide the raw JSON.
         echo isset($_GET['callback']) ? $_GET['callback'] . '(' . json_encode($result) . ')' : json_encode($result);
     } else {
         header('HTTP/1.0 401 Unauthorized');
         print _('You are not allowed to access this resource. ');
         exit;
     }
 }
예제 #2
0
 public function getCurrentPlaylistAction()
 {
     $range = Application_Model_Schedule::GetPlayOrderRange();
     $show = Application_Model_Show::getCurrentShow();
     /* Convert all UTC times to localtime before sending back to user. */
     if (isset($range["previous"])) {
         $range["previous"]["starts"] = Application_Common_DateHelper::ConvertToLocalDateTimeString($range["previous"]["starts"]);
         $range["previous"]["ends"] = Application_Common_DateHelper::ConvertToLocalDateTimeString($range["previous"]["ends"]);
     }
     if (isset($range["current"])) {
         $range["current"]["starts"] = Application_Common_DateHelper::ConvertToLocalDateTimeString($range["current"]["starts"]);
         $range["current"]["ends"] = Application_Common_DateHelper::ConvertToLocalDateTimeString($range["current"]["ends"]);
     }
     if (isset($range["next"])) {
         $range["next"]["starts"] = Application_Common_DateHelper::ConvertToLocalDateTimeString($range["next"]["starts"]);
         $range["next"]["ends"] = Application_Common_DateHelper::ConvertToLocalDateTimeString($range["next"]["ends"]);
     }
     Application_Model_Show::convertToLocalTimeZone($range["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
     Application_Model_Show::convertToLocalTimeZone($range["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
     $source_status = array();
     $switch_status = array();
     $live_dj = Application_Model_Preference::GetSourceStatus("live_dj");
     $master_dj = Application_Model_Preference::GetSourceStatus("master_dj");
     $scheduled_play_switch = Application_Model_Preference::GetSourceSwitchStatus("scheduled_play");
     $live_dj_switch = Application_Model_Preference::GetSourceSwitchStatus("live_dj");
     $master_dj_switch = Application_Model_Preference::GetSourceSwitchStatus("master_dj");
     //might not be the correct place to implement this but for now let's just do it here
     $source_status['live_dj_source'] = $live_dj;
     $source_status['master_dj_source'] = $master_dj;
     $this->view->source_status = $source_status;
     $switch_status['live_dj_source'] = $live_dj_switch;
     $switch_status['master_dj_source'] = $master_dj_switch;
     $switch_status['scheduled_play'] = $scheduled_play_switch;
     $this->view->switch_status = $switch_status;
     $this->view->entries = $range;
     $this->view->show_name = isset($show[0]) ? $show[0]["name"] : "";
 }
예제 #3
0
 /**
  * Retrieve the currently playing show as well as upcoming shows.
  * Number of shows returned and the time interval in which to
  * get the next shows can be configured as GET parameters.
  *
  * TODO: in the future, make interval length a parameter instead of hardcode to 48
  *
  * Possible parameters:
  * type - Can have values of "endofday" or "interval". If set to "endofday",
  *        the function will retrieve shows from now to end of day.
  *        If set to "interval", shows in the next 48 hours will be retrived.
  *        Default is "interval".
  * limit - How many shows to retrieve
  *         Default is "5".
  */
 public function liveInfoAction()
 {
     if (Application_Model_Preference::GetAllow3rdPartyApi()) {
         // disable the view and the layout
         $this->view->layout()->disableLayout();
         $this->_helper->viewRenderer->setNoRender(true);
         $date = new Application_Common_DateHelper();
         $utcTimeNow = $date->getUtcTimestamp();
         $utcTimeEnd = "";
         // if empty, getNextShows will use interval instead of end of day
         $request = $this->getRequest();
         $type = $request->getParam('type');
         /* This is some *extremely* lazy programming that needs to bi fixed. For some reason
          * we are using two entirely different codepaths for very similar functionality (type = endofday
          * vs type = interval). Needs to be fixed for 2.3 - MK */
         if ($type == "endofday") {
             $limit = $request->getParam('limit');
             if ($limit == "" || !is_numeric($limit)) {
                 $limit = "5";
             }
             // make getNextShows use end of day
             $utcTimeEnd = Application_Common_DateHelper::GetDayEndTimestampInUtc();
             $result = array("env" => APPLICATION_ENV, "schedulerTime" => gmdate("Y-m-d H:i:s"), "currentShow" => Application_Model_Show::getCurrentShow($utcTimeNow), "nextShow" => Application_Model_Show::getNextShows($utcTimeNow, $limit, $utcTimeEnd));
             Application_Model_Show::convertToLocalTimeZone($result["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
             Application_Model_Show::convertToLocalTimeZone($result["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
         } else {
             $result = Application_Model_Schedule::GetPlayOrderRange();
             //Convert from UTC to localtime for Web Browser.
             Application_Model_Show::ConvertToLocalTimeZone($result["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
             Application_Model_Show::ConvertToLocalTimeZone($result["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
         }
         //used by caller to determine if the airtime they are running or widgets in use is out of date.
         $result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION;
         header("Content-type: text/javascript");
         // If a callback is not given, then just provide the raw JSON.
         echo isset($_GET['callback']) ? $_GET['callback'] . '(' . json_encode($result) . ')' : json_encode($result);
     } else {
         header('HTTP/1.0 401 Unauthorized');
         print 'You are not allowed to access this resource. ';
         exit;
     }
 }