You are here

function user_load in Drupal 5

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

Fetch a user object.

Parameters

$array: An associative array of attributes to search for in selecting the user, such as user name or e-mail address.

Return value

A fully-loaded $user object upon successful user load or FALSE if user cannot be loaded.

33 calls to user_load()
blog_feed_user in modules/blog/blog.module
Displays an RSS feed containing recent blog entries of a given user.
blog_page_user in modules/blog/blog.module
Displays a Drupal page containing recent blog entries of a given user.
comment_admin_settings in modules/comment/comment.module
Menu callback; presents the comment settings page.
comment_form_add_preview in modules/comment/comment.module
comment_validate in modules/comment/comment.module

... See full list

File

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

Code

function user_load($array = array()) {

  // Dynamically compose a SQL query:
  $query = array();
  $params = array();
  foreach ($array as $key => $value) {
    if ($key == 'uid' || $key == 'status') {
      $query[] = "{$key} = %d";
      $params[] = $value;
    }
    else {
      if ($key == 'pass') {
        $query[] = "pass = '%s'";
        $params[] = md5($value);
      }
      else {
        $query[] = "LOWER({$key}) = LOWER('%s')";
        $params[] = $value;
      }
    }
  }
  $result = db_query('SELECT * FROM {users} u WHERE ' . implode(' AND ', $query), $params);
  if (db_num_rows($result)) {
    $user = db_fetch_object($result);
    $user = drupal_unpack($user);
    $user->roles = array();
    if ($user->uid) {
      $user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
    }
    else {
      $user->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
    }
    $result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid);
    while ($role = db_fetch_object($result)) {
      $user->roles[$role->rid] = $role->name;
    }
    user_module_invoke('load', $array, $user);
  }
  else {
    $user = FALSE;
  }
  return $user;
}