]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/WebFinger/lib/webfingerresource.php
e04d3b407f2f11f8cd6a614f76deba1cfbe9d6f5
[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     protected $identities = array();
15
16     protected $object = null;
17     protected $type   = null;
18
19     public function __construct(Managed_DataObject $object)
20     {
21         $this->object = $object;
22     }
23
24     public function getObject()
25     {
26         if ($this->object === null) {
27             throw new ServerException('Object is not set');
28         }
29         return $this->object;
30     }
31
32     public function getAliases()
33     {
34         $aliases = array();
35
36         // Add the URI as an identity, this is _not_ necessarily an HTTP url
37         $uri = $this->object->getUri();
38         $aliases[$uri] = true;
39         if (common_config('webfinger', 'http_alias')
40                 && strtolower(parse_url($uri, PHP_URL_SCHEME)) === 'https') {
41             $aliases[preg_replace('/^https:/', 'http:', $uri, 1)] = true;
42         }
43
44         try {
45             $aliases[$this->object->getUrl()] = true;
46         } catch (InvalidUrlException $e) {
47             // getUrl failed because no valid URL could be returned, just ignore it
48         }
49
50         if (common_config('webfinger', 'fancyurlfix')) {
51             /**
52              * Here we add some hacky hotfixes for remote lookups that have been taught the
53              * (at least now) wrong URI but it's still obviously the same user. Such as:
54              * - https://site.example/user/1 even if the client requests https://site.example/index.php/user/1
55              * - https://site.example/user/1 even if the client requests https://site.example//index.php/user/1
56              * - https://site.example/index.php/user/1 even if the client requests https://site.example/user/1
57              * - https://site.example/index.php/user/1 even if the client requests https://site.example///index.php/user/1
58              */
59             foreach(array_keys($aliases) as $alias) {
60                 try {
61                     // get a "fancy url" version of the alias, even without index.php/
62                     $alt_url = common_fake_local_fancy_url($alias);
63                     // store this as well so remote sites can be sure we really are the same profile
64                     $aliases[$alt_url] = true;
65                 } catch (Exception $e) {
66                     // Apparently we couldn't rewrite that, the $alias was as the function wanted it to be
67                 }
68     
69                 try {
70                     // get a non-"fancy url" version of the alias, i.e. add index.php/
71                     $alt_url = common_fake_local_nonfancy_url($alias);
72                     // store this as well so remote sites can be sure we really are the same profile
73                     $aliases[$alt_url] = true;
74                 } catch (Exception $e) {
75                     // Apparently we couldn't rewrite that, the $alias was as the function wanted it to be
76                 }
77             }
78         }
79
80         // return a unique set of aliases by extracting only the keys
81         return array_keys($aliases);
82     }
83
84     abstract public function updateXRD(XML_XRD $xrd);
85 }