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'] != get_uid()) {
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 $publish = (($_POST['profile_in_directory'] == 1) ? 1: 0);
58 $net_publish = (($_POST['profile_in_netdirectory'] == 1) ? 1: 0);
59 $old_visibility = ((intval($_POST['visibility']) == 1) ? 1 : 0);
60 $page_flags = ((intval($_POST['page-flags'])) ? intval($_POST['page-flags']) : 0);
65 $notify += intval($_POST['notify1']);
67 $notify += intval($_POST['notify2']);
69 $notify += intval($_POST['notify3']);
71 $notify += intval($_POST['notify4']);
73 $notify += intval($_POST['notify5']);
75 $email_changed = false;
79 if($username != $a->user['username']) {
80 if(strlen($username) > 40)
81 $err .= t(' Please use a shorter name.');
82 if(strlen($username) < 3)
83 $err .= t(' Name too short.');
86 if($email != $a->user['email']) {
87 $email_changed = true;
88 if(!eregi('[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,6}',$email))
89 $err .= t(' Not valid email.');
97 if($timezone != $a->user['timezone']) {
99 date_default_timezone_set($timezone);
102 $str_group_allow = perms2str($_POST['group_allow']);
103 $str_contact_allow = perms2str($_POST['contact_allow']);
104 $str_group_deny = perms2str($_POST['group_deny']);
105 $str_contact_deny = perms2str($_POST['contact_deny']);
107 $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', `theme` = '%s' WHERE `uid` = %d LIMIT 1",
111 dbesc($str_contact_allow),
112 dbesc($str_group_allow),
113 dbesc($str_contact_deny),
114 dbesc($str_group_deny),
122 notice( t('Settings updated.') . EOL);
124 $r = q("UPDATE `profile`
125 SET `publish` = %d, `net-publish` = %d
126 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
128 intval($net_publish),
132 if($old_visibility != $net_publish) {
133 // Update global directory in background
134 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
135 $url = $_SESSION['my_url'];
136 if($url && strlen(get_config('system','directory_submit_url')))
137 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
141 $_SESSION['theme'] = $theme;
142 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
144 // FIXME - set to un-verified, blocked and redirect to logout
148 goaway($a->get_baseurl() . '/settings' );
149 return; // NOTREACHED
153 if(! function_exists('settings_content')) {
154 function settings_content(&$a) {
156 $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
159 notice( t('Permission denied.') . EOL );
163 require_once('view/acl_selectors.php');
165 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
166 intval($_SESSION['uid'])
171 $username = $a->user['username'];
172 $email = $a->user['email'];
173 $nickname = $a->user['nickname'];
174 $timezone = $a->user['timezone'];
175 $notify = $a->user['notify-flags'];
176 $defloc = $a->user['default-location'];
178 if(! strlen($a->user['timezone']))
179 $timezone = date_default_timezone_get();
181 $pageset_tpl = load_view_file('view/pagetypes.tpl');
182 $pagetype = replace_macros($pageset_tpl,array(
183 '$normal' => (($profile['page-flags'] == PAGE_NORMAL) ? " checked=\"checked\" " : ""),
184 '$soapbox' => (($profile['page-flags'] == PAGE_SOAPBOX) ? " checked=\"checked\" " : ""),
185 '$community' => (($profile['page-flags'] == PAGE_COMMUNITY) ? " checked=\"checked\" " : ""),
186 '$freelove' => (($profile['page-flags'] == PAGE_FREELOVE) ? " checked=\"checked\" " : ""),
187 '$page_normal' => PAGE_NORMAL,
188 '$page_soapbox' => PAGE_SOAPBOX,
189 '$page_community' => PAGE_COMMUNITY,
190 '$page_freelove' => PAGE_FREELOVE
194 $opt_tpl = load_view_file("view/profile-in-directory.tpl");
195 $profile_in_dir = replace_macros($opt_tpl,array(
196 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
197 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
200 if(strlen(get_config('system','directory_submit_url'))) {
201 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
203 $profile_in_net_dir = replace_macros($opt_tpl,array(
204 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
205 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
209 $profile_in_net_dir = '';
211 $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
215 notice( t('Profile is <strong>not published</strong>.') . EOL );
217 $nickname_block = load_view_file("view/settings_nick_set.tpl");
219 $nickname_subdir = '';
220 if(strlen($a->get_path())) {
221 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
222 $nickname_subdir = replace_macros($subdir_tpl, array(
223 '$baseurl' => $a->get_baseurl(),
224 '$nickname' => $nickname,
225 '$hostname' => $a->get_hostname()
229 $theme_selector = '<select name="theme" id="theme-select" >';
230 $files = glob('view/theme/*');
232 foreach($files as $file) {
233 $f = basename($file);
234 $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
235 ? ' selected="selected" ' : '' );
236 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
239 $theme_selector .= '</select>';
242 $nickname_block = replace_macros($nickname_block,array(
243 '$nickname' => $nickname,
244 '$uid' => $_SESSION['uid'],
245 '$subdir' => $nickname_subdir,
246 '$basepath' => $a->get_hostname(),
247 '$baseurl' => $a->get_baseurl()));
249 $stpl = load_view_file('view/settings.tpl');
251 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
253 $o .= replace_macros($stpl,array(
254 '$baseurl' => $a->get_baseurl(),
255 '$uid' => $_SESSION['uid'],
256 '$username' => $username,
258 '$nickname_block' => $nickname_block,
259 '$timezone' => $timezone,
260 '$zoneselect' => select_timezone($timezone),
261 '$defloc' => $defloc,
262 '$profile_in_dir' => $profile_in_dir,
263 '$profile_in_net_dir' => $profile_in_net_dir,
264 '$permissions' => t('Default Post Permissions'),
265 '$visibility' => $profile['net-publish'],
266 '$aclselect' => populate_acl($a->user,$celeb),
267 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
268 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
269 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
270 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
271 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : ''),
272 '$theme' => $theme_selector,
273 '$pagetype' => $pagetype