Skip to content

Instantly share code, notes, and snippets.

@joshkoenig
Created January 17, 2013 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshkoenig/4560693 to your computer and use it in GitHub Desktop.
Save joshkoenig/4560693 to your computer and use it in GitHub Desktop.
/**
* Implementation of hook_search().
*/
function user_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) {
switch ($op) {
case 'name':
if ($skip_access_check || user_access('access user profiles')) {
return t('Users');
}
case 'search':
if (user_access('access user profiles')) {
$find = array();
// Replace wildcards with MySQL/PostgreSQL wildcards.
$keys = preg_replace('!\*+!', '%', $keys);
if (user_access('administer users')) {
<<<<<<< HEAD
// Administrators can also search in the otherwise private email field.
$result = pager_query("SELECT name, uid, mail FROM {users} WHERE name LIKE '%%%s%%' OR mail LIKE '%%%s%%'", 15, 0, NULL, $keys, $keys);
=======
// Administrators can also search in the otherwise private email
// field, and they don't need to be restricted to only active users.
$result = pager_query("SELECT name, uid, mail FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%') OR LOWER(mail) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys, $keys);
>>>>>>> b3ecb6e33f1d6edbbd8759b850a6aaa46760f9c6
while ($account = db_fetch_object($result)) {
$find[] = array('title' => $account->name .' ('. $account->mail .')', 'link' => url('user/'. $account->uid, array('absolute' => TRUE)));
}
}
else {
<<<<<<< HEAD
$result = pager_query("SELECT name, uid FROM {users} WHERE name LIKE '%%%s%%'", 15, 0, NULL, $keys);
=======
// Regular users can only search via user names, and we do not show
// them blocked accounts.
$result = pager_query("SELECT name, uid FROM {users} WHERE status = 1 AND LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys);
>>>>>>> b3ecb6e33f1d6edbbd8759b850a6aaa46760f9c6
while ($account = db_fetch_object($result)) {
$find[] = array('title' => $account->name, 'link' => url('user/'. $account->uid, array('absolute' => TRUE)));
}
}
return $find;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment