3 * Add a flag to a profile
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2009, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 if (!defined('STATUSNET')) {
35 * Action to flag a profile.
39 * @author Evan Prodromou <evan@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41 * @link http://status.net/
44 class FlagprofileAction extends Action
50 * Take arguments for running
52 * @param array $args $_REQUEST args
54 * @return boolean success flag
57 function prepare($args)
59 parent::prepare($args);
61 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
62 throw new ClientException(_('Action only accepts POST'));
65 if (!common_logged_in()) {
66 $this->clientError(_('Not logged in.'));
70 $id = $this->trimmed('flagprofileto');
73 $this->clientError(_('No profile specified.'));
77 $this->profile = Profile::staticGet('id', $id);
79 if (empty($this->profile)) {
80 $this->clientError(_('No profile with that ID.'));
84 $this->flag = $this->trimmed('flag');
86 if (empty($this->flag)) {
87 $this->flag = Profile_flag::DEFAULTFLAG;
90 $user = common_current_user();
92 assert(!empty($user)); // checked above
94 if (User_flag_profile::exists($this->profile->id,
98 $this->clientError(_('Flag already exists.'));
108 * @param array $args $_REQUEST args; handled in prepare()
113 function handle($args)
115 parent::handle($args);
117 $this->flagProfile();
122 return _('Flag profile');
126 * save the profile flag
131 function flagProfile()
133 $user = common_current_user();
135 assert(!empty($user));
136 assert(!empty($this->profile));
137 assert(!empty($this->flag));
139 $ufp = new User_flag_profile();
141 $ufp->profile_id = $this->profile->id;
142 $ufp->user_id = $user->id;
143 $ufp->flag = $this->flag;
144 $ufp->created = common_sql_now();
146 if (!$ufp->insert()) {
147 throw new ServerException(sprintf(_("Couldn't flag profile '%s' with flag '%s'."),
148 $this->profile->nickname, $this->flag));
156 // Now, gotta figure where we go back to
157 foreach ($this->args as $k => $v) {
158 if ($k == 'returnto-action') {
160 } elseif (substr($k, 0, 9) == 'returnto-') {
161 $args[substr($k, 9)] = $v;
165 common_redirect(common_local_url($action, $args), 303);