]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/deleteuser.php
Merge branch '0.9-release'
[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
44 class DeleteuserAction extends ProfileFormAction
45 {
46     var $user = null;
47
48     /**
49      * Take arguments for running
50      *
51      * @param array $args $_REQUEST args
52      *
53      * @return boolean success flag
54      */
55
56     function prepare($args)
57     {
58         if (!parent::prepare($args)) {
59             return false;
60         }
61
62         $cur = common_current_user();
63
64         assert(!empty($cur)); // checked by parent
65
66         if (!$cur->hasRight(Right::DELETEUSER)) {
67             $this->clientError(_("You cannot delete users."));
68             return false;
69         }
70
71         $this->user = User::staticGet('id', $this->profile->id);
72
73         if (empty($this->user)) {
74             $this->clientError(_("You can only delete local users."));
75             return false;
76         }
77
78         return true;
79     }
80
81     /**
82      * Handle request
83      *
84      * Shows a page with list of favorite notices
85      *
86      * @param array $args $_REQUEST args; handled in prepare()
87      *
88      * @return void
89      */
90
91     function handle($args)
92     {
93         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
94             if ($this->arg('no')) {
95                 $this->returnToArgs();
96             } elseif ($this->arg('yes')) {
97                 $this->handlePost();
98                 $this->returnToArgs();
99             } else {
100                 $this->showPage();
101             }
102         }
103     }
104
105     function showContent() {
106         $this->areYouSureForm();
107     }
108
109     function title() {
110         return _('Delete user');
111     }
112
113     function showNoticeForm() {
114         // nop
115     }
116
117     /**
118      * Confirm with user.
119      *
120      * Shows a confirmation form.
121      *
122      * @return void
123      */
124     function areYouSureForm()
125     {
126         $id = $this->profile->id;
127         $this->elementStart('form', array('id' => 'deleteuser-' . $id,
128                                            'method' => 'post',
129                                            'class' => 'form_settings form_entity_block',
130                                            'action' => common_local_url('deleteuser')));
131         $this->elementStart('fieldset');
132         $this->hidden('token', common_session_token());
133         $this->element('legend', _('Delete user'));
134         $this->element('p', null,
135                        _('Are you sure you want to delete this user? '.
136                          'This will clear all data about the user from the '.
137                          'database, without a backup.'));
138         $this->element('input', array('id' => 'deleteuserto-' . $id,
139                                       'name' => 'profileid',
140                                       'type' => 'hidden',
141                                       'value' => $id));
142         foreach ($this->args as $k => $v) {
143             if (substr($k, 0, 9) == 'returnto-') {
144                 $this->hidden($k, $v);
145             }
146         }
147         $this->submit('form_action-no', _('No'), 'submit form_action-primary', 'no', _("Do not block this user"));
148         $this->submit('form_action-yes', _('Yes'), 'submit form_action-secondary', 'yes', _('Delete this user'));
149         $this->elementEnd('fieldset');
150         $this->elementEnd('form');
151     }
152
153     /**
154      * Actually delete a user.
155      *
156      * @return void
157      */
158
159     function handlePost()
160     {
161         $this->user->delete();
162     }
163 }
164