4 function settings_init(&$a) {
6 require_once("mod/profile.php");
7 profile_load($a,$a->user['nickname']);
12 function settings_post(&$a) {
15 notice( t('Permission denied.') . EOL);
18 if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != get_uid()) {
19 notice( t('Permission denied.') . EOL);
22 if((x($_POST,'npassword')) || (x($_POST,'confirm'))) {
24 $newpass = trim($_POST['npassword']);
25 $confirm = trim($_POST['confirm']);
28 if($newpass != $confirm ) {
29 notice( t('Passwords do not match. Password unchanged.') . EOL);
33 if((! x($newpass)) || (! x($confirm))) {
34 notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
39 $password = hash('whirlpool',$newpass);
40 $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d LIMIT 1",
45 notice( t('Password changed.') . EOL);
47 notice( t('Password update failed. Please try again.') . EOL);
51 $theme = notags(trim($_POST['theme']));
52 $username = notags(trim($_POST['username']));
53 $email = notags(trim($_POST['email']));
54 $timezone = notags(trim($_POST['timezone']));
55 $defloc = notags(trim($_POST['defloc']));
57 $publish = (($_POST['profile_in_directory'] == 1) ? 1: 0);
58 $net_publish = (($_POST['profile_in_netdirectory'] == 1) ? 1: 0);
59 $old_visibility = ((intval($_POST['visibility']) == 1) ? 1 : 0);
64 $notify += intval($_POST['notify1']);
66 $notify += intval($_POST['notify2']);
68 $notify += intval($_POST['notify3']);
70 $notify += intval($_POST['notify4']);
72 $notify += intval($_POST['notify5']);
74 $email_changed = false;
78 if($username != $a->user['username']) {
79 if(strlen($username) > 40)
80 $err .= t(' Please use a shorter name.');
81 if(strlen($username) < 3)
82 $err .= t(' Name too short.');
84 if($email != $a->user['email']) {
85 $email_changed = true;
86 if(!eregi('[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,6}',$email))
87 $err .= t(' Not valid email.');
88 $r = q("SELECT `uid` FROM `user`
89 WHERE `email` = '%s' LIMIT 1",
92 if($r !== NULL && count($r))
93 $err .= t(' This email address is already registered.');
100 if($timezone != $a->user['timezone']) {
101 if(strlen($timezone))
102 date_default_timezone_set($timezone);
106 $str_group_allow = perms2str($_POST['group_allow']);
107 $str_contact_allow = perms2str($_POST['contact_allow']);
108 $str_group_deny = perms2str($_POST['group_deny']);
109 $str_contact_deny = perms2str($_POST['contact_deny']);
111 $r = q("UPDATE `user` SET `username` = '%s', `email` = '%s', `timezone` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `notify-flags` = %d, `default-location` = '%s', `theme` = '%s' WHERE `uid` = %d LIMIT 1",
115 dbesc($str_contact_allow),
116 dbesc($str_group_allow),
117 dbesc($str_contact_deny),
118 dbesc($str_group_deny),
125 notice( t('Settings updated.') . EOL);
127 $r = q("UPDATE `profile`
128 SET `publish` = %d, `net-publish` = %d
129 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
131 intval($net_publish),
135 if($old_visibility != $net_publish) {
136 // Update global directory in background
137 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
138 $url = $_SESSION['my_url'];
139 if($url && strlen(get_config('system','directory_submit_url')))
140 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
144 $_SESSION['theme'] = $theme;
145 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
147 // FIXME - set to un-verified, blocked and redirect to logout
151 goaway($a->get_baseurl() . '/settings' );
152 return; // NOTREACHED
156 if(! function_exists('settings_content')) {
157 function settings_content(&$a) {
158 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
161 notice( t('Permission denied.') . EOL );
165 require_once('view/acl_selectors.php');
167 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
168 intval($_SESSION['uid'])
173 $username = $a->user['username'];
174 $email = $a->user['email'];
175 $nickname = $a->user['nickname'];
176 $timezone = $a->user['timezone'];
177 $notify = $a->user['notify-flags'];
178 $defloc = $a->user['default-location'];
180 if(! strlen($a->user['timezone']))
181 $timezone = date_default_timezone_get();
184 $opt_tpl = load_view_file("view/profile-in-directory.tpl");
185 $profile_in_dir = replace_macros($opt_tpl,array(
186 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
187 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
190 if(strlen(get_config('system','directory_submit_url'))) {
191 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
193 $profile_in_net_dir = replace_macros($opt_tpl,array(
194 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
195 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
199 $profile_in_net_dir = '';
201 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
205 notice( t('Profile is not published.'));
207 $nickname_block = load_view_file("view/settings_nick_set.tpl");
209 $nickname_subdir = '';
210 if(strlen($a->get_path())) {
211 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
212 $nickname_subdir = replace_macros($subdir_tpl, array(
213 '$baseurl' => $a->get_baseurl(),
214 '$nickname' => $nickname,
215 '$hostname' => $a->get_hostname()
219 $theme_selector = '<select name="theme" id="theme-select" >';
220 $files = glob('view/theme/*');
222 foreach($files as $file) {
223 $f = basename($file);
224 $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
225 ? ' selected="selected" ' : '' );
226 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
229 $theme_selector .= '</select>';
232 $nickname_block = replace_macros($nickname_block,array(
233 '$nickname' => $nickname,
234 '$uid' => $_SESSION['uid'],
235 '$subdir' => $nickname_subdir,
236 '$basepath' => $a->get_hostname(),
237 '$baseurl' => $a->get_baseurl()));
239 $stpl = load_view_file('view/settings.tpl');
241 $o .= replace_macros($stpl,array(
242 '$baseurl' => $a->get_baseurl(),
243 '$uid' => $_SESSION['uid'],
244 '$username' => $username,
246 '$nickname_block' => $nickname_block,
247 '$timezone' => $timezone,
248 '$zoneselect' => select_timezone($timezone),
249 '$defloc' => $defloc,
250 '$profile_in_dir' => $profile_in_dir,
251 '$profile_in_net_dir' => $profile_in_net_dir,
252 '$permissions' => t('Default Post Permissions'),
253 '$visibility' => $profile['net-publish'],
254 '$aclselect' => populate_acl($a->user),
255 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
256 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
257 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
258 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
259 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
260 '$theme' => $theme_selector