Support user profile URL search term in api_users_search()

This commit is contained in:
Hypolite Petovan 2019-12-12 17:04:08 -05:00
parent 9d626516d8
commit 0069bb022d
1 changed files with 19 additions and 14 deletions

View File

@ -1416,32 +1416,37 @@ function api_users_search($type)
$userlist = []; $userlist = [];
if (!empty($_GET['q'])) { if (!empty($_GET['q'])) {
$r = q("SELECT id FROM `contact` WHERE `uid` = 0 AND `name` = '%s'", DBA::escape($_GET["q"])); $contacts = Contact::selectToArray(
['id'],
[
'`uid` = 0 AND (`name` = ? OR `nick` = ? OR `url` = ? OR `addr` = ?)',
$_GET['q'],
$_GET['q'],
$_GET['q'],
$_GET['q'],
]
);
if (!DBA::isResult($r)) { if (DBA::isResult($contacts)) {
$r = q("SELECT `id` FROM `contact` WHERE `uid` = 0 AND `nick` = '%s'", DBA::escape($_GET["q"]));
}
if (DBA::isResult($r)) {
$k = 0; $k = 0;
foreach ($r as $user) { foreach ($contacts as $contact) {
$user_info = api_get_user($a, $user["id"]); $user_info = api_get_user($a, $contact['id']);
if ($type == "xml") { if ($type == 'xml') {
$userlist[$k++.":user"] = $user_info; $userlist[$k++ . ':user'] = $user_info;
} else { } else {
$userlist[] = $user_info; $userlist[] = $user_info;
} }
} }
$userlist = ["users" => $userlist]; $userlist = ['users' => $userlist];
} else { } else {
throw new BadRequestException("User ".$_GET["q"]." not found."); throw new NotFoundException('User ' . $_GET['q'] . ' not found.');
} }
} else { } else {
throw new BadRequestException("No user specified."); throw new BadRequestException('No search term specified.');
} }
return api_format_data("users", $type, $userlist); return api_format_data('users', $type, $userlist);
} }
/// @TODO move to top of file or somewhere better /// @TODO move to top of file or somewhere better