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 = notags(trim($_POST['theme']));
52 $username = notags(trim($_POST['username']));
53 $email = notags(trim($_POST['email']));
54 $timezone = notags(trim($_POST['timezone']));
55 $defloc = notags(trim($_POST['defloc']));
57 $allow_location = (($_POST['allow_location'] == 1) ? 1: 0);
58 $publish = (($_POST['profile_in_directory'] == 1) ? 1: 0);
59 $net_publish = (($_POST['profile_in_netdirectory'] == 1) ? 1: 0);
60 $old_visibility = ((intval($_POST['visibility']) == 1) ? 1 : 0);
61 $page_flags = ((intval($_POST['page-flags'])) ? intval($_POST['page-flags']) : 0);
66 $notify += intval($_POST['notify1']);
68 $notify += intval($_POST['notify2']);
70 $notify += intval($_POST['notify3']);
72 $notify += intval($_POST['notify4']);
74 $notify += intval($_POST['notify5']);
76 $email_changed = false;
80 if($username != $a->user['username']) {
81 if(strlen($username) > 40)
82 $err .= t(' Please use a shorter name.');
83 if(strlen($username) < 3)
84 $err .= t(' Name too short.');
87 if($email != $a->user['email']) {
88 $email_changed = true;
89 if(!eregi('[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,6}',$email))
90 $err .= t(' Not valid email.');
98 if($timezone != $a->user['timezone']) {
100 date_default_timezone_set($timezone);
103 $str_group_allow = perms2str($_POST['group_allow']);
104 $str_contact_allow = perms2str($_POST['contact_allow']);
105 $str_group_deny = perms2str($_POST['group_deny']);
106 $str_contact_deny = perms2str($_POST['contact_deny']);
108 $r = q("UPDATE `user` SET `username` = '%s', `email` = '%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",
112 dbesc($str_contact_allow),
113 dbesc($str_group_allow),
114 dbesc($str_contact_deny),
115 dbesc($str_group_deny),
119 intval($allow_location),
124 notice( t('Settings updated.') . EOL);
126 $r = q("UPDATE `profile`
127 SET `publish` = %d, `net-publish` = %d
128 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
130 intval($net_publish),
134 if($old_visibility != $net_publish) {
135 // Update global directory in background
136 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
137 $url = $_SESSION['my_url'];
138 if($url && strlen(get_config('system','directory_submit_url')))
139 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
143 $_SESSION['theme'] = $theme;
144 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
146 // FIXME - set to un-verified, blocked and redirect to logout
150 goaway($a->get_baseurl() . '/settings' );
151 return; // NOTREACHED
155 if(! function_exists('settings_content')) {
156 function settings_content(&$a) {
158 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
161 notice( t('Permission denied.') . EOL );
165 require_once('view/acl_selectors.php');
167 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
168 intval($_SESSION['uid'])
173 $username = $a->user['username'];
174 $email = $a->user['email'];
175 $nickname = $a->user['nickname'];
176 $timezone = $a->user['timezone'];
177 $notify = $a->user['notify-flags'];
178 $defloc = $a->user['default-location'];
180 if(! strlen($a->user['timezone']))
181 $timezone = date_default_timezone_get();
183 $pageset_tpl = load_view_file('view/pagetypes.tpl');
184 $pagetype = replace_macros($pageset_tpl,array(
185 '$normal' => (($a->user['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
186 '$soapbox' => (($a->user['page-flags'] == PAGE_SOAPBOX) ? " checked=\"checked\" " : ""),
187 '$community' => (($a->user['page-flags'] == PAGE_COMMUNITY) ? " checked=\"checked\" " : ""),
188 '$freelove' => (($a->user['page-flags'] == PAGE_FREELOVE) ? " checked=\"checked\" " : ""),
189 '$page_normal' => PAGE_NORMAL,
190 '$page_soapbox' => PAGE_SOAPBOX,
191 '$page_community' => PAGE_COMMUNITY,
192 '$page_freelove' => PAGE_FREELOVE
196 $opt_tpl = load_view_file("view/profile-in-directory.tpl");
197 $profile_in_dir = replace_macros($opt_tpl,array(
198 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
199 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
202 if(strlen(get_config('system','directory_submit_url'))) {
203 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
205 $profile_in_net_dir = replace_macros($opt_tpl,array(
206 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
207 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
211 $profile_in_net_dir = '';
213 $loc_checked = (($a->user['allow_location'] == 1) ? " checked=\"checked\" " : "");
215 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
219 notice( t('Profile is <strong>not published</strong>.') . EOL );
221 $nickname_block = load_view_file("view/settings_nick_set.tpl");
223 $nickname_subdir = '';
224 if(strlen($a->get_path())) {
225 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
226 $nickname_subdir = replace_macros($subdir_tpl, array(
227 '$baseurl' => $a->get_baseurl(),
228 '$nickname' => $nickname,
229 '$hostname' => $a->get_hostname()
233 $theme_selector = '<select name="theme" id="theme-select" >';
234 $files = glob('view/theme/*');
236 foreach($files as $file) {
237 $f = basename($file);
238 $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
239 ? ' selected="selected" ' : '' );
240 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
243 $theme_selector .= '</select>';
246 $nickname_block = replace_macros($nickname_block,array(
247 '$nickname' => $nickname,
248 '$uid' => $_SESSION['uid'],
249 '$subdir' => $nickname_subdir,
250 '$basepath' => $a->get_hostname(),
251 '$baseurl' => $a->get_baseurl()));
253 $stpl = load_view_file('view/settings.tpl');
255 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
257 $o .= replace_macros($stpl,array(
258 '$baseurl' => $a->get_baseurl(),
259 '$uid' => $_SESSION['uid'],
260 '$username' => $username,
262 '$nickname_block' => $nickname_block,
263 '$timezone' => $timezone,
264 '$zoneselect' => select_timezone($timezone),
265 '$defloc' => $defloc,
266 '$loc_checked' => $loc_checked,
267 '$profile_in_dir' => $profile_in_dir,
268 '$profile_in_net_dir' => $profile_in_net_dir,
269 '$permissions' => t('Default Post Permissions'),
270 '$visibility' => $profile['net-publish'],
271 '$aclselect' => populate_acl($a->user,$celeb),
272 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
273 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
274 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
275 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
276 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
277 '$theme' => $theme_selector,
278 '$pagetype' => $pagetype