]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apigroupmembership.php
Ticket #2750: fixes to HTTP caching behavior across login/logout boundaries
[quix0rs-gnu-social.git] / actions / apigroupmembership.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List a group's members
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    Craig Andrews <candrews@integralblue.com>
25  * @author    Evan Prodromou <evan@status.net>
26  * @author    Jeffery To <jeffery.to@gmail.com>
27  * @author    Zach Copley <zach@status.net>
28  * @copyright 2009 StatusNet, Inc.
29  * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
30  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
31  * @link      http://status.net/
32  */
33
34 if (!defined('STATUSNET')) {
35     exit(1);
36 }
37
38 require_once INSTALLDIR . '/lib/apiprivateauth.php';
39
40 /**
41  * List 20 newest members of the group specified by name or ID.
42  *
43  * @category API
44  * @package  StatusNet
45  * @author   Craig Andrews <candrews@integralblue.com>
46  * @author   Evan Prodromou <evan@status.net>
47  * @author   Jeffery To <jeffery.to@gmail.com>
48  * @author   Zach Copley <zach@status.net>
49  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
50  * @link     http://status.net/
51  */
52
53 class ApiGroupMembershipAction extends ApiPrivateAuthAction
54 {
55     var $group    = null;
56     var $profiles = null;
57
58     /**
59      * Take arguments for running
60      *
61      * @param array $args $_REQUEST args
62      *
63      * @return boolean success flag
64      *
65      */
66
67     function prepare($args)
68     {
69         parent::prepare($args);
70
71         $this->group    = $this->getTargetGroup($this->arg('id'));
72         $this->profiles = $this->getProfiles();
73
74         return true;
75     }
76
77     /**
78      * Handle the request
79      *
80      * Show the members of the group
81      *
82      * @param array $args $_REQUEST data (unused)
83      *
84      * @return void
85      */
86
87     function handle($args)
88     {
89         parent::handle($args);
90
91         if (empty($this->group)) {
92             $this->clientError(_('Group not found.'), 404, $this->format);
93             return false;
94         }
95
96         // XXX: RSS and Atom
97
98         switch($this->format) {
99         case 'xml':
100             $this->showTwitterXmlUsers($this->profiles);
101             break;
102         case 'json':
103             $this->showJsonUsers($this->profiles);
104             break;
105         default:
106             $this->clientError(
107                 _('API method not found.'),
108                 404,
109                 $this->format
110             );
111             break;
112         }
113     }
114
115     /**
116      * Fetch the members of a group
117      *
118      * @return array $profiles list of profiles
119      */
120
121     function getProfiles()
122     {
123         $profiles = array();
124
125         $profile = $this->group->getMembers(
126             ($this->page - 1) * $this->count,
127             $this->count,
128             $this->since_id,
129             $this->max_id
130         );
131
132         while ($profile->fetch()) {
133             $profiles[] = clone($profile);
134         }
135
136         return $profiles;
137     }
138
139     /**
140      * Is this action read only?
141      *
142      * @param array $args other arguments
143      *
144      * @return boolean true
145      */
146
147     function isReadOnly($args)
148     {
149         return true;
150     }
151
152     /**
153      * When was this list of profiles last modified?
154      *
155      * @return string datestamp of the lastest profile in the group
156      */
157
158     function lastModified()
159     {
160         if (!empty($this->profiles) && (count($this->profiles) > 0)) {
161             return strtotime($this->profiles[0]->created);
162         }
163
164         return null;
165     }
166
167     /**
168      * An entity tag for this list of groups
169      *
170      * Returns an Etag based on the action name, language
171      * the group id, and timestamps of the first and last
172      * user who has joined the group
173      *
174      * @return string etag
175      */
176
177     function etag()
178     {
179         if (!empty($this->profiles) && (count($this->profiles) > 0)) {
180
181             $last = count($this->profiles) - 1;
182
183             return '"' . implode(
184                 ':',
185                 array($this->arg('action'),
186                       common_user_cache_hash($this->auth_user),
187                       common_language(),
188                       $this->group->id,
189                       strtotime($this->profiles[0]->created),
190                       strtotime($this->profiles[$last]->created))
191             )
192             . '"';
193         }
194
195         return null;
196     }
197
198 }