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 {
28 function handle($args) {
29 parent::handle($args);
31 $nickname = $this->trimmed('nickname');
33 $user = User::staticGet('nickname', $nickname);
36 common_user_error(_t('No such user'), 404);
40 $profile = $user->getProfile();
43 common_server_error(_t('User has no profile'), 500);
47 header('Content-Type: application/rdf+xml');
50 common_element_start('rdf:RDF', array('xmlns:rdf' =>
51 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
53 'http://www.w3.org/2000/01/rdf-schema#',
54 'xmlns' => 'http://xmlns.com/foaf/0.1/'));
56 # This is the document about the user
58 $this->show_ppd('', $user->uri);
60 # XXX: might not be a person
61 common_element_start('Person', array('rdf:about' =>
63 common_element('mbox_sha1sum', NULL, sha1('mailto:' . $user->email));
64 if ($profile->fullname) {
65 common_element('name', NULL, $profile->fullname);
67 if ($profile->homepage) {
68 common_element('homepage', array('rdf:resource' => $profile->homepage));
71 common_element('rdfs:comment', NULL, $profile->bio);
73 # XXX: more structured location data
74 if ($profile->location) {
75 common_element_start('based_near');
76 common_element_start('geo:SpatialThing');
77 common_element('name', NULL, $profile->location);
78 common_element_end('geo:SpatialThing');
79 common_element_end('based_near');
82 $this->show_microblogging_account($profile, common_root_url());
84 $avatar = $profile->getOriginalAvatar();
87 common_element_start('img');
88 common_element_start('Image', array('rdf:about' => $avatar->url));
89 foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
90 $scaled = $profile->getAvatar($size);
91 if (!$scaled->original) { # sometimes the original has one of our scaled sizes
92 common_element_start('thumbnail');
93 common_element('Image', array('rdf:about' => $scaled->url));
94 common_element_end('thumbnail');
97 common_element_end('Image');
98 common_element_end('img');
101 # Get people user is subscribed to
105 $sub = new Subscription();
106 $sub->subscriber = $profile->id;
109 while ($sub->fetch()) {
111 $other = Remote_profile::staticGet($sub->subscribed);
113 $other = User::staticGet($sub->subscribed);
115 common_element('knows', array('rdf:resource' => $other->uri));
116 $person[$other->uri] = array(LISTENEE, $other);
120 # Get people who subscribe to user
122 $sub = new Subscription();
123 $sub->subscribed = $profile->id;
126 while ($sub->fetch()) {
128 $other = Remote_profile::staticGet($sub->subscribed);
130 $other = User::staticGet($sub->subscribed);
132 if (array_key_exists($other->uri, $person)) {
133 $person[$other->uri][0] = BOTH;
135 $person[$other->uri] = array(LISTENER, $other);
140 common_element_end('Person');
142 foreach ($person as $uri => $p) {
144 if ($p[1] instanceof User) {
145 $foaf_url = common_local_url('foaf', array('nickname' => $p[1]->nickname));
147 $profile = Profile::staticGet($p[1]->id);
148 common_element_start('Person', array('rdf:about' => $uri));
149 if ($p[0] == LISTENER || $p[0] == BOTH) {
150 common_element('knows', array('rdf:resource' => $user->uri));
152 $this->show_microblogging_account($profile, ($p[1] instanceof User) ?
153 common_root_url() : NULL);
155 common_element('rdfs:seeAlso', array('rdf:resource' => $foaf_url));
157 common_element_end('Person');
159 $this->show_ppd($foaf_url, $uri);
163 common_element_end('rdf:RDF');
166 function show_ppd($foaf_url, $person_uri) {
167 common_element_start('PersonalProfileDocument', array('rdf:about' => $foaf_url));
168 common_element('maker', array('rdf:resource' => $person_uri));
169 common_element('primaryTopic', array('rdf:resource' => $person_uri));
170 common_element_end('PersonalProfileDocument');
173 function show_microblogging_account($profile, $service=NULL) {
175 common_element_start('holdsAccount');
176 common_element_start('OnlineAccount');
178 common_element('accountServiceHomepage', array('rdf:resource' =>
181 common_element('accountName', NULL, $profile->nickname);
182 common_element('homepage', array('rdf:resource' => $profile->profileurl));
183 common_element_end('OnlineAccount');
184 common_element_end('holdsAccount');