From a9e89a008129ecc74cbe9a16c0ceb00d0838c5a2 Mon Sep 17 00:00:00 2001
From: andrew morton <drewish@katherinehouse.com>
Date: Mon, 26 Mar 2012 15:33:51 -0400
Subject: [PATCH] Issue #1443092 by nikosnikos and drewish: Add more video
 display settings, switch to universal player.

---
 includes/media_vimeo.formatters.inc   |   49 ++++++++++++++++++++++++-
 includes/media_vimeo.variables.inc    |   10 ++++-
 includes/themes/media_vimeo.theme.inc |   63 +++++++++++++++++----------------
 media_vimeo.module                    |    2 +-
 4 files changed, 88 insertions(+), 36 deletions(-)

diff --git a/includes/media_vimeo.formatters.inc b/includes/media_vimeo.formatters.inc
index 7128d42..fc0368e 100644
--- a/includes/media_vimeo.formatters.inc
+++ b/includes/media_vimeo.formatters.inc
@@ -14,7 +14,15 @@ function media_vimeo_file_formatter_info() {
     'default settings' => array(
       'width' => media_vimeo_variable_get('width'),
       'height' => media_vimeo_variable_get('height'),
+      'preview_uri' => media_vimeo_variable_get('preview_uri'),
+      'api' => media_vimeo_variable_get('api'),
       'autoplay' => media_vimeo_variable_get('autoplay'),
+      'byline' => media_vimeo_variable_get('byline'),
+      'color' => media_vimeo_variable_get('color'),
+      'fullscreen' => media_vimeo_variable_get('fullscreen'),
+      'loop' => media_vimeo_variable_get('loop'),
+      'portrait' => media_vimeo_variable_get('portrait'),
+      'title' => media_vimeo_variable_get('title'),
     ),
     'view callback' => 'media_vimeo_file_formatter_video_view',
     'settings callback' => 'media_vimeo_file_formatter_video_settings',
@@ -42,7 +50,8 @@ function media_vimeo_file_formatter_video_view($file, $display, $langcode) {
       '#theme' => 'media_vimeo_video',
       '#uri' => $file->uri,
     );
-    foreach (array('width', 'height', 'autoplay') as $setting) {
+    $settings = array('width', 'height', 'api' , 'autoplay', 'byline', 'color', 'fullscreen', 'loop', 'portrait', 'title');
+    foreach ($settings as $setting) {
       $element['#' . $setting] = isset($file->override[$setting]) ? $file->override[$setting] : $display['settings'][$setting];
     }
     return $element;
@@ -65,10 +74,46 @@ function media_vimeo_file_formatter_video_settings($form, &$form_state, $setting
     '#default_value' => $settings['height'],
   );
   $element['autoplay'] = array(
-    '#title' => t('Autoplay'),
+    '#title' => t('Play the video automatically on load'),
     '#type' => 'checkbox',
     '#default_value' => $settings['autoplay'],
   );
+  $element['loop'] = array(
+    '#title' => t('Play the video again when it reaches the end'),
+    '#type' => 'checkbox',
+    '#default_value' => $settings['loop'],
+  );
+  $element['fullscreen'] = array(
+    '#title' => t('Allow the player to go into fullscreen'),
+    '#type' => 'checkbox',
+    '#default_value' => $settings['fullscreen'],
+  );
+  $element['api'] = array(
+    '#title' => t('Enable the Javascript API'),
+    '#type' => 'checkbox',
+    '#default_value' => $settings['api'],
+  );
+  $element['color'] = array(
+    '#title' => t('Specify the color of the video controls'),
+    '#type' => 'textfield',
+    '#default_value' => $settings['color'],
+  );
+  $element['portrait'] = array(
+    '#title' => t("Show the user's portrait on the video"),
+    '#type' => 'checkbox',
+    '#default_value' => $settings['portrait'],
+  );
+  $element['title'] = array(
+    '#title' => t('Show the title on the video'),
+    '#type' => 'checkbox',
+    '#default_value' => $settings['title'],
+  );
+  $element['byline'] = array(
+    '#title' => t('Show the byline on the video'),
+    '#type' => 'checkbox',
+    '#default_value' => $settings['byline'],
+  );
+
   return $element;
 }
 
diff --git a/includes/media_vimeo.variables.inc b/includes/media_vimeo.variables.inc
index e9d5d44..4330299 100644
--- a/includes/media_vimeo.variables.inc
+++ b/includes/media_vimeo.variables.inc
@@ -103,9 +103,15 @@ function media_vimeo_variable_default($name = NULL) {
     $defaults = array(
       'width' => 560,
       'height' =>340,
-      'autoplay' => FALSE,
-      'fullscreen' => TRUE,
       'preview_uri' => 'vimeo://v/21869117',
+      'api' => 0,
+      'autoplay' => 0,
+      'byline' => 1,
+      'color' => '#00adef',
+      'fullscreen' => 1,
+      'loop' => 0,
+      'portrait' => 1,
+      'title' => 1,
     );
   }
 
diff --git a/includes/themes/media_vimeo.theme.inc b/includes/themes/media_vimeo.theme.inc
index 12b6b07..348cd37 100644
--- a/includes/themes/media_vimeo.theme.inc
+++ b/includes/themes/media_vimeo.theme.inc
@@ -14,49 +14,50 @@ function media_vimeo_preprocess_media_vimeo_video(&$variables) {
   $uri = $variables['uri'];
   $wrapper = file_stream_wrapper_get_instance_by_uri($uri);
   $parts = $wrapper->get_parameters();
-  $variables['video_id'] = check_plain($parts['v']);
+  $variables['video_id'] = $parts['v'];
 
-  $variables['width'] = isset($variables['width']) ? $variables['width'] : media_vimeo_variable_get('width');
-  $variables['height'] = isset($variables['height']) ? $variables['height'] : media_vimeo_variable_get('height');
-  $variables['autoplay'] = isset($variables['autoplay']) ? $variables['autoplay'] : media_vimeo_variable_get('autoplay');
-  $variables['fullscreen'] = isset($variables['fullscreen']) ? $variables['fullscreen'] : media_vimeo_variable_get('fullscreen');
-  $variables['autoplay'] = $variables['autoplay'] ? 1 : 0;
-  $variables['fullscreen'] = $variables['fullscreen'] ? 'true' : 'false';
+  $wrapper_id = 'media_vimeo_' . $variables['video_id'] . '_' . $variables['id'];
+  $variables['wrapper_id'] = $wrapper_id;
 
-  $variables['wrapper_id'] = 'media_vimeo_' . $variables['video_id'] . '_' . $variables['id'];
+  // Load defaults and coerce these variables to integers.
+  foreach (array('width', 'height', 'autoplay', 'fullscreen', 'loop', 'portrait', 'title', 'byline') as $key) {
+    $variables[$key] = (int) (isset($variables[$key]) ? $variables[$key] : media_vimeo_variable_get($key));
+  }
+  $variables['color'] = str_replace('#', '', isset($variables['color']) ? $variables['color'] : media_vimeo_variable_get('color'));
+
+  // Copy the variables that will be encoded into URLs into a sub array.
+  $variables['options'] = array(
+    'api' => $variables['api'],
+    'autoplay' => $variables['autoplay'],
+    'loop' => $variables['loop'],
+    'color' => $variables['color'],
+    'portrait' => $variables['portrait'],
+    'title' => $variables['title'],
+    'byline' => $variables['byline'],
+    'player_id' => $wrapper_id,
+  );
+
+  $url = url('http://player.vimeo.com/video/' . $variables['video_id'], array('query' => array($variables['options'])));
 
-  // For users with JavaScript, these object and embed tags will be replaced
-  // by an iframe, so that we can support users without Flash.
   $variables['output'] = <<<OUTPUT
-    <object width="{$variables['width']}" height="{$variables['height']}">
-      <param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id={$variables['video_id']}">
-      <param name="allowFullScreen" value="{$variables['fullscreen']}"></param>
-      <param name="wmode" value="transparent" />
-      <embed src="http://vimeo.com/moogaloop.swf?clip_id={$variables['video_id']}" type="application/x-shockwave-flash" width="{$variables['width']}" height="{$variables['height']}" allowfullscreen="{$variables['fullscreen']}"></embed>
-    </object>
+    <iframe src="{$url}" width="{$variables['width']}" height="{$variables['height']}" frameborder="0"></iframe>
 OUTPUT;
 
+/* I'm not sure that these are still necessary:
   // Pass the settings to replace the object tag with an iframe.
-  $settings = array(
-    'media_vimeo' => array(
-      $variables['wrapper_id'] => array(
-        'width' => $variables['width'],
-        'height' => $variables['height'],
-        'video_id' => $variables['video_id'],
-        'fullscreen' => $variables['fullscreen'],
-        'id' => $variables['wrapper_id'] .'_iframe',
-      ),
-    ),
+  $settings['media_vimeo'][$wrapper_id] = array(
+    'width' => $variables['width'],
+    'height' => $variables['height'],
+    'video_id' => $variables['video_id'],
+    'fullscreen' => $variables['fullscreen'],
+    'id' => $wrapper_id .'_iframe',
+    'options' => $variables['options'],
   );
-  if ($variables['autoplay']) {
-    $settings['media_vimeo'][$variables['wrapper_id']]['options'] = array(
-      'autoplay' => $variables['autoplay'],
-    );
-  }
   drupal_add_js($settings, 'setting');
   drupal_add_js(drupal_get_path('module', 'media_vimeo') . '/js/media_vimeo.js');
   drupal_add_css(drupal_get_path('module', 'media_vimeo') . '/css/media_vimeo.css');
   drupal_add_js(drupal_get_path('module', 'media_vimeo') . '/js/flash_detect_min.js');
+*/
 }
 
 function theme_media_vimeo_field_formatter_styles($variables) {
diff --git a/media_vimeo.module b/media_vimeo.module
index 0ad210c..3197b8a 100644
--- a/media_vimeo.module
+++ b/media_vimeo.module
@@ -69,7 +69,7 @@ function media_vimeo_theme($existing, $type, $theme, $path) {
       'path' => $path . '/includes/themes',
     ),
     'media_vimeo_video' => array(
-      'variables' => array('uri' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL, 'fullscreen' => NULL),
+      'variables' => array('uri' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL, 'loop' => NULL, 'fullscreen' => NULL, 'api' => NULL, 'color' => NULL, 'portrait' => NULL, 'title' => NULL, 'byline' => NULL),
       'file' => 'media_vimeo.theme.inc',
       'path' => $path . '/includes/themes',
       'template' => 'media-vimeo-video',
-- 
1.7.7.4

