]> git.mxchange.org Git - friendica.git/blob - mod/settings.php
default acl's
[friendica.git] / mod / settings.php
1 <?php
2
3
4 function settings_init(&$a) {
5
6         if(! local_user()) {
7                 notice("Permission denied." . EOL);
8                 $a->error = 404;
9                 return;
10         }
11         require_once("mod/profile.php");
12         profile_load($a,$a->user['nickname']);
13 }
14
15
16 function settings_post(&$a) {
17
18
19         if(! local_user()) {
20                 notice( t('Permission denied.') . EOL);
21                 return;
22         }
23         if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != $_SESSION['uid']) {
24                 notice( t('Permission denied.') . EOL);
25                 return;
26         }
27         if((x($_POST,'password')) || (x($_POST,'confirm'))) {
28
29                 $newpass = trim($_POST['password']);
30                 $confirm = trim($_POST['confirm']);
31
32                 $err = false;
33                 if($newpass != $confirm ) {
34                         notice( t('Passwords do not match. Password unchanged.') . EOL);
35                         $err = true;
36                 }
37
38                 if((! x($newpass)) || (! x($confirm))) {
39                         notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
40                         $err = true;
41                 }
42
43                 if(! $err) {
44                         $password = hash('whirlpool',$newpass);
45                         $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d LIMIT 1",
46                                 dbesc($password),
47                                 intval($_SESSION['uid']));
48                         if($r)
49                                 notice( t('Password changed.') . EOL);
50                         else
51                                 notice( t('Password update failed. Please try again.') . EOL);
52                 }
53         }
54
55         $username = notags(trim($_POST['username']));
56         $email = notags(trim($_POST['email']));
57         $timezone = notags(trim($_POST['timezone']));
58
59         $username_changed = false;
60         $email_changed = false;
61         $zone_changed = false;
62         $err = '';
63
64         if($username != $a->user['username']) {
65                 $username_changed = true;
66                 if(strlen($username) > 40)
67                         $err .= t(' Please use a shorter name.');
68                 if(strlen($username) < 3)
69                         $err .= t(' Name too short.');
70         }
71         if($email != $a->user['email']) {
72                 $email_changed = true;
73                 if(!eregi('[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,6}',$email))
74                         $err .= t(' Not valid email.');
75                 $r = q("SELECT `uid` FROM `user`
76                         WHERE `email` = '%s' LIMIT 1",
77                         dbesc($email)
78                         );
79                 if($r !== NULL && count($r))
80                         $err .= t(' This email address is already registered.');
81         }
82
83         if(strlen($err)) {
84                 notice($err . EOL);
85                 return;
86         }
87         if($timezone != $a->user['timezone']) {
88                 $zone_changed = true;
89                 if(strlen($timezone))
90                         date_default_timezone_set($timezone);
91         }
92
93         $str_group_allow = '';
94         $group_allow = $_POST['group_allow'];
95         if(is_array($group_allow)) {
96                 array_walk($group_allow,'sanitise_acl');
97                 $str_group_allow = implode('',$group_allow);
98         }
99
100         $str_contact_allow = '';
101         $contact_allow = $_POST['contact_allow'];
102         if(is_array($contact_allow)) {
103                 array_walk($contact_allow,'sanitise_acl');
104                 $str_contact_allow = implode('',$contact_allow);
105         }
106
107         $str_group_deny = '';
108         $group_deny = $_POST['group_deny'];
109         if(is_array($group_deny)) {
110                 array_walk($group_deny,'sanitise_acl');
111                 $str_group_deny = implode('',$group_deny);
112         }
113
114         $str_contact_deny = '';
115         $contact_deny = $_POST['contact_deny'];
116         if(is_array($contact_deny)) {
117                 array_walk($contact_deny,'sanitise_acl');
118                 $str_contact_deny = implode('',$contact_deny);
119         }
120
121
122
123         $r = q("UPDATE `user` SET `username` = '%s', `email` = '%s', `timezone` = '%s',  `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `uid` = %d LIMIT 1",
124                         dbesc($username),
125                         dbesc($email),
126                         dbesc($timezone),
127                         dbesc($str_contact_allow),
128                         dbesc($str_group_allow),
129                         dbesc($str_contact_deny),
130                         dbesc($str_group_deny),
131                         intval($_SESSION['uid'])
132         );
133         if($r)
134                 notice( t('Settings updated.') . EOL);
135
136         if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
137
138                 // FIXME - set to un-verified, blocked and redirect to logout
139
140         }
141
142
143         // Refresh the content display with new data
144
145         $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
146                 intval($_SESSION['uid']));
147         if(count($r))
148                 $a->user = $r[0];
149 }
150                 
151
152 if(! function_exists('settings_content')) {
153 function settings_content(&$a) {
154
155         if(! local_user()) {
156                 notice( t('Permission denied.') . EOL );
157                 return;
158         }
159
160         require_once('view/acl_selectors.php');
161
162         $username = $a->user['username'];
163         $email    = $a->user['email'];
164         $nickname = $a->user['nickname'];
165         $timezone = $a->user['timezone'];
166
167
168
169         $nickname_block = file_get_contents("view/settings_nick_set.tpl");
170         
171
172         $nickname_subdir = '';
173         if(strlen($a->get_path())) {
174                 $subdir_tpl = file_get_contents('view/settings_nick_subdir.tpl');
175                 $nickname_subdir = replace_macros($subdir_tpl, array(
176                         '$baseurl' => $a->get_baseurl(),
177                         '$nickname' => $nickname,
178                         '$hostname' => $a->get_hostname()
179                 ));
180         }
181
182
183         $nickname_block = replace_macros($nickname_block,array(
184                 '$nickname' => $nickname,
185                 '$uid' => $_SESSION['uid'],
186                 '$subdir' => $nickname_subdir,
187                 '$basepath' => $a->get_hostname(),
188                 '$baseurl' => $a->get_baseurl()));      
189
190         $o = file_get_contents('view/settings.tpl');
191
192         $o = replace_macros($o,array(
193                 '$baseurl' => $a->get_baseurl(),
194                 '$uid' => $_SESSION['uid'],
195                 '$username' => $username,
196                 '$email' => $email,
197                 '$nickname_block' => $nickname_block,
198                 '$timezone' => $timezone,
199                 '$zoneselect' => select_timezone($timezone),
200                 '$permissions' => t('Default Post Permissions'),
201                 '$aclselect' => populate_acl($a->user)
202         ));
203
204         return $o;
205
206 }}