? 1063368_codec_ratio.patch
? wysiwyg/.DS_Store
? wysiwyg/tinymce/.DS_Store
Index: video_filter.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/video_filter/video_filter.module,v
retrieving revision 1.12.2.16
diff -u -r1.12.2.16 video_filter.module
--- video_filter.module	9 Dec 2010 19:23:02 -0000	1.12.2.16
+++ video_filter.module	17 Feb 2011 09:08:18 -0000
@@ -66,19 +66,10 @@
     foreach ($matches_code[0] as $ci => $code) {
       $video = array(
         'source' => $matches_code[2][$ci],
-        'width' => variable_get('video_filter_width_'.$format, 400),
-        'height' => variable_get('video_filter_height_'.$format, 400),
         'autoplay' => variable_get('video_filter_autoplay_'.$format, 0),
         'related' => variable_get('video_filter_related_'.$format, 1),
       );
 
-      // Insert default values to this settings array so we don't get any "Undefined index" warnings from PHP.
-      $video += array(
-        'ratio' => 0,
-        'control_bar_height' => 0,
-        'align' => NULL,
-      );
-
       // Pick random out of multiple sources separated by ','
       if (strstr($video['source'], ',')) {
         $sources          = explode(',', $video['source']);
@@ -102,7 +93,6 @@
             $video['codec']['delta'] = $delta;
             $video['codec']['matches'] = $matches;
             $video['codec']['codec_name'] = $codec_name; // used in theme function
-            $video['codec']['control_bar_height'] = 0; // default
             break 2;
           }
         }
@@ -119,20 +109,41 @@
 
         // Use configured ratio if present, use that from the codec otherwise
         $ratio = 0;
-        if ($video['ratio'] && preg_match('/(\d+)\/(\d+)/', $video['ratio'], $tratio) ) {
+        if (isset($video['ratio']) && preg_match('/(\d+)\/(\d+)/', $video['ratio'], $tratio) ) {
           //validate given ratio parameter
           $ratio = $tratio[1] / $tratio[2];
         }
         else {
           $ratio = $video['codec']['ratio'];
         }
+
+        // Sets video width & height after any user input has been parsed.
+        // First, check if user has set a width.
+        if (isset($video['width']) && !isset($video['height'])) {
+          $video['height'] = variable_get('video_filter_height_'.$format, 400);
+        }
+        // Else, if user has set height.
+        elseif (isset($video['height']) && !isset($video['width'])) {
+          $video['width'] = $video['height'] * $ratio;
+        }
+        // Maybe both?
+        elseif (isset($video['height']) && isset($video['width'])) {
+          $video['width'] = $video['width'];
+          $video['height'] = $video['height'];
+        }
+        // Fall back to defaults.
+        else {
+          $video['width'] = variable_get('video_filter_width_'.$format, 400);
+          $video['height'] = variable_get('video_filter_height_'.$format, 400);
+        }
+
         // Default value for control bar height
         $control_bar_height = 0;
-        if ($video['control_bar_height']) {
+        if (isset($video['control_bar_height'])) {
           // respect control_bar_height option if present
           $control_bar_height = $video['control_bar_height'];
         }
-        elseif ($video['codec']['control_bar_height']) {
+        elseif (isset($video['codec']['control_bar_height'])) {
           // respect setting provided by codec otherwise
           $control_bar_height = $video['codec']['control_bar_height'];
         }
@@ -145,9 +156,15 @@
         }
 
         $video['autoplay'] = (bool) $video['autoplay'];
-        $video['align'] = in_array($video['align'], array('left', 'right', 'center')) ? $video['align'] : NULL;
+        $video['align'] = (isset($video['align']) && in_array($video['align'], array('left', 'right', 'center'))) ? $video['align'] : NULL;
 
-        $replacement = $video['codec']['callback']($video);
+        if (is_callable($video['codec']['callback'], FALSE)) {
+          $replacement = call_user_func($video['codec']['callback'], $video);
+        }
+        else {
+          // Invalid callback
+          $replacement = '<!-- VIDEO FILTER - INVALID CALLBACK IN: ' . $pattern . ' -->';
+        }
       // Invalid format
       }
       else {
