OwnerXrd.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. declare(strict_types = 1);
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. namespace Component\FreeNetwork\Controller;
  18. /**
  19. * @package WebFingerPlugin
  20. *
  21. * @author James Walker <james@status.net>
  22. * @author Mikael Nordfeldth <mmn@hethane.se>
  23. * @copyright 2010 StatusNet, Inc.
  24. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  25. */
  26. use App\Entity\LocalUser;
  27. use App\Util\Common;
  28. use Component\FreeNetwork\Util\Discovery;
  29. use Component\FreeNetwork\Util\XrdController;
  30. use Symfony\Component\HttpFoundation\Request;
  31. class OwnerXrd extends XrdController
  32. {
  33. protected string $default_mimetype = Discovery::XRD_MIMETYPE;
  34. public function handle(Request $request): array
  35. {
  36. $user = LocalUser::siteOwner();
  37. $nick = common_canonical_nickname($user->nickname);
  38. $this->resource = 'acct:' . $nick . '@' . Common::config('site', 'server');
  39. // We have now set $args['resource'] to the configured value, since
  40. // only this local site configuration knows who the owner is!
  41. return parent::handle($request);
  42. }
  43. protected function setXRD()
  44. {
  45. // Check to see if a $config['webfinger']['owner'] has been set
  46. // and then make sure 'subject' is set to that primary identity.
  47. if (!empty($owner = Common::config('webfinger', 'owner'))) {
  48. $this->xrd->aliases[] = $this->xrd->subject;
  49. $this->xrd->subject = Discovery::normalize($owner);
  50. } else {
  51. $this->xrd->subject = $this->resource;
  52. }
  53. }
  54. }