-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_video_embed.module
103 lines (88 loc) · 3.1 KB
/
islandora_video_embed.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
<?php
/**
* @file
* Main hooks for Islandora Video Embed.
*/
/**
* Implements hook_menu().
*/
function islandora_video_embed_menu() {
return array(
'admin/islandora/tools/video_embed' => array(
'title' => 'Islandora Video Embed',
'description' => 'Configure Islandora Video Embed settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_video_embed_admin_form'),
'access arguments' => array('administer site configuration'),
),
);
}
/**
* Generates admin form.
*/
function islandora_video_embed_admin_form($form, $form_settings) {
$form['islandora_video_embed_linktext'] = array(
'#type' => 'textfield',
'#title' => t('Link text for embed block'),
'#description' => t('The clickable text that appears in the block.'),
'#default_value' => variable_get('islandora_video_embed_linktext', 'Video embed code'),
);
return system_settings_form($form);
}
/**
* Implements hook_block_info().
*
* Creates blocks.
*/
function islandora_video_embed_block_info() {
return array(
'video_embed_object' => array(
'visibility' => BLOCK_VISIBILITY_LISTED,
'pages' => 'islandora/object/*',
'info' => t('Video embed code'),
),
);
}
/**
* Implements hook_block_view().
*/
function islandora_video_embed_block_view($delta) {
$to_render = array();
drupal_add_js('misc/collapse.js');
drupal_add_js('misc/form.js');
$object = menu_get_object('islandora_object', 2);
// Only display the block on Video and Audio objects.
if (!in_array("islandora:sp_videoCModel", $object->models) && !in_array("islandora:sp-audioCModel", $object->models)) {
return;
}
global $base_url;
$pid = $object->id;
$embed_code = "";
$collapsed = 'collapsed';
if (in_array("islandora:sp_videoCModel", $object->models)) {
$dsid = "MP4";
$width = "320";
$height = "240";
$legend = variable_get('islandora_video_embed_linktext', 'Video embed code');
$video_url = $base_url . '/islandora/object/' . $pid . '/datastream/' . $dsid . '/download/file.mp4';
$embed_code = '<p><i>Copy the HTML below and paste it where you wish to embed the video.</i></p>
<video width="' . $width . '" height="' . $height . '" controls> <br/>
<source src="' . $video_url . '" type="video/mp4"> <br/>
</video>';
}
elseif (in_array("islandora:sp-audioCModel", $object->models)) {
$dsid = "PROXY_MP3";
$legend = variable_get('islandora_video_embed_linktext', 'Audio embed code');
$audio_url = $base_url . '/islandora/object/' . $pid . '/datastream/' . $dsid . '/download/file.mp3';
$embed_code = '<p><i>Copy the HTML below and paste it where you wish to embed the audio.</i></p>
<audio controls> <br/>
<source src="' . $audio_url . '" type="audio/mpeg"> <br/>
</audio>';
}
$embed_code =
'<fieldset class="islandora collapsible ' . $collapsed . '">' .
'<legend><span class="fieldset-legend">' . $legend . '</span></legend><div class="fieldset-wrapper">' .
$embed_code . '</div></fieldset>';
$to_render['content'] = $embed_code;
return $to_render;
}