youtube.theme.inc
4.36 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
<?php
/**
* @file
* Theme functions for the YouTube field module.
*/
/**
* Theme function for videos.
*/
function theme_youtube_video($variables) {
$id = $variables['video_id'];
// Get field display settings.
$size = $variables['size'];
$width = array_key_exists('width', $variables)? $variables['width'] : NULL;
$height = array_key_exists('height', $variables)? $variables['height'] : NULL;
$autoplay = array_key_exists('autoplay', $variables)? $variables['autoplay'] : FALSE;
$showinfo = array_key_exists('showinfo', $variables)? $variables['showinfo'] : FALSE;
$controls = array_key_exists('controls', $variables)? $variables['controls'] : FALSE;
$autohide = array_key_exists('autohide', $variables)? $variables['autohide'] : FALSE;
$iv_load_policy = array_key_exists('iv_load_policy', $variables)? $variables['iv_load_policy'] : FALSE;
// Get YouTube settings.
$suggest = variable_get('youtube_suggest', TRUE);
$privacy = variable_get('youtube_privacy', FALSE);
$modestbranding = variable_get('youtube_modestbranding', FALSE);
$theme = variable_get('youtube_theme', FALSE);
$color = variable_get('youtube_color', FALSE);
$enablejsapi = variable_get('youtube_enablejsapi', FALSE);
$player_class = variable_get('youtube_player_class', 'youtube-field-player');
$wmode = variable_get('youtube_wmode', TRUE);
$privacy = variable_get('youtube_privacy', FALSE);
$dimensions = youtube_get_dimensions($size, $width, $height);
// Query string changes based on setings.
$query = array();
if (!$suggest) {
$query['rel'] = '0';
}
if ($modestbranding) {
$query['modestbranding'] = '1';
}
if ($theme) {
$query['theme'] = 'light';
}
if ($color) {
$query['color'] = 'white';
}
if ($enablejsapi) {
global $base_url;
$query['enablejsapi'] = '1';
$query['origin'] = $base_url;
}
if ($wmode) {
$query['wmode'] = 'opaque';
}
if ($autoplay) {
$query['autoplay'] = '1';
}
if ($showinfo) {
$query['showinfo'] = '0';
}
if ($controls) {
$query['controls'] = '0';
}
if ($autohide) {
$query['autohide'] = '1';
}
if ($iv_load_policy) {
$query['iv_load_policy'] = '3';
}
// Domain changes based on settings.
$domain = ($privacy) ? 'youtube-nocookie.com' : 'youtube.com';
$path = 'https://www.' . $domain . '/embed/' . $id;
$src = url($path, array('query' => $query));
$player_title = t('Embedded video for @entity_title', array(
'@entity_title' => $variables['entity_title'],
));
$output = '<iframe id="' . drupal_html_id($player_class) . '" class="' . $player_class . '"
width="' . $dimensions['width'] . '" height="' . $dimensions['height'] . '"
src="' . $src . '" title="' . $player_title . '" frameborder="0"
allowfullscreen></iframe>';
if ($size == 'responsive') {
$output = '<div class="youtube-container--responsive">' . $output . '</div>';
}
return $output;
}
/**
* Theme function for thumbnails.
*/
function theme_youtube_thumbnail($variables) {
$id = $variables['video_id'];
$style = $variables['image_style'];
// Get YouTube settings - TODO is this needed?
$size = variable_get('youtube_size', '420x315');
$dimensions = youtube_get_dimensions($size);
$files = variable_get('file_public_path', conf_path() . '/files');
$youtube = variable_get('youtube_thumb_dir', 'youtube');
$dest = $files . '/' . $youtube . '/' . $id . '.png';
// Check to see if a thumbnail exists locally.
if (!file_exists($dest)) {
// Retrieve the image from YouTube.
if (!youtube_get_remote_image($id)) {
// Use the remote source if local copy fails.
$src = youtube_build_remote_image_path($id);
return theme('image', array('path' => $src));
}
}
$alt = t('Embedded thumbnail for @entity_title', array(
'@entity_title' => $variables['entity_title'],
));
if ($style) {
$uri = 'public://' . $youtube . '/' . $id . '.png';
$image = theme('image_style', array(
'style_name' => $style,
'path' => $uri,
'alt' => $alt,
));
}
else {
$path = $files . '/' . $youtube . '/' . $id . '.png';
$image = theme('image', array('path' => $path, 'alt' => $alt));
}
// Check if an url path is provided
if ($variables['image_link'] != NULL) {
$url_path = $variables['image_link']['path'];
$options = $variables['image_link']['options'];
$image = l($image, $url_path, $options);
}
return $image;
}