4 function settings_init(&$a) {
6 profile_load($a,$a->user['nickname']);
11 function settings_post(&$a) {
14 notice( t('Permission denied.') . EOL);
17 if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
18 notice( t('Permission denied.') . EOL);
21 if((x($_POST,'npassword')) || (x($_POST,'confirm'))) {
23 $newpass = $_POST['npassword'];
24 $confirm = $_POST['confirm'];
27 if($newpass != $confirm ) {
28 notice( t('Passwords do not match. Password unchanged.') . EOL);
32 if((! x($newpass)) || (! x($confirm))) {
33 notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
38 $password = hash('whirlpool',$newpass);
39 $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 = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
51 $username = ((x($_POST,'username')) ? notags(trim($_POST['username'])) : '');
52 $email = ((x($_POST,'email')) ? notags(trim($_POST['email'])) : '');
53 $timezone = ((x($_POST,'timezone')) ? notags(trim($_POST['timezone'])) : '');
54 $defloc = ((x($_POST,'defloc')) ? notags(trim($_POST['defloc'])) : '');
55 $openid = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url'])) : '');
56 $maxreq = ((x($_POST,'maxreq')) ? intval($_POST['maxreq']) : 0);
58 $allow_location = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
59 $publish = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
60 $net_publish = (((x($_POST,'profile_in_netdirectory')) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
61 $old_visibility = (((x($_POST,'visibility')) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
62 $page_flags = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
66 if(x($_POST,'notify1'))
67 $notify += intval($_POST['notify1']);
68 if(x($_POST,'notify2'))
69 $notify += intval($_POST['notify2']);
70 if(x($_POST,'notify3'))
71 $notify += intval($_POST['notify3']);
72 if(x($_POST,'notify4'))
73 $notify += intval($_POST['notify4']);
74 if(x($_POST,'notify5'))
75 $notify += intval($_POST['notify5']);
77 $email_changed = false;
81 if($username != $a->user['username']) {
82 if(strlen($username) > 40)
83 $err .= t(' Please use a shorter name.');
84 if(strlen($username) < 3)
85 $err .= t(' Name too short.');
88 if($email != $a->user['email']) {
89 $email_changed = true;
90 if(! valid_email($email))
91 $err .= t(' Not valid email.');
99 if($timezone != $a->user['timezone']) {
100 if(strlen($timezone))
101 date_default_timezone_set($timezone);
104 $str_group_allow = perms2str($_POST['group_allow']);
105 $str_contact_allow = perms2str($_POST['contact_allow']);
106 $str_group_deny = perms2str($_POST['group_deny']);
107 $str_contact_deny = perms2str($_POST['contact_deny']);
109 $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",
114 dbesc($str_contact_allow),
115 dbesc($str_group_allow),
116 dbesc($str_contact_deny),
117 dbesc($str_group_deny),
121 intval($allow_location),
127 notice( t('Settings updated.') . EOL);
129 $r = q("UPDATE `profile`
130 SET `publish` = %d, `net-publish` = %d
131 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
133 intval($net_publish),
137 if($old_visibility != $net_publish) {
138 // Update global directory in background
139 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
140 $url = $_SESSION['my_url'];
141 if($url && strlen(get_config('system','directory_submit_url')))
142 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
146 $_SESSION['theme'] = $theme;
147 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
149 // FIXME - set to un-verified, blocked and redirect to logout
153 goaway($a->get_baseurl() . '/settings' );
154 return; // NOTREACHED
158 if(! function_exists('settings_content')) {
159 function settings_content(&$a) {
162 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
165 notice( t('Permission denied.') . EOL );
169 require_once('include/acl_selectors.php');
171 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
177 $username = $a->user['username'];
178 $email = $a->user['email'];
179 $nickname = $a->user['nickname'];
180 $timezone = $a->user['timezone'];
181 $notify = $a->user['notify-flags'];
182 $defloc = $a->user['default-location'];
183 $openid = $a->user['openid'];
184 $maxreq = $a->user['maxreq'];
186 if(! strlen($a->user['timezone']))
187 $timezone = date_default_timezone_get();
189 $pageset_tpl = load_view_file('view/pagetypes.tpl');
190 $pagetype = replace_macros($pageset_tpl,array(
191 '$normal' => (($a->user['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
192 '$soapbox' => (($a->user['page-flags'] == PAGE_SOAPBOX) ? " checked=\"checked\" " : ""),
193 '$community' => (($a->user['page-flags'] == PAGE_COMMUNITY) ? " checked=\"checked\" " : ""),
194 '$freelove' => (($a->user['page-flags'] == PAGE_FREELOVE) ? " checked=\"checked\" " : ""),
195 '$page_normal' => PAGE_NORMAL,
196 '$page_soapbox' => PAGE_SOAPBOX,
197 '$page_community' => PAGE_COMMUNITY,
198 '$page_freelove' => PAGE_FREELOVE
201 $noid = get_config('system','no_openid');
207 $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.");
213 $opt_tpl = load_view_file("view/profile-in-directory.tpl");
214 $profile_in_dir = replace_macros($opt_tpl,array(
215 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
216 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
219 if(strlen(get_config('system','directory_submit_url'))) {
220 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
222 $profile_in_net_dir = replace_macros($opt_tpl,array(
223 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
224 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
228 $profile_in_net_dir = '';
230 $loc_checked = (($a->user['allow_location'] == 1) ? " checked=\"checked\" " : "");
232 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
236 notice( t('Profile is <strong>not published</strong>.') . EOL );
238 $nickname_block = load_view_file("view/settings_nick_set.tpl");
240 $nickname_subdir = '';
241 if(strlen($a->get_path())) {
242 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
243 $nickname_subdir = replace_macros($subdir_tpl, array(
244 '$baseurl' => $a->get_baseurl(),
245 '$nickname' => $nickname,
246 '$hostname' => $a->get_hostname()
250 $theme_selector = '<select name="theme" id="theme-select" >';
251 $files = glob('view/theme/*');
253 foreach($files as $file) {
254 $f = basename($file);
255 $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
256 ? ' selected="selected" ' : '' );
257 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
260 $theme_selector .= '</select>';
263 $nickname_block = replace_macros($nickname_block,array(
264 '$nickname' => $nickname,
265 '$uid' => local_user(),
266 '$subdir' => $nickname_subdir,
267 '$basepath' => $a->get_hostname(),
268 '$baseurl' => $a->get_baseurl()));
270 $stpl = load_view_file('view/settings.tpl');
272 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
274 $o .= replace_macros($stpl,array(
275 '$baseurl' => $a->get_baseurl(),
276 '$oidhtml' => $oidhtml,
277 '$uid' => local_user(),
278 '$username' => $username,
279 '$openid' => $openid,
281 '$nickname_block' => $nickname_block,
282 '$timezone' => $timezone,
283 '$zoneselect' => select_timezone($timezone),
284 '$defloc' => $defloc,
285 '$loc_checked' => $loc_checked,
286 '$profile_in_dir' => $profile_in_dir,
287 '$profile_in_net_dir' => $profile_in_net_dir,
288 '$permissions' => t('Default Post Permissions'),
289 '$visibility' => $profile['net-publish'],
290 '$aclselect' => populate_acl($a->user,$celeb),
291 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
292 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
293 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
294 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
295 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
296 '$maxreq' => $maxreq,
297 '$theme' => $theme_selector,
298 '$pagetype' => $pagetype