]> git.mxchange.org Git - friendica.git/blob - mod/settings.php
mistpark 2.0 infrasturcture lands
[friendica.git] / mod / settings.php
1 <?php
2
3
4 function settings_init(&$a) {
5         if(local_user()) {
6                 require_once("mod/profile.php");
7                 profile_load($a,$a->user['nickname']);
8         }
9 }
10
11
12 function settings_post(&$a) {
13
14         if(! local_user()) {
15                 notice( t('Permission denied.') . EOL);
16                 return;
17         }
18         if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != get_uid()) {
19                 notice( t('Permission denied.') . EOL);
20                 return;
21         }
22         if((x($_POST,'npassword')) || (x($_POST,'confirm'))) {
23
24                 $newpass = trim($_POST['npassword']);
25                 $confirm = trim($_POST['confirm']);
26
27                 $err = false;
28                 if($newpass != $confirm ) {
29                         notice( t('Passwords do not match. Password unchanged.') . EOL);
30                         $err = true;
31                 }
32
33                 if((! x($newpass)) || (! x($confirm))) {
34                         notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
35                         $err = true;
36                 }
37
38                 if(! $err) {
39                         $password = hash('whirlpool',$newpass);
40                         $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d LIMIT 1",
41                                 dbesc($password),
42                                 intval(get_uid());
43                         if($r)
44                                 notice( t('Password changed.') . EOL);
45                         else
46                                 notice( t('Password update failed. Please try again.') . EOL);
47                 }
48         }
49
50         $theme            = notags(trim($_POST['theme']));
51         $username         = notags(trim($_POST['username']));
52         $email            = notags(trim($_POST['email']));
53         $timezone         = notags(trim($_POST['timezone']));
54         $defloc           = notags(trim($_POST['defloc']));
55
56         $publish          = (($_POST['profile_in_directory'] == 1) ? 1: 0);
57         $net_publish      = (($_POST['profile_in_netdirectory'] == 1) ? 1: 0);
58         $old_visibility   = ((intval($_POST['visibility']) == 1) ? 1 : 0);
59
60         $notify = 0;
61
62         if($_POST['notify1'])
63                 $notify += intval($_POST['notify1']);
64         if($_POST['notify2'])
65                 $notify += intval($_POST['notify2']);
66         if($_POST['notify3'])
67                 $notify += intval($_POST['notify3']);
68         if($_POST['notify4'])
69                 $notify += intval($_POST['notify4']);
70         if($_POST['notify5'])
71                 $notify += intval($_POST['notify5']);
72
73         $email_changed = false;
74
75         $err = '';
76
77         if($username != $a->user['username']) {
78                 if(strlen($username) > 40)
79                         $err .= t(' Please use a shorter name.');
80                 if(strlen($username) < 3)
81                         $err .= t(' Name too short.');
82         }
83         if($email != $a->user['email']) {
84                 $email_changed = true;
85                 if(!eregi('[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,6}',$email))
86                         $err .= t(' Not valid email.');
87                 $r = q("SELECT `uid` FROM `user`
88                         WHERE `email` = '%s' LIMIT 1",
89                         dbesc($email)
90                         );
91                 if($r !== NULL && count($r))
92                         $err .= t(' This email address is already registered.');
93         }
94
95         if(strlen($err)) {
96                 notice($err . EOL);
97                 return;
98         }
99         if($timezone != $a->user['timezone']) {
100                 if(strlen($timezone))
101                         date_default_timezone_set($timezone);
102         }
103
104
105         $str_group_allow   = perms2str($_POST['group_allow']);
106         $str_contact_allow = perms2str($_POST['contact_allow']);
107         $str_group_deny    = perms2str($_POST['group_deny']);
108         $str_contact_deny  = perms2str($_POST['contact_deny']);
109
110         $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, `default-location` = '%s', `theme` = '%s'  WHERE `uid` = %d LIMIT 1",
111                         dbesc($username),
112                         dbesc($email),
113                         dbesc($timezone),
114                         dbesc($str_contact_allow),
115                         dbesc($str_group_allow),
116                         dbesc($str_contact_deny),
117                         dbesc($str_group_deny),
118                         intval($notify),
119                         dbesc($defloc),
120                         dbesc($theme),
121                         intval(get_uid())
122         );
123         if($r)
124                 notice( t('Settings updated.') . EOL);
125
126         $r = q("UPDATE `profile` 
127                 SET `publish` = %d, `net-publish` = %d
128                 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
129                 intval($publish),
130                 intval($net_publish),
131                 intval(get_uid())
132         );
133
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\" &",
140                                 array(),$foo));
141         }
142
143         $_SESSION['theme'] = $theme;
144         if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
145
146                 // FIXME - set to un-verified, blocked and redirect to logout
147
148         }
149
150         goaway($a->get_baseurl() . '/settings' );
151         return; // NOTREACHED
152 }
153                 
154
155 if(! function_exists('settings_content')) {
156 function settings_content(&$a) {
157
158         if(! local_user()) {
159                 notice( t('Permission denied.') . EOL );
160                 return;
161         }
162
163         require_once('view/acl_selectors.php');
164
165         $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
166                 intval($_SESSION['uid'])
167         );
168         if(count($p))
169                 $profile = $p[0];
170
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'];
177
178         if(! strlen($a->user['timezone']))
179                 $timezone = date_default_timezone_get();
180
181
182         $opt_tpl = file_get_contents("view/profile-in-directory.tpl");
183         $profile_in_dir = replace_macros($opt_tpl,array(
184                 '$yes_selected' => (($profile['publish'])      ? " checked=\"checked\" " : ""),
185                 '$no_selected'  => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
186         ));
187
188         if(strlen(get_config('system','directory_submit_url'))) {
189                 $opt_tpl = file_get_contents("view/profile-in-netdir.tpl");
190
191                 $profile_in_net_dir = replace_macros($opt_tpl,array(
192                         '$yes_selected' => (($profile['net-publish'])      ? " checked=\"checked\" " : ""),
193                         '$no_selected'  => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
194                 ));
195         }
196         else
197                 $profile_in_net_dir = '';
198
199         $nickname_block = file_get_contents("view/settings_nick_set.tpl");
200         
201         $nickname_subdir = '';
202         if(strlen($a->get_path())) {
203                 $subdir_tpl = file_get_contents('view/settings_nick_subdir.tpl');
204                 $nickname_subdir = replace_macros($subdir_tpl, array(
205                         '$baseurl' => $a->get_baseurl(),
206                         '$nickname' => $nickname,
207                         '$hostname' => $a->get_hostname()
208                 ));
209         }
210
211         $theme_selector = '<select name="theme" id="theme-select" >';
212         $files = glob('view/theme/*');
213         if($files) {
214                 foreach($files as $file) {
215                         $f = basename($file);
216                         $selected = (($f == $_SESSION['theme']) || ($f == 'default' && (! x($_SESSION,'theme')))
217                                 ? ' selected="selected" ' : '' );
218                         $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
219                 }
220         }
221         $theme_selector .= '</select>';
222
223
224         $nickname_block = replace_macros($nickname_block,array(
225                 '$nickname' => $nickname,
226                 '$uid' => $_SESSION['uid'],
227                 '$subdir' => $nickname_subdir,
228                 '$basepath' => $a->get_hostname(),
229                 '$baseurl' => $a->get_baseurl()));      
230
231         $o = file_get_contents('view/settings.tpl');
232
233         $o = replace_macros($o,array(
234                 '$baseurl' => $a->get_baseurl(),
235                 '$uid' => $_SESSION['uid'],
236                 '$username' => $username,
237                 '$email' => $email,
238                 '$nickname_block' => $nickname_block,
239                 '$timezone' => $timezone,
240                 '$zoneselect' => select_timezone($timezone),
241                 '$defloc' => $defloc,
242                 '$profile_in_dir' => $profile_in_dir,
243                 '$profile_in_net_dir' => $profile_in_net_dir,
244                 '$permissions' => t('Default Post Permissions'),
245                 '$visibility' => $profile['net-publish'],
246                 '$aclselect' => populate_acl($a->user),
247                 '$sel_notify1' => (($notify & NOTIFY_INTRO)   ? ' checked="checked" ' : ''),
248                 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
249                 '$sel_notify3' => (($notify & NOTIFY_WALL)    ? ' checked="checked" ' : ''),
250                 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
251                 '$sel_notify5' => (($notify & NOTIFY_MAIL)    ? ' checked="checked" ' : ''),
252                 '$theme' => $theme_selector
253         ));
254
255         return $o;
256
257 }}