]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/usergroups.php
Document messages for which clarification was requested.
[quix0rs-gnu-social.git] / actions / usergroups.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * User groups information
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Personal
23  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/grouplist.php';
36
37 /**
38  * User groups page
39  *
40  * Show the groups a user belongs to
41  *
42  * @category Personal
43  * @package  StatusNet
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/
47  */
48
49 class UsergroupsAction extends OwnerDesignAction
50 {
51     var $page = null;
52     var $profile = null;
53
54     function isReadOnly($args)
55     {
56         return true;
57     }
58
59     function title()
60     {
61         if ($this->page == 1) {
62             // TRANS: Message is used as a page title. %s is a nick name.
63             return sprintf(_('%s groups'), $this->user->nickname);
64         } else {
65             // TRANS: Message is used as a page title. %1$s is a nick name, %2$d is a page number.
66             return sprintf(_('%1$s groups, page %2$d'),
67                            $this->user->nickname,
68                            $this->page);
69         }
70     }
71
72     function prepare($args)
73     {
74         parent::prepare($args);
75
76         $nickname_arg = $this->arg('nickname');
77         $nickname = common_canonical_nickname($nickname_arg);
78
79         // Permanent redirect on non-canonical nickname
80
81         if ($nickname_arg != $nickname) {
82             $args = array('nickname' => $nickname);
83             if ($this->arg('page') && $this->arg('page') != 1) {
84                 $args['page'] = $this->arg['page'];
85             }
86             common_redirect(common_local_url('usergroups', $args), 301);
87             return false;
88         }
89
90         $this->user = User::staticGet('nickname', $nickname);
91
92         if (!$this->user) {
93             $this->clientError(_('No such user.'), 404);
94             return false;
95         }
96
97         $this->profile = $this->user->getProfile();
98
99         if (!$this->profile) {
100             $this->serverError(_('User has no profile.'));
101             return false;
102         }
103
104         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
105
106         return true;
107     }
108
109     function handle($args)
110     {
111         parent::handle($args);
112         $this->showPage();
113     }
114
115     function showLocalNav()
116     {
117         $nav = new SubGroupNav($this, $this->user);
118         $nav->show();
119     }
120
121     function showContent()
122     {
123         $this->elementStart('p', array('id' => 'new_group'));
124         $this->element('a', array('href' => common_local_url('newgroup'),
125                                   'class' => 'more'),
126                        _('Create a new group'));
127         $this->elementEnd('p');
128
129         $this->elementStart('p', array('id' => 'group_search'));
130         $this->element('a', array('href' => common_local_url('groupsearch'),
131                                   'class' => 'more'),
132                        _('Search for more groups'));
133         $this->elementEnd('p');
134
135         if (Event::handle('StartShowUserGroupsContent', array($this))) {
136             $offset = ($this->page-1) * GROUPS_PER_PAGE;
137             $limit =  GROUPS_PER_PAGE + 1;
138
139             $groups = $this->user->getGroups($offset, $limit);
140
141             if ($groups) {
142                 $gl = new GroupList($groups, $this->user, $this);
143                 $cnt = $gl->show();
144                 if (0 == $cnt) {
145                     $this->showEmptyListMessage();
146                 }
147             }
148
149             $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE,
150                               $this->page, 'usergroups',
151                               array('nickname' => $this->user->nickname));
152
153             Event::handle('EndShowUserGroupsContent', array($this));
154         }
155     }
156
157     function showEmptyListMessage()
158     {
159         $message = sprintf(_('%s is not a member of any group.'), $this->user->nickname) . ' ';
160
161         if (common_logged_in()) {
162             $current_user = common_current_user();
163             if ($this->user->id === $current_user->id) {
164                 $message .= _('Try [searching for groups](%%action.groupsearch%%) and joining them.');
165             }
166         }
167         $this->elementStart('div', 'guide');
168         $this->raw(common_markup_to_html($message));
169         $this->elementEnd('div');
170     }
171 }