3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, 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('LACONICA')) { exit(1); }
22 define('LISTENER', 1);
23 define('LISTENEE', -1);
26 class FoafAction extends Action
34 function handle($args)
36 parent::handle($args);
38 $nickname = $this->trimmed('nickname');
40 $user = User::staticGet('nickname', $nickname);
43 $this->clientError(_('No such user.'), 404);
47 $profile = $user->getProfile();
50 $this->serverError(_('User has no profile.'), 500);
54 header('Content-Type: application/rdf+xml');
57 $this->elementStart('rdf:RDF', array('xmlns:rdf' =>
58 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
60 'http://www.w3.org/2000/01/rdf-schema#',
62 'http://www.w3.org/2003/01/geo/wgs84_pos#',
63 'xmlns' => 'http://xmlns.com/foaf/0.1/'));
65 # This is the document about the user
67 $this->show_ppd('', $user->uri);
69 # XXX: might not be a person
70 $this->elementStart('Person', array('rdf:about' =>
72 $this->element('mbox_sha1sum', null, sha1('mailto:' . $user->email));
73 if ($profile->fullname) {
74 $this->element('name', null, $profile->fullname);
76 if ($profile->homepage) {
77 $this->element('homepage', array('rdf:resource' => $profile->homepage));
80 $this->element('rdfs:comment', null, $profile->bio);
82 # XXX: more structured location data
83 if ($profile->location) {
84 $this->elementStart('based_near');
85 $this->elementStart('geo:SpatialThing');
86 $this->element('name', null, $profile->location);
87 $this->elementEnd('geo:SpatialThing');
88 $this->elementEnd('based_near');
91 $this->show_microblogging_account($profile, common_root_url());
93 $avatar = $profile->getOriginalAvatar();
96 $this->elementStart('img');
97 $this->elementStart('Image', array('rdf:about' => $avatar->url));
98 foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
99 $scaled = $profile->getAvatar($size);
100 if (!$scaled->original) { # sometimes the original has one of our scaled sizes
101 $this->elementStart('thumbnail');
102 $this->element('Image', array('rdf:about' => $scaled->url));
103 $this->elementEnd('thumbnail');
106 $this->elementEnd('Image');
107 $this->elementEnd('img');
110 # Get people user is subscribed to
114 $sub = new Subscription();
115 $sub->subscriber = $profile->id;
116 $sub->whereAdd('subscriber != subscribed');
119 while ($sub->fetch()) {
121 $other = Remote_profile::staticGet('id', $sub->subscribed);
123 $other = User::staticGet('id', $sub->subscribed);
126 common_debug('Got a bad subscription: '.print_r($sub,true));
129 $this->element('knows', array('rdf:resource' => $other->uri));
130 $person[$other->uri] = array(LISTENEE, $other);
134 # Get people who subscribe to user
136 $sub = new Subscription();
137 $sub->subscribed = $profile->id;
138 $sub->whereAdd('subscriber != subscribed');
141 while ($sub->fetch()) {
143 $other = Remote_profile::staticGet('id', $sub->subscriber);
145 $other = User::staticGet('id', $sub->subscriber);
148 common_debug('Got a bad subscription: '.print_r($sub,true));
151 if (array_key_exists($other->uri, $person)) {
152 $person[$other->uri][0] = BOTH;
154 $person[$other->uri] = array(LISTENER, $other);
159 $this->elementEnd('Person');
161 foreach ($person as $uri => $p) {
163 if ($p[1] instanceof User) {
164 $foaf_url = common_local_url('foaf', array('nickname' => $p[1]->nickname));
166 $profile = Profile::staticGet($p[1]->id);
167 $this->elementStart('Person', array('rdf:about' => $uri));
168 if ($p[0] == LISTENER || $p[0] == BOTH) {
169 $this->element('knows', array('rdf:resource' => $user->uri));
171 $this->show_microblogging_account($profile, ($p[1] instanceof User) ?
172 common_root_url() : null);
174 $this->element('rdfs:seeAlso', array('rdf:resource' => $foaf_url));
176 $this->elementEnd('Person');
178 $this->show_ppd($foaf_url, $uri);
182 $this->elementEnd('rdf:RDF');
185 function show_ppd($foaf_url, $person_uri)
187 $this->elementStart('PersonalProfileDocument', array('rdf:about' => $foaf_url));
188 $this->element('maker', array('rdf:resource' => $person_uri));
189 $this->element('primaryTopic', array('rdf:resource' => $person_uri));
190 $this->elementEnd('PersonalProfileDocument');
193 function show_microblogging_account($profile, $service=null)
196 $this->elementStart('holdsAccount');
197 $this->elementStart('OnlineAccount');
199 $this->element('accountServiceHomepage', array('rdf:resource' =>
202 $this->element('accountName', null, $profile->nickname);
203 $this->element('homepage', array('rdf:resource' => $profile->profileurl));
204 $this->elementEnd('OnlineAccount');
205 $this->elementEnd('holdsAccount');