]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/WebFinger/lib/webfingerresource/profile.php
Merge remote-tracking branch 'upstream/master'
[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     const PROFILEPAGE = 'http://webfinger.net/rel/profile-page';
15
16     public function __construct(Profile $object)
17     {
18         // The type argument above verifies that it's our class
19         parent::__construct($object);
20     }
21
22     public function getAliases()
23     {
24         $aliases = array();
25
26         try {
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})");
31         }
32
33         return array_merge($aliases, parent::getAliases());
34     }
35
36     public function reconstructAcct()
37     {
38         $acct = null;
39
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);
45             }
46             $acct = mb_strtolower(sprintf('acct:%s@%s', $this->object->nickname, $host));
47
48             Event::handle('EndWebFingerReconstruction', array($this->object, &$acct));
49         }
50
51         return $acct;
52     }
53
54     public function updateXRD(XML_XRD $xrd)
55     {
56         if (Event::handle('StartWebFingerProfileLinks', array($xrd, $this->object))) {
57
58             $xrd->links[] = new XML_XRD_Element_Link(self::PROFILEPAGE,
59                                         $this->object->getUrl(), 'text/html');
60
61             // XFN
62             $xrd->links[] = new XML_XRD_Element_Link('http://gmpg.org/xfn/11',
63                                         $this->object->getUrl(), 'text/html');
64             // FOAF
65             $xrd->links[] = new XML_XRD_Element_Link('describedby',
66                                         common_local_url('foaf',
67                                                         array('nickname' => $this->object->nickname)),
68                                                                 'application/rdf+xml');
69
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;
76
77             if (common_config('site', 'fancy')) {
78                 $apiRoot = common_path('api/', true);
79             } else {
80                 $apiRoot = common_path('index.php/api/', true);
81             }
82
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;
86
87             Event::handle('EndWebFingerProfileLinks', array($xrd, $this->object));
88         }
89     }
90 }