From b91adfb3aac70a8bf59238402f766e68f56db754 Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 30 Mar 2011 13:53:48 -0400 Subject: [PATCH 1/3] -Airtime.ini should follow PHP coding guidelines more closely. --- install/include/AirtimeIni.php | 79 ++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 12 deletions(-) diff --git a/install/include/AirtimeIni.php b/install/include/AirtimeIni.php index 8a5071392..33e7f772e 100644 --- a/install/include/AirtimeIni.php +++ b/install/include/AirtimeIni.php @@ -1,4 +1,10 @@ strlen($property)) - if ($property == substr($lines[$i], 0, strlen($property))){ - $lines[$i] = "$property = $value\n"; + if (strlen($lines[$i]) > strlen($p_property)) + if ($p_property == substr($lines[$i], 0, strlen($p_property))){ + $lines[$i] = "$p_property = $p_value\n"; } } - $fp=fopen($filename, 'w'); + $fp=fopen($p_filename, 'w'); for($i=0; $i<$n; $i++){ fwrite($fp, $lines[$i]); } fclose($fp); } + /** + * After the configuration files have been copied to /etc/airtime, + * this function will update them to values unique to this + * particular installation. + */ static function UpdateIniFiles() { $api_key = AirtimeIni::GenerateRandomString(); From db3134cea88eec1d99f3d7b920dccb2983faf7e1 Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 30 Mar 2011 14:54:31 -0400 Subject: [PATCH 2/3] -Preference page now shows a green confirmation success message similar to Manage Users page. --- application/controllers/PreferenceController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/controllers/PreferenceController.php b/application/controllers/PreferenceController.php index 61508bb1c..9f96979ff 100644 --- a/application/controllers/PreferenceController.php +++ b/application/controllers/PreferenceController.php @@ -35,7 +35,8 @@ class PreferenceController extends Zend_Controller_Action Application_Model_Preference::SetSoundCloudPassword($values["SoundCloudPassword"]); Application_Model_Preference::SetSoundCloudTags($values["SoundCloudTags"]); - $this->view->statusMsg = "Preferences Updated."; + $this->view->statusMsg = "
Preferences updated.
"; + } $this->view->form = $form; From 32c28046ef2a1edde3ae8714d2e6b013cf3cec73 Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 30 Mar 2011 15:34:35 -0400 Subject: [PATCH 3/3] CC-1990: Widget to display schedule and "Now Playing" on any website -admin can now enable/disable access to scheduling information to remote widgets via the preferences page. --- application/controllers/ApiController.php | 70 +++++++++++-------- .../controllers/PreferenceController.php | 2 +- application/forms/Preferences.php | 7 ++ application/models/Preference.php | 13 ++++ 4 files changed, 63 insertions(+), 29 deletions(-) diff --git a/application/controllers/ApiController.php b/application/controllers/ApiController.php index aac57fbbb..ef52aaf51 100644 --- a/application/controllers/ApiController.php +++ b/application/controllers/ApiController.php @@ -103,41 +103,55 @@ class ApiController extends Zend_Controller_Action exit; } - public function liveInfoAction(){ - // disable the view and the layout - $this->view->layout()->disableLayout(); - $this->_helper->viewRenderer->setNoRender(true); + public function liveInfoAction() + { + if (Application_Model_Preference::GetAllow3rdPartyApi()){ + // disable the view and the layout + $this->view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); - $result = Schedule::GetPlayOrderRange(0, 1); + $result = Schedule::GetPlayOrderRange(0, 1); - $date = new Application_Model_DateHelper; - $timeNow = $date->getDate(); - $result = array("env"=>APPLICATION_ENV, - "schedulerTime"=>gmdate("Y-m-d H:i:s"), - "currentShow"=>Show_DAL::GetCurrentShow($timeNow), - "nextShow"=>Show_DAL::GetNextShows($timeNow, 5), - "timezone"=> date("T"), - "timezoneOffset"=> date("Z")); - - //echo json_encode($result); - header("Content-type: text/javascript"); - echo $_GET['callback'].'('.json_encode($result).')'; + $date = new Application_Model_DateHelper; + $timeNow = $date->getDate(); + $result = array("env"=>APPLICATION_ENV, + "schedulerTime"=>gmdate("Y-m-d H:i:s"), + "currentShow"=>Show_DAL::GetCurrentShow($timeNow), + "nextShow"=>Show_DAL::GetNextShows($timeNow, 5), + "timezone"=> date("T"), + "timezoneOffset"=> date("Z")); + + //echo json_encode($result); + header("Content-type: text/javascript"); + echo $_GET['callback'].'('.json_encode($result).')'; + } else { + header('HTTP/1.0 401 Unauthorized'); + print 'You are not allowed to access this resource. '; + exit; + } } - public function weekInfoAction(){ - // disable the view and the layout - $this->view->layout()->disableLayout(); - $this->_helper->viewRenderer->setNoRender(true); + public function weekInfoAction() + { + if (Application_Model_Preference::GetAllow3rdPartyApi()){ + // disable the view and the layout + $this->view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); - $dow = array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"); + $dow = array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"); - $result = array(); - for ($i=0; $i<7; $i++){ - $result[$dow[$i]] = Show_DAL::GetShowsByDayOfWeek($i); + $result = array(); + for ($i=0; $i<7; $i++){ + $result[$dow[$i]] = Show_DAL::GetShowsByDayOfWeek($i); + } + + header("Content-type: text/javascript"); + echo $_GET['callback'].'('.json_encode($result).')'; + } else { + header('HTTP/1.0 401 Unauthorized'); + print 'You are not allowed to access this resource. '; + exit; } - - header("Content-type: text/javascript"); - echo $_GET['callback'].'('.json_encode($result).')'; } public function scheduleAction() diff --git a/application/controllers/PreferenceController.php b/application/controllers/PreferenceController.php index 9f96979ff..46d82054f 100644 --- a/application/controllers/PreferenceController.php +++ b/application/controllers/PreferenceController.php @@ -30,13 +30,13 @@ class PreferenceController extends Zend_Controller_Action Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view); Application_Model_Preference::SetDefaultFade($values["stationDefaultFade"]); Application_Model_Preference::SetStreamLabelFormat($values["streamFormat"]); + Application_Model_Preference::SetAllow3rdPartyApi($values["thirdPartyApi"]); Application_Model_Preference::SetDoSoundCloudUpload($values["UseSoundCloud"]); Application_Model_Preference::SetSoundCloudUser($values["SoundCloudUser"]); Application_Model_Preference::SetSoundCloudPassword($values["SoundCloudPassword"]); Application_Model_Preference::SetSoundCloudTags($values["SoundCloudTags"]); $this->view->statusMsg = "
Preferences updated.
"; - } $this->view->form = $form; diff --git a/application/forms/Preferences.php b/application/forms/Preferences.php index eaaff98a6..a319476a2 100644 --- a/application/forms/Preferences.php +++ b/application/forms/Preferences.php @@ -42,6 +42,13 @@ class Application_Form_Preferences extends Zend_Form $stream_format->setValue(Application_Model_Preference::GetStreamLabelFormat()); $this->addElement($stream_format); + $third_party_api = new Zend_Form_Element_Radio('thirdPartyApi'); + $third_party_api->setLabel('Allow Remote Websites To Access Show Schedule Info'); + $third_party_api->setMultiOptions(array("Disabled", + "Enabled")); + $third_party_api->setValue(Application_Model_Preference::GetAllow3rdPartyApi()); + $this->addElement($third_party_api); + $this->addElement('checkbox', 'UseSoundCloud', array( 'label' => 'Automatically Upload Recorded Shows To SoundCloud', diff --git a/application/models/Preference.php b/application/models/Preference.php index 948b29645..9efd2fd10 100644 --- a/application/models/Preference.php +++ b/application/models/Preference.php @@ -132,5 +132,18 @@ class Application_Model_Preference return Application_Model_Preference::GetValue("soundcloud_tags"); } + public static function SetAllow3rdPartyApi($bool) { + Application_Model_Preference::SetValue("third_party_api", $bool); + } + + public static function GetAllow3rdPartyApi() { + $val = Application_Model_Preference::GetValue("third_party_api"); + if (strlen($val) == 0){ + return "0"; + } else { + return $val; + } + } + }