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) {
24 parent::handle($args);
25 $this->server_error(_('Code not yet ready.'));
27 if ('POST' === $_SERVER['REQUEST_METHOD']) {
30 else if ('GET' === $_SERVER['REQUEST_METHOD']) {
35 function get_instructions() {
36 return _('Export and delete your user information.');
39 function form_header($title, $msg=null, $success=false) {
40 common_show_header($title,
42 array($msg, $success),
43 array($this, 'show_top'));
46 function show_feeds_list($feeds) {
47 common_element_start('div', array('class' => 'feedsdel'));
48 common_element('p', null, 'Feeds:');
49 common_element_start('ul', array('class' => 'xoxo'));
51 foreach ($feeds as $key => $value) {
52 $this->common_feed_item($feeds[$key]);
54 common_element_end('ul');
55 common_element_end('div');
58 //TODO move to common.php (and retrace its origin)
59 function common_feed_item($feed) {
60 $user = common_current_user();
61 $nickname = $user->nickname;
63 switch($feed['item']) {
64 case 'notices': default:
65 $feed_classname = $feed['type'];
66 $feed_mimetype = "application/".$feed['type']."+xml";
67 $feed_title = "$nickname's ".$feed['version']." notice feed";
68 $feed['textContent'] = "RSS";
72 $feed_classname = "foaf";
73 $feed_mimetype = "application/".$feed['type']."+xml";
74 $feed_title = "$nickname's FOAF file";
75 $feed['textContent'] = "FOAF";
78 common_element_start('li');
79 common_element('a', array('href' => $feed['href'],
80 'class' => $feed_classname,
81 'type' => $feed_mimetype,
82 'title' => $feed_title),
83 $feed['textContent']);
84 common_element_end('li');
87 function show_form($msg=null, $success=false) {
88 $this->form_header(_('Delete my account'), $msg, $success);
89 common_element('h2', null, _('Delete my account confirmation'));
90 $this->show_confirm_delete_form();
94 function show_confirm_delete_form() {
95 $user = common_current_user();
96 $notices = DB_DataObject::factory('notice');
97 $notices->profile_id = $user->id;
98 $notice_count = (int) $notices->count();
100 common_element_start('form', array('method' => 'POST',
103 common_local_url('deleteprofile')));
105 common_hidden('token', common_session_token());
106 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.");
108 $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
110 'version' => 'RSS 1.0',
111 'item' => 'notices'),
112 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
117 common_checkbox('confirmation', _('Check if you are sure you want to delete your account.'));
119 common_submit('deleteaccount', _('Delete my account'));
120 common_element_end('form');
123 function handle_post() {
125 $token = $this->trimmed('token');
126 if (!$token || $token != common_session_token()) {
127 $this->show_form(_('There was a problem with your session token. Try again, please.'));
131 if ($this->arg('deleteaccount') && $this->arg('confirmation')) {
132 $this->delete_account();
137 function delete_account() {
138 $user = common_current_user();
139 assert(!is_null($user)); # should already be checked
141 // deleted later through the profile
143 $avatar = new Avatar;
144 $avatar->profile_id = $user->id;
145 $n_avatars_deleted = $avatar->delete();
149 $fave->user_id = $user->id;
150 $n_faves_deleted = $fave->delete();
152 $confirmation = new Confirm_address;
153 $confirmation->user_id = $user->id;
154 $n_confirmations_deleted = $confirmation->delete();
156 // TODO foreign stuff...
158 $invitation = new Invitation;
159 $invitation->user_id = $user->id;
160 $n_invitations_deleted = $invitation->delete();
162 $message_from = new Message;
163 $message_from->from_profile = $user->id;
164 $n_messages_from_deleted = $message_from->delete();
166 $message_to = new Message;
167 $message_to->to_profile = $user->id;
168 $n_messages_to_deleted = $message_to->delete();
170 $notice_inbox = new Notice_inbox;
171 $notice_inbox->user_id = $user->id;
172 $n_notices_inbox_deleted = $notice_inbox->delete();
174 $profile_tagger = new Profile_tag;
175 $profile_tagger->tagger = $user->id;
176 $n_profiles_tagger_deleted = $profile_tagger->delete();
178 $profile_tagged = new Profile_tag;
179 $profile_tagged->tagged = $user->id;
180 $n_profiles_tagged_deleted = $profile_tagged->delete();
182 $remember_me = new Remember_me;
183 $remember_me->user_id = $user->id;
184 $n_remember_mes_deleted = $remember_me->delete();
187 $reply->profile_id = $user->id;
188 $n_replies_deleted = $reply->delete();
190 // FIXME we're not removings replies to deleted notices.
191 // notices should take care of that themselves.
193 $notice = new Notice;
194 $notice->profile_id = $user->id;
195 $n_notices_deleted = $notice->delete();
197 $subscriber = new Subscription;
198 $subscriber->subscriber = $user->id;
199 $n_subscribers_deleted = $subscriber->delete();
201 $subscribed = new Subscription;
202 $subscribed->subscribed = $user->id;
203 $n_subscribeds_deleted = $subscribed->delete();
205 $user_openid = new User_openid;
206 $user_openid->user_id = $user->id;
207 $n_user_openids_deleted = $user_openid->delete();
209 $profile = new Profile;
210 $profile->id = $user->id;
211 $profile->delete_avatars();
212 $n_profiles_deleted = $profile->delete();
213 $n_users_deleted = $user->delete();
215 // logout and redirect to public
216 common_set_user(null);
217 common_real_login(false); # not logged in
218 common_forgetme(); # don't log back in!
219 common_redirect(common_local_url('public'));
222 function show_top($arr) {
226 $this->message($msg, $success);
228 $inst = $this->get_instructions();
229 $output = common_markup_to_html($inst);
230 common_element_start('div', 'instructions');
232 common_element_end('div');
234 $this->settings_menu();
237 function settings_menu() {
238 # action => array('prompt', 'title')
240 array('profilesettings' =>
242 _('Change your profile settings')),
245 _('Change email handling')),
248 _('Add or remove OpenIDs')),
251 _('Updates by SMS')),
254 _('Updates by instant messenger (IM)')),
257 _('Twitter integration options')),
260 _('Other options')));
262 $action = $this->trimmed('action');
263 common_element_start('ul', array('id' => 'nav_views'));
264 foreach ($menu as $menuaction => $menudesc) {
265 if ($menuaction == 'imsettings' &&
266 !common_config('xmpp', 'enabled')) {
269 common_menu_item(common_local_url($menuaction),
272 $action == $menuaction);
274 common_element_end('ul');