Merge branch 'master' of dev.sourcefabric.org:campcaster
This commit is contained in:
commit
d2fb99eff9
|
@ -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()
|
||||
|
|
|
@ -30,12 +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->statusMsg = "<div class='success'>Preferences updated.</div>";
|
||||
}
|
||||
|
||||
$this->view->form = $form;
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Newscoop
|
||||
* @subpackage Subscriptions
|
||||
* @copyright 2011 Sourcefabric o.p.s.
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
// Do not allow remote execution
|
||||
$arr = array_diff_assoc($_SERVER, $_ENV);
|
||||
|
@ -9,6 +15,7 @@ if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
|
|||
exit(1);
|
||||
}
|
||||
|
||||
//make sure user has Postgresql PHP extension installed.
|
||||
if (!function_exists('pg_connect')) {
|
||||
trigger_error("PostgreSQL PHP extension required and not found.", E_USER_ERROR);
|
||||
exit(2);
|
||||
|
@ -16,7 +23,12 @@ if (!function_exists('pg_connect')) {
|
|||
|
||||
class AirtimeIni{
|
||||
|
||||
static function CreateIniFile(){
|
||||
/**
|
||||
* This function creates the /etc/airtime configuration folder
|
||||
* and copies the default config files to it.
|
||||
*/
|
||||
static function CreateIniFile()
|
||||
{
|
||||
if (!file_exists("/etc/airtime/")){
|
||||
if (!mkdir("/etc/airtime/", 0755, true)){
|
||||
echo "Could not create /etc/airtime/ directory. Exiting.";
|
||||
|
@ -42,7 +54,12 @@ class AirtimeIni{
|
|||
}
|
||||
}
|
||||
|
||||
static function RemoveIniFiles(){
|
||||
/**
|
||||
* This function removes /etc/airtime and the configuration
|
||||
* files present within it.
|
||||
*/
|
||||
static function RemoveIniFiles()
|
||||
{
|
||||
if (file_exists("/etc/airtime/airtime.conf")){
|
||||
unlink("/etc/airtime/airtime.conf");
|
||||
}
|
||||
|
@ -64,6 +81,11 @@ class AirtimeIni{
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the user is running this PHP script with root
|
||||
* permissions. If not running with root permissions, causes the
|
||||
* script to exit.
|
||||
*/
|
||||
static function ExitIfNotRoot()
|
||||
{
|
||||
// Need to check that we are superuser before running this.
|
||||
|
@ -73,35 +95,68 @@ class AirtimeIni{
|
|||
}
|
||||
}
|
||||
|
||||
static function GenerateRandomString($len=20, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
|
||||
/**
|
||||
* This function generates a random string.
|
||||
*
|
||||
* The random string uses two parameters: $p_len and $p_chars. These
|
||||
* parameters do not need to be provided, in which case defaults are
|
||||
* used.
|
||||
*
|
||||
* @param string $p_len
|
||||
* How long should the generated string be.
|
||||
* @param string $p_chars
|
||||
* String containing chars that should be used for generating.
|
||||
* @return string
|
||||
* The generated random string.
|
||||
*/
|
||||
static function GenerateRandomString($p_len=20, $p_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
|
||||
{
|
||||
$string = '';
|
||||
for ($i = 0; $i < $len; $i++)
|
||||
for ($i = 0; $i < $p_len; $i++)
|
||||
{
|
||||
$pos = mt_rand(0, strlen($chars)-1);
|
||||
$string .= $chars{$pos};
|
||||
$pos = mt_rand(0, strlen($p_chars)-1);
|
||||
$string .= $p_chars{$pos};
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
static function UpdateIniValue($filename, $property, $value)
|
||||
/**
|
||||
* This function updates an INI style config file.
|
||||
*
|
||||
* A property and the value the property should be changed to are
|
||||
* supplied. If the property is not found, then no changes are made.
|
||||
*
|
||||
* @param string $p_filename
|
||||
* The path the to the file.
|
||||
* @param string $p_property
|
||||
* The property to look for in order to change its value.
|
||||
* @param string $p_value
|
||||
* The value the property should be changed to.
|
||||
*
|
||||
*/
|
||||
static function UpdateIniValue($p_filename, $p_property, $p_value)
|
||||
{
|
||||
$lines = file($filename);
|
||||
$lines = file($p_filename);
|
||||
$n=count($lines);
|
||||
for ($i=0; $i<$n; $i++) {
|
||||
if (strlen($lines[$i]) > 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();
|
||||
|
|
Loading…
Reference in New Issue