]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/lib/sortablesubscriptionlist.php
234923c00323f3c904b44f44ef8892e265b07c7c
[quix0rs-gnu-social.git] / plugins / Directory / lib / sortablesubscriptionlist.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 SortableSubscriptionList extends SubscriptionList
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
72             $attrs   = array('id' => $id);
73             $current = (!empty($this->action->sort) && $this->action->sort == $id);
74
75             if ($current || empty($this->action->sort) && $id == 'nickname') {
76                 $attrs['class'] = 'current';
77             }
78
79             if ($current && $this->action->reverse) {
80                 $attrs['class'] .= ' reverse';
81                 $attrs['class'] = trim($attrs['class']);
82             }
83
84             $this->out->elementStart('th', $attrs);
85
86             $linkAttrs = array();
87             $params    = array('sort' => $id);
88
89             if (!empty($this->action->q)) {
90                 $params['q'] = $this->action->q;
91             }
92
93             if ($current && !$this->action->reverse) {
94                 $params['reverse'] = 'true';
95             }
96
97             $args = array();
98
99             $filter = $this->action->arg('filter');
100
101             if (!empty($filter)) {
102                 $args['filter'] = $filter;
103             }
104
105             $linkAttrs['href'] = common_local_url(
106                 $this->action->arg('action'), $args, $params
107             );
108
109             $this->out->element('a', $linkAttrs, $label);
110             $this->out->elementEnd('th');
111         }
112
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);
118
119         $this->out->elementEnd('tr');
120         $this->out->elementEnd('thead');
121
122         $this->out->elementStart('tbody');
123     }
124
125     function endList()
126     {
127         $this->out->elementEnd('tbody');
128         $this->out->elementEnd('table');
129     }
130
131     function showProfiles()
132     {
133         $cnt = 0;
134
135         while ($this->profile->fetch()) {
136             $cnt++;
137             if($cnt > PROFILES_PER_PAGE) {
138                 break;
139             }
140
141             $odd = ($cnt % 2 == 0); // for zebra striping
142
143             $pli = $this->newListItem($this->profile, $odd);
144             $pli->show();
145         }
146
147         return $cnt;
148     }
149
150     function newListItem($profile, $odd)
151     {
152         return new SortableSubscriptionListItem($profile, $this->owner, $this->action, $odd);
153     }
154 }
155
156 class SortableSubscriptionListItem extends SubscriptionListItem
157 {
158     /** Owner of this list */
159     var $owner = null;
160
161     function __construct($profile, $owner, $action, $alt)
162     {
163         parent::__construct($profile, $owner, $action);
164
165         $this->alt   = $alt; // is this row alternate?
166         $this->owner = $owner;
167     }
168
169     function startItem()
170     {
171         $attr = array(
172             'class' => 'profile',
173             'id'    => 'profile-' . $this->profile->id
174         );
175
176         if ($this->alt) {
177             $attr['class'] .= ' alt';
178         }
179
180         $this->out->elementStart('tr', $attr);
181     }
182
183     function endItem()
184     {
185         $this->out->elementEnd('tr');
186     }
187
188     function startProfile()
189     {
190         $this->out->elementStart('td', 'entity_profile vcard entry-content');
191     }
192
193     function endProfile()
194     {
195         $this->out->elementEnd('td');
196     }
197
198     function startActions()
199     {
200         $this->out->elementStart('td', 'entity_actions');
201         $this->out->elementStart('ul');
202     }
203
204     function endActions()
205     {
206         $this->out->elementEnd('ul');
207         $this->out->elementEnd('td');
208     }
209
210     function show()
211     {
212         if (Event::handle('StartProfileListItem', array($this))) {
213             $this->startItem();
214             if (Event::handle('StartProfileListItemProfile', array($this))) {
215                 $this->showProfile();
216                 Event::handle('EndProfileListItemProfile', array($this));
217             }
218
219             // XXX Add events?
220             $this->showCreatedDate();
221             $this->showSubscriberCount();
222             $this->showNoticeCount();
223
224             if (Event::handle('StartProfileListItemActions', array($this))) {
225                 $this->showActions();
226                 Event::handle('EndProfileListItemActions', array($this));
227             }
228             $this->endItem();
229             Event::handle('EndProfileListItem', array($this));
230         }
231     }
232
233     function showSubscriberCount()
234     {
235         $this->out->elementStart('td', 'entry_subscriber_count');
236         $this->out->raw($this->profile->subscriberCount());
237         $this->out->elementEnd('td');
238     }
239
240     function showCreatedDate()
241     {
242         $this->out->elementStart('td', 'entry_created');
243         $this->out->raw(date('j M Y', strtotime($this->profile->created)));
244         $this->out->elementEnd('td');
245     }
246
247     function showNoticeCount()
248     {
249         $this->out->elementStart('td', 'entry_notice_count');
250         $this->out->raw($this->profile->noticeCount());
251         $this->out->elementEnd('td');
252     }
253
254     /**
255      * Overrided to truncate the bio if it's real long, because it
256      * looks better that way in the SortableSubscriptionList's table
257      */
258     function showBio()
259     {
260         if (!empty($this->profile->bio)) {
261             $cutoff = 140; // XXX Should this be configurable?
262             $bio    = htmlspecialchars($this->profile->bio);
263
264             if (mb_strlen($bio) > $cutoff) {
265                 $bio = mb_substr($bio, 0, $cutoff - 1)
266                     .'<a href="' . $this->profile->profileurl .'">…</a>';
267             }
268
269             $this->out->elementStart('p', 'note');
270             $this->out->raw($bio);
271             $this->out->elementEnd('p');
272         }
273     }
274
275     /**
276      * Only show the tags if we're logged in
277      */
278     function showTags()
279     {
280          if (common_logged_in()) {
281             parent::showTags();
282         }
283
284     }
285 }