WebfingerResourceNote.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. declare(strict_types = 1);
  3. namespace Component\FreeNetwork\Util\WebfingerResource;
  4. use App\Core\Event;
  5. use App\Entity\Note;
  6. use Component\FreeNetwork\Util\WebfingerResource;
  7. use PharIo\Manifest\InvalidUrlException;
  8. use XML_XRD;
  9. use XML_XRD_Element_Link;
  10. /**
  11. * WebFinger resource for Note objects
  12. *
  13. * @package GNUsocial
  14. *
  15. * @author Mikael Nordfeldth
  16. * @copyright 2013 Free Software Foundation, Inc.
  17. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  18. *
  19. * @see http://status.net/
  20. */
  21. class WebfingerResourceNote extends WebfingerResource
  22. {
  23. public function __construct(?Note $object = null)
  24. {
  25. // The type argument above verifies that it's our class
  26. parent::__construct($object);
  27. }
  28. /**
  29. * Update given XRD with self's data
  30. */
  31. public function updateXRD(XML_XRD $xrd)
  32. {
  33. if (Event::handle('StartWebFingerNoticeLinks', [$xrd, $this->object])) {
  34. if ($this->object->isLocal()) {
  35. $xrd->links[] = new XML_XRD_Element_Link(
  36. 'alternate',
  37. common_local_url(
  38. 'ApiStatusesShow',
  39. ['id' => $this->object->id,
  40. 'format' => 'atom', ],
  41. ),
  42. 'application/atom+xml',
  43. );
  44. $xrd->links[] = new XML_XRD_Element_Link(
  45. 'alternate',
  46. common_local_url(
  47. 'ApiStatusesShow',
  48. ['id' => $this->object->id,
  49. 'format' => 'json', ],
  50. ),
  51. 'application/json',
  52. );
  53. } else {
  54. try {
  55. $xrd->links[] = new XML_XRD_Element_Link(
  56. 'alternate',
  57. $this->object->getUrl(),
  58. 'text/html',
  59. );
  60. } catch (InvalidUrlException $e) {
  61. // don't do a fallback in webfinger
  62. }
  63. }
  64. Event::handle('EndWebFingerNoticeLinks', [$xrd, $this->object]);
  65. }
  66. }
  67. }