From faa3933fbb54d0fc4a12145bd0aefa899db30dea Mon Sep 17 00:00:00 2001 From: "matthew.gregg" Date: Tue, 15 Jul 2008 23:20:45 -0400 Subject: Added notice deletion http://laconi.ca/PITS/00045 Removes selected notice and any replies that reference it. Attempts to de-queue anything pending. This patch does not archive notices. darcs-hash:20080716032045-982e4-a0b5d37ecfa84796f1681dda54110094ad1424c6.gz --- actions/deletenotice.php | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 actions/deletenotice.php (limited to 'actions/deletenotice.php') diff --git a/actions/deletenotice.php b/actions/deletenotice.php new file mode 100644 index 000000000..06c1bf27e --- /dev/null +++ b/actions/deletenotice.php @@ -0,0 +1,92 @@ +. + */ + +if (!defined('LACONICA')) { exit(1); } + +require_once(INSTALLDIR.'/lib/deleteaction.php'); + +class DeletenoticeAction extends DeleteAction { + function handle($args) { + parent::handle($args); + # XXX: Ajax! + + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->delete_notice(); + } else if ($_SERVER['REQUEST_METHOD'] == 'GET') { + $this->show_form(); + } + } + + function get_instructions() { + return _('You are about to permanently delete a notice. Once this is done, it cannot be undone.'); + } + + function get_title() { + return _('Delete notice'); + } + + function show_form($error=NULL) { + $user = common_current_user(); + + common_show_header($this->get_title(), array($this, 'show_header'), array($q, $error), + array($this, 'show_top')); + common_element_start('form', array('id' => 'notice_delete_form', + 'method' => 'post', + 'action' => common_local_url('deletenotice'))); + common_hidden('notice', $this->trimmed(notice)); + common_element_start('p'); + common_element('span', array('id' => 'confirmation_text'),_('Are you sure you want to delete this notice?')); + + common_element('input', array('id' => 'submit_no', + 'name' => 'submit', + 'type' => 'submit', + 'value' => _('No'))); + common_element('input', array('id' => 'submit_yes', + 'name' => 'submit', + 'type' => 'submit', + 'value' => _('Yes'))); + common_element_end('p'); + common_element_end('form'); + common_show_footer(); + } + + function delete_notice() { + $url = common_get_returnto(); + $confirmed = $this->trimmed('submit'); + if ($confirmed == 'Yes') { + $user = common_current_user(); + $notice_id = $this->trimmed('notice'); + $notice = Notice::staticGet($notice_id); + $replies = new Reply; + $replies->get('notice_id', $notice_id); + + common_dequeue_notice($notice); + $replies->delete(); + $notice->delete(); + } + else { + if ($url) { + common_set_returnto(NULL); + } else { + $url = common_local_url('public'); + } + } + common_redirect($url); + } +} -- cgit v1.2.3-54-g00ecf