You are here

function _flickr_block_photoset_random in Flickr 6

1 call to _flickr_block_photoset_random()
flickr_block in block/flickr_block.module
Implements hook_block().

File

block/flickr_block.module, line 523

Code

function _flickr_block_photoset_random($nsid, $show_n, $size, $media, $photoset_id) {

  // Get information about the photoset, including the owner.
  $info = flickr_photoset_get_info($photoset_id);
  if (!$info) {
    return;
  }
  $response = flickr_request('flickr.photosets.getPhotos', array(
    'photoset_id' => $photoset_id,
    'per_page' => 500,
    'extras' => 'owner',
    'media' => $media,
  ));
  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;
}