]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/usergroups.php
Merge branch '1.0.x' of git://gitorious.org/statusnet/mainline
[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 class UsergroupsAction extends OwnerDesignAction
49 {
50     var $page = null;
51     var $profile = null;
52
53     function isReadOnly($args)
54     {
55         return true;
56     }
57
58     function title()
59     {
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);
64         } else {
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,
69                            $this->page);
70         }
71     }
72
73     function prepare($args)
74     {
75         parent::prepare($args);
76
77         $nickname_arg = $this->arg('nickname');
78         $nickname = common_canonical_nickname($nickname_arg);
79
80         // Permanent redirect on non-canonical nickname
81
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'];
86             }
87             common_redirect(common_local_url('usergroups', $args), 301);
88             return false;
89         }
90
91         $this->user = User::staticGet('nickname', $nickname);
92
93         if (!$this->user) {
94             // TRANS: Client error displayed requesting groups for a non-existing user.
95             $this->clientError(_('No such user.'), 404);
96             return false;
97         }
98
99         $this->profile = $this->user->getProfile();
100
101         if (!$this->profile) {
102             // TRANS: Server error displayed requesting groups for a user without a profile.
103             $this->serverError(_('User has no profile.'));
104             return false;
105         }
106
107         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
108
109         return true;
110     }
111
112     function handle($args)
113     {
114         parent::handle($args);
115         $this->showPage();
116     }
117
118     function showObjectNav()
119     {
120         $nav = new SubGroupNav($this, $this->user);
121         $nav->show();
122     }
123
124     function showContent()
125     {
126         $this->elementStart('p', array('id' => 'new_group'));
127         $this->element('a', array('href' => common_local_url('newgroup'),
128                                   'class' => 'more'),
129                        // TRANS: Link text on group page to create a new group.
130                        _('Create a new group'));
131         $this->elementEnd('p');
132
133         $this->elementStart('p', array('id' => 'group_search'));
134         $this->element('a', array('href' => common_local_url('groupsearch'),
135                                   'class' => 'more'),
136                        // TRANS: Link text on group page to search for groups.
137                        _('Search for more groups'));
138         $this->elementEnd('p');
139
140         if (Event::handle('StartShowUserGroupsContent', array($this))) {
141             $offset = ($this->page-1) * GROUPS_PER_PAGE;
142             $limit =  GROUPS_PER_PAGE + 1;
143
144             $groups = $this->user->getGroups($offset, $limit);
145
146             if ($groups) {
147                 $gl = new GroupList($groups, $this->user, $this);
148                 $cnt = $gl->show();
149                 if (0 == $cnt) {
150                     $this->showEmptyListMessage();
151                 }
152             }
153
154             $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE,
155                               $this->page, 'usergroups',
156                               array('nickname' => $this->user->nickname));
157
158             Event::handle('EndShowUserGroupsContent', array($this));
159         }
160     }
161
162     function showEmptyListMessage()
163     {
164         // TRANS: Text on group page for a user that is not a member of any group.
165         // TRANS: %s is a user nickname.
166         $message = sprintf(_('%s is not a member of any group.'), $this->user->nickname) . ' ';
167
168         if (common_logged_in()) {
169             $current_user = common_current_user();
170             if ($this->user->id === $current_user->id) {
171                 // TRANS: Text on group page for a user that is not a member of any group. This message contains
172                 // TRANS: a Markdown link in the form [link text](link) and a variable that should not be changed.
173                 $message .= _('Try [searching for groups](%%action.groupsearch%%) and joining them.');
174             }
175         }
176         $this->elementStart('div', 'guide');
177         $this->raw(common_markup_to_html($message));
178         $this->elementEnd('div');
179     }
180
181     function showProfileBlock()
182     {
183         $block = new AccountProfileBlock($this, $this->profile);
184         $block->show();
185     }
186 }