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 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
30 * @link http://status.net/
33 if (!defined('STATUSNET')) {
37 require_once INSTALLDIR . '/lib/apibareauth.php';
40 * Returns whether a user is a member of a specified group.
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/
52 class ApiGroupListAction extends ApiBareAuthAction
57 * Take arguments for running
59 * @param array $args $_REQUEST args
61 * @return boolean success flag
65 function prepare($args)
67 parent::prepare($args);
69 $this->user = $this->getTargetUser(null);
71 if (empty($this->user)) {
72 $this->clientError(_('No such user.'), 404, $this->format);
76 $this->groups = $this->getGroups();
84 * Show the user's groups
86 * @param array $args $_REQUEST data (unused)
91 function handle($args)
93 parent::handle($args);
95 $sitename = common_config('site', 'name');
96 // TRANS: %s is a user name
97 $title = sprintf(_("%s's groups"), $this->user->nickname);
98 $taguribase = TagURI::base();
99 $id = "tag:$taguribase:Groups";
100 $link = common_local_url(
102 array('nickname' => $this->user->nickname)
106 // TRANS: Meant to convey the user %2$s is a member of each of the groups listed on site %1$s
107 _("%1\$s groups %2\$s is a member of."),
109 $this->user->nickname
112 switch($this->format) {
114 $this->showXmlGroups($this->groups);
117 $this->showRssGroups($this->groups, $title, $link, $subtitle);
120 $selfuri = common_root_url() . 'api/statusnet/groups/list/' .
121 $this->user->id . '.atom';
122 $this->showAtomGroups(
132 $this->showJsonGroups($this->groups);
136 _('API method not found.'),
148 * @return array groups
155 $group = $this->user->getGroups(
156 ($this->page - 1) * $this->count,
162 while ($group->fetch()) {
163 $groups[] = clone($group);
170 * Is this action read only?
172 * @param array $args other arguments
174 * @return boolean true
177 function isReadOnly($args)
183 * When was this feed last modified?
185 * @return string datestamp of the latest group the user has joined
188 function lastModified()
190 if (!empty($this->groups) && (count($this->groups) > 0)) {
191 return strtotime($this->groups[0]->created);
198 * An entity tag for this list of groups
200 * Returns an Etag based on the action name, language, user ID and
201 * timestamps of the first and last group the user has joined
203 * @return string etag
208 if (!empty($this->groups) && (count($this->groups) > 0)) {
210 $last = count($this->groups) - 1;
212 return '"' . implode(
214 array($this->arg('action'),
217 strtotime($this->groups[0]->created),
218 strtotime($this->groups[$last]->created))