You are here

flickr_sets.module in Flickr 5

Same filename and directory in other branches
  1. 6 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';

/**
 * Implementation of hook_menu().
 */
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');

        // let a user view their own account or all if they have permission
        $view_access |= user_access('view own flickr photos') && $user->uid == arg(1) || user_access('view all flickr photos');

        // Only admins can view blocked accounts
        $view_access &= $account->status || $admin_access;

        //flickr user set page
        $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),
              // Don't check_plain because flickr does it for us.
              '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,
  ));

  //set this to something else if you want multiple pagers
  $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 '';
  }

  //set pager information we just acquired
  $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');

  //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_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 '';
  }

  //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);
}
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) {

    //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'>\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;
}