]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/profilesettings.php
a8ae2c97a484477349b5d114714e6a02d44a1a5d
[quix0rs-gnu-social.git] / actions / profilesettings.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 require_once(INSTALLDIR.'/lib/settingsaction.php');
23
24 class ProfilesettingsAction extends SettingsAction {
25
26         function show_form($msg=NULL, $success=false) {
27                 $user = common_current_user();
28                 $profile = $user->getProfile();
29                 common_show_header(_t('Profile settings'));
30                 $this->settings_menu();
31                 $this->message($msg, $success);
32                 common_element_start('form', array('method' => 'POST',
33                                                                                    'id' => 'profilesettings',
34                                                                                    'action' =>
35                                                                                    common_local_url('profilesettings')));
36                 # too much common patterns here... abstractable?
37                 common_input('nickname', _t('Nickname'),
38                                          ($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname);
39                 common_input('fullname', _t('Full name'),
40                                          ($this->arg('fullname')) ? $this->arg('fullname') : $profile->fullname);
41                 common_input('email', _t('Email address'),
42                                          ($this->arg('email')) ? $this->arg('email') : $user->email);
43                 common_input('homepage', _t('Homepage'),
44                                          ($this->arg('homepage')) ? $this->arg('homepage') : $profile->homepage);
45                 common_textarea('bio', _t('Bio'),
46                                                 ($this->arg('bio')) ? $this->arg('bio') : $profile->bio);
47                 common_input('location', _t('Location'),
48                                          ($this->arg('location')) ? $this->arg('location') : $profile->location);
49                 common_submit('submit', _t('Save'));
50                 common_element_end('form');
51                 common_show_footer();
52         }
53
54         function handle_post() {
55                 $nickname = $this->arg('nickname');
56                 $fullname = $this->arg('fullname');
57                 $email = $this->arg('email');
58                 $homepage = $this->arg('homepage');
59                 $bio = $this->arg('bio');
60                 $location = $this->arg('location');
61
62                 $user = common_current_user();
63                 assert(!is_null($user)); # should already be checked
64
65                 # FIXME: scrub input
66                 # FIXME: transaction!
67
68                 $original = clone($user);
69
70                 $user->nickname = $this->arg('nickname');
71                 $user->email = $this->arg('email');
72
73                 $val = $user->validate();
74                 if ($val !== TRUE) {
75                         # XXX: better validation
76                         $this->show_form(_t('Error saving user; invalid.'));
77                         return;
78                 }
79
80                 if (!$user->update($original)) {
81                         common_server_error(_t('Couldnt update user.'));
82                         return;
83                 }
84
85                 $profile = $user->getProfile();
86
87                 $orig_profile = clone($profile);
88
89                 $profile->nickname = $user->nickname;
90                 $profile->fullname = $this->arg('fullname');
91                 $profile->homepage = $this->arg('homepage');
92                 $profile->bio = $this->arg('bio');
93                 $profile->location = $this->arg('location');
94                 $profile->profileurl = common_profile_url($nickname);
95
96                 $val = $profile->validate();
97                 if ($val !== TRUE) {
98                         # XXX: some feedback here, please!
99                         $this->show_form(_t('Error saving profile; invalid.'));
100                         return;
101                 }
102
103                 if (!$profile->update($orig_profile)) {
104                         common_server_error(_t('Couldnt save profile.'));
105                         return;
106                 }
107
108                 $this->show_form(_t('Settings saved.'), TRUE);
109         }
110 }