]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/lib/sortablesubscriptionlist.php
Merge branch '1.0.x' into testing
[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
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         $this->out->element('th', array('id' => 'subscriptions'), 'Subscriptions');
114         $this->out->element('th', array('id' => 'notices'), 'Notices');
115         $this->out->element('th', array('id' => 'controls'), null);
116
117         $this->out->elementEnd('tr');
118         $this->out->elementEnd('thead');
119
120         $this->out->elementStart('tbody');
121     }
122
123     function endList()
124     {
125         $this->out->elementEnd('tbody');
126         $this->out->elementEnd('table');
127     }
128
129     function showProfiles()
130     {
131         $cnt = 0;
132
133         while ($this->profile->fetch()) {
134             $cnt++;
135             if($cnt > PROFILES_PER_PAGE) {
136                 break;
137             }
138
139             $odd = ($cnt % 2 == 0); // for zebra striping
140
141             $pli = $this->newListItem($this->profile, $odd);
142             $pli->show();
143         }
144
145         return $cnt;
146     }
147
148     function newListItem($profile, $odd)
149     {
150         return new SortableSubscriptionListItem($profile, $this->owner, $this->action, $odd);
151     }
152 }
153
154 class SortableSubscriptionListItem extends SubscriptionListItem
155 {
156     /** Owner of this list */
157     var $owner = null;
158
159     function __construct($profile, $owner, $action, $alt)
160     {
161         parent::__construct($profile, $owner, $action);
162
163         $this->alt   = $alt; // is this row alternate?
164         $this->owner = $owner;
165     }
166
167     function startItem()
168     {
169         $attr = array(
170             'class' => 'profile',
171             'id'    => 'profile-' . $this->profile->id
172         );
173
174         if ($this->alt) {
175             $attr['class'] .= ' alt';
176         }
177
178         $this->out->elementStart('tr', $attr);
179     }
180
181     function endItem()
182     {
183         $this->out->elementEnd('tr');
184     }
185
186     function startProfile()
187     {
188         $this->out->elementStart('td', 'entity_profile vcard entry-content');
189     }
190
191     function endProfile()
192     {
193         $this->out->elementEnd('td');
194     }
195
196     function startActions()
197     {
198         $this->out->elementStart('td', 'entity_actions');
199         $this->out->elementStart('ul');
200     }
201
202     function endActions()
203     {
204         $this->out->elementEnd('ul');
205         $this->out->elementEnd('td');
206     }
207
208     function show()
209     {
210         if (Event::handle('StartProfileListItem', array($this))) {
211             $this->startItem();
212             if (Event::handle('StartProfileListItemProfile', array($this))) {
213                 $this->showProfile();
214                 Event::handle('EndProfileListItemProfile', array($this));
215             }
216
217             // XXX Add events?
218             $this->showCreatedDate();
219             $this->showSubscriberCount();
220             $this->showNoticeCount();
221
222             if (Event::handle('StartProfileListItemActions', array($this))) {
223                 $this->showActions();
224                 Event::handle('EndProfileListItemActions', array($this));
225             }
226             $this->endItem();
227             Event::handle('EndProfileListItem', array($this));
228         }
229     }
230
231     function showSubscriberCount()
232     {
233         $this->out->elementStart('td', 'entry_subscriber_count');
234         $this->out->raw($this->profile->subscriberCount());
235         $this->out->elementEnd('td');
236     }
237
238     function showCreatedDate()
239     {
240         $this->out->elementStart('td', 'entry_created');
241         $this->out->raw(date('j M Y', strtotime($this->profile->created)));
242         $this->out->elementEnd('td');
243     }
244
245     function showNoticeCount()
246     {
247         $this->out->elementStart('td', 'entry_notice_count');
248         $this->out->raw($this->profile->noticeCount());
249         $this->out->elementEnd('td');
250     }
251
252     /**
253      * Only show the tags if we're logged in
254      */
255     function showTags()
256     {
257          if (common_logged_in()) {
258             parent::showTags();
259         }
260
261     }
262
263 }