-
Notifications
You must be signed in to change notification settings - Fork 1
/
telvue.module
246 lines (200 loc) · 7.15 KB
/
telvue.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
/**
* Implements hook_permission().
*/
function telvue_permission() {
$permissions = array(
'administer telvue' => array(
'title' => t('Administer Telvue'),
'description' => t('Allows users to configure Telvue settings.'),
'restrict access' => TRUE,
),
);
return $permissions;
}
/**
* Implements hook_menu().
*/
function telvue_menu() {
// Standard Administration settings.
$items['admin/config/system/telvue'] = array(
'title' => 'Telvue Configuration',
'page callback' => 'drupal_get_form',
'page arguments' => array('telvue_admin_settings'),
'access callback' => 'user_access',
'access arguments' => array('administer telvue'),
'description' => 'Configure system settings for Telvue integration.',
);
return $items;
}
/**
* Builds the admininstration settings form.
*/
function telvue_admin_settings($form, &$form_state) {
$form = array();
if (variable_get('telvue_uri', NULL)) {
$version = telvue_software_version(variable_get('telvue_uri', NULL), variable_get('telvue_api_key', NULL));
if (isset($version['software_version'])) {
drupal_set_message(t('Successfully communicating with the Telvue. Telvue is running version ') . $version['software_version']);
} else {
if ($version['status'] == 'Access Denied') {
drupal_set_message(t('Connected to Telvue, but API key is either not included or not correct. API Key is required for advanced features like Telvue Push.'), 'warning');
} else {
drupal_set_message(t('There is a problem communicating with the server. Please check the URI.'), 'error');
}
}
}
$form['telvue_uri'] = array(
'#type' => 'textfield',
'#title' => t('URI'),
'#size' => 50,
'#maxlength' => 50,
'#default_value' => variable_get('telvue_uri', NULL),
'#description' => t('IP address or URL of the Telvue server including the :3000 (ie. http://b1000.yourdomain.org:3000 or https://172.25.0.xx:3000)'),
);
$form['telvue_connection_error'] = array(
'#type' => 'textarea',
'#title' => t('Connection Error Message'),
'#rows' => 10,
'#cols' => 5,
'#default_value' => variable_get('telvue_connection_error', t('Unable to update')),
'#description' => t('Enter the message users will see in the blocks if Drupal cannot connect to the Telvue API. If left blank, the block will not be displayed.'),
);
$form['telvue_cache'] = array(
'#type' => 'checkbox',
'#title' => t('Cache results from API when possible'),
'#default_value' => variable_get('telvue_cache', 0),
'#description' => t(''),
);
$form['telvue_user'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#size' => 25,
'#maxlength' => 25,
'#default_value' => variable_get('telvue_user', NULL),
'#description' => t('This is a user on the Telvue server with the API option enabled.'),
);
$form['telvue_api_key'] = array(
'#type' => 'textfield',
'#title' => t('API Key'),
'#size' => 25,
'#maxlength' => 25,
'#default_value' => variable_get('telvue_api_key', NULL),
'#description' => t(''),
);
$form['telvue_verbose_logging'] = array(
'#type' => 'checkbox',
'#title' => t('Verbose Logging Mode'),
'#default_value' => variable_get('telvue_verbose_logging', 0),
'#description' => t('This option will add log messages at several points in during the API connections making it easier to diagnose configuration issues.'),
);
$form = system_settings_form($form);
return ($form);
}
function telvue_hms2sec($hms) {
list($h, $m, $s) = explode (":", $hms);
$seconds = 0;
$seconds += (intval($h) * 3600);
$seconds += (intval($m) * 60);
$seconds += (intval($s));
return $seconds;
}
/**
* Implementation of Telvue APIs
* http://www.telvue.com/support/product-documentation/princeton-server-api-docs/content-methods/
*
*/
/**
* Pushes program to Telvue server based on field mapping in custom module
*
*/
function telvue_addprogram($program, $server) {
/*
$rating = $airing_items[$s]['adult'] ? ' (TV-MA) ' : NULL;
$program_code = $airing_items[$s]['nid'];
$program = $airing_items[$s]['title'] . $rating;
$delete_datetime = date('Y-m-d g:i P', time() + (30 * 24 * 60 * 60));
$ingest_datetime = date('Y-m-d g:i P', time());
$expected_duration = $airing_items[$s]['duration'];
$expected_filename = $airing_items[$s]['filename'];
*/
if (!isset($program['delete_datetime'])) {
// if it isn't set, use 30 days
$program['delete_datetime'] = date('Y-m-d g:i P', time() + (30 * 24 * 60 * 60));
}
if (!isset($program['ingest_datetime'])) {
$program['import_datetime'] = date('Y-m-d g:i P', time());
}
if (!$program['expected_filename'] || !$program['expected_duration']) {
return 'Failed';
}
try {
$service = new SoapClient($server . '/program_service/wsdl');
$result = $service->AddProgram(
new SoapVar('<value xsi:nil="true" />', XSD_ANYXML),
$program['program'],
$program['episode'],
$program['episode_code'],
$program['description'],
$program['delete_datetime'],
$program['import_datetime'],
$program['expected_duration'],
$program['expected_filename'],
$program['contributor'],
$program['location'],
$program['username']
);
//http://www.telvue.com/support/product-documentation/princeton-server-api-docs/content-methods/using-soap-and-ruby-to-add-a-tbd-content-record/
//'M8', // program_code
//'Example TBD Program', //program
//'S8', // episode
//'8', // episode_code
//'This is an example TBD added via soap.', // description
//new SoapVar('<value xsi:nil="true" />', XSD_ANYXML), // delete_datetime
//'2008-10-21 14:39:23-04:00', //import_datetime
//80, //expected_duration
//'exampled_tbd.mpg', //expected_filename
//'Poor Steve', //contributor
//'Princeton, NJ', // location
//'psgadmin' // username
if ($result[0] == 'SUCCEEDED') {
$return = t('File successfully transfered');
watchdog('Telvue', 'telvue_addprogram: Succeeded');
}
else {
$return = t('Transfer failed. ') . $result[1];
watchdog('Telvue', 'telvue_addprogram: Failed ' . $result[1]);
}
} // end try
catch (SoapFault $fault) {
trigger_error("The following SOAP Error was generated, SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}// catch
return $return;
}
/**
* Edit Program on Telvue server based on ProgramID for the server
*
*/
function telvue_editprogram($program, $server) {
}
/**
* Deletes Program on Telvue server based on ProgramID for the server
*
*/
function telvue_deleteprogram($programid, $server) {
$username = 'soap'; //@TODO: set to vailable defined in module
$client = new SoapClient($server['ip'] . '/program_service/wsdl');
$soap_result = $client->__soapCall("DeleteProgram", array($program_id, $username));
return $soap_result;
}
/**
* Gets Software Version from Telvue server
*
*/
function telvue_software_version($server, $apikey) {
$url = $server . '/xml/software_version?api_key=' . $apikey;
$response = simplexml_load_file($url);
$json = json_encode($response);
$array = json_decode($json,TRUE);
return $array;
}