1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file media_youtube/themes/media_youtube.theme.inc
|
5 |
|
|
*
|
6 |
|
|
* Theme and preprocess functions for Media: YouTube.
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* Preprocess function for theme('media_youtube_video').
|
11 |
|
|
*/
|
12 |
|
|
function media_youtube_preprocess_media_youtube_video(&$variables) {
|
13 |
|
|
// Build the URI.
|
14 |
|
|
$wrapper = file_stream_wrapper_get_instance_by_uri($variables['uri']);
|
15 |
|
|
$parts = $wrapper->get_parameters();
|
16 |
|
|
$variables['video_id'] = check_plain($parts['v']);
|
17 |
|
|
|
18 |
|
|
// Make the file object available.
|
19 |
|
|
$file_object = file_uri_to_object($variables['uri']);
|
20 |
|
|
|
21 |
|
|
// Parse options and build the query string. Only add the option to the query
|
22 |
|
|
// array if the option value is not default. Be careful, depending on the
|
23 |
|
|
// wording in media_youtube.formatters.inc, TRUE may be query=0.
|
24 |
|
|
// @see https://developers.google.com/youtube/player_parameters#Parameters
|
25 |
|
|
$query = array();
|
26 |
|
|
|
27 |
|
|
// Make css z-index work with flash object. Must be the first parameter.
|
28 |
|
|
$query['wmode'] = 'opaque';
|
29 |
|
|
|
30 |
|
|
// These queries default to 0. If the option is true, set value to 1.
|
31 |
|
|
foreach (array('autoplay', 'enablejsapi', 'loop', 'modestbranding') as $option) {
|
32 |
|
|
if ($variables['options'][$option]) {
|
33 |
|
|
$query[$option] = 1;
|
34 |
|
|
}
|
35 |
|
|
}
|
36 |
|
|
if ($variables['options']['enablejsapi']) {
|
37 |
|
|
// Add a query ID and identical html ID if js API is set.
|
38 |
|
|
$query['playerapiid'] = drupal_html_id('media-youtube-' . $variables['video_id']);
|
39 |
|
|
$variables['api_id_attribute'] = 'id="' . $query['playerapiid'] . '" ';
|
40 |
|
|
|
41 |
70a4c29b
|
Assos Assos
|
// Add the origin for improved security
|
42 |
85ad3d82
|
Assos Assos
|
$variables['options']['origin'] ? $query['origin'] = $variables['options']['origin'] : '';
|
43 |
|
|
}
|
44 |
|
|
else {
|
45 |
|
|
$variables['api_id_attribute'] = NULL;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
// Currently, loop only works with a playlist. Make fake playlist out of a
|
49 |
|
|
// single video.
|
50 |
|
|
// @see https://developers.google.com/youtube/player_parameters#loop
|
51 |
|
|
if ($variables['options']['loop']) {
|
52 |
|
|
$query['playlist'] = $variables['video_id'];
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
// These queries default to 1. If the option is false, set value to 0.
|
56 |
|
|
foreach (array('rel', 'showinfo') as $option) {
|
57 |
|
|
if (!$variables['options'][$option]) {
|
58 |
|
|
$query[$option] = 0;
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
// These queries default to 1. Option wording is reversed, so if the option
|
63 |
|
|
// is true, set value to 0.
|
64 |
|
|
// (None right now.)
|
65 |
|
|
|
66 |
|
|
// Strings.
|
67 |
|
|
if ($variables['options']['theme'] != 'dark') {
|
68 |
|
|
$query['theme'] = $variables['options']['theme'];
|
69 |
|
|
}
|
70 |
|
|
if ($variables['options']['color'] != 'red') {
|
71 |
|
|
$query['color'] = $variables['options']['color'];
|
72 |
|
|
}
|
73 |
|
|
if ($variables['options']['autohide'] != '2') {
|
74 |
|
|
$query['autohide'] = $variables['options']['autohide'];
|
75 |
|
|
}
|
76 |
70a4c29b
|
Assos Assos
|
if ($variables['options']['captions'] > '0') {
|
77 |
|
|
// Add captions parameters to the query.
|
78 |
|
|
$query['cc_load_policy'] = '1';
|
79 |
|
|
if ($variables['options']['captions'] > '1') {
|
80 |
|
|
global $language;
|
81 |
|
|
// We can specify a default language for captions.
|
82 |
|
|
if ($language->language != LANGUAGE_NONE) {
|
83 |
|
|
$query['cc_lang_pref'] = $language->language;
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
85ad3d82
|
Assos Assos
|
|
88 |
|
|
// Non-query options.
|
89 |
|
|
if ($variables['options']['nocookie']) {
|
90 |
|
|
$url_base = 'youtube-nocookie.com';
|
91 |
|
|
}
|
92 |
|
|
else {
|
93 |
|
|
$url_base = 'youtube.com';
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
if ($variables['options']['protocol_specify']) {
|
97 |
|
|
$protocol = $variables['options']['protocol'];
|
98 |
|
|
}
|
99 |
|
|
else {
|
100 |
|
|
$protocol = '';
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
// Add some options as their own template variables.
|
104 |
|
|
foreach (array('width', 'height') as $theme_var) {
|
105 |
|
|
$variables[$theme_var] = $variables['options'][$theme_var];
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
// Do something useful with the overridden attributes from the file
|
109 |
|
|
// object. We ignore alt and style for now.
|
110 |
|
|
if (isset($variables['options']['attributes']['class'])) {
|
111 |
|
|
if (is_array($variables['options']['attributes']['class'])) {
|
112 |
|
|
$variables['classes_array'] = array_merge($variables['classes_array'], $variables['options']['attributes']['class']);
|
113 |
|
|
}
|
114 |
|
|
else {
|
115 |
|
|
// Provide nominal support for Media 1.x.
|
116 |
|
|
$variables['classes_array'][] = $variables['options']['attributes']['class'];
|
117 |
|
|
}
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
// Add template variables for accessibility.
|
121 |
|
|
$variables['title'] = check_plain($file_object->filename);
|
122 |
|
|
// @TODO: Find an easy/ not too expensive way to get the YouTube description
|
123 |
|
|
// to use for the alternative content.
|
124 |
|
|
$variables['alternative_content'] = t('Video of @title', array('@title' => $variables['title']));
|
125 |
|
|
|
126 |
|
|
// Build the iframe URL with options query string.
|
127 |
|
|
$variables['url'] = url($protocol . '//www.' . $url_base . '/embed/' . $variables['video_id'], array('query' => $query, 'external' => TRUE));
|
128 |
|
|
} |