]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/lib/sortablesubscriptionlist.php
Introduced common_location_shared() to check if location sharing is always,
[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('GNUSOCIAL')) { exit(1); }
31
32 /**
33  * Widget to show a sortable list of subscriptions
34  *
35  * @category Public
36  * @package  StatusNet
37  * @author   Zach Copley <zach@status.net>
38  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
39  * @link     http://status.net/
40  */
41 class SortableSubscriptionList extends SubscriptionList
42 {
43     function startList()
44     {
45         $this->out->elementStart('table', array('class' => 'profile_list xoxo'));
46         $this->out->elementStart('thead');
47         $this->out->elementStart('tr');
48
49         $tableHeaders = array(
50             // TRANS: Column header in table for user nickname.
51             'nickname'    => _m('Nickname'),
52             // TRANS: Column header in table for timestamp when user was created.
53             'created'     => _m('Created')
54         );
55
56         foreach ($tableHeaders as $id => $label) {
57
58             $attrs   = array('id' => $id);
59             $current = (!empty($this->action->sort) && $this->action->sort == $id);
60
61             if ($current || empty($this->action->sort) && $id == 'nickname') {
62                 $attrs['class'] = 'current';
63             }
64
65             if ($current && $this->action->reverse) {
66                 $attrs['class'] .= ' reverse';
67                 $attrs['class'] = trim($attrs['class']);
68             }
69
70             $this->out->elementStart('th', $attrs);
71
72             $linkAttrs = array();
73             $params    = array('sort' => $id);
74
75             if (!empty($this->action->q)) {
76                 $params['q'] = $this->action->q;
77             }
78
79             if ($current && !$this->action->reverse) {
80                 $params['reverse'] = 'true';
81             }
82
83             $args = array();
84
85             $filter = $this->action->arg('filter');
86
87             if (!empty($filter)) {
88                 $args['filter'] = $filter;
89             }
90
91             $linkAttrs['href'] = common_local_url(
92                 $this->action->arg('action'), $args, $params
93             );
94
95             $this->out->element('a', $linkAttrs, $label);
96             $this->out->elementEnd('th');
97         }
98
99         // TRANS: Column header for number of subscriptions.
100         $this->out->element('th', array('id' => 'subscriptions'), _m('Subscriptions'));
101         // TRANS: Column header for number of notices.
102         $this->out->element('th', array('id' => 'notices'), _m('Notices'));
103         $this->out->element('th', array('id' => 'controls'), null);
104
105         $this->out->elementEnd('tr');
106         $this->out->elementEnd('thead');
107
108         $this->out->elementStart('tbody');
109     }
110
111     function endList()
112     {
113         $this->out->elementEnd('tbody');
114         $this->out->elementEnd('table');
115     }
116
117     function newListItem(Profile $profile)
118     {
119         return new SortableSubscriptionListItem($profile, $this->owner, $this->action);
120     }
121 }
122
123 class SortableSubscriptionListItem extends SubscriptionListItem
124 {
125     function startItem()
126     {
127         $attr = array(
128             'class' => 'profile',
129             'id'    => 'profile-' . $this->profile->id
130         );
131
132         $this->out->elementStart('tr', $attr);
133     }
134
135     function endItem()
136     {
137         $this->out->elementEnd('tr');
138     }
139
140     function startProfile()
141     {
142         $this->out->elementStart('td', 'entity_profile h-card');
143     }
144
145     function endProfile()
146     {
147         $this->out->elementEnd('td');
148     }
149
150     function startActions()
151     {
152         $this->out->elementStart('td', 'entity_actions');
153         $this->out->elementStart('ul');
154     }
155
156     function endActions()
157     {
158                 
159                 // delete button
160                 $cur = common_current_user();
161         list($action, $r2args) = $this->out->returnToArgs();
162         $r2args['action'] = $action;        
163                 if ($cur instanceof User && $cur->hasRight(Right::DELETEUSER)) {
164                         $this->out->elementStart('li', 'entity_delete');
165                         $df = new DeleteUserForm($this->out, $this->profile, $r2args);
166                         $df->show();            
167                         $this->out->elementEnd('li');
168                 }
169                         
170         $this->out->elementEnd('ul');
171         $this->out->elementEnd('td');
172     }
173
174     function show()
175     {
176         if (Event::handle('StartProfileListItem', array($this))) {
177             $this->startItem();
178             if (Event::handle('StartProfileListItemProfile', array($this))) {
179                 $this->showProfile();
180                 Event::handle('EndProfileListItemProfile', array($this));
181             }
182
183             // XXX Add events?
184             $this->showCreatedDate();
185             $this->showSubscriberCount();
186             $this->showNoticeCount();
187
188             if (Event::handle('StartProfileListItemActions', array($this))) {
189                 $this->showActions();
190                 Event::handle('EndProfileListItemActions', array($this));
191             }
192             $this->endItem();
193             Event::handle('EndProfileListItem', array($this));
194         }
195     }
196
197     function showSubscriberCount()
198     {
199         $this->out->elementStart('td', 'entry_subscriber_count');
200         $this->out->text($this->profile->subscriberCount());
201         $this->out->elementEnd('td');
202     }
203
204     function showCreatedDate()
205     {
206         $this->out->elementStart('td', 'entry_created');
207         $this->out->text(date('j M Y', strtotime($this->profile->created)));
208         $this->out->elementEnd('td');
209     }
210
211     function showNoticeCount()
212     {
213         $this->out->elementStart('td', 'entry_notice_count');
214         $this->out->text($this->profile->noticeCount());
215         $this->out->elementEnd('td');
216     }
217
218     function showBio()
219     {
220         if ($this->profile->getDescription()) {
221             $this->out->elementStart('p', 'note');
222             $this->out->text($this->profile->getDescription());
223             $this->out->elementEnd('p');
224         }
225     }
226
227     /**
228      * Only show the tags if we're logged in
229      */
230     function showTags()
231     {
232          if (common_logged_in()) {
233             parent::showTags();
234         }
235
236     }
237 }