profile.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * WebFinger resource for Profile objects
  4. *
  5. * @package GNUsocial
  6. * @author Mikael Nordfeldth
  7. * @copyright 2013 Free Software Foundation, Inc.
  8. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  9. * @link http://status.net/
  10. */
  11. class WebFingerResource_Profile extends WebFingerResource
  12. {
  13. const PROFILEPAGE = 'http://webfinger.net/rel/profile-page';
  14. public function __construct(Profile $object)
  15. {
  16. // The type argument above verifies that it's our class
  17. parent::__construct($object);
  18. }
  19. public function getAliases()
  20. {
  21. $aliases = array();
  22. // only persons ("accounts" or "agents" actually) have acct: URIs
  23. if ($this->object->isPerson()) {
  24. try {
  25. // Try to create an acct: URI if we're dealing with a profile
  26. $aliases[] = $this->reconstructAcct();
  27. } catch (WebFingerReconstructionException $e) {
  28. common_debug("WebFinger reconstruction for Profile failed (id={$this->object->getID()})");
  29. }
  30. }
  31. return array_merge($aliases, parent::getAliases());
  32. }
  33. public function reconstructAcct()
  34. {
  35. $acct = null;
  36. if (Event::handle('StartWebFingerReconstruction', array($this->object, &$acct))) {
  37. // TODO: getUri may not always give us the correct host on remote users?
  38. $host = parse_url($this->object->getUri(), PHP_URL_HOST);
  39. if (empty($this->object->getNickname()) || empty($host)) {
  40. throw new WebFingerReconstructionException($this->object);
  41. }
  42. $acct = mb_strtolower(sprintf('acct:%s@%s', $this->object->getNickname(), $host));
  43. Event::handle('EndWebFingerReconstruction', array($this->object, &$acct));
  44. }
  45. return $acct;
  46. }
  47. public function updateXRD(XML_XRD $xrd)
  48. {
  49. if (Event::handle('StartWebFingerProfileLinks', array($xrd, $this->object))) {
  50. if (common_config('site', 'fancy')) {
  51. $apiRoot = common_path('api/', true);
  52. } else {
  53. $apiRoot = common_path('index.php/api/', true);
  54. }
  55. // Profile page, can give more metadata from Link header or HTML parsing
  56. $xrd->links[] = new XML_XRD_Element_Link(self::PROFILEPAGE,
  57. $this->object->getUrl(), 'text/html');
  58. // XFN
  59. $xrd->links[] = new XML_XRD_Element_Link('http://gmpg.org/xfn/11',
  60. $this->object->getUrl(), 'text/html');
  61. if ($this->object->isPerson()) {
  62. // FOAF for user
  63. $xrd->links[] = new XML_XRD_Element_Link('describedby',
  64. common_local_url('foaf',
  65. array('nickname' => $this->object->getNickname())),
  66. 'application/rdf+xml');
  67. // nickname discovery for apps etc.
  68. $link = new XML_XRD_Element_Link('http://apinamespace.org/atom',
  69. common_local_url('ApiAtomService',
  70. array('id' => $this->object->getNickname())),
  71. 'application/atomsvc+xml');
  72. // XML_XRD must implement changing properties first $link['http://apinamespace.org/atom/username'] = $this->object->getNickname();
  73. $xrd->links[] = clone $link;
  74. $link = new XML_XRD_Element_Link('http://apinamespace.org/twitter', $apiRoot);
  75. // XML_XRD must implement changing properties first $link['http://apinamespace.org/twitter/username'] = $this->object->getNickname();
  76. $xrd->links[] = clone $link;
  77. } elseif ($this->object->isGroup()) {
  78. // FOAF for group
  79. $xrd->links[] = new XML_XRD_Element_Link('describedby',
  80. common_local_url('foafgroup',
  81. array('nickname' => $this->object->getNickname())),
  82. 'application/rdf+xml');
  83. }
  84. Event::handle('EndWebFingerProfileLinks', array($xrd, $this->object));
  85. }
  86. }
  87. }