]> git.mxchange.org Git - friendica.git/blob - mod/settings.php
make both content and people search POSTable
[friendica.git] / mod / settings.php
1 <?php
2
3
4 function settings_init(&$a) {
5         if(local_user()) {
6                 profile_load($a,$a->user['nickname']);
7         }
8 }
9
10
11 function settings_post(&$a) {
12
13         if(! local_user()) {
14                 notice( t('Permission denied.') . EOL);
15                 return;
16         }
17         if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
18                 notice( t('Permission denied.') . EOL);
19                 return;
20         }
21         if((x($_POST,'npassword')) || (x($_POST,'confirm'))) {
22
23                 $newpass = $_POST['npassword'];
24                 $confirm = $_POST['confirm'];
25
26                 $err = false;
27                 if($newpass != $confirm ) {
28                         notice( t('Passwords do not match. Password unchanged.') . EOL);
29                         $err = true;
30                 }
31
32                 if((! x($newpass)) || (! x($confirm))) {
33                         notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
34                         $err = true;
35                 }
36
37                 if(! $err) {
38                         $password = hash('whirlpool',$newpass);
39                         $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d LIMIT 1",
40                                 dbesc($password),
41                                 intval(local_user())
42                         );
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            = ((x($_POST,'theme'))      ? notags(trim($_POST['theme']))        : '');
51         $username         = ((x($_POST,'username'))   ? notags(trim($_POST['username']))     : '');
52         $email            = ((x($_POST,'email'))      ? notags(trim($_POST['email']))        : '');
53         $timezone         = ((x($_POST,'timezone'))   ? notags(trim($_POST['timezone']))     : '');
54         $defloc           = ((x($_POST,'defloc'))     ? notags(trim($_POST['defloc']))       : '');
55         $openid           = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url']))   : '');
56
57         $allow_location   = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
58         $publish          = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
59         $net_publish      = (((x($_POST,'profile_in_netdirectory')) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
60         $old_visibility   = (((x($_POST,'visibility')) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
61         $page_flags       = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
62
63         $notify = 0;
64
65         if(x($_POST,'notify1'))
66                 $notify += intval($_POST['notify1']);
67         if(x($_POST,'notify2'))
68                 $notify += intval($_POST['notify2']);
69         if(x($_POST,'notify3'))
70                 $notify += intval($_POST['notify3']);
71         if(x($_POST,'notify4'))
72                 $notify += intval($_POST['notify4']);
73         if(x($_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(! valid_email($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', `openid` = '%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($openid),
112                         dbesc($timezone),
113                         dbesc($str_contact_allow),
114                         dbesc($str_group_allow),
115                         dbesc($str_contact_deny),
116                         dbesc($str_group_deny),
117                         intval($notify),
118                         intval($page_flags),
119                         dbesc($defloc),
120                         intval($allow_location),
121                         dbesc($theme),
122                         intval(local_user())
123         );
124         if($r)
125                 notice( t('Settings updated.') . EOL);
126
127         $r = q("UPDATE `profile` 
128                 SET `publish` = %d, `net-publish` = %d
129                 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
130                 intval($publish),
131                 intval($net_publish),
132                 intval(local_user())
133         );
134
135         if($old_visibility != $net_publish) {
136                 // Update global directory in background
137                 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
138                 $url = $_SESSION['my_url'];
139                 if($url && strlen(get_config('system','directory_submit_url')))
140                         proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
141                                 array(),$foo));
142         }
143
144         $_SESSION['theme'] = $theme;
145         if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
146
147                 // FIXME - set to un-verified, blocked and redirect to logout
148
149         }
150
151         goaway($a->get_baseurl() . '/settings' );
152         return; // NOTREACHED
153 }
154                 
155
156 if(! function_exists('settings_content')) {
157 function settings_content(&$a) {
158
159         $o = '';
160         $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
161
162         if(! local_user()) {
163                 notice( t('Permission denied.') . EOL );
164                 return;
165         }
166
167         require_once('include/acl_selectors.php');
168
169         $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
170                 intval(local_user())
171         );
172         if(count($p))
173                 $profile = $p[0];
174
175         $username = $a->user['username'];
176         $email    = $a->user['email'];
177         $nickname = $a->user['nickname'];
178         $timezone = $a->user['timezone'];
179         $notify   = $a->user['notify-flags'];
180         $defloc   = $a->user['default-location'];
181         $openid   = $a->user['openid'];
182
183         if(! strlen($a->user['timezone']))
184                 $timezone = date_default_timezone_get();
185
186         $pageset_tpl = load_view_file('view/pagetypes.tpl');
187         $pagetype = replace_macros($pageset_tpl,array(
188                 '$normal'         => (($a->user['page-flags'] == PAGE_NORMAL)      ? " checked=\"checked\" " : ""),
189                 '$soapbox'        => (($a->user['page-flags'] == PAGE_SOAPBOX)     ? " checked=\"checked\" " : ""),
190                 '$community'      => (($a->user['page-flags'] == PAGE_COMMUNITY)   ? " checked=\"checked\" " : ""),
191                 '$freelove'       => (($a->user['page-flags'] == PAGE_FREELOVE)    ? " checked=\"checked\" " : ""),
192                 '$page_normal'    => PAGE_NORMAL,
193                 '$page_soapbox'   => PAGE_SOAPBOX,
194                 '$page_community' => PAGE_COMMUNITY,
195                 '$page_freelove'  => PAGE_FREELOVE
196         ));
197
198         $noid = get_config('system','no_openid');
199
200         if($noid) {
201                 $oidhtml = '';
202         }
203         else {
204                 $oidhtml = '<label id="settings-openid-label" for="settings-openid" >' . t('OpenID: ') . '</label><input type="text" id="settings-openid" class="openid" name="openid_url" value="$openid" />' . t("&nbsp;\x28Optional\x29 Allow this OpenID to login to this account.");
205         }
206
207
208
209
210         $opt_tpl = load_view_file("view/profile-in-directory.tpl");
211         $profile_in_dir = replace_macros($opt_tpl,array(
212                 '$yes_selected' => (($profile['publish'])      ? " checked=\"checked\" " : ""),
213                 '$no_selected'  => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
214         ));
215
216         if(strlen(get_config('system','directory_submit_url'))) {
217                 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
218
219                 $profile_in_net_dir = replace_macros($opt_tpl,array(
220                         '$yes_selected' => (($profile['net-publish'])      ? " checked=\"checked\" " : ""),
221                         '$no_selected'  => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
222                 ));
223         }
224         else
225                 $profile_in_net_dir = '';
226
227         $loc_checked = (($a->user['allow_location'] == 1)      ? " checked=\"checked\" " : "");
228
229         $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
230                 ? true : false);
231
232         if($invisible)
233                 notice( t('Profile is <strong>not published</strong>.') . EOL );
234
235         $nickname_block = load_view_file("view/settings_nick_set.tpl");
236         
237         $nickname_subdir = '';
238         if(strlen($a->get_path())) {
239                 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
240                 $nickname_subdir = replace_macros($subdir_tpl, array(
241                         '$baseurl' => $a->get_baseurl(),
242                         '$nickname' => $nickname,
243                         '$hostname' => $a->get_hostname()
244                 ));
245         }
246
247         $theme_selector = '<select name="theme" id="theme-select" >';
248         $files = glob('view/theme/*');
249         if($files) {
250                 foreach($files as $file) {
251                         $f = basename($file);
252                         $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
253                                 ? ' selected="selected" ' : '' );
254                         $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
255                 }
256         }
257         $theme_selector .= '</select>';
258
259
260         $nickname_block = replace_macros($nickname_block,array(
261                 '$nickname' => $nickname,
262                 '$uid' => local_user(),
263                 '$subdir' => $nickname_subdir,
264                 '$basepath' => $a->get_hostname(),
265                 '$baseurl' => $a->get_baseurl()));      
266
267         $stpl = load_view_file('view/settings.tpl');
268
269         $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
270
271         $o .= replace_macros($stpl,array(
272                 '$baseurl' => $a->get_baseurl(),
273                 '$oidhtml' => $oidhtml,
274                 '$uid' => local_user(),
275                 '$username' => $username,
276                 '$openid' => $openid,
277                 '$email' => $email,
278                 '$nickname_block' => $nickname_block,
279                 '$timezone' => $timezone,
280                 '$zoneselect' => select_timezone($timezone),
281                 '$defloc' => $defloc,
282                 '$loc_checked' => $loc_checked,
283                 '$profile_in_dir' => $profile_in_dir,
284                 '$profile_in_net_dir' => $profile_in_net_dir,
285                 '$permissions' => t('Default Post Permissions'),
286                 '$visibility' => $profile['net-publish'],
287                 '$aclselect' => populate_acl($a->user,$celeb),
288                 '$sel_notify1' => (($notify & NOTIFY_INTRO)   ? ' checked="checked" ' : ''),
289                 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
290                 '$sel_notify3' => (($notify & NOTIFY_WALL)    ? ' checked="checked" ' : ''),
291                 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
292                 '$sel_notify5' => (($notify & NOTIFY_MAIL)    ? ' checked="checked" ' : ''),
293                 '$theme' => $theme_selector,
294                 '$pagetype' => $pagetype
295         ));
296
297         return $o;
298
299 }}