]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/tagprofile.php
Added missing isPrivateScope().
[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 require_once INSTALLDIR . '/lib/peopletags.php';
23
24 class TagprofileAction extends FormAction
25 {
26     var $error = null;
27
28     protected $target = null;
29     protected $form = 'TagProfile';
30
31     protected function doPreparation()
32     {
33         $id = $this->trimmed('id');
34         $uri = $this->trimmed('uri');
35         if (!empty($id))  {
36             $this->target = Profile::getKV('id', $id);
37
38             if (!$this->target instanceof Profile) {
39                 // TRANS: Client error displayed when referring to non-existing profile ID.
40                 $this->clientError(_('No profile with that ID.'));
41             }
42         } elseif (!empty($uri)) {
43             $this->target = Profile::fromUri($uri);
44         } else {
45             // TRANS: Client error displayed when trying to tag a user but no ID or profile is provided.
46             $this->clientError(_('No profile identifier provided.'));
47         }
48
49         if (!$this->scoped->canTag($this->target)) {
50             // TRANS: Client error displayed when trying to tag a user that cannot be tagged.
51             $this->clientError(_('You cannot tag this user.'));
52         }
53
54         $this->formOpts = $this->target;
55
56         return true;
57     }
58
59     function title()
60     {
61         if (!$this->target instanceof Profile) {
62             // TRANS: Title for list form when not on a profile page.
63             return _('List a profile');
64         }
65         // TRANS: Title for list form when on a profile page.
66         // TRANS: %s is a profile nickname.
67         return sprintf(_m('ADDTOLIST','List %s'), $this->target->getNickname());
68     }
69
70     function showContent()
71     {
72         $this->elementStart('div', 'entity_profile h-card');
73         // TRANS: Header in list form.
74         $this->element('h2', null, _('User profile'));
75
76         $avatarUrl = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
77         $this->element('img', array('src' => $avatarUrl,
78                                     'class' => 'u-photo avatar entity_depiction',
79                                     'width' => AVATAR_PROFILE_SIZE,
80                                     'height' => AVATAR_PROFILE_SIZE,
81                                     'alt' => $this->target->getBestName()));
82
83         $this->element('a', array('href' => $this->target->getUrl(),
84                                   'class' => 'entity_nickname p-nickname'),
85                        $this->target->getNickname());
86         if ($this->target->fullname) {
87             $this->element('div', 'p-name entity_fn', $this->target->fullname);
88         }
89
90         if ($this->target->location) {
91             $this->element('div', 'p-locality label entity_location', $this->target->location);
92         }
93
94         if ($this->target->homepage) {
95             $this->element('a', array('href' => $this->target->homepage,
96                                       'rel' => 'me',
97                                       'class' => 'u-url entity_url'),
98                            $this->target->homepage);
99         }
100
101         if ($this->target->bio) {
102             $this->element('div', 'p-note entity_note', $this->target->bio);
103         }
104
105         $this->elementEnd('div');
106
107         if (Event::handle('StartShowTagProfileForm', array($this, $this->target))) {
108             parent::showContent();
109             Event::handle('EndShowTagProfileForm', array($this, $this->target));
110         }
111     }
112
113     protected function doPost()
114     {
115         $tagstring = $this->trimmed('tags');
116         $token = $this->trimmed('token');
117
118         if (Event::handle('StartSavePeopletags', array($this, $tagstring))) {
119             $tags = array();
120             $tag_priv = array();
121
122             if (is_string($tagstring) && strlen($tagstring) > 0) {
123
124                 $tags = preg_split('/[\s,]+/', $tagstring);
125
126                 foreach ($tags as &$tag) {
127                     $private = @$tag[0] === '.';
128
129                     $tag = common_canonical_tag($tag);
130                     if (!common_valid_profile_tag($tag)) {
131                         // TRANS: Form validation error displayed if a given tag is invalid.
132                         // TRANS: %s is the invalid tag.
133                         throw new ClientException(sprintf(_('Invalid tag: "%s".'), $tag));
134                     }
135
136                     $tag_priv[$tag] = $private;
137                 }
138             }
139
140             $result = Profile_tag::setTags($this->scoped->getID(), $this->target->getID(), $tags, $tag_priv);
141             if (!$result) {
142                 throw new ServerException('The tags could not be saved.');
143             }
144
145             if ($this->boolean('ajax')) {
146                 $this->startHTML('text/xml;charset=utf-8');
147                 $this->elementStart('head');
148                 $this->element('title', null, _m('TITLE','Tags'));
149                 $this->elementEnd('head');
150                 $this->elementStart('body');
151
152                 if ($this->scoped->id == $this->target->id) {
153                     $widget = new SelftagsWidget($this, $this->scoped, $this->target);
154                     $widget->show();
155                 } else {
156                     $widget = new PeopletagsWidget($this, $this->scoped, $this->target);
157                     $widget->show();
158                 }
159
160                 $this->elementEnd('body');
161                 $this->endHTML();
162             } else {
163                 // TRANS: Success message if lists are saved.
164                 $this->msg = _('Lists saved.');
165                 $this->showForm();
166             }
167
168             Event::handle('EndSavePeopletags', array($this, $tagstring));
169         }
170     }
171 }