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 ProfilesettingsAction extends SettingsAction {
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',
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',
52 'value' => _t('Save')));
53 common_element_end('form');
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');
65 $user = common_current_user();
66 assert(!is_null($user)); # should already be checked
71 $original = clone($user);
73 $user->nickname = $this->arg('nickname');
74 $user->email = $this->arg('email');
76 if (!$user->update($original)) {
77 common_server_error(_t('Couldnt update user.'));
81 $profile = $user->getProfile();
83 $orig_profile = clone($profile);
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);
92 if (!$profile->update($orig_profile)) {
93 common_server_error(_t('Couldnt save profile.'));
97 $this->show_form(_t('Settings saved.'), TRUE);