]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/groupmembers.php
isReadOnly() now takes arguments
[quix0rs-gnu-social.git] / actions / groupmembers.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * List of group members
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  Group
23  * @package   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @copyright 2008-2009 Control Yourself, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once(INSTALLDIR.'/lib/profilelist.php');
35 require_once INSTALLDIR.'/lib/publicgroupnav.php';
36
37 /**
38  * List of group members
39  *
40  * @category Group
41  * @package  Laconica
42  * @author   Evan Prodromou <evan@controlyourself.ca>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://laconi.ca/
45  */
46
47 class GroupmembersAction extends Action
48 {
49     var $page = null;
50
51     function isReadOnly($args)
52     {
53         return true;
54     }
55
56     function prepare($args)
57     {
58         parent::prepare($args);
59         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
60
61         $nickname_arg = $this->arg('nickname');
62         $nickname = common_canonical_nickname($nickname_arg);
63
64         // Permanent redirect on non-canonical nickname
65
66         if ($nickname_arg != $nickname) {
67             $args = array('nickname' => $nickname);
68             if ($this->page != 1) {
69                 $args['page'] = $this->page;
70             }
71             common_redirect(common_local_url('groupmembers', $args), 301);
72             return false;
73         }
74
75         if (!$nickname) {
76             $this->clientError(_('No nickname'), 404);
77             return false;
78         }
79
80         $this->group = User_group::staticGet('nickname', $nickname);
81
82         if (!$this->group) {
83             $this->clientError(_('No such group'), 404);
84             return false;
85         }
86
87         return true;
88     }
89
90     function title()
91     {
92         if ($this->page == 1) {
93             return sprintf(_('%s group members'),
94                            $this->group->nickname);
95         } else {
96             return sprintf(_('%s group members, page %d'),
97                            $this->group->nickname,
98                            $this->page);
99         }
100     }
101
102     function handle($args)
103     {
104         parent::handle($args);
105         $this->showPage();
106     }
107
108     function showPageNotice()
109     {
110         $this->element('p', 'instructions',
111                        _('A list of the users in this group.'));
112     }
113
114     function showLocalNav()
115     {
116         $nav = new GroupNav($this, $this->group);
117         $nav->show();
118     }
119
120     function showContent()
121     {
122         $offset = ($this->page-1) * PROFILES_PER_PAGE;
123         $limit =  PROFILES_PER_PAGE + 1;
124
125         $cnt = 0;
126
127         $members = $this->group->getMembers($offset, $limit);
128
129         if ($members) {
130             $member_list = new ProfileList($members, null, $this);
131             $cnt = $member_list->show();
132         }
133
134         $members->free();
135
136         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
137                           $this->page, 'groupmembers',
138                           array('nickname' => $this->group->nickname));
139     }
140 }