]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/lib/sortablegrouplist.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / plugins / Directory / lib / sortablegrouplist.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Widget to show a sortable list of profiles
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Public
23  * @package   StatusNet
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/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/lib/subscriptionlist.php';
35
36 /**
37  * Widget to show a sortable list of subscriptions
38  *
39  * @category Public
40  * @package  StatusNet
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/
44  */
45 class SortableGroupList extends SortableSubscriptionList
46 {
47     /** Owner of this list */
48     var $owner = null;
49
50     function __construct($profile, $owner=null, $action=null)
51     {
52         parent::__construct($profile, $owner, $action);
53
54         $this->owner = $owner;
55     }
56
57     function startList()
58     {
59         $this->out->elementStart('table', array('class' => 'profile_list xoxo'));
60         $this->out->elementStart('thead');
61         $this->out->elementStart('tr');
62
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')
68         );
69
70         foreach ($tableHeaders as $id => $label) {
71             $attrs   = array('id' => $id);
72             $current = (!empty($this->action->sort) && $this->action->sort == $id);
73
74             if ($current || empty($this->action->sort) && $id == 'nickname') {
75                 $attrs['class'] = 'current';
76             }
77
78             if ($current && $this->action->reverse) {
79                 $attrs['class'] .= ' reverse';
80                 $attrs['class'] = trim($attrs['class']);
81             }
82
83             $this->out->elementStart('th', $attrs);
84
85             $linkAttrs = array();
86             $params    = array('sort' => $id);
87
88             if (!empty($this->action->q)) {
89                 $params['q'] = $this->action->q;
90             }
91
92             if ($current && !$this->action->reverse) {
93                 $params['reverse'] = 'true';
94             }
95
96             $args = array();
97
98             $filter = $this->action->arg('filter');
99
100             if (!empty($filter)) {
101                 $args['filter'] = $filter;
102             }
103
104             $linkAttrs['href'] = common_local_url(
105                 $this->action->arg('action'), $args, $params
106             );
107
108             $this->out->element('a', $linkAttrs, $label);
109             $this->out->elementEnd('th');
110         }
111
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);
115
116         $this->out->elementEnd('tr');
117         $this->out->elementEnd('thead');
118
119         $this->out->elementStart('tbody');
120     }
121
122     function newListItem($profile, $odd)
123     {
124         return new SortableGroupListItem($profile, $this->owner, $this->action, $odd);
125     }
126 }
127
128 class SortableGroupListItem extends SortableSubscriptionListItem
129 {
130     /** Owner of this list */
131     var $owner = null;
132
133     function __construct($profile, $owner, $action, $alt)
134     {
135         parent::__construct($profile, $owner, $action, $alt);
136
137         $this->alt   = $alt; // is this row alternate?
138         $this->owner = $owner;
139     }
140
141     function showHomepage()
142     {
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->homeUrl()));
148             $this->out->elementEnd('a');
149         }
150     }
151
152     function showDescription()
153     {
154         if (!empty($this->profile->description)) {
155             $cutoff      = 140; // XXX Should this be configurable?
156             $description = htmlspecialchars($this->profile->description);
157
158             if (mb_strlen($description) > $cutoff) {
159                 $description = mb_substr($description, 0, $cutoff - 1)
160                     .'<a href="' . $this->profile->homeUrl() .'">…</a>';
161             }
162
163             $this->out->elementStart('p', 'note');
164             $this->out->raw($description);
165             $this->out->elementEnd('p');
166         }
167
168     }
169
170     function showAvatar()
171     {
172         $logo = ($this->profile->stream_logo) ?
173         $this->profile->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE);
174
175         $this->out->elementStart(
176             'a',
177             array(
178                 'href'  => $this->profile->homeUrl(),
179                 'class' => 'url entry-title',
180                 'rel'   => 'contact group'
181             )
182         );
183         $this->out->element(
184             'img',
185             array(
186                 'src'    => $logo,
187                 'class'  => 'photo avatar',
188                 'width'  => AVATAR_STREAM_SIZE,
189                 'height' => AVATAR_STREAM_SIZE,
190                 'alt'    => ($this->profile->fullname)
191                     ? $this->profile->fullname : $this->profile->nickname
192             )
193         );
194
195         $this->out->text(' ');
196         $hasFN = ($this->profile->fullname) ? 'nickname' : 'fn org nickname';
197         $this->out->elementStart('span', $hasFN);
198         $this->out->raw($this->highlight($this->profile->nickname));
199         $this->out->elementEnd('span');
200         $this->out->elementEnd('a');
201     }
202
203     function show()
204     {
205         if (Event::handle('StartProfileListItem', array($this))) {
206             $this->startItem();
207             if (Event::handle('StartProfileListItemProfile', array($this))) {
208                 $this->showProfile();
209                 Event::handle('EndProfileListItemProfile', array($this));
210             }
211
212             // XXX Add events?
213             $this->showCreatedDate();
214             $this->showMemberCount();
215
216             if (Event::handle('StartProfileListItemActions', array($this))) {
217                 $this->showActions();
218                 Event::handle('EndProfileListItemActions', array($this));
219             }
220             $this->endItem();
221
222             Event::handle('EndProfileListItem', array($this));
223         }
224     }
225
226     function showProfile()
227     {
228         $this->startProfile();
229         $this->showAvatar();
230         $this->showFullName();
231         $this->showLocation();
232         $this->showHomepage();
233         $this->showDescription(); // groups have this instead of bios
234         // Relevant portion!
235         $this->showTags();
236         $this->endProfile();
237     }
238
239     function showActions()
240     {
241         $this->startActions();
242         if (Event::handle('StartProfileListItemActionElements', array($this))) {
243             $this->showJoinButton();
244             Event::handle('EndProfileListItemActionElements', array($this));
245         }
246         $this->endActions();
247     }
248
249     function showJoinButton()
250     {
251         $user = $this->owner;
252         if ($user) {
253
254             $this->out->elementStart('li', 'entity_subscribe');
255             // XXX: special-case for user looking at own
256             // subscriptions page
257             if ($user->isMember($this->profile)) {
258                 $lf = new LeaveForm($this->out, $this->profile);
259                 $lf->show();
260             } else if (!Group_block::isBlocked($this->profile, $user->getProfile())) {
261                 $jf = new JoinForm($this->out, $this->profile);
262                 $jf->show();
263             }
264
265             $this->out->elementEnd('li');
266         }
267     }
268
269     function showMemberCount()
270     {
271         $this->out->elementStart('td', 'entry_member_count');
272         $this->out->raw($this->profile->getMemberCount());
273         $this->out->elementEnd('td');
274     }
275
276     function showCreatedDate()
277     {
278         $this->out->elementStart('td', 'entry_created');
279         // @todo FIXME: Should we provide i18n for timestamps in core?
280         $this->out->raw(date('j M Y', strtotime($this->profile->created)));
281         $this->out->elementEnd('td');
282     }
283
284     function showAdmins()
285     {
286         $this->out->elementStart('td', 'entry_admins');
287         // @todo
288         $this->out->raw('gargargar');
289         $this->out->elementEnd('td');
290     }
291
292     /**
293      * Only show the tags if we're logged in
294      */
295     function showTags()
296     {
297          if (common_logged_in()) {
298             parent::showTags();
299         }
300
301     }
302 }