You are here

flickr_sets.module in Flickr 6

Same filename and directory in other branches
  1. 5 sets/flickr_sets.module
  2. 7 sets/flickr_sets.module

File

sets/flickr_sets.module
View source
<?php

require_once drupal_get_path('module', 'flickr') . '/flickr.inc';

/**
 * Implements hook_menu().
 */
function flickr_sets_menu() {
  $items['flickr/%user/sets'] = array(
    'title' => 'Sets',
    'description' => 'Display the Flickr photosets for the specified user',
    'type' => MENU_LOCAL_TASK,
    '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_DEFAULT_LOCAL_TASK,
  );
  $items['flickr/%user/sets/%flickr_set'] = array(
    'title' => 'Flickr photo set',
    'page callback' => 'flickr_sets_photoset',
    'page arguments' => array(
      1,
      3,
    ),
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
  return $items;
}
function flickr_set_load($sid, $page = 1) {

  // TODO: Not sure 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),
    ));
  }
}
function flickr_sets_photosets($account, $nsid = NULL) {
  global $pager_page_array, $pager_total, $pager_total_items, $user;
  if (variable_get('flickr_css', 1)) {
    drupal_add_css(drupal_get_path('module', 'flickr') . '/flickr.css');
  }
  $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_photos_per_page', 20);
  $set_response = flickr_photoset_get_list($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 '';
  }

  // Set pager information we just acquired.
  $pager_total[$element] = $set_response['pages'];
  $pager_total_items[$element] = $set_response['total'];
  return theme('flickr_sets_photosets', $uid, $per_page, $nsid, $set_response['photoset']);
}
function flickr_sets_photoset($account, $set) {
  global $pager_page_array, $pager_total, $pager_total_items, $user;
  if (variable_get('flickr_css', 1)) {
    drupal_add_css(drupal_get_path('module', 'flickr') . '/flickr.css');
  }
  $uid = $user->uid;
  $nsid = $account->flickr['nsid'];
  $set_id = $set['photoset']['id'];
  $set_info = flickr_photoset_get_info($set_id);

  // Make sure that $nsid is the real owner of $set_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_photos_per_page', 20);

  // Request set photos.
  $set_response = flickr_set_load($set_id, $pager_page_array[$element] + 1);
  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 '';
  }

  // 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', $uid, $per_page, $set_response, $set_info);
}

/**
 * Implements hook_theme().
 */
function flickr_sets_theme() {
  return array(
    'flickr_sets_photosets' => array(
      'arguments' => array(
        'uid',
        'per_page',
        'nsid',
        'photosets',
      ),
    ),
    'flickr_sets_photoset' => array(
      'arguments' => array(
        'uid',
        'per_page',
        'photo_arr',
        'set_info',
      ),
    ),
    'flickr_sets_photoset_box' => array(
      'arguments' => array(
        'ps',
        'uid',
        'owner',
        'size' => 'NULL',
        'format' => NULL,
      ),
    ),
  );
}
function theme_flickr_sets_photosets($uid, $per_page, $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) {

    // Insert owner into $photo because
    // theme_flickr_photo_box/flickr_photo_page_url needs it.
    $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'>";
  $output .= l(flickr_img($ps, $size), "flickr/{$uid}/sets/{$ps['id']}", array(
    'html' => TRUE,
  ));
  $output .= '<div class="flickr-photoset-title">' . l($title, "flickr/{$uid}/sets/{$ps['id']}") . '</div>';
  $output .= '<div class="flickr-photoset-count">' . format_plural($ps['photos'], '1 photo', '@count photos') . '</div>';
  $output .= "</div>";
  return $output;
}