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
33 function prepare($args)
35 parent::prepare($args);
36 $this->nickname = $this->trimmed('nickname');
38 $this->user = User::staticGet('nickname', $this->nickname);
41 $this->clientError(_('No such user.'), 404);
45 $this->profile = $this->user->getProfile();
47 if (!$this->profile) {
48 $this->serverError(_('User has no profile.'), 500);
55 function handle($args)
57 parent::handle($args);
59 header('Content-Type: application/rdf+xml');
62 $this->elementStart('rdf:RDF', array('xmlns:rdf' =>
63 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
65 'http://www.w3.org/2000/01/rdf-schema#',
67 'http://www.w3.org/2003/01/geo/wgs84_pos#',
68 'xmlns' => 'http://xmlns.com/foaf/0.1/'));
70 // This is the document about the user
72 $this->showPpd('', $this->user->uri);
74 // XXX: might not be a person
75 $this->elementStart('Person', array('rdf:about' =>
77 $this->element('mbox_sha1sum', null, sha1('mailto:' . $this->user->email));
78 if ($this->profile->fullname) {
79 $this->element('name', null, $this->profile->fullname);
81 if ($this->profile->homepage) {
82 $this->element('homepage', array('rdf:resource' => $this->profile->homepage));
84 if ($this->profile->bio) {
85 $this->element('rdfs:comment', null, $this->profile->bio);
87 // XXX: more structured location data
88 if ($this->profile->location) {
89 $this->elementStart('based_near');
90 $this->elementStart('geo:SpatialThing');
91 $this->element('name', null, $this->profile->location);
92 $this->elementEnd('geo:SpatialThing');
93 $this->elementEnd('based_near');
96 $this->showMicrobloggingAccount($this->profile, common_root_url());
98 $avatar = $this->profile->getOriginalAvatar();
101 $this->elementStart('img');
102 $this->elementStart('Image', array('rdf:about' => $avatar->url));
103 foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
104 $scaled = $this->profile->getAvatar($size);
105 if (!$scaled->original) { // sometimes the original has one of our scaled sizes
106 $this->elementStart('thumbnail');
107 $this->element('Image', array('rdf:about' => $scaled->url));
108 $this->elementEnd('thumbnail');
111 $this->elementEnd('Image');
112 $this->elementEnd('img');
115 // Get people user is subscribed to
119 $sub = new Subscription();
120 $sub->subscriber = $this->profile->id;
121 $sub->whereAdd('subscriber != subscribed');
124 while ($sub->fetch()) {
126 $other = Remote_profile::staticGet('id', $sub->subscribed);
128 $other = User::staticGet('id', $sub->subscribed);
131 common_debug('Got a bad subscription: '.print_r($sub,true));
134 $this->element('knows', array('rdf:resource' => $other->uri));
135 $person[$other->uri] = array(LISTENEE, $other);
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);
150 $other = User::staticGet('id', $sub->subscriber);
153 common_debug('Got a bad subscription: '.print_r($sub,true));
156 if (array_key_exists($other->uri, $person)) {
157 $person[$other->uri][0] = BOTH;
159 $person[$other->uri] = array(LISTENER, $other);
164 $this->elementEnd('Person');
166 foreach ($person as $uri => $p) {
168 if ($p[1] instanceof User) {
169 $foaf_url = common_local_url('foaf', array('nickname' => $p[1]->nickname));
171 $this->profile = Profile::staticGet($p[1]->id);
172 $this->elementStart('Person', array('rdf:about' => $uri));
173 if ($p[0] == LISTENER || $p[0] == BOTH) {
174 $this->element('knows', array('rdf:resource' => $this->user->uri));
176 $this->showMicrobloggingAccount($this->profile, ($p[1] instanceof User) ?
177 common_root_url() : null);
179 $this->element('rdfs:seeAlso', array('rdf:resource' => $foaf_url));
181 $this->elementEnd('Person');
183 $this->showPpd($foaf_url, $uri);
187 $this->elementEnd('rdf:RDF');
191 function showPpd($foaf_url, $person_uri)
193 $this->elementStart('PersonalProfileDocument', array('rdf:about' => $foaf_url));
194 $this->element('maker', array('rdf:resource' => $person_uri));
195 $this->element('primaryTopic', array('rdf:resource' => $person_uri));
196 $this->elementEnd('PersonalProfileDocument');
199 function showMicrobloggingAccount($profile, $service=null)
202 $this->elementStart('holdsAccount');
203 $this->elementStart('OnlineAccount');
205 $this->element('accountServiceHomepage', array('rdf:resource' =>
208 $this->element('accountName', null, $profile->nickname);
209 $this->element('homepage', array('rdf:resource' => $profile->profileurl));
210 $this->elementEnd('OnlineAccount');
211 $this->elementEnd('holdsAccount');