/** * 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; } }