]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/lib/sortablesubscriptionlist.php
CSS can handle alternating row colouring now
[quix0rs-gnu-social.git] / plugins / Directory / lib / sortablesubscriptionlist.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Widget to show a sortable list of profiles
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  Public
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 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('GNUSOCIAL')) { exit(1); }
31
32 /**
33  * Widget to show a sortable list of subscriptions
34  *
35  * @category Public
36  * @package  StatusNet
37  * @author   Zach Copley <zach@status.net>
38  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
39  * @link     http://status.net/
40  */
41 class SortableSubscriptionList extends SubscriptionList
42 {
43     /** Owner of this list */
44     var $owner = null;
45
46     function __construct($profile, $owner=null, $action=null)
47     {
48         parent::__construct($profile, $owner, $action);
49
50         $this->owner = $owner;
51     }
52
53     function startList()
54     {
55         $this->out->elementStart('table', array('class' => 'profile_list xoxo'));
56         $this->out->elementStart('thead');
57         $this->out->elementStart('tr');
58
59         $tableHeaders = array(
60             // TRANS: Column header in table for user nickname.
61             'nickname'    => _m('Nickname'),
62             // TRANS: Column header in table for timestamp when user was created.
63             'created'     => _m('Created')
64         );
65
66         foreach ($tableHeaders as $id => $label) {
67
68             $attrs   = array('id' => $id);
69             $current = (!empty($this->action->sort) && $this->action->sort == $id);
70
71             if ($current || empty($this->action->sort) && $id == 'nickname') {
72                 $attrs['class'] = 'current';
73             }
74
75             if ($current && $this->action->reverse) {
76                 $attrs['class'] .= ' reverse';
77                 $attrs['class'] = trim($attrs['class']);
78             }
79
80             $this->out->elementStart('th', $attrs);
81
82             $linkAttrs = array();
83             $params    = array('sort' => $id);
84
85             if (!empty($this->action->q)) {
86                 $params['q'] = $this->action->q;
87             }
88
89             if ($current && !$this->action->reverse) {
90                 $params['reverse'] = 'true';
91             }
92
93             $args = array();
94
95             $filter = $this->action->arg('filter');
96
97             if (!empty($filter)) {
98                 $args['filter'] = $filter;
99             }
100
101             $linkAttrs['href'] = common_local_url(
102                 $this->action->arg('action'), $args, $params
103             );
104
105             $this->out->element('a', $linkAttrs, $label);
106             $this->out->elementEnd('th');
107         }
108
109         // TRANS: Column header for number of subscriptions.
110         $this->out->element('th', array('id' => 'subscriptions'), _m('Subscriptions'));
111         // TRANS: Column header for number of notices.
112         $this->out->element('th', array('id' => 'notices'), _m('Notices'));
113         $this->out->element('th', array('id' => 'controls'), null);
114
115         $this->out->elementEnd('tr');
116         $this->out->elementEnd('thead');
117
118         $this->out->elementStart('tbody');
119     }
120
121     function endList()
122     {
123         $this->out->elementEnd('tbody');
124         $this->out->elementEnd('table');
125     }
126
127     function newListItem($profile)
128     {
129         return new SortableSubscriptionListItem($profile, $this->owner, $this->action);
130     }
131 }
132
133 class SortableSubscriptionListItem extends SubscriptionListItem
134 {
135     /** Owner of this list */
136     var $owner = null;
137
138     function __construct($profile, $owner, $action)
139     {
140         parent::__construct($profile, $owner, $action);
141
142         $this->owner = $owner;
143     }
144
145     function startItem()
146     {
147         $attr = array(
148             'class' => 'profile',
149             'id'    => 'profile-' . $this->profile->id
150         );
151
152         $this->out->elementStart('tr', $attr);
153     }
154
155     function endItem()
156     {
157         $this->out->elementEnd('tr');
158     }
159
160     function startProfile()
161     {
162         $this->out->elementStart('td', 'entity_profile h-card');
163     }
164
165     function endProfile()
166     {
167         $this->out->elementEnd('td');
168     }
169
170     function startActions()
171     {
172         $this->out->elementStart('td', 'entity_actions');
173         $this->out->elementStart('ul');
174     }
175
176     function endActions()
177     {
178                 
179                 // delete button
180                 $cur = common_current_user();
181         list($action, $r2args) = $this->out->returnToArgs();
182         $r2args['action'] = $action;        
183                 if ($cur instanceof User && $cur->hasRight(Right::DELETEUSER)) {
184                         $this->out->elementStart('li', 'entity_delete');
185                         $df = new DeleteUserForm($this->out, $this->profile, $r2args);
186                         $df->show();            
187                         $this->out->elementEnd('li');
188                 }
189                         
190         $this->out->elementEnd('ul');
191         $this->out->elementEnd('td');
192     }
193
194     function show()
195     {
196         if (Event::handle('StartProfileListItem', array($this))) {
197             $this->startItem();
198             if (Event::handle('StartProfileListItemProfile', array($this))) {
199                 $this->showProfile();
200                 Event::handle('EndProfileListItemProfile', array($this));
201             }
202
203             // XXX Add events?
204             $this->showCreatedDate();
205             $this->showSubscriberCount();
206             $this->showNoticeCount();
207
208             if (Event::handle('StartProfileListItemActions', array($this))) {
209                 $this->showActions();
210                 Event::handle('EndProfileListItemActions', array($this));
211             }
212             $this->endItem();
213             Event::handle('EndProfileListItem', array($this));
214         }
215     }
216
217     function showSubscriberCount()
218     {
219         $this->out->elementStart('td', 'entry_subscriber_count');
220         $this->out->raw($this->profile->subscriberCount());
221         $this->out->elementEnd('td');
222     }
223
224     function showCreatedDate()
225     {
226         $this->out->elementStart('td', 'entry_created');
227         $this->out->raw(date('j M Y', strtotime($this->profile->created)));
228         $this->out->elementEnd('td');
229     }
230
231     function showNoticeCount()
232     {
233         $this->out->elementStart('td', 'entry_notice_count');
234         $this->out->raw($this->profile->noticeCount());
235         $this->out->elementEnd('td');
236     }
237
238     /**
239      * Overrided to truncate the bio if it's real long, because it
240      * looks better that way in the SortableSubscriptionList's table
241      */
242     function showBio()
243     {
244         if (!empty($this->profile->bio)) {
245             $cutoff = 140; // XXX Should this be configurable?
246             $bio    = htmlspecialchars($this->profile->bio);
247
248             if (mb_strlen($bio) > $cutoff) {
249                 $bio = mb_substr($bio, 0, $cutoff - 1)
250                     .'<a href="' . $this->profile->profileurl .'">…</a>';
251             }
252
253             $this->out->elementStart('p', 'note');
254             $this->out->raw($bio);
255             $this->out->elementEnd('p');
256         }
257     }
258
259     /**
260      * Only show the tags if we're logged in
261      */
262     function showTags()
263     {
264          if (common_logged_in()) {
265             parent::showTags();
266         }
267
268     }
269 }