3 * StatusNet, the distributed open-source microblogging tool
5 * Widget to show a sortable list of profiles
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.
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.
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/>.
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/
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR . '/lib/subscriptionlist.php';
37 * Widget to show a sortable list of subscriptions
41 * @author Zach Copley <zach@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
45 class SortableSubscriptionList extends SubscriptionList
47 /** Owner of this list */
50 function __construct($profile, $owner=null, $action=null)
52 parent::__construct($profile, $owner, $action);
54 $this->owner = $owner;
59 $this->out->elementStart('table', array('class' => 'profile_list xoxo'));
60 $this->out->elementStart('thead');
61 $this->out->elementStart('tr');
63 $tableHeaders = array(
64 // TRANS: Column header in table for user nickname.
65 'nickname' => _m('Nickname'),
66 // TRANS: Column header in table for timestamp when user was created.
67 'created' => _m('Created')
70 foreach ($tableHeaders as $id => $label) {
72 $attrs = array('id' => $id);
73 $current = (!empty($this->action->sort) && $this->action->sort == $id);
75 if ($current || empty($this->action->sort) && $id == 'nickname') {
76 $attrs['class'] = 'current';
79 if ($current && $this->action->reverse) {
80 $attrs['class'] .= ' reverse';
81 $attrs['class'] = trim($attrs['class']);
84 $this->out->elementStart('th', $attrs);
87 $params = array('sort' => $id);
89 if (!empty($this->action->q)) {
90 $params['q'] = $this->action->q;
93 if ($current && !$this->action->reverse) {
94 $params['reverse'] = 'true';
99 $filter = $this->action->arg('filter');
101 if (!empty($filter)) {
102 $args['filter'] = $filter;
105 $linkAttrs['href'] = common_local_url(
106 $this->action->arg('action'), $args, $params
109 $this->out->element('a', $linkAttrs, $label);
110 $this->out->elementEnd('th');
113 // TRANS: Column header for number of subscriptions.
114 $this->out->element('th', array('id' => 'subscriptions'), _m('Subscriptions'));
115 // TRANS: Column header for number of notices.
116 $this->out->element('th', array('id' => 'notices'), _m('Notices'));
117 $this->out->element('th', array('id' => 'controls'), null);
119 $this->out->elementEnd('tr');
120 $this->out->elementEnd('thead');
122 $this->out->elementStart('tbody');
127 $this->out->elementEnd('tbody');
128 $this->out->elementEnd('table');
131 function showProfiles()
133 // Note: we don't use fetchAll() because it's borked with query()
137 while ($this->profile->fetch()) {
138 $profiles[] = clone($this->profile);
141 $cnt = count($profiles);
143 $max = min($cnt, $this->maxProfiles());
145 for ($i = 0; $i < $max; $i++) {
146 $odd = ($i % 2 == 0); // for zebra striping
147 $pli = $this->newListItem($profiles[$i], $odd);
154 function newListItem($profile, $odd)
156 return new SortableSubscriptionListItem($profile, $this->owner, $this->action, $odd);
160 class SortableSubscriptionListItem extends SubscriptionListItem
162 /** Owner of this list */
165 function __construct($profile, $owner, $action, $alt)
167 parent::__construct($profile, $owner, $action);
169 $this->alt = $alt; // is this row alternate?
170 $this->owner = $owner;
176 'class' => 'profile',
177 'id' => 'profile-' . $this->profile->id
181 $attr['class'] .= ' alt';
184 $this->out->elementStart('tr', $attr);
189 $this->out->elementEnd('tr');
192 function startProfile()
194 $this->out->elementStart('td', 'entity_profile h-card');
197 function endProfile()
199 $this->out->elementEnd('td');
202 function startActions()
204 $this->out->elementStart('td', 'entity_actions');
205 $this->out->elementStart('ul');
208 function endActions()
212 $cur = common_current_user();
213 list($action, $r2args) = $this->out->returnToArgs();
214 $r2args['action'] = $action;
215 if ($cur instanceof User && $cur->hasRight(Right::DELETEUSER)) {
216 $this->out->elementStart('li', 'entity_delete');
217 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
219 $this->out->elementEnd('li');
222 $this->out->elementEnd('ul');
223 $this->out->elementEnd('td');
228 if (Event::handle('StartProfileListItem', array($this))) {
230 if (Event::handle('StartProfileListItemProfile', array($this))) {
231 $this->showProfile();
232 Event::handle('EndProfileListItemProfile', array($this));
236 $this->showCreatedDate();
237 $this->showSubscriberCount();
238 $this->showNoticeCount();
240 if (Event::handle('StartProfileListItemActions', array($this))) {
241 $this->showActions();
242 Event::handle('EndProfileListItemActions', array($this));
245 Event::handle('EndProfileListItem', array($this));
249 function showSubscriberCount()
251 $this->out->elementStart('td', 'entry_subscriber_count');
252 $this->out->raw($this->profile->subscriberCount());
253 $this->out->elementEnd('td');
256 function showCreatedDate()
258 $this->out->elementStart('td', 'entry_created');
259 $this->out->raw(date('j M Y', strtotime($this->profile->created)));
260 $this->out->elementEnd('td');
263 function showNoticeCount()
265 $this->out->elementStart('td', 'entry_notice_count');
266 $this->out->raw($this->profile->noticeCount());
267 $this->out->elementEnd('td');
271 * Overrided to truncate the bio if it's real long, because it
272 * looks better that way in the SortableSubscriptionList's table
276 if (!empty($this->profile->bio)) {
277 $cutoff = 140; // XXX Should this be configurable?
278 $bio = htmlspecialchars($this->profile->bio);
280 if (mb_strlen($bio) > $cutoff) {
281 $bio = mb_substr($bio, 0, $cutoff - 1)
282 .'<a href="' . $this->profile->profileurl .'">…</a>';
285 $this->out->elementStart('p', 'note');
286 $this->out->raw($bio);
287 $this->out->elementEnd('p');
292 * Only show the tags if we're logged in
296 if (common_logged_in()) {