DiscoveryHints.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. /**
  20. * ActivityPub implementation for GNU social
  21. *
  22. * @package GNUsocial
  23. * @category ActivityPub
  24. * @author Diogo Peralta Cordeiro <@diogo.site>
  25. * @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org
  26. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  27. */
  28. namespace Plugin\ActivityPub\Util;
  29. // This file is part of GNU social - https://www.gnu.org/software/social
  30. //
  31. // GNU social is free software: you can redistribute it and/or modify
  32. // it under the terms of the GNU Affero General Public License as published by
  33. // the Free Software Foundation, either version 3 of the License, or
  34. // (at your option) any later version.
  35. //
  36. // GNU social is distributed in the hope that it will be useful,
  37. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. // GNU Affero General Public License for more details.
  40. //
  41. // You should have received a copy of the GNU Affero General Public License
  42. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  43. use App\Core\Event;
  44. use XML_XRD;
  45. /**
  46. * DiscoveryHints implementation for GNU social
  47. *
  48. *
  49. * @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org
  50. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  51. */
  52. class DiscoveryHints
  53. {
  54. /**
  55. * Search the WebFinger XRD after an ActivityPub URI
  56. *
  57. * @param XML_XRD $xrd
  58. * @return array
  59. */
  60. public static function fromXRD(XML_XRD $xrd): array
  61. {
  62. $hints = [];
  63. if (Event::handle('StartDiscoveryHintsFromXRD', [$xrd, &$hints])) {
  64. foreach ($xrd->links as $link) {
  65. if ($link->rel === 'self' && $link->type === 'application/activity+json') {
  66. $hints['activitypub'] = $link->href;
  67. break;
  68. }
  69. }
  70. Event::handle('EndDiscoveryHintsFromXRD', [$xrd, &$hints]);
  71. }
  72. return $hints;
  73. }
  74. }