3 * StatusNet, the distributed open-source microblogging tool
5 * Check to see whether a user a member of a group
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.
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.
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/>.
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/
34 if (!defined('STATUSNET')) {
39 * Returns whether a user is a member of a specified group.
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/
50 class ApiGroupListAction extends ApiBareAuthAction
55 * Take arguments for running
57 * @param array $args $_REQUEST args
59 * @return boolean success flag
61 function prepare($args)
63 parent::prepare($args);
65 $this->user = $this->getTargetUser(null);
67 if (empty($this->user)) {
68 // TRANS: Client error displayed when user not found for an action.
69 $this->clientError(_('No such user.'), 404, $this->format);
73 $this->groups = $this->getGroups();
81 * Show the user's groups
83 * @param array $args $_REQUEST data (unused)
87 function handle($args)
89 parent::handle($args);
91 $sitename = common_config('site', 'name');
92 // TRANS: Used as title in check for group membership. %s is a user name.
93 $title = sprintf(_("%s's groups"), $this->user->nickname);
94 $taguribase = TagURI::base();
95 $id = "tag:$taguribase:Groups";
96 $link = common_local_url(
98 array('nickname' => $this->user->nickname)
102 // TRANS: Used as subtitle in check for group membership. %1$s is the site name, %2$s is a user name.
103 _('%1$s groups %2$s is a member of.'),
105 $this->user->nickname
108 switch($this->format) {
110 $this->showXmlGroups($this->groups);
113 $this->showRssGroups($this->groups, $title, $link, $subtitle);
116 $selfuri = common_root_url() . 'api/statusnet/groups/list/' .
117 $this->user->id . '.atom';
118 $this->showAtomGroups(
128 $this->showJsonGroups($this->groups);
132 // TRANS: Client error displayed when coming across a non-supported API method.
133 _('API method not found.'),
144 * @return array groups
150 $group = $this->user->getGroups(
151 ($this->page - 1) * $this->count,
157 while ($group->fetch()) {
158 $groups[] = clone($group);
165 * Is this action read only?
167 * @param array $args other arguments
169 * @return boolean true
171 function isReadOnly($args)
177 * When was this feed last modified?
179 * @return string datestamp of the latest group the user has joined
182 function lastModified()
184 if (!empty($this->groups) && (count($this->groups) > 0)) {
185 return strtotime($this->groups[0]->created);
192 * An entity tag for this list of groups
194 * Returns an Etag based on the action name, language, user ID and
195 * timestamps of the first and last group the user has joined
197 * @return string etag
201 if (!empty($this->groups) && (count($this->groups) > 0)) {
203 $last = count($this->groups) - 1;
205 return '"' . implode(
207 array($this->arg('action'),
208 common_user_cache_hash($this->auth_user),
211 strtotime($this->groups[0]->created),
212 strtotime($this->groups[$last]->created))