]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/peopletaglistitem.php
Avoid having to check for notices without rendered copies in upgrade.php
[quix0rs-gnu-social.git] / lib / peopletaglistitem.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('GNUSOCIAL')) { exit(1); }
31
32 class PeopletagListItem extends Widget
33 {
34     var $peopletag = null;
35     var $current = null;
36     var $profile = null;
37
38     /**
39      * constructor
40      *
41      * Also initializes the owner attribute.
42      *
43      * @param Notice $notice The notice we'll display
44      */
45     function __construct($peopletag, $current, $out=null)
46     {
47         parent::__construct($out);
48         $this->peopletag  = $peopletag;
49         $this->current = $current;
50         $this->profile = Profile::getKV('id', $this->peopletag->tagger);
51     }
52
53     /**
54      * recipe function for displaying a single peopletag.
55      *
56      * This uses all the other methods to correctly display a notice. Override
57      * it or one of the others to fine-tune the output.
58      *
59      * @return void
60      */
61     function url()
62     {
63         return $this->peopletag->homeUrl();
64     }
65
66     function show()
67     {
68         if (empty($this->peopletag)) {
69             common_log(LOG_WARNING, "Trying to show missing peopletag; skipping.");
70             return;
71         }
72
73         if (Event::handle('StartShowPeopletagItem', array($this))) {
74             $this->showStart();
75             $this->showPeopletag();
76             $this->showStats();
77             $this->showEnd();
78             Event::handle('EndShowPeopletagItem', array($this));
79         }
80     }
81
82     function showStart()
83     {
84         $mode = ($this->peopletag->private) ? 'private' : 'public';
85         $this->out->elementStart('li', array('class' => 'h-entry peopletag mode-' . $mode,
86                                              'id' => 'peopletag-' . $this->peopletag->id));
87     }
88
89     function showEnd()
90     {
91         $this->out->elementEnd('li');
92     }
93
94     function showPeopletag()
95     {
96         $this->showCreator();
97         $this->showTag();
98         $this->showPrivacy();
99         $this->showUpdated();
100         $this->showActions();
101         $this->showDescription();
102     }
103
104     function showStats()
105     {
106         $this->out->elementStart('div', 'entry-summary entity_statistics');
107         $this->out->elementStart('span', 'tagged-count');
108         $this->out->element('a',
109             array('href' => common_local_url('peopletagged',
110                                               array('tagger' => $this->profile->nickname,
111                                                     'tag' => $this->peopletag->tag))),
112             // TRANS: Link description for link to list of users tagged with a tag (so part of a list).
113             _('Listed'));
114         $this->out->raw($this->peopletag->taggedCount());
115         $this->out->elementEnd('span');
116
117         $this->out->elementStart('span', 'subscriber-count');
118         $this->out->element('a',
119             array('href' => common_local_url('peopletagsubscribers',
120                                               array('tagger' => $this->profile->nickname,
121                                                     'tag' => $this->peopletag->tag))),
122             // TRANS: Link description for link to list of users subscribed to a tag.
123             _('Subscribers'));
124         $this->out->raw($this->peopletag->subscriberCount());
125         $this->out->elementEnd('span');
126         $this->out->elementEnd('div');
127     }
128
129     function showOwnerOptions()
130     {
131         $this->out->elementStart('li', 'entity_edit');
132         $this->out->element('a', array('href' =>
133                     common_local_url('editpeopletag', array('tagger' => $this->profile->nickname,
134                                                     'tag' => $this->peopletag->tag)),
135                                   // TRANS: Title for link to edit list settings.
136                                   'title' => _('Edit list settings.')),
137                        // TRANS: Text for link to edit list settings.
138                        _('Edit'));
139         $this->out->elementEnd('li');
140     }
141
142     function showSubscribeForm()
143     {
144         $this->out->elementStart('li');
145
146         if (Event::handle('StartSubscribePeopletagForm', array($this->out, $this->peopletag))) {
147             if ($this->current) {
148                 if ($this->peopletag->hasSubscriber($this->current->id)) {
149                     $form = new UnsubscribePeopletagForm($this->out, $this->peopletag);
150                     $form->show();
151                 } else {
152                     $form = new SubscribePeopletagForm($this->out, $this->peopletag);
153                     $form->show();
154                 }
155             }
156             Event::handle('EndSubscribePeopletagForm', array($this->out, $this->peopletag));
157         }
158
159         $this->out->elementEnd('li');
160     }
161
162     function showCreator()
163     {
164         $attrs = array();
165         $attrs['href'] = $this->profile->profileurl;
166         $attrs['class'] = 'h-card p-author nickname p-name';
167         $attrs['rel'] = 'contact';
168         $attrs['title'] = $this->profile->getFancyName();
169
170         $this->out->elementStart('a', $attrs);
171         $this->showAvatar($this->profile);
172         $this->out->text($this->profile->getNickname());
173         $this->out->elementEnd('a');
174     }
175
176     function showUpdated()
177     {
178         if (!empty($this->peopletag->modified)) {
179             $this->out->element('abbr',
180                 array('title' => common_date_w3dtf($this->peopletag->modified),
181                       'class' => 'updated'),
182                 common_date_string($this->peopletag->modified));
183         }
184     }
185
186     function showPrivacy()
187     {
188         if ($this->peopletag->private) {
189             $this->out->elementStart('a',
190                 array('href' => common_local_url('peopletagsbyuser',
191                     array('nickname' => $this->profile->nickname, 'private' => 1))));
192             // TRANS: Privacy mode text in list list item for private list.
193             $this->out->element('span', 'privacy_mode', _m('MODE','Private'));
194             $this->out->elementEnd('a');
195         }
196     }
197
198     function showTag()
199     {
200         $this->out->elementStart('span', 'entry-title tag');
201         $this->out->element('a',
202             array('rel'   => 'bookmark',
203                   'href'  => $this->url()),
204             htmlspecialchars($this->peopletag->tag));
205         $this->out->elementEnd('span');
206     }
207
208     function showActions()
209     {
210         $this->out->elementStart('div', 'entity_actions');
211         $this->out->elementStart('ul');
212
213         if (!$this->peopletag->private) {
214             $this->showSubscribeForm();
215         }
216
217         if (!empty($this->current) && $this->profile->id == $this->current->id) {
218             $this->showOwnerOptions();
219         }
220         $this->out->elementEnd('ul');
221         $this->out->elementEnd('div');
222     }
223
224     function showDescription()
225     {
226         $this->out->element('div', 'e-content description', $this->peopletag->description);
227     }
228 }