-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathding_arbo.module
More file actions
executable file
·352 lines (307 loc) · 10.4 KB
/
ding_arbo.module
File metadata and controls
executable file
·352 lines (307 loc) · 10.4 KB
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
/**
* @file
*
* Main ARBO module file.
*/
define('FLV_ADDR', 'http://localhost/index.php?file=');
define('RESPONDER_ADDR', 'http://localhost/index.php');
define('ARBO_PATH', drupal_get_path('module', 'ding_arbo'));
define('TING_PATH', drupal_get_path('module', 'ting'));
/**
* Implements hook_init().
*/
function ding_arbo_init() {
drupal_add_library('system', 'drupal.ajax');
drupal_add_library('system', 'jquery.form');
drupal_add_js(ARBO_PATH . '/js/arbo.js');
drupal_add_js(ARBO_PATH . '/js/flowplayer-3.2.6.min.js');
drupal_add_js(ARBO_PATH . '/js/tiny_carousel.js');
drupal_add_css(ARBO_PATH . '/css/arbo-widget.css');
drupal_add_css(ARBO_PATH . '/css/arbo-carousel.css');
}
/**
* Implements hook_menu().
*/
function ding_arbo_menu() {
$items = array();
$items['admin/config/ding/arbo'] = array(
'title' => 'ARBO config',
'description' => 'Configuration page for ARBO module',
'page callback' => 'drupal_get_form',
'page arguments' => array('ding_arbo_config_form'),
'access arguments' => array('access adminitration pages'),
);
$items['arbo/call'] = array(
'title' => 'ARBO YT responder',
'description' => 'Retrieves the uploaded video review ID generated by YT',
'page callback' => 'arbo_responder',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'ding_arbo.ajax.inc',
);
$items['arbo/ajax/widget/%'] = array(
'title' => 'ARBO widget',
'description' => 'Display ARBO widget through ajax call in a popup overlay.',
'page arguments' => array(1, 3),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'page callback' => 'ding_arbo_widget_display',
);
$items['arbo/ajax/carousel/youtube/%'] = array(
'title' => 'ARBO review popup',
'description' => 'Display ARBO overlay for existing video reviews.',
'page arguments' => array(1, 4),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'page callback' => 'ding_arbo_carousel_youtube',
);
return $items;
}
/**
* Display a YT stored video review in a popup
*
* @param $type
* Type of request
* @param $video_link
* YouTube video link
*/
function ding_arbo_carousel_youtube($type = 'ajax', $video = '') {
if ($type == 'ajax') {
if ($video != '') {
$commands = array();
$video_id = $video;
$commands[] = ajax_command_ding_popup(
'yt_overlay',
t('Video review'),
'<object width="480" height="390"><param name="movie" value="http://www.youtube.com/v/' . $video_id . '?fs=1&hl=en_US&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $video_id . '?fs=1&hl=en_US&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="390"></embed></object>'
);
$result = array('#type' => 'ajax', '#commands' => $commands);
ajax_deliver($result);
}
}
}
/**
* Handles ARBO widget display.
*
* @param $type
* Type of request
* @param $faust_number
* Item faust number
*/
function ding_arbo_widget_display($type = 'ajax', $ting_id) {
if ($type == 'ajax') {
require_once DRUPAL_ROOT . '/' . TING_PATH . '/ting.client.inc';
$t = explode(':', $ting_id);
$faust_number = $t[1];
// Include needed classes
require_once DRUPAL_ROOT . '/' . ARBO_PATH . '/lib/VoxbVideoReviews.class.php';
require_once DRUPAL_ROOT . '/' . VOXB_PATH . '/lib/VoxbItem.class.php';
require_once DRUPAL_ROOT . '/' . VOXB_PATH . '/lib/VoxbProfile.class.php';
$item = new VoxbItem();
$item->fetchByFaust($faust_number);
$profile = new VoxbProfile();
$profile->setUserId($_SESSION['voxb']['userId']);
$video_filename = md5(REQUEST_TIME);
$commands = array();
$commands[] = ajax_command_ding_popup(
'arbo_widget',
t('ARBO Widget'),
theme('arbo_widget', array(
'voxb_item' => $item,
'profile' => $profile,
'faust_number' => $faust_number,
'video_filename' => $video_filename,
'ting_id' => $ting_id))
);
$commands[] = ding_arbo_widget_init($video_filename);
$result = array('#type' => 'ajax', '#commands' => $commands);
// Show the widget
ajax_deliver($result);
}
}
/**
* Initializes the Arbo widget with needed data
*
* @param $video_filename
* Video file name hash delivered to template
* @return
* An array of Drupal ajax calls with additional parameters
*/
function ding_arbo_widget_init($video_filename) {
return array(
'command' => 'ding_arbo_widget_init',
'arbo_path' => ARBO_PATH,
'movie_name' => $video_filename,
'app_name' => 'ARBO',
'stream_path' => variable_get('ding_arbo_flv_server_addr', FLV_ADDR),
);
}
/**
* Implements hook_theme().
*/
function ding_arbo_theme() {
$hooks['arbo'] = array(
'variables' => array('object' => NULL),
'template' => 'ding_arbo',
);
$hooks['arbo_widget'] = array(
'variables' => array('voxb_item' => NULL, 'profile' => NULL, 'faust_number' => NULL, 'video_filename' => NULL),
'template' => 'ding_arbo-widget',
);
return $hooks;
}
/**
* Implements hook_help().
*/
function ding_arbo_help($path, $arg) {
if ($path == 'admin/help#arbo') {
return t('ARBO module provides an interface that allow users to watch and post video reviews.');
}
}
/**
* Arbo module config form.
*
* @param $form
* Processed form fields and their data
* @param $form_state
* Form state
* @return
* An array representing the form structure
*/
function ding_arbo_config_form($form, $form_state) {
$form['ding_arbo_flv_server_addr'] = array(
'#type' => 'textfield',
'#default_value' => variable_get('ding_arbo_flv_server_addr', FLV_ADDR),
'#title' => t('FLV address'),
'#description' => t('Server address where FLV\'s can be accessed., e.g. http://79.125.6.101/arbo-youtube/streamer.php?file='),
'#size' => 40,
'#maxlength' => '256',
'#required' => TRUE,
);
$form['ding_arbo_responder_server_addr'] = array(
'#type' => 'textfield',
'#default_value' => variable_get('ding_arbo_responder_server_addr', RESPONDER_ADDR),
'#title' => t('Upload responder'),
'#description' => t('Server address which replies a newly uploaded video YouTube unique ID, e.g. http://79.125.6.101/arbo-youtube/index.php'),
'#size' => 40,
'#maxlength' => '256',
'#required' => TRUE,
);
return system_settings_form($form);
}
/**
* The video reviews form, to store review data.
*
* @param $form
* Processed form fields and their data
* @param $form_state
* Form state
* @param $faust
* Item faust number
* @param $movie_name
* Video file name hash
* @return
* An array representing the form structure
*/
function ding_arbo_review_form($form, &$form_state, $faust, $movie_name, $ting_id) {
$form['terms'] = array(
'#type' => 'textarea',
'#attributes' => array(
'readonly' => TRUE,
),
);
$form['accept'] = array(
'#type' => 'checkbox',
'#title' => t('I hereby accept the terms'),
);
$form['object_faust'] = array(
'#type' => 'hidden',
'#value' => $faust,
);
$form['object_ting_id'] = array(
'#type' => 'hidden',
'#value' => $ting_id,
);
$form['review_email'] = array(
'#type' => 'hidden',
);
$form['movie_name'] = array(
'#type' => 'hidden',
'#value' => $movie_name,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
'#ajax' => array(
'callback' => 'ding_arbo_review_form_callback'
),
'#attributes' => array(
'class' => array('rounded-corners')
)
);
return $form;
}
/**
* Callback function for processing video reviews,
* stores data in hidden fields and sends them to red5 for further processing.
*
* @param $form
* Processed form fields and their data
* @param $form_state
* Form state
* @return
* An array of Drupal ajax calls with additional parameters
*/
function ding_arbo_review_form_callback($form, &$form_state) {
$commands = array();
if ($form['accept']['#value'] == 1) {
require_once DRUPAL_ROOT . '/' . TING_PATH . '/ting.client.inc';
$object = ting_object_load($form['object_ting_id']['#value']);
$movie_title = $object->title . ' [anmeldelse]';
$movie_description = t('Review by') . ' ' . $object->title . '. Beskrivelse af materialet: ' . $object->abstract;
$movie_tags = 'EasyTown, ' . $object->title . ', inlead, artesis';
$movie_name = $form['movie_name']['#value'] . '.flv';
$object_id = $object->ding_entity_id;
$status = file_get_contents(
variable_get('ding_arbo_responder_server_addr', RESPONDER_ADDR) .
'?movie_name=' . urlencode($movie_name) .
'&review_title=' . urlencode($movie_title) .
'&review_description=' . urlencode($movie_description) .
'&review_tags=' . urlencode($movie_tags) .
'&user_email=' . urlencode($form['review_email']['#value']) .
'&faust_number=' . urlencode($form['object_faust']['#value']) .
'&user_id=' . urlencode($_SESSION['voxb']['userId']) .
'&ding_id=' . urlencode($object_id));
$commands[] = ajax_command_ding_popup_close('arbo_widget');
if ($status == '0x01') {
$commands[] = ajax_command_ding_popup(
'arbo_notice',
t('ARBO widget'),
'<p style="text-align: center;">' . t('Thank you for your review!') . '</p><p style="text-align: center;"><img src="/' . ARBO_PATH . '/img/accept.png" width="128" height="128" alt="" /></p>');
$commands[] = ajax_command_invoke('.reviewsContainer', 'hide', array());
$commands[] = ajax_command_invoke('.addVideoReviewContainer', 'hide', array());
}
else {
$commands[] = ajax_command_ding_popup(
'arbo_notice',
t('ARBO widget'),
'<p style="text-align: center;">' . t('An unexpected error occured, try again later.') . '</p><p style="text-align: center;"><img src="/' . ARBO_PATH . '/img/repeat-128.png" width="128" height="128" alt="" /></p>');
}
}
else {
$commands[] = ajax_command_ding_popup(
'review_error',
t('Error'),
'<p>' . t('You should accept the terms of agreement.') . '</p>');
}
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* Implements MODULE_ctools_plugin_directory().
*/
function ding_arbo_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools') {
return 'plugins/' . $plugin;
}
}