]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/deletenotice.php
Merge branch 'master' into devel
[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 {
26     function handle($args)
27     {
28         parent::handle($args);
29         # XXX: Ajax!
30
31         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
32             $this->delete_notice();
33         } else if ($_SERVER['REQUEST_METHOD'] == 'GET') {
34             $this->show_form();
35         }
36     }
37
38     function get_instructions()
39     {
40         return _('You are about to permanently delete a notice.  Once this is done, it cannot be undone.');
41     }
42
43     function get_title()
44     {
45         return _('Delete notice');
46     }
47
48     function show_form($error=null)
49     {
50         $user = common_current_user();
51
52         common_show_header($this->get_title(), array($this, 'show_header'), $error,
53                            array($this, 'show_top'));
54         common_element_start('form', array('id' => 'notice_delete_form',
55                                    'method' => 'post',
56                                    'action' => common_local_url('deletenotice')));
57         common_hidden('token', common_session_token());
58         common_hidden('notice', $this->trimmed('notice'));
59         common_element_start('p');
60         common_element('span', array('id' => 'confirmation_text'), _('Are you sure you want to delete this notice?'));
61
62         common_element('input', array('id' => 'submit_no',
63                           'name' => 'submit',
64                           'type' => 'submit',
65                           'value' => _('No')));
66         common_element('input', array('id' => 'submit_yes',
67                           'name' => 'submit',
68                           'type' => 'submit',
69                           'value' => _('Yes')));
70         common_element_end('p');
71         common_element_end('form');
72         common_show_footer();
73     }
74
75     function delete_notice()
76     {
77         # CSRF protection
78         $token = $this->trimmed('token');
79         if (!$token || $token != common_session_token()) {
80             $this->show_form(_('There was a problem with your session token. Try again, please.'));
81             return;
82         }
83         $url = common_get_returnto();
84         $confirmed = $this->trimmed('submit');
85         if ($confirmed == _('Yes')) {
86             $user = common_current_user();
87             $notice_id = $this->trimmed('notice');
88             $notice = Notice::staticGet($notice_id);
89             $replies = new Reply;
90             $replies->get('notice_id', $notice_id);
91
92             common_dequeue_notice($notice);
93             if (common_config('memcached', 'enabled')) {
94                 $notice->blowSubsCache();
95             }
96             $replies->delete();
97             $notice->delete();
98         } else {
99             if ($url) {
100                 common_set_returnto(null);
101             } else {
102                 $url = common_local_url('public');
103             }
104         }
105         common_redirect($url);
106     }
107 }