4 function settings_init(&$a) {
6 require_once("mod/profile.php");
7 profile_load($a,$a->user['nickname']);
12 function settings_post(&$a) {
15 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);
22 if((x($_POST,'npassword')) || (x($_POST,'confirm'))) {
24 $newpass = $_POST['npassword'];
25 $confirm = $_POST['confirm'];
28 if($newpass != $confirm ) {
29 notice( t('Passwords do not match. Password unchanged.') . EOL);
33 if((! x($newpass)) || (! x($confirm))) {
34 notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
39 $password = hash('whirlpool',$newpass);
40 $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d LIMIT 1",
45 notice( t('Password changed.') . EOL);
47 notice( t('Password update failed. Please try again.') . EOL);
51 $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
52 $username = ((x($_POST,'username')) ? notags(trim($_POST['username'])) : '');
53 $email = ((x($_POST,'email')) ? notags(trim($_POST['email'])) : '');
54 $timezone = ((x($_POST,'timezone')) ? notags(trim($_POST['timezone'])) : '');
55 $defloc = ((x($_POST,'defloc')) ? notags(trim($_POST['defloc'])) : '');
56 $openid = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url'])) : '');
58 $allow_location = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
59 $publish = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
60 $net_publish = (((x($_POST,'profile_in_netdirectory')) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
61 $old_visibility = (((x($_POST,'visibility')) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
62 $page_flags = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
66 if(x($_POST,'notify1'))
67 $notify += intval($_POST['notify1']);
68 if(x($_POST,'notify2'))
69 $notify += intval($_POST['notify2']);
70 if(x($_POST,'notify3'))
71 $notify += intval($_POST['notify3']);
72 if(x($_POST,'notify4'))
73 $notify += intval($_POST['notify4']);
74 if(x($_POST,'notify5'))
75 $notify += intval($_POST['notify5']);
77 $email_changed = false;
81 if($username != $a->user['username']) {
82 if(strlen($username) > 40)
83 $err .= t(' Please use a shorter name.');
84 if(strlen($username) < 3)
85 $err .= t(' Name too short.');
88 if($email != $a->user['email']) {
89 $email_changed = true;
90 if(! valid_email($email))
91 $err .= t(' Not valid email.');
99 if($timezone != $a->user['timezone']) {
100 if(strlen($timezone))
101 date_default_timezone_set($timezone);
104 $str_group_allow = perms2str($_POST['group_allow']);
105 $str_contact_allow = perms2str($_POST['contact_allow']);
106 $str_group_deny = perms2str($_POST['group_deny']);
107 $str_contact_deny = perms2str($_POST['contact_deny']);
109 $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' WHERE `uid` = %d LIMIT 1",
114 dbesc($str_contact_allow),
115 dbesc($str_group_allow),
116 dbesc($str_contact_deny),
117 dbesc($str_group_deny),
121 intval($allow_location),
126 notice( t('Settings updated.') . EOL);
128 $r = q("UPDATE `profile`
129 SET `publish` = %d, `net-publish` = %d
130 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
132 intval($net_publish),
136 if($old_visibility != $net_publish) {
137 // Update global directory in background
138 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
139 $url = $_SESSION['my_url'];
140 if($url && strlen(get_config('system','directory_submit_url')))
141 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
145 $_SESSION['theme'] = $theme;
146 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
148 // FIXME - set to un-verified, blocked and redirect to logout
152 goaway($a->get_baseurl() . '/settings' );
153 return; // NOTREACHED
157 if(! function_exists('settings_content')) {
158 function settings_content(&$a) {
161 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
164 notice( t('Permission denied.') . EOL );
168 require_once('include/acl_selectors.php');
170 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
176 $username = $a->user['username'];
177 $email = $a->user['email'];
178 $nickname = $a->user['nickname'];
179 $timezone = $a->user['timezone'];
180 $notify = $a->user['notify-flags'];
181 $defloc = $a->user['default-location'];
182 $openid = $a->user['openid'];
184 if(! strlen($a->user['timezone']))
185 $timezone = date_default_timezone_get();
187 $pageset_tpl = load_view_file('view/pagetypes.tpl');
188 $pagetype = replace_macros($pageset_tpl,array(
189 '$normal' => (($a->user['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
190 '$soapbox' => (($a->user['page-flags'] == PAGE_SOAPBOX) ? " checked=\"checked\" " : ""),
191 '$community' => (($a->user['page-flags'] == PAGE_COMMUNITY) ? " checked=\"checked\" " : ""),
192 '$freelove' => (($a->user['page-flags'] == PAGE_FREELOVE) ? " checked=\"checked\" " : ""),
193 '$page_normal' => PAGE_NORMAL,
194 '$page_soapbox' => PAGE_SOAPBOX,
195 '$page_community' => PAGE_COMMUNITY,
196 '$page_freelove' => PAGE_FREELOVE
200 $opt_tpl = load_view_file("view/profile-in-directory.tpl");
201 $profile_in_dir = replace_macros($opt_tpl,array(
202 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
203 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
206 if(strlen(get_config('system','directory_submit_url'))) {
207 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
209 $profile_in_net_dir = replace_macros($opt_tpl,array(
210 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
211 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
215 $profile_in_net_dir = '';
217 $loc_checked = (($a->user['allow_location'] == 1) ? " checked=\"checked\" " : "");
219 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
223 notice( t('Profile is <strong>not published</strong>.') . EOL );
225 $nickname_block = load_view_file("view/settings_nick_set.tpl");
227 $nickname_subdir = '';
228 if(strlen($a->get_path())) {
229 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
230 $nickname_subdir = replace_macros($subdir_tpl, array(
231 '$baseurl' => $a->get_baseurl(),
232 '$nickname' => $nickname,
233 '$hostname' => $a->get_hostname()
237 $theme_selector = '<select name="theme" id="theme-select" >';
238 $files = glob('view/theme/*');
240 foreach($files as $file) {
241 $f = basename($file);
242 $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
243 ? ' selected="selected" ' : '' );
244 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
247 $theme_selector .= '</select>';
250 $nickname_block = replace_macros($nickname_block,array(
251 '$nickname' => $nickname,
252 '$uid' => local_user(),
253 '$subdir' => $nickname_subdir,
254 '$basepath' => $a->get_hostname(),
255 '$baseurl' => $a->get_baseurl()));
257 $stpl = load_view_file('view/settings.tpl');
259 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
261 $o .= replace_macros($stpl,array(
262 '$baseurl' => $a->get_baseurl(),
263 '$uid' => local_user(),
264 '$username' => $username,
265 '$openid' => $openid,
267 '$nickname_block' => $nickname_block,
268 '$timezone' => $timezone,
269 '$zoneselect' => select_timezone($timezone),
270 '$defloc' => $defloc,
271 '$loc_checked' => $loc_checked,
272 '$profile_in_dir' => $profile_in_dir,
273 '$profile_in_net_dir' => $profile_in_net_dir,
274 '$permissions' => t('Default Post Permissions'),
275 '$visibility' => $profile['net-publish'],
276 '$aclselect' => populate_acl($a->user,$celeb),
277 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
278 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
279 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
280 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
281 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
282 '$theme' => $theme_selector,
283 '$pagetype' => $pagetype