]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apiatomservice.php
Removing unnecessary require_once lines (autoload!)
[quix0rs-gnu-social.git] / actions / apiatomservice.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * An AtomPub service document for a user
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  API
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2010 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * Shows an AtomPub service document for a user
36  *
37  * @category  API
38  * @package   StatusNet
39  * @author    Evan Prodromou <evan@status.net>
40  * @copyright 2010 StatusNet, Inc.
41  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
42  * @link      http://status.net/
43  */
44 class ApiAtomServiceAction extends ApiBareAuthAction
45 {
46     /**
47      * Take arguments for running
48      *
49      * @param array $args $_REQUEST args
50      *
51      * @return boolean success flag
52      *
53      */
54     function prepare($args)
55     {
56         parent::prepare($args);
57         $this->user = $this->getTargetUser($this->arg('id'));
58
59         if (empty($this->user)) {
60             // TRANS: Client error displayed when making an Atom API request for an unknown user.
61             $this->clientError(_('No such user.'), 404, $this->format);
62             return;
63         }
64
65         return true;
66     }
67
68     /**
69      * Handle the arguments. In our case, show a service document.
70      *
71      * @param Array $args unused.
72      *
73      * @return void
74      */
75     function handle($args)
76     {
77         parent::handle($args);
78
79         header('Content-Type: application/atomsvc+xml');
80
81         $this->startXML();
82         $this->elementStart('service', array('xmlns' => 'http://www.w3.org/2007/app',
83                                              'xmlns:atom' => 'http://www.w3.org/2005/Atom',
84                                              'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/'));
85         $this->elementStart('workspace');
86         // TRANS: Title for Atom feed.
87         $this->element('atom:title', null, _m('ATOM','Main'));
88         $this->elementStart('collection',
89                             array('href' => common_local_url('ApiTimelineUser',
90                                                              array('id' => $this->user->id,
91                                                                    'format' => 'atom'))));
92         $this->element('atom:title',
93                        null,
94                        // TRANS: Title for Atom feed. %s is a user nickname.
95                        sprintf(_("%s timeline"),
96                                $this->user->nickname));
97         $this->element('accept', null, 'application/atom+xml;type=entry');
98         $this->element('activity:verb', null, ActivityVerb::POST);
99         $this->elementEnd('collection');
100         $this->elementStart('collection',
101                             array('href' => common_local_url('AtomPubSubscriptionFeed',
102                                                              array('subscriber' => $this->user->id))));
103         $this->element('atom:title',
104                        null,
105                        // TRANS: Title for Atom feed with a user's subscriptions. %s is a user nickname.
106                        sprintf(_("%s subscriptions"),
107                                $this->user->nickname));
108         $this->element('accept', null, 'application/atom+xml;type=entry');
109         $this->element('activity:verb', null, ActivityVerb::FOLLOW);
110         $this->elementEnd('collection');
111         $this->elementStart('collection',
112                             array('href' => common_local_url('AtomPubFavoriteFeed',
113                                                              array('profile' => $this->user->id))));
114         $this->element('atom:title',
115                        null,
116                        // TRANS: Title for Atom feed with a user's favorite notices. %s is a user nickname.
117                        sprintf(_("%s favorites"),
118                                $this->user->nickname));
119         $this->element('accept', null, 'application/atom+xml;type=entry');
120         $this->element('activity:verb', null, ActivityVerb::FAVORITE);
121         $this->elementEnd('collection');
122         $this->elementStart('collection',
123                             array('href' => common_local_url('AtomPubMembershipFeed',
124                                                              array('profile' => $this->user->id))));
125         $this->element('atom:title',
126                        null,
127                        // TRANS: Title for Atom feed with a user's memberships. %s is a user nickname.
128                        sprintf(_("%s memberships"),
129                                $this->user->nickname));
130         $this->element('accept', null, 'application/atom+xml;type=entry');
131         $this->element('activity:verb', null, ActivityVerb::JOIN);
132         $this->elementEnd('collection');
133         $this->elementEnd('workspace');
134         $this->elementEnd('service');
135         $this->endXML();
136     }
137 }