3 * StatusNet, the distributed open-source microblogging tool
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.
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.
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/>.
24 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
25 * @link http://status.net/
28 if (!defined('GNUSOCIAL')) { exit(1); }
31 * Show a bunch of peopletags
32 * provide ajax editing if the current user owns the tags
36 * @author Shashi Gowda <connect2shashi@gmail.com>
37 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
39 class PeopletagsWidget extends Widget
42 * the query, current peopletag.
43 * or an array of strings (tags)
52 function __construct($out, $tagger, $tagged)
54 parent::__construct($out);
56 $this->user = common_current_user();
57 $this->tag = Profile_tag::getTags($tagger->id, $tagged->id, $this->user);
58 $this->tagger = $tagger;
59 $this->tagged = $tagged;
64 if (Event::handle('StartShowPeopletags', array($this, $this->tagger, $this->tagged))) {
65 if ($this->tag->N > 0) {
69 $this->showEmptyList();
71 Event::handle('EndShowPeopletags', array($this, $this->tagger, $this->tagged));
77 return $this->tag->homeUrl();
82 // TRANS: Label in lists widget.
83 return _m('LABEL','Your lists');
88 $this->out->elementStart('dl', 'entity_tags user_profile_tags');
89 $this->out->element('dt', null, $this->label());
90 $this->out->elementStart('dd');
93 if ($this->isEditable()) {
94 $class .= ' editable';
98 $this->out->elementStart('ul', $class);
99 while ($this->tag->fetch()) {
100 $mode = $this->tag->private ? 'private' : 'public';
101 $tags[] = $this->tag->tag;
103 $this->out->elementStart('li', 'hashptag mode-' . $mode);
104 // Avoid space by using raw output.
105 $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
106 htmlspecialchars($this->url()) .
107 '">' . htmlspecialchars($this->tag->tag) . '</a>';
108 $this->out->raw($pt);
109 $this->out->elementEnd('li');
111 $this->out->elementEnd('ul');
113 if ($this->isEditable()) {
114 $this->showEditTagForm($tags);
117 $this->out->elementEnd('dd');
118 $this->out->elementEnd('dl');
121 function showEditTagForm($tags=null)
123 $this->out->elementStart('div', 'form_tag_user_wrap');
124 $this->out->elementStart('form', array('method' => 'post',
125 'class' => 'form_tag_user',
126 'name' => 'tagprofile',
127 'action' => common_local_url('tagprofile', array('id' => $this->tagged->id))));
129 $this->out->elementStart('fieldset');
130 // TRANS: Fieldset legend in lists widget.
131 $this->out->element('legend', null, _m('LEGEND','Edit lists'));
132 $this->out->hidden('token', common_session_token());
133 $this->out->hidden('id', $this->tagged->id);
139 $this->out->input('tags', $this->label(),
140 ($this->out->arg('tags')) ? $this->out->arg('tags') : implode(' ', $tags));
141 // TRANS: Button text to save tags for a profile.
142 $this->out->submit('save', _m('BUTTON','Save'));
144 $this->out->elementEnd('fieldset');
145 $this->out->elementEnd('form');
146 $this->out->elementEnd('div');
149 function showEmptyList()
151 $this->out->elementStart('dl', 'entity_tags user_profile_tags');
152 $this->out->element('dt', null, $this->label());
153 $this->out->elementStart('dd');
156 if ($this->isEditable()) {
157 $class .= ' editable';
160 $this->out->elementStart('ul', $class);
161 // TRANS: Empty list message for tags.
162 $this->out->element('li', null, _('(None)'));
163 $this->out->elementEnd('ul');
165 if ($this->isEditable()) {
166 $this->showEditTagForm();
168 $this->out->elementEnd('dd');
169 $this->out->elementEnd('dl');
172 function isEditable()
174 return !empty($this->user) && $this->tagger->id == $this->user->id;