]> git.mxchange.org Git - friendica.git/blob - mod/settings.php
new string wasn't configured for translation.
[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
18         call_hooks('settings_post', $_POST);
19
20         if(($a->argc > 1) && ($a->argv[1] == 'addon'))
21                 return;
22
23         if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
24                 notice( t('Permission denied.') . EOL);
25                 return;
26         }
27         if((x($_POST,'npassword')) || (x($_POST,'confirm'))) {
28
29                 $newpass = $_POST['npassword'];
30                 $confirm = $_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(local_user())
48                         );
49                         if($r)
50                                 notice( t('Password changed.') . EOL);
51                         else
52                                 notice( t('Password update failed. Please try again.') . EOL);
53                 }
54         }
55
56         $theme            = ((x($_POST,'theme'))      ? notags(trim($_POST['theme']))        : '');
57         $username         = ((x($_POST,'username'))   ? notags(trim($_POST['username']))     : '');
58         $email            = ((x($_POST,'email'))      ? notags(trim($_POST['email']))        : '');
59         $timezone         = ((x($_POST,'timezone'))   ? notags(trim($_POST['timezone']))     : '');
60         $defloc           = ((x($_POST,'defloc'))     ? notags(trim($_POST['defloc']))       : '');
61         $openid           = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url']))   : '');
62         $maxreq           = ((x($_POST,'maxreq'))     ? intval($_POST['maxreq'])             : 0);
63
64         $allow_location   = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
65         $publish          = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
66         $net_publish      = (((x($_POST,'profile_in_netdirectory')) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
67         $old_visibility   = (((x($_POST,'visibility')) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
68         $page_flags       = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
69
70         $notify = 0;
71
72         if(x($_POST,'notify1'))
73                 $notify += intval($_POST['notify1']);
74         if(x($_POST,'notify2'))
75                 $notify += intval($_POST['notify2']);
76         if(x($_POST,'notify3'))
77                 $notify += intval($_POST['notify3']);
78         if(x($_POST,'notify4'))
79                 $notify += intval($_POST['notify4']);
80         if(x($_POST,'notify5'))
81                 $notify += intval($_POST['notify5']);
82
83         $email_changed = false;
84
85         $err = '';
86
87         if($username != $a->user['username']) {
88                 if(strlen($username) > 40)
89                         $err .= t(' Please use a shorter name.');
90                 if(strlen($username) < 3)
91                         $err .= t(' Name too short.');
92         }
93
94         if($email != $a->user['email']) {
95                 $email_changed = true;
96         if(! valid_email($email))
97                         $err .= t(' Not valid email.');
98         }
99
100         if(strlen($err)) {
101                 notice($err . EOL);
102                 return;
103         }
104
105         if($timezone != $a->user['timezone']) {
106                 if(strlen($timezone))
107                         date_default_timezone_set($timezone);
108         }
109
110         $str_group_allow   = perms2str($_POST['group_allow']);
111         $str_contact_allow = perms2str($_POST['contact_allow']);
112         $str_group_deny    = perms2str($_POST['group_deny']);
113         $str_contact_deny  = perms2str($_POST['contact_deny']);
114
115         $openidserver = $a->user['openidserver'];
116
117         // If openid has changed or if there's an openid but no openidserver, try and discover it.
118
119         if($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) {
120                 logger('updating openidserver');
121                 require_once('library/openid.php');
122                 $open_id_obj = new LightOpenID;
123                 $open_id_obj->identity = $openid;
124                 $openidserver = $open_id_obj->discover($open_id_obj->identity);
125         }
126
127         $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', `maxreq` = %d, `openidserver` = '%s'  WHERE `uid` = %d LIMIT 1",
128                         dbesc($username),
129                         dbesc($email),
130                         dbesc($openid),
131                         dbesc($timezone),
132                         dbesc($str_contact_allow),
133                         dbesc($str_group_allow),
134                         dbesc($str_contact_deny),
135                         dbesc($str_group_deny),
136                         intval($notify),
137                         intval($page_flags),
138                         dbesc($defloc),
139                         intval($allow_location),
140                         dbesc($theme),
141                         intval($maxreq),
142                         dbesc($openidserver),
143                         intval(local_user())
144         );
145         if($r)
146                 notice( t('Settings updated.') . EOL);
147
148         $r = q("UPDATE `profile` 
149                 SET `publish` = %d, `net-publish` = %d
150                 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
151                 intval($publish),
152                 intval($net_publish),
153                 intval(local_user())
154         );
155
156         if($old_visibility != $net_publish) {
157                 // Update global directory in background
158                 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
159                 $url = $_SESSION['my_url'];
160                 if($url && strlen(get_config('system','directory_submit_url')))
161                         proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
162                                 array(),$foo));
163         }
164
165         $_SESSION['theme'] = $theme;
166         if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
167
168                 // FIXME - set to un-verified, blocked and redirect to logout
169
170         }
171
172         goaway($a->get_baseurl() . '/settings' );
173         return; // NOTREACHED
174 }
175                 
176
177 if(! function_exists('settings_content')) {
178 function settings_content(&$a) {
179
180         $o = '';
181         $o .= '<script> $(document).ready(function() { $(\'#nav-settings-link\').addClass(\'nav-selected\'); });</script>';
182
183         if(! local_user()) {
184                 notice( t('Permission denied.') . EOL );
185                 return;
186         }
187
188         if(($a->argc > 1) && ($a->argv[1] === 'addon')) {
189                 $o .= '<h1>' . t('Plugin Settings') . '</h1>';
190                 $o .= '<div id="account-settings-link"><a href="settings">' . t('Account Settings') . '</a></div>';
191
192                 $o .= '<form action="settings/addon" method="post" >';
193
194                 $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
195                 if(! count($r))
196                         notice( t('No Plugin settings configured') . EOL);
197
198                 call_hooks('plugin_settings', $o);
199                 $o .= '</form>';
200                 return $o;
201         }
202                 
203         require_once('include/acl_selectors.php');
204
205         $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
206                 intval(local_user())
207         );
208         if(count($p))
209                 $profile = $p[0];
210
211         $username = $a->user['username'];
212         $email    = $a->user['email'];
213         $nickname = $a->user['nickname'];
214         $timezone = $a->user['timezone'];
215         $notify   = $a->user['notify-flags'];
216         $defloc   = $a->user['default-location'];
217         $openid   = $a->user['openid'];
218         $maxreq   = $a->user['maxreq'];
219
220         if(! strlen($a->user['timezone']))
221                 $timezone = date_default_timezone_get();
222
223         $pageset_tpl = load_view_file('view/pagetypes.tpl');
224         $pagetype = replace_macros($pageset_tpl,array(
225                 '$normal'         => (($a->user['page-flags'] == PAGE_NORMAL)      ? " checked=\"checked\" " : ""),
226                 '$soapbox'        => (($a->user['page-flags'] == PAGE_SOAPBOX)     ? " checked=\"checked\" " : ""),
227                 '$community'      => (($a->user['page-flags'] == PAGE_COMMUNITY)   ? " checked=\"checked\" " : ""),
228                 '$freelove'       => (($a->user['page-flags'] == PAGE_FREELOVE)    ? " checked=\"checked\" " : ""),
229                 '$page_normal'    => PAGE_NORMAL,
230                 '$page_soapbox'   => PAGE_SOAPBOX,
231                 '$page_community' => PAGE_COMMUNITY,
232                 '$page_freelove'  => PAGE_FREELOVE
233         ));
234
235         $noid = get_config('system','no_openid');
236
237         if($noid) {
238                 $oidhtml = '';
239         }
240         else {
241                 $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.");
242         }
243
244
245
246
247         $opt_tpl = load_view_file("view/profile-in-directory.tpl");
248         $profile_in_dir = replace_macros($opt_tpl,array(
249                 '$yes_selected' => (($profile['publish'])      ? " checked=\"checked\" " : ""),
250                 '$no_selected'  => (($profile['publish'] == 0) ? " checked=\"checked\" " : "")
251         ));
252
253         if(strlen(get_config('system','directory_submit_url'))) {
254                 $opt_tpl = load_view_file("view/profile-in-netdir.tpl");
255
256                 $profile_in_net_dir = replace_macros($opt_tpl,array(
257                         '$yes_selected' => (($profile['net-publish'])      ? " checked=\"checked\" " : ""),
258                         '$no_selected'  => (($profile['net-publish'] == 0) ? " checked=\"checked\" " : "")
259                 ));
260         }
261         else
262                 $profile_in_net_dir = '';
263
264         $loc_checked = (($a->user['allow_location'] == 1)      ? " checked=\"checked\" " : "");
265
266         $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
267                 ? true : false);
268
269         if($invisible)
270                 notice( t('Profile is <strong>not published</strong>.') . EOL );
271
272         $nickname_block = load_view_file("view/settings_nick_set.tpl");
273         
274         $nickname_subdir = '';
275         if(strlen($a->get_path())) {
276                 $subdir_tpl = load_view_file('view/settings_nick_subdir.tpl');
277                 $nickname_subdir = replace_macros($subdir_tpl, array(
278                         '$baseurl' => $a->get_baseurl(),
279                         '$nickname' => $nickname,
280                         '$hostname' => $a->get_hostname()
281                 ));
282         }
283
284         $theme_selector = '<select name="theme" id="theme-select" >';
285         $files = glob('view/theme/*');
286         if($files) {
287                 foreach($files as $file) {
288                         $f = basename($file);
289                         $selected = (($f == $_SESSION['theme']) || ($f === 'default' && (! x($_SESSION,'theme')))
290                                 ? ' selected="selected" ' : '' );
291                         $theme_selector .= '<option val="' . basename($file) . '"' . $selected . '>' . basename($file) . '</option>';
292                 }
293         }
294         $theme_selector .= '</select>';
295
296
297         $nickname_block = replace_macros($nickname_block,array(
298                 '$nickname' => $nickname,
299                 '$uid' => local_user(),
300                 '$subdir' => $nickname_subdir,
301                 '$basepath' => $a->get_hostname(),
302                 '$baseurl' => $a->get_baseurl()));      
303
304         $stpl = load_view_file('view/settings.tpl');
305
306         $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
307
308         $o .= replace_macros($stpl,array(
309                 '$baseurl' => $a->get_baseurl(),
310                 '$oidhtml' => $oidhtml,
311                 '$uid' => local_user(),
312                 '$username' => $username,
313                 '$openid' => $openid,
314                 '$email' => $email,
315                 '$nickname_block' => $nickname_block,
316                 '$timezone' => $timezone,
317                 '$zoneselect' => select_timezone($timezone),
318                 '$defloc' => $defloc,
319                 '$loc_checked' => $loc_checked,
320                 '$profile_in_dir' => $profile_in_dir,
321                 '$profile_in_net_dir' => $profile_in_net_dir,
322                 '$permissions' => t('Default Post Permissions'),
323                 '$visibility' => $profile['net-publish'],
324                 '$aclselect' => populate_acl($a->user,$celeb),
325                 '$sel_notify1' => (($notify & NOTIFY_INTRO)   ? ' checked="checked" ' : ''),
326                 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
327                 '$sel_notify3' => (($notify & NOTIFY_WALL)    ? ' checked="checked" ' : ''),
328                 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
329                 '$sel_notify5' => (($notify & NOTIFY_MAIL)    ? ' checked="checked" ' : ''),
330                 '$maxreq' => $maxreq,
331                 '$theme' => $theme_selector,
332                 '$pagetype' => $pagetype
333         ));
334
335         call_hooks('settings_form',$o);
336
337         $o .= '</form>' . "\r\n";
338
339         return $o;
340
341 }}
342