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('GNUSOCIAL')) { exit(1); }
33 * Widget to show a sortable list of subscriptions
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/
41 class SortableSubscriptionList extends SubscriptionList
45 $this->out->elementStart('table', array('class' => 'profile_list xoxo'));
46 $this->out->elementStart('thead');
47 $this->out->elementStart('tr');
49 $tableHeaders = array(
50 // TRANS: Column header in table for user nickname.
51 'nickname' => _m('Nickname'),
52 // TRANS: Column header in table for timestamp when user was created.
53 'created' => _m('Created')
56 foreach ($tableHeaders as $id => $label) {
58 $attrs = array('id' => $id);
59 $current = (!empty($this->action->sort) && $this->action->sort == $id);
61 if ($current || empty($this->action->sort) && $id == 'nickname') {
62 $attrs['class'] = 'current';
65 if ($current && $this->action->reverse) {
66 $attrs['class'] .= ' reverse';
67 $attrs['class'] = trim($attrs['class']);
70 $this->out->elementStart('th', $attrs);
73 $params = array('sort' => $id);
75 if (!empty($this->action->q)) {
76 $params['q'] = $this->action->q;
79 if ($current && !$this->action->reverse) {
80 $params['reverse'] = 'true';
85 $filter = $this->action->arg('filter');
87 if (!empty($filter)) {
88 $args['filter'] = $filter;
91 $linkAttrs['href'] = common_local_url(
92 $this->action->arg('action'), $args, $params
95 $this->out->element('a', $linkAttrs, $label);
96 $this->out->elementEnd('th');
99 // TRANS: Column header for number of subscriptions.
100 $this->out->element('th', array('id' => 'subscriptions'), _m('Subscriptions'));
101 // TRANS: Column header for number of notices.
102 $this->out->element('th', array('id' => 'notices'), _m('Notices'));
103 $this->out->element('th', array('id' => 'controls'), null);
105 $this->out->elementEnd('tr');
106 $this->out->elementEnd('thead');
108 $this->out->elementStart('tbody');
113 $this->out->elementEnd('tbody');
114 $this->out->elementEnd('table');
117 function newListItem($profile)
119 return new SortableSubscriptionListItem($profile, $this->owner, $this->action);
123 class SortableSubscriptionListItem extends SubscriptionListItem
128 'class' => 'profile',
129 'id' => 'profile-' . $this->profile->id
132 $this->out->elementStart('tr', $attr);
137 $this->out->elementEnd('tr');
140 function startProfile()
142 $this->out->elementStart('td', 'entity_profile h-card');
145 function endProfile()
147 $this->out->elementEnd('td');
150 function startActions()
152 $this->out->elementStart('td', 'entity_actions');
153 $this->out->elementStart('ul');
156 function endActions()
160 $cur = common_current_user();
161 list($action, $r2args) = $this->out->returnToArgs();
162 $r2args['action'] = $action;
163 if ($cur instanceof User && $cur->hasRight(Right::DELETEUSER)) {
164 $this->out->elementStart('li', 'entity_delete');
165 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
167 $this->out->elementEnd('li');
170 $this->out->elementEnd('ul');
171 $this->out->elementEnd('td');
176 if (Event::handle('StartProfileListItem', array($this))) {
178 if (Event::handle('StartProfileListItemProfile', array($this))) {
179 $this->showProfile();
180 Event::handle('EndProfileListItemProfile', array($this));
184 $this->showCreatedDate();
185 $this->showSubscriberCount();
186 $this->showNoticeCount();
188 if (Event::handle('StartProfileListItemActions', array($this))) {
189 $this->showActions();
190 Event::handle('EndProfileListItemActions', array($this));
193 Event::handle('EndProfileListItem', array($this));
197 function showSubscriberCount()
199 $this->out->elementStart('td', 'entry_subscriber_count');
200 $this->out->raw($this->profile->subscriberCount());
201 $this->out->elementEnd('td');
204 function showCreatedDate()
206 $this->out->elementStart('td', 'entry_created');
207 $this->out->raw(date('j M Y', strtotime($this->profile->created)));
208 $this->out->elementEnd('td');
211 function showNoticeCount()
213 $this->out->elementStart('td', 'entry_notice_count');
214 $this->out->raw($this->profile->noticeCount());
215 $this->out->elementEnd('td');
219 * Overrided to truncate the bio if it's real long, because it
220 * looks better that way in the SortableSubscriptionList's table
224 if (!empty($this->profile->bio)) {
225 $cutoff = 140; // XXX Should this be configurable?
226 $bio = htmlspecialchars($this->profile->bio);
228 if (mb_strlen($bio) > $cutoff) {
229 $bio = mb_substr($bio, 0, $cutoff - 1)
230 .'<a href="' . $this->profile->profileurl .'">…</a>';
233 $this->out->elementStart('p', 'note');
234 $this->out->raw($bio);
235 $this->out->elementEnd('p');
240 * Only show the tags if we're logged in
244 if (common_logged_in()) {