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 * @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')) {
38 require_once INSTALLDIR . '/lib/apiprivateauth.php';
41 * Returns of the lastest 20 groups for the site
45 * @author Craig Andrews <candrews@integralblue.com>
46 * @author Evan Prodromou <evan@status.net>
47 * @author Jeffery To <jeffery.to@gmail.com>
48 * @author Zach Copley <zach@status.net>
49 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
50 * @link http://status.net/
53 class ApiGroupListAllAction extends ApiPrivateAuthAction
58 * Take arguments for running
60 * @param array $args $_REQUEST args
62 * @return boolean success flag
66 function prepare($args)
68 parent::prepare($args);
70 $this->user = $this->getTargetUser(null);
71 $this->groups = $this->getGroups();
79 * Show the user's groups
81 * @param array $args $_REQUEST data (unused)
86 function handle($args)
88 parent::handle($args);
90 $sitename = common_config('site', 'name');
91 // TRANS: Message is used as a title. %s is a site name.
92 $title = sprintf(_("%s groups"), $sitename);
93 $taguribase = TagURI::base();
94 $id = "tag:$taguribase:Groups";
95 $link = common_local_url('groups');
96 $subtitle = sprintf(_("groups on %s"), $sitename);
98 switch($this->format) {
100 $this->showXmlGroups($this->groups);
103 $this->showRssGroups($this->groups, $title, $link, $subtitle);
106 $selfuri = common_root_url() .
107 'api/statusnet/groups/list_all.atom';
108 $this->showAtomGroups(
118 $this->showJsonGroups($this->groups);
122 _('API method not found.'),
134 * @return array groups
139 $qry = 'SELECT user_group.* '.
140 'from user_group join local_group on user_group.id = local_group.group_id '.
141 'order by created desc ';
142 $offset = intval($this->page - 1) * intval($this->count);
143 $limit = intval($this->count);
144 if (common_config('db', 'type') == 'pgsql') {
145 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
147 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
149 $group = new User_group();
154 while ($group->fetch()) {
155 $groups[] = clone($group);
162 * Is this action read only?
164 * @param array $args other arguments
166 * @return boolean true
169 function isReadOnly($args)
175 * When was this feed last modified?
177 * @return string datestamp of the site's latest group
180 function lastModified()
182 if (!empty($this->groups) && (count($this->groups) > 0)) {
183 return strtotime($this->groups[0]->created);
190 * An entity tag for this list of groups
192 * Returns an Etag based on the action name, language, and
193 * timestamps of the first and last group the user has joined
195 * @return string etag
200 if (!empty($this->groups) && (count($this->groups) > 0)) {
202 $last = count($this->groups) - 1;
204 return '"' . implode(
206 array($this->arg('action'),
207 common_user_cache_hash($this->auth_user),
209 strtotime($this->groups[0]->created),
210 strtotime($this->groups[$last]->created))