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