]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/peopletaglist.php
Merge branch '1.0.x' into people_tags_rebase
[quix0rs-gnu-social.git] / lib / peopletaglist.php
1 <?php
2
3 /**
4  * StatusNet, the distributed open-source microblogging tool
5  *
6  * Widget to show a list of peopletags
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    Shashi Gowda <connect2shashi@gmail.com>
26  * @copyright 2008-2009 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') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/widget.php';
36
37 define('PEOPLETAGS_PER_PAGE', 20);
38
39 /**
40  * Widget to show a list of peopletags
41  *
42  * @category Public
43  * @package  StatusNet
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  */
47
48 class PeopletagList extends Widget
49 {
50     /** Current peopletag, peopletag query. */
51     var $peopletag = null;
52     /** current user **/
53     var $user = null;
54
55     function __construct($peopletag, $action=null)
56     {
57         parent::__construct($action);
58
59         $this->peopletag = $peopletag;
60
61         if (!empty($owner)) {
62             $this->user = $owner;
63         } else {
64             $this->user = common_current_user();
65         }
66     }
67
68     function show()
69     {
70         $this->out->elementStart('ul', 'peopletags xoxo hfeed');
71
72         $cnt = 0;
73
74         while ($this->peopletag->fetch()) {
75             $cnt++;
76             if($cnt > PEOPLETAGS_PER_PAGE) {
77                 break;
78             }
79             $this->showPeopletag();
80         }
81
82         $this->out->elementEnd('ul');
83
84         return $cnt;
85     }
86
87     function showPeopletag()
88     {
89         $ptag = new PeopletagListItem($this->peopletag, $this->user, $this->out);
90         $ptag->show();
91     }
92 }
93
94 class PeopletagListItem extends Widget
95 {
96     var $peopletag = null;
97     var $current = null;
98     var $profile = null;
99
100     /**
101      * constructor
102      *
103      * Also initializes the owner attribute.
104      *
105      * @param Notice $notice The notice we'll display
106      */
107
108     function __construct($peopletag, $current, $out=null)
109     {
110         parent::__construct($out);
111         $this->peopletag  = $peopletag;
112         $this->current = $current;
113         $this->profile = Profile::staticGet('id', $this->peopletag->tagger);
114     }
115
116     /**
117      * recipe function for displaying a single peopletag.
118      *
119      * This uses all the other methods to correctly display a notice. Override
120      * it or one of the others to fine-tune the output.
121      *
122      * @return void
123      */
124
125     function url()
126     {
127         return $this->peopletag->homeUrl();
128     }
129
130     function show()
131     {
132         if (empty($this->peopletag)) {
133             common_log(LOG_WARNING, "Trying to show missing peopletag; skipping.");
134             return;
135         }
136
137         if (Event::handle('StartShowPeopletagItem', array($this))) {
138             $this->showStart();
139             $this->showPeopletag();
140             $this->showStats();
141             $this->showEnd();
142             Event::handle('EndShowPeopletagItem', array($this));
143         }
144     }
145
146     function showStart()
147     {
148         $mode = ($this->peopletag->private) ? 'private' : 'public';
149         $this->out->elementStart('li', array('class' => 'hentry peopletag mode-' . $mode,
150                                              'id' => 'peopletag-' . $this->peopletag->id));
151     }
152
153     function showEnd()
154     {
155         $this->out->elementEnd('li');
156     }
157
158     function showPeopletag()
159     {
160         $this->showCreator();
161         $this->showTag();
162         $this->showPrivacy();
163         $this->showUpdated();
164         $this->showActions();
165         $this->showDescription();
166     }
167
168     function showStats()
169     {
170         $this->out->elementStart('div', 'entry-summary entity_statistics');
171         $this->out->elementStart('span', 'tagged-count');
172         $this->out->element('a',
173             array('href' => common_local_url('peopletagged',
174                                               array('tagger' => $this->profile->nickname,
175                                                     'tag' => $this->peopletag->tag))),
176             _('Tagged'));
177         $this->out->raw($this->peopletag->taggedCount());
178         $this->out->elementEnd('span');
179
180         $this->out->elementStart('span', 'subscriber-count');
181         $this->out->element('a',
182             array('href' => common_local_url('peopletagsubscribers',
183                                               array('tagger' => $this->profile->nickname,
184                                                     'tag' => $this->peopletag->tag))),
185             _('Subscribers'));
186         $this->out->raw($this->peopletag->subscriberCount());
187         $this->out->elementEnd('span');
188         $this->out->elementEnd('div');
189     }
190
191     function showOwnerOptions()
192     {
193         $this->out->elementStart('li', 'entity_edit');
194         $this->out->element('a', array('href' =>
195                     common_local_url('editpeopletag', array('tagger' => $this->profile->nickname,
196                                                     'tag' => $this->peopletag->tag)),
197                                   'title' => _('Edit peopletag 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         $this->out->elementStart('span', 'author vcard');
225         $attrs = array();
226         $attrs['href'] = $this->profile->profileurl;
227         $attrs['class'] = 'url';
228         $attrs['rel'] = 'contact';
229
230         if (!empty($this->profile->fullname)) {
231             $attrs['title'] = $this->profile->fullname . ' (' . $this->profile->nickname . ')';
232         }
233         $this->out->elementStart('a', $attrs);
234         $this->showAvatar();
235         $this->out->text(' ');
236         $this->out->element('span', 'nickname fn',
237                         htmlspecialchars($this->profile->nickname));
238
239         $this->out->elementEnd('a');
240         $this->out->elementEnd('span');
241     }
242
243     function showUpdated()
244     {
245         if (!empty($this->peopletag->modified)) {
246             $this->out->element('abbr',
247                 array('title' => common_date_w3dtf($this->peopletag->modified),
248                       'class' => 'updated'),
249                 common_date_string($this->peopletag->modified));
250         }
251     }
252
253     function showPrivacy()
254     {
255         if ($this->peopletag->private) {
256             $this->out->elementStart('a',
257                 array('href' => common_local_url('peopletagsbyuser',
258                     array('nickname' => $this->profile->nickname, 'private' => 1))));
259             $this->out->element('span', 'privacy_mode', _('Private'));
260             $this->out->elementEnd('a');
261         }
262     }
263
264     function showTag()
265     {
266         $this->out->elementStart('span', 'entry-title tag');
267         $this->out->element('a',
268             array('rel'   => 'bookmark',
269                   'href'  => $this->url()),
270             htmlspecialchars($this->peopletag->tag));
271         $this->out->elementEnd('span');
272     }
273
274     /**
275      * show the avatar of the peopletag's creator
276      *
277      * This will use the default avatar if no avatar is assigned for the author.
278      * It makes a link to the author's profile.
279      *
280      * @return void
281      */
282
283     function showAvatar($size=AVATAR_STREAM_SIZE)
284     {
285         $avatar = $this->profile->getAvatar($size);
286
287         $this->out->element('img', array('src' => ($avatar) ?
288                                          $avatar->displayUrl() :
289                                          Avatar::defaultImage($size),
290                                          'class' => 'avatar photo',
291                                          'width' => $size,
292                                          'height' => $size,
293                                          'alt' =>
294                                          ($this->profile->fullname) ?
295                                          $this->profile->fullname :
296                                          $this->profile->nickname));
297     }
298
299     function showActions()
300     {
301         $this->out->elementStart('div', 'entity_actions');
302         $this->out->elementStart('ul');
303
304         if (!$this->peopletag->private) {
305             $this->showSubscribeForm();
306         }
307
308         if (!empty($this->current) && $this->profile->id == $this->current->id) {
309             $this->showOwnerOptions();
310         }
311         $this->out->elementEnd('ul');
312         $this->out->elementEnd('div');
313     }
314
315     function showDescription()
316     {
317         $this->out->element('div', 'entry-content description',
318                             $this->peopletag->description);
319     }
320 }