3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @package OStatusPlugin
22 * @maintainer James Walker <james@status.net>
25 if (!defined('STATUSNET')) {
29 class XrdAction extends Action
31 const PROFILEPAGE = 'http://webfinger.net/rel/profile-page';
32 const UPDATESFROM = 'http://schemas.google.com/g/2010#updates-from';
33 const HCARD = 'http://microformats.org/profile/hcard';
43 $nick = $this->user->nickname;
44 $profile = $this->user->getProfile();
46 if (empty($this->xrd)) {
52 if (empty($xrd->subject)) {
53 $xrd->subject = self::normalize($this->uri);
56 if (Event::handle('StartXrdActionAliases', array(&$xrd, $this->user))) {
58 // Possible aliases for the user
60 $uris = array($this->user->uri, $profile->profileurl);
62 // FIXME: Webfinger generation code should live somewhere on its own
64 $path = common_config('site', 'path');
67 $uris[] = sprintf('acct:%s@%s', $nick, common_config('site', 'server'));
70 foreach ($uris as $uri) {
71 if ($uri != $xrd->subject) {
76 Event::handle('EndXrdActionAliases', array(&$xrd, $this->user));
79 if (Event::handle('StartXrdActionLinks', array(&$xrd, $this->user))) {
81 $xrd->links[] = array('rel' => self::PROFILEPAGE,
82 'type' => 'text/html',
83 'href' => $profile->profileurl);
86 $xrd->links[] = array('rel' => 'http://gmpg.org/xfn/11',
87 'type' => 'text/html',
88 'href' => $profile->profileurl);
90 $xrd->links[] = array('rel' => 'describedby',
91 'type' => 'application/rdf+xml',
92 'href' => common_local_url('foaf',
93 array('nickname' => $nick)));
95 $xrd->links[] = array('rel' => 'http://apinamespace.org/atom',
96 'type' => 'application/atomsvc+xml',
97 'href' => common_local_url('ApiAtomService', array('id' => $nick)),
98 'property' => array(array('type' => 'http://apinamespace.org/atom/username',
101 if (common_config('site', 'fancy')) {
102 $apiRoot = common_path('api/', true);
104 $apiRoot = common_path('index.php/api/', true);
107 $xrd->links[] = array('rel' => 'http://apinamespace.org/twitter',
109 'property' => array(array('type' => 'http://apinamespace.org/twitter/username',
112 Event::handle('EndXrdActionLinks', array(&$xrd, $this->user));
115 if (common_config('discovery', 'cors')) {
116 header('Access-Control-Allow-Origin: *');
119 header('Content-type: application/xrd+xml');
125 * Given a "user id" make sure it's normalized to either a webfinger
126 * acct: uri or a profile HTTP URL.
129 public static function normalize($user_id)
131 if (substr($user_id, 0, 5) == 'http:' ||
132 substr($user_id, 0, 6) == 'https:' ||
133 substr($user_id, 0, 5) == 'acct:') {
137 if (strpos($user_id, '@') !== FALSE) {
138 return 'acct:' . $user_id;
141 return 'http://' . $user_id;
144 public static function isWebfinger($user_id)
146 $uri = self::normalize($user_id);
148 return (substr($uri, 0, 5) == 'acct:');
152 * Is this action read-only?
154 * @param array $args other arguments
156 * @return boolean is read only action?
158 function isReadOnly($args)