]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/WebFinger/lib/webfingerresource.php
c9fe1727e298c45498c9e75025ec47be316975eb
[quix0rs-gnu-social.git] / plugins / WebFinger / lib / webfingerresource.php
1 <?php
2 /**
3  * WebFinger resource parent class
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 abstract class WebFingerResource
13 {
14     const PROFILEPAGE = 'http://webfinger.net/rel/profile-page';
15
16     protected $identities = array();
17
18     protected $object = null;
19     protected $type   = null;
20
21     public function __construct(Managed_DataObject $object)
22     {
23         $this->object = $object;
24     }
25
26     public function getObject()
27     {
28         if ($this->object === null) {
29             throw new ServerException('Object is not set');
30         }
31         return $this->object;
32     }
33
34     public function getAliases()
35     {
36         $aliases = array();
37
38         // Add the URI as an identity, this is _not_ necessarily an HTTP url
39         $aliases[] = $this->object->getUri();
40
41         try {
42             $aliases[] = $this->object->getUrl();
43         } catch (InvalidUrlException $e) {
44             // getUrl failed because no valid URL could be returned, just ignore it
45         }
46
47         return $aliases;
48     }
49
50     public function updateXRD(XML_XRD $xrd) {
51         $xrd->links[] = new XML_XRD_Element_Link(WebFingerResource::PROFILEPAGE,
52                                         $this->object->getUrl(), 'text/html');
53     }
54 }