Projet

Général

Profil

Paste
Télécharger (4,05 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / media_youtube / themes / media_youtube.theme.inc @ dd54aff9

1
<?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

    
14
  // Build the URI.
15
  $wrapper = file_stream_wrapper_get_instance_by_uri($variables['uri']);
16
  $parts = $wrapper->get_parameters();
17
  $variables['video_id'] = check_plain($parts['v']);
18

    
19
  // Make the file object available.
20
  $file_object = file_uri_to_object($variables['uri']);
21

    
22
  // Parse options and build the query string. Only add the option to the query
23
  // array if the option value is not default. Be careful, depending on the
24
  // wording in media_youtube.formatters.inc, TRUE may be query=0.
25
  // @see https://developers.google.com/youtube/player_parameters#Parameters
26
  $query = array();
27

    
28
  // Make css z-index work with flash object. Must be the first parameter.
29
  $query['wmode'] = 'opaque';
30

    
31
  // These queries default to 0. If the option is true, set value to 1.
32
  foreach (array('autoplay', 'enablejsapi', 'loop', 'modestbranding') as $option) {
33
    if ($variables['options'][$option]) {
34
      $query[$option] = 1;
35
    }
36
  }
37
  if ($variables['options']['enablejsapi']) {
38
    // Add a query ID and identical html ID if js API is set.
39
    $query['playerapiid'] = drupal_html_id('media-youtube-' . $variables['video_id']);
40
    $variables['api_id_attribute'] = 'id="' . $query['playerapiid'] . '" ';
41

    
42
    //Add the origin for improved security
43
    $variables['options']['origin'] ? $query['origin'] = $variables['options']['origin'] : '';
44
  }
45
  else {
46
    $variables['api_id_attribute'] = NULL;
47
  }
48

    
49
  // Currently, loop only works with a playlist. Make fake playlist out of a
50
  // single video.
51
  // @see https://developers.google.com/youtube/player_parameters#loop
52
  if ($variables['options']['loop']) {
53
    $query['playlist'] = $variables['video_id'];
54
  }
55

    
56
  // These queries default to 1. If the option is false, set value to 0.
57
  foreach (array('rel', 'showinfo') as $option) {
58
    if (!$variables['options'][$option]) {
59
      $query[$option] = 0;
60
    }
61
  }
62

    
63
  // These queries default to 1. Option wording is reversed, so if the option
64
  // is true, set value to 0.
65
  // (None right now.)
66

    
67
  // Strings.
68
  if ($variables['options']['theme'] != 'dark') {
69
    $query['theme'] = $variables['options']['theme'];
70
  }
71
  if ($variables['options']['color'] != 'red') {
72
    $query['color'] = $variables['options']['color'];
73
  }
74
  if ($variables['options']['autohide'] != '2') {
75
    $query['autohide'] = $variables['options']['autohide'];
76
  }
77

    
78
  // Non-query options.
79
  if ($variables['options']['nocookie']) {
80
    $url_base = 'youtube-nocookie.com';
81
  }
82
  else {
83
    $url_base = 'youtube.com';
84
  }
85

    
86
  if ($variables['options']['protocol_specify']) {
87
    $protocol = $variables['options']['protocol'];
88
  }
89
  else {
90
    $protocol = '';
91
  }
92

    
93
  // Add some options as their own template variables.
94
  foreach (array('width', 'height') as $theme_var) {
95
    $variables[$theme_var] = $variables['options'][$theme_var];
96
  }
97

    
98
  // Do something useful with the overridden attributes from the file
99
  // object. We ignore alt and style for now.
100
  if (isset($variables['options']['attributes']['class'])) {
101
    if (is_array($variables['options']['attributes']['class'])) {
102
      $variables['classes_array'] = array_merge($variables['classes_array'], $variables['options']['attributes']['class']);
103
    }
104
    else {
105
      // Provide nominal support for Media 1.x.
106
      $variables['classes_array'][] = $variables['options']['attributes']['class'];
107
    }
108
  }
109

    
110
  // Add template variables for accessibility.
111
  $variables['title'] = check_plain($file_object->filename);
112
  // @TODO: Find an easy/ not too expensive way to get the YouTube description
113
  // to use for the alternative content.
114
  $variables['alternative_content'] = t('Video of @title', array('@title' => $variables['title']));
115

    
116
  // Build the iframe URL with options query string.
117
  $variables['url'] = url($protocol . '//www.' . $url_base . '/embed/' . $variables['video_id'], array('query' => $query, 'external' => TRUE));
118
}