]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apigroupadmins.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / actions / apigroupadmins.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List a group's admins
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   GNUsocial
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  * @author    Hannes Mannerheim <h@nnesmannerhe.im>
29  * @copyright 2009 StatusNet, Inc.
30  * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
31  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
32  * @link      http://www.gnu.org/software/social/
33  */
34
35 if (!defined('GNUSOCIAL')) {
36     exit(1);
37 }
38
39 /**
40  * List 20 newest admins of the group specified by name or ID.
41  *
42  * @category API
43  * @package  GNUsocial
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  * @author   Hannes Mannerheim <h@nnesmannerhe.im> 
49  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
50  * @link     http://www.gnu.org/software/social/
51  */
52 class ApiGroupAdminsAction 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     protected function prepare(array $args=array())
65     {
66         parent::prepare($args);
67
68         $this->group    = $this->getTargetGroup($this->arg('id'));
69         if (empty($this->group)) {
70             // TRANS: Client error displayed trying to show group membership on a non-existing group.
71             $this->clientError(_('Group not found.'), 404);
72         }
73
74         $this->profiles = $this->getProfiles();
75
76         return true;
77     }
78
79     /**
80      * Handle the request
81      *
82      * Show the admin of the group
83      *
84      * @param array $args $_REQUEST data (unused)
85      *
86      * @return void
87      */
88     protected function handle()
89     {
90         parent::handle();
91
92         // XXX: RSS and Atom
93
94         switch($this->format) {
95         case 'xml':
96             $this->showTwitterXmlUsers($this->profiles);
97             break;
98         case 'json':
99             $this->showJsonUsers($this->profiles);
100             break;
101         default:
102             $this->clientError(
103                 // TRANS: Client error displayed when coming across a non-supported API method.
104                 _('API method not found.'),
105                 404,
106                 $this->format
107             );
108             break;
109         }
110     }
111
112     /**
113      * Fetch the admins of a group
114      *
115      * @return array $profiles list of profiles
116      */
117     function getProfiles()
118     {
119         $profiles = array();
120
121         $profile = $this->group->getAdmins(
122             ($this->page - 1) * $this->count,
123             $this->count,
124             $this->since_id,
125             $this->max_id
126         );
127
128         while ($profile->fetch()) {
129             $profiles[] = clone($profile);
130         }
131
132         return $profiles;
133     }
134
135     /**
136      * Is this action read only?
137      *
138      * @param array $args other arguments
139      *
140      * @return boolean true
141      */
142     function isReadOnly(array $args=array())
143     {
144         return true;
145     }
146
147     /**
148      * When was this list of profiles last modified?
149      *
150      * @return string datestamp of the lastest profile in the group
151      */
152     function lastModified()
153     {
154         if (!empty($this->profiles) && (count($this->profiles) > 0)) {
155             return strtotime($this->profiles[0]->created);
156         }
157
158         return null;
159     }
160
161     /**
162      * An entity tag for this list of groups
163      *
164      * Returns an Etag based on the action name, language
165      * the group id, and timestamps of the first and last
166      * user who has joined the group
167      *
168      * @return string etag
169      */
170     function etag()
171     {
172         if (!empty($this->profiles) && (count($this->profiles) > 0)) {
173
174             $last = count($this->profiles) - 1;
175
176             return '"' . implode(
177                 ':',
178                 array($this->arg('action'),
179                       common_user_cache_hash($this->auth_user),
180                       common_language(),
181                       $this->group->id,
182                       strtotime($this->profiles[0]->created),
183                       strtotime($this->profiles[$last]->created))
184             )
185             . '"';
186         }
187
188         return null;
189     }
190 }