WebfingerResourceNote.php 1.9 KB

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