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 require_once INSTALLDIR.'/lib/grouplist.php';
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
55 function isReadOnly($args)
62 if ($this->page == 1) {
63 return sprintf(_("%s groups"), $this->user->nickname);
65 return sprintf(_("%s groups, page %d"),
66 $this->user->nickname,
71 function prepare($args)
73 parent::prepare($args);
75 $nickname_arg = $this->arg('nickname');
76 $nickname = common_canonical_nickname($nickname_arg);
78 // Permanent redirect on non-canonical nickname
80 if ($nickname_arg != $nickname) {
81 $args = array('nickname' => $nickname);
82 if ($this->arg('page') && $this->arg('page') != 1) {
83 $args['page'] = $this->arg['page'];
85 common_redirect(common_local_url('usergroups', $args), 301);
89 $this->user = User::staticGet('nickname', $nickname);
92 $this->clientError(_('No such user.'), 404);
96 $this->profile = $this->user->getProfile();
98 if (!$this->profile) {
99 $this->serverError(_('User has no profile.'));
103 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
108 function handle($args)
110 parent::handle($args);
114 function showLocalNav()
116 $nav = new SubGroupNav($this, $this->user);
120 function showContent()
122 $this->elementStart('p', array('id' => 'new_group'));
123 $this->element('a', array('href' => common_local_url('newgroup'),
125 _('Create a new group'));
126 $this->elementEnd('p');
128 $this->elementStart('p', array('id' => 'group_search'));
129 $this->element('a', array('href' => common_local_url('groupsearch'),
131 _('Search for more groups'));
132 $this->elementEnd('p');
134 $offset = ($this->page-1) * GROUPS_PER_PAGE;
135 $limit = GROUPS_PER_PAGE + 1;
137 $groups = $this->user->getGroups($offset, $limit);
140 $gl = new GroupList($groups, $this->user, $this);
143 $this->showEmptyListMessage();
147 $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE,
148 $this->page, 'usergroups',
149 array('nickname' => $this->user->nickname));
152 function showEmptyListMessage()
154 $message = sprintf(_('%s is not a member of any group.'), $this->user->nickname) . ' ';
156 if (common_logged_in()) {
157 $current_user = common_current_user();
158 if ($this->user->id === $current_user->id) {
159 $message .= _('Try [searching for groups](%%action.groupsearch%%) and joining them.');
162 $this->elementStart('div', 'guide');
163 $this->raw(common_markup_to_html($message));
164 $this->elementEnd('div');