--- block/flickr_block.module.orig	2009-01-15 22:02:41.000000000 +1100
+++ block/flickr_block.module	2009-01-15 23:13:42.000000000 +1100
@@ -17,6 +17,9 @@
     $blocks[4]['info'] = t('Flickr recent photosets');
     $blocks[5]['info'] = t('Flickr random photos');
 
+    // Photoset blocks
+    $blocks[6]['info'] = t('Flickr random photo from photoset');
+
     return $blocks;
 
   case 'configure':
@@ -29,7 +32,7 @@
     unset($size_options['b']);
     unset($size_options['o']);
 
-    $settings = variable_get('flickr_block_'. $delta, array('user_id' => '', 'show_n' => 4, 'size' => 's'));
+    $settings = variable_get('flickr_block_'. $delta, array('user_id' => '', 'show_n' => 4, 'size' => 's', 'photoset_id' => ''));
 
     $form = array();
     $form["flickr_block_{$delta}_user_id"] = array(
@@ -75,6 +78,15 @@
       break;
     case 5: // sitewide, random
       break;
+    case 6: // sitewide, random
+      $form["flickr_block_{$delta}_photoset"] = array(
+        '#type' => 'textfield',
+        '#title' => t('Flickr Photoset Id'),
+        '#default_value' => $settings['photoset_id'],
+        '#description' => t("The id of a Flickr photoset."),
+        '#required' => TRUE,
+      );
+      break;
     }
 
     return $form;
@@ -99,6 +111,15 @@
         'size' => $edit["flickr_block_{$delta}_size"],
       ));
       break;
+
+    case 6:
+      variable_set('flickr_block_'. $delta, array(
+        'user_id' => $edit["flickr_block_{$delta}_user_id"],
+        'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
+        'size' => $edit["flickr_block_{$delta}_size"],
+        'photoset_id' => $edit["flickr_block_{$delta}_photoset"],
+      ));
+
     }
     break;
 
@@ -149,6 +170,10 @@
       $block['subject'] = t('Flickr random photos');
       $block['content'] = _flickr_block_random($settings['user_id'], $settings['show_n'], $settings['size']);
     }
+    elseif ($delta == 6) {
+      $block['subject'] = t('Flickr random photoset photos');
+      $block['content'] = _flickr_block_photoset_random($settings['user_id'], $settings['show_n'], $settings['size'], $settings['photoset_id']);
+    }
     return $block;
   }
 }
@@ -189,17 +214,52 @@
       $index = rand(0, count($photos['photo']) - 1);
       $photo_id = $photos['photo'][$index]['id'];
       if (in_array($photo_id, $random_photos)) {
-        $i--; // photo already added 
-      } 
+        $i--; // photo already added
+      }
       else {
-        $random_photos[] = $photo_id; 
-        $output .= theme('flickr_block_photo', $photos['photo'][$index], $size); 
+        $random_photos[] = $photo_id;
+        $output .= theme('flickr_block_photo', $photos['photo'][$index], $size);
       }
     }
-  } 
+  }
   return $output;
 }
 
+function _flickr_block_photoset_random($nsid, $show_n, $size, $photoset_id) {
+  // Get information about the photoset, including the owner.
+  $info = flickr_photoset_get_info($photoset_id);
+  if (!$info) {
+    return;
+  }
+
+  // Get a list of "all" the photos in the photoset. This is cached.
+  $response = flickr_request('flickr.photosets.getPhotos',
+    array(
+      'photoset_id' => $photoset_id,
+      'per_page' => 500, // get as many images as possible
+      'extras' => 'owner',
+    )
+  );
+  if (!$response) {
+    return;
+  }
+
+  // Randomly display $show_n of them
+  $photos = $response['photoset']['photo'];
+  shuffle($photos);
+
+  // we shouldn't try to return more than the total number of photos
+  $output = '';
+  $to = min($show_n, count($photos));
+  for ($i = 0; $i < $to; $i++) {
+    //insert owner into $photo because theme_flickr_photo needs it
+    $photos[$i]['owner'] = $info['owner'];
+    $output .= theme('flickr_block_photo', $photos[$i], $size);
+  }
+  return $output;
+}
+
+
 /**
  * Implementation of hook_theme().
  */
