|
|
|
@ -230,146 +230,138 @@ class SearchApiV2Service
|
|
|
|
if (Helpers::validateLocalUrl($query)) {
|
|
|
|
if (Helpers::validateLocalUrl($query)) {
|
|
|
|
if (Str::contains($query, '/p/') || Str::contains($query, 'i/web/post/')) {
|
|
|
|
if (Str::contains($query, '/p/') || Str::contains($query, 'i/web/post/')) {
|
|
|
|
return $this->resolveLocalStatus();
|
|
|
|
return $this->resolveLocalStatus();
|
|
|
|
} elseif (Str::contains($query, 'i/web/profile/')) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Str::contains($query, 'i/web/profile/')) {
|
|
|
|
return $this->resolveLocalProfileId();
|
|
|
|
return $this->resolveLocalProfileId();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return $this->resolveLocalProfile();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return $this->resolveLocalProfile();
|
|
|
|
if (! Helpers::validateUrl($query) && !str_contains($query, '@')) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! Helpers::validateUrl($query) && !str_contains($query, '@')) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
! Str::startsWith($query, 'http') &&
|
|
|
|
|
|
|
|
Str::substrCount($query, '@') == 1 &&
|
|
|
|
|
|
|
|
str_contains($query, '@') &&
|
|
|
|
|
|
|
|
!str_starts_with($query, '@')
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
$res = WebfingerService::lookup('@'.$query, $mastodonMode);
|
|
|
|
|
|
|
|
} catch (\Exception) {
|
|
|
|
return $default;
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($res && isset($res['id'], $res['url'])) {
|
|
|
|
if (
|
|
|
|
$domain = strtolower(parse_url($res['url'], PHP_URL_HOST));
|
|
|
|
! Str::startsWith($query, 'http') &&
|
|
|
|
if (in_array($domain, $banned)) {
|
|
|
|
Str::substrCount($query, '@') == 1 &&
|
|
|
|
|
|
|
|
str_contains($query, '@') &&
|
|
|
|
|
|
|
|
!str_starts_with($query, '@')
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
$res = WebfingerService::lookup('@'.$query, $mastodonMode);
|
|
|
|
|
|
|
|
} catch (\Exception) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($res && isset($res['id'], $res['url'])) {
|
|
|
|
$paginated = collect($res)->take($limit)->skip($offset)->toArray();
|
|
|
|
$domain = strtolower(parse_url($res['url'], PHP_URL_HOST));
|
|
|
|
if (! empty($paginated)) {
|
|
|
|
if (in_array($domain, $banned)) {
|
|
|
|
$default['accounts'][] = $paginated;
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$paginated = collect($res)->take($limit)->skip($offset)->toArray();
|
|
|
|
|
|
|
|
if (! empty($paginated)) {
|
|
|
|
|
|
|
|
$default['accounts'][] = $paginated;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$default['accounts'] = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return $default;
|
|
|
|
$default['accounts'] = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Str::substrCount($query, '@') == 2) {
|
|
|
|
return $default;
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
$res = WebfingerService::lookup($query, $mastodonMode);
|
|
|
|
return $default;
|
|
|
|
} catch (\Exception) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Str::substrCount($query, '@') == 2) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
$res = WebfingerService::lookup($query, $mastodonMode);
|
|
|
|
|
|
|
|
} catch (\Exception) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($res && isset($res['id'])) {
|
|
|
|
|
|
|
|
$domain = strtolower(parse_url($res['url'], PHP_URL_HOST));
|
|
|
|
|
|
|
|
if (in_array($domain, $banned)) {
|
|
|
|
return $default;
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($res && isset($res['id'])) {
|
|
|
|
$paginated = collect($res)->take($limit)->skip($offset)->toArray();
|
|
|
|
$domain = strtolower(parse_url($res['url'], PHP_URL_HOST));
|
|
|
|
if (! empty($paginated)) {
|
|
|
|
if (in_array($domain, $banned)) {
|
|
|
|
$default['accounts'][] = $paginated;
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$paginated = collect($res)->take($limit)->skip($offset)->toArray();
|
|
|
|
|
|
|
|
if (! empty($paginated)) {
|
|
|
|
|
|
|
|
$default['accounts'][] = $paginated;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$default['accounts'] = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return $default;
|
|
|
|
$default['accounts'] = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sid = Status::whereUri($query)->first()) {
|
|
|
|
|
|
|
|
$s = StatusService::get($sid->id, false);
|
|
|
|
|
|
|
|
if (! $s || isset($s['account']['moved'], $s['account']['moved']['id'])) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_array($s['visibility'], ['public', 'unlisted'])) {
|
|
|
|
|
|
|
|
$default['statuses'][] = $s;
|
|
|
|
|
|
|
|
|
|
|
|
if ($sid = Status::whereUri($query)->first()) {
|
|
|
|
return $default;
|
|
|
|
$s = StatusService::get($sid->id, false);
|
|
|
|
}
|
|
|
|
if (! $s || isset($s['account']['moved'], $s['account']['moved']['id'])) {
|
|
|
|
}
|
|
|
|
return $default;
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
$res = ActivityPubFetchService::get($query);
|
|
|
|
if (in_array($s['visibility'], ['public', 'unlisted'])) {
|
|
|
|
|
|
|
|
$default['statuses'][] = $s;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
if ($res) {
|
|
|
|
|
|
|
|
$json = json_decode($res, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (! $json || ! isset($json['@context']) || ! isset($json['type']) || ! in_array($json['type'], ['Note', 'Person'])) {
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
'accounts' => [],
|
|
|
|
|
|
|
|
'hashtags' => [],
|
|
|
|
|
|
|
|
'statuses' => [],
|
|
|
|
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
switch ($json['type']) {
|
|
|
|
$res = ActivityPubFetchService::get($query);
|
|
|
|
case 'Note':
|
|
|
|
|
|
|
|
$obj = Helpers::statusFetch($query);
|
|
|
|
|
|
|
|
if (! $obj || ! isset($obj['id'])) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$note = $mastodonMode ?
|
|
|
|
|
|
|
|
StatusService::getMastodon($obj['id'], false) :
|
|
|
|
|
|
|
|
StatusService::get($obj['id'], false);
|
|
|
|
|
|
|
|
if (! $note) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! isset($note['visibility']) || ! in_array($note['visibility'], ['public', 'unlisted'])) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$default['statuses'][] = $note;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'Person':
|
|
|
|
|
|
|
|
$obj = Helpers::profileFetch($query);
|
|
|
|
|
|
|
|
if (! $obj) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_array($obj['domain'], $banned)) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$default['accounts'][] = $mastodonMode ?
|
|
|
|
|
|
|
|
AccountService::getMastodon($obj['id'], true) :
|
|
|
|
|
|
|
|
AccountService::get($obj['id'], true);
|
|
|
|
|
|
|
|
|
|
|
|
if ($res) {
|
|
|
|
return $default;
|
|
|
|
$json = json_decode($res, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (! $json || ! isset($json['@context']) || ! isset($json['type']) || ! in_array($json['type'], ['Note', 'Person'])) {
|
|
|
|
default:
|
|
|
|
return [
|
|
|
|
return [
|
|
|
|
'accounts' => [],
|
|
|
|
'accounts' => [],
|
|
|
|
'hashtags' => [],
|
|
|
|
'hashtags' => [],
|
|
|
|
'statuses' => [],
|
|
|
|
'statuses' => [],
|
|
|
|
];
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch ($json['type']) {
|
|
|
|
|
|
|
|
case 'Note':
|
|
|
|
|
|
|
|
$obj = Helpers::statusFetch($query);
|
|
|
|
|
|
|
|
if (! $obj || ! isset($obj['id'])) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$note = $mastodonMode ?
|
|
|
|
|
|
|
|
StatusService::getMastodon($obj['id'], false) :
|
|
|
|
|
|
|
|
StatusService::get($obj['id'], false);
|
|
|
|
|
|
|
|
if (! $note) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! isset($note['visibility']) || ! in_array($note['visibility'], ['public', 'unlisted'])) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$default['statuses'][] = $note;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'Person':
|
|
|
|
|
|
|
|
$obj = Helpers::profileFetch($query);
|
|
|
|
|
|
|
|
if (! $obj) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_array($obj['domain'], $banned)) {
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$default['accounts'][] = $mastodonMode ?
|
|
|
|
|
|
|
|
AccountService::getMastodon($obj['id'], true) :
|
|
|
|
|
|
|
|
AccountService::get($obj['id'], true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
'accounts' => [],
|
|
|
|
|
|
|
|
'hashtags' => [],
|
|
|
|
|
|
|
|
'statuses' => [],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (\Exception) {
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
'accounts' => [],
|
|
|
|
|
|
|
|
'hashtags' => [],
|
|
|
|
|
|
|
|
'statuses' => [],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (\Exception) {
|
|
|
|
return $default;
|
|
|
|
return [
|
|
|
|
|
|
|
|
'accounts' => [],
|
|
|
|
|
|
|
|
'hashtags' => [],
|
|
|
|
|
|
|
|
'statuses' => [],
|
|
|
|
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|