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 weekInfoAction() { 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(); $dayStart = $date->getWeekStartDate(); $utcDayStart = Application_Common_DateHelper::ConvertToUtcDateTimeString($dayStart); $dow = array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"); $result = array(); for ($i = 0; $i < 7; $i++) { $utcDayEnd = Application_Common_DateHelper::GetDayEndTimestamp($utcDayStart); $shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd); $utcDayStart = $utcDayEnd; Application_Model_Show::convertToLocalTimeZone($shows, array("starts", "ends", "start_timestamp", "end_timestamp")); $result[$dow[$i]] = $shows; } //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; } }