OwnerXrd.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. namespace Component\FreeNetwork\Controller;
  17. /**
  18. * @package WebFingerPlugin
  19. *
  20. * @author James Walker <james@status.net>
  21. * @author Mikael Nordfeldth <mmn@hethane.se>
  22. * @copyright 2010 StatusNet, Inc.
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. use App\Entity\LocalUser;
  26. use App\Util\Common;
  27. use Component\FreeNetwork\Util\Discovery;
  28. use Component\FreeNetwork\Util\XrdController;
  29. use Symfony\Component\HttpFoundation\Request;
  30. use Symfony\Component\HttpFoundation\Response;
  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. }