You are here

function _flickr_block_random in Flickr 5

Same name and namespace in other branches
  1. 6 block/flickr_block.module \_flickr_block_random()
1 call to _flickr_block_random()
flickr_block in block/flickr_block.module
Implementation of hook_block().

File

block/flickr_block.module, line 174

Code

function _flickr_block_random($nsid, $show_n, $size) {
  $output = '';
  if ($photos = flickr_photos_search($nsid, 1, array(
    'per_page' => 500,
  ))) {
    $page_count = $photos['pages'];

    // we shouldn't try to return more than the total number of photos
    $to = min($show_n, $photos['total']);
    $output = '';
    for ($i = 0; $i < $to; $i++) {
      sleep(0.125);

      // request a random page
      $photos = flickr_photos_search($nsid, rand(1, $page_count), array(
        'per_page' => 500,
      ));

      // then select a random photo
      $index = rand(0, count($photos['photo']) - 1);
      $output .= theme('flickr_block_photo', $photos['photo'][$index], $size);
    }
  }
  return $output;
}