4 function settings_init(&$a) {
6 profile_load($a,$a->user['nickname']);
12 function settings_post(&$a) {
15 notice( t('Permission denied.') . EOL);
19 if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
20 notice( t('Permission denied.') . EOL);
24 if(($a->argc > 1) && ($a->argv[1] == 'addon')) {
25 call_hooks('plugin_settings_post', $_POST);
29 call_hooks('settings_post', $_POST);
31 if((x($_POST,'npassword')) || (x($_POST,'confirm'))) {
33 $newpass = $_POST['npassword'];
34 $confirm = $_POST['confirm'];
37 if($newpass != $confirm ) {
38 notice( t('Passwords do not match. Password unchanged.') . EOL);
42 if((! x($newpass)) || (! x($confirm))) {
43 notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
48 $password = hash('whirlpool',$newpass);
49 $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d LIMIT 1",
54 notice( t('Password changed.') . EOL);
56 notice( t('Password update failed. Please try again.') . EOL);
60 $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
61 $username = ((x($_POST,'username')) ? notags(trim($_POST['username'])) : '');
62 $email = ((x($_POST,'email')) ? notags(trim($_POST['email'])) : '');
63 $timezone = ((x($_POST,'timezone')) ? notags(trim($_POST['timezone'])) : '');
64 $defloc = ((x($_POST,'defloc')) ? notags(trim($_POST['defloc'])) : '');
65 $openid = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url'])) : '');
66 $maxreq = ((x($_POST,'maxreq')) ? intval($_POST['maxreq']) : 0);
67 $expire = ((x($_POST,'expire')) ? intval($_POST['expire']) : 0);
69 $allow_location = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
70 $publish = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
71 $net_publish = (((x($_POST,'profile_in_netdirectory')) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
72 $old_visibility = (((x($_POST,'visibility')) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
73 $page_flags = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
74 $blockwall = (((x($_POST,'blockwall')) && (intval($_POST['blockwall']) == 1)) ? 0: 1); // this setting is inverted!
78 if(x($_POST,'notify1'))
79 $notify += intval($_POST['notify1']);
80 if(x($_POST,'notify2'))
81 $notify += intval($_POST['notify2']);
82 if(x($_POST,'notify3'))
83 $notify += intval($_POST['notify3']);
84 if(x($_POST,'notify4'))
85 $notify += intval($_POST['notify4']);
86 if(x($_POST,'notify5'))
87 $notify += intval($_POST['notify5']);
89 $email_changed = false;
95 if($username != $a->user['username']) {
97 if(strlen($username) > 40)
98 $err .= t(' Please use a shorter name.');
99 if(strlen($username) < 3)
100 $err .= t(' Name too short.');
103 if($email != $a->user['email']) {
104 $email_changed = true;
105 if(! valid_email($email))
106 $err .= t(' Not valid email.');
107 if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) {
108 $err .= t(' Cannot change to that email.');
109 $email = $a->user['email'];
118 if($timezone != $a->user['timezone']) {
119 if(strlen($timezone))
120 date_default_timezone_set($timezone);
123 $str_group_allow = perms2str($_POST['group_allow']);
124 $str_contact_allow = perms2str($_POST['contact_allow']);
125 $str_group_deny = perms2str($_POST['group_deny']);
126 $str_contact_deny = perms2str($_POST['contact_deny']);
128 $openidserver = $a->user['openidserver'];
130 // If openid has changed or if there's an openid but no openidserver, try and discover it.
132 if($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) {
134 if(strlen($tmp_str) && validate_url($tmp_str)) {
135 logger('updating openidserver');
136 require_once('library/openid.php');
137 $open_id_obj = new LightOpenID;
138 $open_id_obj->identity = $openid;
139 $openidserver = $open_id_obj->discover($open_id_obj->identity);
145 $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, `expire` = %d, `openidserver` = '%s', `blockwall` = %d WHERE `uid` = %d LIMIT 1",
150 dbesc($str_contact_allow),
151 dbesc($str_group_allow),
152 dbesc($str_contact_deny),
153 dbesc($str_group_deny),
157 intval($allow_location),
161 dbesc($openidserver),
166 notice( t('Settings updated.') . EOL);
168 $r = q("UPDATE `profile`
169 SET `publish` = %d, `net-publish` = %d
170 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
172 intval($net_publish),
178 q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self` = 1 LIMIT 1",
180 dbesc(datetime_convert()),
185 if($old_visibility != $net_publish) {
186 // Update global directory in background
187 $url = $_SESSION['my_url'];
188 if($url && strlen(get_config('system','directory_submit_url')))
189 proc_run('php',"include/directory.php","$url");
192 $_SESSION['theme'] = $theme;
193 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
195 // FIXME - set to un-verified, blocked and redirect to logout
199 goaway($a->get_baseurl() . '/settings' );
200 return; // NOTREACHED
204 if(! function_exists('settings_content')) {
205 function settings_content(&$a) {
208 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
211 notice( t('Permission denied.') . EOL );
215 if(($a->argc > 1) && ($a->argv[1] === 'addon')) {
216 $o .= '<h1>' . t('Plugin Settings') . '</h1>';
217 $o .= '<div id="account-settings-link"><a href="settings">' . t('Account Settings') . '</a></div>';
219 $o .= '<form action="settings/addon" method="post" >';
221 $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
223 notice( t('No Plugin settings configured') . EOL);
225 call_hooks('plugin_settings', $o);
230 require_once('include/acl_selectors.php');
232 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
238 $username = $a->user['username'];
239 $email = $a->user['email'];
240 $nickname = $a->user['nickname'];
241 $timezone = $a->user['timezone'];
242 $notify = $a->user['notify-flags'];
243 $defloc = $a->user['default-location'];
244 $openid = $a->user['openid'];
245 $maxreq = $a->user['maxreq'];
246 $expire = ((intval($a->user['expire'])) ? $a->user['expire'] : '');
247 $blockwall = $a->user['blockwall'];
249 if(! strlen($a->user['timezone']))
250 $timezone = date_default_timezone_get();
252 $pageset_tpl = load_view_file('view/pagetypes.tpl');
253 $pagetype = replace_macros($pageset_tpl,array(
254 '$normal' => (($a->user['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
255 '$soapbox' => (($a->user['page-flags'] == PAGE_SOAPBOX) ? " checked=\"checked\" " : ""),
256 '$community' => (($a->user['page-flags'] == PAGE_COMMUNITY) ? " checked=\"checked\" " : ""),
257 '$freelove' => (($a->user['page-flags'] == PAGE_FREELOVE) ? " checked=\"checked\" " : ""),
258 '$page_normal' => PAGE_NORMAL,
259 '$page_soapbox' => PAGE_SOAPBOX,
260 '$page_community' => PAGE_COMMUNITY,
261 '$page_freelove' => PAGE_FREELOVE
264 $noid = get_config('system','no_openid');
270 $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.");
274 if(get_config('system','publish_all')) {
275 $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
278 $opt_tpl = load_view_file("view/profile-in-directory.tpl");
279 $profile_in_dir = replace_macros($opt_tpl,array(
280 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
281 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
285 if(strlen(get_config('system','directory_submit_url'))) {
286 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
288 $profile_in_net_dir = replace_macros($opt_tpl,array(
289 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
290 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
294 $profile_in_net_dir = '';
296 $loc_checked = (($a->user['allow_location'] == 1) ? " checked=\"checked\" " : "");
298 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
302 notice( t('Profile is <strong>not published</strong>.') . EOL );
304 $nickname_block = load_view_file("view/settings_nick_set.tpl");
306 $nickname_subdir = '';
307 if(strlen($a->get_path())) {
308 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
309 $nickname_subdir = replace_macros($subdir_tpl, array(
310 '$baseurl' => $a->get_baseurl(),
311 '$nickname' => $nickname,
312 '$hostname' => $a->get_hostname()
316 $theme_selector = '<select name="theme" id="theme-select" >';
317 $files = glob('view/theme/*');
319 $default_theme = get_config('system','theme');
321 $default_theme = 'default';
324 foreach($files as $file) {
325 $f = basename($file);
326 $selected = (($f == $_SESSION['theme']) || ($f === $default_theme && (! x($_SESSION,'theme')))
327 ? ' selected="selected" ' : '' );
328 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
331 $theme_selector .= '</select>';
334 $nickname_block = replace_macros($nickname_block,array(
335 '$nickname' => $nickname,
336 '$uid' => local_user(),
337 '$subdir' => $nickname_subdir,
338 '$basepath' => $a->get_hostname(),
339 '$baseurl' => $a->get_baseurl()));
341 $stpl = load_view_file('view/settings.tpl');
343 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
345 $uexport = '<div id="uexport-link"><a href="uexport" >' . t('Export Personal Data') . '</a></div>';
348 $o .= replace_macros($stpl,array(
349 '$baseurl' => $a->get_baseurl(),
350 '$oidhtml' => $oidhtml,
351 '$uexport' => $uexport,
352 '$uid' => local_user(),
353 '$username' => $username,
354 '$openid' => $openid,
356 '$nickname_block' => $nickname_block,
357 '$timezone' => $timezone,
358 '$zoneselect' => select_timezone($timezone),
359 '$defloc' => $defloc,
360 '$loc_checked' => $loc_checked,
361 '$profile_in_dir' => $profile_in_dir,
362 '$profile_in_net_dir' => $profile_in_net_dir,
363 '$permissions' => t('Default Post Permissions'),
364 '$visibility' => $profile['net-publish'],
365 '$aclselect' => populate_acl($a->user,$celeb),
366 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
367 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
368 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
369 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
370 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
371 '$maxreq' => $maxreq,
372 '$expire' => $expire,
373 '$blockw_checked' => (($blockwall) ? '' : ' checked="checked" ' ),
374 '$theme' => $theme_selector,
375 '$pagetype' => $pagetype
378 call_hooks('settings_form',$o);
380 $o .= '</form>' . "\r\n";