You are here

function flickrgallery_wrapper_albums in FlickrGallery 7.3

Same name and namespace in other branches
  1. 7 flickrgallery.module \flickrgallery_wrapper_albums()
  2. 7.2 flickrgallery.module \flickrgallery_wrapper_albums()

List Flickr albums

1 call to flickrgallery_wrapper_albums()
flickrgallery_block_view in ./flickrgallery.module
Implements hook_block_view().
1 string reference to 'flickrgallery_wrapper_albums'
flickrgallery_menu in ./flickrgallery.module
Implements hook_menu().

File

includes/flickrgallery.pages.inc, line 6

Code

function flickrgallery_wrapper_albums() {
  $build = array();

  // Create Flickr object.
  $f = flickrapi_phpFlickr();

  // Check for private pictures
  $token = variable_get('flickrgallery_token', NULL);
  $private = variable_get('flickrgallery_private_pictures', 0);
  if (!empty($token) && $private == 1) {
    $f
      ->setToken($token);
  }

  // Get Flickr User info and User ID.
  $flickr_user = $f
    ->people_getInfo(variable_get('flickrgallery_userID', NULL));
  $flickr_uid = $flickr_user['id'];

  // Get Flickr sets.
  if (variable_get('flickrgallery_displaysets_bool') == 1) {

    // If true, then select the flickrgallery_displaysets_values
    $array_set = array_map('trim', explode("\n", trim(variable_get('flickrgallery_displaysets_values'))));
    foreach ($array_set as $key => $set) {
      $sets['photoset'][$key] = $f
        ->photosets_getInfo($set);
    }
  }
  else {
    $sets = $f
      ->photosets_getList($flickr_uid);
  }
  if (!empty($sets)) {
    $albums = array();
    $flickr_path = variable_get('flickrgallery_path', 'flickr');
    foreach ($sets['photoset'] as $set) {
      if (variable_get('flickrgallery_display_type') == 1 && module_exists('image') && module_exists('imagecache_external')) {
        $img = array(
          '#theme' => 'imagecache_external',
          '#style_name' => variable_get('flickrgallery_albums_imagestyle', 'thumbnail'),
          '#path' => "https://farm" . $set['farm'] . ".static.flickr.com/" . $set['server'] . "/" . $set['primary'] . "_" . $set['secret'] . "_b.jpg",
        );
      }
      else {
        $img = array(
          '#theme' => 'image',
          '#path' => "https://farm" . $set['farm'] . ".staticflickr.com/" . $set['server'] . "/" . $set['primary'] . "_" . $set['secret'] . "_" . variable_get('flickrgallery_albums', 's') . ".jpg",
        );
      }

      // Add default attributes
      $img += array(
        '#title' => $set['title']['_content'],
        '#alt' => $set['title']['_content'],
        '#attributes' => array(
          'class' => 'flickrgallery-set-image',
        ),
      );
      $image_link = array(
        '#theme' => 'link',
        '#path' => $flickr_path . "/set/" . $set['id'],
        '#text' => drupal_render($img),
        '#options' => array(
          'html' => TRUE,
          'attributes' => array(
            'class' => array(
              'flickrgallery',
            ),
            'title' => $set['title']['_content'],
          ),
        ),
      );
      $title_link = array(
        '#theme' => 'link',
        '#path' => $flickr_path . "/set/" . $set['id'],
        '#text' => $set['title']['_content'],
        '#options' => array(
          'html' => TRUE,
          'attributes' => array(
            'class' => array(
              'flickrgallery-title',
            ),
            'title' => $set['title']['_content'],
          ),
        ),
      );
      $albums[] = array(
        'info' => $set,
        'total' => $set['photos'],
        'image_link' => drupal_render($image_link),
        'title_link' => drupal_render($title_link),
      );
    }
    $build = array(
      '#theme' => 'flickrgallery_albums',
      '#description' => t(variable_get('flickrgallery_description', NULL)),
      '#albums' => $albums,
    );
  }
  else {
    drupal_set_message(t('No picture albums available'), 'error');
  }

  // Return the output.
  return drupal_render($build);
}