3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, 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/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
22 define('LISTENER', 1);
23 define('LISTENEE', -1);
26 class FoafAction extends Action
28 function isReadOnly($args)
33 function prepare($args)
35 parent::prepare($args);
37 $nickname_arg = $this->arg('nickname');
39 if (empty($nickname_arg)) {
40 $this->clientError(_('No such user.'), 404);
44 $this->nickname = common_canonical_nickname($nickname_arg);
46 // Permanent redirect on non-canonical nickname
48 if ($nickname_arg != $this->nickname) {
49 common_redirect(common_local_url('foaf',
50 array('nickname' => $this->nickname)),
55 $this->user = User::staticGet('nickname', $this->nickname);
58 $this->clientError(_('No such user.'), 404);
62 $this->profile = $this->user->getProfile();
64 if (!$this->profile) {
65 $this->serverError(_('User has no profile.'), 500);
72 function handle($args)
74 parent::handle($args);
76 header('Content-Type: application/rdf+xml');
79 $this->elementStart('rdf:RDF', array('xmlns:rdf' =>
80 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
82 'http://www.w3.org/2000/01/rdf-schema#',
84 'http://www.w3.org/2003/01/geo/wgs84_pos#',
86 'http://purl.org/vocab/bio/0.1/',
88 'http://rdfs.org/sioc/ns#',
89 'xmlns' => 'http://xmlns.com/foaf/0.1/'));
91 // This is the document about the user
93 $this->showPpd('', $this->user->uri);
95 // Would be nice to tell if they were a Person or not (e.g. a #person usertag?)
96 $this->elementStart('Agent', array('rdf:about' =>
98 $this->element('mbox_sha1sum', null, sha1('mailto:' . $this->user->email));
99 if ($this->profile->fullname) {
100 $this->element('name', null, $this->profile->fullname);
102 if ($this->profile->homepage) {
103 $this->element('homepage', array('rdf:resource' => $this->profile->homepage));
105 if ($this->profile->profileurl) {
106 $this->element('weblog', array('rdf:resource' => $this->profile->profileurl));
108 if ($this->profile->bio) {
109 $this->element('bio:olb', null, $this->profile->bio);
111 // XXX: more structured location data
112 if ($this->profile->location) {
113 $this->elementStart('based_near');
114 $this->elementStart('geo:SpatialThing');
115 $this->element('name', null, $this->profile->location);
116 $this->elementEnd('geo:SpatialThing');
117 $this->elementEnd('based_near');
120 $avatar = $this->profile->getOriginalAvatar();
122 $this->elementStart('img');
123 $this->elementStart('Image', array('rdf:about' => $avatar->url));
124 foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
125 $scaled = $this->profile->getAvatar($size);
126 if (!$scaled->original) { // sometimes the original has one of our scaled sizes
127 $this->elementStart('thumbnail');
128 $this->element('Image', array('rdf:about' => $scaled->url));
129 $this->elementEnd('thumbnail');
132 $this->elementEnd('Image');
133 $this->elementEnd('img');
136 $person = $this->showMicrobloggingAccount($this->profile,
137 common_root_url(), $this->user->uri, false);
139 // Get people who subscribe to user
141 $sub = new Subscription();
142 $sub->subscribed = $this->profile->id;
143 $sub->whereAdd('subscriber != subscribed');
146 while ($sub->fetch()) {
148 $other = Remote_profile::staticGet('id', $sub->subscriber);
149 $profile = Profile::staticGet('id', $sub->subscriber);
151 $other = User::staticGet('id', $sub->subscriber);
152 $profile = Profile::staticGet('id', $sub->subscriber);
155 common_debug('Got a bad subscription: '.print_r($sub,true));
158 if (array_key_exists($other->uri, $person)) {
159 $person[$other->uri][0] = BOTH;
161 $person[$other->uri] = array(LISTENER,
164 (empty($sub->token)) ? 'User' : 'Remote_profile');
179 foreach ($person as $uri => $p) {
180 list($type, $id, $nickname, $cls) = $p;
182 $this->element('knows', array('rdf:resource' => $uri));
186 $this->elementEnd('Agent');
189 foreach ($person as $uri => $p) {
191 list($type, $id, $nickname, $cls) = $p;
192 if ($cls == 'User') {
193 $foaf_url = common_local_url('foaf', array('nickname' => $nickname));
195 $profile = Profile::staticGet($id);
196 $this->elementStart('Agent', array('rdf:about' => $uri));
198 $this->element('knows', array('rdf:resource' => $this->user->uri));
200 $this->showMicrobloggingAccount($profile,
201 ($cls == 'User') ? common_root_url() : null,
205 $this->element('rdfs:seeAlso', array('rdf:resource' => $foaf_url));
207 $this->elementEnd('Agent');
209 $this->showPpd($foaf_url, $uri);
216 $this->elementEnd('rdf:RDF');
220 function showPpd($foaf_url, $person_uri)
222 $this->elementStart('PersonalProfileDocument', array('rdf:about' => $foaf_url));
223 $this->element('maker', array('rdf:resource' => $person_uri));
224 $this->element('primaryTopic', array('rdf:resource' => $person_uri));
225 $this->elementEnd('PersonalProfileDocument');
228 function showMicrobloggingAccount($profile, $service=null, $useruri=null, $isSubscriber=false)
232 $attr['rdf:about'] = $useruri . '#acct';
236 $this->elementStart('holdsAccount');
237 $this->elementStart('OnlineAccount', $attr);
239 $this->element('accountServiceHomepage', array('rdf:resource' =>
242 $this->element('accountName', null, $profile->nickname);
243 $this->element('accountProfilePage', array('rdf:resource' => $profile->profileurl));
245 $this->element('sioc:account_of', array('rdf:resource'=>$useruri));
251 $this->element('sioc:follows', array('rdf:resource'=>$this->user->uri . '#acct'));
253 // Get people user is subscribed to
254 $sub = new Subscription();
255 $sub->subscriber = $profile->id;
256 $sub->whereAdd('subscriber != subscribed');
259 while ($sub->fetch()) {
260 if (!empty($sub->token)) {
261 $other = Remote_profile::staticGet('id', $sub->subscribed);
262 $profile = Profile::staticGet('id', $sub->subscribed);
264 $other = User::staticGet('id', $sub->subscribed);
265 $profile = Profile::staticGet('id', $sub->subscribed);
268 common_debug('Got a bad subscription: '.print_r($sub,true));
271 $this->element('sioc:follows', array('rdf:resource' => $other->uri.'#acct'));
272 $person[$other->uri] = array(LISTENEE,
275 (empty($sub->token)) ? 'User' : 'Remote_profile');
290 $this->elementEnd('OnlineAccount');
291 $this->elementEnd('holdsAccount');