]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/deleteprofile.php
move opening brace of class declaration to next line
[quix0rs-gnu-social.git] / actions / deleteprofile.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 class DeleteprofileAction extends Action
23 {
24     function handle($args)
25     {
26         parent::handle($args);
27         $this->server_error(_('Code not yet ready.'));
28         return;
29         if ('POST' === $_SERVER['REQUEST_METHOD']) {
30             $this->handle_post();
31         }
32         else if ('GET' === $_SERVER['REQUEST_METHOD']) {
33             $this->show_form();
34         }
35     }
36
37     function get_instructions()
38     {
39         return _('Export and delete your user information.');
40     }
41
42     function form_header($title, $msg=null, $success=false)
43     {
44         common_show_header($title,
45                            null,
46                            array($msg, $success),
47                            array($this, 'show_top'));
48     }
49
50     function show_feeds_list($feeds)
51     {
52         common_element_start('div', array('class' => 'feedsdel'));
53         common_element('p', null, 'Feeds:');
54         common_element_start('ul', array('class' => 'xoxo'));
55
56         foreach ($feeds as $key => $value) {
57             $this->common_feed_item($feeds[$key]);
58         }
59         common_element_end('ul');
60         common_element_end('div');
61     }
62
63     //TODO move to common.php (and retrace its origin)
64     function common_feed_item($feed)
65     {
66         $user = common_current_user();
67         $nickname = $user->nickname;
68
69         switch($feed['item']) {
70             case 'notices': default:
71                 $feed_classname = $feed['type'];
72                 $feed_mimetype = "application/".$feed['type']."+xml";
73                 $feed_title = "$nickname's ".$feed['version']." notice feed";
74                 $feed['textContent'] = "RSS";
75                 break;
76
77             case 'foaf':
78                 $feed_classname = "foaf";
79                 $feed_mimetype = "application/".$feed['type']."+xml";
80                 $feed_title = "$nickname's FOAF file";
81                 $feed['textContent'] = "FOAF";
82                 break;
83         }
84         common_element_start('li');
85         common_element('a', array('href' => $feed['href'],
86                                   'class' => $feed_classname,
87                                   'type' => $feed_mimetype,
88                                   'title' => $feed_title),
89                             $feed['textContent']);
90         common_element_end('li');
91     }
92
93     function show_form($msg=null, $success=false)
94     {
95         $this->form_header(_('Delete my account'), $msg, $success);
96         common_element('h2', null, _('Delete my account confirmation'));
97         $this->show_confirm_delete_form();
98         common_show_footer();
99     }
100
101     function show_confirm_delete_form()
102     {
103         $user = common_current_user();
104         $notices = DB_DataObject::factory('notice');
105         $notices->profile_id = $user->id;
106         $notice_count = (int) $notices->count();
107
108         common_element_start('form', array('method' => 'POST',
109                                            'id' => 'delete',
110                                            'action' =>
111                                            common_local_url('deleteprofile')));
112
113         common_hidden('token', common_session_token());
114         common_element('p', null, "Last chance to copy your notices and contacts by saving the two links below before deleting your account. Be careful, this operation cannot be undone.");
115
116         $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
117                                               'type' => 'rss',
118                                               'version' => 'RSS 1.0',
119                                               'item' => 'notices'),
120                                      1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
121                                               'type' => 'rdf',
122                                               'version' => 'FOAF',
123                                               'item' => 'foaf')));
124
125         common_checkbox('confirmation', _('Check if you are sure you want to delete your account.'));
126
127         common_submit('deleteaccount', _('Delete my account'));
128         common_element_end('form');
129     }
130
131     function handle_post()
132     {
133         # CSRF protection
134         $token = $this->trimmed('token');
135         if (!$token || $token != common_session_token()) {
136             $this->show_form(_('There was a problem with your session token. Try again, please.'));
137             return;
138         }
139
140         if ($this->arg('deleteaccount') && $this->arg('confirmation')) {
141             $this->delete_account();
142         }
143         $this->show_form();
144     }
145
146     function delete_account()
147     {
148         $user = common_current_user();
149         assert(!is_null($user)); # should already be checked
150
151         // deleted later through the profile
152         /*
153         $avatar = new Avatar;
154         $avatar->profile_id = $user->id;
155         $n_avatars_deleted = $avatar->delete();
156         */
157
158         $fave = new Fave;
159         $fave->user_id = $user->id;
160         $n_faves_deleted = $fave->delete();
161
162         $confirmation = new Confirm_address;
163         $confirmation->user_id = $user->id;
164         $n_confirmations_deleted = $confirmation->delete();
165
166         // TODO foreign stuff...
167
168         $invitation = new Invitation;
169         $invitation->user_id = $user->id;
170         $n_invitations_deleted = $invitation->delete();
171
172         $message_from = new Message;
173         $message_from->from_profile = $user->id;
174         $n_messages_from_deleted = $message_from->delete();
175
176         $message_to = new Message;
177         $message_to->to_profile = $user->id;
178         $n_messages_to_deleted = $message_to->delete();
179
180         $notice_inbox = new Notice_inbox;
181         $notice_inbox->user_id = $user->id;
182         $n_notices_inbox_deleted = $notice_inbox->delete();
183
184         $profile_tagger = new Profile_tag;
185         $profile_tagger->tagger = $user->id;
186         $n_profiles_tagger_deleted = $profile_tagger->delete();
187
188         $profile_tagged = new Profile_tag;
189         $profile_tagged->tagged = $user->id;
190         $n_profiles_tagged_deleted = $profile_tagged->delete();
191
192         $remember_me = new Remember_me;
193         $remember_me->user_id = $user->id;
194         $n_remember_mes_deleted = $remember_me->delete();
195
196         $reply= new Reply;
197         $reply->profile_id = $user->id;
198         $n_replies_deleted = $reply->delete();
199
200         // FIXME we're not removings replies to deleted notices.
201         //       notices should take care of that themselves.
202
203         $notice = new Notice;
204         $notice->profile_id = $user->id;
205         $n_notices_deleted = $notice->delete();
206
207         $subscriber = new Subscription;
208         $subscriber->subscriber = $user->id;
209         $n_subscribers_deleted = $subscriber->delete();
210
211         $subscribed = new Subscription;
212         $subscribed->subscribed = $user->id;
213         $n_subscribeds_deleted = $subscribed->delete();
214
215         $user_openid = new User_openid;
216         $user_openid->user_id = $user->id;
217         $n_user_openids_deleted = $user_openid->delete();
218
219         $profile = new Profile;
220         $profile->id = $user->id;
221         $profile->delete_avatars();
222         $n_profiles_deleted = $profile->delete();
223         $n_users_deleted = $user->delete();
224
225         // logout and redirect to public
226         common_set_user(null);
227         common_real_login(false); # not logged in
228         common_forgetme(); # don't log back in!
229         common_redirect(common_local_url('public'));
230     }
231
232     function show_top($arr)
233     {
234         $msg = $arr[0];
235         $success = $arr[1];
236         if ($msg) {
237             $this->message($msg, $success);
238         } else {
239             $inst = $this->get_instructions();
240             $output = common_markup_to_html($inst);
241             common_element_start('div', 'instructions');
242             common_raw($output);
243             common_element_end('div');
244         }
245         $this->settings_menu();
246     }
247
248     function settings_menu()
249     {
250         # action => array('prompt', 'title')
251         $menu =
252           array('profilesettings' =>
253                 array(_('Profile'),
254                       _('Change your profile settings')),
255                 'emailsettings' =>
256                 array(_('Email'),
257                       _('Change email handling')),
258                 'openidsettings' =>
259                 array(_('OpenID'),
260                       _('Add or remove OpenIDs')),
261                 'smssettings' =>
262                 array(_('SMS'),
263                       _('Updates by SMS')),
264                 'imsettings' =>
265                 array(_('IM'),
266                       _('Updates by instant messenger (IM)')),
267                 'twittersettings' =>
268                 array(_('Twitter'),
269                       _('Twitter integration options')),
270                 'othersettings' =>
271                 array(_('Other'),
272                       _('Other options')));
273
274         $action = $this->trimmed('action');
275         common_element_start('ul', array('id' => 'nav_views'));
276         foreach ($menu as $menuaction => $menudesc) {
277             if ($menuaction == 'imsettings' &&
278                 !common_config('xmpp', 'enabled')) {
279                 continue;
280             }
281             common_menu_item(common_local_url($menuaction),
282                     $menudesc[0],
283                     $menudesc[1],
284                     $action == $menuaction);
285         }
286         common_element_end('ul');
287     }
288 }
289