You are here

function user_category_load in Drupal 6

Same name and namespace in other branches
  1. 7 modules/user/user.module \user_category_load()

Return a user object after checking if any profile category in the path exists.

File

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

Code

function user_category_load($uid, &$map, $index) {
  static $user_categories, $accounts;

  // Cache $account - this load function will get called for each profile tab.
  if (!isset($accounts[$uid])) {
    $accounts[$uid] = user_load($uid);
  }
  $valid = TRUE;
  if (($account = $accounts[$uid]) && isset($map[$index + 1]) && $map[$index + 1] == 'edit') {

    // Since the path is like user/%/edit/category_name, the category name will
    // be at a position 2 beyond the index corresponding to the % wildcard.
    $category_index = $index + 2;

    // Valid categories may contain slashes, and hence need to be imploded.
    $category_path = implode('/', array_slice($map, $category_index));
    if ($category_path) {

      // Check that the requested category exists.
      $valid = FALSE;
      if (!isset($user_categories)) {
        $empty_account = new stdClass();
        $user_categories = _user_categories($empty_account);
      }
      foreach ($user_categories as $category) {
        if ($category['name'] == $category_path) {
          $valid = TRUE;

          // Truncate the map array in case the category name had slashes.
          $map = array_slice($map, 0, $category_index);

          // Assign the imploded category name to the last map element.
          $map[$category_index] = $category_path;
          break;
        }
      }
    }
  }
  return $valid ? $account : FALSE;
}