diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-08-29 21:05:16 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-08-29 21:05:16 +0000 |
commit | 44063e1cf19ad80f1a7e72b2c7e70a305297043b (patch) | |
tree | b067173596c69a197986f39c62c8e3c9c16d0574 /modules/user/user.module | |
parent | d4d43f11eacc7f566d612a19c176a8c4ac867df6 (diff) | |
download | brdo-44063e1cf19ad80f1a7e72b2c7e70a305297043b.tar.gz brdo-44063e1cf19ad80f1a7e72b2c7e70a305297043b.tar.bz2 |
- Patch #505214 by pwolanin: make the search module a slightly better framework.
Diffstat (limited to 'modules/user/user.module')
-rw-r--r-- | modules/user/user.module | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/modules/user/user.module b/modules/user/user.module index 94cea8afd..72ffbfdcb 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -795,39 +795,46 @@ function user_file_delete($file) { } /** - * Implement hook_search(). + * Implement hook_search_info(). */ -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); - $query = db_select('users')->extend('PagerDefault'); - $query->fields('users', array('name', 'uid', 'mail')); - if (user_access('administer users')) { - // Administrators can also search in the otherwise private email field. - $query->condition(db_or()-> - where('LOWER(name) LIKE LOWER(:name)', array(':name' => "%$keys%"))-> - where('LOWER(mail) LIKE LOWER(:mail)', array(':mail' => "%$keys%"))); - } - else { - $query->where('LOWER(name) LIKE LOWER(:name)', array(':name' => "%$keys%")); - } - $result = $query - ->limit(15) - ->execute(); - foreach ($result as $account) { - $find[] = array('title' => $account->name . ' (' . $account->mail . ')', 'link' => url('user/' . $account->uid, array('absolute' => TRUE))); - } - return $find; - } +function user_search_info() { + return array( + 'title' => 'Users', + ); +} + +/** + * Implement hook_search_access(). + */ +function user_search_access() { + return user_access('access user profiles'); +} + +/** + * Implement hook_search_execute(). + */ +function user_search_execute($keys = NULL) { + $find = array(); + // Replace wildcards with MySQL/PostgreSQL wildcards. + $keys = preg_replace('!\*+!', '%', $keys); + $query = db_select('users')->extend('PagerDefault'); + $query->fields('users', array('name', 'uid', 'mail')); + if (user_access('administer users')) { + // Administrators can also search in the otherwise private email field. + $query->condition(db_or()-> + where('LOWER(name) LIKE LOWER(:name)', array(':name' => "%$keys%"))-> + where('LOWER(mail) LIKE LOWER(:mail)', array(':mail' => "%$keys%"))); + } + else { + $query->where('LOWER(name) LIKE LOWER(:name)', array(':name' => "%$keys%")); + } + $result = $query + ->limit(15) + ->execute(); + foreach ($result as $account) { + $find[] = array('title' => $account->name . ' (' . $account->mail . ')', 'link' => url('user/' . $account->uid, array('absolute' => TRUE))); } + return $find; } /** |