WebfingerResource.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types = 1);
  3. namespace Component\FreeNetwork\Util;
  4. use App\Core\Entity;
  5. use App\Util\Common;
  6. use App\Util\Exception\ServerException;
  7. use XML_XRD;
  8. /**
  9. * WebFinger resource parent class
  10. *
  11. * @package GNUsocial
  12. *
  13. * @author Mikael Nordfeldth
  14. * @copyright 2013 Free Software Foundation, Inc.
  15. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  16. *
  17. * @see http://status.net/
  18. */
  19. abstract class WebfingerResource
  20. {
  21. protected $identities = [];
  22. protected $object;
  23. protected $type;
  24. public function __construct(Entity $object)
  25. {
  26. $this->object = $object;
  27. }
  28. public function getObject()
  29. {
  30. if ($this->object === null) {
  31. throw new ServerException('Object is not set');
  32. }
  33. return $this->object;
  34. }
  35. /**
  36. * List of alternative IDs of a certain Actor
  37. */
  38. public function getAliases(): array
  39. {
  40. $aliases = $this->object->getAliasesWithIDs();
  41. // Some sites have changed from http to https and still want
  42. // (because remote sites look for it) verify that they are still
  43. // the same identity as they were on HTTP. Should NOT be used if
  44. // you've run HTTPS all the time!
  45. if (Common::config('fix', 'legacy_http')) {
  46. foreach ($aliases as $alias => $id) {
  47. if (!mb_strtolower(parse_url($alias, \PHP_URL_SCHEME)) === 'https') {
  48. continue;
  49. }
  50. $aliases[preg_replace('/^https:/i', 'http:', $alias, 1)] = $id;
  51. }
  52. }
  53. // return a unique set of aliases by extracting only the keys
  54. return array_keys($aliases);
  55. }
  56. abstract public function updateXRD(XML_XRD $xrd);
  57. }