]> git.mxchange.org Git - friendica.git/blob - mod/settings.php
celebrity/group/community pages about 75% implemented
[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 = $_POST['npassword'];
25                 $confirm = $_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                         );
44                         if($r)
45                                 notice( t('Password changed.') . EOL);
46                         else
47                                 notice( t('Password update failed. Please try again.') . EOL);
48                 }
49         }
50
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']));
56
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
61         $notify = 0;
62
63         if($_POST['notify1'])
64                 $notify += intval($_POST['notify1']);
65         if($_POST['notify2'])
66                 $notify += intval($_POST['notify2']);
67         if($_POST['notify3'])
68                 $notify += intval($_POST['notify3']);
69         if($_POST['notify4'])
70                 $notify += intval($_POST['notify4']);
71         if($_POST['notify5'])
72                 $notify += intval($_POST['notify5']);
73
74         $email_changed = false;
75
76         $err = '';
77
78         if($username != $a->user['username']) {
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
85         if($email != $a->user['email']) {
86                 $email_changed = true;
87                 if(!eregi('[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,6}',$email))
88                         $err .= t(' Not valid email.');
89         }
90
91         if(strlen($err)) {
92                 notice($err . EOL);
93                 return;
94         }
95
96         if($timezone != $a->user['timezone']) {
97                 if(strlen($timezone))
98                         date_default_timezone_set($timezone);
99         }
100
101         $str_group_allow   = perms2str($_POST['group_allow']);
102         $str_contact_allow = perms2str($_POST['contact_allow']);
103         $str_group_deny    = perms2str($_POST['group_deny']);
104         $str_contact_deny  = perms2str($_POST['contact_deny']);
105
106         $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",
107                         dbesc($username),
108                         dbesc($email),
109                         dbesc($timezone),
110                         dbesc($str_contact_allow),
111                         dbesc($str_group_allow),
112                         dbesc($str_contact_deny),
113                         dbesc($str_group_deny),
114                         intval($notify),
115                         dbesc($defloc),
116                         dbesc($theme),
117                         intval(get_uid())
118         );
119         if($r)
120                 notice( t('Settings updated.') . EOL);
121
122         $r = q("UPDATE `profile` 
123                 SET `publish` = %d, `net-publish` = %d
124                 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
125                 intval($publish),
126                 intval($net_publish),
127                 intval(get_uid())
128         );
129
130         if($old_visibility != $net_publish) {
131                 // Update global directory in background
132                 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
133                 $url = $_SESSION['my_url'];
134                 if($url && strlen(get_config('system','directory_submit_url')))
135                         proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
136                                 array(),$foo));
137         }
138
139         $_SESSION['theme'] = $theme;
140         if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
141
142                 // FIXME - set to un-verified, blocked and redirect to logout
143
144         }
145
146         goaway($a->get_baseurl() . '/settings' );
147         return; // NOTREACHED
148 }
149                 
150
151 if(! function_exists('settings_content')) {
152 function settings_content(&$a) {
153
154         $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
155
156         if(! local_user()) {
157                 notice( t('Permission denied.') . EOL );
158                 return;
159         }
160
161         require_once('view/acl_selectors.php');
162
163         $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
164                 intval($_SESSION['uid'])
165         );
166         if(count($p))
167                 $profile = $p[0];
168
169         $username = $a->user['username'];
170         $email    = $a->user['email'];
171         $nickname = $a->user['nickname'];
172         $timezone = $a->user['timezone'];
173         $notify   = $a->user['notify-flags'];
174         $defloc   = $a->user['default-location'];
175
176         if(! strlen($a->user['timezone']))
177                 $timezone = date_default_timezone_get();
178
179
180         $opt_tpl = load_view_file("view/profile-in-directory.tpl");
181         $profile_in_dir = replace_macros($opt_tpl,array(
182                 '$yes_selected' => (($profile['publish'])      ? " checked=\"checked\" " : ""),
183                 '$no_selected'  => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
184         ));
185
186         if(strlen(get_config('system','directory_submit_url'))) {
187                 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
188
189                 $profile_in_net_dir = replace_macros($opt_tpl,array(
190                         '$yes_selected' => (($profile['net-publish'])      ? " checked=\"checked\" " : ""),
191                         '$no_selected'  => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
192                 ));
193         }
194         else
195                 $profile_in_net_dir = '';
196
197         $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
198                 ? true : false);
199
200         if($invisible)
201                 notice( t('Profile is <strong>not published</strong>.') . EOL );
202
203         $nickname_block = load_view_file("view/settings_nick_set.tpl");
204         
205         $nickname_subdir = '';
206         if(strlen($a->get_path())) {
207                 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
208                 $nickname_subdir = replace_macros($subdir_tpl, array(
209                         '$baseurl' => $a->get_baseurl(),
210                         '$nickname' => $nickname,
211                         '$hostname' => $a->get_hostname()
212                 ));
213         }
214
215         $theme_selector = '<select name="theme" id="theme-select" >';
216         $files = glob('view/theme/*');
217         if($files) {
218                 foreach($files as $file) {
219                         $f = basename($file);
220                         $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
221                                 ? ' selected="selected" ' : '' );
222                         $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
223                 }
224         }
225         $theme_selector .= '</select>';
226
227
228         $nickname_block = replace_macros($nickname_block,array(
229                 '$nickname' => $nickname,
230                 '$uid' => $_SESSION['uid'],
231                 '$subdir' => $nickname_subdir,
232                 '$basepath' => $a->get_hostname(),
233                 '$baseurl' => $a->get_baseurl()));      
234
235         $stpl = load_view_file('view/settings.tpl');
236
237         $o .= replace_macros($stpl,array(
238                 '$baseurl' => $a->get_baseurl(),
239                 '$uid' => $_SESSION['uid'],
240                 '$username' => $username,
241                 '$email' => $email,
242                 '$nickname_block' => $nickname_block,
243                 '$timezone' => $timezone,
244                 '$zoneselect' => select_timezone($timezone),
245                 '$defloc' => $defloc,
246                 '$profile_in_dir' => $profile_in_dir,
247                 '$profile_in_net_dir' => $profile_in_net_dir,
248                 '$permissions' => t('Default Post Permissions'),
249                 '$visibility' => $profile['net-publish'],
250                 '$aclselect' => populate_acl($a->user),
251                 '$sel_notify1' => (($notify & NOTIFY_INTRO)   ? ' checked="checked" ' : ''),
252                 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
253                 '$sel_notify3' => (($notify & NOTIFY_WALL)    ? ' checked="checked" ' : ''),
254                 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
255                 '$sel_notify5' => (($notify & NOTIFY_MAIL)    ? ' checked="checked" ' : ''),
256                 '$theme' => $theme_selector
257         ));
258
259         return $o;
260
261 }}