]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/deletenotice.php
f2c040a5a9a179a33610a7e465eaea6783d4d970
[quix0rs-gnu-social.git] / actions / deletenotice.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/deleteaction.php');
23
24 class DeletenoticeAction extends DeleteAction {
25         function handle($args) {
26                 parent::handle($args);
27                 # XXX: Ajax!
28
29                 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
30                         $this->delete_notice();
31                 } else if ($_SERVER['REQUEST_METHOD'] == 'GET') {
32                         $this->show_form();
33                 }
34         }
35
36         function get_instructions() {
37                 return _('You are about to permanently delete a notice.  Once this is done, it cannot be undone.');
38         }
39
40         function get_title() {
41                 return _('Delete notice');
42         }
43
44         function show_form($error=NULL) {
45                 $user = common_current_user();
46
47                 common_show_header($this->get_title(), array($this, 'show_header'), NULL,
48                                                    array($this, 'show_top'));
49                 common_element_start('form', array('id' => 'notice_delete_form',
50                                                                    'method' => 'post',
51                                                                    'action' => common_local_url('deletenotice')));
52                 common_hidden('notice', $this->trimmed('notice'));
53                 common_element_start('p');
54                 common_element('span', array('id' => 'confirmation_text'), _('Are you sure you want to delete this notice?'));
55
56                 common_element('input', array('id' => 'submit_no',
57                                                   'name' => 'submit',
58                                                   'type' => 'submit',
59                                                   'value' => _('No')));
60                 common_element('input', array('id' => 'submit_yes',
61                                                   'name' => 'submit',
62                                                   'type' => 'submit',
63                                                   'value' => _('Yes')));
64                 common_element_end('p');
65                 common_element_end('form');
66                 common_show_footer();
67         }
68
69         function delete_notice() {
70                 $url = common_get_returnto();
71                 $confirmed = $this->trimmed('submit');
72                 if ($confirmed == _('Yes')) {
73                         $user = common_current_user();
74                         $notice_id = $this->trimmed('notice');
75                         $notice = Notice::staticGet($notice_id);
76                         $replies = new Reply;
77                         $replies->get('notice_id', $notice_id);
78
79                         common_dequeue_notice($notice);
80                         $replies->delete();
81                         $notice->delete();
82                 } else {
83                         if ($url) {
84                                 common_set_returnto(NULL);
85                         } else {
86                                 $url = common_local_url('public');
87                         }
88                 }
89                 common_redirect($url);
90         }
91 }