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/
43 class FlagprofileAction extends ProfileFormAction
46 * Take arguments for running
48 * @param array $args $_REQUEST args
50 * @return boolean success flag
52 function prepare($args)
54 if (!parent::prepare($args)) {
58 $user = common_current_user();
60 assert(!empty($user)); // checked above
61 assert(!empty($this->profile)); // checked above
63 if (User_flag_profile::exists($this->profile->id,
65 // TRANS: Client error when setting flag that has already been set for a profile.
66 $this->clientError(_m('Flag already exists.'));
76 * Overriding the base Action's handle() here to deal check
77 * for Ajax and return an HXR response if necessary
79 * @param array $args $_REQUEST args; handled in prepare()
83 function handle($args)
85 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
87 if (!$this->boolean('ajax')) {
88 $this->returnToPrevious();
100 $user = common_current_user();
102 assert(!empty($user));
103 assert(!empty($this->profile));
105 // throws an exception on error
107 User_flag_profile::create($user->id, $this->profile->id);
109 if ($this->boolean('ajax')) {
110 $this->ajaxResults();
115 * Return results as AJAX message
119 function ajaxResults()
121 header('Content-Type: text/xml;charset=utf-8');
122 $this->xw->startDocument('1.0', 'UTF-8');
123 $this->elementStart('html');
124 $this->elementStart('head');
125 // TRANS: AJAX form title for a flagged profile.
126 $this->element('title', null, _m('Flagged for review'));
127 $this->elementEnd('head');
128 $this->elementStart('body');
129 // TRANS: Body text for AJAX form when a profile has been flagged for review.
130 $this->element('p', 'flagged', _m('Flagged'));
131 $this->elementEnd('body');
132 $this->elementEnd('html');