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/
52 class ApiGroupListAllAction extends ApiPrivateAuthAction
57 * Take arguments for running
59 * @param array $args $_REQUEST args
61 * @return boolean success flag
63 function prepare($args)
65 parent::prepare($args);
67 $this->user = $this->getTargetUser(null);
68 $this->groups = $this->getGroups();
76 * Show the user's groups
78 * @param array $args $_REQUEST data (unused)
82 function handle($args)
84 parent::handle($args);
86 $sitename = common_config('site', 'name');
87 // TRANS: Message is used as a title when listing the lastest 20 groups. %s is a site name.
88 $title = sprintf(_("%s groups"), $sitename);
89 $taguribase = TagURI::base();
90 $id = "tag:$taguribase:Groups";
91 $link = common_local_url('groups');
92 // TRANS: Message is used as a subtitle when listing the latest 20 groups. %s is a site name.
93 $subtitle = sprintf(_("groups on %s"), $sitename);
95 switch($this->format) {
97 $this->showXmlGroups($this->groups);
100 $this->showRssGroups($this->groups, $title, $link, $subtitle);
103 $selfuri = common_root_url() .
104 'api/statusnet/groups/list_all.atom';
105 $this->showAtomGroups(
115 $this->showJsonGroups($this->groups);
119 // TRANS: Client error displayed when coming across a non-supported API method.
120 _('API method not found.'),
131 * @return array groups
135 $qry = 'SELECT user_group.* '.
136 'from user_group join local_group on user_group.id = local_group.group_id '.
137 'order by created desc ';
138 $offset = intval($this->page - 1) * intval($this->count);
139 $limit = intval($this->count);
140 if (common_config('db', 'type') == 'pgsql') {
141 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
143 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
145 $group = new User_group();
150 while ($group->fetch()) {
151 $groups[] = clone($group);
158 * Is this action read only?
160 * @param array $args other arguments
162 * @return boolean true
164 function isReadOnly($args)
170 * When was this feed last modified?
172 * @return string datestamp of the site's latest group
174 function lastModified()
176 if (!empty($this->groups) && (count($this->groups) > 0)) {
177 return strtotime($this->groups[0]->created);
184 * An entity tag for this list of groups
186 * Returns an Etag based on the action name, language, and
187 * timestamps of the first and last group the user has joined
189 * @return string etag
193 if (!empty($this->groups) && (count($this->groups) > 0)) {
195 $last = count($this->groups) - 1;
197 return '"' . implode(
199 array($this->arg('action'),
200 common_user_cache_hash($this->auth_user),
202 strtotime($this->groups[0]->created),
203 strtotime($this->groups[$last]->created))