]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/grouplist.php
change laconi.ca to status.net
[quix0rs-gnu-social.git] / lib / grouplist.php
1 <?php
2
3 /**
4  * StatusNet, the distributed open-source microblogging tool
5  *
6  * Widget to show a list of groups
7  *
8  * PHP version 5
9  *
10  * LICENCE: This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Public
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@controlyourself.ca>
26  * @copyright 2008-2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/widget.php';
36
37 define('GROUPS_PER_PAGE', 20);
38
39 /**
40  * Widget to show a list of groups
41  *
42  * @category Public
43  * @package  StatusNet
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://status.net/
47  */
48
49 class GroupList extends Widget
50 {
51     /** Current group, group query. */
52     var $group = null;
53     /** Owner of this list */
54     var $owner = null;
55     /** Action object using us. */
56     var $action = null;
57
58     function __construct($group, $owner=null, $action=null)
59     {
60         parent::__construct($action);
61
62         $this->group = $group;
63         $this->owner = $owner;
64         $this->action = $action;
65     }
66
67     function show()
68     {
69         $this->out->elementStart('ul', 'profiles groups xoxo');
70
71         $cnt = 0;
72
73         while ($this->group->fetch()) {
74             $cnt++;
75             if($cnt > GROUPS_PER_PAGE) {
76                 break;
77             }
78             $this->showgroup();
79         }
80
81         $this->out->elementEnd('ul');
82
83         return $cnt;
84     }
85
86     function showGroup()
87     {
88         $this->out->elementStart('li', array('class' => 'profile',
89                                              'id' => 'group-' . $this->group->id));
90
91         $user = common_current_user();
92
93         $this->out->elementStart('div', 'entity_profile vcard');
94
95         $logo = ($this->group->stream_logo) ?
96           $this->group->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE);
97
98         $this->out->elementStart('a', array('href' => $this->group->homeUrl(),
99                                             'class' => 'url',
100                                             'rel' => 'group'));
101         $this->out->element('img', array('src' => $logo,
102                                          'class' => 'photo avatar',
103                                          'width' => AVATAR_STREAM_SIZE,
104                                          'height' => AVATAR_STREAM_SIZE,
105                                          'alt' =>
106                                          ($this->group->fullname) ? $this->group->fullname :
107                                          $this->group->nickname));
108         $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid';
109         $this->out->elementStart('span', $hasFN);
110         $this->out->raw($this->highlight($this->group->nickname));
111         $this->out->elementEnd('span');
112         $this->out->elementEnd('a');
113
114         if ($this->group->fullname) {
115             $this->out->elementStart('dl', 'entity_fn');
116             $this->out->element('dt', null, 'Full name');
117             $this->out->elementStart('dd');
118             $this->out->elementStart('span', 'fn org');
119             $this->out->raw($this->highlight($this->group->fullname));
120             $this->out->elementEnd('span');
121             $this->out->elementEnd('dd');
122             $this->out->elementEnd('dl');
123         }
124         if ($this->group->location) {
125             $this->out->elementStart('dl', 'entity_location');
126             $this->out->element('dt', null, _('Location'));
127             $this->out->elementStart('dd', 'label');
128             $this->out->raw($this->highlight($this->group->location));
129             $this->out->elementEnd('dd');
130             $this->out->elementEnd('dl');
131         }
132         if ($this->group->homepage) {
133             $this->out->elementStart('dl', 'entity_url');
134             $this->out->element('dt', null, _('URL'));
135             $this->out->elementStart('dd');
136             $this->out->elementStart('a', array('href' => $this->group->homepage,
137                                                 'class' => 'url'));
138             $this->out->raw($this->highlight($this->group->homepage));
139             $this->out->elementEnd('a');
140             $this->out->elementEnd('dd');
141             $this->out->elementEnd('dl');
142         }
143         if ($this->group->description) {
144             $this->out->elementStart('dl', 'entity_note');
145             $this->out->element('dt', null, _('Note'));
146             $this->out->elementStart('dd', 'note');
147             $this->out->raw($this->highlight($this->group->description));
148             $this->out->elementEnd('dd');
149             $this->out->elementEnd('dl');
150         }
151
152         # If we're on a list with an owner (subscriptions or subscribers)...
153
154         if (!empty($user) && !empty($this->owner) && $user->id == $this->owner->id) {
155             $this->showOwnerControls();
156         }
157
158         $this->out->elementEnd('div');
159
160         if ($user) {
161             $this->out->elementStart('div', 'entity_actions');
162             $this->out->elementStart('ul');
163             $this->out->elementStart('li', 'entity_subscribe');
164             # XXX: special-case for user looking at own
165             # subscriptions page
166             if ($user->isMember($this->group)) {
167                 $lf = new LeaveForm($this->out, $this->group);
168                 $lf->show();
169             } else if (!Group_block::isBlocked($this->group, $user->getProfile())) {
170                 $jf = new JoinForm($this->out, $this->group);
171                 $jf->show();
172             }
173             $this->out->elementEnd('li');
174             $this->out->elementEnd('ul');
175             $this->out->elementEnd('div');
176         }
177
178         $this->out->elementEnd('li');
179     }
180
181     /* Override this in subclasses. */
182
183     function showOwnerControls()
184     {
185         return;
186     }
187
188     function highlight($text)
189     {
190         return htmlspecialchars($text);
191     }
192 }