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('STATUSNET') && !defined('LACONICA')) {
32 require_once INSTALLDIR.'/lib/widget.php';
35 * Show a bunch of peopletags
36 * provide ajax editing if the current user owns the tags
40 * @author Shashi Gowda <connect2shashi@gmail.com>
41 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 class PeopletagsWidget extends Widget
46 * the query, current peopletag.
47 * or an array of strings (tags)
56 function __construct($out, $tagger, $tagged)
58 parent::__construct($out);
60 $this->user = common_current_user();
61 $this->tag = Profile_tag::getTags($tagger->id, $tagged->id, $this->user);
62 $this->tagger = $tagger;
63 $this->tagged = $tagged;
68 if (Event::handle('StartShowPeopletags', array($this, $this->tagger, $this->tagged))) {
69 if ($this->tag->N > 0) {
73 $this->showEmptyList();
75 Event::handle('EndShowPeopletags', array($this, $this->tagger, $this->tagged));
81 return $this->tag->homeUrl();
86 // TRANS: Label in lists widget.
87 return _m('LABEL','Your lists');
92 $this->out->elementStart('dl', 'entity_tags user_profile_tags');
93 $this->out->element('dt', null, $this->label());
94 $this->out->elementStart('dd');
97 if ($this->isEditable()) {
98 $class .= ' editable';
102 $this->out->elementStart('ul', $class);
103 while ($this->tag->fetch()) {
104 $mode = $this->tag->private ? 'private' : 'public';
105 $tags[] = $this->tag->tag;
107 $this->out->elementStart('li', 'hashptag mode-' . $mode);
108 // Avoid space by using raw output.
109 $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
110 $this->url($this->tag->tag) .
111 '">' . $this->tag->tag . '</a>';
112 $this->out->raw($pt);
113 $this->out->elementEnd('li');
115 $this->out->elementEnd('ul');
117 if ($this->isEditable()) {
118 $this->showEditTagForm($tags);
121 $this->out->elementEnd('dd');
122 $this->out->elementEnd('dl');
125 function showEditTagForm($tags=null)
127 $this->out->elementStart('div', 'form_tag_user_wrap');
128 $this->out->elementStart('form', array('method' => 'post',
129 'class' => 'form_tag_user',
130 'name' => 'tagprofile',
131 'action' => common_local_url('tagprofile', array('id' => $this->tagged->id))));
133 $this->out->elementStart('fieldset');
134 // TRANS: Fieldset legend in lists widget.
135 $this->out->element('legend', null, _m('LEGEND','Edit lists'));
136 $this->out->hidden('token', common_session_token());
137 $this->out->hidden('id', $this->tagged->id);
143 $this->out->input('tags', $this->label(),
144 ($this->out->arg('tags')) ? $this->out->arg('tags') : implode(' ', $tags));
145 // TRANS: Button text to save tags for a profile.
146 $this->out->submit('save', _m('BUTTON','Save'));
148 $this->out->elementEnd('fieldset');
149 $this->out->elementEnd('form');
150 $this->out->elementEnd('div');
153 function showEmptyList()
155 $this->out->elementStart('dl', 'entity_tags user_profile_tags');
156 $this->out->element('dt', null, $this->label());
157 $this->out->elementStart('dd');
160 if ($this->isEditable()) {
161 $class .= ' editable';
164 $this->out->elementStart('ul', $class);
165 // TRANS: Empty list message for tags.
166 $this->out->element('li', null, _('(None)'));
167 $this->out->elementEnd('ul');
169 if ($this->isEditable()) {
170 $this->showEditTagForm();
172 $this->out->elementEnd('dd');
173 $this->out->elementEnd('dl');
176 function isEditable()
178 return !empty($this->user) && $this->tagger->id == $this->user->id;
182 class SelftagsWidget extends PeopletagsWidget
186 // link to self tag page
187 return common_local_url('selftag', array('tag' => $tag));
192 // TRANS: Label in self tags widget.
193 return _m('LABEL','Tags');