]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/deleteprofile.php
moving delete profile to its own space.
[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 require_once(INSTALLDIR.'/lib/settingsaction.php');
23
24 class DeleteprofileAction extends Action { // was SettingsAction...
25
26         function get_instructions() {
27                 return _('You can update your personal profile info here '.
28                                   'so people know more about you.');
29         }
30
31         function show_form($msg=NULL, $success=false) {
32                 $this->form_header(_('Delete my account'), $msg, $success);
33                 common_element('h2', NULL, _('Delete my account'));
34                 $this->show_delete_form();
35                 common_show_footer();
36         }
37
38         function handle_post() {
39
40                 # CSRF protection
41
42                 $token = $this->trimmed('token');
43                 if (!$token || $token != common_session_token()) {
44                         $this->show_form(_('There was a problem with your session token. Try again, please.'));
45                         return;
46                 }
47
48                 if ($this->arg('deleteaccount')) {
49                         $this->delete_account_confirmation();
50                 }
51
52         }
53
54         function show_feeds_list($feeds) {
55                 common_element_start('div', array('class' => 'feedsdel'));
56                 common_element('p', null, 'Feeds:');
57                 common_element_start('ul', array('class' => 'xoxo'));
58
59                 foreach ($feeds as $key => $value) {
60                         $this->common_feed_item($feeds[$key]);
61                 }
62                 common_element_end('ul');
63                 common_element_end('div');
64         }
65
66     //TODO move to common.php (and retrace its origin)
67         function common_feed_item($feed) {
68         $user = common_current_user();
69                 $nickname = $user->nickname;
70
71                 switch($feed['item']) {
72                         case 'notices': default:
73                                 $feed_classname = $feed['type'];
74                                 $feed_mimetype = "application/".$feed['type']."+xml";
75                                 $feed_title = "$nickname's ".$feed['version']." notice feed";
76                                 $feed['textContent'] = "RSS";
77                                 break;
78
79                         case 'foaf':
80                                 $feed_classname = "foaf";
81                                 $feed_mimetype = "application/".$feed['type']."+xml";
82                                 $feed_title = "$nickname's FOAF file";
83                                 $feed['textContent'] = "FOAF";
84                                 break;
85                 }
86                 common_element_start('li');
87                 common_element('a', array('href' => $feed['href'],
88                                                                   'class' => $feed_classname,
89                                                                   'type' => $feed_mimetype,
90                                                                   'title' => $feed_title),
91                                                         $feed['textContent']);
92                 common_element_end('li');
93         }
94
95         function show_delete_form() {
96                 $user = common_current_user();
97         $notices = DB_DataObject::factory('notice');
98         $notices->profile_id = $user->id;
99         $notice_count = (int) $notices->count();
100
101                 common_element_start('form', array('method' => 'POST',
102                                                                                    'id' => 'delete',
103                                                                                    'action' =>
104                                                                                    common_local_url('profilesettings')));
105
106                 common_hidden('token', common_session_token());
107         common_element('p', null, "You can copy your notices and contacts by saving the two links belowxbefore deleting your account. Be careful, this operation cannot be undone.");
108
109
110                 $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)), 
111                                                                                           'type' => 'rss',
112                                                                                           'version' => 'RSS 1.0',
113                                                                                           'item' => 'notices'),
114                                                                          1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
115                                                                                           'type' => 'rdf',
116                                                                                           'version' => 'FOAF',
117                                                                                           'item' => 'foaf')));
118
119                 common_submit('deleteaccount', _('Delete my account'));
120                 common_element_end('form');
121         }
122
123     function delete_account_confirmation() {
124         // ask confirmation then
125         $this->delete_account();
126     }
127
128         function delete_account() {
129                 $user = common_current_user();
130                 assert(!is_null($user)); # should already be checked
131
132         // deleted later through the profile
133         /*
134         $avatar = new Avatar;
135         $avatar->profile_id = $user->id;
136         $n_avatars_deleted = $avatar->delete();
137         */
138
139         $fave = new Fave;
140         $fave->user_id = $user->id;
141         $n_faves_deleted = $fave->delete(); 
142
143         $confirmation = new Confirm_address;
144         $confirmation->user_id = $user->id;
145         $n_confirmations_deleted = $confirmation->delete();
146
147         // TODO foreign stuff...
148
149         $invitation = new Invitation;
150         $invitation->user_id = $user->id;
151         $n_invitations_deleted = $invitation->delete();
152
153         $message_from = new Message;
154         $message_from->from_profile = $user->id;
155         $n_messages_from_deleted = $message_from->delete();
156
157         $message_to = new Message;
158         $message_to->to_profile = $user->id;
159         $n_messages_to_deleted = $message_to->delete();
160
161         $notice_inbox = new Notice_inbox;
162         $notice_inbox->user_id = $user->id;
163         $n_notices_inbox_deleted = $notice_inbox->delete();
164
165         $profile_tagger = new Profile_tag;
166         $profile_tagger->tagger = $user->id;
167         $n_profiles_tagger_deleted = $profile_tagger->delete();
168
169         $profile_tagged = new Profile_tag;
170         $profile_tagged->tagged = $user->id;
171         $n_profiles_tagged_deleted = $profile_tagged->delete();
172                
173         $remember_me = new Remember_me;
174         $remember_me->user_id = $user->id;
175         $n_remember_mes_deleted = $remember_me->delete();
176
177         $reply= new Reply;
178         $reply->profile_id = $user->id;
179         $n_replies_deleted = $reply->delete();
180
181         // FIXME we're not removings replies to deleted notices.
182         //       notices should take care of that themselves.
183
184         $notice = new Notice;
185         $notice->profile_id = $user->id;
186         $n_notices_deleted = $notice->delete();
187
188         $subscriber = new Subscription;
189         $subscriber->subscriber = $user->id;
190         $n_subscribers_deleted = $subscriber->delete();
191
192         $subscribed = new Subscription;
193         $subscribed->subscribed = $user->id;
194         $n_subscribeds_deleted = $subscribed->delete();
195
196         $user_openid = new User_openid;
197         $user_openid->user_id = $user->id;
198         $n_user_openids_deleted = $user_openid->delete();
199
200         $profile = new Profile;
201         $profile->id = $user->id;
202         $profile->delete_avatars();
203         $n_profiles_deleted = $profile->delete();
204         $n_users_deleted = $user->delete();
205
206         // logout and redirect to public
207         common_set_user(NULL);
208         common_real_login(false); # not logged in
209         common_forgetme(); # don't log back in!
210         common_redirect(common_local_url('public'));
211     }
212 }