--- imagecache.module	2008-07-22 11:44:54.000000000 +0100
+++ imagecache-new.module	2008-10-28 13:51:29.000000000 +0000
@@ -39,7 +39,7 @@
  * Implementation of hook_perm().
  */
 function imagecache_perm() {
-  $perms =  array('administer imagecache', 'flush imagecache');
+  $perms =  array('administer imagecache', 'flush imagecache', 'cache external images');
   foreach (imagecache_presets() as $preset) {
     $perms[] =  'view imagecache '. $preset['presetname'];
   }
@@ -197,6 +197,9 @@ function imagecache_action_definition($a
  */
 function imagecache_create_url($presetname, $path) {
   $path = _imagecache_strip_file_directory($path);
+  if (stripos($path, 'http://')==0){
+  	$path = str_ireplace('http://', 'http/', $path);
+  }
   switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
     case FILE_DOWNLOADS_PUBLIC:
       return url(file_directory_path() .'/imagecache/'. $presetname .'/'. $path, NULL, NULL, TRUE);
@@ -211,7 +214,13 @@ function imagecache_create_url($presetna
  * Keep in mind that the image might not yet exist and won't be created.
  */
 function imagecache_create_path($presetname, $path) {
-  $path = _imagecache_strip_file_directory($path);
+  if (substr($path, 0, 5) == 'http/' && user_access('cache external images')){
+	 	$path = str_ireplace('http%2F', "http/", urlencode($path));
+  }
+  else
+  {
+  	$path = _imagecache_strip_file_directory($path);	
+  }
   return file_create_path() .'/imagecache/'. $presetname .'/'. $path;
 }
 
@@ -270,6 +279,18 @@ function _imagecache_cache($presetname, 
     header('HTTP/1.0 404 Not Found');
     exit;
   }
+  
+  // handle external http files
+  /*if (user_access('cache external images')) {
+		$args = split('/', $path, 2);
+		$http = ($args[0]=='http');
+		if($http){
+			$dst = file_create_path() .'/imagecache/'. $preset['presetname'] .'/http/' . urlencode($args[1]);
+			if (file_exists($dst)) {
+				imagecache_transfer($dst);
+			} 
+		}
+  }*/
 
   // umm yeah deliver it early if it is there. especially useful
   // to prevent lock files from being created when delivering private files. 
@@ -279,13 +300,40 @@ function _imagecache_cache($presetname, 
   }  
 
   $src = $path;
-  
+
+	// handle external http files
+	if(substr($src, 0, 5) == 'http/' && user_access('cache external images')){
+		$args = split('/', $path, 2);
+		$url = 'http://'. $args[1];
+		$src = file_create_path() . '/imagecache/http-originals/' . urlencode($args[1]);
+		if (!file_exists($src)) {
+			$dir = file_create_path() .'/imagecache/http-originals';
+			if(!file_check_directory($dir)){
+				mkdir($dir, 0775, true);
+			}
+			$result = drupal_http_request($url);
+			$code = floor($result->code / 100) * 100;
+			$types = array('image/jpeg', 'image/png', 'image/gif');
+			
+			if($result->data && $code != 400 && $code != 500 && in_array($result->Content-Type, $types)){
+				$src = file_save_data($result->data, $src);
+			}
+			else
+			{
+				//to prevent calling this external site repeatedly place blank file??
+				$src = file_save_data('', $src);
+			}
+		}
+		$dst = file_create_path() .'/imagecache/'. $preset['presetname'] .'/http/' . urlencode($args[1]);
+	}
+
   // check if the path to the file exists
   if (!is_file($src)) {
     // check if it is a file in the files dir if we couldn't find it.
     $src = file_create_path($src);
   };
-
+  
+  
   // If the file doesn exist.. It could be an imagefield preview... 
   if (!is_file($src)) {
     // scan for imagefield previews 
