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