]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/peopletags.php
Don't log every included config file
[quix0rs-gnu-social.git] / lib / peopletags.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('STATUSNET') && !defined('LACONICA')) {
29     exit(1);
30 }
31
32 require_once INSTALLDIR.'/lib/widget.php';
33
34 /*
35  * Show a bunch of peopletags
36  * provide ajax editing if the current user owns the tags
37  *
38  * @category Action
39  * @pacage   StatusNet
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
42  */
43 class PeopletagsWidget extends Widget
44 {
45     /*
46      * the query, current peopletag.
47      * or an array of strings (tags)
48      */
49
50     var $tag=null;
51
52     var $user=null;
53     var $tagger=null;
54     var $tagged=null;
55
56     function __construct($out, $tagger, $tagged)
57     {
58         parent::__construct($out);
59
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;
64     }
65
66     function show()
67     {
68         if (Event::handle('StartShowPeopletags', array($this, $this->tagger, $this->tagged))) {
69             if ($this->tag->N > 0) {
70                 $this->showTags();
71             }
72             else {
73                 $this->showEmptyList();
74             }
75             Event::handle('EndShowPeopletags', array($this, $this->tagger, $this->tagged));
76         }
77     }
78
79     function url()
80     {
81         return $this->tag->homeUrl();
82     }
83
84     function label()
85     {
86         // TRANS: Label in lists widget.
87         return _m('LABEL','Your lists');
88     }
89
90     function showTags()
91     {
92         $this->out->elementStart('dl', 'entity_tags user_profile_tags');
93         $this->out->element('dt', null, $this->label());
94         $this->out->elementStart('dd');
95
96         $class = 'tags xoxo';
97         if ($this->isEditable()) {
98             $class .= ' editable';
99         }
100
101         $tags = array();
102         $this->out->elementStart('ul', $class);
103         while ($this->tag->fetch()) {
104             $mode = $this->tag->private ? 'private' : 'public';
105             $tags[] = $this->tag->tag;
106
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');
114         }
115         $this->out->elementEnd('ul');
116
117         if ($this->isEditable()) {
118             $this->showEditTagForm($tags);
119         }
120
121         $this->out->elementEnd('dd');
122         $this->out->elementEnd('dl');
123     }
124
125     function showEditTagForm($tags=null)
126     {
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))));
132
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);
138
139         if (!$tags) {
140             $tags = array();
141         }
142
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'));
147
148         $this->out->elementEnd('fieldset');
149         $this->out->elementEnd('form');
150         $this->out->elementEnd('div');
151     }
152
153     function showEmptyList()
154     {
155         $this->out->elementStart('dl', 'entity_tags user_profile_tags');
156         $this->out->element('dt', null, $this->label());
157         $this->out->elementStart('dd');
158
159         $class = 'tags';
160         if ($this->isEditable()) {
161             $class .= ' editable';
162         }
163
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');
168
169         if ($this->isEditable()) {
170             $this->showEditTagForm();
171         }
172         $this->out->elementEnd('dd');
173         $this->out->elementEnd('dl');
174     }
175
176     function isEditable()
177     {
178         return !empty($this->user) && $this->tagger->id == $this->user->id;
179     }
180 }
181
182 class SelftagsWidget extends PeopletagsWidget
183 {
184     function url($tag)
185     {
186         // link to self tag page
187         return common_local_url('selftag', array('tag' => $tag));
188     }
189
190     function label()
191     {
192         // TRANS: Label in self tags widget.
193         return _m('LABEL','Tags');
194     }
195 }