]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/WebFinger/lib/webfingerresource/profile.php
49353145ed3f242625c9868f4257bc0f0fe5214f
[quix0rs-gnu-social.git] / plugins / WebFinger / lib / webfingerresource / profile.php
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
12 class WebFingerResource_Profile extends WebFingerResource
13 {
14     public function __construct(Profile $object)
15     {
16         // The type argument above verifies that it's our class
17         parent::__construct($object);
18     }
19
20     public function getAliases()
21     {
22         $aliases = array();
23
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->id})");
29         }
30
31         return array_merge($aliases, parent::getAliases());
32     }
33
34     public function reconstructAcct()
35     {
36         $acct = null;
37
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);
43             }
44             $acct = mb_strtolower(sprintf('acct:%s@%s', $this->object->nickname, $host));
45
46             Event::handle('EndWebFingerReconstruction', array($this->object, &$acct));
47         }
48
49         return $acct;
50     }
51
52     public function updateXRD(XML_XRD $xrd)
53     {
54         if (Event::handle('StartWebFingerProfileLinks', array($xrd, $this->object))) {
55
56             parent::updateXRD($xrd);
57
58             // XFN
59             $xrd->links[] = new XML_XRD_Element_Link('http://gmpg.org/xfn/11',
60                                         $this->object->getUrl(), 'text/html');
61             // FOAF
62             $xrd->links[] = new XML_XRD_Element_Link('describedby',
63                                         common_local_url('foaf',
64                                                         array('nickname' => $this->object->nickname)),
65                                                                 'application/rdf+xml');
66
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;
73
74             if (common_config('site', 'fancy')) {
75                 $apiRoot = common_path('api/', true);
76             } else {
77                 $apiRoot = common_path('index.php/api/', true);
78             }
79
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;
83
84             Event::handle('EndWebFingerProfileLinks', array($xrd, $this->object));
85         }
86     }
87 }