Exemplo n.º 1
0
 public function weekInfoAction()
 {
     if (Application_Model_Preference::GetAllow3rdPartyApi()) {
         // disable the view and the layout
         $this->view->layout()->disableLayout();
         $this->_helper->viewRenderer->setNoRender(true);
         //weekStart is in station time.
         $weekStartDateTime = Application_Common_DateHelper::getWeekStartDateTime();
         $dow = array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", "nextmonday", "nexttuesday", "nextwednesday", "nextthursday", "nextfriday", "nextsaturday", "nextsunday");
         $result = array();
         $utcTimezone = new DateTimeZone("UTC");
         $stationTimezone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone());
         $weekStartDateTime->setTimezone($utcTimezone);
         $utcDayStart = $weekStartDateTime->format("Y-m-d H:i:s");
         for ($i = 0; $i < 14; $i++) {
             //have to be in station timezone when adding 1 day for daylight savings.
             $weekStartDateTime->setTimezone($stationTimezone);
             $weekStartDateTime->add(new DateInterval('P1D'));
             //convert back to UTC to get the actual timestamp used for search.
             $weekStartDateTime->setTimezone($utcTimezone);
             $utcDayEnd = $weekStartDateTime->format("Y-m-d H:i:s");
             $shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd);
             $utcDayStart = $utcDayEnd;
             Application_Common_DateHelper::convertTimestamps($shows, array("starts", "ends", "start_timestamp", "end_timestamp"), "station");
             $result[$dow[$i]] = $shows;
         }
         // XSS exploit prevention
         foreach ($dow as $d) {
             foreach ($result[$d] as &$show) {
                 $show["name"] = htmlspecialchars($show["name"]);
                 $show["url"] = htmlspecialchars($show["url"]);
             }
         }
         //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;
     }
 }
 public function getCurrentPlaylistAction()
 {
     $range = Application_Model_Schedule::GetPlayOrderRange();
     $show = Application_Model_Show::getCurrentShow();
     /* Convert all UTC times to localtime before sending back to user. */
     $range["schedulerTime"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["schedulerTime"]);
     if (isset($range["previous"])) {
         $range["previous"]["starts"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["previous"]["starts"]);
         $range["previous"]["ends"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["previous"]["ends"]);
     }
     if (isset($range["current"])) {
         $range["current"]["starts"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["current"]["starts"]);
         $range["current"]["ends"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["current"]["ends"]);
     }
     if (isset($range["next"])) {
         $range["next"]["starts"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["next"]["starts"]);
         $range["next"]["ends"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["next"]["ends"]);
     }
     Application_Common_DateHelper::convertTimestamps($range["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp"), "user");
     Application_Common_DateHelper::convertTimestamps($range["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"), "user");
     //TODO: Add timezone and timezoneOffset back into the ApiController's results.
     $range["timezone"] = Application_Common_DateHelper::getUserTimezoneAbbreviation();
     $range["timezoneOffset"] = Application_Common_DateHelper::getUserTimezoneOffset();
     $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"] : "";
 }