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()
135 while ($this->profile->fetch()) {
137 if($cnt > PROFILES_PER_PAGE) {
141 $odd = ($cnt % 2 == 0); // for zebra striping
143 $pli = $this->newListItem($this->profile, $odd);
150 function newListItem($profile, $odd)
152 return new SortableSubscriptionListItem($profile, $this->owner, $this->action, $odd);
156 class SortableSubscriptionListItem extends SubscriptionListItem
158 /** Owner of this list */
161 function __construct($profile, $owner, $action, $alt)
163 parent::__construct($profile, $owner, $action);
165 $this->alt = $alt; // is this row alternate?
166 $this->owner = $owner;
172 'class' => 'profile',
173 'id' => 'profile-' . $this->profile->id
177 $attr['class'] .= ' alt';
180 $this->out->elementStart('tr', $attr);
185 $this->out->elementEnd('tr');
188 function startProfile()
190 $this->out->elementStart('td', 'entity_profile vcard entry-content');
193 function endProfile()
195 $this->out->elementEnd('td');
198 function startActions()
200 $this->out->elementStart('td', 'entity_actions');
201 $this->out->elementStart('ul');
204 function endActions()
206 $this->out->elementEnd('ul');
207 $this->out->elementEnd('td');
212 if (Event::handle('StartProfileListItem', array($this))) {
214 if (Event::handle('StartProfileListItemProfile', array($this))) {
215 $this->showProfile();
216 Event::handle('EndProfileListItemProfile', array($this));
220 $this->showCreatedDate();
221 $this->showSubscriberCount();
222 $this->showNoticeCount();
224 if (Event::handle('StartProfileListItemActions', array($this))) {
225 $this->showActions();
226 Event::handle('EndProfileListItemActions', array($this));
229 Event::handle('EndProfileListItem', array($this));
233 function showSubscriberCount()
235 $this->out->elementStart('td', 'entry_subscriber_count');
236 $this->out->raw($this->profile->subscriberCount());
237 $this->out->elementEnd('td');
240 function showCreatedDate()
242 $this->out->elementStart('td', 'entry_created');
243 $this->out->raw(date('j M Y', strtotime($this->profile->created)));
244 $this->out->elementEnd('td');
247 function showNoticeCount()
249 $this->out->elementStart('td', 'entry_notice_count');
250 $this->out->raw($this->profile->noticeCount());
251 $this->out->elementEnd('td');
255 * Overrided to truncate the bio if it's real long, because it
256 * looks better that way in the SortableSubscriptionList's table
260 if (!empty($this->profile->bio)) {
261 $cutoff = 140; // XXX Should this be configurable?
262 $bio = htmlspecialchars($this->profile->bio);
264 if (mb_strlen($bio) > $cutoff) {
265 $bio = mb_substr($bio, 0, $cutoff - 1)
266 .'<a href="' . $this->profile->profileurl .'">…</a>';
269 $this->out->elementStart('p', 'note');
270 $this->out->raw($bio);
271 $this->out->elementEnd('p');
276 * Only show the tags if we're logged in
280 if (common_logged_in()) {