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'])) : '');
57 $allow_location = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
58 $publish = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
59 $net_publish = (((x($_POST,'profile_in_netdirectory')) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
60 $old_visibility = (((x($_POST,'visibility')) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
61 $page_flags = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
65 if(x($_POST,'notify1'))
66 $notify += intval($_POST['notify1']);
67 if(x($_POST,'notify2'))
68 $notify += intval($_POST['notify2']);
69 if(x($_POST,'notify3'))
70 $notify += intval($_POST['notify3']);
71 if(x($_POST,'notify4'))
72 $notify += intval($_POST['notify4']);
73 if(x($_POST,'notify5'))
74 $notify += intval($_POST['notify5']);
76 $email_changed = false;
80 if($username != $a->user['username']) {
81 if(strlen($username) > 40)
82 $err .= t(' Please use a shorter name.');
83 if(strlen($username) < 3)
84 $err .= t(' Name too short.');
87 if($email != $a->user['email']) {
88 $email_changed = true;
89 if(! valid_email($email))
90 $err .= t(' Not valid email.');
98 if($timezone != $a->user['timezone']) {
100 date_default_timezone_set($timezone);
103 $str_group_allow = perms2str($_POST['group_allow']);
104 $str_contact_allow = perms2str($_POST['contact_allow']);
105 $str_group_deny = perms2str($_POST['group_deny']);
106 $str_contact_deny = perms2str($_POST['contact_deny']);
108 $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' WHERE `uid` = %d LIMIT 1",
113 dbesc($str_contact_allow),
114 dbesc($str_group_allow),
115 dbesc($str_contact_deny),
116 dbesc($str_group_deny),
120 intval($allow_location),
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) {
160 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
163 notice( t('Permission denied.') . EOL );
167 require_once('include/acl_selectors.php');
169 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
175 $username = $a->user['username'];
176 $email = $a->user['email'];
177 $nickname = $a->user['nickname'];
178 $timezone = $a->user['timezone'];
179 $notify = $a->user['notify-flags'];
180 $defloc = $a->user['default-location'];
181 $openid = $a->user['openid'];
183 if(! strlen($a->user['timezone']))
184 $timezone = date_default_timezone_get();
186 $pageset_tpl = load_view_file('view/pagetypes.tpl');
187 $pagetype = replace_macros($pageset_tpl,array(
188 '$normal' => (($a->user['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
189 '$soapbox' => (($a->user['page-flags'] == PAGE_SOAPBOX) ? " checked=\"checked\" " : ""),
190 '$community' => (($a->user['page-flags'] == PAGE_COMMUNITY) ? " checked=\"checked\" " : ""),
191 '$freelove' => (($a->user['page-flags'] == PAGE_FREELOVE) ? " checked=\"checked\" " : ""),
192 '$page_normal' => PAGE_NORMAL,
193 '$page_soapbox' => PAGE_SOAPBOX,
194 '$page_community' => PAGE_COMMUNITY,
195 '$page_freelove' => PAGE_FREELOVE
198 $noid = get_config('system','no_openid');
204 $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.");
210 $opt_tpl = load_view_file("view/profile-in-directory.tpl");
211 $profile_in_dir = replace_macros($opt_tpl,array(
212 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
213 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
216 if(strlen(get_config('system','directory_submit_url'))) {
217 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
219 $profile_in_net_dir = replace_macros($opt_tpl,array(
220 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
221 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
225 $profile_in_net_dir = '';
227 $loc_checked = (($a->user['allow_location'] == 1) ? " checked=\"checked\" " : "");
229 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
233 notice( t('Profile is <strong>not published</strong>.') . EOL );
235 $nickname_block = load_view_file("view/settings_nick_set.tpl");
237 $nickname_subdir = '';
238 if(strlen($a->get_path())) {
239 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
240 $nickname_subdir = replace_macros($subdir_tpl, array(
241 '$baseurl' => $a->get_baseurl(),
242 '$nickname' => $nickname,
243 '$hostname' => $a->get_hostname()
247 $theme_selector = '<select name="theme" id="theme-select" >';
248 $files = glob('view/theme/*');
250 foreach($files as $file) {
251 $f = basename($file);
252 $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
253 ? ' selected="selected" ' : '' );
254 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
257 $theme_selector .= '</select>';
260 $nickname_block = replace_macros($nickname_block,array(
261 '$nickname' => $nickname,
262 '$uid' => local_user(),
263 '$subdir' => $nickname_subdir,
264 '$basepath' => $a->get_hostname(),
265 '$baseurl' => $a->get_baseurl()));
267 $stpl = load_view_file('view/settings.tpl');
269 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
271 $o .= replace_macros($stpl,array(
272 '$baseurl' => $a->get_baseurl(),
273 '$oidhtml' => $oidhtml,
274 '$uid' => local_user(),
275 '$username' => $username,
276 '$openid' => $openid,
278 '$nickname_block' => $nickname_block,
279 '$timezone' => $timezone,
280 '$zoneselect' => select_timezone($timezone),
281 '$defloc' => $defloc,
282 '$loc_checked' => $loc_checked,
283 '$profile_in_dir' => $profile_in_dir,
284 '$profile_in_net_dir' => $profile_in_net_dir,
285 '$permissions' => t('Default Post Permissions'),
286 '$visibility' => $profile['net-publish'],
287 '$aclselect' => populate_acl($a->user,$celeb),
288 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
289 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
290 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
291 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
292 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
293 '$theme' => $theme_selector,
294 '$pagetype' => $pagetype