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