]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/groupaction.php
TagCloud turned into plugin (performance issues on large installs)
[quix0rs-gnu-social.git] / lib / groupaction.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Base class for group actions
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  Action
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2009-2011 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('GNUSOCIAL')) { exit(1); }
31
32 define('MEMBERS_PER_SECTION', 27);
33
34 /**
35  * Base class for group actions, similar to ProfileAction
36  *
37  * @category Action
38  * @package  StatusNet
39  * @author   Zach Copley <zach@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  */
43 class GroupAction extends Action
44 {
45     protected $group;
46
47     protected function prepare(array $args=array())
48     {
49         parent::prepare($args);
50
51         $nickname_arg = $this->arg('nickname');
52         $nickname = common_canonical_nickname($nickname_arg);
53
54         // Permanent redirect on non-canonical nickname
55
56         if ($nickname_arg != $nickname) {
57             $args = array('nickname' => $nickname);
58             if ($this->page != 1) {
59                 $args['page'] = $this->page;
60             }
61             common_redirect(common_local_url('showgroup', $args), 301);
62         }
63
64         if (!$nickname) {
65             // TRANS: Client error displayed if no nickname argument was given requesting a group page.
66             $this->clientError(_('No nickname.'), 404);
67         }
68
69         $local = Local_group::getKV('nickname', $nickname);
70
71         if (!$local) {
72             $alias = Group_alias::getKV('alias', $nickname);
73             if ($alias) {
74                 $args = array('id' => $alias->group_id);
75                 if ($this->page != 1) {
76                     $args['page'] = $this->page;
77                 }
78                 common_redirect(common_local_url('groupbyid', $args), 301);
79             } else {
80                 common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
81                 // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
82                 $this->clientError(_('No such group.'), 404);
83             }
84         }
85
86         $this->group = User_group::getKV('id', $local->group_id);
87
88         if (!$this->group instanceof User_group) {
89             // TRANS: Client error displayed if no local group with a given name was found requesting group page.
90             $this->clientError(_('No such group.'), 404);
91         }
92     }
93
94     function showProfileBlock()
95     {
96         $block = new GroupProfileBlock($this, $this->group);
97         $block->show();
98     }
99
100     /**
101      * Fill in the sidebar.
102      *
103      * @return void
104      */
105     function showSections()
106     {
107         $this->showMembers();
108         $cur = common_current_user();
109         if ($cur && $cur->isAdmin($this->group)) {
110             $this->showPending();
111             $this->showBlocked();
112         }
113
114         $this->showAdmins();
115     }
116
117     /**
118      * Show mini-list of members
119      *
120      * @return void
121      */
122     function showMembers()
123     {
124         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
125
126         if (!$member) {
127             return;
128         }
129
130         $this->elementStart('div', array('id' => 'entity_members',
131                                          'class' => 'section'));
132
133         if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
134             $this->elementStart('h2');
135
136             $this->element('a', array('href' => common_local_url('groupmembers', array('nickname' =>
137                                                                                        $this->group->nickname))),
138                            // TRANS: Header for mini list of group members on a group page (h2).
139                            _('Members'));
140
141             $this->text(' ');
142
143             $this->text($this->group->getMemberCount());
144
145             $this->elementEnd('h2');
146
147             $gmml = new GroupMembersMiniList($member, $this);
148             $cnt = $gmml->show();
149             if ($cnt == 0) {
150                 // TRANS: Description for mini list of group members on a group page when the group has no members.
151                 $this->element('p', null, _('(None)'));
152             }
153
154             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
155             //              for example http://identi.ca/group/statusnet. Broken?
156             if ($cnt > MEMBERS_PER_SECTION) {
157                 $this->element('a', array('href' => common_local_url('groupmembers',
158                                                                      array('nickname' => $this->group->nickname))),
159                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
160                                _('All members'));
161             }
162
163             Event::handle('EndShowGroupMembersMiniList', array($this));
164         }
165
166         $this->elementEnd('div');
167     }
168
169     function showPending()
170     {
171         if ($this->group->join_policy != User_group::JOIN_POLICY_MODERATE) {
172             return;
173         }
174
175         $pending = $this->group->getQueueCount();
176
177         if (!$pending) {
178             return;
179         }
180
181         $request = $this->group->getRequests(0, MEMBERS_PER_SECTION);
182
183         if (!$request) {
184             return;
185         }
186
187         $this->elementStart('div', array('id' => 'entity_pending',
188                                          'class' => 'section'));
189
190         if (Event::handle('StartShowGroupPendingMiniList', array($this))) {
191
192             $this->elementStart('h2');
193
194             $this->element('a', array('href' => common_local_url('groupqueue', array('nickname' =>
195                                                                                      $this->group->nickname))),
196                            // TRANS: Header for mini list of users with a pending membership request on a group page (h2).
197                            _('Pending'));
198
199             $this->text(' ');
200
201             $this->text($pending);
202
203             $this->elementEnd('h2');
204
205             $gmml = new ProfileMiniList($request, $this);
206             $gmml->show();
207
208             Event::handle('EndShowGroupPendingMiniList', array($this));
209         }
210
211         $this->elementEnd('div');
212     }
213
214     function showBlocked()
215     {
216         $blocked = $this->group->getBlocked(0, MEMBERS_PER_SECTION);
217
218         $this->elementStart('div', array('id' => 'entity_blocked',
219                                          'class' => 'section'));
220
221         if (Event::handle('StartShowGroupBlockedMiniList', array($this))) {
222
223             $this->elementStart('h2');
224
225             $this->element('a', array('href' => common_local_url('blockedfromgroup', array('nickname' =>
226                                                                                            $this->group->nickname))),
227                            // TRANS: Header for mini list of users that are blocked in a group page (h2).
228                            _('Blocked'));
229
230             $this->text(' ');
231
232             $this->text($this->group->getBlockedCount());
233
234             $this->elementEnd('h2');
235
236             $gmml = new GroupBlockedMiniList($blocked, $this);
237             $cnt = $gmml->show();
238             if ($cnt == 0) {
239                 // TRANS: Description for mini list of group members on a group page when the group has no members.
240                 $this->element('p', null, _('(None)'));
241             }
242
243             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
244             //              for example http://identi.ca/group/statusnet. Broken?
245             if ($cnt > MEMBERS_PER_SECTION) {
246                 $this->element('a', array('href' => common_local_url('blockedfromgroup',
247                                                                      array('nickname' => $this->group->nickname))),
248                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
249                                _('All members'));
250             }
251
252             Event::handle('EndShowGroupBlockedMiniList', array($this));
253         }
254
255         $this->elementEnd('div');
256     }
257
258     /**
259      * Show list of admins
260      *
261      * @return void
262      */
263     function showAdmins()
264     {
265         $adminSection = new GroupAdminSection($this, $this->group);
266         $adminSection->show();
267     }
268
269     function noticeFormOptions()
270     {
271         $options = parent::noticeFormOptions();
272         $cur = common_current_user();
273
274         if (!empty($cur) && $cur->isMember($this->group)) {
275             $options['to_group'] =  $this->group;
276         }
277
278         return $options;
279     }
280
281     function getGroup()
282     {
283         return $this->group;
284     }
285 }