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
43 /** Owner of this list */
46 function __construct($profile, $owner=null, $action=null)
48 parent::__construct($profile, $owner, $action);
50 $this->owner = $owner;
55 $this->out->elementStart('table', array('class' => 'profile_list xoxo'));
56 $this->out->elementStart('thead');
57 $this->out->elementStart('tr');
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')
66 foreach ($tableHeaders as $id => $label) {
68 $attrs = array('id' => $id);
69 $current = (!empty($this->action->sort) && $this->action->sort == $id);
71 if ($current || empty($this->action->sort) && $id == 'nickname') {
72 $attrs['class'] = 'current';
75 if ($current && $this->action->reverse) {
76 $attrs['class'] .= ' reverse';
77 $attrs['class'] = trim($attrs['class']);
80 $this->out->elementStart('th', $attrs);
83 $params = array('sort' => $id);
85 if (!empty($this->action->q)) {
86 $params['q'] = $this->action->q;
89 if ($current && !$this->action->reverse) {
90 $params['reverse'] = 'true';
95 $filter = $this->action->arg('filter');
97 if (!empty($filter)) {
98 $args['filter'] = $filter;
101 $linkAttrs['href'] = common_local_url(
102 $this->action->arg('action'), $args, $params
105 $this->out->element('a', $linkAttrs, $label);
106 $this->out->elementEnd('th');
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);
115 $this->out->elementEnd('tr');
116 $this->out->elementEnd('thead');
118 $this->out->elementStart('tbody');
123 $this->out->elementEnd('tbody');
124 $this->out->elementEnd('table');
127 function newListItem($profile)
129 return new SortableSubscriptionListItem($profile, $this->owner, $this->action);
133 class SortableSubscriptionListItem extends SubscriptionListItem
135 /** Owner of this list */
138 function __construct($profile, $owner, $action)
140 parent::__construct($profile, $owner, $action);
142 $this->owner = $owner;
148 'class' => 'profile',
149 'id' => 'profile-' . $this->profile->id
152 $this->out->elementStart('tr', $attr);
157 $this->out->elementEnd('tr');
160 function startProfile()
162 $this->out->elementStart('td', 'entity_profile h-card');
165 function endProfile()
167 $this->out->elementEnd('td');
170 function startActions()
172 $this->out->elementStart('td', 'entity_actions');
173 $this->out->elementStart('ul');
176 function endActions()
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);
187 $this->out->elementEnd('li');
190 $this->out->elementEnd('ul');
191 $this->out->elementEnd('td');
196 if (Event::handle('StartProfileListItem', array($this))) {
198 if (Event::handle('StartProfileListItemProfile', array($this))) {
199 $this->showProfile();
200 Event::handle('EndProfileListItemProfile', array($this));
204 $this->showCreatedDate();
205 $this->showSubscriberCount();
206 $this->showNoticeCount();
208 if (Event::handle('StartProfileListItemActions', array($this))) {
209 $this->showActions();
210 Event::handle('EndProfileListItemActions', array($this));
213 Event::handle('EndProfileListItem', array($this));
217 function showSubscriberCount()
219 $this->out->elementStart('td', 'entry_subscriber_count');
220 $this->out->raw($this->profile->subscriberCount());
221 $this->out->elementEnd('td');
224 function showCreatedDate()
226 $this->out->elementStart('td', 'entry_created');
227 $this->out->raw(date('j M Y', strtotime($this->profile->created)));
228 $this->out->elementEnd('td');
231 function showNoticeCount()
233 $this->out->elementStart('td', 'entry_notice_count');
234 $this->out->raw($this->profile->noticeCount());
235 $this->out->elementEnd('td');
239 * Overrided to truncate the bio if it's real long, because it
240 * looks better that way in the SortableSubscriptionList's table
244 if (!empty($this->profile->bio)) {
245 $cutoff = 140; // XXX Should this be configurable?
246 $bio = htmlspecialchars($this->profile->bio);
248 if (mb_strlen($bio) > $cutoff) {
249 $bio = mb_substr($bio, 0, $cutoff - 1)
250 .'<a href="' . $this->profile->profileurl .'">…</a>';
253 $this->out->elementStart('p', 'note');
254 $this->out->raw($bio);
255 $this->out->elementEnd('p');
260 * Only show the tags if we're logged in
264 if (common_logged_in()) {