WebfingerResource.php 1.7 KB

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