]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/tagprofile.php
Removed plugin Google-Analytics as this is free/libre and decentralized
[quix0rs-gnu-social.git] / actions / tagprofile.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('GNUSOCIAL')) { exit(1); }
21
22 class TagprofileAction extends FormAction
23 {
24     var $error = null;
25
26     protected $target = null;
27     protected $form = 'TagProfile';
28
29     protected function doPreparation()
30     {
31         $id = $this->trimmed('id');
32         $uri = $this->trimmed('uri');
33         if (!empty($id))  {
34             $this->target = Profile::getKV('id', $id);
35
36             if (!$this->target instanceof Profile) {
37                 // TRANS: Client error displayed when referring to non-existing profile ID.
38                 $this->clientError(_('No profile with that ID.'));
39             }
40         } elseif (!empty($uri)) {
41             $this->target = Profile::fromUri($uri);
42         } else {
43             // TRANS: Client error displayed when trying to tag a user but no ID or profile is provided.
44             $this->clientError(_('No profile identifier provided.'));
45         }
46
47         if (!$this->scoped->canTag($this->target)) {
48             // TRANS: Client error displayed when trying to tag a user that cannot be tagged.
49             $this->clientError(_('You cannot tag this user.'));
50         }
51
52         $this->formOpts = $this->target;
53
54         return true;
55     }
56
57     function title()
58     {
59         if (!$this->target instanceof Profile) {
60             // TRANS: Title for list form when not on a profile page.
61             return _('List a profile');
62         }
63         // TRANS: Title for list form when on a profile page.
64         // TRANS: %s is a profile nickname.
65         return sprintf(_m('ADDTOLIST','List %s'), $this->target->getNickname());
66     }
67
68     function showPage()
69     {
70         // Only serve page content if we aren't POSTing via ajax
71         // otherwise, we serve XML content from doPost()
72         if (!$this->isPost() || !$this->boolean('ajax')) {
73             parent::showPage();
74         }
75     }
76
77     function showContent()
78     {
79         $this->elementStart('div', 'entity_profile h-card');
80         // TRANS: Header in list form.
81         $this->element('h2', null, _('User profile'));
82
83         $avatarUrl = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
84         $this->element('img', array('src' => $avatarUrl,
85                                     'class' => 'u-photo avatar entity_depiction',
86                                     'width' => AVATAR_PROFILE_SIZE,
87                                     'height' => AVATAR_PROFILE_SIZE,
88                                     'alt' => $this->target->getBestName()));
89
90         $this->element('a', array('href' => $this->target->getUrl(),
91                                   'class' => 'entity_nickname p-nickname'),
92                        $this->target->getNickname());
93         if ($this->target->fullname) {
94             $this->element('div', 'p-name entity_fn', $this->target->fullname);
95         }
96
97         if ($this->target->location) {
98             $this->element('div', 'p-locality label entity_location', $this->target->location);
99         }
100
101         if ($this->target->homepage) {
102             $this->element('a', array('href' => $this->target->homepage,
103                                       'rel' => 'me',
104                                       'class' => 'u-url entity_url'),
105                            $this->target->homepage);
106         }
107
108         if ($this->target->bio) {
109             $this->element('div', 'p-note entity_note', $this->target->bio);
110         }
111
112         $this->elementEnd('div');
113
114         if (Event::handle('StartShowTagProfileForm', array($this, $this->target))) {
115             parent::showContent();
116             Event::handle('EndShowTagProfileForm', array($this, $this->target));
117         }
118     }
119
120     protected function doPost()
121     {
122         $tagstring = $this->trimmed('tags');
123         $token = $this->trimmed('token');
124
125         if (Event::handle('StartSavePeopletags', array($this, $tagstring))) {
126             $tags = array();
127             $tag_priv = array();
128
129             if (is_string($tagstring) && strlen($tagstring) > 0) {
130
131                 $tags = preg_split('/[\s,]+/', $tagstring);
132
133                 foreach ($tags as &$tag) {
134                     $private = @$tag[0] === '.';
135
136                     $tag = common_canonical_tag($tag);
137                     if (!common_valid_profile_tag($tag)) {
138                         // TRANS: Form validation error displayed if a given tag is invalid.
139                         // TRANS: %s is the invalid tag.
140                         throw new ClientException(sprintf(_('Invalid tag: "%s".'), $tag));
141                     }
142
143                     $tag_priv[$tag] = $private;
144                 }
145             }
146
147             $result = Profile_tag::setTags($this->scoped->getID(), $this->target->getID(), $tags, $tag_priv);
148             if (!$result) {
149                 throw new ServerException('The tags could not be saved.');
150             }
151
152             if ($this->boolean('ajax')) {
153                 $this->startHTML('text/xml;charset=utf-8');
154                 $this->elementStart('head');
155                 $this->element('title', null, _m('TITLE','Tags'));
156                 $this->elementEnd('head');
157                 $this->elementStart('body');
158
159                 if ($this->scoped->id == $this->target->id) {
160                     $widget = new SelftagsWidget($this, $this->scoped, $this->target);
161                     $widget->show();
162                 } else {
163                     $widget = new PeopletagsWidget($this, $this->scoped, $this->target);
164                     $widget->show();
165                 }
166
167                 $this->elementEnd('body');
168                 $this->endHTML();
169             } else {
170                 // TRANS: Success message if lists are saved.
171                 $this->msg = _('Lists saved.');
172                 $this->showForm();
173             }
174
175             Event::handle('EndSavePeopletags', array($this, $tagstring));
176         }
177     }
178 }