2008-07-16 12:20:45 +09:00
|
|
|
<?php
|
2009-01-21 15:20:17 +09:00
|
|
|
/**
|
2009-08-26 07:12:20 +09:00
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
2008-07-16 12:20:45 +09:00
|
|
|
*
|
2009-01-21 15:20:17 +09:00
|
|
|
* Class for deleting a notice
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
2008-07-16 12:20:45 +09:00
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-01-21 15:20:17 +09:00
|
|
|
*
|
|
|
|
* @category Personal
|
2009-08-26 07:12:20 +09:00
|
|
|
* @package StatusNet
|
2009-08-26 07:19:04 +09:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @author Sarven Capadisli <csarven@status.net>
|
2009-08-26 07:12:20 +09:00
|
|
|
* @copyright 2008 StatusNet, Inc.
|
2009-01-21 15:20:17 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-26 07:16:46 +09:00
|
|
|
* @link http://status.net/
|
2008-07-16 12:20:45 +09:00
|
|
|
*/
|
|
|
|
|
2009-08-26 23:41:36 +09:00
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) {
|
2009-01-21 15:20:17 +09:00
|
|
|
exit(1);
|
|
|
|
}
|
2008-07-16 12:20:45 +09:00
|
|
|
|
2010-11-02 00:26:23 +09:00
|
|
|
// @todo FIXME: documentation needed.
|
2009-09-28 10:10:17 +09:00
|
|
|
class DeletenoticeAction extends Action
|
2008-12-24 04:49:23 +09:00
|
|
|
{
|
2009-09-28 10:10:17 +09:00
|
|
|
var $error = null;
|
|
|
|
var $user = null;
|
|
|
|
var $notice = null;
|
|
|
|
var $profile = null;
|
|
|
|
var $user_profile = null;
|
|
|
|
|
|
|
|
function prepare($args)
|
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
|
|
|
$this->user = common_current_user();
|
2010-10-09 02:33:43 +09:00
|
|
|
|
|
|
|
if (!$this->user) {
|
2011-04-04 07:41:21 +09:00
|
|
|
// TRANS: Error message displayed when trying to perform an action that requires a logged in user.
|
2010-10-09 02:33:43 +09:00
|
|
|
common_user_error(_('Not logged in.'));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2009-09-28 10:10:17 +09:00
|
|
|
$notice_id = $this->trimmed('notice');
|
2013-08-18 20:04:58 +09:00
|
|
|
$this->notice = Notice::getKV($notice_id);
|
2009-09-28 10:10:17 +09:00
|
|
|
|
|
|
|
if (!$this->notice) {
|
2010-11-02 00:26:23 +09:00
|
|
|
// TRANS: Error message displayed trying to delete a non-existing notice.
|
2009-09-28 10:10:17 +09:00
|
|
|
common_user_error(_('No such notice.'));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->profile = $this->notice->getProfile();
|
|
|
|
$this->user_profile = $this->user->getProfile();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-21 15:20:17 +09:00
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function handle($args)
|
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
2009-09-28 10:10:17 +09:00
|
|
|
|
2010-10-09 02:33:43 +09:00
|
|
|
if ($this->notice->profile_id != $this->user_profile->id &&
|
2009-11-08 12:26:03 +09:00
|
|
|
!$this->user->hasRight(Right::DELETEOTHERSNOTICE)) {
|
2010-11-02 00:26:23 +09:00
|
|
|
// TRANS: Error message displayed trying to delete a notice that was not made by the current user.
|
2011-01-21 02:39:46 +09:00
|
|
|
common_user_error(_('Cannot delete this notice.'));
|
2009-09-28 10:10:17 +09:00
|
|
|
exit;
|
|
|
|
}
|
2009-01-21 15:20:17 +09:00
|
|
|
// XXX: Ajax!
|
2008-07-16 12:20:45 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
2009-01-21 15:20:17 +09:00
|
|
|
$this->deleteNotice();
|
2008-12-24 04:19:07 +09:00
|
|
|
} else if ($_SERVER['REQUEST_METHOD'] == 'GET') {
|
2009-01-21 15:20:17 +09:00
|
|
|
$this->showForm();
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
}
|
2008-07-16 12:20:45 +09:00
|
|
|
|
2009-01-21 15:20:17 +09:00
|
|
|
/**
|
|
|
|
* Show the page notice
|
|
|
|
*
|
|
|
|
* Shows instructions for the page
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showPageNotice()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2009-01-21 15:20:17 +09:00
|
|
|
$instr = $this->getInstructions();
|
|
|
|
$output = common_markup_to_html($instr);
|
|
|
|
|
|
|
|
$this->elementStart('div', 'instructions');
|
|
|
|
$this->raw($output);
|
|
|
|
$this->elementEnd('div');
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-07-16 12:20:45 +09:00
|
|
|
|
2009-01-21 15:20:17 +09:00
|
|
|
function getInstructions()
|
|
|
|
{
|
2010-11-02 00:26:23 +09:00
|
|
|
// TRANS: Instructions for deleting a notice.
|
2009-01-21 15:20:17 +09:00
|
|
|
return _('You are about to permanently delete a notice. ' .
|
2009-01-25 03:12:47 +09:00
|
|
|
'Once this is done, it cannot be undone.');
|
2009-01-21 15:20:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function title()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2010-11-02 00:26:23 +09:00
|
|
|
// TRANS: Page title when deleting a notice.
|
2008-12-24 04:19:07 +09:00
|
|
|
return _('Delete notice');
|
|
|
|
}
|
2008-07-16 12:20:45 +09:00
|
|
|
|
2009-01-21 15:20:17 +09:00
|
|
|
/**
|
|
|
|
* Wrapper for showing a page
|
|
|
|
*
|
|
|
|
* Stores an error and shows the page
|
|
|
|
*
|
|
|
|
* @param string $error Error, if any
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showForm($error = null)
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2009-01-21 15:20:17 +09:00
|
|
|
$this->error = $error;
|
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert delete notice form into the content
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showContent()
|
|
|
|
{
|
2009-02-06 15:27:04 +09:00
|
|
|
$this->elementStart('form', array('id' => 'form_notice_delete',
|
|
|
|
'class' => 'form_settings',
|
2009-01-25 03:12:47 +09:00
|
|
|
'method' => 'post',
|
|
|
|
'action' => common_local_url('deletenotice')));
|
2009-02-06 15:27:04 +09:00
|
|
|
$this->elementStart('fieldset');
|
2010-11-02 00:26:23 +09:00
|
|
|
// TRANS: Fieldset legend for the delete notice form.
|
2009-02-06 15:27:04 +09:00
|
|
|
$this->element('legend', null, _('Delete notice'));
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->hidden('token', common_session_token());
|
|
|
|
$this->hidden('notice', $this->trimmed('notice'));
|
2010-11-02 00:26:23 +09:00
|
|
|
// TRANS: Message for the delete notice form.
|
2009-02-06 15:27:04 +09:00
|
|
|
$this->element('p', null, _('Are you sure you want to delete this notice?'));
|
2010-04-12 04:04:07 +09:00
|
|
|
$this->submit('form_action-no',
|
|
|
|
// TRANS: Button label on the delete notice form.
|
|
|
|
_m('BUTTON','No'),
|
|
|
|
'submit form_action-primary',
|
|
|
|
'no',
|
|
|
|
// TRANS: Submit button title for 'No' when deleting a notice.
|
2011-02-17 08:39:53 +09:00
|
|
|
_('Do not delete this notice.'));
|
2010-04-12 04:04:07 +09:00
|
|
|
$this->submit('form_action-yes',
|
|
|
|
// TRANS: Button label on the delete notice form.
|
|
|
|
_m('BUTTON','Yes'),
|
|
|
|
'submit form_action-secondary',
|
|
|
|
'yes',
|
|
|
|
// TRANS: Submit button title for 'Yes' when deleting a notice.
|
2011-02-17 08:39:53 +09:00
|
|
|
_('Delete this notice.'));
|
2009-02-06 15:27:04 +09:00
|
|
|
$this->elementEnd('fieldset');
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->elementEnd('form');
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-07-16 12:20:45 +09:00
|
|
|
|
2009-01-21 15:20:17 +09:00
|
|
|
function deleteNotice()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2009-01-21 15:20:17 +09:00
|
|
|
// CSRF protection
|
2008-12-24 04:19:07 +09:00
|
|
|
$token = $this->trimmed('token');
|
2009-01-21 15:20:17 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
if (!$token || $token != common_session_token()) {
|
2011-04-04 06:47:46 +09:00
|
|
|
// TRANS: Client error displayed when the session token does not match or is not given.
|
2009-01-21 15:20:17 +09:00
|
|
|
$this->showForm(_('There was a problem with your session token. ' .
|
2010-01-10 20:26:24 +09:00
|
|
|
'Try again, please.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
2009-01-21 15:20:17 +09:00
|
|
|
|
2009-01-25 03:38:40 +09:00
|
|
|
if ($this->arg('yes')) {
|
2010-09-09 05:37:12 +09:00
|
|
|
if (Event::handle('StartDeleteOwnNotice', array($this->user, $this->notice))) {
|
|
|
|
$this->notice->delete();
|
|
|
|
Event::handle('EndDeleteOwnNotice', array($this->user, $this->notice));
|
|
|
|
}
|
2009-01-25 03:38:40 +09:00
|
|
|
}
|
2009-01-21 15:20:17 +09:00
|
|
|
|
2009-01-25 03:38:40 +09:00
|
|
|
$url = common_get_returnto();
|
2009-01-21 15:20:17 +09:00
|
|
|
|
2009-01-25 03:38:40 +09:00
|
|
|
if ($url) {
|
|
|
|
common_set_returnto(null);
|
|
|
|
} else {
|
|
|
|
$url = common_local_url('public');
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2009-01-25 03:38:40 +09:00
|
|
|
|
2009-04-02 04:30:59 +09:00
|
|
|
common_redirect($url, 303);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-07-16 12:20:45 +09:00
|
|
|
}
|