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