]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/peopletagswidget.php
Last type-hint is an array, added.
[quix0rs-gnu-social.git] / lib / peopletagswidget.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Tags for a profile
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  Action
23  * @package   StatusNet
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/
26  */
27
28 if (!defined('GNUSOCIAL')) { exit(1); }
29
30 /*
31  * Show a bunch of peopletags
32  * provide ajax editing if the current user owns the tags
33  *
34  * @category Action
35  * @pacage   StatusNet
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
38  */
39 class PeopletagsWidget extends Widget
40 {
41     /*
42      * the query, current peopletag.
43      * or an array of strings (tags)
44      */
45
46     var $tag=null;
47
48     var $user=null;
49     var $tagger=null;
50     var $tagged=null;
51
52     function __construct($out, $tagger, $tagged)
53     {
54         parent::__construct($out);
55
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;
60     }
61
62     function show()
63     {
64         if (Event::handle('StartShowPeopletags', array($this, $this->tagger, $this->tagged))) {
65             if ($this->tag->N > 0) {
66                 $this->showTags();
67             }
68             else {
69                 $this->showEmptyList();
70             }
71             Event::handle('EndShowPeopletags', array($this, $this->tagger, $this->tagged));
72         }
73     }
74
75     function url()
76     {
77         return $this->tag->homeUrl();
78     }
79
80     function label()
81     {
82         // TRANS: Label in lists widget.
83         return _m('LABEL','Your lists');
84     }
85
86     function showTags()
87     {
88         $this->out->elementStart('dl', 'entity_tags user_profile_tags');
89         $this->out->element('dt', null, $this->label());
90         $this->out->elementStart('dd');
91
92         $class = 'tags xoxo';
93         if ($this->isEditable()) {
94             $class .= ' editable';
95         }
96
97         $tags = array();
98         $this->out->elementStart('ul', $class);
99         while ($this->tag->fetch()) {
100             $mode = $this->tag->private ? 'private' : 'public';
101             $tags[] = $this->tag->tag;
102
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');
110         }
111         $this->out->elementEnd('ul');
112
113         if ($this->isEditable()) {
114             $this->showEditTagForm($tags);
115         }
116
117         $this->out->elementEnd('dd');
118         $this->out->elementEnd('dl');
119     }
120
121     function showEditTagForm($tags=null)
122     {
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))));
128
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);
134
135         if (!$tags) {
136             $tags = array();
137         }
138
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'));
143
144         $this->out->elementEnd('fieldset');
145         $this->out->elementEnd('form');
146         $this->out->elementEnd('div');
147     }
148
149     function showEmptyList()
150     {
151         $this->out->elementStart('dl', 'entity_tags user_profile_tags');
152         $this->out->element('dt', null, $this->label());
153         $this->out->elementStart('dd');
154
155         $class = 'tags';
156         if ($this->isEditable()) {
157             $class .= ' editable';
158         }
159
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');
164
165         if ($this->isEditable()) {
166             $this->showEditTagForm();
167         }
168         $this->out->elementEnd('dd');
169         $this->out->elementEnd('dl');
170     }
171
172     function isEditable()
173     {
174         return !empty($this->user) && $this->tagger->id == $this->user->id;
175     }
176 }