]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/lib/sortablegrouplist.php
DirectoryPlugin - Group directory mostly working. HTML markup for results needs fixing.
[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', 'border' => '1'));
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 showProfiles()
124     {
125         $cnt = 0;
126
127         while ($this->profile->fetch()) {
128             $cnt++;
129             if($cnt > PROFILES_PER_PAGE) {
130                 break;
131             }
132
133             $odd = ($cnt % 2 == 0); // for zebra striping
134
135             $pli = $this->newListItem($this->profile, $odd);
136             $pli->show();
137         }
138
139         return $cnt;
140     }
141
142     function newListItem($profile, $odd)
143     {
144         return new SortableGroupListItem($profile, $this->owner, $this->action, $odd);
145     }
146 }
147
148 class SortableGroupListItem extends SortableSubscriptionListItem
149 {
150     /** Owner of this list */
151     var $owner = null;
152
153     function __construct($profile, $owner, $action, $alt)
154     {
155         parent::__construct($profile, $owner, $action, $alt);
156
157         $this->alt   = $alt; // is this row alternate?
158         $this->owner = $owner;
159     }
160
161     function startItem()
162     {
163         $attr = array(
164             'class' => 'profile',
165             'id'    => 'profile-' . $this->profile->id
166         );
167
168         if ($this->alt) {
169             $attr['class'] .= ' alt';
170         }
171
172         $this->out->elementStart('tr', $attr);
173     }
174
175     function showHomepage()
176     {
177         if (!empty($this->profile->homepage)) {
178             $this->out->text(' ');
179             $aAttrs = $this->homepageAttributes();
180             $this->out->elementStart('a', $aAttrs);
181             $this->out->raw($this->highlight($this->profile->homeUrl()));
182             $this->out->elementEnd('a');
183         }
184     }
185
186     function showAvatar()
187     {
188         $avatar = $this->profile->stream_logo;
189         $aAttrs = $this->linkAttributes();
190         $this->out->elementStart('a', $aAttrs);
191         $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
192                                          'class' => 'photo avatar',
193                                          'width' => AVATAR_STREAM_SIZE,
194                                          'height' => AVATAR_STREAM_SIZE,
195                                          'alt' =>
196                                          ($this->profile->fullname) ? $this->profile->fullname :
197                                          $this->profile->nickname));
198         $this->out->text(' ');
199         $hasFN = (!empty($this->profile->fullname)) ? 'nickname' : 'fn nickname';
200         $this->out->elementStart('span', $hasFN);
201         $this->out->raw($this->highlight($this->profile->nickname));
202         $this->out->elementEnd('span');
203         $this->out->elementEnd('a');
204     }
205
206
207     function endItem()
208     {
209         $this->out->elementEnd('tr');
210     }
211
212     function startProfile()
213     {
214         $this->out->elementStart('td', 'entity_profile vcard entry-content');
215     }
216
217     function endProfile()
218     {
219         $this->out->elementEnd('td');
220     }
221
222     function startActions()
223     {
224         $this->out->elementStart('td', 'entity_actions');
225         $this->out->elementStart('ul');
226     }
227
228     function endActions()
229     {
230         $this->out->elementEnd('ul');
231         $this->out->elementEnd('td');
232     }
233
234     function show()
235     {
236         if (Event::handle('StartProfileListItem', array($this))) {
237             $this->startItem();
238             if (Event::handle('StartProfileListItemProfile', array($this))) {
239                 $this->showProfile();
240                 Event::handle('EndProfileListItemProfile', array($this));
241             }
242
243             // XXX Add events?
244             $this->showCreatedDate();
245             $this->showMemberCount();
246             $this->showAdmins();
247
248             if (Event::handle('StartProfileListItemActions', array($this))) {
249                 $this->showActions();
250                 Event::handle('EndProfileListItemActions', array($this));
251             }
252             $this->endItem();
253             Event::handle('EndProfileListItem', array($this));
254         }
255     }
256
257     function showActions()
258     {
259         $this->startActions();
260         if (Event::handle('StartProfileListItemActionElements', array($this))) {
261             $this->showJoinButton();
262             Event::handle('EndProfileListItemActionElements', array($this));
263         }
264         $this->endActions();
265     }
266
267     function showJoinButton()
268     {
269         $this->out->elementStart('td', 'entry_controls');
270
271         $user = $this->owner;
272         if ($user) {
273   
274             $this->out->elementStart('li', 'entity_subscribe');
275             // XXX: special-case for user looking at own
276             // subscriptions page
277             if ($user->isMember($this->profile)) {
278                 $lf = new LeaveForm($this->out, $this->profile);
279                 $lf->show();
280             } else if (!Group_block::isBlocked($this->profile, $user->getProfile())) {
281                 $jf = new JoinForm($this->out, $this->profile);
282                 $jf->show();
283             }
284         }
285         $this->out->elementEnd('td');
286
287     }
288
289     function showMemberCount()
290     {
291         $this->out->elementStart('td', 'entry_subscriber_count');
292         $this->out->raw($this->profile->getMemberCount());
293         $this->out->elementEnd('td');
294     }
295
296     function showCreatedDate()
297     {
298         $this->out->elementStart('td', 'entry_created');
299         $this->out->raw(date('j M Y', strtotime($this->profile->created)));
300         $this->out->elementEnd('td');
301     }
302
303     function showAdmins()
304     {
305         $this->out->elementStart('td', 'entry_notice_count');
306         // @todo
307         $this->out->raw('gargargar');
308         $this->out->elementEnd('td');
309     }
310
311     /**
312      * Only show the tags if we're logged in
313      */
314     function showTags()
315     {
316          if (common_logged_in()) {
317             parent::showTags();
318         }
319
320     }
321
322 }