3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008-2010, StatusNet, Inc.
6 * Action to add a people tag to a user.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Shashi Gowda <connect2shashi@gmail.com>
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR . '/lib/togglepeopletag.php';
38 * Action to tag a profile with a single tag.
42 * - tagged: the ID of the profile being tagged
43 * - token: session token to prevent CSRF attacks
44 * - ajax: boolean; whether to return Ajax or full-browser results
45 * - peopletag_id: the ID of the tag being used
47 * Only works if the current user is logged in.
51 * @author Shashi Gowda <connect2shashi@gmail.com>
52 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
53 * @link http://status.net/
55 class AddpeopletagAction extends Action
62 * Check pre-requisites and instantiate attributes
64 * @param Array $args array of arguments (URL, GET, POST)
66 * @return boolean success flag
68 function prepare($args)
70 parent::prepare($args);
74 $token = $this->trimmed('token');
76 if (!$token || $token != common_session_token()) {
77 // TRANS: Client error displayed when the session token does not match or is not given.
78 $this->clientError(_('There was a problem with your session token.'.
79 ' Try again, please.'));
83 // Only for logged-in users
85 $this->user = common_current_user();
87 if (empty($this->user)) {
88 // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
89 $this->clientError(_('Not logged in.'));
93 // Profile to subscribe to
95 $tagged_id = $this->arg('tagged');
97 $this->tagged = Profile::staticGet('id', $tagged_id);
99 if (empty($this->tagged)) {
100 // TRANS: Client error displayed trying to perform an action related to a non-existing profile.
101 $this->clientError(_('No such profile.'));
105 $id = $this->arg('peopletag_id');
106 $this->peopletag = Profile_list::staticGet('id', $id);
108 if (empty($this->peopletag)) {
109 // TRANS: Client error displayed trying to reference a non-existing people tag.
110 $this->clientError(_('No such people tag.'));
114 // OMB 0.1 doesn't have a mechanism for local-server-
117 $omb01 = Remote_profile::staticGet('id', $tagged_id);
119 if (!empty($omb01)) {
120 // TRANS: Client error displayed trying to tag an OMB 0.1 remote profile.
121 $this->clientError(_('You cannot tag an OMB 0.1'.
122 ' remote profile with this action.'));
132 * Does the tagging and returns results.
134 * @param Array $args unused.
138 function handle($args)
140 // Throws exception on error
141 $ptag = Profile_tag::setTag($this->user->id, $this->tagged->id,
142 $this->peopletag->tag);
145 $user = User::staticGet('id', $id);
148 // TRANS: Client error displayed when an unknown error occurs while tagging a user.
149 // TRANS: %s is a username.
150 sprintf(_('There was an unexpected error while tagging %s.'),
153 // TRANS: Client error displayed when an unknown error occurs while tagging a user.
154 // TRANS: %s is a profile URL.
155 $this->clientError(sprintf(_('There was a problem tagging %s. ' .
156 'The remote server is probably not responding correctly, ' .
157 'please try retrying later.'), $this->profile->profileurl));
161 if ($this->boolean('ajax')) {
162 $this->startHTML('text/xml;charset=utf-8');
163 $this->elementStart('head');
164 // TRANS: Title after subscribing to a people tag.
165 $this->element('title', null, _('Subscribed'));
166 $this->elementEnd('head');
167 $this->elementStart('body');
168 $unsubscribe = new UntagButton($this, $this->tagged, $this->peopletag);
169 $unsubscribe->show();
170 $this->elementEnd('body');
171 $this->elementEnd('html');
173 $url = common_local_url('subscriptions',
174 array('nickname' => $this->user->nickname));
175 common_redirect($url, 303);