2011-08-15 22:10:46 +02:00
|
|
|
<?php
|
|
|
|
class Application_Model_StreamSetting {
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
public static function SetValue($key, $value, $type)
|
|
|
|
{
|
|
|
|
global $CC_CONFIG;
|
|
|
|
$con = Propel::getConnection();
|
2012-03-02 22:55:11 +01:00
|
|
|
|
|
|
|
$key = pg_escape_string($key);
|
|
|
|
$value = pg_escape_string($value);
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
// Check if key already exists
|
2012-03-02 22:55:11 +01:00
|
|
|
$sql = "SELECT COUNT(*) FROM cc_stream_setting"
|
2012-04-01 21:51:03 +02:00
|
|
|
." WHERE keyname = '$key'";
|
|
|
|
|
|
|
|
$result = $con->query($sql)->fetchColumn(0);
|
2012-03-02 22:55:11 +01:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
if ($result == 1) {
|
2012-03-02 22:55:11 +01:00
|
|
|
$sql = "UPDATE cc_stream_setting"
|
|
|
|
." SET value = '$value', type='$type'"
|
|
|
|
." WHERE keyname = '$key'";
|
|
|
|
} else {
|
|
|
|
$sql = "INSERT INTO cc_stream_setting (keyname, value, type)"
|
|
|
|
." VALUES ('$key', '$value', '$type')";
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
return $con->exec($sql);
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
public static function GetValue($key)
|
|
|
|
{
|
|
|
|
global $CC_CONFIG;
|
|
|
|
$con = Propel::getConnection();
|
|
|
|
|
2012-03-02 22:55:11 +01:00
|
|
|
//Check if key already exists
|
|
|
|
$sql = "SELECT COUNT(*) FROM cc_stream_setting"
|
|
|
|
." WHERE keyname = '$key'";
|
2012-04-01 21:51:03 +02:00
|
|
|
$result = $con->query($sql)->fetchColumn(0);
|
2012-03-02 22:55:11 +01:00
|
|
|
|
|
|
|
if ($result == 0)
|
|
|
|
return "";
|
|
|
|
else {
|
|
|
|
$sql = "SELECT value FROM cc_stream_setting"
|
2012-04-01 21:51:03 +02:00
|
|
|
." WHERE keyname = '$key'";
|
|
|
|
|
|
|
|
$result = $con->query($sql)->fetchColumn(0);
|
2012-04-19 22:54:38 +02:00
|
|
|
return ($result !== false) ? $result : NULL;
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
|
|
|
}
|
2011-09-27 21:26:40 +02:00
|
|
|
|
|
|
|
/* Returns the id's of all streams that are enabled in an array. An
|
|
|
|
* example of the array returned in JSON notation is ["s1", "s2", "s3"] */
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function getEnabledStreamIds()
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
2011-09-27 21:26:40 +02:00
|
|
|
$sql = "SELECT * "
|
|
|
|
."FROM cc_stream_setting "
|
2011-11-29 22:25:30 +01:00
|
|
|
."WHERE keyname LIKE '%_enable' "
|
2011-11-30 22:10:40 +01:00
|
|
|
."AND value='true'";
|
2011-09-27 21:26:40 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$rows = $con->query($sql)->fetchAll();
|
2011-09-27 21:26:40 +02:00
|
|
|
$ids = array();
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
foreach ($rows as $row) {
|
2011-09-27 21:26:40 +02:00
|
|
|
$ids[] = substr($row["keyname"], 0, strpos($row["keyname"], "_"));
|
|
|
|
}
|
|
|
|
|
|
|
|
//Logging::log(print_r($ids, true));
|
|
|
|
return $ids;
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
/* Returns only global data as array*/
|
|
|
|
public static function getGlobalData()
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
2011-11-25 23:33:59 +01:00
|
|
|
$sql = "SELECT * "
|
2012-04-01 21:51:03 +02:00
|
|
|
."FROM cc_stream_setting "
|
|
|
|
."WHERE keyname IN ('output_sound_device', 'icecast_vorbis_metadata')";
|
|
|
|
|
|
|
|
$rows = $con->query($sql)->fetchAll();
|
2011-11-25 23:33:59 +01:00
|
|
|
$data = array();
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
$data[$row["keyname"]] = $row["value"];
|
2011-11-25 23:33:59 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-11-25 23:33:59 +01:00
|
|
|
return $data;
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-09-27 21:26:40 +02:00
|
|
|
/* Returns all information related to a specific stream. An example
|
|
|
|
* of a stream id is 's1' or 's2'. */
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function getStreamData($p_streamId)
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
2011-09-27 21:26:40 +02:00
|
|
|
$sql = "SELECT * "
|
|
|
|
."FROM cc_stream_setting "
|
|
|
|
."WHERE keyname LIKE '${p_streamId}_%'";
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$rows = $con->query($sql)->fetchAll();
|
2011-09-27 21:26:40 +02:00
|
|
|
$data = array();
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
foreach ($rows as $row) {
|
2011-09-27 21:26:40 +02:00
|
|
|
$data[$row["keyname"]] = $row["value"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
2011-08-15 22:10:46 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
public static function getStreamSetting()
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
2011-08-15 22:10:46 +02:00
|
|
|
$sql = "SELECT *"
|
2011-10-11 02:14:27 +02:00
|
|
|
." FROM cc_stream_setting"
|
|
|
|
." WHERE keyname not like '%_error'";
|
2011-08-15 22:10:46 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$rows = $con->query($sql)->fetchAll();
|
|
|
|
|
2012-03-05 19:51:59 +01:00
|
|
|
$exists = array();
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
foreach ($rows as $r) {
|
|
|
|
if ($r['keyname'] == 'master_live_stream_port') {
|
2012-03-05 19:51:59 +01:00
|
|
|
$exists['master_live_stream_port'] = true;
|
2012-04-01 21:51:03 +02:00
|
|
|
} elseif($r['keyname'] == 'master_live_stream_mp') {
|
2012-03-05 19:51:59 +01:00
|
|
|
$exists['master_live_stream_mp'] = true;
|
2012-04-01 21:51:03 +02:00
|
|
|
} elseif($r['keyname'] == 'dj_live_stream_port') {
|
2012-03-05 19:51:59 +01:00
|
|
|
$exists['dj_live_stream_port'] = true;
|
2012-04-01 21:51:03 +02:00
|
|
|
} elseif($r['keyname'] == 'dj_live_stream_mp') {
|
2012-03-05 19:51:59 +01:00
|
|
|
$exists['dj_live_stream_mp'] = true;
|
|
|
|
}
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
if (!isset($exists["master_live_stream_port"])) {
|
2012-03-05 19:51:59 +01:00
|
|
|
$rows[] = (array("keyname" =>"master_live_stream_port", "value"=>self::GetMasterLiveSteamPort(), "type"=>"integer"));
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
if (!isset($exists["master_live_stream_mp"])) {
|
2012-03-05 19:51:59 +01:00
|
|
|
$rows[] = (array("keyname" =>"master_live_stream_mp", "value"=>self::GetMasterLiveSteamMountPoint(), "type"=>"string"));
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
if (!isset($exists["dj_live_stream_port"])) {
|
2012-03-05 19:51:59 +01:00
|
|
|
$rows[] = (array("keyname" =>"dj_live_stream_port", "value"=>self::GetDJLiveSteamPort(), "type"=>"integer"));
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
if (!isset($exists["dj_live_stream_mp"])) {
|
2012-03-05 19:51:59 +01:00
|
|
|
$rows[] = (array("keyname" =>"dj_live_stream_mp", "value"=>self::GetDJLiveSteamMountPoint(), "type"=>"string"));
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2011-08-15 22:10:46 +02:00
|
|
|
return $rows;
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-11-13 21:34:26 +01:00
|
|
|
/*
|
|
|
|
* function that take all the information of stream and sets them.
|
|
|
|
* This is used by stream setting via UI.
|
2012-04-01 21:51:03 +02:00
|
|
|
*
|
2011-11-13 21:34:26 +01:00
|
|
|
* @param $data - array that contains all the data. $data is [][] which
|
|
|
|
* contains multiple stream information
|
|
|
|
*/
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function setStreamSetting($data)
|
|
|
|
{
|
2012-06-12 23:08:36 +02:00
|
|
|
$con = Propel::getConnection();
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-11-29 22:25:30 +01:00
|
|
|
foreach ($data as $key=>$d) {
|
|
|
|
if ($key == "output_sound_device" || $key == "icecast_vorbis_metadata") {
|
2011-08-18 19:53:12 +02:00
|
|
|
$v = $d == 1?"true":"false";
|
|
|
|
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$key'";
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2011-12-05 03:47:11 +01:00
|
|
|
} else if ($key == "output_sound_device_type") {
|
|
|
|
$sql = "UPDATE cc_stream_setting SET value='$d' WHERE keyname='$key'";
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2012-02-11 00:43:40 +01:00
|
|
|
} else if (is_array($d)) {
|
2011-08-18 19:53:12 +02:00
|
|
|
$temp = explode('_', $key);
|
|
|
|
$prefix = $temp[0];
|
2011-11-29 22:25:30 +01:00
|
|
|
foreach ($d as $k=>$v) {
|
|
|
|
$keyname = $prefix . "_" . $k;
|
|
|
|
if ($k == 'enable') {
|
|
|
|
$v = $d['enable'] == 1 ? 'true' : 'false';
|
2011-08-18 19:53:12 +02:00
|
|
|
}
|
2011-09-01 22:02:06 +02:00
|
|
|
$v = trim($v);
|
2012-06-04 04:39:42 +02:00
|
|
|
|
|
|
|
#escape double single quotes CC-3926
|
|
|
|
$v = str_replace("'", "''", $v);
|
2011-08-18 19:53:12 +02:00
|
|
|
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'";
|
2012-06-04 04:39:42 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2011-08-18 19:53:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-11-13 21:34:26 +01:00
|
|
|
/*
|
|
|
|
* Sets indivisual stream setting.
|
2012-04-01 21:51:03 +02:00
|
|
|
*
|
2011-11-13 21:34:26 +01:00
|
|
|
* $data - data array. $data is [].
|
|
|
|
*/
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function setIndivisualStreamSetting($data)
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
|
|
|
|
|
|
|
foreach ($data as $keyname => $v) {
|
2011-11-13 21:34:26 +01:00
|
|
|
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'";
|
2012-04-01 21:51:03 +02:00
|
|
|
$con->exec($sql);
|
2011-11-13 21:34:26 +01:00
|
|
|
}
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-11-30 02:15:38 +01:00
|
|
|
/*
|
|
|
|
* Stores liquidsoap status if $boot_time > save time.
|
|
|
|
* save time is the time that user clicked save on stream setting page
|
|
|
|
*/
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function setLiquidsoapError($stream_id, $msg, $boot_time=null)
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
|
|
|
|
2011-11-30 02:15:38 +01:00
|
|
|
$update_time = Application_Model_Preference::GetStreamUpdateTimestemp();
|
2012-04-01 21:51:03 +02:00
|
|
|
if ($boot_time == null || $boot_time > $update_time) {
|
2011-11-30 02:15:38 +01:00
|
|
|
$keyname = "s".$stream_id."_liquidsoap_error";
|
|
|
|
$sql = "SELECT COUNT(*) FROM cc_stream_setting"
|
2011-10-11 02:14:27 +02:00
|
|
|
." WHERE keyname = '$keyname'";
|
2012-04-01 21:51:03 +02:00
|
|
|
$result = $con->query($sql)->fetchColumn(0);
|
|
|
|
if ($result == 1) {
|
2011-11-30 02:15:38 +01:00
|
|
|
$sql = "UPDATE cc_stream_setting"
|
|
|
|
." SET value = '$msg'"
|
|
|
|
." WHERE keyname = '$keyname'";
|
2012-04-01 21:51:03 +02:00
|
|
|
} else {
|
2011-11-30 02:15:38 +01:00
|
|
|
$sql = "INSERT INTO cc_stream_setting (keyname, value, type)"
|
|
|
|
." VALUES ('$keyname', '$msg', 'string')";
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
$res = $con->exec($sql);
|
2011-10-11 02:14:27 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
public static function getLiquidsoapError($stream_id)
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
|
|
|
|
2011-10-11 02:14:27 +02:00
|
|
|
$keyname = "s".$stream_id."_liquidsoap_error";
|
|
|
|
$sql = "SELECT value FROM cc_stream_setting"
|
2011-10-13 20:20:08 +02:00
|
|
|
." WHERE keyname = '$keyname'";
|
2012-04-01 21:51:03 +02:00
|
|
|
$result = $con->query($sql)->fetchColumn(0);
|
|
|
|
|
2012-04-19 22:54:38 +02:00
|
|
|
return ($result !== false) ? $result : NULL;
|
2011-10-11 02:14:27 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
public static function getStreamEnabled($stream_id)
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
|
|
|
|
2011-11-29 22:25:30 +01:00
|
|
|
$keyname = "s" . $stream_id . "_enable";
|
2011-10-13 20:20:08 +02:00
|
|
|
$sql = "SELECT value FROM cc_stream_setting"
|
|
|
|
." WHERE keyname = '$keyname'";
|
2012-04-01 21:51:03 +02:00
|
|
|
$result = $con->query($sql)->fetchColumn(0);
|
2011-11-29 22:25:30 +01:00
|
|
|
if ($result == 'false') {
|
2011-10-13 20:20:08 +02:00
|
|
|
$result = false;
|
2011-11-29 22:25:30 +01:00
|
|
|
} else {
|
2011-10-13 20:20:08 +02:00
|
|
|
$result = true;
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-12-07 16:31:16 +01:00
|
|
|
/*
|
|
|
|
* Only returns info that is needed for data collection
|
|
|
|
* returns array('s1'=>array(keyname=>value))
|
|
|
|
*/
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function getStreamInfoForDataCollection()
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
|
|
|
|
2011-12-07 16:31:16 +01:00
|
|
|
$out = array();
|
|
|
|
$enabled_stream = self::getEnabledStreamIds();
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
foreach ($enabled_stream as $stream) {
|
2011-12-07 16:31:16 +01:00
|
|
|
$keys = "'".$stream."_output', "."'".$stream."_type', "."'".$stream."_bitrate', "."'".$stream."_host'";
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-12-07 16:31:16 +01:00
|
|
|
$sql = "SELECT keyname, value FROM cc_stream_setting"
|
2012-04-01 21:51:03 +02:00
|
|
|
." WHERE keyname IN ($keys)";
|
|
|
|
|
|
|
|
$rows = $con->query($sql)->fetchAll();
|
2011-12-07 16:31:16 +01:00
|
|
|
$info = array();
|
2012-04-01 21:51:03 +02:00
|
|
|
foreach ($rows as $r) {
|
2011-12-07 16:31:16 +01:00
|
|
|
$temp = explode("_", $r['keyname']);
|
|
|
|
$info[$temp[1]] = $r['value'];
|
2012-04-01 21:51:03 +02:00
|
|
|
$out[$stream] = $info;
|
2011-12-07 16:31:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-03-02 22:55:11 +01:00
|
|
|
public static function SetMasterLiveSteamPort($value){
|
|
|
|
self::SetValue("master_live_stream_port", $value, "integer");
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-03-02 22:55:11 +01:00
|
|
|
public static function GetMasterLiveSteamPort(){
|
|
|
|
return self::GetValue("master_live_stream_port");
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-03-02 22:55:11 +01:00
|
|
|
public static function SetMasterLiveSteamMountPoint($value){
|
|
|
|
self::SetValue("master_live_stream_mp", $value, "string");
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-03-02 22:55:11 +01:00
|
|
|
public static function GetMasterLiveSteamMountPoint(){
|
|
|
|
return self::GetValue("master_live_stream_mp");
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-03-02 22:55:11 +01:00
|
|
|
public static function SetDJLiveSteamPort($value){
|
|
|
|
self::SetValue("dj_live_stream_port", $value, "integer");
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-03-02 22:55:11 +01:00
|
|
|
public static function GetDJLiveSteamPort(){
|
|
|
|
return self::GetValue("dj_live_stream_port");
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-03-02 22:55:11 +01:00
|
|
|
public static function SetDJLiveSteamMountPoint($value){
|
|
|
|
self::SetValue("dj_live_stream_mp", $value, "string");
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-03-02 22:55:11 +01:00
|
|
|
public static function GetDJLiveSteamMountPoint(){
|
|
|
|
return self::GetValue("dj_live_stream_mp");
|
|
|
|
}
|
2011-09-27 21:26:40 +02:00
|
|
|
}
|