]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apiatomservice.php
Merge branch 'testing'
[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 require_once INSTALLDIR.'/lib/apibareauth.php';
31
32 /**
33  * Shows an AtomPub service document for a user
34  *
35  * @category  API
36  * @package   StatusNet
37  * @author    Evan Prodromou <evan@status.net>
38  * @copyright 2010 StatusNet, Inc.
39  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
40  * @link      http://status.net/
41  */
42 class ApiAtomServiceAction extends ApiBareAuthAction
43 {
44     /**
45      * Take arguments for running
46      *
47      * @param array $args $_REQUEST args
48      *
49      * @return boolean success flag
50      *
51      */
52     function prepare($args)
53     {
54         parent::prepare($args);
55         $this->user = $this->getTargetUser($this->arg('id'));
56
57         if (empty($this->user)) {
58             // TRANS: Client error displayed when making an Atom API request for an unknown user.
59             $this->clientError(_('No such user.'), 404, $this->format);
60             return;
61         }
62
63         return true;
64     }
65
66     /**
67      * Handle the arguments. In our case, show a service document.
68      *
69      * @param Array $args unused.
70      *
71      * @return void
72      */
73     function handle($args)
74     {
75         parent::handle($args);
76
77         header('Content-Type: application/atomsvc+xml');
78
79         $this->startXML();
80         $this->elementStart('service', array('xmlns' => 'http://www.w3.org/2007/app',
81                                              'xmlns:atom' => 'http://www.w3.org/2005/Atom',
82                                              'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/'));
83         $this->elementStart('workspace');
84         // TRANS: Title for Atom feed.
85         $this->element('atom:title', null, _m('ATOM','Main'));
86         $this->elementStart('collection',
87                             array('href' => common_local_url('ApiTimelineUser',
88                                                              array('id' => $this->user->id,
89                                                                    'format' => 'atom'))));
90         $this->element('atom:title',
91                        null,
92                        // TRANS: Title for Atom feed. %s is a user nickname.
93                        sprintf(_("%s timeline"),
94                                $this->user->nickname));
95         $this->element('accept', null, 'application/atom+xml;type=entry');
96         $this->element('activity:verb', null, ActivityVerb::POST);
97         $this->elementEnd('collection');
98         $this->elementStart('collection',
99                             array('href' => common_local_url('AtomPubSubscriptionFeed',
100                                                              array('subscriber' => $this->user->id))));
101         $this->element('atom:title',
102                        null,
103                        // TRANS: Title for Atom feed with a user's subscriptions. %s is a user nickname.
104                        sprintf(_("%s subscriptions"),
105                                $this->user->nickname));
106         $this->element('accept', null, 'application/atom+xml;type=entry');
107         $this->element('activity:verb', null, ActivityVerb::FOLLOW);
108         $this->elementEnd('collection');
109         $this->elementStart('collection',
110                             array('href' => common_local_url('AtomPubFavoriteFeed',
111                                                              array('profile' => $this->user->id))));
112         $this->element('atom:title',
113                        null,
114                        // TRANS: Title for Atom feed with a user's favorite notices. %s is a user nickname.
115                        sprintf(_("%s favorites"),
116                                $this->user->nickname));
117         $this->element('accept', null, 'application/atom+xml;type=entry');
118         $this->element('activity:verb', null, ActivityVerb::FAVORITE);
119         $this->elementEnd('collection');
120         $this->elementStart('collection',
121                             array('href' => common_local_url('AtomPubMembershipFeed',
122                                                              array('profile' => $this->user->id))));
123         $this->element('atom:title',
124                        null,
125                        // TRANS: Title for Atom feed with a user's memberships. %s is a user nickname.
126                        sprintf(_("%s memberships"),
127                                $this->user->nickname));
128         $this->element('accept', null, 'application/atom+xml;type=entry');
129         $this->element('activity:verb', null, ActivityVerb::JOIN);
130         $this->elementEnd('collection');
131         $this->elementEnd('workspace');
132         $this->elementEnd('service');
133         $this->endXML();
134     }
135 }