FreeNetwork.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <?php
  2. declare(strict_types = 1);
  3. // {{{ License
  4. // This file is part of GNU social - https://www.gnu.org/software/social
  5. //
  6. // GNU social is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // GNU social is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  18. // }}}
  19. namespace Component\FreeNetwork;
  20. use App\Core\DB;
  21. use App\Core\Event;
  22. use App\Core\GSFile;
  23. use App\Core\HTTPClient;
  24. use function App\Core\I18n\_m;
  25. use App\Core\Log;
  26. use App\Core\Modules\Component;
  27. use App\Core\Router;
  28. use App\Entity\Activity;
  29. use App\Entity\Actor;
  30. use App\Entity\LocalUser;
  31. use App\Entity\Note;
  32. use App\Util\Common;
  33. use App\Util\Exception\ClientException;
  34. use App\Util\Exception\NicknameEmptyException;
  35. use App\Util\Exception\NicknameException;
  36. use App\Util\Exception\NicknameInvalidException;
  37. use App\Util\Exception\NicknameNotAllowedException;
  38. use App\Util\Exception\NicknameTakenException;
  39. use App\Util\Exception\NicknameTooLongException;
  40. use App\Util\Exception\NoSuchActorException;
  41. use App\Util\Exception\ServerException;
  42. use App\Util\Formatting;
  43. use App\Util\Nickname;
  44. use Component\FreeNetwork\Controller\Feeds;
  45. use Component\FreeNetwork\Controller\HostMeta;
  46. use Component\FreeNetwork\Controller\OwnerXrd;
  47. use Component\FreeNetwork\Controller\Webfinger;
  48. use Component\FreeNetwork\Util\Discovery;
  49. use Component\FreeNetwork\Util\WebfingerResource;
  50. use Component\FreeNetwork\Util\WebfingerResource\WebfingerResourceActor;
  51. use Component\FreeNetwork\Util\WebfingerResource\WebfingerResourceNote;
  52. use Doctrine\Common\Collections\ExpressionBuilder;
  53. use EventResult;
  54. use Exception;
  55. use const PREG_SET_ORDER;
  56. use Symfony\Component\HttpFoundation\JsonResponse;
  57. use Symfony\Component\HttpFoundation\Response;
  58. use XML_XRD;
  59. use XML_XRD_Element_Link;
  60. /**
  61. * Implements WebFinger (RFC7033) for GNU social, as well as Link-based Resource Descriptor Discovery based on RFC6415,
  62. * Web Host Metadata ('.well-known/host-meta') resource.
  63. *
  64. * @package GNUsocial
  65. *
  66. * @author Mikael Nordfeldth <mmn@hethane.se>
  67. * @author Diogo Peralta Cordeiro <mail@diogo.site>
  68. */
  69. class FreeNetwork extends Component
  70. {
  71. public const PLUGIN_VERSION = '0.1.0';
  72. public const OAUTH_ACCESS_TOKEN_REL = 'http://apinamespace.org/oauth/access_token';
  73. public const OAUTH_REQUEST_TOKEN_REL = 'http://apinamespace.org/oauth/request_token';
  74. public const OAUTH_AUTHORIZE_REL = 'http://apinamespace.org/oauth/authorize';
  75. private static array $protocols = [];
  76. public function onInitializeComponent(): EventResult
  77. {
  78. Event::handle('AddFreeNetworkProtocol', [&self::$protocols]);
  79. return Event::next;
  80. }
  81. public function onAddRoute(Router $m): EventResult
  82. {
  83. // Feeds
  84. $m->connect('feed_network', '/feed/network', [Feeds::class, 'network']);
  85. $m->connect('feed_clique', '/feed/clique', [Feeds::class, 'clique']);
  86. $m->connect('feed_federated', '/feed/federated', [Feeds::class, 'federated']);
  87. $m->connect('freenetwork_hostmeta', '.well-known/host-meta', [HostMeta::class, 'handle']);
  88. $m->connect(
  89. 'freenetwork_hostmeta_format',
  90. '.well-known/host-meta.:format',
  91. [HostMeta::class, 'handle'],
  92. ['format' => '(xml|json)'],
  93. );
  94. // the resource GET parameter can be anywhere, so don't mention it here
  95. $m->connect('freenetwork_webfinger', '.well-known/webfinger', [Webfinger::class, 'handle']);
  96. $m->connect(
  97. 'freenetwork_webfinger_format',
  98. '.well-known/webfinger.:format',
  99. [Webfinger::class, 'handle'],
  100. ['format' => '(xml|json)'],
  101. );
  102. $m->connect('freenetwork_ownerxrd', 'main/ownerxrd', [OwnerXrd::class, 'handle']);
  103. return Event::next;
  104. }
  105. public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): EventResult
  106. {
  107. DB::persist(\App\Entity\Feed::create(['actor_id' => $actor_id, 'url' => Router::url($route = 'feed_network'), 'route' => $route, 'title' => _m('Meteorites'), 'ordering' => $ordering++]));
  108. DB::persist(\App\Entity\Feed::create(['actor_id' => $actor_id, 'url' => Router::url($route = 'feed_clique'), 'route' => $route, 'title' => _m('Planetary System'), 'ordering' => $ordering++]));
  109. DB::persist(\App\Entity\Feed::create(['actor_id' => $actor_id, 'url' => Router::url($route = 'feed_federated'), 'route' => $route, 'title' => _m('Galaxy'), 'ordering' => $ordering++]));
  110. return Event::next;
  111. }
  112. public function onStartGetProfileAcctUri(Actor $profile, &$acct): EventResult
  113. {
  114. $wfr = new WebFingerResourceActor($profile);
  115. try {
  116. $acct = $wfr->reconstructAcct();
  117. } catch (Exception) {
  118. return Event::next;
  119. }
  120. return Event::stop;
  121. }
  122. /**
  123. * Last attempts getting a WebFingerResource object
  124. *
  125. * @param string $resource String that contains the requested URI
  126. * @param null|WebfingerResource $target WebFingerResource extended object goes here
  127. * @param array $args Array which may contains arguments such as 'rel' filtering values
  128. *
  129. * @throws NicknameEmptyException
  130. * @throws NicknameException
  131. * @throws NicknameInvalidException
  132. * @throws NicknameNotAllowedException
  133. * @throws NicknameTakenException
  134. * @throws NicknameTooLongException
  135. * @throws NoSuchActorException
  136. * @throws ServerException
  137. */
  138. public function onEndGetWebFingerResource(string $resource, ?WebfingerResource &$target = null, array $args = []): EventResult
  139. {
  140. // * Either we didn't find the profile, then we want to make
  141. // the $profile variable null for clarity.
  142. // * Or we did find it but for a possibly malicious remote
  143. // user who might've set their profile URL to a Note URL
  144. // which would've caused a sort of DoS unless we continue
  145. // our search here by discarding the remote profile.
  146. $profile = null;
  147. if (Discovery::isAcct($resource)) {
  148. $parts = explode('@', mb_substr(urldecode($resource), 5)); // 5 is strlen of 'acct:'
  149. if (\count($parts) === 2) {
  150. [$nick, $domain] = $parts;
  151. if ($domain !== Common::config('site', 'server')) {
  152. throw new ServerException(_m('Remote profiles not supported via WebFinger yet.'));
  153. }
  154. $nick = Nickname::normalize(nickname: $nick, check_already_used: false, check_is_allowed: false);
  155. $freenetwork_actor = LocalUser::getByPK(['nickname' => $nick]);
  156. if (!($freenetwork_actor instanceof LocalUser)) {
  157. throw new NoSuchActorException($nick);
  158. }
  159. $profile = $freenetwork_actor->getActor();
  160. }
  161. } else {
  162. try {
  163. if (Common::isValidHttpUrl($resource)) {
  164. // This means $resource is a valid url
  165. $resource_parts = parse_url($resource);
  166. // TODO: Use URLMatcher
  167. if ($resource_parts['host'] === Common::config('site', 'server')) {
  168. $str = $resource_parts['path'];
  169. // actor_view_nickname
  170. $renick = '/\/@(' . Nickname::DISPLAY_FMT . ')\/?/m';
  171. // actor_view_id
  172. $reuri = '/\/actor\/(\d+)\/?/m';
  173. if (preg_match_all($renick, $str, $matches, PREG_SET_ORDER, 0) === 1) {
  174. $profile = LocalUser::getByPK(['nickname' => $matches[0][1]])->getActor();
  175. } elseif (preg_match_all($reuri, $str, $matches, PREG_SET_ORDER, 0) === 1) {
  176. $profile = Actor::getById((int) $matches[0][1]);
  177. }
  178. }
  179. }
  180. } catch (NoSuchActorException $e) {
  181. // not a User, maybe a Note? we'll try that further down...
  182. // try {
  183. // Log::debug(__METHOD__ . ': Finding User_group URI for WebFinger lookup on resource==' . $resource);
  184. // $group = new User_group();
  185. // $group->whereAddIn('uri', array_keys($alt_urls), $group->columnType('uri'));
  186. // $group->limit(1);
  187. // if ($group->find(true)) {
  188. // $profile = $group->getProfile();
  189. // }
  190. // unset($group);
  191. // } catch (Exception $e) {
  192. // Log::error(get_class($e) . ': ' . $e->getMessage());
  193. // throw $e;
  194. // }
  195. }
  196. }
  197. if ($profile instanceof Actor) {
  198. Log::debug(__METHOD__ . ': Found Profile with ID==' . $profile->getID() . ' for resource==' . $resource);
  199. $target = new WebfingerResourceActor($profile);
  200. return Event::stop; // We got our target, stop handler execution
  201. }
  202. if (!\is_null($note = DB::findOneBy(Note::class, ['url' => $resource], return_null: true))) {
  203. $target = new WebfingerResourceNote($note);
  204. return Event::stop; // We got our target, stop handler execution
  205. }
  206. return Event::next;
  207. }
  208. public function onStartHostMetaLinks(array &$links): EventResult
  209. {
  210. foreach (Discovery::supportedMimeTypes() as $type) {
  211. $links[] = new XML_XRD_Element_Link(
  212. Discovery::LRDD_REL,
  213. Router::url(id: 'freenetwork_webfinger', args: [], type: Router::ABSOLUTE_URL) . '?resource={uri}',
  214. $type,
  215. isTemplate: true,
  216. );
  217. }
  218. // TODO OAuth connections
  219. //$links[] = new XML_XRD_Element_link(self::OAUTH_ACCESS_TOKEN_REL, common_local_url('ApiOAuthAccessToken'));
  220. //$links[] = new XML_XRD_Element_link(self::OAUTH_REQUEST_TOKEN_REL, common_local_url('ApiOAuthRequestToken'));
  221. //$links[] = new XML_XRD_Element_link(self::OAUTH_AUTHORIZE_REL, common_local_url('ApiOAuthAuthorize'));
  222. return Event::next;
  223. }
  224. /**
  225. * Add a link header for LRDD Discovery
  226. *
  227. * @param mixed $action
  228. */
  229. public function onStartShowHTML($action): EventResult
  230. {
  231. if ($action instanceof ShowstreamAction) {
  232. $resource = $action->getTarget()->getUri();
  233. $url = common_local_url('webfinger') . '?resource=' . urlencode($resource);
  234. foreach ([Discovery::JRD_MIMETYPE, Discovery::XRD_MIMETYPE] as $type) {
  235. header('Link: <' . $url . '>; rel="' . Discovery::LRDD_REL . '"; type="' . $type . '"', false);
  236. }
  237. }
  238. return Event::next;
  239. }
  240. public function onStartDiscoveryMethodRegistration(Discovery $disco): EventResult
  241. {
  242. $disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodWebfinger');
  243. return Event::next;
  244. }
  245. public function onEndDiscoveryMethodRegistration(Discovery $disco): EventResult
  246. {
  247. $disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodHostMeta');
  248. $disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodLinkHeader');
  249. $disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodLinkHtml');
  250. return Event::next;
  251. }
  252. /**
  253. * @throws ClientException
  254. * @throws ServerException
  255. */
  256. public function onControllerResponseInFormat(string $route, array $accept_header, array $vars, ?Response &$response = null): EventResult
  257. {
  258. if (!\in_array($route, ['freenetwork_hostmeta', 'freenetwork_hostmeta_format', 'freenetwork_webfinger', 'freenetwork_webfinger_format', 'freenetwork_ownerxrd'])) {
  259. return Event::next;
  260. }
  261. $mimeType = array_intersect(array_values(Discovery::supportedMimeTypes()), $accept_header);
  262. /*
  263. * "A WebFinger resource MUST return a JRD as the representation
  264. * for the resource if the client requests no other supported
  265. * format explicitly via the HTTP "Accept" header. [...]
  266. * The WebFinger resource MUST silently ignore any requested
  267. * representations that it does not understand and support."
  268. * -- RFC 7033 (WebFinger)
  269. * http://tools.ietf.org/html/rfc7033
  270. */
  271. $mimeType = \count($mimeType) !== 0 ? array_pop($mimeType) : $vars['default_mimetype'];
  272. $headers = [];
  273. if (Common::config('discovery', 'cors')) {
  274. $headers['Access-Control-Allow-Origin'] = '*';
  275. }
  276. $headers['Content-Type'] = $mimeType;
  277. $response = match ($mimeType) {
  278. Discovery::XRD_MIMETYPE => new Response(content: $vars['xrd']->to('xml'), headers: $headers),
  279. Discovery::JRD_MIMETYPE, Discovery::JRD_MIMETYPE_OLD => new JsonResponse(data: $vars['xrd']->to('json'), headers: $headers, json: true),
  280. };
  281. $response->headers->set('cache-control', 'no-store, no-cache, must-revalidate');
  282. return Event::stop;
  283. }
  284. /**
  285. * Webfinger matches: @user@example.com or even @user--one.george_orwell@1984.biz
  286. *
  287. * @param string $text The text from which to extract webfinger IDs
  288. * @param string $preMention Character(s) that signals a mention ('@', '!'...)
  289. *
  290. * @return array the matching IDs (without $preMention) and each respective position in the given string
  291. */
  292. public static function extractWebfingerIds(string $text, string $preMention = '@'): array
  293. {
  294. $wmatches = [];
  295. $result = preg_match_all(
  296. '/' . Nickname::BEFORE_MENTIONS . preg_quote($preMention, '/') . '(' . Nickname::WEBFINGER_FMT . ')/',
  297. $text,
  298. $wmatches,
  299. \PREG_OFFSET_CAPTURE,
  300. );
  301. if ($result === false) {
  302. Log::error(__METHOD__ . ': Error parsing webfinger IDs from text (preg_last_error==' . preg_last_error() . ').');
  303. return [];
  304. } elseif (($n_matches = \count($wmatches)) != 0) {
  305. Log::debug((sprintf('Found %d matches for WebFinger IDs: %s', $n_matches, print_r($wmatches, true))));
  306. }
  307. return $wmatches[1];
  308. }
  309. /**
  310. * Profile URL matches: @param string $text The text from which to extract URL mentions
  311. *
  312. * @param string $preMention Character(s) that signals a mention ('@', '!'...)
  313. *
  314. * @return array the matching URLs (without @ or acct:) and each respective position in the given string
  315. *
  316. * @example.com/mublog/user
  317. */
  318. public static function extractUrlMentions(string $text, string $preMention = '@'): array
  319. {
  320. $wmatches = [];
  321. // In the regexp below we need to match / _before_ URL_REGEX_VALID_PATH_CHARS because it otherwise gets merged
  322. // with the TLD before (but / is in URL_REGEX_VALID_PATH_CHARS anyway, it's just its positioning that is important)
  323. $result = preg_match_all(
  324. '/' . Nickname::BEFORE_MENTIONS . preg_quote($preMention, '/') . '(' . URL_REGEX_DOMAIN_NAME . '(?:\/[' . URL_REGEX_VALID_PATH_CHARS . ']*)*)/',
  325. $text,
  326. $wmatches,
  327. \PREG_OFFSET_CAPTURE,
  328. );
  329. if ($result === false) {
  330. Log::error(__METHOD__ . ': Error parsing profile URL mentions from text (preg_last_error==' . preg_last_error() . ').');
  331. return [];
  332. } elseif (\count($wmatches)) {
  333. Log::debug((sprintf('Found %d matches for profile URL mentions: %s', \count($wmatches), print_r($wmatches, true))));
  334. }
  335. return $wmatches[1];
  336. }
  337. /**
  338. * Find any explicit remote mentions. Accepted forms:
  339. * Webfinger: @user@example.com
  340. * Profile link: @param Actor $sender
  341. *
  342. * @param string $text input markup text
  343. * @param $mentions
  344. *
  345. * @return bool hook return value
  346. *
  347. * @example.com/mublog/user
  348. */
  349. public function onEndFindMentions(Actor $sender, string $text, array &$mentions): EventResult
  350. {
  351. $matches = [];
  352. foreach (self::extractWebfingerIds($text, $preMention = '@') as $wmatch) {
  353. [$target, $pos] = $wmatch;
  354. Log::info("Checking webfinger person '{$target}'");
  355. $actor = null;
  356. $resource_parts = explode($preMention, $target);
  357. if ($resource_parts[1] === Common::config('site', 'server')) {
  358. $actor = LocalUser::getByPK(['nickname' => $resource_parts[0]])->getActor();
  359. } else {
  360. Event::handle('FreeNetworkFindMentions', [$target, &$actor]);
  361. if (\is_null($actor)) {
  362. continue;
  363. }
  364. }
  365. \assert($actor instanceof Actor);
  366. $displayName = !empty($actor->getFullname()) ? $actor->getFullname() : $actor->getNickname() ?? $target; // TODO: we could do getBestName() or getFullname() here
  367. $matches[$pos] = [
  368. 'mentioned' => [$actor],
  369. 'type' => 'mention',
  370. 'text' => $displayName,
  371. 'position' => $pos,
  372. 'length' => mb_strlen($target),
  373. 'url' => $actor->getUri(),
  374. ];
  375. }
  376. foreach (self::extractUrlMentions($text) as $wmatch) {
  377. [$target, $pos] = $wmatch;
  378. $url = "https://{$target}";
  379. if (Common::isValidHttpUrl($url)) {
  380. // This means $resource is a valid url
  381. $resource_parts = parse_url($url);
  382. // TODO: Use URLMatcher
  383. if ($resource_parts['host'] === Common::config('site', 'server')) {
  384. $str = $resource_parts['path'];
  385. // actor_view_nickname
  386. $renick = '/\/@(' . Nickname::DISPLAY_FMT . ')\/?/m';
  387. // actor_view_id
  388. $reuri = '/\/actor\/(\d+)\/?/m';
  389. if (preg_match_all($renick, $str, $matches, PREG_SET_ORDER, 0) === 1) {
  390. $actor = LocalUser::getByPK(['nickname' => $matches[0][1]])->getActor();
  391. } elseif (preg_match_all($reuri, $str, $matches, PREG_SET_ORDER, 0) === 1) {
  392. $actor = Actor::getById((int) $matches[0][1]);
  393. } else {
  394. Log::error('Unexpected behaviour onEndFindMentions at FreeNetwork');
  395. throw new ServerException('Unexpected behaviour onEndFindMentions at FreeNetwork');
  396. }
  397. } else {
  398. Log::info("Checking actor address '{$url}'");
  399. $link = new XML_XRD_Element_Link(
  400. Discovery::LRDD_REL,
  401. 'https://' . parse_url($url, \PHP_URL_HOST) . '/.well-known/webfinger?resource={uri}',
  402. Discovery::JRD_MIMETYPE,
  403. true, // isTemplate
  404. );
  405. $xrd_uri = Discovery::applyTemplate($link->template, $url);
  406. $response = HTTPClient::get($xrd_uri, ['headers' => ['Accept' => $link->type]]);
  407. if ($response->getStatusCode() !== 200) {
  408. continue;
  409. }
  410. $xrd = new XML_XRD();
  411. switch (GSFile::mimetypeBare($response->getHeaders()['content-type'][0])) {
  412. case Discovery::JRD_MIMETYPE_OLD:
  413. case Discovery::JRD_MIMETYPE:
  414. $type = 'json';
  415. break;
  416. case Discovery::XRD_MIMETYPE:
  417. $type = 'xml';
  418. break;
  419. default:
  420. // fall back to letting XML_XRD auto-detect
  421. Log::debug('No recognized content-type header for resource descriptor body on ' . $xrd_uri);
  422. $type = null;
  423. }
  424. $xrd->loadString($response->getContent(), $type);
  425. $actor = null;
  426. Event::handle('FreeNetworkFoundXrd', [$xrd, &$actor]);
  427. if (\is_null($actor)) {
  428. continue;
  429. }
  430. }
  431. $displayName = $actor->getFullname() ?? $actor->getNickname() ?? $target; // TODO: we could do getBestName() or getFullname() here
  432. $matches[$pos] = [
  433. 'mentioned' => [$actor],
  434. 'type' => 'mention',
  435. 'text' => $displayName,
  436. 'position' => $pos,
  437. 'length' => mb_strlen($target),
  438. 'url' => $actor->getUri(),
  439. ];
  440. }
  441. }
  442. foreach ($mentions as $i => $other) {
  443. // If we share a common prefix with a local user, override it!
  444. $pos = $other['position'];
  445. if (isset($matches[$pos])) {
  446. $mentions[$i] = $matches[$pos];
  447. unset($matches[$pos]);
  448. }
  449. }
  450. foreach ($matches as $mention) {
  451. $mentions[] = $mention;
  452. }
  453. return Event::next;
  454. }
  455. /**
  456. * @param Actor[] $targets
  457. */
  458. public static function notify(Actor $sender, Activity $activity, array $targets, ?string $reason = null): bool
  459. {
  460. foreach (self::$protocols as $protocol) {
  461. $protocol::freeNetworkDistribute($sender, $activity, $targets, $reason);
  462. }
  463. return false;
  464. }
  465. public static function mentionTagToName(string $nickname, string $uri): string
  466. {
  467. return '@' . $nickname . '@' . parse_url($uri, \PHP_URL_HOST);
  468. }
  469. public static function groupTagToName(string $nickname, string $uri): string
  470. {
  471. return '!' . $nickname . '@' . parse_url($uri, \PHP_URL_HOST);
  472. }
  473. /**
  474. * Add fediverse: query expression
  475. * // TODO: adding WebFinger would probably be nice
  476. *
  477. * @param mixed $note_expr
  478. * @param mixed $actor_expr
  479. */
  480. public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): EventResult
  481. {
  482. if (Formatting::startsWith($term, ['fediverse:'])) {
  483. foreach (self::$protocols as $protocol) {
  484. // 10 is strlen of `fediverse:`
  485. if ($protocol::freeNetworkGrabRemote(mb_substr($term, 10))) {
  486. break;
  487. }
  488. }
  489. }
  490. return Event::next;
  491. }
  492. public function onPluginVersion(array &$versions): EventResult
  493. {
  494. $versions[] = [
  495. 'name' => 'WebFinger',
  496. 'version' => self::PLUGIN_VERSION,
  497. 'author' => 'Mikael Nordfeldth',
  498. 'homepage' => GNUSOCIAL_ENGINE_URL,
  499. // TRANS: Plugin description.
  500. 'rawdescription' => _m('WebFinger and LRDD support'),
  501. ];
  502. return true;
  503. }
  504. }