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