3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Mikael Nordfeldth
25 * @copyright 2013 Free Software Foundation, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
27 * @link http://status.net/
32 const PROFILEPAGE = 'http://webfinger.net/rel/profile-page';
35 * Reconstructs a WebFinger ID from data we know about the profile.
37 * @param Profile $profile The profile we want a WebFinger ID for
39 * @return string $acct acct:user@example.com URI
41 public static function reconstruct(Profile $profile)
45 if (Event::handle('StartWebFingerReconstruction', array($profile, &$acct))) {
46 // TODO: getUri may not always give us the correct host on remote users?
47 $host = parse_url($profile->getUri(), PHP_URL_HOST);
48 if (empty($profile->nickname) || empty($host)) {
49 throw new WebFingerReconstructionException($profile);
51 $acct = sprintf('acct:%s@%s', $profile->nickname, $host);
53 Event::handle('EndWebFingerReconstruction', array($profile, &$acct));
60 * Gets all URI aliases for a Profile
62 * @param Profile $profile The profile we want aliases for
64 * @return array $aliases All the Profile's alternative URLs
66 public static function getAliases(Profile $profile)
69 $aliases[] = $profile->getUri();
71 $aliases[] = $profile->getUrl();
72 } catch (InvalidUrlException $e) {
73 common_debug('Profile id='.$profile->id.' has invalid profileurl: ' .
74 var_export($profile->profileurl, true));
80 * Gets all identities for a Profile, includes WebFinger acct: if
81 * available, as well as alias URLs.
83 * @param Profile $profile The profile we want aliases for
85 * @return array $uris WebFinger acct: URI and alias URLs
87 public static function getIdentities(Profile $profile)
91 $uris[] = self::reconstruct($profile);
92 } catch (WebFingerReconstructionException $e) {
93 common_debug('WebFinger reconstruction for Profile failed, ' .
94 ' (id='.$profile->id.')');
96 $uris = array_merge($uris, self::getAliases($profile));