3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
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.
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.
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/>.
20 if (!defined('GNUSOCIAL')) { exit(1); }
22 require_once INSTALLDIR . '/lib/settingsaction.php';
23 require_once INSTALLDIR . '/lib/peopletags.php';
25 class TagprofileAction extends FormAction
29 protected $target = null;
30 protected $form = 'TagProfile';
32 protected function prepare(array $args=array())
34 parent::prepare($args);
36 $id = $this->trimmed('id');
40 $this->target = Profile::getKV('id', $id);
42 if (!$this->target instanceof Profile) {
43 // TRANS: Client error displayed when referring to non-existing profile ID.
44 $this->clientError(_('No profile with that ID.'));
48 if ($this->target instanceof Profile && !$this->scoped->canTag($this->target)) {
49 // TRANS: Client error displayed when trying to tag a user that cannot be tagged.
50 $this->clientError(_('You cannot tag this user.'));
56 protected function handle()
58 if (Event::handle('StartTagProfileAction', array($this, $this->target))) {
60 Event::handle('EndTagProfileAction', array($this, $this->target));
66 if (!$this->target instanceof Profile) {
67 // TRANS: Title for list form when not on a profile page.
68 return _('List a profile');
70 // TRANS: Title for list form when on a profile page.
71 // TRANS: %s is a profile nickname.
72 return sprintf(_m('ADDTOLIST','List %s'), $this->target->getNickname());
75 function showContent()
77 $this->elementStart('div', 'entity_profile h-card');
78 // TRANS: Header in list form.
79 $this->element('h2', null, _('User profile'));
81 $avatarUrl = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
82 $this->element('img', array('src' => $avatarUrl,
83 'class' => 'u-photo avatar entity_depiction',
84 'width' => AVATAR_PROFILE_SIZE,
85 'height' => AVATAR_PROFILE_SIZE,
86 'alt' => $this->target->getBestName()));
88 $this->element('a', array('href' => $this->target->getUrl(),
89 'class' => 'entity_nickname p-nickname'),
90 $this->target->getNickname());
91 if ($this->target->fullname) {
92 $this->element('div', 'p-name entity_fn', $this->target->fullname);
95 if ($this->target->location) {
96 $this->element('div', 'p-locality label entity_location', $this->target->location);
99 if ($this->target->homepage) {
100 $this->element('a', array('href' => $this->target->homepage,
102 'class' => 'u-url entity_url'),
103 $this->target->homepage);
106 if ($this->target->bio) {
107 $this->element('div', 'p-note entity_note', $this->target->bio);
110 $this->elementEnd('div');
112 if (Event::handle('StartShowTagProfileForm', array($this, $this->target))) {
113 parent::showContent();
114 Event::handle('EndShowTagProfileForm', array($this, $this->target));
118 protected function getForm()
120 $class = $this->form.'Form';
121 $form = new $class($this, $this->target);
125 protected function handlePost()
127 parent::handlePost(); // Does nothing for now
129 $tagstring = $this->trimmed('tags');
130 $token = $this->trimmed('token');
132 if (Event::handle('StartSavePeopletags', array($this, $tagstring))) {
136 if (is_string($tagstring) && strlen($tagstring) > 0) {
138 $tags = preg_split('/[\s,]+/', $tagstring);
140 foreach ($tags as &$tag) {
141 $private = @$tag[0] === '.';
143 $tag = common_canonical_tag($tag);
144 if (!common_valid_profile_tag($tag)) {
145 // TRANS: Form validation error displayed if a given tag is invalid.
146 // TRANS: %s is the invalid tag.
147 $this->showForm(sprintf(_('Invalid tag: "%s".'), $tag));
151 $tag_priv[$tag] = $private;
156 $result = Profile_tag::setTags($this->scoped->id, $this->target->id, $tags, $tag_priv);
158 throw new Exception('The tags could not be saved.');
160 } catch (Exception $e) {
161 $this->showForm($e->getMessage());
165 if ($this->boolean('ajax')) {
166 $this->startHTML('text/xml;charset=utf-8');
167 $this->elementStart('head');
168 $this->element('title', null, _m('TITLE','Tags'));
169 $this->elementEnd('head');
170 $this->elementStart('body');
172 if ($this->scoped->id == $this->target->id) {
173 $widget = new SelftagsWidget($this, $this->scoped, $this->target);
176 $widget = new PeopletagsWidget($this, $this->scoped, $this->target);
180 $this->elementEnd('body');
183 // TRANS: Success message if lists are saved.
184 $this->msg = _('Lists saved.');
188 Event::handle('EndSavePeopletags', array($this, $tagstring));
192 function showPageNotice()
195 $this->element('p', 'error', $this->error);
197 $this->elementStart('div', 'instructions');
198 $this->element('p', null,
199 // TRANS: Page notice.
200 _('Use this form to add your subscribers or subscriptions to lists.'));
201 $this->elementEnd('div');