From 8e8e0b820cfb462db70d3d9d925975458c77e2cc Mon Sep 17 00:00:00 2001
From: Hans Nilsson <hans.nilsson@gmail.com>
Date: Thu, 15 Sep 2011 22:53:38 +0200
Subject: [PATCH] Issue [#1233706] - add theme function for HTML5 output.

---
 video_filter.codecs.inc |    9 +++----
 video_filter.module     |   61 ++++++++++++++++++++++++++++++++++------------
 2 files changed, 49 insertions(+), 21 deletions(-)

diff --git a/video_filter.codecs.inc b/video_filter.codecs.inc
index 8b33d92..e161014 100644
--- a/video_filter.codecs.inc
+++ b/video_filter.codecs.inc
@@ -196,10 +196,9 @@ function video_filter_youtube_html5($video) {
     'rel' => $video['related'] ? 'rel=1' : 'rel=0',
     'autoplay' => $video['autoplay'] ? 'autoplay=1' : 'autoplay=0',
   );
-  $url = $video['codec']['matches'][1] . '?' . implode('&amp;', $attributes);
-  $html = '<iframe src="http://www.youtube.com/embed/'.$url.'" width="'.$video['width'].'" height="'.$video['height'].'" frameborder="0"></iframe>';
+  $video['source'] = 'http://www.youtube.com/embed/' . $video['codec']['matches'][1] . '?' . implode('&amp;', $attributes);
 
-  return $html;
+  return theme('video_filter_html5', array('video' => $video));
 }
 
 function video_filter_google($video) {
@@ -227,9 +226,9 @@ function video_filter_vimeo($video) {
 }
 
 function video_filter_vimeo_html5($video) {
-  $html = '<iframe src="http://player.vimeo.com/video/'.$video['codec']['matches'][1].($video['autoplay'] ? '?autoplay=1' : '').'" width="'.$video['width'].'" height="'.$video['height'].'" frameborder="0"></iframe>';
+  $video['source'] = 'http://player.vimeo.com/video/'.$video['codec']['matches'][1].($video['autoplay'] ? '?autoplay=1' : '');
 
-  return $html;
+  return theme('video_filter_html5', array('video' => $video));
 }
 
 function video_filter_flickr_slideshows($video) {
diff --git a/video_filter.module b/video_filter.module
index d3d8550..daba439 100644
--- a/video_filter.module
+++ b/video_filter.module
@@ -251,32 +251,35 @@ function video_filter_get_codec_info() {
 }
 
 /**
- * Function that outputs the <object> element.
+ * Function that outputs HTML5 compatible iFrame for codecs that support it.
  *
  * @ingroup themeable
  */
-function theme_video_filter_flash($variables) {
+function theme_video_filter_html5($variables) {
   $output = '';
 
   $video = $variables['video'];
   $params = isset($variables['params']) ? $variables['params'] : array();
 
-  // Create classes
-  $classes = array(
-    'video-filter',
-    'video-' . $video['codec']['codec_name'],  // Adds codec name
-  );
+  $classes = video_filter_get_classes($video);
 
-  // Adds alignment
-  if (isset($video['align'])) {
-    $classes[] = 'video-' . $video['align'];
-  }
+  $output = '<iframe src="' . $video['source'] . '" width="'. $video['width'] . '" height="'. $video['height']. '" class="' . implode(' ', $classes). '" frameborder="0"></iframe>';
 
-  // First match is the URL, we don't want that as a class.
-  unset($video['codec']['matches'][0]);
-  foreach ($video['codec']['matches'] AS $match) {
-    $classes[] = 'vf-' . strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $match));
-  }
+  return $output;
+}
+
+/**
+ * Function that outputs the <object> element.
+ *
+ * @ingroup themeable
+ */
+function theme_video_filter_flash($variables) {
+  $output = '';
+
+  $video = $variables['video'];
+  $params = isset($variables['params']) ? $variables['params'] : array();
+
+  $classes = video_filter_get_classes($video);
 
   $output .= '<object class="' . implode(' ', $classes) . '" type="application/x-shockwave-flash" ';
 
@@ -307,6 +310,9 @@ function video_filter_theme($existing, $type, $theme, $path) {
     'video_filter_flash' => array(
       'variables' => array('video' => NULL, 'params' => NULL),
     ),
+    'video_filter_html5' => array(
+      'variables' => array('video' => NULL, 'params' => NULL),
+    ),
     'video_filter_dashboard' => array(
       'variables' => array('form' => NULL),
       'template' => 'video_filter_dashboard',
@@ -315,6 +321,29 @@ function video_filter_theme($existing, $type, $theme, $path) {
 }
 
 /**
+ * Helper function that extracts some classes from $video.
+ */
+function video_filter_get_classes($video) {
+  $classes = array(
+    'video-filter',
+    'video-' . $video['codec']['codec_name'],  // Adds codec name
+  );
+
+  // Adds alignment
+  if (isset($video['align'])) {
+    $classes[] = 'video-' . $video['align'];
+  }
+
+  // First match is the URL, we don't want that as a class.
+  unset($video['codec']['matches'][0]);
+  foreach ($video['codec']['matches'] AS $match) {
+    $classes[] = 'vf-' . strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $match));
+  }
+
+  return $classes;
+}
+
+/**
  * Implementation of hook_menu().
  */
 function video_filter_menu() {
-- 
1.7.4.4

