3 * WebFinger resource parent class
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 abstract class WebFingerResource
14 protected $identities = array();
16 protected $object = null;
17 protected $type = null;
19 public function __construct(Managed_DataObject $object)
21 $this->object = $object;
24 public function getObject()
26 if ($this->object === null) {
27 throw new ServerException('Object is not set');
32 public function getAliases()
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;
45 $aliases[$this->object->getUrl()] = true;
46 } catch (InvalidUrlException $e) {
47 // getUrl failed because no valid URL could be returned, just ignore it
50 if (common_config('webfinger', 'fancyurlfix')) {
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
59 foreach(array_keys($aliases) as $alias) {
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
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
80 // return a unique set of aliases by extracting only the keys
81 return array_keys($aliases);
84 abstract public function updateXRD(XML_XRD $xrd);