You are here

function _flickr_block_group_random in Flickr 6

Random from group block.

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

File

block/flickr_block.module, line 561

Code

function _flickr_block_group_random($group_id, $show_n, $size, $media) {

  // Get a list of "all" the photos in the group. This is cached.
  $response = flickr_request('flickr.groups.pools.getPhotos', array(
    'group_id' => $group_id,
    // Get as many images as possible.
    'per_page' => 500,
    'extras' => 'owner',
    'media' => $media,
  ));
  if (!$response) {
    return;
  }

  // Randomly display $show_n of them.
  $photos = $response['photos']['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++) {
    $output .= theme('flickr_block_photo', $photos[$i], $size);
  }
  return $output;
}