3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
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.
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.
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/>.
20 if (!defined('LACONICA')) { exit(1); }
22 class DeleteprofileAction extends Action
24 function handle($args)
26 parent::handle($args);
27 $this->serverError(_('Code not yet ready.'));
29 if ('POST' === $_SERVER['REQUEST_METHOD']) {
32 else if ('GET' === $_SERVER['REQUEST_METHOD']) {
37 function get_instructions()
39 return _('Export and delete your user information.');
42 function form_header($title, $msg=null, $success=false)
44 common_show_header($title,
46 array($msg, $success),
47 array($this, 'show_top'));
50 function show_feeds_list($feeds)
52 $this->elementStart('div', array('class' => 'feedsdel'));
53 $this->element('p', null, 'Feeds:');
54 $this->elementStart('ul', array('class' => 'xoxo'));
56 foreach ($feeds as $key => $value) {
57 $this->common_feed_item($feeds[$key]);
59 $this->elementEnd('ul');
60 $this->elementEnd('div');
63 //TODO move to common.php (and retrace its origin)
64 function common_feed_item($feed)
66 $user = common_current_user();
67 $nickname = $user->nickname;
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";
78 $feed_classname = "foaf";
79 $feed_mimetype = "application/".$feed['type']."+xml";
80 $feed_title = "$nickname's FOAF file";
81 $feed['textContent'] = "FOAF";
84 $this->elementStart('li');
85 $this->element('a', array('href' => $feed['href'],
86 'class' => $feed_classname,
87 'type' => $feed_mimetype,
88 'title' => $feed_title),
89 $feed['textContent']);
90 $this->elementEnd('li');
93 function show_form($msg=null, $success=false)
95 $this->form_header(_('Delete my account'), $msg, $success);
96 $this->element('h2', null, _('Delete my account confirmation'));
97 $this->show_confirm_delete_form();
101 function show_confirm_delete_form()
103 $user = common_current_user();
104 $notices = DB_DataObject::factory('notice');
105 $notices->profile_id = $user->id;
106 $notice_count = (int) $notices->count();
108 $this->elementStart('form', array('method' => 'POST',
111 common_local_url('deleteprofile')));
113 $this->hidden('token', common_session_token());
114 $this->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.");
116 $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
118 'version' => 'RSS 1.0',
119 'item' => 'notices'),
120 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
125 $this->checkbox('confirmation', _('Check if you are sure you want to delete your account.'));
127 $this->submit('deleteaccount', _('Delete my account'));
128 $this->elementEnd('form');
131 function handle_post()
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.'));
140 if ($this->arg('deleteaccount') && $this->arg('confirmation')) {
141 $this->delete_account();
146 function delete_account()
148 $user = common_current_user();
149 assert(!is_null($user)); # should already be checked
151 // deleted later through the profile
153 $avatar = new Avatar;
154 $avatar->profile_id = $user->id;
155 $n_avatars_deleted = $avatar->delete();
159 $fave->user_id = $user->id;
160 $n_faves_deleted = $fave->delete();
162 $confirmation = new Confirm_address;
163 $confirmation->user_id = $user->id;
164 $n_confirmations_deleted = $confirmation->delete();
166 // TODO foreign stuff...
168 $invitation = new Invitation;
169 $invitation->user_id = $user->id;
170 $n_invitations_deleted = $invitation->delete();
172 $message_from = new Message;
173 $message_from->from_profile = $user->id;
174 $n_messages_from_deleted = $message_from->delete();
176 $message_to = new Message;
177 $message_to->to_profile = $user->id;
178 $n_messages_to_deleted = $message_to->delete();
180 $notice_inbox = new Notice_inbox;
181 $notice_inbox->user_id = $user->id;
182 $n_notices_inbox_deleted = $notice_inbox->delete();
184 $profile_tagger = new Profile_tag;
185 $profile_tagger->tagger = $user->id;
186 $n_profiles_tagger_deleted = $profile_tagger->delete();
188 $profile_tagged = new Profile_tag;
189 $profile_tagged->tagged = $user->id;
190 $n_profiles_tagged_deleted = $profile_tagged->delete();
192 $remember_me = new Remember_me;
193 $remember_me->user_id = $user->id;
194 $n_remember_mes_deleted = $remember_me->delete();
197 $reply->profile_id = $user->id;
198 $n_replies_deleted = $reply->delete();
200 // FIXME we're not removings replies to deleted notices.
201 // notices should take care of that themselves.
203 $notice = new Notice;
204 $notice->profile_id = $user->id;
205 $n_notices_deleted = $notice->delete();
207 $subscriber = new Subscription;
208 $subscriber->subscriber = $user->id;
209 $n_subscribers_deleted = $subscriber->delete();
211 $subscribed = new Subscription;
212 $subscribed->subscribed = $user->id;
213 $n_subscribeds_deleted = $subscribed->delete();
215 $user_openid = new User_openid;
216 $user_openid->user_id = $user->id;
217 $n_user_openids_deleted = $user_openid->delete();
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();
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'));
232 function show_top($arr)
237 $this->message($msg, $success);
239 $inst = $this->get_instructions();
240 $output = common_markup_to_html($inst);
241 $this->elementStart('div', 'instructions');
243 $this->elementEnd('div');
245 $this->settings_menu();
248 function settings_menu()
250 # action => array('prompt', 'title')
252 array('profilesettings' =>
254 _('Change your profile settings')),
257 _('Change email handling')),
260 _('Add or remove OpenIDs')),
263 _('Updates by SMS')),
266 _('Updates by instant messenger (IM)')),
269 _('Twitter integration options')),
272 _('Other options')));
274 $action = $this->trimmed('action');
275 $this->elementStart('ul', array('id' => 'nav_views'));
276 foreach ($menu as $menuaction => $menudesc) {
277 if ($menuaction == 'imsettings' &&
278 !common_config('xmpp', 'enabled')) {
281 common_menu_item(common_local_url($menuaction),
284 $action == $menuaction);
286 $this->elementEnd('ul');