Created
May 25, 2014 14:19
-
-
Save naquad/c5e1196aeb044230ff21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function streaming_data_node_info() | |
{ | |
return array( | |
'frontend' => array( | |
'name' => t('Streaming server'), | |
'base' => 'streaming_data_frontend', | |
'description' => t('A server that will broadcast video stream to users.'), | |
'help' => t('Stream-proxy instance that will request configuration.'), | |
'has_title' => true, | |
'title_label' => t('Name'), | |
'locked' => true | |
), | |
'channel' => array( | |
'name' => t('Channel'), | |
'base' => 'streaming_data_channel', | |
'description' => t('A channel source.'), | |
'help' => t('URL where streaming server should get given channel.'), | |
'has_title' => true, | |
'title_label' => t('Name'), | |
'locked' => true | |
) | |
); | |
} | |
function streaming_data_channel_validate($node, $form, &$form_state) | |
{ | |
if (!empty($form_state['values']['streaming_url']['und'][0]['value']) && | |
!_streaming_data_is_unique('channel', 'streaming_url', $form_state['values']['streaming_url']['und'][0]['value'], $node->nid)) { | |
form_set_error('streaming_url', t('URL already exists.')); | |
} | |
} | |
function streaming_data_frontend_validate($node, $form, &$form_state) | |
{ | |
if (!empty($form_state['values']['streaming_key']['und'][0]['value']) && | |
!_streaming_data_is_unique('frontend', 'streaming_key', $form_state['values']['streaming_key']['und'][0]['value'], $node->nid)) { | |
form_set_error('streaming_key', t('Key already exists.')); | |
} | |
} | |
function streaming_data_channel_form($node, &$form_state) | |
{ | |
return node_content_form($node, $form_state); | |
} | |
function streaming_data_frontend_form($node, &$form_state) | |
{ | |
$form = node_content_form($node, $form_state); | |
//$form['#after_build'][] = 'streaming_data_set_key'; | |
return $form; | |
} | |
function streaming_data_frontend_form_alter($node, &$form_state, $form_id) | |
{ | |
die('IN!!!'); | |
} | |
function _streaming_data_is_unique($type, $field, $value, $except = null) | |
{ | |
module_load_include('inc', 'streaming_data'); | |
$query = streaming_data_query($type); | |
$query->fieldCondition($field, 'value', $value, '='); | |
if ($except) { | |
$query->propertyCondition('nid', $except, '!='); | |
} | |
$query->count(); | |
return $query->execute() == 0; | |
} | |
function streaming_data_set_key($form, &$form_state) | |
{ | |
do { | |
$key = hash('sha256', uniqid() . time()); | |
$exists = db_query('SELECT COUNT(*) FROM {field_data_streaming_key} WHERE streaming_key_value = ?', array($key))->fetchColumn(0); | |
} while($exists); | |
$form['streaming_key']['und'][0]['value']['#value'] = $key; | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment