function flickrgallery_set in FlickrGallery 7.3
Same name and namespace in other branches
- 6.2 flickrgallery.module \flickrgallery_set()
- 7 flickrgallery.module \flickrgallery_set()
- 7.2 flickrgallery.module \flickrgallery_set()
1 string reference to 'flickrgallery_set'
- flickrgallery_menu in ./
flickrgallery.module - Implements hook_menu().
File
- includes/
flickrgallery.pages.inc, line 109
Code
function flickrgallery_set($set_id) {
$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 set info.
$set_info = $f
->photosets_getInfo($set_id);
// Get total photo count
$count = $set_info['count_photos'];
// Load # images per page
$per_page = variable_get('flickrgallery_per_page', '500');
// Get page number from query params
$page = 0;
$params = drupal_get_query_parameters();
if (isset($params['page'])) {
$page = $params['page'];
}
// Get Flickr photos for this set.
$photos = $f
->photosets_getPhotos($set_id, NULL, NULL, $per_page, $page + 1);
// Limit the number of pictures?
if (variable_get('flickrgallery_display_itemsets_bool', 0) == 1) {
$number_sets = variable_get('flickrgallery_display_itemsets_values');
array_splice($photos['photoset']['photo'], $number_sets - 1, -1);
}
// If there aren't any photo's, display message.
if (empty($set_id) || empty($photos)) {
drupal_set_message(t('This set doesn\'t exists or there aren\'t any pictures available for this set.'), 'error');
return;
}
// Declare variables.
$photoset = array();
$image_meta = array();
foreach ($photos['photoset']['photo'] as $photo) {
$original_photo = $f
->buildPhotoURL($photo, variable_get('flickrgallery_large', 'large'));
if (variable_get('flickrgallery_display_type') == 1 && module_exists('image') && module_exists('imagecache_external')) {
$img = array(
'#theme' => 'imagecache_external',
'#style_name' => variable_get('flickrgallery_thumb_imagestyle', 'large'),
'#path' => $original_photo,
);
$url_external = imagecache_external_generate_path($original_photo, variable_get('flickrgallery_large_imagestyle', 'large'));
$url = image_style_url(variable_get('flickrgallery_large_imagestyle', 'large'), $url_external);
}
else {
$img = array(
'#theme' => 'image',
'#path' => $f
->buildPhotoURL($photo, variable_get('flickrgallery_thumb', 'square')),
);
$url = $original_photo;
}
// Add default attributes
$img += array(
'#title' => $photo['title'],
'#alt' => $photo['title'],
'#attributes' => array(
'class' => 'flickrgallery-set-image',
),
);
// Get META data for this image, only if flickrgallery_override is set to TRUE in the admin screen
// This will lead to slower performance
if (variable_get('flickrgallery_override') == TRUE) {
$image_meta = $f
->photos_getInfo($photo['id']);
}
// Get the type for Lightbox.
$type = variable_get('flickrgallery_lightbox_type', 'lighbox2');
$image = array(
'#theme' => 'link',
'#path' => $url,
'#text' => drupal_render($img),
'#options' => array(
'html' => TRUE,
'attributes' => array(
'class' => array(
'flickrgallery-image',
$type,
),
'rel' => $type . '[flickrgallery]',
'title' => $photo['title'],
),
),
);
$photoset_photo = array(
'#theme' => 'flickrgallery_photo',
'#image' => array(
'info' => $photo,
'image' => drupal_render($image),
),
'#image_meta' => $image_meta,
);
$photoset[] = drupal_render($photoset_photo);
}
// Build photoset
$build['flickrgallery_photoset'] = array(
'#theme' => 'flickrgallery_photoset',
'#photoset' => $photoset,
'#meta' => $set_info,
);
// Build pager
$current_page = pager_default_initialize($count, $per_page);
$build['pager'] = array(
'#theme' => 'pager',
'#quantity' => $count,
);
// Return the output.
return drupal_render($build);
}