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/
56 class AddpeopletagAction extends Action
63 * Check pre-requisites and instantiate attributes
65 * @param Array $args array of arguments (URL, GET, POST)
67 * @return boolean success flag
70 function prepare($args)
72 parent::prepare($args);
76 $token = $this->trimmed('token');
78 if (!$token || $token != common_session_token()) {
79 $this->clientError(_('There was a problem with your session token.'.
80 ' Try again, please.'));
84 // Only for logged-in users
86 $this->user = common_current_user();
88 if (empty($this->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 $this->clientError(_('No such profile.'));
104 $id = $this->arg('peopletag_id');
105 $this->peopletag = Profile_list::staticGet('id', $id);
107 if (empty($this->peopletag)) {
108 $this->clientError(_('No such peopletag.'));
112 // OMB 0.1 doesn't have a mechanism for local-server-
115 $omb01 = Remote_profile::staticGet('id', $tagged_id);
117 if (!empty($omb01)) {
118 $this->clientError(_('You cannot tag an OMB 0.1'.
119 ' remote profile with this action.'));
129 * Does the tagging and returns results.
131 * @param Array $args unused.
136 function handle($args)
139 // Throws exception on error
140 $ptag = Profile_tag::setTag($this->user->id, $this->tagged->id,
141 $this->peopletag->tag);
144 $user = User::staticGet('id', $id);
147 sprintf(_('There was an unexpected error while tagging %s'),
150 $this->clientError(sprintf(_('There was a problem tagging %s.' .
151 'The remote server is probably not responding correctly, ' .
152 'please try retrying later.'), $this->profile->profileurl));
156 if ($this->boolean('ajax')) {
157 $this->startHTML('text/xml;charset=utf-8');
158 $this->elementStart('head');
159 $this->element('title', null, _('Subscribed'));
160 $this->elementEnd('head');
161 $this->elementStart('body');
162 $unsubscribe = new UntagButton($this, $this->tagged, $this->peopletag);
163 $unsubscribe->show();
164 $this->elementEnd('body');
165 $this->elementEnd('html');
167 $url = common_local_url('subscriptions',
168 array('nickname' => $this->user->nickname));
169 common_redirect($url, 303);