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::getKV('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::getKV('id', $id);
108 if (empty($this->peopletag)) {
109 // TRANS: Client error displayed trying to reference a non-existing list.
110 $this->clientError(_('No such list.'));
120 * Does the tagging and returns results.
122 * @param Array $args unused.
126 function handle($args)
128 // Throws exception on error
129 $ptag = Profile_tag::setTag($this->user->id, $this->tagged->id,
130 $this->peopletag->tag);
133 $user = User::getKV('id', $id);
136 // TRANS: Client error displayed when an unknown error occurs when adding a user to a list.
137 // TRANS: %s is a username.
138 sprintf(_('There was an unexpected error while listing %s.'),
141 // TRANS: Client error displayed when an unknown error occurs when adding a user to a list.
142 // TRANS: %s is a profile URL.
143 $this->clientError(sprintf(_('There was a problem listing %s. ' .
144 'The remote server is probably not responding correctly. ' .
145 'Please try retrying later.'), $this->profile->profileurl));
149 if ($this->boolean('ajax')) {
150 $this->startHTML('text/xml;charset=utf-8');
151 $this->elementStart('head');
152 // TRANS: Title after adding a user to a list.
153 $this->element('title', null, _m('TITLE','Listed'));
154 $this->elementEnd('head');
155 $this->elementStart('body');
156 $unsubscribe = new UntagButton($this, $this->tagged, $this->peopletag);
157 $unsubscribe->show();
158 $this->elementEnd('body');
161 $url = common_local_url('subscriptions',
162 array('nickname' => $this->user->nickname));
163 common_redirect($url, 303);