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('GNUSOCIAL')) { exit(1); }
22 define('LISTENER', 1);
23 define('LISTENEE', -1);
26 // @todo XXX: Documentation missing.
27 class FoafAction extends ManagedAction
29 function isReadOnly(array $args=array())
34 protected function doPreparation()
36 $nickname_arg = $this->arg('nickname');
38 if (empty($nickname_arg)) {
39 // TRANS: Client error displayed when requesting Friends of a Friend feed without providing a user nickname.
40 $this->clientError(_('No such user.'), 404);
43 $this->nickname = common_canonical_nickname($nickname_arg);
45 // Permanent redirect on non-canonical nickname
47 if ($nickname_arg != $this->nickname) {
48 common_redirect(common_local_url('foaf',
49 array('nickname' => $this->nickname)),
53 $this->user = User::getKV('nickname', $this->nickname);
56 // TRANS: Client error displayed when requesting Friends of a Friend feed for an object that is not a user.
57 $this->clientError(_('No such user.'), 404);
60 $this->profile = $this->user->getProfile();
62 if (!$this->profile) {
63 // TRANS: Error message displayed when referring to a user without a profile.
64 $this->serverError(_('User has no profile.'), 500);
70 public function showPage()
72 header('Content-Type: application/rdf+xml');
75 $this->elementStart('rdf:RDF', array('xmlns:rdf' =>
76 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
78 'http://www.w3.org/2000/01/rdf-schema#',
80 'http://www.w3.org/2003/01/geo/wgs84_pos#',
82 'http://purl.org/vocab/bio/0.1/',
84 'http://rdfs.org/sioc/ns#',
85 'xmlns' => 'http://xmlns.com/foaf/0.1/'));
87 // This is the document about the user
89 $this->showPpd('', $this->user->getUri());
91 // Would be nice to tell if they were a Person or not (e.g. a #person usertag?)
92 $this->elementStart('Agent', array('rdf:about' => $this->user->getUri()));
93 if ($this->user->email) {
94 $this->element('mbox_sha1sum', null, sha1('mailto:' . $this->user->email));
96 if ($this->profile->fullname) {
97 $this->element('name', null, $this->profile->fullname);
99 if ($this->profile->homepage) {
100 $this->element('homepage', array('rdf:resource' => $this->profile->homepage));
102 if ($this->profile->profileurl) {
103 $this->element('weblog', array('rdf:resource' => $this->profile->profileurl));
105 if ($this->profile->bio) {
106 $this->element('bio:olb', null, $this->profile->bio);
109 $location = $this->profile->getLocation();
112 if ($location->getRdfURL()) {
113 $attr['rdf:about'] = $location->getRdfURL();
115 $location_name = $location->getName();
117 $this->elementStart('based_near');
118 $this->elementStart('geo:SpatialThing', $attr);
119 if ($location_name) {
120 $this->element('name', null, $location_name);
122 if ($location->lat) {
123 $this->element('geo:lat', null, $location->lat);
125 if ($location->lon) {
126 $this->element('geo:long', null, $location->lon);
128 if ($location->getURL()) {
129 $this->element('page', array('rdf:resource'=>$location->getURL()));
131 $this->elementEnd('geo:SpatialThing');
132 $this->elementEnd('based_near');
136 $avatar = Avatar::getUploaded($this->profile);
137 $this->elementStart('img');
138 $this->elementStart('Image', array('rdf:about' => $avatar->displayUrl()));
139 foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
141 $scaled = $this->profile->getAvatar($size);
142 $this->elementStart('thumbnail');
143 $this->element('Image', array('rdf:about' => $scaled->displayUrl()));
144 $this->elementEnd('thumbnail');
145 } catch (Exception $e) {
146 // This avatar did not exist
149 $this->elementEnd('Image');
150 $this->elementEnd('img');
151 } catch (NoAvatarException $e) {
152 // No avatar for this user!
155 $person = $this->showMicrobloggingAccount($this->profile,
156 common_root_url(), $this->user->getUri(),
157 /*$fetchSubscriptions*/true,
158 /*$isSubscriber*/false);
160 // Get people who subscribe to user
162 $sub = new Subscription();
163 $sub->subscribed = $this->profile->id;
164 $sub->whereAdd('subscriber != subscribed');
167 while ($sub->fetch()) {
168 $profile = Profile::getKV('id', $sub->subscriber);
169 if (!$profile instanceof Profile) {
170 common_debug('Got a bad subscription: '.print_r($sub,true));
173 $other_uri = $profile->getUri();
174 if (array_key_exists($other_uri, $person)) {
175 $person[$other_uri][0] = BOTH;
177 $person[$other_uri] = array(LISTENER,
180 $profile->isLocal() ? 'local' : 'remote');
188 foreach ($person as $uri => $p) {
189 list($type, $id, $nickname, $local) = $p;
191 $this->element('knows', array('rdf:resource' => $uri));
195 $this->elementEnd('Agent');
198 foreach ($person as $uri => $p) {
200 list($type, $id, $nickname, $local) = $p;
201 if ($local == 'local') {
202 $foaf_url = common_local_url('foaf', array('nickname' => $nickname));
204 $profile = Profile::getKV($id);
205 $this->elementStart('Agent', array('rdf:about' => $uri));
207 $this->element('knows', array('rdf:resource' => $this->user->getUri()));
209 $this->showMicrobloggingAccount($profile,
210 ($local == 'local') ? common_root_url() : null,
212 /*$fetchSubscriptions*/false,
213 /*$isSubscriber*/($type == LISTENER || $type == BOTH));
215 $this->element('rdfs:seeAlso', array('rdf:resource' => $foaf_url));
217 $this->elementEnd('Agent');
219 $this->showPpd($foaf_url, $uri);
226 $this->elementEnd('rdf:RDF');
230 function showPpd($foaf_url, $person_uri)
232 $this->elementStart('PersonalProfileDocument', array('rdf:about' => $foaf_url));
233 $this->element('maker', array('rdf:resource' => $person_uri));
234 $this->element('primaryTopic', array('rdf:resource' => $person_uri));
235 $this->elementEnd('PersonalProfileDocument');
239 * Output FOAF <account> bit for the given profile.
241 * @param Profile $profile
242 * @param mixed $service Root URL of this StatusNet instance for a local
243 * user, otherwise null.
244 * @param mixed $useruri URI string for the referenced profile..
245 * @param boolean $fetchSubscriptions Should we load and list all their subscriptions?
246 * @param boolean $isSubscriber if not fetching subs, we can still mark the user as following the current page.
248 * @return array if $fetchSubscribers is set, return a list of info on those
251 function showMicrobloggingAccount($profile, $service=null, $useruri=null, $fetchSubscriptions=false, $isSubscriber=false)
255 $attr['rdf:about'] = $useruri . '#acct';
259 $this->elementStart('account');
260 $this->elementStart('OnlineAccount', $attr);
262 $this->element('accountServiceHomepage', array('rdf:resource' =>
265 $this->element('accountName', null, $profile->nickname);
266 $this->element('accountProfilePage', array('rdf:resource' => $profile->profileurl));
268 $this->element('sioc:account_of', array('rdf:resource'=>$useruri));
273 if ($fetchSubscriptions) {
274 // Get people user is subscribed to
275 $sub = new Subscription();
276 $sub->subscriber = $profile->id;
277 $sub->whereAdd('subscriber != subscribed');
280 while ($sub->fetch()) {
281 $profile = Profile::getKV('id', $sub->subscribed);
282 if (empty($profile)) {
283 common_debug('Got a bad subscription: '.print_r($sub,true));
286 $other_uri = $profile->getUri();
287 $this->element('sioc:follows', array('rdf:resource' => $other_uri.'#acct'));
288 $person[$other_uri] = array(LISTENEE,
291 $profile->isLocal() ? 'local' : 'remote');
297 } else if ($isSubscriber) {
298 // Just declare that they follow the user whose FOAF we're showing.
299 $this->element('sioc:follows', array('rdf:resource' => $this->user->getUri() . '#acct'));
302 $this->elementEnd('OnlineAccount');
303 $this->elementEnd('account');