]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/lib/sortablesubscriptionlist.php
a22aeadb3d25873337abd7012ec328afaa068e87
[quix0rs-gnu-social.git] / plugins / Directory / lib / sortablesubscriptionlist.php
1 <?php
2
3 /**
4  * StatusNet, the distributed open-source microblogging tool
5  *
6  * Widget to show a sortable list of profiles
7  *
8  * PHP version 5
9  *
10  * LICENCE: This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Public
24  * @package   StatusNet
25  * @author    Zach Copley <zach@status.net>
26  * @copyright 2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR . '/lib/subscriptionlist.php';
36
37 /**
38  * Widget to show a sortable list of subscriptions
39  *
40  * @category Public
41  * @package  StatusNet
42  * @author   Zach Copley <zach@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://status.net/
45  */
46
47 class SortableSubscriptionList extends SubscriptionList
48 {
49     /** Owner of this list */
50     var $owner = null;
51
52     function __construct($profile, $owner=null, $action=null)
53     {
54         parent::__construct($profile, $owner, $action);
55
56         $this->owner = $owner;
57     }
58
59     function startList()
60     {
61         $this->out->elementStart('table', array('class' => 'profile_list xoxo'));
62         $this->out->elementStart('thead');
63         $this->out->elementStart('tr');
64
65         $tableHeaders = array(
66             'nickname'    => _m('Nickname'),
67             'created'     => _m('Created')
68         );
69
70         foreach ($tableHeaders as $id => $label) {
71             $attrs = array('id' => $id);
72
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->boolean('asc')) {
80                 $attrs['class'] .= ' asc';
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 ($current && !$this->action->boolean('asc')) {
90                 $params['asc'] = "true";
91             }
92
93             $args = array();
94
95             $filter = $this->action->arg('filter');
96
97             if (!empty($filter)) {
98                 $args['filter'] = $filter;
99             }
100
101             $linkAttrs['href'] = common_local_url(
102                 $this->action->arg('action'), $args, $params
103             );
104
105             $this->out->element('a', $linkAttrs, $label);
106             $this->out->elementEnd('th');
107         }
108
109         $this->out->element('th', array('id' => 'subscriptions'), 'Subscriptions');
110         $this->out->element('th', array('id' => 'notices'), 'Notices');
111         //$this->out->element('th', array('id' => 'controls'), 'Controls');
112
113         $this->out->elementEnd('tr');
114         $this->out->elementEnd('thead');
115
116         $this->out->elementStart('tbody');
117     }
118
119     function endList()
120     {
121         $this->out->elementEnd('tbody');
122         $this->out->elementEnd('table');
123     }
124
125     function showProfiles()
126     {
127         $cnt = 0;
128
129         while ($this->profile->fetch()) {
130             $cnt++;
131             if($cnt > PROFILES_PER_PAGE) {
132                 break;
133             }
134
135             $odd = ($cnt % 2 == 0); // for zebra striping
136
137             $pli = $this->newListItem($this->profile, $odd);
138             $pli->show();
139         }
140
141         return $cnt;
142     }
143
144     function newListItem($profile, $odd)
145     {
146         return new SortableSubscriptionListItem($profile, $this->owner, $this->action, $odd);
147     }
148 }
149
150 class SortableSubscriptionListItem extends SubscriptionListItem
151 {
152     /** Owner of this list */
153     var $owner = null;
154
155     function __construct($profile, $owner, $action, $alt)
156     {
157         parent::__construct($profile, $owner, $action);
158
159         $this->alt   = $alt; // is this row alternate?
160         $this->owner = $owner;
161     }
162
163     function startItem()
164     {
165         $attr = array(
166             'class' => 'profile',
167             'id'    => 'profile-' . $this->profile->id
168         );
169
170         if ($this->alt) {
171             $attr['class'] .= ' alt';
172         }
173
174         $this->out->elementStart('tr', $attr);
175     }
176
177     function endItem()
178     {
179         $this->out->elementEnd('tr');
180     }
181
182     function startProfile()
183     {
184         $this->out->elementStart('td', 'entity_profile vcard entry-content');
185     }
186
187     function endProfile()
188     {
189         $this->out->elementEnd('td');
190     }
191
192     function startActions()
193     {
194         $this->out->elementStart('td', 'entity_actions');
195         $this->out->elementStart('ul');
196     }
197
198     function endActions()
199     {
200         $this->out->elementEnd('ul');
201         $this->out->elementEnd('td');
202     }
203
204     function show()
205     {
206         if (Event::handle('StartProfileListItem', array($this))) {
207             $this->startItem();
208             if (Event::handle('StartProfileListItemProfile', array($this))) {
209                 $this->showProfile();
210                 Event::handle('EndProfileListItemProfile', array($this));
211             }
212
213             // XXX Add events?
214             $this->showCreatedDate();
215             $this->showSubscriberCount();
216             $this->showNoticeCount();
217
218             if (Event::handle('StartProfileListItemActions', array($this))) {
219                 $this->showActions();
220                 Event::handle('EndProfileListItemActions', array($this));
221             }
222             $this->endItem();
223             Event::handle('EndProfileListItem', array($this));
224         }
225     }
226
227     function showSubscriberCount()
228     {
229         $this->out->elementStart('td', 'entry_subscriber_count');
230         $this->out->raw($this->profile->subscriberCount());
231         $this->out->elementEnd('td');
232     }
233
234     function showCreatedDate()
235     {
236         $this->out->elementStart('td', 'entry_created');
237         $this->out->raw(date('j M Y', strtotime($this->profile->created)));
238         $this->out->elementEnd('td');
239     }
240
241     function showNoticeCount()
242     {
243         $this->out->elementStart('td', 'entry_notice_count');
244         $this->out->raw($this->profile->noticeCount());
245         $this->out->elementEnd('td');
246     }
247
248     /**
249      * Only show the tags if we're logged in
250      */
251     function showTags()
252     {
253          if (common_logged_in()) {
254             parent::showTags();
255         }
256
257     }
258
259 }