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