3 * StatusNet, the distributed open-source microblogging tool
5 * Class for deleting a notice
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Sarven Capadisli <csarven@status.net>
26 * @copyright 2008 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 // @todo FIXME: documentation needed.
36 class DeletenoticeAction extends Action
42 var $user_profile = null;
44 function prepare($args)
46 parent::prepare($args);
48 $this->user = common_current_user();
51 // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
52 common_user_error(_('Not logged in.'));
56 $notice_id = $this->trimmed('notice');
57 $this->notice = Notice::staticGet($notice_id);
60 // TRANS: Error message displayed trying to delete a non-existing notice.
61 common_user_error(_('No such notice.'));
65 $this->profile = $this->notice->getProfile();
66 $this->user_profile = $this->user->getProfile();
71 function handle($args)
73 parent::handle($args);
75 if ($this->notice->profile_id != $this->user_profile->id &&
76 !$this->user->hasRight(Right::DELETEOTHERSNOTICE)) {
77 // TRANS: Error message displayed trying to delete a notice that was not made by the current user.
78 common_user_error(_('Cannot delete this notice.'));
83 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
84 $this->deleteNotice();
85 } else if ($_SERVER['REQUEST_METHOD'] == 'GET') {
91 * Show the page notice
93 * Shows instructions for the page
97 function showPageNotice()
99 $instr = $this->getInstructions();
100 $output = common_markup_to_html($instr);
102 $this->elementStart('div', 'instructions');
104 $this->elementEnd('div');
107 function getInstructions()
109 // TRANS: Instructions for deleting a notice.
110 return _('You are about to permanently delete a notice. ' .
111 'Once this is done, it cannot be undone.');
116 // TRANS: Page title when deleting a notice.
117 return _('Delete notice');
121 * Wrapper for showing a page
123 * Stores an error and shows the page
125 * @param string $error Error, if any
129 function showForm($error = null)
131 $this->error = $error;
136 * Insert delete notice form into the content
140 function showContent()
142 $this->elementStart('form', array('id' => 'form_notice_delete',
143 'class' => 'form_settings',
145 'action' => common_local_url('deletenotice')));
146 $this->elementStart('fieldset');
147 // TRANS: Fieldset legend for the delete notice form.
148 $this->element('legend', null, _('Delete notice'));
149 $this->hidden('token', common_session_token());
150 $this->hidden('notice', $this->trimmed('notice'));
151 // TRANS: Message for the delete notice form.
152 $this->element('p', null, _('Are you sure you want to delete this notice?'));
153 $this->submit('form_action-no',
154 // TRANS: Button label on the delete notice form.
156 'submit form_action-primary',
158 // TRANS: Submit button title for 'No' when deleting a notice.
159 _('Do not delete this notice.'));
160 $this->submit('form_action-yes',
161 // TRANS: Button label on the delete notice form.
163 'submit form_action-secondary',
165 // TRANS: Submit button title for 'Yes' when deleting a notice.
166 _('Delete this notice.'));
167 $this->elementEnd('fieldset');
168 $this->elementEnd('form');
171 function deleteNotice()
174 $token = $this->trimmed('token');
176 if (!$token || $token != common_session_token()) {
177 // TRANS: Client error displayed when the session token does not match or is not given.
178 $this->showForm(_('There was a problem with your session token. ' .
179 'Try again, please.'));
183 if ($this->arg('yes')) {
184 if (Event::handle('StartDeleteOwnNotice', array($this->user, $this->notice))) {
185 $this->notice->delete();
186 Event::handle('EndDeleteOwnNotice', array($this->user, $this->notice));
190 $url = common_get_returnto();
193 common_set_returnto(null);
195 $url = common_local_url('public');
198 common_redirect($url, 303);