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 if ('POST' === $_SERVER['REQUEST_METHOD']) {
28 else if ('GET' === $_SERVER['REQUEST_METHOD']) {
33 function get_instructions() {
34 return _('Export and delete your user information.');
37 function form_header($title, $msg=NULL, $success=false) {
38 common_show_header($title,
40 array($msg, $success),
41 array($this, 'show_top'));
44 function show_feeds_list($feeds) {
45 common_element_start('div', array('class' => 'feedsdel'));
46 common_element('p', null, 'Feeds:');
47 common_element_start('ul', array('class' => 'xoxo'));
49 foreach ($feeds as $key => $value) {
50 $this->common_feed_item($feeds[$key]);
52 common_element_end('ul');
53 common_element_end('div');
56 //TODO move to common.php (and retrace its origin)
57 function common_feed_item($feed) {
58 $user = common_current_user();
59 $nickname = $user->nickname;
61 switch($feed['item']) {
62 case 'notices': default:
63 $feed_classname = $feed['type'];
64 $feed_mimetype = "application/".$feed['type']."+xml";
65 $feed_title = "$nickname's ".$feed['version']." notice feed";
66 $feed['textContent'] = "RSS";
70 $feed_classname = "foaf";
71 $feed_mimetype = "application/".$feed['type']."+xml";
72 $feed_title = "$nickname's FOAF file";
73 $feed['textContent'] = "FOAF";
76 common_element_start('li');
77 common_element('a', array('href' => $feed['href'],
78 'class' => $feed_classname,
79 'type' => $feed_mimetype,
80 'title' => $feed_title),
81 $feed['textContent']);
82 common_element_end('li');
85 function show_form($msg=NULL, $success=false) {
86 $this->form_header(_('Delete my account'), $msg, $success);
87 common_element('h2', NULL, _('Delete my account confirmation'));
88 $this->show_confirm_delete_form();
92 function show_confirm_delete_form() {
93 $user = common_current_user();
94 $notices = DB_DataObject::factory('notice');
95 $notices->profile_id = $user->id;
96 $notice_count = (int) $notices->count();
98 common_element_start('form', array('method' => 'POST',
101 common_local_url('deleteprofile')));
103 common_hidden('token', common_session_token());
104 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.");
107 $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
109 'version' => 'RSS 1.0',
110 'item' => 'notices'),
111 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
116 common_checkbox('confirmation', _('Check if you are sure you want to delete your account.'));
118 common_submit('deleteaccount', _('Delete my account'));
119 common_element_end('form');
122 function handle_post() {
124 $token = $this->trimmed('token');
125 if (!$token || $token != common_session_token()) {
126 $this->show_form(_('There was a problem with your session token. Try again, please.'));
130 if ($this->arg('deleteaccount') && $this->arg('confirmation')) {
131 $this->delete_account();
136 function delete_account() {
137 $user = common_current_user();
138 assert(!is_null($user)); # should already be checked
140 // deleted later through the profile
142 $avatar = new Avatar;
143 $avatar->profile_id = $user->id;
144 $n_avatars_deleted = $avatar->delete();
148 $fave->user_id = $user->id;
149 $n_faves_deleted = $fave->delete();
151 $confirmation = new Confirm_address;
152 $confirmation->user_id = $user->id;
153 $n_confirmations_deleted = $confirmation->delete();
155 // TODO foreign stuff...
157 $invitation = new Invitation;
158 $invitation->user_id = $user->id;
159 $n_invitations_deleted = $invitation->delete();
161 $message_from = new Message;
162 $message_from->from_profile = $user->id;
163 $n_messages_from_deleted = $message_from->delete();
165 $message_to = new Message;
166 $message_to->to_profile = $user->id;
167 $n_messages_to_deleted = $message_to->delete();
169 $notice_inbox = new Notice_inbox;
170 $notice_inbox->user_id = $user->id;
171 $n_notices_inbox_deleted = $notice_inbox->delete();
173 $profile_tagger = new Profile_tag;
174 $profile_tagger->tagger = $user->id;
175 $n_profiles_tagger_deleted = $profile_tagger->delete();
177 $profile_tagged = new Profile_tag;
178 $profile_tagged->tagged = $user->id;
179 $n_profiles_tagged_deleted = $profile_tagged->delete();
181 $remember_me = new Remember_me;
182 $remember_me->user_id = $user->id;
183 $n_remember_mes_deleted = $remember_me->delete();
186 $reply->profile_id = $user->id;
187 $n_replies_deleted = $reply->delete();
189 // FIXME we're not removings replies to deleted notices.
190 // notices should take care of that themselves.
192 $notice = new Notice;
193 $notice->profile_id = $user->id;
194 $n_notices_deleted = $notice->delete();
196 $subscriber = new Subscription;
197 $subscriber->subscriber = $user->id;
198 $n_subscribers_deleted = $subscriber->delete();
200 $subscribed = new Subscription;
201 $subscribed->subscribed = $user->id;
202 $n_subscribeds_deleted = $subscribed->delete();
204 $user_openid = new User_openid;
205 $user_openid->user_id = $user->id;
206 $n_user_openids_deleted = $user_openid->delete();
208 $profile = new Profile;
209 $profile->id = $user->id;
210 $profile->delete_avatars();
211 $n_profiles_deleted = $profile->delete();
212 $n_users_deleted = $user->delete();
214 // logout and redirect to public
215 common_set_user(NULL);
216 common_real_login(false); # not logged in
217 common_forgetme(); # don't log back in!
218 common_redirect(common_local_url('public'));
221 function show_top($arr) {
225 $this->message($msg, $success);
227 $inst = $this->get_instructions();
228 $output = common_markup_to_html($inst);
229 common_element_start('div', 'instructions');
231 common_element_end('div');
233 $this->settings_menu();
236 function settings_menu() {
237 # action => array('prompt', 'title')
239 array('profilesettings' =>
241 _('Change your profile settings')),
244 _('Change email handling')),
247 _('Add or remove OpenIDs')),
250 _('Updates by SMS')),
253 _('Updates by instant messenger (IM)')),
256 _('Twitter integration options')),
259 _('Other options')));
261 $action = $this->trimmed('action');
262 common_element_start('ul', array('id' => 'nav_views'));
263 foreach ($menu as $menuaction => $menudesc) {
264 if ($menuaction == 'imsettings' &&
265 !common_config('xmpp', 'enabled')) {
268 common_menu_item(common_local_url($menuaction),
271 $action == $menuaction);
273 common_element_end('ul');