]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/lib/sortablegrouplist.php
Group directory - nuke admins column (not that useful)
[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' => 'controls'), null);
115
116         $this->out->elementEnd('tr');
117         $this->out->elementEnd('thead');
118
119         $this->out->elementStart('tbody');
120     }
121
122     function newListItem($profile, $odd)
123     {
124         return new SortableGroupListItem($profile, $this->owner, $this->action, $odd);
125     }
126 }
127
128 class SortableGroupListItem extends SortableSubscriptionListItem
129 {
130     /** Owner of this list */
131     var $owner = null;
132
133     function __construct($profile, $owner, $action, $alt)
134     {
135         parent::__construct($profile, $owner, $action, $alt);
136
137         $this->alt   = $alt; // is this row alternate?
138         $this->owner = $owner;
139     }
140
141     function showHomepage()
142     {
143         if (!empty($this->profile->homepage)) {
144             $this->out->text(' ');
145             $aAttrs = $this->homepageAttributes();
146             $this->out->elementStart('a', $aAttrs);
147             $this->out->raw($this->highlight($this->profile->homeUrl()));
148             $this->out->elementEnd('a');
149         }
150     }
151
152     function showAvatar()
153     {
154         $logo = ($this->profile->stream_logo) ?
155         $this->profile->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE);
156
157         $this->out->elementStart(
158             'a',
159             array(
160                 'href'  => $this->profile->homeUrl(),
161                 'class' => 'url entry-title',
162                 'rel'   => 'contact group'
163             )
164         );
165         $this->out->element(
166             'img',
167             array(
168                 'src'    => $logo,
169                 'class'  => 'photo avatar',
170                 'width'  => AVATAR_STREAM_SIZE,
171                 'height' => AVATAR_STREAM_SIZE,
172                 'alt'    => ($this->profile->fullname)
173                     ? $this->profile->fullname : $this->profile->nickname
174             )
175         );
176
177         $this->out->text(' ');
178         $hasFN = ($this->profile->fullname) ? 'nickname' : 'fn org nickname';
179         $this->out->elementStart('span', $hasFN);
180         $this->out->raw($this->highlight($this->profile->nickname));
181         $this->out->elementEnd('span');
182         $this->out->elementEnd('a');
183     }
184
185     function show()
186     {
187         if (Event::handle('StartProfileListItem', array($this))) {
188             $this->startItem();
189             if (Event::handle('StartProfileListItemProfile', array($this))) {
190                 $this->showProfile();
191                 Event::handle('EndProfileListItemProfile', array($this));
192             }
193
194             // XXX Add events?
195             $this->showCreatedDate();
196             $this->showMemberCount();
197
198             if (Event::handle('StartProfileListItemActions', array($this))) {
199                 $this->showActions();
200                 Event::handle('EndProfileListItemActions', array($this));
201             }
202             $this->endItem();
203
204             Event::handle('EndProfileListItem', array($this));
205         }
206     }
207
208     function showActions()
209     {
210         $this->startActions();
211         if (Event::handle('StartProfileListItemActionElements', array($this))) {
212             $this->showJoinButton();
213             Event::handle('EndProfileListItemActionElements', array($this));
214         }
215         $this->endActions();
216     }
217
218     function showJoinButton()
219     {
220         $user = $this->owner;
221         if ($user) {
222
223             $this->out->elementStart('li', 'entity_subscribe');
224             // XXX: special-case for user looking at own
225             // subscriptions page
226             if ($user->isMember($this->profile)) {
227                 $lf = new LeaveForm($this->out, $this->profile);
228                 $lf->show();
229             } else if (!Group_block::isBlocked($this->profile, $user->getProfile())) {
230                 $jf = new JoinForm($this->out, $this->profile);
231                 $jf->show();
232             }
233
234             $this->out->elementEnd('li');
235         }
236     }
237
238     function showMemberCount()
239     {
240         $this->out->elementStart('td', 'entry_member_count');
241         $this->out->raw($this->profile->getMemberCount());
242         $this->out->elementEnd('td');
243     }
244
245     function showCreatedDate()
246     {
247         $this->out->elementStart('td', 'entry_created');
248         $this->out->raw(date('j M Y', strtotime($this->profile->created)));
249         $this->out->elementEnd('td');
250     }
251
252     function showAdmins()
253     {
254         $this->out->elementStart('td', 'entry_admins');
255         // @todo
256         $this->out->raw('gargargar');
257         $this->out->elementEnd('td');
258     }
259
260     /**
261      * Only show the tags if we're logged in
262      */
263     function showTags()
264     {
265          if (common_logged_in()) {
266             parent::showTags();
267         }
268
269     }
270
271 }