3 * Laconica, the distributed open-source microblogging tool
5 * User groups information
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 Evan Prodromou <evan@controlyourself.ca>
25 * @author Sarven Capadisli <csarven@controlyourself.ca>
26 * @copyright 2008-2009 Control Yourself, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://laconi.ca/
31 if (!defined('LACONICA')) {
35 define('GROUPS_PER_PAGE', 20);
40 * Show the groups a user belongs to
44 * @author Evan Prodromou <evan@controlyourself.ca>
45 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46 * @link http://laconi.ca/
49 class UsergroupsAction extends Action
57 if ($this->page == 1) {
58 return sprintf(_("%s groups"), $this->user->nickname);
60 return sprintf(_("%s groups, page %d"),
61 $this->user->nickname,
66 function prepare($args)
68 parent::prepare($args);
70 $nickname_arg = $this->arg('nickname');
71 $nickname = common_canonical_nickname($nickname_arg);
73 // Permanent redirect on non-canonical nickname
75 if ($nickname_arg != $nickname) {
76 $args = array('nickname' => $nickname);
77 if ($this->arg('page') && $this->arg('page') != 1) {
78 $args['page'] = $this->arg['page'];
80 common_redirect(common_local_url('usergroups', $args), 301);
84 $this->user = User::staticGet('nickname', $nickname);
87 $this->clientError(_('No such user.'), 404);
91 $this->profile = $this->user->getProfile();
93 if (!$this->profile) {
94 $this->serverError(_('User has no profile.'));
98 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
103 function handle($args)
105 parent::handle($args);
109 function showLocalNav()
111 $nav = new SubGroupNav($this, $this->user);
115 function showContent()
117 $offset = ($this->page-1) * GROUPS_PER_PAGE;
118 $limit = GROUPS_PER_PAGE + 1;
120 $groups = $this->user->getGroups($offset, $limit);
123 $gl = new GroupList($groups, $this->user, $this);
127 $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE,
128 $this->page, 'usergroups',
129 array('nickname' => $this->user->nickname));