Révision 18596a08
Ajouté par Assos Assos il y a presque 7 ans
drupal7/sites/all/modules/media_youtube/themes/media_youtube.theme.inc | ||
---|---|---|
13 | 13 |
// Build the URI. |
14 | 14 |
$wrapper = file_stream_wrapper_get_instance_by_uri($variables['uri']); |
15 | 15 |
$parts = $wrapper->get_parameters(); |
16 |
$variables['video_id'] = check_plain($parts['v']); |
|
16 |
if (isset($parts['v'])) { |
|
17 |
$variables['embed_type'] = 'video'; |
|
18 |
$variables['video_id'] = check_plain($parts['v']); |
|
19 |
$embed_path = '/embed/' . $variables['video_id']; |
|
20 |
} |
|
21 |
elseif (isset($parts['l'])) { |
|
22 |
$variables['embed_type'] = 'playlist'; |
|
23 |
$variables['video_id'] = check_plain($parts['l']); |
|
24 |
$embed_path = '/embed/videoseries'; |
|
25 |
} |
|
17 | 26 |
|
18 |
// Make the file object available. |
|
19 |
$file_object = file_uri_to_object($variables['uri']); |
|
27 |
// Checked existing function. |
|
28 |
if(function_exists('file_uri_to_object')) { |
|
29 |
// Make the file object available. |
|
30 |
$file_object = file_uri_to_object($variables['uri']); |
|
31 |
} |
|
32 |
else { |
|
33 |
$file_object = media_youtube_file_uri_to_object($variables['uri']); |
|
34 |
} |
|
20 | 35 |
|
21 | 36 |
// Parse options and build the query string. Only add the option to the query |
22 | 37 |
// array if the option value is not default. Be careful, depending on the |
... | ... | |
85 | 100 |
} |
86 | 101 |
} |
87 | 102 |
|
88 |
// Non-query options. |
|
89 |
if ($variables['options']['nocookie']) { |
|
90 |
$url_base = 'youtube-nocookie.com'; |
|
103 |
if ($variables['options']['protocol_specify']) { |
|
104 |
$protocol = $variables['options']['protocol']; |
|
91 | 105 |
} |
92 | 106 |
else { |
93 |
$url_base = 'youtube.com';
|
|
107 |
$protocol = 'https:';
|
|
94 | 108 |
} |
95 | 109 |
|
96 |
if ($variables['options']['protocol_specify']) { |
|
97 |
$protocol = $variables['options']['protocol']; |
|
110 |
// Non-query options. |
|
111 |
if ($variables['options']['nocookie']) { |
|
112 |
$url_base = 'youtube-nocookie.com'; |
|
98 | 113 |
} |
99 | 114 |
else { |
100 |
$protocol = '';
|
|
115 |
$url_base = 'youtube.com';
|
|
101 | 116 |
} |
102 | 117 |
|
103 | 118 |
// Add some options as their own template variables. |
... | ... | |
123 | 138 |
// to use for the alternative content. |
124 | 139 |
$variables['alternative_content'] = t('Video of @title', array('@title' => $variables['title'])); |
125 | 140 |
|
141 |
if (isset($parts['l'])) { |
|
142 |
$query['list'] = $parts['l']; |
|
143 |
} |
|
126 | 144 |
// 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)); |
|
145 |
$variables['url'] = url($protocol . '//www.' . $url_base . $embed_path, array('query' => $query, 'external' => TRUE)); |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Helping function. |
|
150 |
*/ |
|
151 |
function media_youtube_file_uri_to_object($uri) { |
|
152 |
$uri = file_stream_wrapper_uri_normalize($uri); |
|
153 |
$files = entity_load('file', FALSE, array('uri' => $uri)); |
|
154 |
$file = !empty($files) ? reset($files) : FALSE; |
|
155 |
if (!$file) { |
|
156 |
global $user; |
|
157 |
$file = new stdClass(); |
|
158 |
$file->uid = $user->uid; |
|
159 |
$file->filename = basename($uri); |
|
160 |
$file->uri = $uri; |
|
161 |
$file->filemime = file_get_mimetype($uri); |
|
162 |
// This is gagged because some uris will not support it. |
|
163 |
$file->filesize = @filesize($uri); |
|
164 |
$file->timestamp = REQUEST_TIME; |
|
165 |
$file->status = FILE_STATUS_PERMANENT; |
|
166 |
} |
|
167 |
return $file; |
|
128 | 168 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules