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",
44 notice( t('Password changed.') . EOL);
46 notice( t('Password update failed. Please try again.') . EOL);
50 $theme = notags(trim($_POST['theme']));
51 $username = notags(trim($_POST['username']));
52 $email = notags(trim($_POST['email']));
53 $timezone = notags(trim($_POST['timezone']));
54 $defloc = notags(trim($_POST['defloc']));
56 $publish = (($_POST['profile_in_directory'] == 1) ? 1: 0);
57 $net_publish = (($_POST['profile_in_netdirectory'] == 1) ? 1: 0);
58 $old_visibility = ((intval($_POST['visibility']) == 1) ? 1 : 0);
63 $notify += intval($_POST['notify1']);
65 $notify += intval($_POST['notify2']);
67 $notify += intval($_POST['notify3']);
69 $notify += intval($_POST['notify4']);
71 $notify += intval($_POST['notify5']);
73 $email_changed = false;
77 if($username != $a->user['username']) {
78 if(strlen($username) > 40)
79 $err .= t(' Please use a shorter name.');
80 if(strlen($username) < 3)
81 $err .= t(' Name too short.');
83 if($email != $a->user['email']) {
84 $email_changed = true;
85 if(!eregi('[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,6}',$email))
86 $err .= t(' Not valid email.');
87 $r = q("SELECT `uid` FROM `user`
88 WHERE `email` = '%s' LIMIT 1",
91 if($r !== NULL && count($r))
92 $err .= t(' This email address is already registered.');
99 if($timezone != $a->user['timezone']) {
100 if(strlen($timezone))
101 date_default_timezone_set($timezone);
105 $str_group_allow = perms2str($_POST['group_allow']);
106 $str_contact_allow = perms2str($_POST['contact_allow']);
107 $str_group_deny = perms2str($_POST['group_deny']);
108 $str_contact_deny = perms2str($_POST['contact_deny']);
110 $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",
114 dbesc($str_contact_allow),
115 dbesc($str_group_allow),
116 dbesc($str_contact_deny),
117 dbesc($str_group_deny),
124 notice( t('Settings updated.') . EOL);
126 $r = q("UPDATE `profile`
127 SET `publish` = %d, `net-publish` = %d
128 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
130 intval($net_publish),
134 if($old_visibility != $net_publish) {
135 // Update global directory in background
136 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
137 $url = $_SESSION['my_url'];
138 if($url && strlen(get_config('system','directory_submit_url')))
139 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
143 $_SESSION['theme'] = $theme;
144 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
146 // FIXME - set to un-verified, blocked and redirect to logout
150 goaway($a->get_baseurl() . '/settings' );
151 return; // NOTREACHED
155 if(! function_exists('settings_content')) {
156 function settings_content(&$a) {
159 notice( t('Permission denied.') . EOL );
163 require_once('view/acl_selectors.php');
165 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
166 intval($_SESSION['uid'])
171 $username = $a->user['username'];
172 $email = $a->user['email'];
173 $nickname = $a->user['nickname'];
174 $timezone = $a->user['timezone'];
175 $notify = $a->user['notify-flags'];
176 $defloc = $a->user['default-location'];
178 if(! strlen($a->user['timezone']))
179 $timezone = date_default_timezone_get();
182 $opt_tpl = file_get_contents("view/profile-in-directory.tpl");
183 $profile_in_dir = replace_macros($opt_tpl,array(
184 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
185 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
188 if(strlen(get_config('system','directory_submit_url'))) {
189 $opt_tpl = file_get_contents("view/profile-in-netdir.tpl");
191 $profile_in_net_dir = replace_macros($opt_tpl,array(
192 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
193 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
197 $profile_in_net_dir = '';
199 $nickname_block = file_get_contents("view/settings_nick_set.tpl");
201 $nickname_subdir = '';
202 if(strlen($a->get_path())) {
203 $subdir_tpl = file_get_contents('view/settings_nick_subdir.tpl');
204 $nickname_subdir = replace_macros($subdir_tpl, array(
205 '$baseurl' => $a->get_baseurl(),
206 '$nickname' => $nickname,
207 '$hostname' => $a->get_hostname()
211 $theme_selector = '<select name="theme" id="theme-select" >';
212 $files = glob('view/theme/*');
214 foreach($files as $file) {
215 $f = basename($file);
216 $selected = (($f == $_SESSION['theme']) || ($f == 'default' && (! x($_SESSION,'theme')))
217 ? ' selected="selected" ' : '' );
218 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
221 $theme_selector .= '</select>';
224 $nickname_block = replace_macros($nickname_block,array(
225 '$nickname' => $nickname,
226 '$uid' => $_SESSION['uid'],
227 '$subdir' => $nickname_subdir,
228 '$basepath' => $a->get_hostname(),
229 '$baseurl' => $a->get_baseurl()));
231 $o = file_get_contents('view/settings.tpl');
233 $o = replace_macros($o,array(
234 '$baseurl' => $a->get_baseurl(),
235 '$uid' => $_SESSION['uid'],
236 '$username' => $username,
238 '$nickname_block' => $nickname_block,
239 '$timezone' => $timezone,
240 '$zoneselect' => select_timezone($timezone),
241 '$defloc' => $defloc,
242 '$profile_in_dir' => $profile_in_dir,
243 '$profile_in_net_dir' => $profile_in_net_dir,
244 '$permissions' => t('Default Post Permissions'),
245 '$visibility' => $profile['net-publish'],
246 '$aclselect' => populate_acl($a->user),
247 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
248 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
249 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
250 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
251 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
252 '$theme' => $theme_selector