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/>.
21 * @author Evan Prodromou <evan@status.net>
22 * @author Toby Inkster <mail@tobyinkster.co.uk>
23 * @copyright 2009 StatusNet, Inc.
24 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
25 * @link http://status.net/
28 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
30 // @todo XXX: Documentation missing.
31 class FoafGroupAction extends Action
33 function isReadOnly($args)
38 function prepare($args)
40 parent::prepare($args);
42 $nickname_arg = $this->arg('nickname');
44 if (empty($nickname_arg)) {
45 // TRANS: Client error displayed when requesting Friends of a Friend feed without providing a group nickname.
46 $this->clientError(_('No such group.'), 404);
50 $this->nickname = common_canonical_nickname($nickname_arg);
52 // Permanent redirect on non-canonical nickname
54 if ($nickname_arg != $this->nickname) {
55 common_redirect(common_local_url('foafgroup',
56 array('nickname' => $this->nickname)),
61 $local = Local_group::staticGet('nickname', $this->nickname);
64 // TRANS: Client error displayed when requesting Friends of a Friend feed for a non-local group.
65 $this->clientError(_('No such group.'), 404);
69 $this->group = User_group::staticGet('id', $local->group_id);
72 // TRANS: Client error displayed when requesting Friends of a Friend feed for a nickname that is not a group.
73 $this->clientError(_('No such group.'), 404);
77 common_set_returnto($this->selfUrl());
82 function handle($args)
84 parent::handle($args);
86 header('Content-Type: application/rdf+xml');
89 $this->elementStart('rdf:RDF', array('xmlns:rdf' =>
90 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
92 'http://purl.org/dc/terms/',
94 'http://rdfs.org/sioc/ns#',
96 'http://xmlns.com/foaf/0.1/',
98 'http://status.net/ont/',
99 'xmlns' => 'http://xmlns.com/foaf/0.1/'));
101 $this->showPpd(common_local_url('foafgroup', array('nickname' => $this->nickname)), $this->group->permalink());
103 $this->elementStart('Group', array('rdf:about' =>
104 $this->group->permalink()));
105 if ($this->group->fullname) {
106 $this->element('name', null, $this->group->fullname);
108 if ($this->group->description) {
109 $this->element('dcterms:description', null, $this->group->description);
111 if ($this->group->nickname) {
112 $this->element('dcterms:identifier', null, $this->group->nickname);
113 $this->element('nick', null, $this->group->nickname);
115 foreach ($this->group->getAliases() as $alias) {
116 $this->element('nick', null, $alias);
118 if ($this->group->homeUrl()) {
119 $this->element('weblog', array('rdf:resource' => $this->group->homeUrl()));
121 if ($this->group->homepage) {
122 $this->element('page', array('rdf:resource' => $this->group->homepage));
124 if ($this->group->homepage_logo) {
125 $this->element('depiction', array('rdf:resource' => $this->group->homepage_logo));
128 $members = $this->group->getMembers();
129 $member_details = array();
130 while ($members->fetch()) {
131 $member_uri = common_local_url('userbyid', array('id'=>$members->id));
132 $member_details[$member_uri] = array(
133 'nickname' => $members->nickname,
136 $this->element('member', array('rdf:resource' => $member_uri));
139 $admins = $this->group->getAdmins();
140 while ($admins->fetch()) {
141 $admin_uri = common_local_url('userbyid', array('id'=>$admins->id));
142 $member_details[$admin_uri]['is_admin'] = true;
143 $this->element('statusnet:groupAdmin', array('rdf:resource' => $admin_uri));
146 $this->elementEnd('Group');
148 ksort($member_details);
149 foreach ($member_details as $uri => $details) {
150 if ($details['is_admin'])
152 $this->elementStart('Agent', array('rdf:about' => $uri));
153 $this->element('nick', null, $details['nickname']);
154 $this->elementStart('account');
155 $this->elementStart('sioc:User', array('rdf:about'=>$uri.'#acct'));
156 $this->elementStart('sioc:has_function');
157 $this->elementStart('statusnet:GroupAdminRole');
158 $this->element('sioc:scope', array('rdf:resource' => $this->group->permalink()));
159 $this->elementEnd('statusnet:GroupAdminRole');
160 $this->elementEnd('sioc:has_function');
161 $this->elementEnd('sioc:User');
162 $this->elementEnd('account');
163 $this->elementEnd('Agent');
167 $this->element('Agent', array(
168 'foaf:nick' => $details['nickname'],
174 $this->elementEnd('rdf:RDF');
178 function showPpd($foaf_url, $person_uri)
180 $this->elementStart('Document', array('rdf:about' => $foaf_url));
181 $this->element('primaryTopic', array('rdf:resource' => $person_uri));
182 $this->elementEnd('Document');