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 Zach Copley <zach@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR . '/lib/api.php';
37 * Returns of the lastest 20 groups for the site
41 * @author Zach Copley <zach@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
46 class ApiGroupListAllAction extends ApiAction
51 * Take arguments for running
53 * @param array $args $_REQUEST args
55 * @return boolean success flag
59 function prepare($args)
61 parent::prepare($args);
63 $this->user = $this->getTargetUser($id);
64 $this->groups = $this->getGroups();
72 * Show the user's groups
74 * @param array $args $_REQUEST data (unused)
79 function handle($args)
81 parent::handle($args);
83 $sitename = common_config('site', 'name');
84 $title = sprintf(_("%s groups"), $sitename);
85 $taguribase = common_config('integration', 'taguri');
86 $id = "tag:$taguribase:Groups";
87 $link = common_local_url('groups');
88 $subtitle = sprintf(_("groups on %s"), $sitename);
90 switch($this->format) {
92 $this->showXmlGroups($this->groups);
95 $this->showRssGroups($this->groups, $title, $link, $subtitle);
98 $selfuri = common_root_url() .
99 'api/statusnet/groups/list_all.atom';
100 $this->showAtomGroups(
110 $this->showJsonGroups($this->groups);
114 _('API method not found!'),
126 * @return array groups
133 // XXX: Use the $page, $count, $max_id, $since_id, and $since parameters
135 $group = new User_group();
136 $group->orderBy('created DESC');
139 while ($group->fetch()) {
140 $groups[] = clone($group);
147 * Is this action read only?
149 * @param array $args other arguments
151 * @return boolean true
154 function isReadOnly($args)
160 * When was this feed last modified?
162 * @return string datestamp of the site's latest group
165 function lastModified()
167 if (!empty($this->groups) && (count($this->groups) > 0)) {
168 return strtotime($this->groups[0]->created);
175 * An entity tag for this list of groups
177 * Returns an Etag based on the action name, language, and
178 * timestamps of the first and last group the user has joined
180 * @return string etag
185 if (!empty($this->groups) && (count($this->groups) > 0)) {
187 $last = count($this->groups) - 1;
189 return '"' . implode(
191 array($this->arg('action'),
193 strtotime($this->groups[0]->created),
194 strtotime($this->groups[$last]->created))