4 function settings_init(&$a) {
6 profile_load($a,$a->user['nickname']);
11 function settings_post(&$a) {
14 notice( t('Permission denied.') . EOL);
18 call_hooks('settings_post', $_POST);
20 if(($a->argc > 1) && ($a->argv[1] == 'addon'))
23 if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
24 notice( t('Permission denied.') . EOL);
27 if((x($_POST,'npassword')) || (x($_POST,'confirm'))) {
29 $newpass = $_POST['npassword'];
30 $confirm = $_POST['confirm'];
33 if($newpass != $confirm ) {
34 notice( t('Passwords do not match. Password unchanged.') . EOL);
38 if((! x($newpass)) || (! x($confirm))) {
39 notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
44 $password = hash('whirlpool',$newpass);
45 $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d LIMIT 1",
50 notice( t('Password changed.') . EOL);
52 notice( t('Password update failed. Please try again.') . EOL);
56 $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
57 $username = ((x($_POST,'username')) ? notags(trim($_POST['username'])) : '');
58 $email = ((x($_POST,'email')) ? notags(trim($_POST['email'])) : '');
59 $timezone = ((x($_POST,'timezone')) ? notags(trim($_POST['timezone'])) : '');
60 $defloc = ((x($_POST,'defloc')) ? notags(trim($_POST['defloc'])) : '');
61 $openid = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url'])) : '');
62 $maxreq = ((x($_POST,'maxreq')) ? intval($_POST['maxreq']) : 0);
64 $allow_location = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
65 $publish = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
66 $net_publish = (((x($_POST,'profile_in_netdirectory')) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
67 $old_visibility = (((x($_POST,'visibility')) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
68 $page_flags = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
72 if(x($_POST,'notify1'))
73 $notify += intval($_POST['notify1']);
74 if(x($_POST,'notify2'))
75 $notify += intval($_POST['notify2']);
76 if(x($_POST,'notify3'))
77 $notify += intval($_POST['notify3']);
78 if(x($_POST,'notify4'))
79 $notify += intval($_POST['notify4']);
80 if(x($_POST,'notify5'))
81 $notify += intval($_POST['notify5']);
83 $email_changed = false;
87 if($username != $a->user['username']) {
88 if(strlen($username) > 40)
89 $err .= t(' Please use a shorter name.');
90 if(strlen($username) < 3)
91 $err .= t(' Name too short.');
94 if($email != $a->user['email']) {
95 $email_changed = true;
96 if(! valid_email($email))
97 $err .= t(' Not valid email.');
105 if($timezone != $a->user['timezone']) {
106 if(strlen($timezone))
107 date_default_timezone_set($timezone);
110 $str_group_allow = perms2str($_POST['group_allow']);
111 $str_contact_allow = perms2str($_POST['contact_allow']);
112 $str_group_deny = perms2str($_POST['group_deny']);
113 $str_contact_deny = perms2str($_POST['contact_deny']);
115 $openidserver = $a->user['openidserver'];
117 // If openid has changed or if there's an openid but no openidserver, try and discover it.
119 if($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) {
120 if(strlen($openid)) {
121 logger('updating openidserver');
122 require_once('library/openid.php');
123 $open_id_obj = new LightOpenID;
124 $open_id_obj->identity = $openid;
125 $openidserver = $open_id_obj->discover($open_id_obj->identity);
131 $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, `openidserver` = '%s' WHERE `uid` = %d LIMIT 1",
136 dbesc($str_contact_allow),
137 dbesc($str_group_allow),
138 dbesc($str_contact_deny),
139 dbesc($str_group_deny),
143 intval($allow_location),
146 dbesc($openidserver),
150 notice( t('Settings updated.') . EOL);
152 $r = q("UPDATE `profile`
153 SET `publish` = %d, `net-publish` = %d
154 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
156 intval($net_publish),
160 if($old_visibility != $net_publish) {
161 // Update global directory in background
162 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
163 $url = $_SESSION['my_url'];
164 if($url && strlen(get_config('system','directory_submit_url')))
165 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
169 $_SESSION['theme'] = $theme;
170 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
172 // FIXME - set to un-verified, blocked and redirect to logout
176 goaway($a->get_baseurl() . '/settings' );
177 return; // NOTREACHED
181 if(! function_exists('settings_content')) {
182 function settings_content(&$a) {
185 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
188 notice( t('Permission denied.') . EOL );
192 if(($a->argc > 1) && ($a->argv[1] === 'addon')) {
193 $o .= '<h1>' . t('Plugin Settings') . '</h1>';
194 $o .= '<div id="account-settings-link"><a href="settings">' . t('Account Settings') . '</a></div>';
196 $o .= '<form action="settings/addon" method="post" >';
198 $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
200 notice( t('No Plugin settings configured') . EOL);
202 call_hooks('plugin_settings', $o);
207 require_once('include/acl_selectors.php');
209 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
215 $username = $a->user['username'];
216 $email = $a->user['email'];
217 $nickname = $a->user['nickname'];
218 $timezone = $a->user['timezone'];
219 $notify = $a->user['notify-flags'];
220 $defloc = $a->user['default-location'];
221 $openid = $a->user['openid'];
222 $maxreq = $a->user['maxreq'];
224 if(! strlen($a->user['timezone']))
225 $timezone = date_default_timezone_get();
227 $pageset_tpl = load_view_file('view/pagetypes.tpl');
228 $pagetype = replace_macros($pageset_tpl,array(
229 '$normal' => (($a->user['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
230 '$soapbox' => (($a->user['page-flags'] == PAGE_SOAPBOX) ? " checked=\"checked\" " : ""),
231 '$community' => (($a->user['page-flags'] == PAGE_COMMUNITY) ? " checked=\"checked\" " : ""),
232 '$freelove' => (($a->user['page-flags'] == PAGE_FREELOVE) ? " checked=\"checked\" " : ""),
233 '$page_normal' => PAGE_NORMAL,
234 '$page_soapbox' => PAGE_SOAPBOX,
235 '$page_community' => PAGE_COMMUNITY,
236 '$page_freelove' => PAGE_FREELOVE
239 $noid = get_config('system','no_openid');
245 $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.");
251 $opt_tpl = load_view_file("view/profile-in-directory.tpl");
252 $profile_in_dir = replace_macros($opt_tpl,array(
253 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
254 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
257 if(strlen(get_config('system','directory_submit_url'))) {
258 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
260 $profile_in_net_dir = replace_macros($opt_tpl,array(
261 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
262 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
266 $profile_in_net_dir = '';
268 $loc_checked = (($a->user['allow_location'] == 1) ? " checked=\"checked\" " : "");
270 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
274 notice( t('Profile is <strong>not published</strong>.') . EOL );
276 $nickname_block = load_view_file("view/settings_nick_set.tpl");
278 $nickname_subdir = '';
279 if(strlen($a->get_path())) {
280 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
281 $nickname_subdir = replace_macros($subdir_tpl, array(
282 '$baseurl' => $a->get_baseurl(),
283 '$nickname' => $nickname,
284 '$hostname' => $a->get_hostname()
288 $theme_selector = '<select name="theme" id="theme-select" >';
289 $files = glob('view/theme/*');
291 foreach($files as $file) {
292 $f = basename($file);
293 $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
294 ? ' selected="selected" ' : '' );
295 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
298 $theme_selector .= '</select>';
301 $nickname_block = replace_macros($nickname_block,array(
302 '$nickname' => $nickname,
303 '$uid' => local_user(),
304 '$subdir' => $nickname_subdir,
305 '$basepath' => $a->get_hostname(),
306 '$baseurl' => $a->get_baseurl()));
308 $stpl = load_view_file('view/settings.tpl');
310 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
312 $o .= replace_macros($stpl,array(
313 '$baseurl' => $a->get_baseurl(),
314 '$oidhtml' => $oidhtml,
315 '$uid' => local_user(),
316 '$username' => $username,
317 '$openid' => $openid,
319 '$nickname_block' => $nickname_block,
320 '$timezone' => $timezone,
321 '$zoneselect' => select_timezone($timezone),
322 '$defloc' => $defloc,
323 '$loc_checked' => $loc_checked,
324 '$profile_in_dir' => $profile_in_dir,
325 '$profile_in_net_dir' => $profile_in_net_dir,
326 '$permissions' => t('Default Post Permissions'),
327 '$visibility' => $profile['net-publish'],
328 '$aclselect' => populate_acl($a->user,$celeb),
329 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
330 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
331 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
332 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
333 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
334 '$maxreq' => $maxreq,
335 '$theme' => $theme_selector,
336 '$pagetype' => $pagetype
339 call_hooks('settings_form',$o);
341 $o .= '</form>' . "\r\n";