3 * StatusNet, 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@status.net>
25 * @author Sarven Capadisli <csarven@status.net>
26 * @copyright 2008-2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 require_once INSTALLDIR.'/lib/grouplist.php';
40 * Show the groups a user belongs to
44 * @author Evan Prodromou <evan@status.net>
45 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46 * @link http://status.net/
48 class UsergroupsAction extends ProfileAction
53 function isReadOnly($args)
60 if ($this->page == 1) {
61 // TRANS: Page title for first page of groups for a user.
62 // TRANS: %s is a nickname.
63 return sprintf(_('%s groups'), $this->user->nickname);
65 // TRANS: Page title for all but the first page of groups for a user.
66 // TRANS: %1$s is a nickname, %2$d is a page number.
67 return sprintf(_('%1$s groups, page %2$d'),
68 $this->user->nickname,
73 function prepare($args)
75 parent::prepare($args);
77 $nickname_arg = $this->arg('nickname');
78 $nickname = common_canonical_nickname($nickname_arg);
80 // Permanent redirect on non-canonical nickname
82 if ($nickname_arg != $nickname) {
83 $args = array('nickname' => $nickname);
84 if ($this->arg('page') && $this->arg('page') != 1) {
85 $args['page'] = $this->arg['page'];
87 common_redirect(common_local_url('usergroups', $args), 301);
91 $this->user = User::staticGet('nickname', $nickname);
94 // TRANS: Client error displayed requesting groups for a non-existing user.
95 $this->clientError(_('No such user.'), 404);
99 $this->profile = $this->user->getProfile();
101 if (!$this->profile) {
102 // TRANS: Error message displayed when referring to a user without a profile.
103 $this->serverError(_('User has no profile.'));
107 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
112 function handle($args)
114 parent::handle($args);
118 function showContent()
120 $this->elementStart('p', array('id' => 'new_group'));
121 $this->element('a', array('href' => common_local_url('newgroup'),
123 // TRANS: Link text on group page to create a new group.
124 _('Create a new group'));
125 $this->elementEnd('p');
127 $this->elementStart('p', array('id' => 'group_search'));
128 $this->element('a', array('href' => common_local_url('groupsearch'),
130 // TRANS: Link text on group page to search for groups.
131 _('Search for more groups'));
132 $this->elementEnd('p');
134 if (Event::handle('StartShowUserGroupsContent', array($this))) {
135 $offset = ($this->page-1) * GROUPS_PER_PAGE;
136 $limit = GROUPS_PER_PAGE + 1;
138 $groups = $this->user->getGroups($offset, $limit);
141 $gl = new GroupList($groups, $this->user, $this);
144 $this->showEmptyListMessage();
148 $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE,
149 $this->page, 'usergroups',
150 array('nickname' => $this->user->nickname));
152 Event::handle('EndShowUserGroupsContent', array($this));
156 function showEmptyListMessage()
158 // TRANS: Text on group page for a user that is not a member of any group.
159 // TRANS: %s is a user nickname.
160 $message = sprintf(_('%s is not a member of any group.'), $this->user->nickname) . ' ';
162 if (common_logged_in()) {
163 $current_user = common_current_user();
164 if ($this->user->id === $current_user->id) {
165 // TRANS: Text on group page for a user that is not a member of any group. This message contains
166 // TRANS: a Markdown link in the form [link text](link) and a variable that should not be changed.
167 $message .= _('Try [searching for groups](%%action.groupsearch%%) and joining them.');
170 $this->elementStart('div', 'guide');
171 $this->raw(common_markup_to_html($message));
172 $this->elementEnd('div');
175 function showProfileBlock()
177 $block = new AccountProfileBlock($this, $this->profile);