You are here

function flickr_menu in Flickr 5

Same name and namespace in other branches
  1. 6 flickr.module \flickr_menu()
  2. 7 flickr.module \flickr_menu()

Implementation of hook_menu().

File

./flickr.module, line 32

Code

function flickr_menu($may_cache) {
  global $user;
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/settings/flickr',
      'title' => t('Flickr'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'flickr_admin_settings',
      ),
      'access' => user_access('administer site configuration'),
      'type' => MENU_NORMAL_ITEM,
      'description' => t('Change settings for the flickr module.'),
    );
    $items[] = array(
      'path' => 'flickr',
      'title' => t('Flickr photos'),
      'access' => TRUE,
      'type' => MENU_CALLBACK,
      'callback' => 'flickr_photos',
      'description' => t('Flickr photos of default user id.'),
    );
    $items[] = array(
      'path' => 'flickr/auth',
      'access' => TRUE,
      'type' => MENU_CALLBACK,
      'callback' => 'flickr_auth_callback',
    );
  }
  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;

        //main flickr user page(photos)
        $items[] = array(
          'path' => 'flickr/' . arg(1),
          'title' => t("@user's Flickr", array(
            '@user' => $account->name,
          )),
          'type' => MENU_CALLBACK,
          'callback' => 'flickr_photos',
          'callback arguments' => array(
            arg(1),
          ),
          'access' => $view_access,
        );
        $items[] = array(
          'path' => 'flickr/' . arg(1) . '/photos',
          'title' => t('Photos'),
          'type' => MENU_DEFAULT_LOCAL_TASK,
          'weight' => -10,
          'access' => $view_access,
        );
      }
      elseif ($account !== FALSE && !isset($account->flickr['nsid'])) {
        drupal_set_message(t('%user does not have a Flickr account', array(
          '%user' => $account->name,
        )), 'error');
      }
    }
  }
  return $items;
}