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