]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/deletenotice.php
change LACONICA to STATUSNET
[quix0rs-gnu-social.git] / actions / deletenotice.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Class for deleting a notice
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Personal
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2008 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/deleteaction.php';
36
37 class DeletenoticeAction extends DeleteAction
38 {
39     var $error = null;
40
41     function handle($args)
42     {
43         parent::handle($args);
44         // XXX: Ajax!
45
46         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
47             $this->deleteNotice();
48         } else if ($_SERVER['REQUEST_METHOD'] == 'GET') {
49             $this->showForm();
50         }
51     }
52
53     /**
54      * Show the page notice
55      *
56      * Shows instructions for the page
57      *
58      * @return void
59      */
60
61     function showPageNotice()
62     {
63         $instr  = $this->getInstructions();
64         $output = common_markup_to_html($instr);
65
66         $this->elementStart('div', 'instructions');
67         $this->raw($output);
68         $this->elementEnd('div');
69     }
70
71     function getInstructions()
72     {
73         return _('You are about to permanently delete a notice. ' .
74                  'Once this is done, it cannot be undone.');
75     }
76
77     function title()
78     {
79         return _('Delete notice');
80     }
81
82     /**
83      * Wrapper for showing a page
84      *
85      * Stores an error and shows the page
86      *
87      * @param string $error Error, if any
88      *
89      * @return void
90      */
91
92     function showForm($error = null)
93     {
94         $this->error = $error;
95         $this->showPage();
96     }
97
98     /**
99      * Insert delete notice form into the content
100      *
101      * @return void
102      */
103
104     function showContent()
105     {
106         $this->elementStart('form', array('id' => 'form_notice_delete',
107                                           'class' => 'form_settings',
108                                           'method' => 'post',
109                                           'action' => common_local_url('deletenotice')));
110         $this->elementStart('fieldset');
111         $this->element('legend', null, _('Delete notice'));
112         $this->hidden('token', common_session_token());
113         $this->hidden('notice', $this->trimmed('notice'));
114         $this->element('p', null, _('Are you sure you want to delete this notice?'));
115         $this->submit('form_action-no', _('No'), 'submit form_action-primary', 'no', _("Do not delete this notice"));
116         $this->submit('form_action-yes', _('Yes'), 'submit form_action-secondary', 'yes', _('Delete this notice'));
117         $this->elementEnd('fieldset');
118         $this->elementEnd('form');
119     }
120
121     function deleteNotice()
122     {
123         // CSRF protection
124         $token = $this->trimmed('token');
125
126         if (!$token || $token != common_session_token()) {
127             $this->showForm(_('There was a problem with your session token. ' .
128                               ' Try again, please.'));
129             return;
130         }
131
132         if ($this->arg('yes')) {
133             $this->notice->delete();
134         }
135
136         $url = common_get_returnto();
137
138         if ($url) {
139             common_set_returnto(null);
140         } else {
141             $url = common_local_url('public');
142         }
143
144         common_redirect($url, 303);
145     }
146 }