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!
76 $mail_server = ((x($_POST,'mail_server')) ? $_POST['mail_server'] : '');
77 $mail_port = ((x($_POST,'mail_port')) ? $_POST['mail_port'] : '');
78 $mail_ssl = ((x($_POST,'mail_ssl')) ? strtolower(trim($_POST['mail_ssl'])) : '');
79 $mail_user = ((x($_POST,'mail_user')) ? $_POST['mail_user'] : '');
80 $mail_pass = ((x($_POST,'mail_pass')) ? trim($_POST['mail_pass']) : '');
81 $mail_replyto = ((x($_POST,'mail_replyto')) ? $_POST['mail_replyto'] : '');
82 $mail_pubmail = ((x($_POST,'mail_pubmail')) ? $_POST['mail_pubmail'] : '');
85 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
87 if(! $mail_disabled) {
88 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
92 q("INSERT INTO `mailacct` (`uid`) VALUES (%d)",
96 if(strlen($mail_pass)) {
98 openssl_public_encrypt($mail_pass,$pass,$a->user['pubkey']);
99 q("UPDATE `mailacct` SET `pass` = '%s' WHERE `uid` = %d LIMIT 1",
100 dbesc(bin2hex($pass)),
104 $r = q("UPDATE `mailacct` SET `server` = '%s', `port` = %d, `ssltype` = '%s', `user` = '%s',
105 `mailbox` = 'INBOX', `reply_to` = '%s', `pubmail` = %d WHERE `uid` = %d LIMIT 1",
110 dbesc($mail_replyto),
111 intval($mail_pubmail),
118 if(x($_POST,'notify1'))
119 $notify += intval($_POST['notify1']);
120 if(x($_POST,'notify2'))
121 $notify += intval($_POST['notify2']);
122 if(x($_POST,'notify3'))
123 $notify += intval($_POST['notify3']);
124 if(x($_POST,'notify4'))
125 $notify += intval($_POST['notify4']);
126 if(x($_POST,'notify5'))
127 $notify += intval($_POST['notify5']);
129 $email_changed = false;
133 $name_change = false;
135 if($username != $a->user['username']) {
137 if(strlen($username) > 40)
138 $err .= t(' Please use a shorter name.');
139 if(strlen($username) < 3)
140 $err .= t(' Name too short.');
143 if($email != $a->user['email']) {
144 $email_changed = true;
145 if(! valid_email($email))
146 $err .= t(' Not valid email.');
147 if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) {
148 $err .= t(' Cannot change to that email.');
149 $email = $a->user['email'];
158 if($timezone != $a->user['timezone']) {
159 if(strlen($timezone))
160 date_default_timezone_set($timezone);
163 $str_group_allow = perms2str($_POST['group_allow']);
164 $str_contact_allow = perms2str($_POST['contact_allow']);
165 $str_group_deny = perms2str($_POST['group_deny']);
166 $str_contact_deny = perms2str($_POST['contact_deny']);
168 $openidserver = $a->user['openidserver'];
170 // If openid has changed or if there's an openid but no openidserver, try and discover it.
172 if($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) {
174 if(strlen($tmp_str) && validate_url($tmp_str)) {
175 logger('updating openidserver');
176 require_once('library/openid.php');
177 $open_id_obj = new LightOpenID;
178 $open_id_obj->identity = $openid;
179 $openidserver = $open_id_obj->discover($open_id_obj->identity);
185 $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",
190 dbesc($str_contact_allow),
191 dbesc($str_group_allow),
192 dbesc($str_contact_deny),
193 dbesc($str_group_deny),
197 intval($allow_location),
201 dbesc($openidserver),
206 notice( t('Settings updated.') . EOL);
208 $r = q("UPDATE `profile`
209 SET `publish` = %d, `net-publish` = %d
210 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
212 intval($net_publish),
218 q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self` = 1 LIMIT 1",
220 dbesc(datetime_convert()),
225 if($old_visibility != $net_publish) {
226 // Update global directory in background
227 $url = $_SESSION['my_url'];
228 if($url && strlen(get_config('system','directory_submit_url')))
229 proc_run('php',"include/directory.php","$url");
232 $_SESSION['theme'] = $theme;
233 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
235 // FIXME - set to un-verified, blocked and redirect to logout
239 goaway($a->get_baseurl() . '/settings' );
240 return; // NOTREACHED
244 if(! function_exists('settings_content')) {
245 function settings_content(&$a) {
248 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
251 notice( t('Permission denied.') . EOL );
255 if(($a->argc > 1) && ($a->argv[1] === 'addon')) {
256 $o .= '<h1>' . t('Plugin Settings') . '</h1>';
257 $o .= '<div id="account-settings-link"><a href="settings">' . t('Account Settings') . '</a></div>';
259 $o .= '<form action="settings/addon" method="post" >';
261 $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
263 notice( t('No Plugin settings configured') . EOL);
265 call_hooks('plugin_settings', $o);
270 require_once('include/acl_selectors.php');
272 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
278 $username = $a->user['username'];
279 $email = $a->user['email'];
280 $nickname = $a->user['nickname'];
281 $timezone = $a->user['timezone'];
282 $notify = $a->user['notify-flags'];
283 $defloc = $a->user['default-location'];
284 $openid = $a->user['openid'];
285 $maxreq = $a->user['maxreq'];
286 $expire = ((intval($a->user['expire'])) ? $a->user['expire'] : '');
287 $blockwall = $a->user['blockwall'];
289 if(! strlen($a->user['timezone']))
290 $timezone = date_default_timezone_get();
293 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
295 if(! $mail_disabled) {
296 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
302 $imap_disabled = (($mail_disabled) ? ' disabled="disabled" ' : '');
305 $mail_server = ((count($r)) ? $r[0]['server'] : '');
306 $mail_port = ((count($r) && intval($r[0]['port'])) ? intval($r[0]['port']) : '');
307 $mail_ssl = ((count($r)) ? $r[0]['ssltype'] : '');
308 $mail_user = ((count($r)) ? $r[0]['user'] : '');
309 $mail_replyto = ((count($r)) ? $r[0]['reply_to'] : '');
310 $mail_pubmail = ((count($r)) ? $r[0]['pubmail'] : 0);
313 $pageset_tpl = get_markup_template('pagetypes.tpl');
314 $pagetype = replace_macros($pageset_tpl,array(
315 '$normal' => (($a->user['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
316 '$soapbox' => (($a->user['page-flags'] == PAGE_SOAPBOX) ? " checked=\"checked\" " : ""),
317 '$community' => (($a->user['page-flags'] == PAGE_COMMUNITY) ? " checked=\"checked\" " : ""),
318 '$freelove' => (($a->user['page-flags'] == PAGE_FREELOVE) ? " checked=\"checked\" " : ""),
319 '$page_normal' => PAGE_NORMAL,
320 '$page_soapbox' => PAGE_SOAPBOX,
321 '$page_community' => PAGE_COMMUNITY,
322 '$page_freelove' => PAGE_FREELOVE,
323 '$n_l' => t('Normal Account'),
324 '$n_d' => t('This account is a normal personal profile'),
325 '$s_l' => t('Soapbox Account'),
326 '$s_d' => t('Automatically approve all connection/friend requests as read-only fans'),
327 '$c_l' => t('Community/Celebrity Account'),
328 '$c_d' => t('Automatically approve all connection/friend requests as read-write fans'),
329 '$f_l' => t('Automatic Friend Account'),
330 '$f_d' => t('Automatically approve all connection/friend requests as friends')
333 $noid = get_config('system','no_openid');
339 $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.");
343 if(get_config('system','publish_all')) {
344 $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
347 $opt_tpl = get_markup_template("profile-in-directory.tpl");
348 $profile_in_dir = replace_macros($opt_tpl,array(
349 '$desc' => t('Publish your default profile in site directory?'),
350 '$yes_str' => t('Yes'),
351 '$no_str' => t('No'),
352 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
353 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
357 if(strlen(get_config('system','directory_submit_url'))) {
358 $opt_tpl = get_markup_template("profile-in-netdir.tpl");
360 $profile_in_net_dir = replace_macros($opt_tpl,array(
361 '$desc' => t('Publish your default profile in global social directory?'),
362 '$yes_str' => t('Yes'),
363 '$no_str' => t('No'),
364 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
365 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
369 $profile_in_net_dir = '';
371 $loc_checked = (($a->user['allow_location'] == 1) ? " checked=\"checked\" " : "");
373 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
377 notice( t('Profile is <strong>not published</strong>.') . EOL );
380 $theme_selector = '<select name="theme" id="theme-select" >';
381 $files = glob('view/theme/*');
383 $default_theme = get_config('system','theme');
385 $default_theme = 'default';
388 foreach($files as $file) {
389 $f = basename($file);
390 $selected = (($f == $_SESSION['theme']) || ($f === $default_theme && (! x($_SESSION,'theme')))
391 ? ' selected="selected" ' : '' );
392 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
396 $theme_selector .= '</select>';
398 $subdir = ((strlen($a->get_path())) ? '<br />' . t('or') . ' ' . $a->get_baseurl() . '/profile/' . $nickname : '');
400 $tpl_addr = get_markup_template("settings_nick_set.tpl");
402 $prof_addr = replace_macros($tpl_addr,array(
403 '$desc' => t('Your Identity Address is'),
404 '$nickname' => $nickname,
405 '$subdir' => $subdir,
406 '$basepath' => $a->get_hostname()
409 $stpl = get_markup_template('settings.tpl');
411 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
413 $uexport = '<div id="uexport-link"><a href="uexport" >' . t('Export Personal Data') . '</a></div>';
416 $o .= replace_macros($stpl,array(
417 '$ptitle' => t('Account Settings'),
418 '$lbl_plug' => t('Plugin Settings'),
419 '$lbl_basic' => t('Basic Settings'),
420 '$lbl_fn' => t('Full Name:'),
421 '$lbl_email' => t('Email Address:'),
422 '$lbl_tz' => t('Your Timezone:'),
423 '$lbl_loc1' => t('Default Post Location:'),
424 '$lbl_loc2' => t('Use Browser Location:'),
425 '$lbl_theme' => t('Display Theme:'),
426 '$submit' => t('Submit'),
427 '$lbl_prv' => t('Security and Privacy Settings'),
428 '$lbl_maxreq' => t('Maximum Friend Requests/Day:'),
429 '$lbl_maxrdesc' => t("\x28to prevent spam abuse\x29"),
430 '$lbl_rempost' => t('Allow friends to post to your profile page:'),
431 '$lbl_exp1' => t("Automatically expire \x28delete\x29 posts older than"),
432 '$lbl_exp2' => t('days'),
433 '$lbl_not1' => t('Notification Settings'),
434 '$lbl_not2' => t('Send a notification email when:'),
435 '$lbl_not3' => t('You receive an introduction'),
436 '$lbl_not4' => t('Your introductions are confirmed'),
437 '$lbl_not5' => t('Someone writes on your profile wall'),
438 '$lbl_not6' => t('Someone writes a followup comment'),
439 '$lbl_not7' => t('You receive a private message'),
440 '$lbl_pass1' => t('Password Settings'),
441 '$lbl_pass2' => t('Leave password fields blank unless changing'),
442 '$lbl_pass3' => t('New Password:'),
443 '$lbl_pass4' => t('Confirm:'),
444 '$lbl_advn' => t('Advanced Page Settings'),
445 '$baseurl' => $a->get_baseurl(),
446 '$oidhtml' => $oidhtml,
447 '$uexport' => $uexport,
448 '$uid' => local_user(),
449 '$username' => $username,
450 '$openid' => $openid,
452 '$nickname_block' => $prof_addr,
453 '$timezone' => $timezone,
454 '$zoneselect' => select_timezone($timezone),
455 '$defloc' => $defloc,
456 '$loc_checked' => $loc_checked,
457 '$profile_in_dir' => $profile_in_dir,
458 '$profile_in_net_dir' => $profile_in_net_dir,
459 '$permissions' => t('Default Post Permissions'),
460 '$permdesc' => t("\x28click to open/close\x29"),
461 '$visibility' => $profile['net-publish'],
462 '$aclselect' => populate_acl($a->user,$celeb),
463 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
464 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
465 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
466 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
467 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
468 '$maxreq' => $maxreq,
469 '$expire' => $expire,
470 '$blockw_checked' => (($blockwall) ? '' : ' checked="checked" ' ),
471 '$theme' => $theme_selector,
472 '$pagetype' => $pagetype,
473 '$lbl_imap0' => t('Email/Mailbox Setup'),
474 '$imap_desc' => t("If you wish to communicate with email contacts using this service \x28optional\x29, please specify how to connect to your mailbox."),
475 '$lbl_imap1' => t('IMAP server name:'),
476 '$imap_server' => $mail_server,
477 '$lbl_imap2' => t('IMAP port:'),
478 '$imap_port' => $mail_port,
479 '$lbl_imap3' => t("Security \x28TLS or SSL\x29:"),
480 '$imap_ssl' => $mail_ssl,
481 '$lbl_imap4' => t('Email login name:'),
482 '$imap_user' => $mail_user,
483 '$lbl_imap5' => t('Email password:'),
484 '$lbl_imap6' => t("Reply-to address \x28Optional\x29:"),
485 '$imap_replyto' => $mail_replyto,
486 '$lbl_imap7' => t('Send public posts to all email contacts:'),
487 '$pubmail_checked' => (($mail_pubmail) ? ' checked="checked" ' : ''),
488 '$mail_disabled' => (($mail_disabled) ? '<div class="error-message">' . t('Email access is disabled on this site.') . '</div>' : ''),
489 '$imap_disabled' => $imap_disabled
492 call_hooks('settings_form',$o);
494 $o .= '</form>' . "\r\n";