]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/peopletags.php
96b85afd4f773541bc2886d5345cafbee9138502
[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
44 class PeopletagsWidget extends Widget
45 {
46     /*
47      * the query, current peopletag.
48      * or an array of strings (tags)
49      */
50
51     var $tag=null;
52
53     var $user=null;
54     var $tagger=null;
55     var $tagged=null;
56
57     function __construct($out, $tagger, $tagged)
58     {
59         parent::__construct($out);
60
61         $this->user   = common_current_user();
62         $this->tag = Profile_tag::getTags($tagger->id, $tagged->id, $this->user);
63         $this->tagger = $tagger;
64         $this->tagged = $tagged;
65     }
66
67     function show()
68     {
69         if (Event::handle('StartShowPeopletags', array($this, $this->tagger, $this->tagged))) {
70             if ($this->tag->N > 0) {
71                 $this->showTags();
72             }
73             else {
74                 $this->showEmptyList();
75             }
76             Event::handle('EndShowPeopletags', array($this, $this->tagger, $this->tagged));
77         }
78     }
79
80     function url()
81     {
82         return $this->tag->homeUrl();
83     }
84
85     function label()
86     {
87         return _('Tags by you');
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('span', '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         $this->out->element('legend', null, _('Edit tags'));
135         $this->out->hidden('token', common_session_token());
136         $this->out->hidden('id', $this->tagged->id);
137
138         if (!$tags) {
139             $tags = array();
140         }
141
142         $this->out->input('tags', $this->label(),
143                      ($this->out->arg('tags')) ? $this->out->arg('tags') : implode(' ', $tags));
144         $this->out->submit('save', _('Save'));
145
146         $this->out->elementEnd('fieldset');
147         $this->out->elementEnd('form');
148         $this->out->elementEnd('span');
149     }
150
151     function showEmptyList()
152     {
153         $this->out->elementStart('dl', 'entity_tags user_profile_tags');
154         $this->out->element('dt', null, $this->label());
155         $this->out->elementStart('dd');
156
157         $class = 'tags';
158         if ($this->isEditable()) {
159             $class .= ' editable';
160         }
161
162         $this->out->elementStart('ul', $class);
163         $this->out->element('li', null, _('(None)'));
164         $this->out->elementEnd('ul');
165
166         if ($this->isEditable()) {
167             $this->showEditTagForm();
168         }
169         $this->out->elementEnd('dd');
170         $this->out->elementEnd('dl');
171     }
172
173     function isEditable()
174     {
175         return !empty($this->user) && $this->tagger->id == $this->user->id;
176     }
177 }
178
179 class SelftagsWidget extends PeopletagsWidget
180 {
181     function url($tag)
182     {
183         // link to self tag page
184         return common_local_url('selftag', array('tag' => $tag));
185     }
186
187     function label()
188     {
189         return _('Tags');
190     }
191 }