]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - _darcs/pristine/actions/deleteprofile.php
replace all tabs with four spaces
[quix0rs-gnu-social.git] / _darcs / pristine / actions / deleteprofile.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 class DeleteprofileAction extends Action {
23     function handle($args) {
24         parent::handle($args);
25         $this->server_error(_('Code not yet ready.'));
26         return;
27         if ('POST' === $_SERVER['REQUEST_METHOD']) {
28             $this->handle_post();
29         }
30         else if ('GET' === $_SERVER['REQUEST_METHOD']) {
31             $this->show_form();
32         }
33     }
34
35     function get_instructions() {
36         return _('Export and delete your user information.');
37     }
38
39     function form_header($title, $msg=NULL, $success=false) {
40         common_show_header($title,
41                            NULL,
42                            array($msg, $success),
43                            array($this, 'show_top'));
44     }
45
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'));
50
51         foreach ($feeds as $key => $value) {
52             $this->common_feed_item($feeds[$key]);
53         }
54         common_element_end('ul');
55         common_element_end('div');
56     }
57
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;
62
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";
69                 break;
70
71             case 'foaf':
72                 $feed_classname = "foaf";
73                 $feed_mimetype = "application/".$feed['type']."+xml";
74                 $feed_title = "$nickname's FOAF file";
75                 $feed['textContent'] = "FOAF";
76                 break;
77         }
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');
85     }
86
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();
91         common_show_footer();
92     }
93
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();
99
100         common_element_start('form', array('method' => 'POST',
101                                            'id' => 'delete',
102                                            'action' =>
103                                            common_local_url('deleteprofile')));
104
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.");
107
108         $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
109                                               'type' => 'rss',
110                                               'version' => 'RSS 1.0',
111                                               'item' => 'notices'),
112                                      1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
113                                               'type' => 'rdf',
114                                               'version' => 'FOAF',
115                                               'item' => 'foaf')));
116
117         common_checkbox('confirmation', _('Check if you are sure you want to delete your account.'));
118
119         common_submit('deleteaccount', _('Delete my account'));
120         common_element_end('form');
121     }
122
123     function handle_post() {
124         # CSRF protection
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.'));
128             return;
129         }
130
131         if ($this->arg('deleteaccount') && $this->arg('confirmation')) {
132             $this->delete_account();
133         }
134         $this->show_form();
135     }
136
137     function delete_account() {
138         $user = common_current_user();
139         assert(!is_null($user)); # should already be checked
140
141         // deleted later through the profile
142         /*
143         $avatar = new Avatar;
144         $avatar->profile_id = $user->id;
145         $n_avatars_deleted = $avatar->delete();
146         */
147
148         $fave = new Fave;
149         $fave->user_id = $user->id;
150         $n_faves_deleted = $fave->delete();
151
152         $confirmation = new Confirm_address;
153         $confirmation->user_id = $user->id;
154         $n_confirmations_deleted = $confirmation->delete();
155
156         // TODO foreign stuff...
157
158         $invitation = new Invitation;
159         $invitation->user_id = $user->id;
160         $n_invitations_deleted = $invitation->delete();
161
162         $message_from = new Message;
163         $message_from->from_profile = $user->id;
164         $n_messages_from_deleted = $message_from->delete();
165
166         $message_to = new Message;
167         $message_to->to_profile = $user->id;
168         $n_messages_to_deleted = $message_to->delete();
169
170         $notice_inbox = new Notice_inbox;
171         $notice_inbox->user_id = $user->id;
172         $n_notices_inbox_deleted = $notice_inbox->delete();
173
174         $profile_tagger = new Profile_tag;
175         $profile_tagger->tagger = $user->id;
176         $n_profiles_tagger_deleted = $profile_tagger->delete();
177
178         $profile_tagged = new Profile_tag;
179         $profile_tagged->tagged = $user->id;
180         $n_profiles_tagged_deleted = $profile_tagged->delete();
181
182         $remember_me = new Remember_me;
183         $remember_me->user_id = $user->id;
184         $n_remember_mes_deleted = $remember_me->delete();
185
186         $reply= new Reply;
187         $reply->profile_id = $user->id;
188         $n_replies_deleted = $reply->delete();
189
190         // FIXME we're not removings replies to deleted notices.
191         //       notices should take care of that themselves.
192
193         $notice = new Notice;
194         $notice->profile_id = $user->id;
195         $n_notices_deleted = $notice->delete();
196
197         $subscriber = new Subscription;
198         $subscriber->subscriber = $user->id;
199         $n_subscribers_deleted = $subscriber->delete();
200
201         $subscribed = new Subscription;
202         $subscribed->subscribed = $user->id;
203         $n_subscribeds_deleted = $subscribed->delete();
204
205         $user_openid = new User_openid;
206         $user_openid->user_id = $user->id;
207         $n_user_openids_deleted = $user_openid->delete();
208
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();
214
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'));
220     }
221
222     function show_top($arr) {
223         $msg = $arr[0];
224         $success = $arr[1];
225         if ($msg) {
226             $this->message($msg, $success);
227         } else {
228             $inst = $this->get_instructions();
229             $output = common_markup_to_html($inst);
230             common_element_start('div', 'instructions');
231             common_raw($output);
232             common_element_end('div');
233         }
234         $this->settings_menu();
235     }
236
237     function settings_menu() {
238         # action => array('prompt', 'title')
239         $menu =
240           array('profilesettings' =>
241                 array(_('Profile'),
242                       _('Change your profile settings')),
243                 'emailsettings' =>
244                 array(_('Email'),
245                       _('Change email handling')),
246                 'openidsettings' =>
247                 array(_('OpenID'),
248                       _('Add or remove OpenIDs')),
249                 'smssettings' =>
250                 array(_('SMS'),
251                       _('Updates by SMS')),
252                 'imsettings' =>
253                 array(_('IM'),
254                       _('Updates by instant messenger (IM)')),
255                 'twittersettings' =>
256                 array(_('Twitter'),
257                       _('Twitter integration options')),
258                 'othersettings' =>
259                 array(_('Other'),
260                       _('Other options')));
261
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')) {
267                 continue;
268             }
269             common_menu_item(common_local_url($menuaction),
270                     $menudesc[0],
271                     $menudesc[1],
272                     $action == $menuaction);
273         }
274         common_element_end('ul');
275     }
276 }
277