profile.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. try {
  23. // Try to create an acct: URI if we're dealing with a profile
  24. $aliases[] = $this->reconstructAcct();
  25. } catch (WebFingerReconstructionException $e) {
  26. common_debug("WebFinger reconstruction for Profile failed (id={$this->object->id})");
  27. }
  28. return array_merge($aliases, parent::getAliases());
  29. }
  30. public function reconstructAcct()
  31. {
  32. $acct = null;
  33. if (Event::handle('StartWebFingerReconstruction', array($this->object, &$acct))) {
  34. // TODO: getUri may not always give us the correct host on remote users?
  35. $host = parse_url($this->object->getUri(), PHP_URL_HOST);
  36. if (empty($this->object->nickname) || empty($host)) {
  37. throw new WebFingerReconstructionException($this->object);
  38. }
  39. $acct = mb_strtolower(sprintf('acct:%s@%s', $this->object->nickname, $host));
  40. Event::handle('EndWebFingerReconstruction', array($this->object, &$acct));
  41. }
  42. return $acct;
  43. }
  44. public function updateXRD(XML_XRD $xrd)
  45. {
  46. if (Event::handle('StartWebFingerProfileLinks', array($xrd, $this->object))) {
  47. $xrd->links[] = new XML_XRD_Element_Link(self::PROFILEPAGE,
  48. $this->object->getUrl(), 'text/html');
  49. // XFN
  50. $xrd->links[] = new XML_XRD_Element_Link('http://gmpg.org/xfn/11',
  51. $this->object->getUrl(), 'text/html');
  52. // FOAF
  53. $xrd->links[] = new XML_XRD_Element_Link('describedby',
  54. common_local_url('foaf',
  55. array('nickname' => $this->object->nickname)),
  56. 'application/rdf+xml');
  57. $link = new XML_XRD_Element_Link('http://apinamespace.org/atom',
  58. common_local_url('ApiAtomService',
  59. array('id' => $this->object->nickname)),
  60. 'application/atomsvc+xml');
  61. // XML_XRD must implement changing properties first $link['http://apinamespace.org/atom/username'] = $this->object->nickname;
  62. $xrd->links[] = clone $link;
  63. if (common_config('site', 'fancy')) {
  64. $apiRoot = common_path('api/', true);
  65. } else {
  66. $apiRoot = common_path('index.php/api/', true);
  67. }
  68. $link = new XML_XRD_Element_Link('http://apinamespace.org/twitter', $apiRoot);
  69. // XML_XRD must implement changing properties first $link['http://apinamespace.org/twitter/username'] = $this->object->nickname;
  70. $xrd->links[] = clone $link;
  71. Event::handle('EndWebFingerProfileLinks', array($xrd, $this->object));
  72. }
  73. }
  74. }