4 function settings_init(&$a) {
6 profile_load($a,$a->user['nickname']);
11 function settings_post(&$a) {
14 notice( t('Permission denied.') . EOL);
18 call_hooks('settings_post', $_POST);
20 if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
21 notice( t('Permission denied.') . EOL);
24 if((x($_POST,'npassword')) || (x($_POST,'confirm'))) {
26 $newpass = $_POST['npassword'];
27 $confirm = $_POST['confirm'];
30 if($newpass != $confirm ) {
31 notice( t('Passwords do not match. Password unchanged.') . EOL);
35 if((! x($newpass)) || (! x($confirm))) {
36 notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
41 $password = hash('whirlpool',$newpass);
42 $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d LIMIT 1",
47 notice( t('Password changed.') . EOL);
49 notice( t('Password update failed. Please try again.') . EOL);
53 $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
54 $username = ((x($_POST,'username')) ? notags(trim($_POST['username'])) : '');
55 $email = ((x($_POST,'email')) ? notags(trim($_POST['email'])) : '');
56 $timezone = ((x($_POST,'timezone')) ? notags(trim($_POST['timezone'])) : '');
57 $defloc = ((x($_POST,'defloc')) ? notags(trim($_POST['defloc'])) : '');
58 $openid = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url'])) : '');
59 $maxreq = ((x($_POST,'maxreq')) ? intval($_POST['maxreq']) : 0);
61 $allow_location = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
62 $publish = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
63 $net_publish = (((x($_POST,'profile_in_netdirectory')) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
64 $old_visibility = (((x($_POST,'visibility')) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
65 $page_flags = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
69 if(x($_POST,'notify1'))
70 $notify += intval($_POST['notify1']);
71 if(x($_POST,'notify2'))
72 $notify += intval($_POST['notify2']);
73 if(x($_POST,'notify3'))
74 $notify += intval($_POST['notify3']);
75 if(x($_POST,'notify4'))
76 $notify += intval($_POST['notify4']);
77 if(x($_POST,'notify5'))
78 $notify += intval($_POST['notify5']);
80 $email_changed = false;
84 if($username != $a->user['username']) {
85 if(strlen($username) > 40)
86 $err .= t(' Please use a shorter name.');
87 if(strlen($username) < 3)
88 $err .= t(' Name too short.');
91 if($email != $a->user['email']) {
92 $email_changed = true;
93 if(! valid_email($email))
94 $err .= t(' Not valid email.');
102 if($timezone != $a->user['timezone']) {
103 if(strlen($timezone))
104 date_default_timezone_set($timezone);
107 $str_group_allow = perms2str($_POST['group_allow']);
108 $str_contact_allow = perms2str($_POST['contact_allow']);
109 $str_group_deny = perms2str($_POST['group_deny']);
110 $str_contact_deny = perms2str($_POST['contact_deny']);
112 $r = q("UPDATE `user` SET `username` = '%s', `email` = '%s', `openid` = '%s', `timezone` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `notify-flags` = %d, `page-flags` = %d, `default-location` = '%s', `allow_location` = %d, `theme` = '%s', `maxreq` = %d WHERE `uid` = %d LIMIT 1",
117 dbesc($str_contact_allow),
118 dbesc($str_group_allow),
119 dbesc($str_contact_deny),
120 dbesc($str_group_deny),
124 intval($allow_location),
130 notice( t('Settings updated.') . EOL);
132 $r = q("UPDATE `profile`
133 SET `publish` = %d, `net-publish` = %d
134 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
136 intval($net_publish),
140 if($old_visibility != $net_publish) {
141 // Update global directory in background
142 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
143 $url = $_SESSION['my_url'];
144 if($url && strlen(get_config('system','directory_submit_url')))
145 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
149 $_SESSION['theme'] = $theme;
150 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
152 // FIXME - set to un-verified, blocked and redirect to logout
156 goaway($a->get_baseurl() . '/settings' );
157 return; // NOTREACHED
161 if(! function_exists('settings_content')) {
162 function settings_content(&$a) {
165 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
168 notice( t('Permission denied.') . EOL );
172 require_once('include/acl_selectors.php');
174 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
180 $username = $a->user['username'];
181 $email = $a->user['email'];
182 $nickname = $a->user['nickname'];
183 $timezone = $a->user['timezone'];
184 $notify = $a->user['notify-flags'];
185 $defloc = $a->user['default-location'];
186 $openid = $a->user['openid'];
187 $maxreq = $a->user['maxreq'];
189 if(! strlen($a->user['timezone']))
190 $timezone = date_default_timezone_get();
192 $pageset_tpl = load_view_file('view/pagetypes.tpl');
193 $pagetype = replace_macros($pageset_tpl,array(
194 '$normal' => (($a->user['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
195 '$soapbox' => (($a->user['page-flags'] == PAGE_SOAPBOX) ? " checked=\"checked\" " : ""),
196 '$community' => (($a->user['page-flags'] == PAGE_COMMUNITY) ? " checked=\"checked\" " : ""),
197 '$freelove' => (($a->user['page-flags'] == PAGE_FREELOVE) ? " checked=\"checked\" " : ""),
198 '$page_normal' => PAGE_NORMAL,
199 '$page_soapbox' => PAGE_SOAPBOX,
200 '$page_community' => PAGE_COMMUNITY,
201 '$page_freelove' => PAGE_FREELOVE
204 $noid = get_config('system','no_openid');
210 $oidhtml = '<label id="settings-openid-label" for="settings-openid" >' . t('OpenID: ') . '</label><input type="text" id="settings-openid" class="openid" name="openid_url" value="$openid" />' . t(" \x28Optional\x29 Allow this OpenID to login to this account.");
216 $opt_tpl = load_view_file("view/profile-in-directory.tpl");
217 $profile_in_dir = replace_macros($opt_tpl,array(
218 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
219 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
222 if(strlen(get_config('system','directory_submit_url'))) {
223 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
225 $profile_in_net_dir = replace_macros($opt_tpl,array(
226 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
227 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
231 $profile_in_net_dir = '';
233 $loc_checked = (($a->user['allow_location'] == 1) ? " checked=\"checked\" " : "");
235 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
239 notice( t('Profile is <strong>not published</strong>.') . EOL );
241 $nickname_block = load_view_file("view/settings_nick_set.tpl");
243 $nickname_subdir = '';
244 if(strlen($a->get_path())) {
245 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
246 $nickname_subdir = replace_macros($subdir_tpl, array(
247 '$baseurl' => $a->get_baseurl(),
248 '$nickname' => $nickname,
249 '$hostname' => $a->get_hostname()
253 $theme_selector = '<select name="theme" id="theme-select" >';
254 $files = glob('view/theme/*');
256 foreach($files as $file) {
257 $f = basename($file);
258 $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
259 ? ' selected="selected" ' : '' );
260 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
263 $theme_selector .= '</select>';
266 $nickname_block = replace_macros($nickname_block,array(
267 '$nickname' => $nickname,
268 '$uid' => local_user(),
269 '$subdir' => $nickname_subdir,
270 '$basepath' => $a->get_hostname(),
271 '$baseurl' => $a->get_baseurl()));
273 $stpl = load_view_file('view/settings.tpl');
275 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
277 $o .= replace_macros($stpl,array(
278 '$baseurl' => $a->get_baseurl(),
279 '$oidhtml' => $oidhtml,
280 '$uid' => local_user(),
281 '$username' => $username,
282 '$openid' => $openid,
284 '$nickname_block' => $nickname_block,
285 '$timezone' => $timezone,
286 '$zoneselect' => select_timezone($timezone),
287 '$defloc' => $defloc,
288 '$loc_checked' => $loc_checked,
289 '$profile_in_dir' => $profile_in_dir,
290 '$profile_in_net_dir' => $profile_in_net_dir,
291 '$permissions' => t('Default Post Permissions'),
292 '$visibility' => $profile['net-publish'],
293 '$aclselect' => populate_acl($a->user,$celeb),
294 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
295 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
296 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
297 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
298 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
299 '$maxreq' => $maxreq,
300 '$theme' => $theme_selector,
301 '$pagetype' => $pagetype
304 call_hooks('settings_page',$o);