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 SortableGroupList extends SortableSubscriptionList
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) {
71 $attrs = array('id' => $id);
72 $current = (!empty($this->action->sort) && $this->action->sort == $id);
74 if ($current || empty($this->action->sort) && $id == 'nickname') {
75 $attrs['class'] = 'current';
78 if ($current && $this->action->reverse) {
79 $attrs['class'] .= ' reverse';
80 $attrs['class'] = trim($attrs['class']);
83 $this->out->elementStart('th', $attrs);
86 $params = array('sort' => $id);
88 if (!empty($this->action->q)) {
89 $params['q'] = $this->action->q;
92 if ($current && !$this->action->reverse) {
93 $params['reverse'] = 'true';
98 $filter = $this->action->arg('filter');
100 if (!empty($filter)) {
101 $args['filter'] = $filter;
104 $linkAttrs['href'] = common_local_url(
105 $this->action->arg('action'), $args, $params
108 $this->out->element('a', $linkAttrs, $label);
109 $this->out->elementEnd('th');
112 // TRANS: Column header in table for members of a group.
113 $this->out->element('th', array('id' => 'Members'), _m('Members'));
114 $this->out->element('th', array('id' => 'controls'), null);
116 $this->out->elementEnd('tr');
117 $this->out->elementEnd('thead');
119 $this->out->elementStart('tbody');
122 function newListItem($profile, $odd)
124 return new SortableGroupListItem($profile, $this->owner, $this->action, $odd);
128 class SortableGroupListItem extends SortableSubscriptionListItem
130 /** Owner of this list */
133 function __construct($profile, $owner, $action, $alt)
135 parent::__construct($profile, $owner, $action, $alt);
137 $this->alt = $alt; // is this row alternate?
138 $this->owner = $owner;
141 function showHomepage()
143 if (!empty($this->profile->homepage)) {
144 $this->out->text(' ');
145 $aAttrs = $this->homepageAttributes();
146 $this->out->elementStart('a', $aAttrs);
147 $this->out->raw($this->highlight($this->profile->homepage));
148 $this->out->elementEnd('a');
152 function showDescription()
154 if (!empty($this->profile->description)) {
155 $cutoff = 140; // XXX Should this be configurable?
156 $description = htmlspecialchars($this->profile->description);
158 if (mb_strlen($description) > $cutoff) {
159 $description = mb_substr($description, 0, $cutoff - 1)
160 .'<a href="' . $this->profile->homeUrl() .'">…</a>';
163 $this->out->elementStart('p', 'note');
164 $this->out->raw($description);
165 $this->out->elementEnd('p');
170 // TODO: Make sure we can do ->getAvatar() for group profiles too!
171 function showAvatar(Profile $profile, $size=null)
173 $logo = $profile->getGroup()->stream_logo ?: User_group::defaultLogo($size ?: $this->avatarSize());
175 $this->out->element('img', array('src' => $logo,
176 'class' => 'avatar u-photo',
177 'width' => AVATAR_STREAM_SIZE,
178 'height' => AVATAR_STREAM_SIZE,
179 'alt' => $profile->getBestName()));
184 if (Event::handle('StartProfileListItem', array($this))) {
186 if (Event::handle('StartProfileListItemProfile', array($this))) {
187 $this->showProfile();
188 Event::handle('EndProfileListItemProfile', array($this));
192 $this->showCreatedDate();
193 $this->showMemberCount();
195 if (Event::handle('StartProfileListItemActions', array($this))) {
196 $this->showActions();
197 Event::handle('EndProfileListItemActions', array($this));
201 Event::handle('EndProfileListItem', array($this));
205 function showProfile()
207 $this->startProfile();
209 $this->showAvatar($this->profile->getProfile());
210 $this->out->element('a', array('href' => $this->profile->homeUrl(),
211 'class' => 'p-org p-nickname',
212 'rel' => 'contact group'),
213 $this->profile->getNickname());
215 $this->showFullName();
216 $this->showLocation();
217 $this->showHomepage();
218 $this->showDescription(); // groups have this instead of bios
224 function endActions()
227 $cur = common_current_user();
228 list($action, $r2args) = $this->out->returnToArgs();
229 $r2args['action'] = $action;
230 if ($cur instanceof User && $cur->hasRight(Right::DELETEGROUP)) {
231 $this->out->elementStart('li', 'entity_delete');
232 $df = new DeleteGroupForm($this->out, $this->profile, $r2args);
234 $this->out->elementEnd('li');
237 $this->out->elementEnd('ul');
238 $this->out->elementEnd('td');
241 function showActions()
243 $this->startActions();
244 if (Event::handle('StartProfileListItemActionElements', array($this))) {
245 $this->showJoinButton();
246 Event::handle('EndProfileListItemActionElements', array($this));
251 function showJoinButton()
253 $user = $this->owner;
255 if ($user instanceof User) {
256 $this->out->elementStart('li', 'entity_subscribe');
257 // XXX: special-case for user looking at own
258 // subscriptions page
259 if ($user->isMember($this->profile)) {
260 $lf = new LeaveForm($this->out, $this->profile);
262 } else if (!Group_block::isBlocked($this->profile, $user->getProfile())) {
263 $jf = new JoinForm($this->out, $this->profile);
267 $this->out->elementEnd('li');
271 function showMemberCount()
273 $this->out->elementStart('td', 'entry_member_count');
274 $this->out->raw($this->profile->getMemberCount());
275 $this->out->elementEnd('td');
278 function showCreatedDate()
280 $this->out->elementStart('td', 'entry_created');
281 // @todo FIXME: Should we provide i18n for timestamps in core?
282 $this->out->raw(date('j M Y', strtotime($this->profile->created)));
283 $this->out->elementEnd('td');
286 function showAdmins()
288 $this->out->elementStart('td', 'entry_admins');
290 $this->out->raw('gargargar');
291 $this->out->elementEnd('td');
295 * Only show the tags if we're logged in
299 if (common_logged_in()) {