]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/profilesettings.php
15c455fe2e33579a2f58550c61fe93e4cb2e41a0
[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_input('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_element('input', array('name' => 'submit',
50                                                                           'type' => 'submit',
51                                                                           'id' => 'submit',
52                                                                           'value' => _t('Save')));
53                 common_element_end('form');
54                 common_show_footer();
55         }
56
57         function handle_post() {
58                 $nickname = $this->arg('nickname');
59                 $fullname = $this->arg('fullname');
60                 $email = $this->arg('email');
61                 $homepage = $this->arg('homepage');
62                 $bio = $this->arg('bio');
63                 $location = $this->arg('location');
64
65                 $user = common_current_user();
66                 assert(!is_null($user)); # should already be checked
67
68                 # FIXME: scrub input
69                 # FIXME: transaction!
70
71                 $original = clone($user);
72
73                 $user->nickname = $this->arg('nickname');
74                 $user->email = $this->arg('email');
75
76                 if (!$user->update($original)) {
77                         common_server_error(_t('Couldnt update user.'));
78                         return;
79                 }
80
81                 $profile = $user->getProfile();
82
83                 $orig_profile = clone($profile);
84
85                 $profile->nickname = $user->nickname;
86                 $profile->fullname = $this->arg('fullname');
87                 $profile->homepage = $this->arg('homepage');
88                 $profile->bio = $this->arg('bio');
89                 $profile->location = $this->arg('location');
90                 $profile->profileurl = common_profile_url($nickname);
91
92                 if (!$profile->update($orig_profile)) {
93                         common_server_error(_t('Couldnt save profile.'));
94                         return;
95                 }
96
97                 $this->show_form(_t('Settings saved.'), TRUE);
98         }
99 }