Index: ooyala.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ooyala/ooyala.module,v
retrieving revision 1.22
diff -u -r1.22 ooyala.module
--- ooyala.module	11 Aug 2010 00:42:17 -0000	1.22
+++ ooyala.module	11 Aug 2010 21:08:06 -0000
@@ -574,7 +574,7 @@
   $request = $ooyala_api->signed_params(
     array(
       'embedCode' => $embedcode,
-      'range' => '0',
+      'range' => '0-1',
       'resolution' => '1024x768',
       'expires' => time() + 30,
     )
@@ -696,6 +696,25 @@
   $output .= '<div class="ooyala-button-container">';
   $output .= drupal_render($element['value']);
   $output .= '</div>';
+  $output .= '</div>';
+  return $output;
+}
+
+/**
+ * Theme the preview thumbnail on the node form.
+ */
+function theme_ooyala_upload_preview($embedcode = NULL) {
+  if (isset($embedcode)) {
+    $path = ooyala_get_thumbnail_url($embedcode, NULL, TRUE);
+    if (is_file($path)) {
+      $output = theme('ooyala_thumbnail', $embedcode, NULL, NULL, NULL, array('width' => 150), FALSE);
+    }
+  }
+
+  if (!isset($output)) {
+    $output = '<div class="ooyala-preview-placeholder">' . t('No Preview Available') . '</div>';
+  }
+
   return $output;
 }
 
@@ -711,10 +730,10 @@
 
   switch ($formatter[1]) {
     case 'ooyala_imagecache':
-      $return = theme('ooyala_thumbnail', _ooyala_get_thumbnail_url($element['#item']['value'], $preset), FALSE);
+      $return = theme('ooyala_thumbnail', $element['#item']['value'], $preset);
       break;
     case 'ooyala_linked_imagecache':
-      $return = theme('ooyala_thumbnail', _ooyala_get_thumbnail_url($element['#item']['value'], $preset), url('node/' . $element['#node']->nid));
+      $return = theme('ooyala_thumbnail', $element['#item']['value'], $preset, 'node/' . $element['#node']->nid);
       break;
     case 'ooyala_thickbox':
       $return = theme('ooyala_formatter_ooyala_thickbox', $element, $preset);
@@ -741,7 +760,7 @@
     $values[] = ($allowed = _text_allowed_values($item)) ? $allowed : $item['#item']['safe'];
   }
 
-  // TODO: Make this formatter work on mulitple values.
+  // TODO: Make this formatter work on multiple values.
   return theme('ooyala_player', implode($values));
 }
 
@@ -749,45 +768,63 @@
  * Theme function to output the "ooyala_thumbnail" formatter.
  */
 function theme_ooyala_formatter_ooyala_thumbnail($element) {
-  $values = array();
+  $output = '';
   foreach (element_children($element) as $key) {
     $item = $element[$key];
     if ($item['#item']['value']) {
-      $values[] = _ooyala_get_thumbnail_url($item['#item']['value'], NULL);
+      $output .= theme('ooyala_thumbnail', $item['#item']['value']);
     }
   }
 
-  foreach ($values as $value) {
-    $return .= theme('ooyala_thumbnail', $value, NULL );
-  }
-  return $return;
+  return $output;
 }
 
 /**
  * Theme function to output the "ooyala_thickbox" formatter.
  */
 function theme_ooyala_formatter_ooyala_thickbox($element, $preset = NULL) {
-  $embededcode = $element['#item']['value'];
-
-  $image_url = _ooyala_get_thumbnail_url($embededcode, $preset);
-  $link_url = url('ooyalavideo/' . $embededcode, array('query' => array(
+  $link_url = url('ooyalavideo/' . $element['#item']['value'], array('query' => array(
     'KeepThis' => 'true',
     'TB_iframe' => 'true',
     'width' => variable_get('ooyala_thickbox_width', 500),
     'height' => variable_get('ooyala_thickbox_height', 400),
   )));
 
-  $return = theme('ooyala_thumbnail', $image_url, $link_url, array('class' => 'thickbox'));
+  $return = theme('ooyala_thumbnail', $element['#item']['value'], $preset, $link_url, array('class' => 'thickbox'));
 
   return $return;
 }
 
 /**
- * Preprocess function for ooyala-thumbnail.tpl.php.
+ * Themed output for an Ooyala thumbnail.
  */
-function template_preprocess_ooyala_thumbnail(&$variables) {
-  $image_code = sprintf('<img src=%s />', $variables['thumbpath']);
-  $variables['thumbnail_code'] = ($variables['link_to_node'])? sprintf('<a href=%s %s>%s</a>', $variables['link_to_node'], drupal_attributes($variables['link_attributes']), $image_code) : $image_code;
+function theme_ooyala_thumbnail($embedcode, $preset = NULL, $link_href = NULL, $link_attributes = array(), $image_attributes = array(), $get_size = TRUE) {
+  $src = ooyala_get_thumbnail_url($embedcode, NULL, TRUE);
+
+  // Retrieve the alt and title variables to be passed to other theme functions.
+  $image_attributes += array('alt' => '', 'title' => '');
+  $alt = $image_attributes['alt'];
+  $title = $image_attributes['title'];
+  unset($image_attributes['alt'], $image_attributes['title']);
+
+  // Generate the img tag.
+  if (isset($preset)) {
+    $output = theme('imagecache', $preset, $src, $alt, $title, $image_attributes, $get_size);
+  }
+  else {
+    $output = theme('image', $src, $alt, $title, $image_attributes, $get_size);
+  }
+
+  // Wrap if needed in our link.
+  if ($link_href) {
+    $options = array(
+      'html' => TRUE,
+      'attributes' => $link_attributes,
+    );
+    $output = l($output, $link_href, $options);
+  }
+
+  return '<div class="ooyala-thumbnail">' . $output .'</div>';
 }
 
 /**
@@ -821,10 +858,10 @@
 /**
  * Helper function to generate a thumbnail URL from an Ooyala video code.
  */
-function _ooyala_get_thumbnail_url($embededcode, $preset = NULL, $return_path = FALSE) {
+function ooyala_get_thumbnail_url($embedcode, $preset = NULL, $return_path = FALSE) {
   $directory = file_create_path(variable_get('ooyala_thumbnail_path', 'ooyalathumbs'));
   _ooyala_check_directory($directory);
-  $path = $directory . '/' . $embededcode . '.jpg';
+  $path = $directory . '/' . $embedcode . '.jpg';
 
   if ($return_path) {
     return $path;
@@ -842,8 +879,8 @@
     // Save this embeded code to download the thumbnail on next cron run.
     $thumbnails_to_get = variable_get('ooyala_pending_thumbnails', array());
 
-    if ($embededcode && !isset($thumbnails_to_get[$embededcode])) {
-      $thumbnails_to_get[$embededcode] = $embededcode;
+    if ($embedcode && !isset($thumbnails_to_get[$embedcode])) {
+      $thumbnails_to_get[$embedcode] = $embedcode;
       variable_set('ooyala_pending_thumbnails', $thumbnails_to_get);
       drupal_set_message(t('The thumbnail will be downloaded from Ooyala in the next Cron run'), 'status');
     }
Index: templates/ooyala-thumbnail.tpl.php
===================================================================
RCS file: templates/ooyala-thumbnail.tpl.php
diff -N templates/ooyala-thumbnail.tpl.php
--- templates/ooyala-thumbnail.tpl.php	11 Nov 2009 00:33:47 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,3 +0,0 @@
-<div class='ooyala_thumbnail'>
-	<?php print $thumbnail_code ?>
-</div>
\ No newline at end of file
