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