You are here

function realname_search in Real Name 6

Implements hook_search().

File

./realname.module, line 606

Code

function realname_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) {
  if (!variable_get('realname_search_enable', FALSE)) {
    return;
  }
  switch ($op) {
    case 'name':
      if ($skip_access_check || user_access('access user profiles')) {
        return variable_get('realname_user_disable', FALSE) ? t('Users') : t('User names');
      }
      break;
    case 'reset':
      variable_set('realname_last_index', -1);
      break;
    case 'status':
      $start = variable_get('realname_last_index', -1) + 1;
      $total = db_result(db_query('SELECT COUNT(*) FROM {users} WHERE status = 1'));
      $remaining = db_result(db_query("SELECT COUNT(*) FROM {users} WHERE status = 1 AND uid >= %d", $start));
      return array(
        'remaining' => $remaining,
        'total' => $total,
      );
    case 'search':
      if ($skip_access_check || user_access('access user profiles')) {
        $results = array();
        $find = do_search($keys, 'realname');
        foreach ($find as $item) {
          if ($item->type != 'realname') {
            continue;
          }
          $account = user_load(array(
            'uid' => $item->sid,
          ));
          $realname = realname_make_name($account);
          $results[] = array(
            'link' => url('user/' . $account->uid, array(
              'absolute' => TRUE,
            )),
            'type' => t('User'),
            'title' => $realname,
            'user' => theme('username', $account) . '<div class="clear-block"></div>',
            'score' => $item->score,
            'snippet' => theme('user_picture', $account) . (user_access('administer users') ? t('Login name: @name', array(
              '@name' => $account->name,
            )) : NULL),
          );
        }
        return $results;
      }
      break;
  }
}