]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/deletenotice.php
Merge branch '0.9.x' into 1.0.x
[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') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 class DeletenoticeAction extends Action
36 {
37     var $error        = null;
38     var $user         = null;
39     var $notice       = null;
40     var $profile      = null;
41     var $user_profile = null;
42
43     function prepare($args)
44     {
45         parent::prepare($args);
46
47         $this->user   = common_current_user();
48
49         if (!$this->user) {
50             common_user_error(_('Not logged in.'));
51             exit;
52         }
53
54         $notice_id    = $this->trimmed('notice');
55         $this->notice = Notice::staticGet($notice_id);
56
57         if (!$this->notice) {
58             common_user_error(_('No such notice.'));
59             exit;
60         }
61
62         $this->profile      = $this->notice->getProfile();
63         $this->user_profile = $this->user->getProfile();
64
65         return true;
66     }
67
68     function handle($args)
69     {
70         parent::handle($args);
71
72         if ($this->notice->profile_id != $this->user_profile->id &&
73                    !$this->user->hasRight(Right::DELETEOTHERSNOTICE)) {
74             common_user_error(_('Can\'t delete this notice.'));
75             exit;
76         }
77         // XXX: Ajax!
78
79         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
80             $this->deleteNotice();
81         } else if ($_SERVER['REQUEST_METHOD'] == 'GET') {
82             $this->showForm();
83         }
84     }
85
86     /**
87      * Show the page notice
88      *
89      * Shows instructions for the page
90      *
91      * @return void
92      */
93
94     function showPageNotice()
95     {
96         $instr  = $this->getInstructions();
97         $output = common_markup_to_html($instr);
98
99         $this->elementStart('div', 'instructions');
100         $this->raw($output);
101         $this->elementEnd('div');
102     }
103
104     function getInstructions()
105     {
106         return _('You are about to permanently delete a notice. ' .
107                  'Once this is done, it cannot be undone.');
108     }
109
110     function title()
111     {
112         return _('Delete notice');
113     }
114
115     /**
116      * Wrapper for showing a page
117      *
118      * Stores an error and shows the page
119      *
120      * @param string $error Error, if any
121      *
122      * @return void
123      */
124
125     function showForm($error = null)
126     {
127         $this->error = $error;
128         $this->showPage();
129     }
130
131     /**
132      * Insert delete notice form into the content
133      *
134      * @return void
135      */
136
137     function showContent()
138     {
139         $this->elementStart('form', array('id' => 'form_notice_delete',
140                                           'class' => 'form_settings',
141                                           'method' => 'post',
142                                           'action' => common_local_url('deletenotice')));
143         $this->elementStart('fieldset');
144         $this->element('legend', null, _('Delete notice'));
145         $this->hidden('token', common_session_token());
146         $this->hidden('notice', $this->trimmed('notice'));
147         $this->element('p', null, _('Are you sure you want to delete this notice?'));
148         $this->submit('form_action-no',
149                       // TRANS: Button label on the delete notice form.
150                       _m('BUTTON','No'),
151                       'submit form_action-primary',
152                       'no',
153                       // TRANS: Submit button title for 'No' when deleting a notice.
154                       _("Do not delete this notice"));
155         $this->submit('form_action-yes',
156                       // TRANS: Button label on the delete notice form.
157                       _m('BUTTON','Yes'),
158                       'submit form_action-secondary',
159                       'yes',
160                       // TRANS: Submit button title for 'Yes' when deleting a notice.
161                       _('Delete this notice'));
162         $this->elementEnd('fieldset');
163         $this->elementEnd('form');
164     }
165
166     function deleteNotice()
167     {
168         // CSRF protection
169         $token = $this->trimmed('token');
170
171         if (!$token || $token != common_session_token()) {
172             $this->showForm(_('There was a problem with your session token. ' .
173                               'Try again, please.'));
174             return;
175         }
176
177         if ($this->arg('yes')) {
178             if (Event::handle('StartDeleteOwnNotice', array($this->user, $this->notice))) {
179                 $this->notice->delete();
180                 Event::handle('EndDeleteOwnNotice', array($this->user, $this->notice));
181             }
182         }
183
184         $url = common_get_returnto();
185
186         if ($url) {
187             common_set_returnto(null);
188         } else {
189             $url = common_local_url('public');
190         }
191
192         common_redirect($url, 303);
193     }
194 }