4 function settings_init(&$a) {
6 profile_load($a,$a->user['nickname']);
11 function settings_post(&$a) {
14 notice( t('Permission denied.') . EOL);
18 if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
19 notice( t('Permission denied.') . EOL);
23 if(($a->argc > 1) && ($a->argv[1] == 'addon')) {
24 call_hooks('plugin_settings_post', $_POST);
28 call_hooks('settings_post', $_POST);
30 if((x($_POST,'npassword')) || (x($_POST,'confirm'))) {
32 $newpass = $_POST['npassword'];
33 $confirm = $_POST['confirm'];
36 if($newpass != $confirm ) {
37 notice( t('Passwords do not match. Password unchanged.') . EOL);
41 if((! x($newpass)) || (! x($confirm))) {
42 notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
47 $password = hash('whirlpool',$newpass);
48 $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d LIMIT 1",
53 notice( t('Password changed.') . EOL);
55 notice( t('Password update failed. Please try again.') . EOL);
59 $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
60 $username = ((x($_POST,'username')) ? notags(trim($_POST['username'])) : '');
61 $email = ((x($_POST,'email')) ? notags(trim($_POST['email'])) : '');
62 $timezone = ((x($_POST,'timezone')) ? notags(trim($_POST['timezone'])) : '');
63 $defloc = ((x($_POST,'defloc')) ? notags(trim($_POST['defloc'])) : '');
64 $openid = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url'])) : '');
65 $maxreq = ((x($_POST,'maxreq')) ? intval($_POST['maxreq']) : 0);
66 $expire = ((x($_POST,'expire')) ? intval($_POST['expire']) : 0);
68 $allow_location = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
69 $publish = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
70 $net_publish = (((x($_POST,'profile_in_netdirectory')) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
71 $old_visibility = (((x($_POST,'visibility')) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
72 $page_flags = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
76 if(x($_POST,'notify1'))
77 $notify += intval($_POST['notify1']);
78 if(x($_POST,'notify2'))
79 $notify += intval($_POST['notify2']);
80 if(x($_POST,'notify3'))
81 $notify += intval($_POST['notify3']);
82 if(x($_POST,'notify4'))
83 $notify += intval($_POST['notify4']);
84 if(x($_POST,'notify5'))
85 $notify += intval($_POST['notify5']);
87 $email_changed = false;
93 if($username != $a->user['username']) {
95 if(strlen($username) > 40)
96 $err .= t(' Please use a shorter name.');
97 if(strlen($username) < 3)
98 $err .= t(' Name too short.');
101 if($email != $a->user['email']) {
102 $email_changed = true;
103 if(! valid_email($email))
104 $err .= t(' Not valid email.');
105 if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) {
106 $err .= t(' Cannot change to that email.');
107 $email = $a->user['email'];
116 if($timezone != $a->user['timezone']) {
117 if(strlen($timezone))
118 date_default_timezone_set($timezone);
121 $str_group_allow = perms2str($_POST['group_allow']);
122 $str_contact_allow = perms2str($_POST['contact_allow']);
123 $str_group_deny = perms2str($_POST['group_deny']);
124 $str_contact_deny = perms2str($_POST['contact_deny']);
126 $openidserver = $a->user['openidserver'];
128 // If openid has changed or if there's an openid but no openidserver, try and discover it.
130 if($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) {
132 if(strlen($tmp_str) && validate_url($tmp_str)) {
133 logger('updating openidserver');
134 require_once('library/openid.php');
135 $open_id_obj = new LightOpenID;
136 $open_id_obj->identity = $openid;
137 $openidserver = $open_id_obj->discover($open_id_obj->identity);
143 $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' WHERE `uid` = %d LIMIT 1",
148 dbesc($str_contact_allow),
149 dbesc($str_group_allow),
150 dbesc($str_contact_deny),
151 dbesc($str_group_deny),
155 intval($allow_location),
159 dbesc($openidserver),
163 notice( t('Settings updated.') . EOL);
165 $r = q("UPDATE `profile`
166 SET `publish` = %d, `net-publish` = %d
167 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
169 intval($net_publish),
175 q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self` = 1 LIMIT 1",
177 dbesc(datetime_convert()),
182 if($old_visibility != $net_publish) {
183 // Update global directory in background
184 $url = $_SESSION['my_url'];
185 if($url && strlen(get_config('system','directory_submit_url')))
186 proc_run('php',"include/directory.php","$url");
189 $_SESSION['theme'] = $theme;
190 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
192 // FIXME - set to un-verified, blocked and redirect to logout
196 goaway($a->get_baseurl() . '/settings' );
197 return; // NOTREACHED
201 if(! function_exists('settings_content')) {
202 function settings_content(&$a) {
205 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
208 notice( t('Permission denied.') . EOL );
212 if(($a->argc > 1) && ($a->argv[1] === 'addon')) {
213 $o .= '<h1>' . t('Plugin Settings') . '</h1>';
214 $o .= '<div id="account-settings-link"><a href="settings">' . t('Account Settings') . '</a></div>';
216 $o .= '<form action="settings/addon" method="post" >';
218 $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
220 notice( t('No Plugin settings configured') . EOL);
222 call_hooks('plugin_settings', $o);
227 require_once('include/acl_selectors.php');
229 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
235 $username = $a->user['username'];
236 $email = $a->user['email'];
237 $nickname = $a->user['nickname'];
238 $timezone = $a->user['timezone'];
239 $notify = $a->user['notify-flags'];
240 $defloc = $a->user['default-location'];
241 $openid = $a->user['openid'];
242 $maxreq = $a->user['maxreq'];
243 $expire = ((intval($a->user['expire'])) ? $a->user['expire'] : '');
245 if(! strlen($a->user['timezone']))
246 $timezone = date_default_timezone_get();
248 $pageset_tpl = load_view_file('view/pagetypes.tpl');
249 $pagetype = replace_macros($pageset_tpl,array(
250 '$normal' => (($a->user['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
251 '$soapbox' => (($a->user['page-flags'] == PAGE_SOAPBOX) ? " checked=\"checked\" " : ""),
252 '$community' => (($a->user['page-flags'] == PAGE_COMMUNITY) ? " checked=\"checked\" " : ""),
253 '$freelove' => (($a->user['page-flags'] == PAGE_FREELOVE) ? " checked=\"checked\" " : ""),
254 '$page_normal' => PAGE_NORMAL,
255 '$page_soapbox' => PAGE_SOAPBOX,
256 '$page_community' => PAGE_COMMUNITY,
257 '$page_freelove' => PAGE_FREELOVE
260 $noid = get_config('system','no_openid');
266 $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.");
270 if(get_config('system','publish_all')) {
271 $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
274 $opt_tpl = load_view_file("view/profile-in-directory.tpl");
275 $profile_in_dir = replace_macros($opt_tpl,array(
276 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
277 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
281 if(strlen(get_config('system','directory_submit_url'))) {
282 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
284 $profile_in_net_dir = replace_macros($opt_tpl,array(
285 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
286 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
290 $profile_in_net_dir = '';
292 $loc_checked = (($a->user['allow_location'] == 1) ? " checked=\"checked\" " : "");
294 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
298 notice( t('Profile is <strong>not published</strong>.') . EOL );
300 $nickname_block = load_view_file("view/settings_nick_set.tpl");
302 $nickname_subdir = '';
303 if(strlen($a->get_path())) {
304 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
305 $nickname_subdir = replace_macros($subdir_tpl, array(
306 '$baseurl' => $a->get_baseurl(),
307 '$nickname' => $nickname,
308 '$hostname' => $a->get_hostname()
312 $theme_selector = '<select name="theme" id="theme-select" >';
313 $files = glob('view/theme/*');
315 $default_theme = get_config('system','theme');
317 $default_theme = 'default';
320 foreach($files as $file) {
321 $f = basename($file);
322 $selected = (($f == $_SESSION['theme']) || ($f === $default_theme && (! x($_SESSION,'theme')))
323 ? ' selected="selected" ' : '' );
324 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
327 $theme_selector .= '</select>';
330 $nickname_block = replace_macros($nickname_block,array(
331 '$nickname' => $nickname,
332 '$uid' => local_user(),
333 '$subdir' => $nickname_subdir,
334 '$basepath' => $a->get_hostname(),
335 '$baseurl' => $a->get_baseurl()));
337 $stpl = load_view_file('view/settings.tpl');
339 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
341 $o .= replace_macros($stpl,array(
342 '$baseurl' => $a->get_baseurl(),
343 '$oidhtml' => $oidhtml,
344 '$uid' => local_user(),
345 '$username' => $username,
346 '$openid' => $openid,
348 '$nickname_block' => $nickname_block,
349 '$timezone' => $timezone,
350 '$zoneselect' => select_timezone($timezone),
351 '$defloc' => $defloc,
352 '$loc_checked' => $loc_checked,
353 '$profile_in_dir' => $profile_in_dir,
354 '$profile_in_net_dir' => $profile_in_net_dir,
355 '$permissions' => t('Default Post Permissions'),
356 '$visibility' => $profile['net-publish'],
357 '$aclselect' => populate_acl($a->user,$celeb),
358 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
359 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
360 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
361 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
362 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
363 '$maxreq' => $maxreq,
364 '$expire' => $expire,
365 '$theme' => $theme_selector,
366 '$pagetype' => $pagetype
369 call_hooks('settings_form',$o);
371 $o .= '</form>' . "\r\n";