You are here

function user_menu in Drupal 5

Same name and namespace in other branches
  1. 4 modules/user.module \user_menu()
  2. 6 modules/user/user.module \user_menu()
  3. 7 modules/user/user.module \user_menu()

Implementation of hook_menu().

File

modules/user/user.module, line 703
Enables the user registration and login system.

Code

function user_menu($may_cache) {
  global $user;
  $items = array();
  $admin_access = user_access('administer users');
  $access_access = user_access('administer access control');
  $view_access = user_access('access user profiles');
  if ($may_cache) {
    $items[] = array(
      'path' => 'user',
      'title' => t('User account'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'user_login',
      ),
      'access' => !$user->uid,
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'user/autocomplete',
      'title' => t('User autocomplete'),
      'callback' => 'user_autocomplete',
      'access' => $view_access,
      'type' => MENU_CALLBACK,
    );

    // Registration and login pages.
    $items[] = array(
      'path' => 'user/login',
      'title' => t('Log in'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'user_login',
      ),
      'access' => !$user->uid,
      'type' => MENU_DEFAULT_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'user/register',
      'title' => t('Create new account'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'user_register',
      ),
      'access' => !$user->uid && variable_get('user_register', 1),
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'user/password',
      'title' => t('Request new password'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'user_pass',
      ),
      'access' => !$user->uid,
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'user/reset',
      'title' => t('Reset password'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'user_pass_reset',
      ),
      'access' => TRUE,
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'user/help',
      'title' => t('Help'),
      'callback' => 'user_help_page',
      'type' => MENU_CALLBACK,
    );

    // Admin user pages
    $items[] = array(
      'path' => 'admin/user',
      'title' => t('User management'),
      'description' => t('Manage your site\'s users, groups and access to site features.'),
      'position' => 'left',
      'callback' => 'system_admin_menu_block_page',
      'access' => user_access('administer site configuration'),
    );
    $items[] = array(
      'path' => 'admin/user/user',
      'title' => t('Users'),
      'description' => t('List, add, and edit users.'),
      'callback' => 'user_admin',
      'callback arguments' => array(
        'list',
      ),
      'access' => $admin_access,
    );
    $items[] = array(
      'path' => 'admin/user/user/list',
      'title' => t('List'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -10,
    );
    $items[] = array(
      'path' => 'admin/user/user/create',
      'title' => t('Add user'),
      'callback' => 'user_admin',
      'callback arguments' => array(
        'create',
      ),
      'access' => $admin_access,
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/user/settings',
      'title' => t('User settings'),
      'description' => t('Configure default behavior of users, including registration requirements, e-mails, and user pictures.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'user_admin_settings',
      ),
    );

    // Admin access pages
    $items[] = array(
      'path' => 'admin/user/access',
      'title' => t('Access control'),
      'description' => t('Determine access to features by selecting permissions for roles.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'user_admin_perm',
      ),
      'access' => $access_access,
    );
    $items[] = array(
      'path' => 'admin/user/roles',
      'title' => t('Roles'),
      'description' => t('List, edit, or add user roles.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'user_admin_new_role',
      ),
      'access' => $access_access,
      'type' => MENU_NORMAL_ITEM,
    );
    $items[] = array(
      'path' => 'admin/user/roles/edit',
      'title' => t('Edit role'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'user_admin_role',
      ),
      'access' => $access_access,
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'admin/user/rules',
      'title' => t('Access rules'),
      'description' => t('List and create rules to disallow usernames, e-mail addresses, and IP addresses.'),
      'callback' => 'user_admin_access',
      'access' => $access_access,
    );
    $items[] = array(
      'path' => 'admin/user/rules/list',
      'title' => t('List'),
      'access' => $access_access,
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -10,
    );
    $items[] = array(
      'path' => 'admin/user/rules/add',
      'title' => t('Add rule'),
      'callback' => 'user_admin_access_add',
      'access' => $access_access,
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/user/rules/check',
      'title' => t('Check rules'),
      'callback' => 'user_admin_access_check',
      'access' => $access_access,
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/user/rules/edit',
      'title' => t('Edit rule'),
      'callback' => 'user_admin_access_edit',
      'access' => $access_access,
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'admin/user/rules/delete',
      'title' => t('Delete rule'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'user_admin_access_delete_confirm',
      ),
      'access' => $access_access,
      'type' => MENU_CALLBACK,
    );
    if (module_exists('search')) {
      $items[] = array(
        'path' => 'admin/user/search',
        'title' => t('Search users'),
        'description' => t('Search users by name.'),
        'callback' => 'user_admin',
        'callback arguments' => array(
          'search',
        ),
        'access' => $admin_access,
        'type' => MENU_NORMAL_ITEM,
      );
    }

    // Your personal page
    if ($user->uid) {
      $items[] = array(
        'path' => 'user/' . $user->uid,
        'title' => t('My account'),
        'callback' => 'user_view',
        'callback arguments' => array(
          arg(1),
        ),
        'access' => TRUE,
        'type' => MENU_DYNAMIC_ITEM,
      );
    }
    $items[] = array(
      'path' => 'logout',
      'title' => t('Log out'),
      'access' => $user->uid,
      'callback' => 'user_logout',
      'weight' => 10,
    );
  }
  else {

    // Add the CSS for this module. We put this in !$may_cache so it is only
    // added once per request.
    drupal_add_css(drupal_get_path('module', 'user') . '/user.css', 'module');
    if ($_GET['q'] == 'user' && $user->uid) {

      // We want to make the current user's profile accessible without knowing
      // their uid, so just linking to /user is enough.
      drupal_goto('user/' . $user->uid);
    }
    if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0) {
      $account = user_load(array(
        'uid' => arg(1),
      ));
      if ($user !== FALSE) {

        // Always let a user view their own account
        $view_access |= $user->uid == arg(1);

        // Only admins can view blocked accounts
        $view_access &= $account->status || $admin_access;
        $items[] = array(
          'path' => 'user/' . arg(1),
          'title' => t('User'),
          'type' => MENU_CALLBACK,
          'callback' => 'user_view',
          'callback arguments' => array(
            arg(1),
          ),
          'access' => $view_access,
        );
        $items[] = array(
          'path' => 'user/' . arg(1) . '/view',
          'title' => t('View'),
          'access' => $view_access,
          'type' => MENU_DEFAULT_LOCAL_TASK,
          'weight' => -10,
        );
        $items[] = array(
          'path' => 'user/' . arg(1) . '/edit',
          'title' => t('Edit'),
          'callback' => 'drupal_get_form',
          'callback arguments' => array(
            'user_edit',
          ),
          'access' => $admin_access || $user->uid == arg(1),
          'type' => MENU_LOCAL_TASK,
        );
        $items[] = array(
          'path' => 'user/' . arg(1) . '/delete',
          'title' => t('Delete'),
          'callback' => 'user_edit',
          'access' => $admin_access,
          'type' => MENU_CALLBACK,
        );
        if (arg(2) == 'edit') {
          if (($categories = _user_categories($account)) && count($categories) > 1) {
            foreach ($categories as $key => $category) {
              $items[] = array(
                'path' => 'user/' . arg(1) . '/edit/' . $category['name'],
                'title' => $category['title'],
                'type' => $category['name'] == 'account' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
                'weight' => $category['weight'],
                'access' => $admin_access || $user->uid == arg(1),
              );
            }
          }
        }
      }
    }
  }
  return $items;
}