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) {
159 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
162 notice( t('Permission denied.') . EOL );
166 require_once('view/acl_selectors.php');
168 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
169 intval($_SESSION['uid'])
174 $username = $a->user['username'];
175 $email = $a->user['email'];
176 $nickname = $a->user['nickname'];
177 $timezone = $a->user['timezone'];
178 $notify = $a->user['notify-flags'];
179 $defloc = $a->user['default-location'];
181 if(! strlen($a->user['timezone']))
182 $timezone = date_default_timezone_get();
184 $pageset_tpl = load_view_file('view/pagetypes.tpl');
185 $pagetype = replace_macros($pageset_tpl,array(
186 '$normal' => (($a->user['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
187 '$soapbox' => (($a->user['page-flags'] == PAGE_SOAPBOX) ? " checked=\"checked\" " : ""),
188 '$community' => (($a->user['page-flags'] == PAGE_COMMUNITY) ? " checked=\"checked\" " : ""),
189 '$freelove' => (($a->user['page-flags'] == PAGE_FREELOVE) ? " checked=\"checked\" " : ""),
190 '$page_normal' => PAGE_NORMAL,
191 '$page_soapbox' => PAGE_SOAPBOX,
192 '$page_community' => PAGE_COMMUNITY,
193 '$page_freelove' => PAGE_FREELOVE
197 $opt_tpl = load_view_file("view/profile-in-directory.tpl");
198 $profile_in_dir = replace_macros($opt_tpl,array(
199 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
200 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
203 if(strlen(get_config('system','directory_submit_url'))) {
204 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
206 $profile_in_net_dir = replace_macros($opt_tpl,array(
207 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
208 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
212 $profile_in_net_dir = '';
214 $loc_checked = (($a->user['allow_location'] == 1) ? " checked=\"checked\" " : "");
216 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
220 notice( t('Profile is <strong>not published</strong>.') . EOL );
222 $nickname_block = load_view_file("view/settings_nick_set.tpl");
224 $nickname_subdir = '';
225 if(strlen($a->get_path())) {
226 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
227 $nickname_subdir = replace_macros($subdir_tpl, array(
228 '$baseurl' => $a->get_baseurl(),
229 '$nickname' => $nickname,
230 '$hostname' => $a->get_hostname()
234 $theme_selector = '<select name="theme" id="theme-select" >';
235 $files = glob('view/theme/*');
237 foreach($files as $file) {
238 $f = basename($file);
239 $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
240 ? ' selected="selected" ' : '' );
241 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
244 $theme_selector .= '</select>';
247 $nickname_block = replace_macros($nickname_block,array(
248 '$nickname' => $nickname,
249 '$uid' => $_SESSION['uid'],
250 '$subdir' => $nickname_subdir,
251 '$basepath' => $a->get_hostname(),
252 '$baseurl' => $a->get_baseurl()));
254 $stpl = load_view_file('view/settings.tpl');
256 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
258 $o .= replace_macros($stpl,array(
259 '$baseurl' => $a->get_baseurl(),
260 '$uid' => $_SESSION['uid'],
261 '$username' => $username,
263 '$nickname_block' => $nickname_block,
264 '$timezone' => $timezone,
265 '$zoneselect' => select_timezone($timezone),
266 '$defloc' => $defloc,
267 '$loc_checked' => $loc_checked,
268 '$profile_in_dir' => $profile_in_dir,
269 '$profile_in_net_dir' => $profile_in_net_dir,
270 '$permissions' => t('Default Post Permissions'),
271 '$visibility' => $profile['net-publish'],
272 '$aclselect' => populate_acl($a->user,$celeb),
273 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
274 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
275 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
276 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
277 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
278 '$theme' => $theme_selector,
279 '$pagetype' => $pagetype