diff --git a/README.txt b/README.txt index 803902c..bd505ee 100644 --- a/README.txt +++ b/README.txt @@ -5,7 +5,7 @@ YouTube video to a content type, user, or any entity. Display types include: - * YouTube videos of various sizes. + * YouTube videos of various sizes and options. * YouTube thumbnails with image styles. @@ -34,12 +34,15 @@ additional parameters after the URL will be ignored. CONFIGURATION -------------- -A YouTube field can be output as a video of at one of four standard sizes, or at -a custom size, with the ability to auto-play if necessary. The thumbnail of the -YouTube image can also be used and it can be linked to the full entity or the -video on YouTube. +Global module settings can be found at admin/config/media/youtube. -General and default settings can be configured at admin/config/media/youtube +The video output of a YouTube field can be manipulated in three ways: + * global parameters found on the configuration page mentioned above + * field-specific parameters found in that particular field's display settings + * Views settings for the specific field + +The thumbnail of the YouTube image can also be used and can link to either the +content, the video on YouTube, or nothing at all. To configure the field settings: diff --git a/youtube.install b/youtube.install index 079b3e2..ec1f2eb 100644 --- a/youtube.install +++ b/youtube.install @@ -35,6 +35,11 @@ function youtube_field_schema($field) { function youtube_uninstall() { // Delete youtube variables when module is removed. variable_del('youtube_suggest'); + variable_del('youtube_modestbranding'); + variable_del('youtube_theme'); + variable_del('youtube_color'); + variable_del('youtube_enablejsapi'); + variable_del('youtube_playerid'); variable_del('youtube_privacy'); variable_del('youtube_thumb_dir'); variable_del('youtube_wmode'); diff --git a/youtube.module b/youtube.module index 55c73b0..17e8ec3 100644 --- a/youtube.module +++ b/youtube.module @@ -42,25 +42,61 @@ function youtube_settings_form($form) { $form['text'] = array( '#type' => 'markup', '#markup' => '

' . t('The following settings will be used as default values - on all YouTube video fields. Many of these settings can be overridden - on a per-field basis.') . '

', + on all YouTube video fields. More settings can be altered in the display + settings of individual fields.') . '

', ); - $form['youtube_privacy'] = array( + $form['youtube_global'] = array( + '#type' => 'fieldset', + '#title' => 'Video Parameters', + ); + $form['youtube_global']['youtube_suggest'] = array( '#type' => 'checkbox', - '#title' => t('Enable privacy-enhanced mode'), - '#default_value' => variable_get('youtube_privacy', FALSE), - '#description' => t('Checking this box will prevent YouTube from setting cookies in your site visitors browser.'), + '#title' => t('Show suggested videos when the video finishes (rel).'), + '#default_value' => variable_get('youtube_suggest', TRUE), + ); + $form['youtube_global']['youtube_modestbranding'] = array( + '#type' => 'checkbox', + '#title' => t('Do not show YouTube logo on video player (modestbranding).'), + '#default_value' => variable_get('youtube_modestbranding', FALSE), + ); + $form['youtube_global']['youtube_theme'] = array( + '#type' => 'checkbox', + '#title' => t('Use a light colored control bar for video player controls (theme).'), + '#default_value' => variable_get('youtube_theme', FALSE), + ); + $form['youtube_global']['youtube_color'] = array( + '#type' => 'checkbox', + '#title' => t('Use a white colored video progress bar (color).'), + '#default_value' => variable_get('youtube_color', FALSE), + '#description' => 'Note: the modestbranding parameter will be ignored when this is in use.', + ); + $form['youtube_global']['youtube_enablejsapi'] = array( + '#type' => 'checkbox', + '#title' => t('Enable use of the JavaScript API (enablejsapi, origin).'), + '#default_value' => variable_get('youtube_enablejsapi', FALSE), + '#description' => 'For more information on the Javascript API and how to use it, see the JavaScript API documentation.', + ); + $form['youtube_global']['youtube_playerid'] = array( + '#type' => 'textfield', + '#title' => t('Javascript API Player ID'), + '#default_value' => variable_get('youtube_playerid', 'youtube-field-player'), + '#states' => array( + 'visible' => array( + ':input[name="youtube_enablejsapi"]' => array('checked' => TRUE), + ), + ), ); - $form['youtube_wmode'] = array( + $form['youtube_global']['youtube_wmode'] = array( '#type' => 'checkbox', - '#title' => t('Fix overlay problem in IE'), + '#title' => t('Fix overlay problem in IE (wmode).'), '#default_value' => variable_get('youtube_wmode', TRUE), '#description' => t('Checking this will fix the issue of a YouTube video showing above elements with fixed or absolute positioning (including Drupal\'s Overlay and Toolbar).'), ); - $form['youtube_suggest'] = array( + $form['youtube_privacy'] = array( '#type' => 'checkbox', - '#title' => t('Show suggested videos when the video finishes'), - '#default_value' => variable_get('youtube_suggest', TRUE), + '#title' => t('Enable privacy-enhanced mode.'), + '#default_value' => variable_get('youtube_privacy', FALSE), + '#description' => t('Checking this box will prevent YouTube from setting cookies in your site visitors browser.'), ); $form['youtube_thumb_dir'] = array( '#type' => 'textfield', @@ -129,6 +165,10 @@ function youtube_field_formatter_info() { 'youtube_width' => NULL, 'youtube_height' => NULL, 'youtube_autoplay' => FALSE, + 'youtube_showinfo' => FALSE, + 'youtube_controls' => FALSE, + 'youtube_autohide' => FALSE, + 'youtube_iv_load_policy' => FALSE, ), ), // This formatter just displays a thumbnail for your video. @@ -151,6 +191,13 @@ function youtube_field_formatter_info() { function youtube_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { $display = $instance['display'][$view_mode]; $settings = $display['settings']; + $parameters = array( + $settings['youtube_autoplay'], + $settings['youtube_showinfo'], + $settings['youtube_controls'], + $settings['youtube_autohide'], + $settings['youtube_iv_load_policy'], + ); if ($display['type'] == 'youtube_video') { $element['youtube_size'] = array( @@ -183,9 +230,29 @@ function youtube_field_formatter_settings_form($field, $instance, $view_mode, $f ); $element['youtube_autoplay'] = array( '#type' => 'checkbox', - '#title' => t('Play video automatically when loaded (Autoplay).'), + '#title' => t('Play video automatically when loaded (autoplay).'), '#default_value' => $settings['youtube_autoplay'], ); + $element['youtube_showinfo'] = array( + '#type' => 'checkbox', + '#title' => t('Hide video title and uploader info (showinfo).'), + '#default_value' => $settings['youtube_showinfo'], + ); + $element['youtube_controls'] = array( + '#type' => 'checkbox', + '#title' => t('Always hide video controls (controls).'), + '#default_value' => $settings['youtube_controls'], + ); + $element['youtube_autohide'] = array( + '#type' => 'checkbox', + '#title' => t('Hide video controls after play begins (autohide).'), + '#default_value' => $settings['youtube_autohide'], + ); + $element['youtube_iv_load_policy'] = array( + '#type' => 'checkbox', + '#title' => t('Hide video annotations by default (iv_load_policy).'), + '#default_value' => $settings['youtube_iv_load_policy'], + ); } if ($display['type'] == 'youtube_thumbnail') { @@ -230,8 +297,11 @@ function youtube_field_formatter_settings_summary($field, $instance, $view_mode) else { $summary = t('YouTube video: 450px by 315px'); } - if ($settings['youtube_autoplay']) { - $summary .= t(', Autoplay'); + foreach ($parameters as $parameter) { + if ($parameter) { + $summary .= t(', custom parameters'); + break; + } } return $summary; } @@ -276,6 +346,10 @@ function youtube_field_formatter_view($entity_type, $entity, $field, $instance, '#width' => array_key_exists('youtube_width', $display['settings']) ? $display['settings']['youtube_width'] : NULL, '#height' => array_key_exists('youtube_height', $display['settings']) ? $display['settings']['youtube_height'] : NULL, '#autoplay' => array_key_exists('youtube_autoplay', $display['settings']) ? $display['settings']['youtube_autoplay'] : FALSE, + '#showinfo' => array_key_exists('youtube_showinfo', $display['settings']) ? $display['settings']['youtube_showinfo'] : FALSE, + '#controls' => array_key_exists('youtube_controls', $display['settings']) ? $display['settings']['youtube_controls'] : FALSE, + '#autohide' => array_key_exists('youtube_autohide', $display['settings']) ? $display['settings']['youtube_autohide'] : FALSE, + '#iv_load_policy' => array_key_exists('youtube_iv_load_policy', $display['settings']) ? $display['settings']['youtube_iv_load_policy'] : FALSE, ); } break; @@ -396,12 +470,26 @@ function youtube_field_widget_error($element, $error, $form, &$form_state) { function youtube_theme($existing, $type, $theme, $path) { return array( 'youtube_thumbnail' => array( - 'variables' => array('video_id' => NULL, 'image_style' => NULL, 'image_link' => NULL), + 'variables' => array( + 'video_id' => NULL, + 'image_style' => NULL, + 'image_link' => NULL + ), 'file' => 'youtube.theme.inc', ), 'youtube_video' => array( - 'variables' => array('video_id' => NULL, 'size' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => FALSE), + 'variables' => array( + 'video_id' => NULL, + 'size' => NULL, + 'width' => NULL, + 'height' => NULL, + 'autoplay' => FALSE, + 'showinfo' => FALSE, + 'controls' => FALSE, + 'autohide' => FALSE, + 'iv_load_policy' => FALSE, + ), 'file' => 'youtube.theme.inc', ), ); -} \ No newline at end of file +} diff --git a/youtube.theme.inc b/youtube.theme.inc index 42e9741..6648908 100644 --- a/youtube.theme.inc +++ b/youtube.theme.inc @@ -9,17 +9,35 @@ */ 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); $wmode = variable_get('youtube_wmode', TRUE); + $privacy = variable_get('youtube_privacy', FALSE); $dimensions = youtube_get_dimensions($size, $width, $height); + if ($enablejsapi) { + $playerid = variable_get('youtube_playerid', 'youtube-field-player'); + } + else { + $playerid = 'youtube-field-player'; + } + // Protocol changes based on current page TODO. $protocol = (isset($_SERVER['HTTPS'])) ? 'https' : 'http'; @@ -28,12 +46,38 @@ function theme_youtube_video($variables) { 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'] = parse_url($base_url, PHP_URL_HOST); + } 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'; @@ -41,7 +85,7 @@ function theme_youtube_video($variables) { $path = $protocol . '://www.' . $domain . '/embed/' . $id; $src = url($path, array('query' => $query)); - $output = ''; @@ -91,4 +135,4 @@ function theme_youtube_thumbnail($variables) { } return $image; -} \ No newline at end of file +}