4 function settings_init(&$a) {
7 notice("Permission denied." . EOL);
11 require_once("mod/profile.php");
12 profile_load($a,$a->user['nickname']);
16 function settings_post(&$a) {
20 notice( t('Permission denied.') . EOL);
23 if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != $_SESSION['uid']) {
24 notice( t('Permission denied.') . EOL);
27 if((x($_POST,'password')) || (x($_POST,'confirm'))) {
29 $newpass = trim($_POST['password']);
30 $confirm = trim($_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",
47 intval($_SESSION['uid']));
49 notice( t('Password changed.') . EOL);
51 notice( t('Password update failed. Please try again.') . EOL);
55 $theme = notags(trim($_POST['theme']));
56 $username = notags(trim($_POST['username']));
57 $email = notags(trim($_POST['email']));
58 $timezone = notags(trim($_POST['timezone']));
60 $publish = (($_POST['profile_in_directory'] == 1) ? 1: 0);
61 $net_publish = (($_POST['profile_in_netdirectory'] == 1) ? 1: 0);
62 $old_visibility = ((intval($_POST['visibility']) == 1) ? 1 : 0);
67 $notify += intval($_POST['notify1']);
69 $notify += intval($_POST['notify2']);
71 $notify += intval($_POST['notify3']);
73 $notify += intval($_POST['notify4']);
75 $notify += intval($_POST['notify5']);
77 $username_changed = false;
78 $email_changed = false;
79 $zone_changed = false;
82 if($username != $a->user['username']) {
83 $username_changed = true;
84 if(strlen($username) > 40)
85 $err .= t(' Please use a shorter name.');
86 if(strlen($username) < 3)
87 $err .= t(' Name too short.');
89 if($email != $a->user['email']) {
90 $email_changed = true;
91 if(!eregi('[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,6}',$email))
92 $err .= t(' Not valid email.');
93 $r = q("SELECT `uid` FROM `user`
94 WHERE `email` = '%s' LIMIT 1",
97 if($r !== NULL && count($r))
98 $err .= t(' This email address is already registered.');
105 if($timezone != $a->user['timezone']) {
106 $zone_changed = true;
107 if(strlen($timezone))
108 date_default_timezone_set($timezone);
111 $str_group_allow = '';
112 $group_allow = $_POST['group_allow'];
113 if(is_array($group_allow)) {
114 array_walk($group_allow,'sanitise_acl');
115 $str_group_allow = implode('',$group_allow);
118 $str_contact_allow = '';
119 $contact_allow = $_POST['contact_allow'];
120 if(is_array($contact_allow)) {
121 array_walk($contact_allow,'sanitise_acl');
122 $str_contact_allow = implode('',$contact_allow);
125 $str_group_deny = '';
126 $group_deny = $_POST['group_deny'];
127 if(is_array($group_deny)) {
128 array_walk($group_deny,'sanitise_acl');
129 $str_group_deny = implode('',$group_deny);
132 $str_contact_deny = '';
133 $contact_deny = $_POST['contact_deny'];
134 if(is_array($contact_deny)) {
135 array_walk($contact_deny,'sanitise_acl');
136 $str_contact_deny = implode('',$contact_deny);
139 $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, `theme` = '%s' WHERE `uid` = %d LIMIT 1",
143 dbesc($str_contact_allow),
144 dbesc($str_group_allow),
145 dbesc($str_contact_deny),
146 dbesc($str_group_deny),
149 intval($_SESSION['uid'])
152 notice( t('Settings updated.') . EOL);
154 $r = q("UPDATE `profile`
155 SET `publish` = %d, `net-publish` = %d
156 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
158 intval($net_publish),
159 intval($_SESSION['uid'])
162 if($old_visibility != $net_publish) {
163 // Update global directory in background
164 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
165 $url = $_SESSION['my_url'];
166 if($url && strlen(get_config('system','directory_submit_url')))
167 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
171 $_SESSION['theme'] = $theme;
172 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
174 // FIXME - set to un-verified, blocked and redirect to logout
178 goaway($a->get_baseurl() . '/settings' );
182 if(! function_exists('settings_content')) {
183 function settings_content(&$a) {
186 notice( t('Permission denied.') . EOL );
190 require_once('view/acl_selectors.php');
192 $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
193 intval($_SESSION['uid'])
198 $username = $a->user['username'];
199 $email = $a->user['email'];
200 $nickname = $a->user['nickname'];
201 $timezone = $a->user['timezone'];
202 $notify = $a->user['notify-flags'];
204 if(! strlen($a->user['timezone']))
205 $timezone = date_default_timezone_get();
208 $opt_tpl = file_get_contents("view/profile-in-directory.tpl");
209 $profile_in_dir = replace_macros($opt_tpl,array(
210 '$yes_selected' => (($profile['publish']) ? " checked=\"checked\" " : ""),
211 '$no_selected' => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
214 if(strlen(get_config('system','directory_submit_url'))) {
215 $opt_tpl = file_get_contents("view/profile-in-netdir.tpl");
217 $profile_in_net_dir = replace_macros($opt_tpl,array(
218 '$yes_selected' => (($profile['net-publish']) ? " checked=\"checked\" " : ""),
219 '$no_selected' => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
223 $profile_in_net_dir = '';
229 $nickname_block = file_get_contents("view/settings_nick_set.tpl");
232 $nickname_subdir = '';
233 if(strlen($a->get_path())) {
234 $subdir_tpl = file_get_contents('view/settings_nick_subdir.tpl');
235 $nickname_subdir = replace_macros($subdir_tpl, array(
236 '$baseurl' => $a->get_baseurl(),
237 '$nickname' => $nickname,
238 '$hostname' => $a->get_hostname()
242 $theme_selector = '<select name="theme" id="theme-select" >';
243 $files = glob('view/theme/*');
245 foreach($files as $file) {
246 $f = basename($file);
247 $selected = (($f == $_SESSION['theme']) || ($f == 'default' && (! x($_SESSION,'theme')))
248 ? ' selected="selected" ' : '' );
249 $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
252 $theme_selector .= '</select>';
255 $nickname_block = replace_macros($nickname_block,array(
256 '$nickname' => $nickname,
257 '$uid' => $_SESSION['uid'],
258 '$subdir' => $nickname_subdir,
259 '$basepath' => $a->get_hostname(),
260 '$baseurl' => $a->get_baseurl()));
262 $o = file_get_contents('view/settings.tpl');
264 $o = replace_macros($o,array(
265 '$baseurl' => $a->get_baseurl(),
266 '$uid' => $_SESSION['uid'],
267 '$username' => $username,
269 '$nickname_block' => $nickname_block,
270 '$timezone' => $timezone,
271 '$zoneselect' => select_timezone($timezone),
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),
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