3 * WebFinger resource for Profile objects
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/
12 class WebFingerResource_Profile extends WebFingerResource
14 const PROFILEPAGE = 'http://webfinger.net/rel/profile-page';
16 public function __construct(Profile $object)
18 // The type argument above verifies that it's our class
19 parent::__construct($object);
22 public function getAliases()
27 // Try to create an acct: URI if we're dealing with a profile
28 $aliases[] = $this->reconstructAcct();
29 } catch (WebFingerReconstructionException $e) {
30 common_debug("WebFinger reconstruction for Profile failed (id={$this->object->id})");
33 return array_merge($aliases, parent::getAliases());
36 public function reconstructAcct()
40 if (Event::handle('StartWebFingerReconstruction', array($this->object, &$acct))) {
41 // TODO: getUri may not always give us the correct host on remote users?
42 $host = parse_url($this->object->getUri(), PHP_URL_HOST);
43 if (empty($this->object->nickname) || empty($host)) {
44 throw new WebFingerReconstructionException($this->object);
46 $acct = mb_strtolower(sprintf('acct:%s@%s', $this->object->nickname, $host));
48 Event::handle('EndWebFingerReconstruction', array($this->object, &$acct));
54 public function updateXRD(XML_XRD $xrd)
56 if (Event::handle('StartWebFingerProfileLinks', array($xrd, $this->object))) {
58 $xrd->links[] = new XML_XRD_Element_Link(self::PROFILEPAGE,
59 $this->object->getUrl(), 'text/html');
62 $xrd->links[] = new XML_XRD_Element_Link('http://gmpg.org/xfn/11',
63 $this->object->getUrl(), 'text/html');
65 $xrd->links[] = new XML_XRD_Element_Link('describedby',
66 common_local_url('foaf',
67 array('nickname' => $this->object->nickname)),
68 'application/rdf+xml');
70 $link = new XML_XRD_Element_Link('http://apinamespace.org/atom',
71 common_local_url('ApiAtomService',
72 array('id' => $this->object->nickname)),
73 'application/atomsvc+xml');
74 // XML_XRD must implement changing properties first $link['http://apinamespace.org/atom/username'] = $this->object->nickname;
75 $xrd->links[] = clone $link;
77 if (common_config('site', 'fancy')) {
78 $apiRoot = common_path('api/', true);
80 $apiRoot = common_path('index.php/api/', true);
83 $link = new XML_XRD_Element_Link('http://apinamespace.org/twitter', $apiRoot);
84 // XML_XRD must implement changing properties first $link['http://apinamespace.org/twitter/username'] = $this->object->nickname;
85 $xrd->links[] = clone $link;
87 Event::handle('EndWebFingerProfileLinks', array($xrd, $this->object));