View source
<?php
require_once drupal_get_path('module', 'flickr') . '/flickr.inc';
function flickr_sets_menu($may_cache) {
global $user;
$items = array();
if ($may_cache) {
}
else {
if (arg(0) == 'flickr' && is_numeric(arg(1)) && arg(1) > 0) {
$account = user_load(array(
'uid' => arg(1),
));
if ($account !== FALSE && isset($account->flickr['nsid'])) {
$nsid = $account->flickr['nsid'];
$admin_access = user_access('administer flickr');
$view_access |= user_access('view own flickr photos') && $user->uid == arg(1) || user_access('view all flickr photos');
$view_access &= $account->status || $admin_access;
$items[] = array(
'path' => 'flickr/' . arg(1) . '/sets',
'title' => t("Sets"),
'type' => MENU_LOCAL_TASK,
'callback' => 'flickr_sets_photosets',
'callback arguments' => array(
arg(1),
$nsid,
),
'access' => $view_access,
);
$items[] = array(
'path' => 'flickr/' . arg(1) . '/sets/list',
'title' => t("List"),
'type' => MENU_DEFAULT_LOCAL_TASK,
'access' => $view_access,
);
if (arg(3) != NULL && arg(2) == 'sets') {
$set_info = flickr_photoset_get_info(arg(3));
if ($set_info !== FALSE) {
$items[] = array(
'path' => 'flickr/' . arg(1) . '/sets/' . arg(3),
'title' => t("Set: !setname", array(
'!setname' => $set_info['title']['_content'],
)),
'type' => MENU_LOCAL_TASK,
'callback' => 'flickr_sets_photoset',
'callback arguments' => array(
arg(1),
$nsid,
arg(3),
$set_info,
),
'access' => $view_access,
);
}
}
}
}
}
return $items;
}
function flickr_sets_photosets($uid, $nsid) {
global $pager_page_array, $pager_total, $pager_total_items, $user;
drupal_add_css(drupal_get_path('module', 'flickr') . '/flickr.css');
$account = user_load(array(
'uid' => $uid,
));
$element = 0;
$pager_page_array[$element] = empty($_GET['page']) ? 0 : (int) $_GET['page'];
$set_response = flickr_photoset_get_list($nsid);
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 '';
}
$pager_total[$element] = ceil(count($set_response) / variable_get('flickr_photosets_per_page', 20));
$pager_total_items[$element] = count($set_response);
return theme('flickr_sets_photosets', $uid, $nsid, $set_response);
}
function flickr_sets_photoset($uid, $nsid, $set_id, $set_info) {
global $pager_page_array, $pager_total, $pager_total_items, $user;
drupal_add_css(drupal_get_path('module', 'flickr') . '/flickr.css');
if ($nsid != $set_info['owner']) {
drupal_goto('flickr/' . $uid . '/sets');
}
$element = 0;
$pager_page_array[$element] = empty($_GET['page']) ? 0 : (int) $_GET['page'];
$per_page = variable_get('flickr_photos_per_page', 20);
$set_response = flickr_request('flickr.photosets.getPhotos', array(
'photoset_id' => $set_id,
'page' => $pager_page_array[$element] + 1,
'per_page' => variable_get('flickr_photos_per_page', 20),
));
if (!$set_response) {
drupal_set_message(t('Error retrieving :setid\'s photosets from Flickr'), array(
':setid',
$set_id,
));
return '';
}
elseif (!isset($set_response['photoset']['photo']) || empty($set_response['photoset']['photo'])) {
drupal_set_message('This photoset is empty');
return '';
}
$pager_total_items[$element] = $set_response['photoset']['total'];
$pager_total[$element] = $set_response['photoset']['pages'];
return theme('flickr_sets_photoset', $uid, $per_page, $set_response, $set_info);
}
function theme_flickr_sets_photosets($uid, $nsid, $photosets) {
$output = theme('pager', NULL, variable_get('flickr_photosets_per_page', 20));
$output .= "<div class='fickr-photosets'>\n";
foreach ((array) $photosets as $photoset) {
$output .= theme('flickr_sets_photoset_box', $photoset, $uid, $nsid, 's');
}
$output .= '</div>';
$output .= theme('pager', NULL, variable_get('flickr_photosets_per_page', 20));
return $output;
}
function theme_flickr_sets_photoset($uid, $per_page, $photo_arr, $set_info) {
$output = theme('pager', NULL, variable_get('flickr_photos_per_page', 20));
$output .= "<div class='fickr-photoset'>\n";
foreach ((array) $photo_arr['photoset']['photo'] as $photo) {
$photo['owner'] = $set_info['owner'];
$output .= theme('flickr_photo_box', $photo, 'm');
}
$output .= '</div>';
$output .= theme('pager', NULL, variable_get('flickr_photos_per_page', 20));
return $output;
}
function theme_flickr_sets_photoset_box($ps, $uid, $owner, $size = NULL, $format = NULL) {
$title = is_array($ps['title']) ? $ps['title']['_content'] : $ps['title'];
$output .= "<div class='flickr-photoset-box'>\n";
$output .= l(flickr_img($ps, $size) . "\n", "flickr/{$uid}/sets/{$ps['id']}", array(), NULL, NULL, FALSE, TRUE);
$output .= l('<div class="flickr-photoset-title">' . $title . "</div>\n", "flickr/{$uid}/sets/{$ps['id']}", array(), NULL, NULL, FALSE, TRUE);
$output .= '<div class="flickr-photoset-count">' . format_plural($ps['photos'], '@count photo', '@count photos') . "</div>\n";
$output .= "</div>\n";
return $output;
}