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 require_once(INSTALLDIR.'/lib/settingsaction.php');
24 class DeleteprofileAction extends Action { // was SettingsAction...
26 function get_instructions() {
27 return _('You can update your personal profile info here '.
28 'so people know more about you.');
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();
38 function handle_post() {
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.'));
48 if ($this->arg('deleteaccount')) {
49 $this->delete_account_confirmation();
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'));
59 foreach ($feeds as $key => $value) {
60 $this->common_feed_item($feeds[$key]);
62 common_element_end('ul');
63 common_element_end('div');
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;
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";
80 $feed_classname = "foaf";
81 $feed_mimetype = "application/".$feed['type']."+xml";
82 $feed_title = "$nickname's FOAF file";
83 $feed['textContent'] = "FOAF";
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');
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();
101 common_element_start('form', array('method' => 'POST',
104 common_local_url('profilesettings')));
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.");
110 $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
112 'version' => 'RSS 1.0',
113 'item' => 'notices'),
114 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
119 common_submit('deleteaccount', _('Delete my account'));
120 common_element_end('form');
123 function delete_account_confirmation() {
124 // ask confirmation then
125 $this->delete_account();
128 function delete_account() {
129 $user = common_current_user();
130 assert(!is_null($user)); # should already be checked
132 // deleted later through the profile
134 $avatar = new Avatar;
135 $avatar->profile_id = $user->id;
136 $n_avatars_deleted = $avatar->delete();
140 $fave->user_id = $user->id;
141 $n_faves_deleted = $fave->delete();
143 $confirmation = new Confirm_address;
144 $confirmation->user_id = $user->id;
145 $n_confirmations_deleted = $confirmation->delete();
147 // TODO foreign stuff...
149 $invitation = new Invitation;
150 $invitation->user_id = $user->id;
151 $n_invitations_deleted = $invitation->delete();
153 $message_from = new Message;
154 $message_from->from_profile = $user->id;
155 $n_messages_from_deleted = $message_from->delete();
157 $message_to = new Message;
158 $message_to->to_profile = $user->id;
159 $n_messages_to_deleted = $message_to->delete();
161 $notice_inbox = new Notice_inbox;
162 $notice_inbox->user_id = $user->id;
163 $n_notices_inbox_deleted = $notice_inbox->delete();
165 $profile_tagger = new Profile_tag;
166 $profile_tagger->tagger = $user->id;
167 $n_profiles_tagger_deleted = $profile_tagger->delete();
169 $profile_tagged = new Profile_tag;
170 $profile_tagged->tagged = $user->id;
171 $n_profiles_tagged_deleted = $profile_tagged->delete();
173 $remember_me = new Remember_me;
174 $remember_me->user_id = $user->id;
175 $n_remember_mes_deleted = $remember_me->delete();
178 $reply->profile_id = $user->id;
179 $n_replies_deleted = $reply->delete();
181 // FIXME we're not removings replies to deleted notices.
182 // notices should take care of that themselves.
184 $notice = new Notice;
185 $notice->profile_id = $user->id;
186 $n_notices_deleted = $notice->delete();
188 $subscriber = new Subscription;
189 $subscriber->subscriber = $user->id;
190 $n_subscribers_deleted = $subscriber->delete();
192 $subscribed = new Subscription;
193 $subscribed->subscribed = $user->id;
194 $n_subscribeds_deleted = $subscribed->delete();
196 $user_openid = new User_openid;
197 $user_openid->user_id = $user->id;
198 $n_user_openids_deleted = $user_openid->delete();
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();
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'));