]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/usergroups.php
isReadOnly() now takes arguments
[quix0rs-gnu-social.git] / actions / usergroups.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
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/
29  */
30
31 if (!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  Laconica
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/
47  */
48
49 class UsergroupsAction extends Action
50 {
51     var $user = null;
52     var $page = null;
53     var $profile = null;
54
55     function isReadOnly($args)
56     {
57         return true;
58     }
59
60     function title()
61     {
62         if ($this->page == 1) {
63             return sprintf(_("%s groups"), $this->user->nickname);
64         } else {
65             return sprintf(_("%s groups, page %d"),
66                            $this->user->nickname,
67                            $this->page);
68         }
69     }
70
71     function prepare($args)
72     {
73         parent::prepare($args);
74
75         $nickname_arg = $this->arg('nickname');
76         $nickname = common_canonical_nickname($nickname_arg);
77
78         // Permanent redirect on non-canonical nickname
79
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'];
84             }
85             common_redirect(common_local_url('usergroups', $args), 301);
86             return false;
87         }
88
89         $this->user = User::staticGet('nickname', $nickname);
90
91         if (!$this->user) {
92             $this->clientError(_('No such user.'), 404);
93             return false;
94         }
95
96         $this->profile = $this->user->getProfile();
97
98         if (!$this->profile) {
99             $this->serverError(_('User has no profile.'));
100             return false;
101         }
102
103         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
104
105         return true;
106     }
107
108     function handle($args)
109     {
110         parent::handle($args);
111         $this->showPage();
112     }
113
114     function showLocalNav()
115     {
116         $nav = new SubGroupNav($this, $this->user);
117         $nav->show();
118     }
119
120     function showContent()
121     {
122         $this->elementStart('p', array('id' => 'new_group'));
123         $this->element('a', array('href' => common_local_url('newgroup'),
124                                   'class' => 'more'),
125                        _('Create a new group'));
126         $this->elementEnd('p');
127
128         $this->elementStart('p', array('id' => 'group_search'));
129         $this->element('a', array('href' => common_local_url('groupsearch'),
130                                   'class' => 'more'),
131                        _('Search for more groups'));
132         $this->elementEnd('p');
133
134         $offset = ($this->page-1) * GROUPS_PER_PAGE;
135         $limit =  GROUPS_PER_PAGE + 1;
136
137         $groups = $this->user->getGroups($offset, $limit);
138
139         if ($groups) {
140             $gl = new GroupList($groups, $this->user, $this);
141             $cnt = $gl->show();
142             if (0 == $cnt) {
143                 $this->showEmptyListMessage();
144             }
145         }
146
147         $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE,
148                           $this->page, 'usergroups',
149                           array('nickname' => $this->user->nickname));
150     }
151
152     function showEmptyListMessage()
153     {
154         $message = sprintf(_('%s is not a member of any group.'), $this->user->nickname) . ' ';
155
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.');
160             }
161         }
162         $this->elementStart('div', 'guide');
163         $this->raw(common_markup_to_html($message));
164         $this->elementEnd('div');
165     }
166 }