]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/lib/sortablegrouplist.php
Group directory - fix group logo display
[quix0rs-gnu-social.git] / plugins / Directory / lib / sortablegrouplist.php
1 <?php
2
3 /**
4  * StatusNet, the distributed open-source microblogging tool
5  *
6  * Widget to show a sortable list of profiles
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    Zach Copley <zach@status.net>
26  * @copyright 2011 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('STATUSNET')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR . '/lib/subscriptionlist.php';
36
37 /**
38  * Widget to show a sortable list of subscriptions
39  *
40  * @category Public
41  * @package  StatusNet
42  * @author   Zach Copley <zach@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://status.net/
45  */
46
47 class SortableGroupList extends SortableSubscriptionList
48 {
49     /** Owner of this list */
50     var $owner = null;
51
52     function __construct($profile, $owner=null, $action=null)
53     {
54         parent::__construct($profile, $owner, $action);
55
56         $this->owner = $owner;
57     }
58
59     function startList()
60     {
61         $this->out->elementStart('table', array('class' => 'profile_list xoxo'));
62         $this->out->elementStart('thead');
63         $this->out->elementStart('tr');
64
65         $tableHeaders = array(
66             'nickname'    => _m('Nickname'),
67             'created'     => _m('Created')
68         );
69
70         foreach ($tableHeaders as $id => $label) {
71
72             $attrs   = array('id' => $id);
73             $current = (!empty($this->action->sort) && $this->action->sort == $id);
74
75             if ($current || empty($this->action->sort) && $id == 'nickname') {
76                 $attrs['class'] = 'current';
77             }
78
79             if ($current && $this->action->reverse) {
80                 $attrs['class'] .= ' reverse';
81                 $attrs['class'] = trim($attrs['class']);
82             }
83
84             $this->out->elementStart('th', $attrs);
85
86             $linkAttrs = array();
87             $params    = array('sort' => $id);
88
89             if (!empty($this->action->q)) {
90                 $params['q'] = $this->action->q;
91             }
92
93             if ($current && !$this->action->reverse) {
94                 $params['reverse'] = 'true';
95             }
96
97             $args = array();
98
99             $filter = $this->action->arg('filter');
100
101             if (!empty($filter)) {
102                 $args['filter'] = $filter;
103             }
104
105             $linkAttrs['href'] = common_local_url(
106                 $this->action->arg('action'), $args, $params
107             );
108
109             $this->out->element('a', $linkAttrs, $label);
110             $this->out->elementEnd('th');
111         }
112
113         $this->out->element('th', array('id' => 'Members'), _m('Members'));
114         $this->out->element('th', array('id' => 'Admins'), _m('Admins'));
115         $this->out->element('th', array('id' => 'controls'), null);
116
117         $this->out->elementEnd('tr');
118         $this->out->elementEnd('thead');
119
120         $this->out->elementStart('tbody');
121     }
122
123     function newListItem($profile, $odd)
124     {
125         return new SortableGroupListItem($profile, $this->owner, $this->action, $odd);
126     }
127 }
128
129 class SortableGroupListItem extends SortableSubscriptionListItem
130 {
131     /** Owner of this list */
132     var $owner = null;
133
134     function __construct($profile, $owner, $action, $alt)
135     {
136         parent::__construct($profile, $owner, $action, $alt);
137
138         $this->alt   = $alt; // is this row alternate?
139         $this->owner = $owner;
140     }
141
142     function startItem()
143     {
144         $attr = array(
145             'class' => 'profile',
146             'id'    => 'profile-' . $this->profile->id
147         );
148
149         if ($this->alt) {
150             $attr['class'] .= ' alt';
151         }
152
153         $this->out->elementStart('tr', $attr);
154     }
155
156     function showHomepage()
157     {
158         if (!empty($this->profile->homepage)) {
159             $this->out->text(' ');
160             $aAttrs = $this->homepageAttributes();
161             $this->out->elementStart('a', $aAttrs);
162             $this->out->raw($this->highlight($this->profile->homeUrl()));
163             $this->out->elementEnd('a');
164         }
165     }
166
167     function showAvatar()
168     {
169         $logo = ($this->profile->stream_logo) ?
170         $this->profile->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE);
171
172         $this->out->elementStart(
173             'a',
174             array(
175                 'href'  => $this->profile->homeUrl(),
176                 'class' => 'url entry-title',
177                 'rel'   => 'contact group'
178             )
179         );
180         $this->out->element(
181             'img',
182             array(
183                 'src'    => $logo,
184                 'class'  => 'photo avatar',
185                 'width'  => AVATAR_STREAM_SIZE,
186                 'height' => AVATAR_STREAM_SIZE,
187                 'alt'    => ($this->profile->fullname)
188                     ? $this->profile->fullname : $this->profile->nickname
189             )
190         );
191
192         $this->out->text(' ');
193         $hasFN = ($this->profile->fullname) ? 'nickname' : 'fn org nickname';
194         $this->out->elementStart('span', $hasFN);
195         $this->out->raw($this->highlight($this->profile->nickname));
196         $this->out->elementEnd('span');
197         $this->out->elementEnd('a');
198     }
199
200     function endItem()
201     {
202         $this->out->elementEnd('tr');
203     }
204
205     function startProfile()
206     {
207         $this->out->elementStart('td', 'entity_profile vcard entry-content');
208     }
209
210     function endProfile()
211     {
212         $this->out->elementEnd('td');
213     }
214
215     function startActions()
216     {
217         $this->out->elementStart('td', 'entity_actions');
218         $this->out->elementStart('ul');
219     }
220
221     function endActions()
222     {
223         $this->out->elementEnd('ul');
224         $this->out->elementEnd('td');
225     }
226
227     function show()
228     {
229         if (Event::handle('StartProfileListItem', array($this))) {
230             $this->startItem();
231             if (Event::handle('StartProfileListItemProfile', array($this))) {
232                 $this->showProfile();
233                 Event::handle('EndProfileListItemProfile', array($this));
234             }
235
236             // XXX Add events?
237             $this->showCreatedDate();
238             $this->showMemberCount();
239             $this->showAdmins();
240
241             if (Event::handle('StartProfileListItemActions', array($this))) {
242                 $this->showActions();
243                 Event::handle('EndProfileListItemActions', array($this));
244             }
245             $this->endItem();
246             Event::handle('EndProfileListItem', array($this));
247         }
248     }
249
250     function showActions()
251     {
252         $this->startActions();
253         if (Event::handle('StartProfileListItemActionElements', array($this))) {
254             $this->showJoinButton();
255             Event::handle('EndProfileListItemActionElements', array($this));
256         }
257         $this->endActions();
258     }
259
260     function showJoinButton()
261     {
262         $user = $this->owner;
263         if ($user) {
264
265             $this->out->elementStart('li', 'entity_subscribe');
266             // XXX: special-case for user looking at own
267             // subscriptions page
268             if ($user->isMember($this->profile)) {
269                 $lf = new LeaveForm($this->out, $this->profile);
270                 $lf->show();
271             } else if (!Group_block::isBlocked($this->profile, $user->getProfile())) {
272                 $jf = new JoinForm($this->out, $this->profile);
273                 $jf->show();
274             }
275         }
276     }
277
278     function showMemberCount()
279     {
280         $this->out->elementStart('td', 'entry_subscriber_count');
281         $this->out->raw($this->profile->getMemberCount());
282         $this->out->elementEnd('td');
283     }
284
285     function showCreatedDate()
286     {
287         $this->out->elementStart('td', 'entry_created');
288         $this->out->raw(date('j M Y', strtotime($this->profile->created)));
289         $this->out->elementEnd('td');
290     }
291
292     function showAdmins()
293     {
294         $this->out->elementStart('td', 'entry_notice_count');
295         // @todo
296         $this->out->raw('gargargar');
297         $this->out->elementEnd('td');
298     }
299
300     /**
301      * Only show the tags if we're logged in
302      */
303     function showTags()
304     {
305          if (common_logged_in()) {
306             parent::showTags();
307         }
308
309     }
310
311 }