]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/foafgroup.php
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / actions / foafgroup.php
1 <?php
2 /*
3  * StatusNet the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  *
19  * @category  Mail
20  * @package   StatusNet
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/
26  */
27
28 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
29
30 class FoafGroupAction extends Action
31 {
32     function isReadOnly($args)
33     {
34         return true;
35     }
36
37     function prepare($args)
38     {
39         parent::prepare($args);
40
41         $nickname_arg = $this->arg('nickname');
42
43         if (empty($nickname_arg)) {
44             $this->clientError(_('No such group.'), 404);
45             return false;
46         }
47
48         $this->nickname = common_canonical_nickname($nickname_arg);
49
50         // Permanent redirect on non-canonical nickname
51
52         if ($nickname_arg != $this->nickname) {
53             common_redirect(common_local_url('foafgroup',
54                                              array('nickname' => $this->nickname)),
55                             301);
56             return false;
57         }
58
59         $local = Local_group::staticGet('nickname', $nickname);
60
61         if (!$local) {
62             $this->clientError(_('No such group.'), 404);
63             return false;
64         }
65
66         $this->group = User_group::staticGet('id', $local->group_id);
67
68         if (!$this->group) {
69             $this->clientError(_('No such group.'), 404);
70             return false;
71         }
72
73         common_set_returnto($this->selfUrl());
74
75         return true;
76     }
77
78     function handle($args)
79     {
80         parent::handle($args);
81
82         header('Content-Type: application/rdf+xml');
83
84         $this->startXML();
85         $this->elementStart('rdf:RDF', array('xmlns:rdf' =>
86                                               'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
87                                               'xmlns:dcterms' =>
88                                               'http://purl.org/dc/terms/',
89                                               'xmlns:sioc' =>
90                                               'http://rdfs.org/sioc/ns#',
91                                               'xmlns:foaf' =>
92                                               'http://xmlns.com/foaf/0.1/',
93                                               'xmlns:statusnet' =>
94                                               'http://status.net/ont/',
95                                               'xmlns' => 'http://xmlns.com/foaf/0.1/'));
96
97         $this->showPpd(common_local_url('foafgroup', array('nickname' => $this->nickname)), $this->group->permalink());
98
99         $this->elementStart('Group', array('rdf:about' =>
100                                              $this->group->permalink()));
101         if ($this->group->fullname) {
102             $this->element('name', null, $this->group->fullname);
103         }
104         if ($this->group->description) {
105             $this->element('dcterms:description', null, $this->group->description);
106         }
107         if ($this->group->nickname) {
108             $this->element('dcterms:identifier', null, $this->group->nickname);
109             $this->element('nick', null, $this->group->nickname);
110         }
111         foreach ($this->group->getAliases() as $alias) {
112             $this->element('nick', null, $alias);
113         }
114         if ($this->group->homeUrl()) {
115             $this->element('weblog', array('rdf:resource' => $this->group->homeUrl()));
116         }
117         if ($this->group->homepage) {
118             $this->element('page', array('rdf:resource' => $this->group->homepage));
119         }
120         if ($this->group->homepage_logo) {
121             $this->element('depiction', array('rdf:resource' => $this->group->homepage_logo));
122         }
123
124         $members = $this->group->getMembers();
125         $member_details = array();
126         while ($members->fetch()) {
127             $member_uri = common_local_url('userbyid', array('id'=>$members->id));
128             $member_details[$member_uri] = array(
129                                         'nickname' => $members->nickname
130                                         );
131             $this->element('member', array('rdf:resource' => $member_uri));
132         }
133
134         $admins = $this->group->getAdmins();
135         while ($admins->fetch()) {
136             $admin_uri = common_local_url('userbyid', array('id'=>$admins->id));
137             $member_details[$admin_uri]['is_admin'] = true;
138             $this->element('statusnet:groupAdmin', array('rdf:resource' => $admin_uri));
139         }
140
141         $this->elementEnd('Group');
142
143         ksort($member_details);
144         foreach ($member_details as $uri => $details) {
145             if ($details['is_admin'])
146             {
147                 $this->elementStart('Agent', array('rdf:about' => $uri));
148                 $this->element('nick', null, $details['nickname']);
149                 $this->elementStart('holdsAccount');
150                 $this->elementStart('sioc:User', array('rdf:about'=>$uri.'#acct'));
151                 $this->elementStart('sioc:has_function');
152                 $this->elementStart('statusnet:GroupAdminRole');
153                 $this->element('sioc:scope', array('rdf:resource' => $this->group->permalink()));
154                 $this->elementEnd('statusnet:GroupAdminRole');
155                 $this->elementEnd('sioc:has_function');
156                 $this->elementEnd('sioc:User');
157                 $this->elementEnd('holdsAccount');
158                 $this->elementEnd('Agent');
159             }
160             else
161             {
162                 $this->element('Agent', array(
163                                         'foaf:nick' => $details['nickname'],
164                                         'rdf:about' => $uri,
165                                         ));
166             }
167         }
168
169         $this->elementEnd('rdf:RDF');
170         $this->endXML();
171     }
172
173     function showPpd($foaf_url, $person_uri)
174     {
175         $this->elementStart('Document', array('rdf:about' => $foaf_url));
176         $this->element('primaryTopic', array('rdf:resource' => $person_uri));
177         $this->elementEnd('Document');
178     }
179
180 }