Index: ad_flash.module
===================================================================
--- ad_flash.module	(revision 21)
+++ ad_flash.module	(working copy)
@@ -19,6 +19,7 @@
 /**
  * Implementation of hook_theme().
  */
+require_once ('sites/all/libraries/getid3/getid3.php');
 function ad_flash_theme() {
   return array(
     'ad_flash_render' => array(
@@ -364,31 +365,54 @@
 /**
  * Validate that the size of the uploaded flash is within the defined limits.
  */
-function ad_flash_validate_size($file, $gid) {
+function ad_flash_validate_size($file, $nid) {
   $size = NULL;
   $error = FALSE;
+  $edit = isset($_POST['edit']) ? $_POST['edit'] : array();
   if (is_object($file)) {
-  	if (strstr(strtolower($file->filename), '.flv')) return (object) array('width' => 0, 'height' => 0);
-	
-    $format = ad_flash_format_load($gid);
-    list($size->width, $size->height) = getimagesize($file->filepath);
+    // TODO: Detect if new terms have been set, and if so validate against
+    // them, not the old ones.  See what's in $edit['taxonomy'].
+    $node = node_load($nid);
+    $terms = module_invoke('taxonomy', 'node_get_terms', $node);
+    if (count($terms) == 0) {
+      // We need at least a single (NULL) term to be ensure we still get the
+      // default flash size.
+      $terms[] = NULL;
+    }
+    foreach ($terms as $tid => $term) {
+    $getID3 = new getID3;
+    $fid_info=$getID3->analyze($file->filepath);
+    $size->width = $fid_info['video']['resolution_x'];
+    $size->height = $fid_info['video']['resolution_y'];
+      $size->bytes = strlen(join('', file($file->filepath)));
+      if ($format = ad_flash_format_load($tid)) {
     if ($size->width < $format->min_width) {
-      drupal_set_message(t('The flash %name is only %current pixels wide, which is less than the minimum of %minimum pixels allowed in the selected ad group.', array('%name' => $file->filename, '%current' => $size->width, '%minimum' => $format->min_width)), 'error');
+          drupal_set_message(t('The flash %name is only %current pixels wide, which is less than the minimum of %minimum pixels allowed in the %group ad group.', array('%name' => $file->filename, '%current' => $size->width, '%minimum' => $format->min_width, '%group' => isset($term->name) ? $term->name : t('default'))), 'error');
       $error = TRUE;
     }
     else if ($format->max_width && ($size->width > $format->max_width)) {
-      drupal_set_message(t('The flash %name is %current pixels wide, which is more than the maximum of %maximum pixels allowed in the selected ad group.', array('%name' => $file->filename, '%current' => $size->width, '%maximum' => $format->max_width)), 'error');
+          drupal_set_message(t('The flash %name is %current pixels wide, which is more than the maximum of %maximum pixels allowed in the %group ad group.', array('%name' => $file->filename, '%current' => $size->width, '%maximum' => $format->max_width, '%group' => isset($term->name) ? $term->name : t('default'))), 'error');
       $error = TRUE;
     }
     if ($size->height < $format->min_height) {
-      drupal_set_message(t('The flash %name is only %current pixels high, which is less than the minimum of %minimum pixels allowed in the selected ad group.', array('%name' => $file->filename, '%current' => $size->height, '%minimum' => $format->min_height)), 'error');
+          drupal_set_message(t('The flash %name is only %current pixels high, which is less than the minimum of %minimum pixels allowed in the %group ad group.', array('%name' => $file->filename, '%current' => $size->height, '%minimum' => $format->min_height, '%group' => isset($term->name) ? $term->name : t('default'))), 'error');
       $error = TRUE;
     }
     else if ($format->max_height && $size->height > $format->max_height) {
-      drupal_set_message(t('The flash %name is %current pixels high, which is more than the maximum of %maximum pixels allowed in the selected ad group.', array('%name' => $file->filename, '%current' => $size->height, '%maximum' => $format->max_height)), 'error');
+          drupal_set_message(t('The flash %name is %current pixels high, which is more than the maximum of %maximum pixels allowed in the %group ad group.', array('%name' => $file->filename, '%current' => $size->height, '%maximum' => $format->max_height, '%group' => isset($term->name) ? $term->name : t('default'))), 'error');
       $error = TRUE;
     }
+        if ($format->max_size && $size->bytes > $format->max_size) {
+          drupal_set_message(t('The flash %name is %current bytes in size, which is more than the maximum of %maximum bytes allowed in the %group ad group.', array('%name' => $file->filename, '%current' => $size->bytes, '%maximum' => $format->max_size, '%group' => isset($term->name) ? $term->name : t('default'))), 'error');
+          $error = TRUE;
+        }
+      }
+    }
   }
+  else {
+    $error = TRUE;
+    drupal_set_message('Please report error: $file is not an object, bug #146147.');
+  }
   if ($error) {
     return FALSE;
   }
@@ -411,7 +435,7 @@
     foreach ($node->files as $file) {
       if (is_array($file)) {
         if ($file['list'] && file_exists($file['filepath'])) {
-          $flash = ad_flash_validate_size((object)$file, $node->gid);
+          $flash = ad_flash_validate_size((object)$file, $node->nid);
           if ($flash !== FALSE) {
             $flash->fid = $file['fid'];
 						$flash->type = strtolower(pathinfo($file['filepath'], PATHINFO_EXTENSION));
@@ -421,7 +445,7 @@
       }
       else {
         if ($file->list && file_exists($file->filepath)) {
-          $flash = ad_flash_validate_size($file, $node->gid);
+          $flash = ad_flash_validate_size($file, $node->nid);
           if ($flash !== FALSE) {
             $flash->fid = $file->fid;
 						$flash->type = strtolower(pathinfo($file->filepath, PATHINFO_EXTENSION));
@@ -461,13 +485,16 @@
   if ($num) {
     foreach ($files as $file) {
       if ($file->list && file_exists($file->filepath)) {
-        list($flash->width, $flash->height) = getimagesize($file->filepath);
+        $getID3 = new getID3;
+        $fid_info=$getID3->analyze($file->filepath);
+        $flash->width = $fid_info['video']['resolution_x'];
+        $flash->height = $fid_info['video']['resolution_y'];
         $flash->path = file_create_url($file->filepath);
-        //$path .= theme('ad_flash_render', null, $flash);
-        $flash = ad_flash_validate_size($file, $node->gid);
+        $path .= theme('ad_flash_render', null, $flash);
+        $flash = ad_flash_validate_size($file, $node->nid);
         if ($flash === FALSE) {
           $path .= t('(invalid flash file)'). '<br />';
-        }
+         }
         else if (!$active++) {
           $path .= t('(active)'). '<br />';
         }
