1
0
Fork 0

Restructured variable handling

This commit is contained in:
Michael 2021-05-18 08:38:04 +00:00
parent 724a61390f
commit f935c1cf73

View file

@ -47,44 +47,34 @@ class Search extends BaseApi
$uid = self::getCurrentUserID(); $uid = self::getCurrentUserID();
$request = self::getRequest([ $request = self::getRequest([
'max_id' => 0, 'min_id' => 0, 'account_id' => 0, 'type' => '', 'exclude_unreviewed' => false, 'account_id' => 0, // If provided, statuses returned will be authored only by this account
'resolve' => false, 'q' => '', 'limit' => 20, 'offset' => 0, 'following' => false]); 'max_id' => 0, // Return results older than this id
'min_id' => 0, // Return results immediately newer than this id
// If provided, statuses returned will be authored only by this account 'type' => '', // Enum(accounts, hashtags, statuses)
$account_id = $request['account_id']; 'exclude_unreviewed' => false, // Filter out unreviewed tags? Defaults to false. Use true when trying to find trending tags.
// Return results older than this id 'q' => '', // The search query
$max_id = $request['max_id']; 'resolve' => false, // Attempt WebFinger lookup. Defaults to false.
// Return results immediately newer than this id 'limit' => 20, // Maximum number of results to load, per type. Defaults to 20. Max 40.
$min_id = $request['min_id']; 'offset' => 0, // Maximum number of results to load, per type. Defaults to 20. Max 40.
// Enum(accounts, hashtags, statuses) 'following' => false, // Only who the user is following. Defaults to false.
$type = $request['type']; ]);
// Filter out unreviewed tags? Defaults to false. Use true when trying to find trending tags.
$exclude_unreviewed = $request['exclude_unreviewed']; if (empty($request['q'])) {
// The search query
$q = $request['q'];
// Attempt WebFinger lookup. Defaults to false.
$resolve = $request['resolve'];
// Maximum number of results to load, per type. Defaults to 20. Max 40.
$limit = min($request['limit'], 40);
// Offset in search results. Used for pagination. Defaults to 0.
$offset = $request['offset'];
// Only who the user is following. Defaults to false.
$following = $request['following'];
if (empty($q)) {
DI::mstdnError()->UnprocessableEntity(); DI::mstdnError()->UnprocessableEntity();
} }
$limit = min($request['limit'], 40);
$result = ['accounts' => [], 'statuses' => [], 'hashtags' => []]; $result = ['accounts' => [], 'statuses' => [], 'hashtags' => []];
if (empty($type) || ($type == 'accounts')) { if (empty($request['type']) || ($request['type'] == 'accounts')) {
$result['accounts'] = self::searchAccounts($uid, $q, $resolve, $limit, $offset, $following); $result['accounts'] = self::searchAccounts($uid, $request['q'], $request['resolve'], $limit, $request['offset'], $request['following']);
} }
if ((empty($type) || ($type == 'statuses')) && (strpos($q, '@') == false)) { if ((empty($request['type']) || ($request['type'] == 'statuses')) && (strpos($request['q'], '@') == false)) {
$result['statuses'] = self::searchStatuses($uid, $q, $account_id, $max_id, $min_id, $limit, $offset); $result['statuses'] = self::searchStatuses($uid, $request['q'], $request['account_id'], $request['max_id'], $request['min_id'], $limit, $request['offset']);
} }
if ((empty($type) || ($type == 'hashtags')) && (strpos($q, '@') == false)) { if ((empty($request['type']) || ($request['type'] == 'hashtags')) && (strpos($request['q'], '@') == false)) {
$result['hashtags'] = self::searchHashtags($q, $exclude_unreviewed, $limit, $offset); $result['hashtags'] = self::searchHashtags($request['q'], $request['exclude_unreviewed'], $limit, $request['offset']);
} }
System::jsonExit($result); System::jsonExit($result);