flickrgallery.module in FlickrGallery 6.2
Same filename and directory in other branches
This module shows the sets and photo's from a Flickr account
File
flickrgallery.moduleView source
<?php
/**
* @file
* This module shows the sets and photo's from a Flickr account
*/
/**
* Implementation of hook_help()
*/
function flickrgallery_help($path, $arg) {
if ($path == 'admin/help#flickrgallery') {
return '<p>' . t('This module shows the sets and photo\'s from a Flickr account.') . '</p>';
}
}
/**
* Implementation of hook_perm()
*/
function flickrgallery_perm() {
return array(
'view photosets',
'administer flickr settings',
);
}
/**
* Implementation of hook_menu()
*/
function flickrgallery_menu() {
$items = array();
$items['admin/settings/flickr'] = array(
'title' => 'Flickr settings',
'description' => 'Configure options for the flickr Gallery module',
'page callback' => 'flickrgallery_admin_settings',
'access arguments' => array(
'administer flickr settings',
),
);
$items['flickr'] = array(
'title' => 'Flickr Gallery',
'page callback' => 'flickrgallery_albums',
'access arguments' => array(
'view photosets',
),
'type' => MENU_NORMAL_ITEM,
'weight' => -100,
);
$items['flickr/set/%'] = array(
'title' => 'Flickr Gallery Set',
'page callback' => 'flickrgallery_set',
'access arguments' => array(
'view photosets',
),
'type' => MENU_CALLBACK,
);
return $items;
}
function flickrgallery_admin_settings() {
return drupal_get_form('flickrgallery_settings_form');
}
function flickrgallery_settings_form() {
$form = array();
// Check if phpFlickr.php is in place
_flickrgallery_check_file();
$options = array(
's' => t('small square 75x75'),
't' => t('thumbnail, 100 on longest side'),
'm' => t('small, 240 on longest side'),
'z' => t('medium 640, 640 on longest side'),
'b' => t('large, 1024 on longest side'),
);
$sizes = array(
"square" => t('small square 75x75'),
"thumbnail" => t('thumbnail, 100 on longest side'),
"small" => t('small, 240 on longest side'),
"medium_640" => t('medium 640, 640 on longest side'),
"large" => t('large, 1024 on longest side'),
);
$form['flickrgallery_apikey'] = array(
'#type' => 'textfield',
'#title' => t('API Key'),
'#description' => t('Fill in your API key.') . ' ' . l('Get your API key', 'http://www.flickr.com/services/apps/by/me'),
'#default_value' => variable_get('flickrgallery_apikey', NULL),
);
$form['flickrgallery_secretkey'] = array(
'#type' => 'textfield',
'#title' => t('Secret Key'),
'#description' => t('Fill in your secret key.') . ' ' . l('Get your secret key', 'http://www.flickr.com/services/apps/by/me'),
'#default_value' => variable_get('flickrgallery_secretkey', NULL),
);
$form['flickrgallery_userID'] = array(
'#type' => 'textfield',
'#title' => t('User ID'),
'#description' => t('Fill in your user ID.') . ' ' . l('Find your User ID', 'http://idgettr.com/'),
'#default_value' => variable_get('flickrgallery_userID', NULL),
);
$form['flickrgallery_title'] = array(
'#type' => 'textfield',
'#title' => t('Title sets page'),
'#description' => t('Provide a title for the sets page.'),
'#default_value' => variable_get('flickrgallery_title', NULL),
);
$form['flickrgallery_description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#description' => t('Provide a description for the sets page.'),
'#default_value' => variable_get('flickrgallery_description', NULL),
);
$form['flickrgallery_lightbox_type'] = array(
'#type' => 'textfield',
'#title' => t('Lightbox type'),
'#description' => t('Fill in what type of Lightbox you would like to use. Examples: lightbox, shadowbox, colorbox, ...<br />This field will be used as the link rel tag and class name. (You need to download these modules separately)'),
'#default_value' => variable_get('flickrgallery_lightbox_type', 'lightbox'),
);
$form['flickrgallery_albums'] = array(
'#type' => 'select',
'#title' => t('Display sets images size.'),
'#description' => t('Select the size for the sets images'),
'#default_value' => variable_get('flickrgallery_albums', 's'),
'#options' => $options,
);
$form['flickrgallery_thumb'] = array(
'#type' => 'select',
'#title' => t('Display thumbnails on a set page'),
'#description' => t('Select the size for the thumbnails on a set page.'),
'#default_value' => variable_get('flickrgallery_thumb', 'square'),
'#options' => $sizes,
);
$form['flickrgallery_large'] = array(
'#type' => 'select',
'#title' => t('Display large images from a set'),
'#description' => t('Select the size for the larger images'),
'#default_value' => variable_get('flickrgallery_large', 'b'),
'#options' => $sizes,
);
$form['flickrgallery_help'] = array(
'#type' => 'markup',
'#value' => '<div>' . t('When all settings are filled in correctly, you can visit your ') . l('Flickr Gallery', 'flickr') . '</div>',
);
return system_settings_form($form);
}
/**
* Implementation of hook_theme()
*/
function flickrgallery_theme() {
return array(
'flickrgallery_albums' => array(),
'flickrgallery_set' => array(
'arguments' => 'set',
),
);
}
function flickrgallery_albums() {
return theme('flickrgallery_albums');
}
function flickrgallery_set() {
return theme('flickrgallery_set', arg(2));
}
/**
* Helper function for checking required phpFlickr.php file
*/
function _flickrgallery_check_file() {
$library_path = libraries_get_path('phpFlickr');
if (file_exists($library_path . '/phpFlickr.php')) {
return TRUE;
}
else {
if (user_access('administer flickr settings')) {
drupal_set_message(t('You need to download and place phpFlickr.php inside sites/all/libraries/phpFlickr: ') . l('http://code.google.com/p/phpflickr/', 'http://code.google.com/p/phpflickr/'), 'error');
}
return FALSE;
}
}
function theme_flickrgallery_albums() {
// Check if phpFlickr file is downloaded
if (_flickrgallery_check_file()) {
// Require phpFlickr.php
require_once libraries_get_path('phpFlickr') . "/phpFlickr.php";
// Add CSS file
drupal_add_css(drupal_get_path('module', 'flickrgallery') . '/flickrgallery.css');
// Set custom title
drupal_set_title(variable_get('flickrgallery_title', 'Flickr Gallery'));
// Create Flickr object
$f = new phpFlickr(variable_get('flickrgallery_apikey', ''), variable_get('flickrgallery_secretkey', NULL));
// 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
$sets = $f
->photosets_getList($flickr_uid);
// Start output
$output = "<div id='flickrgallery'>";
$output .= "<div id='flickrgallery-description'>" . variable_get('flickrgallery_description', NULL) . "</div>";
$output .= "<div id='flickrgallery-albums'>";
// Check if $sets isn't empty
if (!empty($sets)) {
foreach ($sets['photoset'] as $set) {
$thumbUrl = "http://farm" . $set['farm'] . ".static.flickr.com/" . $set['server'] . "/" . $set['primary'] . "_" . $set['secret'] . "_" . variable_get('flickrgallery_albums', 's') . ".jpg";
$img = theme_image($thumbUrl, $set['title'], $set['title'], NULL, FALSE);
$output .= "<div class='flickr-wrap'>";
$output .= l($img, "flickr/set/" . $set['id'], array(
'attributes' => array(
'class' => 'flickrgallery',
'title' => $set['title'],
),
'html' => 'true',
));
$output .= l($set['title'], "flickr/set/" . $set['id'], array(
'attributes' => array(
'class' => 'flickrgallery-title',
'title' => $set['title'],
),
'html' => 'true',
));
$output .= t('Total') . ": " . $set['photos'] . "\n";
$output .= "</div>";
}
}
else {
// If no sets, display msg
$output .= "<h2>" . t("No pictures available") . "</h2>";
}
$output .= '</div>';
$output .= '</div>';
return $output;
}
else {
return '';
}
}
function theme_flickrgallery_set($set_id = 0) {
// Check if phpFlickr file is downloaded
if (_flickrgallery_check_file()) {
// Require phpFlickr.php
require_once libraries_get_path('phpFlickr') . "/phpFlickr.php";
// Add CSS file
drupal_add_css(drupal_get_path('module', 'flickrgallery') . '/flickrgallery.css');
// Create Flickr object
$f = new phpFlickr(variable_get('flickrgallery_apikey', NULL), variable_get('flickrgallery_secretkey', NULL));
// Get Flickr set title
$set_info = $f
->photosets_getInfo($set_id);
// Set Flickr set title as page title
drupal_set_title($set_info['title']);
// Get Flickr photos for this set
$photos = $f
->photosets_getPhotos($set_id);
// If there aren't any photo's, display message
if (empty($set_id) || empty($photos)) {
drupal_set_message("This set doesn't exists or there aren't any pictures available for this set.", "error");
}
// Get the type for Lightbox
$type = variable_get('flickrgallery_lightbox_type', NULL);
// Start the output
$output = "<div id='flickrgallery'>";
$output .= '<div id="flickrgallery-set">';
foreach ($photos['photoset']['photo'] as $photo) {
$img = theme_image($f
->buildPhotoURL($photo, variable_get('flickrgallery_thumb', 'square')), $photo['title'], $photo['title'], NULL, FALSE);
$output .= "<div class='flickr-wrap'>";
$output .= l($img, $f
->buildPhotoURL($photo, variable_get('flickrgallery_large', 'large')), array(
'attributes' => array(
'class' => 'flickrgallery-image ' . $type,
'rel' => $type . "[flickrgallery]",
'title' => $photo['title'],
),
'html' => 'true',
));
if (!empty($photo['title'])) {
$output .= "<div class='flickrgallery-picture-title'>" . $photo['title'] . '</div>';
}
$output .= "</div>";
}
$output .= "<div class='flickrgallery-return'>" . l(t('Back to sets'), 'flickr') . "</div>";
$output .= "</div>";
$output .= '</div>';
return $output;
}
else {
return '';
}
}
Functions
Name![]() |
Description |
---|---|
flickrgallery_admin_settings | |
flickrgallery_albums | |
flickrgallery_help | Implementation of hook_help() |
flickrgallery_menu | Implementation of hook_menu() |
flickrgallery_perm | Implementation of hook_perm() |
flickrgallery_set | |
flickrgallery_settings_form | |
flickrgallery_theme | Implementation of hook_theme() |
theme_flickrgallery_albums | |
theme_flickrgallery_set | |
_flickrgallery_check_file | Helper function for checking required phpFlickr.php file |