3 * StatusNet, the distributed open-source microblogging tool
5 * Show the newest groups
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/apiprivateauth.php';
40 * Returns of the lastest 20 groups for the site
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 ApiGroupListAllAction extends ApiPrivateAuthAction
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($id);
70 $this->groups = $this->getGroups();
78 * Show the user's groups
80 * @param array $args $_REQUEST data (unused)
85 function handle($args)
87 parent::handle($args);
89 $sitename = common_config('site', 'name');
90 $title = sprintf(_("%s groups"), $sitename);
91 $taguribase = TagURI::base();
92 $id = "tag:$taguribase:Groups";
93 $link = common_local_url('groups');
94 $subtitle = sprintf(_("groups on %s"), $sitename);
96 switch($this->format) {
98 $this->showXmlGroups($this->groups);
101 $this->showRssGroups($this->groups, $title, $link, $subtitle);
104 $selfuri = common_root_url() .
105 'api/statusnet/groups/list_all.atom';
106 $this->showAtomGroups(
116 $this->showJsonGroups($this->groups);
120 _('API method not found.'),
132 * @return array groups
137 $qry = 'SELECT user_group.* '.
138 'from user_group join local_group on user_group.id = local_group.group_id '.
139 'order by created desc ';
141 $group = new User_group();
145 while ($group->fetch()) {
146 $groups[] = clone($group);
153 * Is this action read only?
155 * @param array $args other arguments
157 * @return boolean true
160 function isReadOnly($args)
166 * When was this feed last modified?
168 * @return string datestamp of the site's latest group
171 function lastModified()
173 if (!empty($this->groups) && (count($this->groups) > 0)) {
174 return strtotime($this->groups[0]->created);
181 * An entity tag for this list of groups
183 * Returns an Etag based on the action name, language, and
184 * timestamps of the first and last group the user has joined
186 * @return string etag
191 if (!empty($this->groups) && (count($this->groups) > 0)) {
193 $last = count($this->groups) - 1;
195 return '"' . implode(
197 array($this->arg('action'),
199 strtotime($this->groups[0]->created),
200 strtotime($this->groups[$last]->created))