Index: embedfilter.module
===================================================================
--- embedfilter.module	(revision 83)
+++ embedfilter.module	(revision 90)
@@ -38,8 +38,8 @@
 </pre>
 EOF;
 
-      $output .= '<p>'. t('To use this moudule, start by entering a number of hosts that you wish to allow. This is done from the <a href="/?q=admin/settings/embedfilter">settings page</a>. Examples taken from the sites mentioned above would be: <ul><li>http://www.youtube.com</li><li>http://www.ifilm.com</li><li>http://media.nowpublic.com</li></ul> Note that variants on a host, such as <code>http://www.youtube.com</code> and <code>http://youtube.com</code> must be entered individually.From the settings page you can also define some HTML that will be embedded before and after any tags (in case you want to be able to visually identify them on your site), as well as some filter tip instructions to your users.') .'</p>';
-      $output .= '<p>'. t('After you have configured the module from the settings page, you need to add the "Object and embed" filter to the appropriate input formats (such as "Filtered HTML") on the <a href="/?q=admin/filters">input formats</a> administration page. Configure your HTML filter to accept &lt;object>, &lt;embed> and &lt;script> tags by adding them to the list of accepted tags. Configure the order of the filters so that the "Object and embed tag" filter comes directly after the "HTML" filter. After this you should be ready to go!'). '</p>';
+      $output .= '<p>'. t('To use this module, start by entering a number of hosts that you wish to allow. This is done from the <a href="/?q=admin/settings/embedfilter">settings page</a>. Examples taken from the sites mentioned above would be: <ul><li>youtube.com</li><li>ifilm.com</li><li>nowpublic.com</li></ul> You can define some HTML that will be embedded before and after any tags (in case you want to be able to visually identify them on your site), as well as some filter tip instructions to your users.') .'</p>';
+      $output .= '<p>'. t('After you have configured the module from the settings page, you need to add the "Object and embed" filter to the appropriate input formats (such as "Filtered HTML") on the <a href="/?q=admin/filters">input formats</a> administration page. Configure your HTML filter to accept &lt;object>, &lt;embed>, &lt;param> and &lt;script> tags by adding them to the list of accepted tags. Configure the order of the filters so that the "Object and embed tag" filter comes directly after the "HTML" filter. After this you should be ready to go!'). '</p>';
       return $output;
   }
 }
@@ -73,7 +73,7 @@
     '#type' => 'textarea',
     '#title' => t('Allowed hosts'),
     '#default_value' => variable_get('embedfilter_host_whitelist', "http://www.youtube.com\nhttp://media.nowpublic.com"),
-    '#description' => t('Each host name or base URL from which <object>, <embed> or <script> tags should be accepted. One URL per line. Make sure to match the URL exactly (for instance, http://www.example.com and http://example.com will be seen as different URLs). Example: http://www.youtube.com'),
+    '#description' => t('Each host name from which &lt;object>, &lt;embed>, &lt;param> or &lt;script> tags should be accepted. One host per line. This module is patched to expect only domain.tld format and ignores subdomains. Example: youtube.com'),
   );
 
   $form['extramarkup'] = array(
@@ -231,7 +231,7 @@
     $input = preg_replace_callback('@<(embed|object|script)([^>]*)>(.*?)</\1>@s', 'embedfilter_process', $input, 5);
   }
 
-  return $input;
+  return embedfilter_media_resize($input, 550);
 }
 
 /**
@@ -249,9 +249,15 @@
   preg_match_all($pattern, $input, $matches);
   foreach ($matches[3] as $url) {
     $parts = parse_url($url);
-    if (!in_array($parts['scheme']. '://'. $parts['host'], embedfilter_get_whitelist())) {
+    //first check if there is no subdomain
+    if (preg_match('/^\.(com|co\.uk|tv|net|org|gov)/',strstr($parts['host'],'.'))) {
+      if (!in_array($parts['host'], embedfilter_get_whitelist())) {
+        return false;
+      }
+    //otherwise check if domain and subdomain are both missing from the permitted list
+    } elseif ((!in_array(ltrim(strstr($parts['host'],'.'),'.'), embedfilter_get_whitelist())) && (!in_array($parts['host'], embedfilter_get_whitelist()))) {
       return false;
-    }
+    } 
   }
   return true;
 }
@@ -273,6 +279,13 @@
     $pattern = '@(src|href)=([\'"])([^"]+)\\2@i';
     $output = preg_replace_callback($pattern, 'embedfilter_sanitize', $input);
   }
+
+  //removes any errant slashes from the end of $output
+  $last = $input[strlen($output)-1];
+  if ($last == '/') {
+    $output = substr($output, 0, -1);
+  }
+
   return $output;
 }
 
@@ -296,3 +309,43 @@
   }
   return $output;
 }
+
+/**
+ * Resizes over-sized media
+ * 
+ *  @param $input
+ *  string of HTML with width and height attributes
+ * 
+ *  @param $maxwidth
+ *  the maximum permitted width on the website for embedded media
+ * 
+ *  @return
+ *  replacement $input HTML string containing revised width and height
+ */
+ 
+function embedfilter_media_resize($input = '', $maxwidth = 550) {
+  preg_match('/height="([0-9]*)"/',$input,$fetchheight);
+  preg_match('/width="([0-9]*)"/',$input,$fetchwidth);
+  if ($fetchheight && $fetchwidth) {
+    $height = $fetchheight[1];
+    $width = $fetchwidth[1];  
+  }
+
+  if ($width > $maxwidth) {
+    $diff = $width-$maxwidth;
+    $ratio = $diff/$width;
+    $heightdiff = $ratio*$height;
+    $height = round($height-$heightdiff);
+    $width = $maxwidth;
+    
+    $patterns[0] = '/height="([0-9]*)"/';
+    $patterns[1] = '/width="([0-9]*)"/';
+    $replacements[1] = 'height="'.$height.'"';
+    $replacements[0] = 'width="'.$width.'"';
+    
+    $input = preg_replace($patterns, $replacements, $input);
+  }
+  
+  return $input;
+}
+
