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,
262 '$n_l' => t('Normal Account'),
263 '$n_d' => t('This account is a normal personal profile'),
264 '$s_l' => t('Soapbox Account'),
265 '$s_d' => t('Automatically approve all connection/friend requests as read-only fans'),
266 '$c_l' => t('Community/Celebrity Account'),
267 '$c_d' => t('Automatically approve all connection/friend requests as read-write fans'),
268 '$f_l' => t('Automatic Friend Account'),
269 '$f_d' => t('Automatically approve all connection/friend requests as friends')
272 $noid = get_config('system','no_openid');
278 $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.");
282 if(get_config('system','publish_all')) {
283 $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
286 $opt_tpl = load_view_file("view/profile-in-directory.tpl");
287 $profile_in_dir = replace_macros($opt_tpl,array(
288 '$desc' => t('Publish your default profile in site directory?'),
289 '$yes_str' => t('Yes'),
290 '$no_str' => t('No'),
291 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
292 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
296 if(strlen(get_config('system','directory_submit_url'))) {
297 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
299 $profile_in_net_dir = replace_macros($opt_tpl,array(
300 '$desc' => t('Publish your default profile in global social directory?'),
301 '$yes_str' => t('Yes'),
302 '$no_str' => t('No'),
303 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
304 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
308 $profile_in_net_dir = '';
310 $loc_checked = (($a->user['allow_location'] == 1) ? " checked=\"checked\" " : "");
312 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
316 notice( t('Profile is <strong>not published</strong>.') . EOL );
319 $theme_selector = '<select name="theme" id="theme-select" >';
320 $files = glob('view/theme/*');
322 $default_theme = get_config('system','theme');
324 $default_theme = 'default';
327 foreach($files as $file) {
328 $f = basename($file);
329 $selected = (($f == $_SESSION['theme']) || ($f === $default_theme && (! x($_SESSION,'theme')))
330 ? ' selected="selected" ' : '' );
331 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
335 $theme_selector .= '</select>';
337 $subdir = ((strlen($a->get_path())) ? '<br />' . t('or') . ' ' . $a->get_baseurl() . '/profile/' . $nickname : '');
339 $tpl_addr = load_view_file("view/settings_nick_set.tpl");
341 $prof_addr = replace_macros($tpl_addr,array(
342 '$desc' => t('Your Identity Address is'),
343 '$nickname' => $nickname,
344 '$subdir' => $subdir,
345 '$basepath' => $a->get_hostname()
348 $stpl = load_view_file('view/settings.tpl');
350 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
352 $uexport = '<div id="uexport-link"><a href="uexport" >' . t('Export Personal Data') . '</a></div>';
355 $o .= replace_macros($stpl,array(
356 '$ptitle' => t('Account Settings'),
357 '$lbl_plug' => t('Plugin Settings'),
358 '$lbl_basic' => t('Basic Settings'),
359 '$lbl_fn' => t('Full Name:'),
360 '$lbl_email' => t('Email Address:'),
361 '$lbl_tz' => t('Your Timezone:'),
362 '$lbl_loc1' => t('Default Post Location:'),
363 '$lbl_loc2' => t('Use Browser Location:'),
364 '$lbl_theme' => t('Display Theme:'),
365 '$submit' => t('Submit'),
366 '$lbl_prv' => t('Security and Privacy Settings'),
367 '$lbl_maxreq' => t('Maximum Friend Requests/Day:'),
368 '$lbl_maxrdesc' => t("\x28to prevent spam abuse\x29"),
369 '$lbl_rempost' => t('Allow friends to post to your profile page:'),
370 '$lbl_exp1' => t("Automatically expire \x28delete\x29 posts older than"),
371 '$lbl_exp2' => t('days'),
372 '$lbl_not1' => t('Notification Settings'),
373 '$lbl_not2' => t('Send a notification email when:'),
374 '$lbl_not3' => t('You receive an introduction'),
375 '$lbl_not4' => t('Your introductions are confirmed'),
376 '$lbl_not5' => t('Someone writes on your profile wall'),
377 '$lbl_not6' => t('Someone writes a followup comment'),
378 '$lbl_not7' => t('You receive a private message'),
379 '$lbl_pass1' => t('Password Settings'),
380 '$lbl_pass2' => t('Leave password fields blank unless changing'),
381 '$lbl_pass3' => t('New Password:'),
382 '$lbl_pass4' => t('Confirm:'),
383 '$lbl_advn' => t('Advanced Page Settings'),
384 '$baseurl' => $a->get_baseurl(),
385 '$oidhtml' => $oidhtml,
386 '$uexport' => $uexport,
387 '$uid' => local_user(),
388 '$username' => $username,
389 '$openid' => $openid,
391 '$nickname_block' => $prof_addr,
392 '$timezone' => $timezone,
393 '$zoneselect' => select_timezone($timezone),
394 '$defloc' => $defloc,
395 '$loc_checked' => $loc_checked,
396 '$profile_in_dir' => $profile_in_dir,
397 '$profile_in_net_dir' => $profile_in_net_dir,
398 '$permissions' => t('Default Post Permissions'),
399 '$permdesc' => t("\x28click to open/close\x29"),
400 '$visibility' => $profile['net-publish'],
401 '$aclselect' => populate_acl($a->user,$celeb),
402 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
403 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
404 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
405 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
406 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
407 '$maxreq' => $maxreq,
408 '$expire' => $expire,
409 '$blockw_checked' => (($blockwall) ? '' : ' checked="checked" ' ),
410 '$theme' => $theme_selector,
411 '$pagetype' => $pagetype
414 call_hooks('settings_form',$o);
416 $o .= '</form>' . "\r\n";