]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/deleteuser.php
Merge branch 'master' into social-master
[quix0rs-gnu-social.git] / actions / deleteuser.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Action class to delete a user
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  Action
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Delete a user
36  *
37  * @category Action
38  * @package  StatusNet
39  * @author   Evan Prodromou <evan@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41  * @link     http://status.net/
42  */
43 class DeleteuserAction extends ProfileFormAction
44 {
45     var $user = null;
46
47     /**
48      * Take arguments for running
49      *
50      * @param array $args $_REQUEST args
51      *
52      * @return boolean success flag
53      */
54     function prepare(array $args=array())
55     {
56         if (!parent::prepare($args)) {
57             return false;
58         }
59
60         $cur = common_current_user();
61
62         assert(!empty($cur)); // checked by parent
63
64         if (!$cur->hasRight(Right::DELETEUSER)) {
65             // TRANS: Client error displayed when trying to delete a user without having the right to delete users.
66             $this->clientError(_('You cannot delete users.'));
67         }
68
69         $this->user = User::getKV('id', $this->profile->id);
70
71         if (empty($this->user)) {
72             // TRANS: Client error displayed when trying to delete a non-local user.
73             $this->clientError(_('You can only delete local users.'));
74         }
75
76         return true;
77     }
78
79     /**
80      * Handle request
81      *
82      * Shows a page with list of favorite notices
83      *
84      * @param array $args $_REQUEST args; handled in prepare()
85      *
86      * @return void
87      */
88     function handle(array $args=array())
89     {
90         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
91             if ($this->arg('no')) {
92                 $this->returnToPrevious();
93             } elseif ($this->arg('yes')) {
94                 $this->handlePost();
95                 $this->returnToPrevious();
96             } else {
97                 $this->showPage();
98             }
99         }
100     }
101
102     function showContent() {
103         $this->areYouSureForm();
104     }
105
106     function title() {
107         // TRANS: Title of delete user page.
108         return _m('TITLE','Delete user');
109     }
110
111     function showNoticeForm() {
112         // nop
113     }
114
115     /**
116      * Confirm with user.
117      *
118      * Shows a confirmation form.
119      *
120      * @return void
121      */
122     function areYouSureForm()
123     {
124         $id = $this->profile->id;
125         $this->elementStart('form', array('id' => 'deleteuser-' . $id,
126                                            'method' => 'post',
127                                            'class' => 'form_settings form_entity_block',
128                                            'action' => common_local_url('deleteuser')));
129         $this->elementStart('fieldset');
130         $this->hidden('token', common_session_token());
131         // TRANS: Fieldset legend on delete user page.
132         $this->element('legend', _('Delete user'));
133         if (Event::handle('StartDeleteUserForm', array($this, $this->user))) {
134             $this->element('p', null,
135                            // TRANS: Information text to request if a user is certain that the described action has to be performed.
136                            _('Are you sure you want to delete this user? '.
137                              'This will clear all data about the user from the '.
138                              'database, without a backup.'));
139             $this->element('input', array('id' => 'deleteuserto-' . $id,
140                                           'name' => 'profileid',
141                                           'type' => 'hidden',
142                                           'value' => $id));
143             foreach ($this->args as $k => $v) {
144                 if (substr($k, 0, 9) == 'returnto-') {
145                     $this->hidden($k, $v);
146                 }
147             }
148             Event::handle('EndDeleteUserForm', array($this, $this->user));
149         }
150         $this->submit('form_action-no',
151                       // TRANS: Button label on the delete user form.
152                       _m('BUTTON','No'),
153                       'submit form_action-primary',
154                       'no',
155                       // TRANS: Submit button title for 'No' when deleting a user.
156                       _('Do not delete this user.'));
157         $this->submit('form_action-yes',
158                       // TRANS: Button label on the delete user form.
159                       _m('BUTTON','Yes'),
160                       'submit form_action-secondary',
161                       'yes',
162                       // TRANS: Submit button title for 'Yes' when deleting a user.
163                       _('Delete this user.'));
164         $this->elementEnd('fieldset');
165         $this->elementEnd('form');
166     }
167
168     /**
169      * Actually delete a user.
170      *
171      * @return void
172      */
173     function handlePost()
174     {
175         if (Event::handle('StartDeleteUser', array($this, $this->user))) {
176             // Mark the account as deleted and shove low-level deletion tasks
177             // to background queues. Removing a lot of posts can take a while...
178             if (!$this->user->hasRole(Profile_role::DELETED)) {
179                 $this->user->grantRole(Profile_role::DELETED);
180             }
181
182             $qm = QueueManager::get();
183             $qm->enqueue($this->user, 'deluser');
184
185             Event::handle('EndDeleteUser', array($this, $this->user));
186         }
187     }
188 }