2012-02-06 23:51:02 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
|
|
|
|
{
|
2012-05-28 21:37:45 +02:00
|
|
|
|
2012-02-06 23:51:02 +01:00
|
|
|
public function init()
|
|
|
|
{
|
2012-06-05 18:18:59 +02:00
|
|
|
global $CC_CONFIG;
|
|
|
|
$isDemo = isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1;
|
|
|
|
$isStreamConfigable = Application_Model_Preference::GetEnableStreamConf() == "true";
|
|
|
|
|
2012-05-28 21:37:45 +02:00
|
|
|
$isSaas = Application_Model_Preference::GetPlanLevel() == 'disabled'?false:true;
|
2012-03-21 03:16:17 +01:00
|
|
|
$defaultFade = Application_Model_Preference::GetDefaultTransitionFade();
|
|
|
|
if($defaultFade == ""){
|
|
|
|
$defaultFade = '00.000000';
|
|
|
|
}
|
|
|
|
|
2012-06-12 21:38:03 +02:00
|
|
|
// automatic trasition on source disconnection
|
2012-06-05 22:41:41 +02:00
|
|
|
$auto_transition = new Zend_Form_Element_Checkbox("auto_transition");
|
2012-06-12 21:38:03 +02:00
|
|
|
$auto_transition->setLabel("Auto Switch Off")
|
2012-06-05 22:41:41 +02:00
|
|
|
->setValue(Application_Model_Preference::GetAutoTransition())
|
|
|
|
->setDecorators(array('ViewHelper'));
|
|
|
|
$this->addElement($auto_transition);
|
|
|
|
|
2012-06-12 21:38:03 +02:00
|
|
|
// automatic switch on upon source connection
|
|
|
|
$auto_switch = new Zend_Form_Element_Checkbox("auto_switch");
|
|
|
|
$auto_switch->setLabel("Auto Switch On")
|
|
|
|
->setValue(Application_Model_Preference::GetAutoSwitch())
|
|
|
|
->setDecorators(array('ViewHelper'));
|
|
|
|
$this->addElement($auto_switch);
|
|
|
|
|
2012-06-05 22:41:41 +02:00
|
|
|
// Default transition fade
|
2012-03-21 03:16:17 +01:00
|
|
|
$transition_fade = new Zend_Form_Element_Text("transition_fade");
|
|
|
|
$transition_fade->setLabel("Switch Transition Fade (s)")
|
|
|
|
->setFilters(array('StringTrim'))
|
2012-04-13 18:05:59 +02:00
|
|
|
->addValidator('regex', false, array('/^[0-9]{1,2}(\.\d{1,6})?$/',
|
2012-03-21 03:16:17 +01:00
|
|
|
'messages' => 'enter a time in seconds 00{.000000}'))
|
|
|
|
->setValue($defaultFade)
|
|
|
|
->setDecorators(array('ViewHelper'));
|
|
|
|
$this->addElement($transition_fade);
|
|
|
|
|
2012-02-06 23:51:02 +01:00
|
|
|
//Master username
|
|
|
|
$master_username = new Zend_Form_Element_Text('master_username');
|
2012-02-21 23:58:05 +01:00
|
|
|
$master_username->setAttrib('autocomplete', 'off')
|
2012-02-08 06:04:19 +01:00
|
|
|
->setAllowEmpty(true)
|
2012-02-06 23:51:02 +01:00
|
|
|
->setLabel('Master Username')
|
|
|
|
->setFilters(array('StringTrim'))
|
|
|
|
->setValue(Application_Model_Preference::GetLiveSteamMasterUsername())
|
|
|
|
->setDecorators(array('ViewHelper'));
|
|
|
|
$this->addElement($master_username);
|
|
|
|
|
|
|
|
//Master password
|
2012-06-05 18:18:59 +02:00
|
|
|
if($isDemo){
|
|
|
|
$master_password = new Zend_Form_Element_Text('master_password');
|
|
|
|
}else{
|
|
|
|
$master_password = new Zend_Form_Element_Password('master_password');
|
|
|
|
$master_password->setAttrib('renderPassword','true');
|
|
|
|
}
|
2012-02-21 23:58:05 +01:00
|
|
|
$master_password->setAttrib('autocomplete', 'off')
|
2012-02-08 06:04:19 +01:00
|
|
|
->setAttrib('renderPassword','true')
|
|
|
|
->setAllowEmpty(true)
|
2012-02-23 17:51:20 +01:00
|
|
|
->setValue(Application_Model_Preference::GetLiveSteamMasterPassword())
|
2012-02-06 23:51:02 +01:00
|
|
|
->setLabel('Master Password')
|
|
|
|
->setFilters(array('StringTrim'))
|
|
|
|
->setDecorators(array('ViewHelper'));
|
|
|
|
$this->addElement($master_password);
|
2012-02-23 17:11:02 +01:00
|
|
|
|
2012-06-05 21:13:04 +02:00
|
|
|
//Master source connection url
|
|
|
|
$master_dj_connection_url = new Zend_Form_Element_Text('master_dj_connection_url');
|
|
|
|
$master_dj_connection_url->setAttrib('readonly', true)
|
|
|
|
->setLabel('Master Source Connection URL')
|
2012-06-12 00:08:36 +02:00
|
|
|
->setValue(Application_Model_Preference::GetMasterDJSourceConnectionURL())
|
2012-06-05 21:13:04 +02:00
|
|
|
->setDecorators(array('ViewHelper'));
|
|
|
|
$this->addElement($master_dj_connection_url);
|
|
|
|
|
|
|
|
//Show source connection url
|
|
|
|
$live_dj_connection_url = new Zend_Form_Element_Text('live_dj_connection_url');
|
|
|
|
$live_dj_connection_url->setAttrib('readonly', true)
|
|
|
|
->setLabel('Show Source Connection URL')
|
2012-06-12 00:08:36 +02:00
|
|
|
->setValue(Application_Model_Preference::GetLiveDJSourceConnectionURL())
|
2012-06-05 21:13:04 +02:00
|
|
|
->setDecorators(array('ViewHelper'));
|
|
|
|
$this->addElement($live_dj_connection_url);
|
|
|
|
|
2012-02-23 17:11:02 +01:00
|
|
|
//liquidsoap harbor.input port
|
2012-05-28 21:37:45 +02:00
|
|
|
if (!$isSaas) {
|
2012-07-10 05:32:21 +02:00
|
|
|
$m_port = Application_Model_StreamSetting::getMasterLiveStreamPort();
|
2012-05-28 21:37:45 +02:00
|
|
|
$master_dj_port = new Zend_Form_Element_Text('master_harbor_input_port');
|
|
|
|
$master_dj_port->setLabel("Master Source Port")
|
|
|
|
->setValue($m_port)
|
|
|
|
->setValidators(array(new Zend_Validate_Between(array('min'=>1024, 'max'=>49151))))
|
|
|
|
->addValidator('regex', false, array('pattern'=>'/^[0-9]+$/', 'messages'=>array('regexNotMatch'=>'Only numbers are allowed.')))
|
|
|
|
->setDecorators(array('ViewHelper'));
|
|
|
|
$this->addElement($master_dj_port);
|
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
$m_mount = Application_Model_StreamSetting::getMasterLiveStreamMountPoint();
|
2012-05-28 21:37:45 +02:00
|
|
|
$master_dj_mount = new Zend_Form_Element_Text('master_harbor_input_mount_point');
|
|
|
|
$master_dj_mount->setLabel("Master Source Mount Point")
|
|
|
|
->setValue($m_mount)
|
|
|
|
->setValidators(array(
|
|
|
|
array('regex', false, array('/^[^ &<>]+$/', 'messages' => 'Invalid character entered'))))
|
|
|
|
->setDecorators(array('ViewHelper'));
|
|
|
|
$this->addElement($master_dj_mount);
|
|
|
|
|
|
|
|
//liquidsoap harbor.input port
|
2012-07-10 05:32:21 +02:00
|
|
|
$l_port = Application_Model_StreamSetting::getDjLiveStreamPort();
|
2012-05-28 21:37:45 +02:00
|
|
|
$live_dj_port = new Zend_Form_Element_Text('dj_harbor_input_port');
|
|
|
|
$live_dj_port->setLabel("Show Source Port")
|
|
|
|
->setValue($l_port)
|
|
|
|
->setValidators(array(new Zend_Validate_Between(array('min'=>1024, 'max'=>49151))))
|
|
|
|
->addValidator('regex', false, array('pattern'=>'/^[0-9]+$/', 'messages'=>array('regexNotMatch'=>'Only numbers are allowed.')))
|
|
|
|
->setDecorators(array('ViewHelper'));
|
|
|
|
$this->addElement($live_dj_port);
|
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
$l_mount = Application_Model_StreamSetting::getDjLiveStreamMountPoint();
|
2012-05-28 21:37:45 +02:00
|
|
|
$live_dj_mount = new Zend_Form_Element_Text('dj_harbor_input_mount_point');
|
|
|
|
$live_dj_mount->setLabel("Show Source Mount Point")
|
|
|
|
->setValue($l_mount)
|
|
|
|
->setValidators(array(
|
|
|
|
array('regex', false, array('/^[^ &<>]+$/', 'messages' => 'Invalid character entered'))))
|
|
|
|
->setDecorators(array('ViewHelper'));
|
|
|
|
$this->addElement($live_dj_mount);
|
|
|
|
}
|
2012-06-05 18:18:59 +02:00
|
|
|
// demo only code
|
|
|
|
if(!$isStreamConfigable){
|
|
|
|
$elements = $this->getElements();
|
|
|
|
foreach ($elements as $element)
|
|
|
|
{
|
|
|
|
if ($element->getType() != 'Zend_Form_Element_Hidden')
|
|
|
|
{
|
|
|
|
$element->setAttrib("disabled", "disabled");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 23:51:02 +01:00
|
|
|
}
|
2012-03-19 21:08:23 +01:00
|
|
|
|
2012-04-17 00:21:28 +02:00
|
|
|
public function updateVariables(){
|
2012-06-05 18:18:59 +02:00
|
|
|
global $CC_CONFIG;
|
2012-06-05 21:13:04 +02:00
|
|
|
|
2012-05-19 01:08:50 +02:00
|
|
|
$isSaas = Application_Model_Preference::GetPlanLevel() == 'disabled'?false:true;
|
2012-06-05 18:18:59 +02:00
|
|
|
$isDemo = isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1;
|
2012-06-12 00:08:36 +02:00
|
|
|
$master_dj_connection_url = Application_Model_Preference::GetMasterDJSourceConnectionURL();
|
|
|
|
$live_dj_connection_url = Application_Model_Preference::GetLiveDJSourceConnectionURL();
|
2012-06-05 21:13:04 +02:00
|
|
|
|
2012-03-19 21:08:23 +01:00
|
|
|
$this->setDecorators(array(
|
2012-06-06 19:10:57 +02:00
|
|
|
array('ViewScript', array('viewScript' => 'form/preferences_livestream.phtml', 'master_dj_connection_url'=>$master_dj_connection_url, 'live_dj_connection_url'=>$live_dj_connection_url, 'isSaas' => $isSaas, 'isDemo' => $isDemo))
|
2012-03-19 21:08:23 +01:00
|
|
|
));
|
|
|
|
}
|
2012-03-22 21:21:23 +01:00
|
|
|
|
|
|
|
public function isValid($data){
|
2012-05-28 21:37:45 +02:00
|
|
|
$isSaas = Application_Model_Preference::GetPlanLevel() == 'disabled'?false:true;
|
2012-03-22 21:21:23 +01:00
|
|
|
$isValid = parent::isValid($data);
|
2012-05-28 21:37:45 +02:00
|
|
|
if (!$isSaas) {
|
|
|
|
$master_harbor_input_port = $data['master_harbor_input_port'];
|
|
|
|
$dj_harbor_input_port = $data['dj_harbor_input_port'];
|
|
|
|
|
|
|
|
if($master_harbor_input_port == $dj_harbor_input_port && $master_harbor_input_port != ""){
|
|
|
|
$element = $this->getElement("dj_harbor_input_port");
|
|
|
|
$element->addError("You cannot use same port as Master DJ port.");
|
|
|
|
}
|
|
|
|
if($master_harbor_input_port != ""){
|
|
|
|
if(is_numeric($master_harbor_input_port)){
|
2012-07-10 05:32:21 +02:00
|
|
|
if($master_harbor_input_port != Application_Model_StreamSetting::getMasterLiveStreamPort()){
|
2012-05-28 21:37:45 +02:00
|
|
|
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
|
|
|
$res = socket_bind($sock, 0, $master_harbor_input_port);
|
|
|
|
if(!$res){
|
|
|
|
$element = $this->getElement("master_harbor_input_port");
|
|
|
|
$element->addError("Port '$master_harbor_input_port' is not available.");
|
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
socket_close($sock);
|
2012-04-19 21:18:53 +02:00
|
|
|
}
|
2012-05-28 21:37:45 +02:00
|
|
|
}else{
|
|
|
|
$isValid = false;
|
2012-03-27 23:14:34 +02:00
|
|
|
}
|
2012-03-22 21:21:23 +01:00
|
|
|
}
|
2012-05-28 21:37:45 +02:00
|
|
|
if($dj_harbor_input_port != ""){
|
|
|
|
if(is_numeric($dj_harbor_input_port)){
|
2012-07-10 05:32:21 +02:00
|
|
|
if($dj_harbor_input_port != Application_Model_StreamSetting::getDjLiveStreamPort()){
|
2012-05-28 21:37:45 +02:00
|
|
|
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
|
|
|
$res = socket_bind($sock, 0, $dj_harbor_input_port);
|
|
|
|
if(!$res){
|
|
|
|
$element = $this->getElement("dj_harbor_input_port");
|
|
|
|
$element->addError("Port '$dj_harbor_input_port' is not available.");
|
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
socket_close($sock);
|
2012-04-19 21:18:53 +02:00
|
|
|
}
|
2012-05-28 21:37:45 +02:00
|
|
|
}else{
|
|
|
|
$isValid = false;
|
2012-03-27 23:14:34 +02:00
|
|
|
}
|
2012-03-22 21:21:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $isValid;
|
|
|
|
}
|
|
|
|
|
2012-05-19 01:08:50 +02:00
|
|
|
}
|