Some code to search flickr for images

  1. function _optotrip_block_flickr() {
  2.   $termtext = _optotrip_get_block_context();
  3.   if ($termtext == '') {
  4.     return NULL;
  5.   }
  6.  
  7.   $starttime = microtime(TRUE);
  8.  
  9.   lightbox2_add_files();
  10.  
  11.   // perform search
  12.   $args = array(
  13.     'text' => $termtext,
  14.     'per_page' => 16,
  15.     'sort' => 'interestingness-desc', // 'relevance',
  16.   );
  17.  
  18.   // if results found, emit block content
  19.   if ($photos = flickr_photos_search('', 1, $args)) {
  20.     $content = '<div class="myflickr">';
  21.     foreach ($photos['photo'] as $photo) {
  22.       $content .= theme('flickr_photo', $photo, 's', array('rel' => 'lightbox[flickr]') );
  23.       // print theme('flickr_photo_box', $photo, 's');
  24.     }
  25.     $content .= '</div>';
  26.     // HACK: add some padding to the flickr images
  27.     drupal_set_html_head('<style type="text/css" media="all">div.myflickr img { padding: 5px; }</style>');
  28.   }
  29.   else {
  30.     $content = t('No photos found');
  31.   }
  32.  
  33.   // dsm("_optotrip_block_flickr($termtext) ===> ". (microtime(TRUE) - $starttime));
  34.  
  35.   // return the block information
  36.   return array(
  37.     'subject' => t('Flickr for: @name', array('@name' => $termtext)),
  38.     'content' => $content,
  39.   );
  40. }