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 {
23 function handle($args)
25 parent::handle($args);
26 $this->server_error(_('Code not yet ready.'));
28 if ('POST' === $_SERVER['REQUEST_METHOD']) {
31 else if ('GET' === $_SERVER['REQUEST_METHOD']) {
36 function get_instructions()
38 return _('Export and delete your user information.');
41 function form_header($title, $msg=null, $success=false)
43 common_show_header($title,
45 array($msg, $success),
46 array($this, 'show_top'));
49 function show_feeds_list($feeds)
51 common_element_start('div', array('class' => 'feedsdel'));
52 common_element('p', null, 'Feeds:');
53 common_element_start('ul', array('class' => 'xoxo'));
55 foreach ($feeds as $key => $value) {
56 $this->common_feed_item($feeds[$key]);
58 common_element_end('ul');
59 common_element_end('div');
62 //TODO move to common.php (and retrace its origin)
63 function common_feed_item($feed)
65 $user = common_current_user();
66 $nickname = $user->nickname;
68 switch($feed['item']) {
69 case 'notices': default:
70 $feed_classname = $feed['type'];
71 $feed_mimetype = "application/".$feed['type']."+xml";
72 $feed_title = "$nickname's ".$feed['version']." notice feed";
73 $feed['textContent'] = "RSS";
77 $feed_classname = "foaf";
78 $feed_mimetype = "application/".$feed['type']."+xml";
79 $feed_title = "$nickname's FOAF file";
80 $feed['textContent'] = "FOAF";
83 common_element_start('li');
84 common_element('a', array('href' => $feed['href'],
85 'class' => $feed_classname,
86 'type' => $feed_mimetype,
87 'title' => $feed_title),
88 $feed['textContent']);
89 common_element_end('li');
92 function show_form($msg=null, $success=false)
94 $this->form_header(_('Delete my account'), $msg, $success);
95 common_element('h2', null, _('Delete my account confirmation'));
96 $this->show_confirm_delete_form();
100 function show_confirm_delete_form()
102 $user = common_current_user();
103 $notices = DB_DataObject::factory('notice');
104 $notices->profile_id = $user->id;
105 $notice_count = (int) $notices->count();
107 common_element_start('form', array('method' => 'POST',
110 common_local_url('deleteprofile')));
112 common_hidden('token', common_session_token());
113 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 $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
117 'version' => 'RSS 1.0',
118 'item' => 'notices'),
119 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
124 common_checkbox('confirmation', _('Check if you are sure you want to delete your account.'));
126 common_submit('deleteaccount', _('Delete my account'));
127 common_element_end('form');
130 function handle_post()
133 $token = $this->trimmed('token');
134 if (!$token || $token != common_session_token()) {
135 $this->show_form(_('There was a problem with your session token. Try again, please.'));
139 if ($this->arg('deleteaccount') && $this->arg('confirmation')) {
140 $this->delete_account();
145 function delete_account()
147 $user = common_current_user();
148 assert(!is_null($user)); # should already be checked
150 // deleted later through the profile
152 $avatar = new Avatar;
153 $avatar->profile_id = $user->id;
154 $n_avatars_deleted = $avatar->delete();
158 $fave->user_id = $user->id;
159 $n_faves_deleted = $fave->delete();
161 $confirmation = new Confirm_address;
162 $confirmation->user_id = $user->id;
163 $n_confirmations_deleted = $confirmation->delete();
165 // TODO foreign stuff...
167 $invitation = new Invitation;
168 $invitation->user_id = $user->id;
169 $n_invitations_deleted = $invitation->delete();
171 $message_from = new Message;
172 $message_from->from_profile = $user->id;
173 $n_messages_from_deleted = $message_from->delete();
175 $message_to = new Message;
176 $message_to->to_profile = $user->id;
177 $n_messages_to_deleted = $message_to->delete();
179 $notice_inbox = new Notice_inbox;
180 $notice_inbox->user_id = $user->id;
181 $n_notices_inbox_deleted = $notice_inbox->delete();
183 $profile_tagger = new Profile_tag;
184 $profile_tagger->tagger = $user->id;
185 $n_profiles_tagger_deleted = $profile_tagger->delete();
187 $profile_tagged = new Profile_tag;
188 $profile_tagged->tagged = $user->id;
189 $n_profiles_tagged_deleted = $profile_tagged->delete();
191 $remember_me = new Remember_me;
192 $remember_me->user_id = $user->id;
193 $n_remember_mes_deleted = $remember_me->delete();
196 $reply->profile_id = $user->id;
197 $n_replies_deleted = $reply->delete();
199 // FIXME we're not removings replies to deleted notices.
200 // notices should take care of that themselves.
202 $notice = new Notice;
203 $notice->profile_id = $user->id;
204 $n_notices_deleted = $notice->delete();
206 $subscriber = new Subscription;
207 $subscriber->subscriber = $user->id;
208 $n_subscribers_deleted = $subscriber->delete();
210 $subscribed = new Subscription;
211 $subscribed->subscribed = $user->id;
212 $n_subscribeds_deleted = $subscribed->delete();
214 $user_openid = new User_openid;
215 $user_openid->user_id = $user->id;
216 $n_user_openids_deleted = $user_openid->delete();
218 $profile = new Profile;
219 $profile->id = $user->id;
220 $profile->delete_avatars();
221 $n_profiles_deleted = $profile->delete();
222 $n_users_deleted = $user->delete();
224 // logout and redirect to public
225 common_set_user(null);
226 common_real_login(false); # not logged in
227 common_forgetme(); # don't log back in!
228 common_redirect(common_local_url('public'));
231 function show_top($arr)
236 $this->message($msg, $success);
238 $inst = $this->get_instructions();
239 $output = common_markup_to_html($inst);
240 common_element_start('div', 'instructions');
242 common_element_end('div');
244 $this->settings_menu();
247 function settings_menu()
249 # action => array('prompt', 'title')
251 array('profilesettings' =>
253 _('Change your profile settings')),
256 _('Change email handling')),
259 _('Add or remove OpenIDs')),
262 _('Updates by SMS')),
265 _('Updates by instant messenger (IM)')),
268 _('Twitter integration options')),
271 _('Other options')));
273 $action = $this->trimmed('action');
274 common_element_start('ul', array('id' => 'nav_views'));
275 foreach ($menu as $menuaction => $menudesc) {
276 if ($menuaction == 'imsettings' &&
277 !common_config('xmpp', 'enabled')) {
280 common_menu_item(common_local_url($menuaction),
283 $action == $menuaction);
285 common_element_end('ul');