From b1e71e5adfdadb85021f0f28e9033412c902f804 Mon Sep 17 00:00:00 2001 From: Jamie Connor Date: Mon, 26 Aug 2013 11:26:09 +1200 Subject: [PATCH] added optional parameter number_of_days for getting schedule information --- .../application/controllers/ApiController.php | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 63c24d14a..c3a3c14f0 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -299,7 +299,7 @@ class ApiController extends Zend_Controller_Action } } - public function weekInfoAction() + public function weekInfoAction() { if (Application_Model_Preference::GetAllow3rdPartyApi()) { // disable the view and the layout @@ -314,25 +314,47 @@ class ApiController extends Zend_Controller_Action "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; + + if(isset($_GET['number_of_days'])){ //allows for schedule to be returned for multiple days + for ($i=0; $i<$number_of_days; $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")); + Application_Model_Show::convertToLocalTimeZone($shows, + array("starts", "ends", "start_timestamp", + "end_timestamp")); - $result[$dow[$i]] = $shows; - } + $result[$i] = $shows; + } + // XSS exploit prevention + for ($i=0; $i<$number_of_days; $i++) { + foreach ($result[$i] as &$show) { + $show["name"] = htmlspecialchars($show["name"]); + $show["url"] = htmlspecialchars($show["url"]); + } + } + }else{ + for ($i=0; $i<7; $i++) { + $utcDayEnd = Application_Common_DateHelper::GetDayEndTimestamp($utcDayStart); + $shows = Application_Model_Show::getNextShows($utcDayStart, "ALL", $utcDayEnd); + $utcDayStart = $utcDayEnd; - // XSS exploit prevention - foreach ($dow as $d) { - foreach ($result[$d] as &$show) { - $show["name"] = htmlspecialchars($show["name"]); - $show["url"] = htmlspecialchars($show["url"]); - } - } + Application_Model_Show::convertToLocalTimeZone($shows, + array("starts", "ends", "start_timestamp", + "end_timestamp")); + + $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;