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 public function __construct(Profile $object)
16 // The type argument above verifies that it's our class
17 parent::__construct($object);
20 public function getAliases()
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->id})");
31 return array_merge($aliases, parent::getAliases());
34 public function reconstructAcct()
38 if (Event::handle('StartWebFingerReconstruction', array($this->object, &$acct))) {
39 // TODO: getUri may not always give us the correct host on remote users?
40 $host = parse_url($this->object->getUri(), PHP_URL_HOST);
41 if (empty($this->object->nickname) || empty($host)) {
42 throw new WebFingerReconstructionException($this->object);
44 $acct = mb_strtolower(sprintf('acct:%s@%s', $this->object->nickname, $host));
46 Event::handle('EndWebFingerReconstruction', array($this->object, &$acct));
52 public function updateXRD(XML_XRD $xrd)
54 if (Event::handle('StartWebFingerProfileLinks', array($xrd, $this->object))) {
56 parent::updateXRD($xrd);
59 $xrd->links[] = new XML_XRD_Element_Link('http://gmpg.org/xfn/11',
60 $this->object->getUrl(), 'text/html');
62 $xrd->links[] = new XML_XRD_Element_Link('describedby',
63 common_local_url('foaf',
64 array('nickname' => $this->object->nickname)),
65 'application/rdf+xml');
67 $link = new XML_XRD_Element_Link('http://apinamespace.org/atom',
68 common_local_url('ApiAtomService',
69 array('id' => $this->object->nickname)),
70 'application/atomsvc+xml');
71 // XML_XRD must implement changing properties first $link['http://apinamespace.org/atom/username'] = $this->object->nickname;
72 $xrd->links[] = clone $link;
74 if (common_config('site', 'fancy')) {
75 $apiRoot = common_path('api/', true);
77 $apiRoot = common_path('index.php/api/', true);
80 $link = new XML_XRD_Element_Link('http://apinamespace.org/twitter', $apiRoot);
81 // XML_XRD must implement changing properties first $link['http://apinamespace.org/twitter/username'] = $this->object->nickname;
82 $xrd->links[] = clone $link;
84 Event::handle('EndWebFingerProfileLinks', array($xrd, $this->object));