]> git.mxchange.org Git - friendica.git/blob - mod/settings.php
cleanup photo page a bit more, some work on branding
[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'] != local_user()) {
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(local_user())
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         $allow_location   = (($_POST['allow_location'] == 1) ? 1: 0);
58         $publish          = (($_POST['profile_in_directory'] == 1) ? 1: 0);
59         $net_publish      = (($_POST['profile_in_netdirectory'] == 1) ? 1: 0);
60         $old_visibility   = ((intval($_POST['visibility']) == 1) ? 1 : 0);
61         $page_flags       = ((intval($_POST['page-flags'])) ? intval($_POST['page-flags']) : 0);
62
63         $notify = 0;
64
65         if($_POST['notify1'])
66                 $notify += intval($_POST['notify1']);
67         if($_POST['notify2'])
68                 $notify += intval($_POST['notify2']);
69         if($_POST['notify3'])
70                 $notify += intval($_POST['notify3']);
71         if($_POST['notify4'])
72                 $notify += intval($_POST['notify4']);
73         if($_POST['notify5'])
74                 $notify += intval($_POST['notify5']);
75
76         $email_changed = false;
77
78         $err = '';
79
80         if($username != $a->user['username']) {
81                 if(strlen($username) > 40)
82                         $err .= t(' Please use a shorter name.');
83                 if(strlen($username) < 3)
84                         $err .= t(' Name too short.');
85         }
86
87         if($email != $a->user['email']) {
88                 $email_changed = true;
89                 if(!eregi('[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,6}',$email))
90                         $err .= t(' Not valid email.');
91         }
92
93         if(strlen($err)) {
94                 notice($err . EOL);
95                 return;
96         }
97
98         if($timezone != $a->user['timezone']) {
99                 if(strlen($timezone))
100                         date_default_timezone_set($timezone);
101         }
102
103         $str_group_allow   = perms2str($_POST['group_allow']);
104         $str_contact_allow = perms2str($_POST['contact_allow']);
105         $str_group_deny    = perms2str($_POST['group_deny']);
106         $str_contact_deny  = perms2str($_POST['contact_deny']);
107
108         $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, `page-flags` = %d, `default-location` = '%s', `allow_location` = %d, `theme` = '%s'  WHERE `uid` = %d LIMIT 1",
109                         dbesc($username),
110                         dbesc($email),
111                         dbesc($timezone),
112                         dbesc($str_contact_allow),
113                         dbesc($str_group_allow),
114                         dbesc($str_contact_deny),
115                         dbesc($str_group_deny),
116                         intval($notify),
117                         intval($page_flags),
118                         dbesc($defloc),
119                         intval($allow_location),
120                         dbesc($theme),
121                         intval(local_user())
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(local_user())
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         $o = '';
159         $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
160
161         if(! local_user()) {
162                 notice( t('Permission denied.') . EOL );
163                 return;
164         }
165
166         require_once('view/acl_selectors.php');
167
168         $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
169                 intval($_SESSION['uid'])
170         );
171         if(count($p))
172                 $profile = $p[0];
173
174         $username = $a->user['username'];
175         $email    = $a->user['email'];
176         $nickname = $a->user['nickname'];
177         $timezone = $a->user['timezone'];
178         $notify   = $a->user['notify-flags'];
179         $defloc   = $a->user['default-location'];
180
181         if(! strlen($a->user['timezone']))
182                 $timezone = date_default_timezone_get();
183
184         $pageset_tpl = load_view_file('view/pagetypes.tpl');
185         $pagetype = replace_macros($pageset_tpl,array(
186                 '$normal'         => (($a->user['page-flags'] == PAGE_NORMAL)      ? " checked=\"checked\" " : ""),
187                 '$soapbox'        => (($a->user['page-flags'] == PAGE_SOAPBOX)     ? " checked=\"checked\" " : ""),
188                 '$community'      => (($a->user['page-flags'] == PAGE_COMMUNITY)   ? " checked=\"checked\" " : ""),
189                 '$freelove'       => (($a->user['page-flags'] == PAGE_FREELOVE)    ? " checked=\"checked\" " : ""),
190                 '$page_normal'    => PAGE_NORMAL,
191                 '$page_soapbox'   => PAGE_SOAPBOX,
192                 '$page_community' => PAGE_COMMUNITY,
193                 '$page_freelove'  => PAGE_FREELOVE
194         ));
195
196
197         $opt_tpl = load_view_file("view/profile-in-directory.tpl");
198         $profile_in_dir = replace_macros($opt_tpl,array(
199                 '$yes_selected' => (($profile['publish'])      ? " checked=\"checked\" " : ""),
200                 '$no_selected'  => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
201         ));
202
203         if(strlen(get_config('system','directory_submit_url'))) {
204                 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
205
206                 $profile_in_net_dir = replace_macros($opt_tpl,array(
207                         '$yes_selected' => (($profile['net-publish'])      ? " checked=\"checked\" " : ""),
208                         '$no_selected'  => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
209                 ));
210         }
211         else
212                 $profile_in_net_dir = '';
213
214         $loc_checked = (($a->user['allow_location'] == 1)      ? " checked=\"checked\" " : "");
215
216         $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
217                 ? true : false);
218
219         if($invisible)
220                 notice( t('Profile is <strong>not published</strong>.') . EOL );
221
222         $nickname_block = load_view_file("view/settings_nick_set.tpl");
223         
224         $nickname_subdir = '';
225         if(strlen($a->get_path())) {
226                 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
227                 $nickname_subdir = replace_macros($subdir_tpl, array(
228                         '$baseurl' => $a->get_baseurl(),
229                         '$nickname' => $nickname,
230                         '$hostname' => $a->get_hostname()
231                 ));
232         }
233
234         $theme_selector = '<select name="theme" id="theme-select" >';
235         $files = glob('view/theme/*');
236         if($files) {
237                 foreach($files as $file) {
238                         $f = basename($file);
239                         $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
240                                 ? ' selected="selected" ' : '' );
241                         $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
242                 }
243         }
244         $theme_selector .= '</select>';
245
246
247         $nickname_block = replace_macros($nickname_block,array(
248                 '$nickname' => $nickname,
249                 '$uid' => $_SESSION['uid'],
250                 '$subdir' => $nickname_subdir,
251                 '$basepath' => $a->get_hostname(),
252                 '$baseurl' => $a->get_baseurl()));      
253
254         $stpl = load_view_file('view/settings.tpl');
255
256         $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
257
258         $o .= replace_macros($stpl,array(
259                 '$baseurl' => $a->get_baseurl(),
260                 '$uid' => $_SESSION['uid'],
261                 '$username' => $username,
262                 '$email' => $email,
263                 '$nickname_block' => $nickname_block,
264                 '$timezone' => $timezone,
265                 '$zoneselect' => select_timezone($timezone),
266                 '$defloc' => $defloc,
267                 '$loc_checked' => $loc_checked,
268                 '$profile_in_dir' => $profile_in_dir,
269                 '$profile_in_net_dir' => $profile_in_net_dir,
270                 '$permissions' => t('Default Post Permissions'),
271                 '$visibility' => $profile['net-publish'],
272                 '$aclselect' => populate_acl($a->user,$celeb),
273                 '$sel_notify1' => (($notify & NOTIFY_INTRO)   ? ' checked="checked" ' : ''),
274                 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
275                 '$sel_notify3' => (($notify & NOTIFY_WALL)    ? ' checked="checked" ' : ''),
276                 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
277                 '$sel_notify5' => (($notify & NOTIFY_MAIL)    ? ' checked="checked" ' : ''),
278                 '$theme' => $theme_selector,
279                 '$pagetype' => $pagetype
280         ));
281
282         return $o;
283
284 }}