]> git.mxchange.org Git - friendica.git/blob - mod/settings.php
10336e7716e5781c911c5fda404d4ef66b6bfe40
[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         $notify = 0;
60
61         if($_POST['notify1'])
62                 $notify += intval($_POST['notify1']);
63         if($_POST['notify2'])
64                 $notify += intval($_POST['notify2']);
65         if($_POST['notify3'])
66                 $notify += intval($_POST['notify3']);
67         if($_POST['notify4'])
68                 $notify += intval($_POST['notify4']);
69         if($_POST['notify5'])
70                 $notify += intval($_POST['notify5']);
71
72         $username_changed = false;
73         $email_changed = false;
74         $zone_changed = false;
75         $err = '';
76
77         if($username != $a->user['username']) {
78                 $username_changed = true;
79                 if(strlen($username) > 40)
80                         $err .= t(' Please use a shorter name.');
81                 if(strlen($username) < 3)
82                         $err .= t(' Name too short.');
83         }
84         if($email != $a->user['email']) {
85                 $email_changed = true;
86                 if(!eregi('[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,6}',$email))
87                         $err .= t(' Not valid email.');
88                 $r = q("SELECT `uid` FROM `user`
89                         WHERE `email` = '%s' LIMIT 1",
90                         dbesc($email)
91                         );
92                 if($r !== NULL && count($r))
93                         $err .= t(' This email address is already registered.');
94         }
95
96         if(strlen($err)) {
97                 notice($err . EOL);
98                 return;
99         }
100         if($timezone != $a->user['timezone']) {
101                 $zone_changed = true;
102                 if(strlen($timezone))
103                         date_default_timezone_set($timezone);
104         }
105
106         $str_group_allow = '';
107         $group_allow = $_POST['group_allow'];
108         if(is_array($group_allow)) {
109                 array_walk($group_allow,'sanitise_acl');
110                 $str_group_allow = implode('',$group_allow);
111         }
112
113         $str_contact_allow = '';
114         $contact_allow = $_POST['contact_allow'];
115         if(is_array($contact_allow)) {
116                 array_walk($contact_allow,'sanitise_acl');
117                 $str_contact_allow = implode('',$contact_allow);
118         }
119
120         $str_group_deny = '';
121         $group_deny = $_POST['group_deny'];
122         if(is_array($group_deny)) {
123                 array_walk($group_deny,'sanitise_acl');
124                 $str_group_deny = implode('',$group_deny);
125         }
126
127         $str_contact_deny = '';
128         $contact_deny = $_POST['contact_deny'];
129         if(is_array($contact_deny)) {
130                 array_walk($contact_deny,'sanitise_acl');
131                 $str_contact_deny = implode('',$contact_deny);
132         }
133
134
135
136         $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  WHERE `uid` = %d LIMIT 1",
137                         dbesc($username),
138                         dbesc($email),
139                         dbesc($timezone),
140                         dbesc($str_contact_allow),
141                         dbesc($str_group_allow),
142                         dbesc($str_contact_deny),
143                         dbesc($str_group_deny),
144                         intval($notify),
145                         intval($_SESSION['uid'])
146         );
147         if($r)
148                 notice( t('Settings updated.') . EOL);
149
150         if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
151
152                 // FIXME - set to un-verified, blocked and redirect to logout
153
154         }
155
156
157         // Refresh the content display with new data
158
159         $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
160                 intval($_SESSION['uid']));
161         if(count($r))
162                 $a->user = $r[0];
163 }
164                 
165
166 if(! function_exists('settings_content')) {
167 function settings_content(&$a) {
168
169         if(! local_user()) {
170                 notice( t('Permission denied.') . EOL );
171                 return;
172         }
173
174         require_once('view/acl_selectors.php');
175
176         $username = $a->user['username'];
177         $email    = $a->user['email'];
178         $nickname = $a->user['nickname'];
179         $timezone = $a->user['timezone'];
180         $notify   = $a->user['notify-flags'];
181
182
183         $nickname_block = file_get_contents("view/settings_nick_set.tpl");
184         
185
186         $nickname_subdir = '';
187         if(strlen($a->get_path())) {
188                 $subdir_tpl = file_get_contents('view/settings_nick_subdir.tpl');
189                 $nickname_subdir = replace_macros($subdir_tpl, array(
190                         '$baseurl' => $a->get_baseurl(),
191                         '$nickname' => $nickname,
192                         '$hostname' => $a->get_hostname()
193                 ));
194         }
195
196
197         $nickname_block = replace_macros($nickname_block,array(
198                 '$nickname' => $nickname,
199                 '$uid' => $_SESSION['uid'],
200                 '$subdir' => $nickname_subdir,
201                 '$basepath' => $a->get_hostname(),
202                 '$baseurl' => $a->get_baseurl()));      
203
204         $o = file_get_contents('view/settings.tpl');
205
206         $o = replace_macros($o,array(
207                 '$baseurl' => $a->get_baseurl(),
208                 '$uid' => $_SESSION['uid'],
209                 '$username' => $username,
210                 '$email' => $email,
211                 '$nickname_block' => $nickname_block,
212                 '$timezone' => $timezone,
213                 '$zoneselect' => select_timezone($timezone),
214                 '$permissions' => t('Default Post Permissions'),
215                 '$aclselect' => populate_acl($a->user),
216                 '$sel_notify1' => (($notify & NOTIFY_INTRO)   ? ' checked="checked" ' : ''),
217                 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
218                 '$sel_notify3' => (($notify & NOTIFY_WALL)    ? ' checked="checked" ' : ''),
219                 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
220                 '$sel_notify5' => (($notify & NOTIFY_MAIL)    ? ' checked="checked" ' : '')
221         ));
222
223         return $o;
224
225 }}