]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/peopletaglist.php
b2f2dcca463753c2766de08dda9834505b81e911
[quix0rs-gnu-social.git] / lib / peopletaglist.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Widget to show a list of peopletags
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    Shashi Gowda <connect2shashi@gmail.com>
25  * @copyright 2008-2009 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') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/widget.php';
35
36 define('PEOPLETAGS_PER_PAGE', 20);
37
38 /**
39  * Widget to show a list of peopletags
40  *
41  * @category Public
42  * @package  StatusNet
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 class PeopletagList extends Widget
47 {
48     /** Current peopletag, peopletag query. */
49     var $peopletag = null;
50     /** current user **/
51     var $user = null;
52
53     function __construct($peopletag, $action=null)
54     {
55         parent::__construct($action);
56
57         $this->peopletag = $peopletag;
58
59         if (!empty($owner)) {
60             $this->user = $owner;
61         } else {
62             $this->user = common_current_user();
63         }
64     }
65
66     function show()
67     {
68         $this->out->elementStart('ul', 'peopletags xoxo hfeed');
69
70         $cnt = 0;
71
72         while ($this->peopletag->fetch()) {
73             $cnt++;
74             if($cnt > PEOPLETAGS_PER_PAGE) {
75                 break;
76             }
77             $this->showPeopletag();
78         }
79
80         $this->out->elementEnd('ul');
81
82         return $cnt;
83     }
84
85     function showPeopletag()
86     {
87         $ptag = new PeopletagListItem($this->peopletag, $this->user, $this->out);
88         $ptag->show();
89     }
90 }
91
92 class PeopletagListItem extends Widget
93 {
94     var $peopletag = null;
95     var $current = null;
96     var $profile = null;
97
98     /**
99      * constructor
100      *
101      * Also initializes the owner attribute.
102      *
103      * @param Notice $notice The notice we'll display
104      */
105     function __construct($peopletag, $current, $out=null)
106     {
107         parent::__construct($out);
108         $this->peopletag  = $peopletag;
109         $this->current = $current;
110         $this->profile = Profile::getKV('id', $this->peopletag->tagger);
111     }
112
113     /**
114      * recipe function for displaying a single peopletag.
115      *
116      * This uses all the other methods to correctly display a notice. Override
117      * it or one of the others to fine-tune the output.
118      *
119      * @return void
120      */
121     function url()
122     {
123         return $this->peopletag->homeUrl();
124     }
125
126     function show()
127     {
128         if (empty($this->peopletag)) {
129             common_log(LOG_WARNING, "Trying to show missing peopletag; skipping.");
130             return;
131         }
132
133         if (Event::handle('StartShowPeopletagItem', array($this))) {
134             $this->showStart();
135             $this->showPeopletag();
136             $this->showStats();
137             $this->showEnd();
138             Event::handle('EndShowPeopletagItem', array($this));
139         }
140     }
141
142     function showStart()
143     {
144         $mode = ($this->peopletag->private) ? 'private' : 'public';
145         $this->out->elementStart('li', array('class' => 'h-entry peopletag mode-' . $mode,
146                                              'id' => 'peopletag-' . $this->peopletag->id));
147     }
148
149     function showEnd()
150     {
151         $this->out->elementEnd('li');
152     }
153
154     function showPeopletag()
155     {
156         $this->showCreator();
157         $this->showTag();
158         $this->showPrivacy();
159         $this->showUpdated();
160         $this->showActions();
161         $this->showDescription();
162     }
163
164     function showStats()
165     {
166         $this->out->elementStart('div', 'entry-summary entity_statistics');
167         $this->out->elementStart('span', 'tagged-count');
168         $this->out->element('a',
169             array('href' => common_local_url('peopletagged',
170                                               array('tagger' => $this->profile->nickname,
171                                                     'tag' => $this->peopletag->tag))),
172             // TRANS: Link description for link to list of users tagged with a tag (so part of a list).
173             _('Listed'));
174         $this->out->raw($this->peopletag->taggedCount());
175         $this->out->elementEnd('span');
176
177         $this->out->elementStart('span', 'subscriber-count');
178         $this->out->element('a',
179             array('href' => common_local_url('peopletagsubscribers',
180                                               array('tagger' => $this->profile->nickname,
181                                                     'tag' => $this->peopletag->tag))),
182             // TRANS: Link description for link to list of users subscribed to a tag.
183             _('Subscribers'));
184         $this->out->raw($this->peopletag->subscriberCount());
185         $this->out->elementEnd('span');
186         $this->out->elementEnd('div');
187     }
188
189     function showOwnerOptions()
190     {
191         $this->out->elementStart('li', 'entity_edit');
192         $this->out->element('a', array('href' =>
193                     common_local_url('editpeopletag', array('tagger' => $this->profile->nickname,
194                                                     'tag' => $this->peopletag->tag)),
195                                   // TRANS: Title for link to edit list settings.
196                                   'title' => _('Edit list settings.')),
197                        // TRANS: Text for link to edit list settings.
198                        _('Edit'));
199         $this->out->elementEnd('li');
200     }
201
202     function showSubscribeForm()
203     {
204         $this->out->elementStart('li');
205
206         if (Event::handle('StartSubscribePeopletagForm', array($this->out, $this->peopletag))) {
207             if ($this->current) {
208                 if ($this->peopletag->hasSubscriber($this->current->id)) {
209                     $form = new UnsubscribePeopletagForm($this->out, $this->peopletag);
210                     $form->show();
211                 } else {
212                     $form = new SubscribePeopletagForm($this->out, $this->peopletag);
213                     $form->show();
214                 }
215             }
216             Event::handle('EndSubscribePeopletagForm', array($this->out, $this->peopletag));
217         }
218
219         $this->out->elementEnd('li');
220     }
221
222     function showCreator()
223     {
224         $attrs = array();
225         $attrs['href'] = $this->profile->profileurl;
226         $attrs['class'] = 'h-card p-author nickname p-name';
227         $attrs['rel'] = 'contact';
228         $attrs['title'] = $this->profile->getFancyName();
229
230         $this->out->elementStart('a', $attrs);
231         $this->showAvatar($this->profile);
232         $this->out->text($this->profile->getNickname());
233         $this->out->elementEnd('a');
234     }
235
236     function showUpdated()
237     {
238         if (!empty($this->peopletag->modified)) {
239             $this->out->element('abbr',
240                 array('title' => common_date_w3dtf($this->peopletag->modified),
241                       'class' => 'updated'),
242                 common_date_string($this->peopletag->modified));
243         }
244     }
245
246     function showPrivacy()
247     {
248         if ($this->peopletag->private) {
249             $this->out->elementStart('a',
250                 array('href' => common_local_url('peopletagsbyuser',
251                     array('nickname' => $this->profile->nickname, 'private' => 1))));
252             // TRANS: Privacy mode text in list list item for private list.
253             $this->out->element('span', 'privacy_mode', _m('MODE','Private'));
254             $this->out->elementEnd('a');
255         }
256     }
257
258     function showTag()
259     {
260         $this->out->elementStart('span', 'entry-title tag');
261         $this->out->element('a',
262             array('rel'   => 'bookmark',
263                   'href'  => $this->url()),
264             htmlspecialchars($this->peopletag->tag));
265         $this->out->elementEnd('span');
266     }
267
268     function showActions()
269     {
270         $this->out->elementStart('div', 'entity_actions');
271         $this->out->elementStart('ul');
272
273         if (!$this->peopletag->private) {
274             $this->showSubscribeForm();
275         }
276
277         if (!empty($this->current) && $this->profile->id == $this->current->id) {
278             $this->showOwnerOptions();
279         }
280         $this->out->elementEnd('ul');
281         $this->out->elementEnd('div');
282     }
283
284     function showDescription()
285     {
286         $this->out->element('div', 'e-content description', $this->peopletag->description);
287     }
288 }