flickr_sets.module in Flickr 7
Same filename and directory in other branches
The Flickr sets module.
File
sets/flickr_sets.moduleView source
<?php
/**
* @file
* The Flickr sets module.
*/
// Load flickr_sets.admin.inc from the flickr_sets module.
module_load_include('inc', 'flickr_sets', 'flickr_sets.admin');
/**
* Implements hook_help().
*/
function flickr_sets_help($path, $arg) {
switch ($path) {
case 'admin/help#flickr_sets':
// Return a line-break version of the README.txt.
return _filter_autop(file_get_contents(dirname(__FILE__) . '/README.txt'));
}
}
/**
* Implements hook_menu().
*/
function flickr_sets_menu() {
$items['flickr/%user/sets'] = array(
'title' => 'Sets',
'description' => 'Display the Flickr photosets for the specified user',
'page callback' => 'flickr_sets_photosets',
'page arguments' => array(
1,
),
'access callback' => 'flickr_photos_access',
'access arguments' => array(
1,
),
);
$items['flickr/%user/sets/list'] = array(
'title' => 'List',
'description' => 'Display the Flickr photosets for the specified user',
'type' => MENU_LOCAL_TASK,
);
$items['flickr/%user/sets/%flickr_set'] = array(
'page callback' => 'flickr_sets_photoset',
'page arguments' => array(
1,
3,
),
'access callback' => 'flickr_photos_access',
'access arguments' => array(
1,
),
);
return $items;
}
/**
* Get the list of photos in a set.
*/
function flickr_set_load($sid, $page = 1) {
// TODO: Why this called for /flickr and does not show for admin role?
if (is_numeric($sid)) {
return flickr_request('flickr.photosets.getPhotos', array(
'photoset_id' => $sid,
'page' => $page,
'per_page' => variable_get('flickr_photos_per_page', 20),
));
}
}
/**
* Set a user's photosets page title.
*/
function flickr_sets_page_title($user) {
if (isset($user->name)) {
return t('Flickr photosets') . ' - ' . $user->name;
}
return t('Flickr photosets');
}
/**
* Return a user's photosets (one thumb per set).
*/
function flickr_sets_photosets($account, $nsid = NULL) {
global $pager_page_array, $pager_total, $pager_total_items, $user;
drupal_set_title(flickr_sets_page_title($user));
$uid = $account->uid;
$nsid = $account->flickr['nsid'];
// Set this to something else if you want multiple pagers.
$element = 0;
$pager_page_array[$element] = empty($_GET['page']) ? 0 : (int) $_GET['page'];
$per_page = variable_get('flickr_sets_per_page', 8);
// First we need the complete list of sets just for the pager info.
$set_response = flickr_photosets_getlist($nsid);
$pager_total[$element] = ceil(count($set_response) / variable_get('flickr_sets_per_page', 8));
$pager_total_items[$element] = count($set_response);
// Now we only get the sets for the corresponding page.
$set_response = flickr_photosets_getlist($nsid, $pager_page_array[$element] + 1);
if ($set_response === FALSE) {
drupal_set_message(t("Error retrieving %user's photosets from Flickr", array(
'%user' => $account->name,
)));
return '';
}
if (!$set_response || empty($set_response)) {
drupal_set_message(t('%user has no photosets', array(
'%user' => $account->name,
)));
return '';
}
return theme('flickr_sets_photosets', array(
'uid' => $uid,
'per_page' => $per_page,
'nsid' => $nsid,
'photosets' => $set_response,
));
}
/**
* Return a user's photos from a given set.
*/
function flickr_sets_photoset($account, $set) {
global $pager_page_array, $pager_total, $pager_total_items, $user;
$uid = $account->uid;
$nsid = $account->flickr['nsid'];
$id = $set['photoset']['id'];
$set_info = flickr_photosets_getinfo($id);
// Make sure that $nsid is the real owner of $id.
if ($nsid != $set_info['owner']) {
drupal_goto('flickr/' . $uid . '/sets');
}
// Display photos.
// Set this to something else if you want multiple pagers.
$element = 0;
$pager_page_array[$element] = empty($_GET['page']) ? 0 : (int) $_GET['page'];
$per_page = variable_get('flickr_sets_photos_per_set', 6);
// Request set of photos.
$set_response = flickr_set_load($id, $pager_page_array[$element] + 1);
if (!$set_response) {
drupal_set_message(t("Error retrieving :setid's photosets from Flickr"), array(
':setid',
$id,
));
return '';
}
elseif (!isset($set_response['photoset']['photo']) || empty($set_response['photoset']['photo'])) {
drupal_set_message(t('This photoset is empty'));
return '';
}
// Set pager information we just acquired.
$pager_total_items[$element] = $set_response['photoset']['total'];
$pager_total[$element] = $set_response['photoset']['pages'];
return theme('flickr_sets_photoset', array(
'uid' => $uid,
'per_page' => $per_page,
'photo_arr' => $set_response,
'set_info' => $set_info,
));
}
/**
* Implements hook_theme().
*/
function flickr_sets_theme() {
return array(
'flickr_sets_photosets' => array(
'variables' => array(
'uid',
'nsid',
'photosets',
),
),
'flickr_sets_photoset' => array(
'variables' => array(
'uid',
'per_page',
'photo_arr',
'set_info',
),
),
'flickr_sets_photoset_box' => array(
'variables' => array(
'size' => NULL,
'format' => NULL,
),
),
);
}
/**
* Theme a user's photosets (one thumb per set).
*/
function theme_flickr_sets_photosets($variables) {
$uid = $variables['uid'];
$per_page = $variables['per_page'];
$nsid = $variables['nsid'];
$photosets = $variables['photosets'];
$output = theme('pager', array(
'quantity' => variable_get('flickr_sets_per_page', 8),
));
$output .= "<div class='flickr-photosets'>\n";
foreach ((array) $photosets as $photoset) {
$output .= theme('flickr_sets_photoset_box', array(
'photoset' => $photoset,
'uid' => $uid,
'nsid' => $nsid,
'size' => variable_get('flickr_sets_thumb_default_size', 's'),
));
}
$output .= '</div>';
$output .= theme('pager', array(
'quantity' => variable_get('flickr_sets_per_page', 8),
));
return $output;
}
/**
* Theme photos in a given set.
*/
function theme_flickr_sets_photoset($variables) {
$uid = $variables['uid'];
$per_page = $variables['per_page'];
$photo_arr = $variables['photo_arr'];
$set_info = $variables['set_info'];
$output = theme('pager', array(
'quantity' => variable_get('flickr_sets_photos_per_set', 6),
));
$output .= flickr_album('photoset', $set_info['id'], $per_page, NULL, 'photos', '', '', 101, 'unsorted', 'h1', NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, $photo_arr['photoset']['page']);
$output .= theme('pager', array(
'quantity' => variable_get('flickr_photos_per_page', 6),
));
return $output;
}
/**
* Theme a user's photos in a given set.
*/
function theme_flickr_sets_photoset_box($variables) {
$uid = $variables['uid'];
$photoset = $variables['photoset'];
$size = $variables['size'];
$format = $variables['format'];
$title = is_array($photoset['title']) ? $photoset['title']['_content'] : $photoset['title'];
$output = "<div class='flickr-photoset-box'>\n";
$output .= l(flickr_img($photoset, $size), "flickr/{$uid}/sets/{$photoset['id']}", array(
'html' => TRUE,
)) . "\n";
$output .= '<div class="flickr-photoset-title">' . l($title, "flickr/{$uid}/sets/{$photoset['id']}") . "</div>\n";
$output .= '<div class="flickr-photoset-count">' . format_plural($photoset['photos'], '@count photo', '@count photos') . "</div>\n";
$output .= "</div>\n";
return $output;
}
Functions
Name | Description |
---|---|
flickr_sets_help | Implements hook_help(). |
flickr_sets_menu | Implements hook_menu(). |
flickr_sets_page_title | Set a user's photosets page title. |
flickr_sets_photoset | Return a user's photos from a given set. |
flickr_sets_photosets | Return a user's photosets (one thumb per set). |
flickr_sets_theme | Implements hook_theme(). |
flickr_set_load | Get the list of photos in a set. |
theme_flickr_sets_photoset | Theme photos in a given set. |
theme_flickr_sets_photosets | Theme a user's photosets (one thumb per set). |
theme_flickr_sets_photoset_box | Theme a user's photos in a given set. |