=== modified file 'FlickrImportSet.inc'
--- FlickrImportSet.inc	2007-06-02 02:11:48 +0000
+++ FlickrImportSet.inc	2007-06-02 04:01:46 +0000
@@ -117,7 +117,7 @@
 	$Flickr['photos'] = $f2g->flickr->photosets_getPhotos($sid);
 
 	for ($i = 0; $i < count($Flickr['photos']['photo']); $i++) {
-	  $Flickr['photos']['photo'][$i]['thumb'] = $f2g->flickr->buildPhotoURL($Flickr['photos']['photo'][$i], 'thumbnail');
+	  $Flickr['photos']['photo'][$i]['thumb'] = $f2g->flickr->buildPhotoURLFromPhoto($Flickr['photos']['photo'][$i], 'thumbnail');
 	}
 
 	$template->setVariable('Flickr', $Flickr);
@@ -125,4 +125,4 @@
 	return array(null, array('body' => 'modules/Gallery2Flickr/templates/FlickrImportSet.tpl'));
     }
 }
-?>
\ No newline at end of file
+?>

=== modified file 'FlickrSearch.inc'
--- FlickrSearch.inc	2007-06-02 02:11:48 +0000
+++ FlickrSearch.inc	2007-06-02 04:01:46 +0000
@@ -196,7 +196,7 @@
 	    }
 
 	    for ($i = 0; $i < count($result['photo']); $i++) {
-	      $result['photo'][$i]['thumb'] = $f2g->flickr->buildPhotoURL($result['photo'][$i], 'thumbnail');
+	      $result['photo'][$i]['thumb'] = $f2g->flickr->buildPhotoURLFromPhoto($result['photo'][$i], 'thumbnail');
 	      $result['photo'][$i]['oid'] = $f2g->flickr->people_getInfo($result['photo'][$i]['owner']);
 	    }
 	    
@@ -247,4 +247,4 @@
 	return array(null, array('body' => 'modules/Gallery2Flickr/templates/FlickrSearch.tpl'));
     }
 }
-?>
\ No newline at end of file
+?>

=== modified file 'classes/Gallery2Flickr.class.php'
--- classes/Gallery2Flickr.class.php	2007-06-02 02:11:48 +0000
+++ classes/Gallery2Flickr.class.php	2007-06-02 04:01:46 +0000
@@ -155,8 +155,11 @@
 
 	$g2id = (int)$g2id;
 
+    $photo_size = $this->flickr->photos_getSizes($photo_id);
+    $photo_url = $this->flickr->buildPhotoURLFromSizes($photo_size,
+        'original');
+
 	$photo = $this->flickr->photos_getInfo($photo_id);
-	$photo_url = $this->flickr->buildPhotoURL($photo, 'original');
 
 	/* Define basic information */
 	$mimeType = 'image/jpeg';
@@ -586,4 +589,4 @@
 	return array(null, $token);
     }
 
-}
\ No newline at end of file
+}

=== modified file 'classes/phpFlickr/phpFlickr.php'
--- classes/phpFlickr/phpFlickr.php	2007-06-02 02:11:48 +0000
+++ classes/phpFlickr/phpFlickr.php	2007-06-02 04:01:46 +0000
@@ -321,40 +321,64 @@
     
     /* These functions are front ends for the flickr calls */
     
-    function buildPhotoURL ($photo, $size = "Medium") 
+    function buildPhotoURLFromPhoto ($photo, $size = "Medium") 
     {
         //receives an array (can use the individual photo data returned 
         //from an API call) and returns a URL (doesn't mean that the 
         //file size exists)
+
+        // Note that this is entirely unreliable for 'Large' and 'Original'
+        // sizes for free users. Use buildPhotoURLFromSizes where uncertain
 		if ($this->service == "23") {
 			$url = "http://www.23hq.com/";
 		} else {
-			$url = "http://static.flickr.com/";
+			$url = "http://farm". $photo["farm"] . ".static.flickr.com/";
         }
-        $url .= $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'];
+        $secret = $photo['secret'];
+        $ext .= ".jpg";
         switch (strtolower($size)) {
             case "square":
-                $url .= "_s";
+                $append = "_s";
                 break;
             case "thumbnail":
-                $url .= "_t";
+                $append = "_t";
                 break;
             case "small":
-                $url .= "_m";
+                $append = "_m";
                 break;
             case "medium":
-                $url .= "";
+                $append = "";
                 break;
             case "large":
-                $url .= "_b";
+                $append = "_b";
                 break;
             case "original":
-                $url .= "_o";
+                $secret = $photo['originalsecret'];
+                $ext = $photo["originalformat"];
+                $append = "_o";
                 break;
         }
-        $url .= ".jpg";
+        $url .= $photo['server'] . "/" . $photo['id'] . "_" . $secret .  $append . $ext;
         return $url;
     }
+
+    function buildPhotoURLFromSizes ($photo_sizes, $size = "Medium") 
+    {
+        foreach ($photo_sizes as $one_size) {
+            if (strtolower($size) == strtolower($one_size["label"])){
+                return $one_size["source"];
+            }
+        }
+        // if we've missed out here, and the label is "original", try again
+        // with "large", since Free users won't have "original"
+        foreach ($photo_sizes as $one_size) {
+            if ("large" == strtolower($one_size["label"])){
+                return $one_size["source"];
+            }
+        }
+        trigger_error("No size!");
+        return "";
+    }
     
     function getFriendlyGeodata($lat, $lon) {
         /* I've added this method to get the friendly geodata (i.e. 'in New York, NY') that the

