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 info( 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),
114 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
119 require_once('include/email.php');
120 $mb = construct_mailbox_name($eacct);
121 if(strlen($eacct['server'])) {
123 openssl_private_decrypt(hex2bin($eacct['pass']),$dcrpass,$a->user['prvkey']);
124 $mbox = email_connect($mb,$mail_user,$dcrpass);
127 notice( t('Failed to connect with email account using the settings provided.') . EOL);
134 if(x($_POST,'notify1'))
135 $notify += intval($_POST['notify1']);
136 if(x($_POST,'notify2'))
137 $notify += intval($_POST['notify2']);
138 if(x($_POST,'notify3'))
139 $notify += intval($_POST['notify3']);
140 if(x($_POST,'notify4'))
141 $notify += intval($_POST['notify4']);
142 if(x($_POST,'notify5'))
143 $notify += intval($_POST['notify5']);
145 $email_changed = false;
149 $name_change = false;
151 if($username != $a->user['username']) {
153 if(strlen($username) > 40)
154 $err .= t(' Please use a shorter name.');
155 if(strlen($username) < 3)
156 $err .= t(' Name too short.');
159 if($email != $a->user['email']) {
160 $email_changed = true;
161 if(! valid_email($email))
162 $err .= t(' Not valid email.');
163 if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) {
164 $err .= t(' Cannot change to that email.');
165 $email = $a->user['email'];
174 if($timezone != $a->user['timezone']) {
175 if(strlen($timezone))
176 date_default_timezone_set($timezone);
179 $str_group_allow = perms2str($_POST['group_allow']);
180 $str_contact_allow = perms2str($_POST['contact_allow']);
181 $str_group_deny = perms2str($_POST['group_deny']);
182 $str_contact_deny = perms2str($_POST['contact_deny']);
184 $openidserver = $a->user['openidserver'];
186 // If openid has changed or if there's an openid but no openidserver, try and discover it.
188 if($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) {
190 if(strlen($tmp_str) && validate_url($tmp_str)) {
191 logger('updating openidserver');
192 require_once('library/openid.php');
193 $open_id_obj = new LightOpenID;
194 $open_id_obj->identity = $openid;
195 $openidserver = $open_id_obj->discover($open_id_obj->identity);
201 $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",
206 dbesc($str_contact_allow),
207 dbesc($str_group_allow),
208 dbesc($str_contact_deny),
209 dbesc($str_group_deny),
213 intval($allow_location),
217 dbesc($openidserver),
222 info( t('Settings updated.') . EOL);
224 $r = q("UPDATE `profile`
225 SET `publish` = %d, `net-publish` = %d
226 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
228 intval($net_publish),
234 q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self` = 1 LIMIT 1",
236 dbesc(datetime_convert()),
241 if($old_visibility != $net_publish) {
242 // Update global directory in background
243 $url = $_SESSION['my_url'];
244 if($url && strlen(get_config('system','directory_submit_url')))
245 proc_run('php',"include/directory.php","$url");
248 $_SESSION['theme'] = $theme;
249 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
251 // FIXME - set to un-verified, blocked and redirect to logout
255 goaway($a->get_baseurl() . '/settings' );
256 return; // NOTREACHED
260 if(! function_exists('settings_content')) {
261 function settings_content(&$a) {
264 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
267 notice( t('Permission denied.') . EOL );
271 if(($a->argc > 1) && ($a->argv[1] === 'addon')) {
272 $o .= '<h1>' . t('Plugin Settings') . '</h1>';
273 $o .= '<div id="account-settings-link"><a href="settings">' . t('Account Settings') . '</a></div>';
275 $o .= '<form action="settings/addon" method="post" >';
277 $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
279 notice( t('No Plugin settings configured') . EOL);
281 call_hooks('plugin_settings', $o);
286 require_once('include/acl_selectors.php');
288 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
294 $username = $a->user['username'];
295 $email = $a->user['email'];
296 $nickname = $a->user['nickname'];
297 $timezone = $a->user['timezone'];
298 $notify = $a->user['notify-flags'];
299 $defloc = $a->user['default-location'];
300 $openid = $a->user['openid'];
301 $maxreq = $a->user['maxreq'];
302 $expire = ((intval($a->user['expire'])) ? $a->user['expire'] : '');
303 $blockwall = $a->user['blockwall'];
305 if(! strlen($a->user['timezone']))
306 $timezone = date_default_timezone_get();
309 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
311 if(! $mail_disabled) {
312 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
318 $imap_disabled = (($mail_disabled) ? ' disabled="disabled" ' : '');
321 $mail_server = ((count($r)) ? $r[0]['server'] : '');
322 $mail_port = ((count($r) && intval($r[0]['port'])) ? intval($r[0]['port']) : '');
323 $mail_ssl = ((count($r)) ? $r[0]['ssltype'] : '');
324 $mail_user = ((count($r)) ? $r[0]['user'] : '');
325 $mail_replyto = ((count($r)) ? $r[0]['reply_to'] : '');
326 $mail_pubmail = ((count($r)) ? $r[0]['pubmail'] : 0);
327 $mail_chk = ((count($r)) ? $r[0]['last_check'] : '0000-00-00 00:00:00');
329 $pageset_tpl = get_markup_template('pagetypes.tpl');
330 $pagetype = replace_macros($pageset_tpl,array(
331 '$normal' => (($a->user['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
332 '$soapbox' => (($a->user['page-flags'] == PAGE_SOAPBOX) ? " checked=\"checked\" " : ""),
333 '$community' => (($a->user['page-flags'] == PAGE_COMMUNITY) ? " checked=\"checked\" " : ""),
334 '$freelove' => (($a->user['page-flags'] == PAGE_FREELOVE) ? " checked=\"checked\" " : ""),
335 '$page_normal' => PAGE_NORMAL,
336 '$page_soapbox' => PAGE_SOAPBOX,
337 '$page_community' => PAGE_COMMUNITY,
338 '$page_freelove' => PAGE_FREELOVE,
339 '$n_l' => t('Normal Account'),
340 '$n_d' => t('This account is a normal personal profile'),
341 '$s_l' => t('Soapbox Account'),
342 '$s_d' => t('Automatically approve all connection/friend requests as read-only fans'),
343 '$c_l' => t('Community/Celebrity Account'),
344 '$c_d' => t('Automatically approve all connection/friend requests as read-write fans'),
345 '$f_l' => t('Automatic Friend Account'),
346 '$f_d' => t('Automatically approve all connection/friend requests as friends')
349 $noid = get_config('system','no_openid');
355 $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.");
359 if(get_config('system','publish_all')) {
360 $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
363 $opt_tpl = get_markup_template("profile-in-directory.tpl");
364 $profile_in_dir = replace_macros($opt_tpl,array(
365 '$desc' => t('Publish your default profile in site directory?'),
366 '$yes_str' => t('Yes'),
367 '$no_str' => t('No'),
368 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
369 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
373 if(strlen(get_config('system','directory_submit_url'))) {
374 $opt_tpl = get_markup_template("profile-in-netdir.tpl");
376 $profile_in_net_dir = replace_macros($opt_tpl,array(
377 '$desc' => t('Publish your default profile in global social directory?'),
378 '$yes_str' => t('Yes'),
379 '$no_str' => t('No'),
380 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
381 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
385 $profile_in_net_dir = '';
387 $loc_checked = (($a->user['allow_location'] == 1) ? " checked=\"checked\" " : "");
389 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
393 info( t('Profile is <strong>not published</strong>.') . EOL );
396 $theme_selector = '<select name="theme" id="theme-select" >';
397 $files = glob('view/theme/*');
399 $default_theme = get_config('system','theme');
401 $default_theme = 'default';
404 foreach($files as $file) {
405 $f = basename($file);
406 $selected = (($f == $_SESSION['theme']) || ($f === $default_theme && (! x($_SESSION,'theme')))
407 ? ' selected="selected" ' : '' );
408 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
412 $theme_selector .= '</select>';
414 $subdir = ((strlen($a->get_path())) ? '<br />' . t('or') . ' ' . $a->get_baseurl() . '/profile/' . $nickname : '');
416 $tpl_addr = get_markup_template("settings_nick_set.tpl");
418 $prof_addr = replace_macros($tpl_addr,array(
419 '$desc' => t('Your Identity Address is'),
420 '$nickname' => $nickname,
421 '$subdir' => $subdir,
422 '$basepath' => $a->get_hostname()
425 $stpl = get_markup_template('settings.tpl');
427 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
429 $uexport = '<div id="uexport-link"><a href="uexport" >' . t('Export Personal Data') . '</a></div>';
432 $o .= replace_macros($stpl,array(
433 '$ptitle' => t('Account Settings'),
434 '$lbl_plug' => t('Plugin Settings'),
435 '$lbl_basic' => t('Basic Settings'),
436 '$lbl_fn' => t('Full Name:'),
437 '$lbl_email' => t('Email Address:'),
438 '$lbl_tz' => t('Your Timezone:'),
439 '$lbl_loc1' => t('Default Post Location:'),
440 '$lbl_loc2' => t('Use Browser Location:'),
441 '$lbl_theme' => t('Display Theme:'),
442 '$submit' => t('Submit'),
443 '$lbl_prv' => t('Security and Privacy Settings'),
444 '$lbl_maxreq' => t('Maximum Friend Requests/Day:'),
445 '$lbl_maxrdesc' => t("\x28to prevent spam abuse\x29"),
446 '$lbl_rempost' => t('Allow friends to post to your profile page:'),
447 '$lbl_exp1' => t("Automatically expire \x28delete\x29 posts older than"),
448 '$lbl_exp2' => t('days'),
449 '$lbl_not1' => t('Notification Settings'),
450 '$lbl_not2' => t('Send a notification email when:'),
451 '$lbl_not3' => t('You receive an introduction'),
452 '$lbl_not4' => t('Your introductions are confirmed'),
453 '$lbl_not5' => t('Someone writes on your profile wall'),
454 '$lbl_not6' => t('Someone writes a followup comment'),
455 '$lbl_not7' => t('You receive a private message'),
456 '$lbl_pass1' => t('Password Settings'),
457 '$lbl_pass2' => t('Leave password fields blank unless changing'),
458 '$lbl_pass3' => t('New Password:'),
459 '$lbl_pass4' => t('Confirm:'),
460 '$lbl_advn' => t('Advanced Page Settings'),
461 '$baseurl' => $a->get_baseurl(),
462 '$oidhtml' => $oidhtml,
463 '$uexport' => $uexport,
464 '$uid' => local_user(),
465 '$username' => $username,
466 '$openid' => $openid,
468 '$nickname_block' => $prof_addr,
469 '$timezone' => $timezone,
470 '$zoneselect' => select_timezone($timezone),
471 '$defloc' => $defloc,
472 '$loc_checked' => $loc_checked,
473 '$profile_in_dir' => $profile_in_dir,
474 '$profile_in_net_dir' => $profile_in_net_dir,
475 '$permissions' => t('Default Post Permissions'),
476 '$permdesc' => t("\x28click to open/close\x29"),
477 '$visibility' => $profile['net-publish'],
478 '$aclselect' => populate_acl($a->user,$celeb),
479 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
480 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
481 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
482 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
483 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
484 '$maxreq' => $maxreq,
485 '$expire' => $expire,
486 '$blockw_checked' => (($blockwall) ? '' : ' checked="checked" ' ),
487 '$theme' => $theme_selector,
488 '$pagetype' => $pagetype,
489 '$lbl_imap0' => t('Email/Mailbox Setup'),
490 '$imap_desc' => t("If you wish to communicate with email contacts using this service \x28optional\x29, please specify how to connect to your mailbox."),
491 '$lbl_imap1' => t('IMAP server name:'),
492 '$imap_server' => $mail_server,
493 '$lbl_imap2' => t('IMAP port:'),
494 '$imap_port' => $mail_port,
495 '$lbl_imap3' => t("Security \x28TLS or SSL\x29:"),
496 '$imap_ssl' => $mail_ssl,
497 '$lbl_imap4' => t('Email login name:'),
498 '$imap_user' => $mail_user,
499 '$lbl_imap5' => t('Email password:'),
500 '$lbl_imap6' => t("Reply-to address \x28Optional\x29:"),
501 '$imap_replyto' => $mail_replyto,
502 '$lbl_imap7' => t('Send public posts to all email contacts:'),
503 '$lbl_imap8' => t('Last successful email check:'),
504 '$lbl_imap9' => (($mail_chk === '0000-00-00 00:00:00') ? t('never') : datetime_convert('UTC', date_default_timezone_get(), $mail_chk, t('g A l F d Y'))),
505 '$pubmail_checked' => (($mail_pubmail) ? ' checked="checked" ' : ''),
506 '$mail_disabled' => (($mail_disabled) ? '<div class="info-message">' . t('Email access is disabled on this site.') . '</div>' : ''),
507 '$imap_disabled' => $imap_disabled
510 call_hooks('settings_form',$o);
512 $o .= '</form>' . "\r\n";