]> git.mxchange.org Git - friendica.git/blob - mod/settings.php
Merge pull request #2326 from fabrixxm/revert_db949bb8
[friendica.git] / mod / settings.php
1 <?php
2
3
4 function get_theme_config_file($theme){
5         $a = get_app();
6         $base_theme = $a->theme_info['extends'];
7
8         if (file_exists("view/theme/$theme/config.php")){
9                 return "view/theme/$theme/config.php";
10         }
11         if (file_exists("view/theme/$base_theme/config.php")){
12                 return "view/theme/$base_theme/config.php";
13         }
14         return null;
15 }
16
17 function settings_init(&$a) {
18
19         if(! local_user()) {
20                 notice( t('Permission denied.') . EOL );
21                 return;
22         }
23
24         // APC deactivated, since there are problems with PHP 5.5
25         //if (function_exists("apc_delete")) {
26         //      $toDelete = new APCIterator('user', APC_ITER_VALUE);
27         //      apc_delete($toDelete);
28         //}
29
30         // These lines provide the javascript needed by the acl selector
31
32         $tpl = get_markup_template("settings-head.tpl");
33         $a->page['htmlhead'] .= replace_macros($tpl,array(
34                 '$ispublic' => t('everybody')
35         ));
36
37
38
39         $tabs = array(
40                 array(
41                         'label' => t('Account'),
42                         'url'   => $a->get_baseurl(true).'/settings',
43                         'selected'      =>  (($a->argc == 1) && ($a->argv[0] === 'settings')?'active':''),
44                         'accesskey' => 'o',
45                 ),
46         );
47
48         if(get_features()) {
49                 $tabs[] =       array(
50                                         'label' => t('Additional features'),
51                                         'url'   => $a->get_baseurl(true).'/settings/features',
52                                         'selected'      => (($a->argc > 1) && ($a->argv[1] === 'features') ? 'active' : ''),
53                                         'accesskey' => 't',
54                                 );
55         }
56
57         $tabs[] =       array(
58                 'label' => t('Display'),
59                 'url'   => $a->get_baseurl(true).'/settings/display',
60                 'selected'      => (($a->argc > 1) && ($a->argv[1] === 'display')?'active':''),
61                 'accesskey' => 'i',
62         );
63
64         $tabs[] =       array(
65                 'label' => t('Social Networks'),
66                 'url'   => $a->get_baseurl(true).'/settings/connectors',
67                 'selected'      => (($a->argc > 1) && ($a->argv[1] === 'connectors')?'active':''),
68                 'accesskey' => 'w',
69         );
70
71         $tabs[] =       array(
72                 'label' => t('Plugins'),
73                 'url'   => $a->get_baseurl(true).'/settings/addon',
74                 'selected'      => (($a->argc > 1) && ($a->argv[1] === 'addon')?'active':''),
75                 'accesskey' => 'l',
76         );
77
78         $tabs[] =       array(
79                 'label' => t('Delegations'),
80                 'url'   => $a->get_baseurl(true).'/delegate',
81                 'selected'      => (($a->argc == 1) && ($a->argv[0] === 'delegate')?'active':''),
82                 'accesskey' => 'd',
83         );
84
85         $tabs[] =       array(
86                 'label' => t('Connected apps'),
87                 'url' => $a->get_baseurl(true) . '/settings/oauth',
88                 'selected' => (($a->argc > 1) && ($a->argv[1] === 'oauth')?'active':''),
89                 'accesskey' => 'b',
90         );
91
92         $tabs[] =       array(
93                 'label' => t('Export personal data'),
94                 'url' => $a->get_baseurl(true) . '/uexport',
95                 'selected' => (($a->argc == 1) && ($a->argv[0] === 'uexport')?'active':''),
96                 'accesskey' => 'e',
97         );
98
99         $tabs[] =       array(
100                 'label' => t('Remove account'),
101                 'url' => $a->get_baseurl(true) . '/removeme',
102                 'selected' => (($a->argc == 1) && ($a->argv[0] === 'removeme')?'active':''),
103                 'accesskey' => 'r',
104         );
105
106
107         $tabtpl = get_markup_template("generic_links_widget.tpl");
108         $a->page['aside'] = replace_macros($tabtpl, array(
109                 '$title' => t('Settings'),
110                 '$class' => 'settings-widget',
111                 '$items' => $tabs,
112         ));
113
114 }
115
116
117 function settings_post(&$a) {
118
119         if(! local_user())
120                 return;
121
122         if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
123                 return;
124
125         if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
126                 notice( t('Permission denied.') . EOL);
127                 return;
128         }
129
130         $old_page_flags = $a->user['page-flags'];
131
132         if(($a->argc > 1) && ($a->argv[1] === 'oauth') && x($_POST,'remove')){
133                 check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
134
135                 $key = $_POST['remove'];
136                 q("DELETE FROM tokens WHERE id='%s' AND uid=%d",
137                         dbesc($key),
138                         local_user());
139                 goaway($a->get_baseurl(true)."/settings/oauth/");
140                 return;
141         }
142
143         if(($a->argc > 2) && ($a->argv[1] === 'oauth')  && ($a->argv[2] === 'edit'||($a->argv[2] === 'add')) && x($_POST,'submit')) {
144
145                 check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
146
147                 $name           = ((x($_POST,'name')) ? $_POST['name'] : '');
148                 $key            = ((x($_POST,'key')) ? $_POST['key'] : '');
149                 $secret         = ((x($_POST,'secret')) ? $_POST['secret'] : '');
150                 $redirect       = ((x($_POST,'redirect')) ? $_POST['redirect'] : '');
151                 $icon           = ((x($_POST,'icon')) ? $_POST['icon'] : '');
152                 if ($name=="" || $key=="" || $secret==""){
153                         notice(t("Missing some important data!"));
154
155                 } else {
156                         if ($_POST['submit']==t("Update")){
157                                 $r = q("UPDATE clients SET
158                                                         client_id='%s',
159                                                         pw='%s',
160                                                         name='%s',
161                                                         redirect_uri='%s',
162                                                         icon='%s',
163                                                         uid=%d
164                                                 WHERE client_id='%s'",
165                                                 dbesc($key),
166                                                 dbesc($secret),
167                                                 dbesc($name),
168                                                 dbesc($redirect),
169                                                 dbesc($icon),
170                                                 local_user(),
171                                                 dbesc($key));
172                         } else {
173                                 $r = q("INSERT INTO clients
174                                                         (client_id, pw, name, redirect_uri, icon, uid)
175                                                 VALUES ('%s','%s','%s','%s','%s',%d)",
176                                                 dbesc($key),
177                                                 dbesc($secret),
178                                                 dbesc($name),
179                                                 dbesc($redirect),
180                                                 dbesc($icon),
181                                                 local_user());
182                         }
183                 }
184                 goaway($a->get_baseurl(true)."/settings/oauth/");
185                 return;
186         }
187
188         if(($a->argc > 1) && ($a->argv[1] == 'addon')) {
189                 check_form_security_token_redirectOnErr('/settings/addon', 'settings_addon');
190
191                 call_hooks('plugin_settings_post', $_POST);
192                 return;
193         }
194
195         if(($a->argc > 1) && ($a->argv[1] == 'connectors')) {
196
197                 check_form_security_token_redirectOnErr('/settings/connectors', 'settings_connectors');
198
199                 if(x($_POST, 'general-submit')) {
200                         set_pconfig(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening']));
201                         set_pconfig(local_user(), 'system', 'ostatus_autofriend', intval($_POST['snautofollow']));
202                         set_pconfig(local_user(), 'ostatus', 'legacy_contact', $_POST['legacy_contact']);
203                 } elseif(x($_POST, 'imap-submit')) {
204
205                         $mail_server       = ((x($_POST,'mail_server')) ? $_POST['mail_server'] : '');
206                         $mail_port         = ((x($_POST,'mail_port')) ? $_POST['mail_port'] : '');
207                         $mail_ssl          = ((x($_POST,'mail_ssl')) ? strtolower(trim($_POST['mail_ssl'])) : '');
208                         $mail_user         = ((x($_POST,'mail_user')) ? $_POST['mail_user'] : '');
209                         $mail_pass         = ((x($_POST,'mail_pass')) ? trim($_POST['mail_pass']) : '');
210                         $mail_action       = ((x($_POST,'mail_action')) ? trim($_POST['mail_action']) : '');
211                         $mail_movetofolder = ((x($_POST,'mail_movetofolder')) ? trim($_POST['mail_movetofolder']) : '');
212                         $mail_replyto      = ((x($_POST,'mail_replyto')) ? $_POST['mail_replyto'] : '');
213                         $mail_pubmail      = ((x($_POST,'mail_pubmail')) ? $_POST['mail_pubmail'] : '');
214
215
216                         $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
217                         if(get_config('system','dfrn_only'))
218                                 $mail_disabled = 1;
219
220                         if(! $mail_disabled) {
221                                 $failed = false;
222                                 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
223                                         intval(local_user())
224                                 );
225                                 if(! count($r)) {
226                                         q("INSERT INTO `mailacct` (`uid`) VALUES (%d)",
227                                                 intval(local_user())
228                                         );
229                                 }
230                                 if(strlen($mail_pass)) {
231                                         $pass = '';
232                                         openssl_public_encrypt($mail_pass,$pass,$a->user['pubkey']);
233                                         q("UPDATE `mailacct` SET `pass` = '%s' WHERE `uid` = %d",
234                                                 dbesc(bin2hex($pass)),
235                                                 intval(local_user())
236                                         );
237                                 }
238                                 $r = q("UPDATE `mailacct` SET `server` = '%s', `port` = %d, `ssltype` = '%s', `user` = '%s',
239                                         `action` = %d, `movetofolder` = '%s',
240                                         `mailbox` = 'INBOX', `reply_to` = '%s', `pubmail` = %d WHERE `uid` = %d",
241                                         dbesc($mail_server),
242                                         intval($mail_port),
243                                         dbesc($mail_ssl),
244                                         dbesc($mail_user),
245                                         intval($mail_action),
246                                         dbesc($mail_movetofolder),
247                                         dbesc($mail_replyto),
248                                         intval($mail_pubmail),
249                                         intval(local_user())
250                                 );
251                                 logger("mail: updating mailaccount. Response: ".print_r($r, true));
252                                 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
253                                         intval(local_user())
254                                 );
255                                 if(count($r)) {
256                                         $eacct = $r[0];
257                                         require_once('include/email.php');
258                                         $mb = construct_mailbox_name($eacct);
259                                         if(strlen($eacct['server'])) {
260                                                 $dcrpass = '';
261                                                 openssl_private_decrypt(hex2bin($eacct['pass']),$dcrpass,$a->user['prvkey']);
262                                                 $mbox = email_connect($mb,$mail_user,$dcrpass);
263                                                 unset($dcrpass);
264                                                 if(! $mbox) {
265                                                         $failed = true;
266                                                         notice( t('Failed to connect with email account using the settings provided.') . EOL);
267                                                 }
268                                         }
269                                 }
270                                 if(! $failed)
271                                         info( t('Email settings updated.') . EOL);
272                         }
273                 }
274
275                 call_hooks('connector_settings_post', $_POST);
276                 return;
277         }
278
279         if(($a->argc > 1) && ($a->argv[1] === 'features')) {
280                 check_form_security_token_redirectOnErr('/settings/features', 'settings_features');
281                 foreach($_POST as $k => $v) {
282                         if(strpos($k,'feature_') === 0) {
283                                 set_pconfig(local_user(),'feature',substr($k,8),((intval($v)) ? 1 : 0));
284                         }
285                 }
286                 info( t('Features updated') . EOL);
287                 return;
288         }
289
290         if(($a->argc > 1) && ($a->argv[1] === 'display')) {
291
292                 check_form_security_token_redirectOnErr('/settings/display', 'settings_display');
293
294                 $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme']))  : $a->user['theme']);
295                 $mobile_theme = ((x($_POST,'mobile_theme')) ? notags(trim($_POST['mobile_theme']))  : '');
296                 $nosmile = ((x($_POST,'nosmile')) ? intval($_POST['nosmile'])  : 0);
297                 $first_day_of_week = ((x($_POST,'first_day_of_week')) ? intval($_POST['first_day_of_week'])  : 0);
298                 $noinfo = ((x($_POST,'noinfo')) ? intval($_POST['noinfo'])  : 0);
299                 $infinite_scroll = ((x($_POST,'infinite_scroll')) ? intval($_POST['infinite_scroll'])  : 0);
300                 $no_auto_update = ((x($_POST,'no_auto_update')) ? intval($_POST['no_auto_update'])  : 0);
301                 $browser_update   = ((x($_POST,'browser_update')) ? intval($_POST['browser_update']) : 0);
302                 if ($browser_update != -1) {
303                         $browser_update   = $browser_update * 1000;
304                         if ($browser_update < 10000)
305                                 $browser_update = 10000;
306                 }
307
308                 $itemspage_network   = ((x($_POST,'itemspage_network')) ? intval($_POST['itemspage_network']) : 40);
309                 if($itemspage_network > 100)
310                         $itemspage_network = 100;
311                 $itemspage_mobile_network   = ((x($_POST,'itemspage_mobile_network')) ? intval($_POST['itemspage_mobile_network']) : 20);
312                 if($itemspage_mobile_network > 100)
313                         $itemspage_mobile_network = 100;
314
315
316                 if($mobile_theme !== '') {
317                         set_pconfig(local_user(),'system','mobile_theme',$mobile_theme);
318                 }
319
320                 set_pconfig(local_user(),'system','update_interval', $browser_update);
321                 set_pconfig(local_user(),'system','itemspage_network', $itemspage_network);
322                 set_pconfig(local_user(),'system','itemspage_mobile_network', $itemspage_mobile_network);
323                 set_pconfig(local_user(),'system','no_smilies',$nosmile);
324                 set_pconfig(local_user(),'system','first_day_of_week',$first_day_of_week);
325                 set_pconfig(local_user(),'system','ignore_info',$noinfo);
326                 set_pconfig(local_user(),'system','infinite_scroll',$infinite_scroll);
327                 set_pconfig(local_user(),'system','no_auto_update',$no_auto_update);
328
329
330                 if ($theme == $a->user['theme']){
331                         // call theme_post only if theme has not been changed
332                         if( ($themeconfigfile = get_theme_config_file($theme)) != null){
333                                 require_once($themeconfigfile);
334                                 theme_post($a);
335                         }
336                 }
337
338
339                 $r = q("UPDATE `user` SET `theme` = '%s' WHERE `uid` = %d",
340                                 dbesc($theme),
341                                 intval(local_user())
342                 );
343
344                 call_hooks('display_settings_post', $_POST);
345                 goaway($a->get_baseurl(true) . '/settings/display' );
346                 return; // NOTREACHED
347         }
348
349         check_form_security_token_redirectOnErr('/settings', 'settings');
350
351         if (x($_POST,'resend_relocate')) {
352                 proc_run('php', 'include/notifier.php', 'relocate', local_user());
353                 info(t("Relocate message has been send to your contacts"));
354                 goaway($a->get_baseurl(true) . '/settings');
355         }
356
357         call_hooks('settings_post', $_POST);
358
359         if((x($_POST,'password')) || (x($_POST,'confirm'))) {
360
361                 $newpass = $_POST['password'];
362                 $confirm = $_POST['confirm'];
363                 $oldpass = hash('whirlpool', $_POST['opassword']);
364
365                 $err = false;
366                 if($newpass != $confirm ) {
367                         notice( t('Passwords do not match. Password unchanged.') . EOL);
368                         $err = true;
369                 }
370
371                 if((! x($newpass)) || (! x($confirm))) {
372                         notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
373                         $err = true;
374         }
375
376         //  check if the old password was supplied correctly before
377         //  changing it to the new value
378         $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user()));
379         if( $oldpass != $r[0]['password'] ) {
380             notice( t('Wrong password.') . EOL);
381             $err = true;
382         }
383
384                 if(! $err) {
385                         $password = hash('whirlpool',$newpass);
386                         $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d",
387                                 dbesc($password),
388                                 intval(local_user())
389                         );
390                         if($r)
391                                 info( t('Password changed.') . EOL);
392                         else
393                                 notice( t('Password update failed. Please try again.') . EOL);
394                 }
395         }
396
397
398         $username         = ((x($_POST,'username'))   ? notags(trim($_POST['username']))     : '');
399         $email            = ((x($_POST,'email'))      ? notags(trim($_POST['email']))        : '');
400         $timezone         = ((x($_POST,'timezone'))   ? notags(trim($_POST['timezone']))     : '');
401         $language         = ((x($_POST,'language'))   ? notags(trim($_POST['language']))     : '');
402
403         $defloc           = ((x($_POST,'defloc'))     ? notags(trim($_POST['defloc']))       : '');
404         $openid           = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url']))   : '');
405         $maxreq           = ((x($_POST,'maxreq'))     ? intval($_POST['maxreq'])             : 0);
406         $expire           = ((x($_POST,'expire'))     ? intval($_POST['expire'])             : 0);
407         $def_gid          = ((x($_POST,'group-selection')) ? intval($_POST['group-selection']) : 0);
408
409
410         $expire_items     = ((x($_POST,'expire_items')) ? intval($_POST['expire_items'])         : 0);
411         $expire_notes     = ((x($_POST,'expire_notes')) ? intval($_POST['expire_notes'])         : 0);
412         $expire_starred   = ((x($_POST,'expire_starred')) ? intval($_POST['expire_starred']) : 0);
413         $expire_photos    = ((x($_POST,'expire_photos'))? intval($_POST['expire_photos'])        : 0);
414         $expire_network_only    = ((x($_POST,'expire_network_only'))? intval($_POST['expire_network_only'])      : 0);
415
416         $allow_location   = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
417         $publish          = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
418         $net_publish      = (((x($_POST,'profile_in_netdirectory')) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
419         $old_visibility   = (((x($_POST,'visibility')) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
420         $page_flags       = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
421         $blockwall        = (((x($_POST,'blockwall')) && (intval($_POST['blockwall']) == 1)) ? 0: 1); // this setting is inverted!
422         $blocktags        = (((x($_POST,'blocktags')) && (intval($_POST['blocktags']) == 1)) ? 0: 1); // this setting is inverted!
423         $unkmail          = (((x($_POST,'unkmail')) && (intval($_POST['unkmail']) == 1)) ? 1: 0);
424         $cntunkmail       = ((x($_POST,'cntunkmail')) ? intval($_POST['cntunkmail']) : 0);
425         $suggestme        = ((x($_POST,'suggestme')) ? intval($_POST['suggestme'])  : 0);
426         $hide_friends     = (($_POST['hide-friends'] == 1) ? 1: 0);
427         $hidewall         = (($_POST['hidewall'] == 1) ? 1: 0);
428         $post_newfriend   = (($_POST['post_newfriend'] == 1) ? 1: 0);
429         $post_joingroup   = (($_POST['post_joingroup'] == 1) ? 1: 0);
430         $post_profilechange   = (($_POST['post_profilechange'] == 1) ? 1: 0);
431
432         $email_textonly   = (($_POST['email_textonly'] == 1) ? 1 : 0);
433
434         $notify = 0;
435
436         if(x($_POST,'notify1'))
437                 $notify += intval($_POST['notify1']);
438         if(x($_POST,'notify2'))
439                 $notify += intval($_POST['notify2']);
440         if(x($_POST,'notify3'))
441                 $notify += intval($_POST['notify3']);
442         if(x($_POST,'notify4'))
443                 $notify += intval($_POST['notify4']);
444         if(x($_POST,'notify5'))
445                 $notify += intval($_POST['notify5']);
446         if(x($_POST,'notify6'))
447                 $notify += intval($_POST['notify6']);
448         if(x($_POST,'notify7'))
449                 $notify += intval($_POST['notify7']);
450         if(x($_POST,'notify8'))
451                 $notify += intval($_POST['notify8']);
452
453         $email_changed = false;
454
455         $err = '';
456
457         $name_change = false;
458
459         if($username != $a->user['username']) {
460                 $name_change = true;
461                 if(strlen($username) > 40)
462                         $err .= t(' Please use a shorter name.');
463                 if(strlen($username) < 3)
464                         $err .= t(' Name too short.');
465         }
466
467         if($email != $a->user['email']) {
468                 $email_changed = true;
469                 //  check for the correct password
470                 $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user()));
471                 $password = hash('whirlpool', $_POST['mpassword']);
472                 if ($password != $r[0]['password']) {
473                         $err .= t('Wrong Password') . EOL;
474                         $email = $a->user['email'];
475                 }
476                 //  check the email is valid
477                 if(! valid_email($email))
478                         $err .= t(' Not valid email.');
479                 //  ensure new email is not the admin mail
480                 //if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) {
481                 if(x($a->config,'admin_email')) {
482                         $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email'])));
483                         if (in_array(strtolower($email), $adminlist)) {
484                                 $err .= t(' Cannot change to that email.');
485                                 $email = $a->user['email'];
486                         }
487                 }
488         }
489
490         if(strlen($err)) {
491                 notice($err . EOL);
492                 return;
493         }
494
495         if($timezone != $a->user['timezone']) {
496                 if(strlen($timezone))
497                         date_default_timezone_set($timezone);
498         }
499
500         $str_group_allow   = perms2str($_POST['group_allow']);
501         $str_contact_allow = perms2str($_POST['contact_allow']);
502         $str_group_deny    = perms2str($_POST['group_deny']);
503         $str_contact_deny  = perms2str($_POST['contact_deny']);
504
505         $openidserver = $a->user['openidserver'];
506         //$openid = normalise_openid($openid);
507
508         // If openid has changed or if there's an openid but no openidserver, try and discover it.
509
510         if($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) {
511                 $tmp_str = $openid;
512                 if(strlen($tmp_str) && validate_url($tmp_str)) {
513                         logger('updating openidserver');
514                         require_once('library/openid.php');
515                         $open_id_obj = new LightOpenID;
516                         $open_id_obj->identity = $openid;
517                         $openidserver = $open_id_obj->discover($open_id_obj->identity);
518                 }
519                 else
520                         $openidserver = '';
521         }
522
523         set_pconfig(local_user(),'expire','items', $expire_items);
524         set_pconfig(local_user(),'expire','notes', $expire_notes);
525         set_pconfig(local_user(),'expire','starred', $expire_starred);
526         set_pconfig(local_user(),'expire','photos', $expire_photos);
527         set_pconfig(local_user(),'expire','network_only', $expire_network_only);
528
529         set_pconfig(local_user(),'system','suggestme', $suggestme);
530         set_pconfig(local_user(),'system','post_newfriend', $post_newfriend);
531         set_pconfig(local_user(),'system','post_joingroup', $post_joingroup);
532         set_pconfig(local_user(),'system','post_profilechange', $post_profilechange);
533
534         set_pconfig(local_user(),'system','email_textonly', $email_textonly);
535
536         if($page_flags == PAGE_PRVGROUP) {
537                 $hidewall = 1;
538                 if((! $str_contact_allow) && (! $str_group_allow) && (! $str_contact_deny) && (! $str_group_deny)) {
539                         if($def_gid) {
540                                 info( t('Private forum has no privacy permissions. Using default privacy group.'). EOL);
541                                 $str_group_allow = '<' . $def_gid . '>';
542                         }
543                         else {
544                                 notice( t('Private forum has no privacy permissions and no default privacy group.') . EOL);
545                         }
546                 }
547         }
548
549
550         $r = q("UPDATE `user` SET `username` = '%s', `email` = '%s',
551                                 `openid` = '%s', `timezone` = '%s',
552                                 `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s',
553                                 `notify-flags` = %d, `page-flags` = %d, `default-location` = '%s',
554                                 `allow_location` = %d, `maxreq` = %d, `expire` = %d, `openidserver` = '%s',
555                                 `def_gid` = %d, `blockwall` = %d, `hidewall` = %d, `blocktags` = %d,
556                                 `unkmail` = %d, `cntunkmail` = %d, `language` = '%s'
557                         WHERE `uid` = %d",
558                         dbesc($username),
559                         dbesc($email),
560                         dbesc($openid),
561                         dbesc($timezone),
562                         dbesc($str_contact_allow),
563                         dbesc($str_group_allow),
564                         dbesc($str_contact_deny),
565                         dbesc($str_group_deny),
566                         intval($notify),
567                         intval($page_flags),
568                         dbesc($defloc),
569                         intval($allow_location),
570                         intval($maxreq),
571                         intval($expire),
572                         dbesc($openidserver),
573                         intval($def_gid),
574                         intval($blockwall),
575                         intval($hidewall),
576                         intval($blocktags),
577                         intval($unkmail),
578                         intval($cntunkmail),
579                         dbesc($language),
580                         intval(local_user())
581         );
582         if($r)
583                 info( t('Settings updated.') . EOL);
584
585         // clear session language
586         unset($_SESSION['language']);
587
588         $r = q("UPDATE `profile`
589                 SET `publish` = %d,
590                 `name` = '%s',
591                 `net-publish` = %d,
592                 `hide-friends` = %d
593                 WHERE `is-default` = 1 AND `uid` = %d",
594                 intval($publish),
595                 dbesc($username),
596                 intval($net_publish),
597                 intval($hide_friends),
598                 intval(local_user())
599         );
600
601
602         if($name_change) {
603                 q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self` = 1",
604                         dbesc($username),
605                         dbesc(datetime_convert()),
606                         intval(local_user())
607                 );
608         }
609
610         if(($old_visibility != $net_publish) || ($page_flags != $old_page_flags)) {
611                 // Update global directory in background
612                 $url = $_SESSION['my_url'];
613                 if($url && strlen(get_config('system','directory')))
614                         proc_run('php',"include/directory.php","$url");
615
616         }
617
618
619         require_once('include/profile_update.php');
620         profile_change();
621
622         //$_SESSION['theme'] = $theme;
623         if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
624
625                 // FIXME - set to un-verified, blocked and redirect to logout
626                 // Why? Are we verifying people or email addresses?
627
628         }
629
630         goaway($a->get_baseurl(true) . '/settings' );
631         return; // NOTREACHED
632 }
633
634
635 function settings_content(&$a) {
636
637         $o = '';
638         nav_set_selected('settings');
639
640         if(! local_user()) {
641                 #notice( t('Permission denied.') . EOL );
642                 return;
643         }
644
645         if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
646                 notice( t('Permission denied.') . EOL );
647                 return;
648         }
649
650
651
652         if(($a->argc > 1) && ($a->argv[1] === 'oauth')) {
653
654                 if(($a->argc > 2) && ($a->argv[2] === 'add')) {
655                         $tpl = get_markup_template("settings_oauth_edit.tpl");
656                         $o .= replace_macros($tpl, array(
657                                 '$form_security_token' => get_form_security_token("settings_oauth"),
658                                 '$title'        => t('Add application'),
659                                 '$submit'       => t('Save Settings'),
660                                 '$cancel'       => t('Cancel'),
661                                 '$name'         => array('name', t('Name'), '', ''),
662                                 '$key'          => array('key', t('Consumer Key'), '', ''),
663                                 '$secret'       => array('secret', t('Consumer Secret'), '', ''),
664                                 '$redirect'     => array('redirect', t('Redirect'), '', ''),
665                                 '$icon'         => array('icon', t('Icon url'), '', ''),
666                         ));
667                         return $o;
668                 }
669
670                 if(($a->argc > 3) && ($a->argv[2] === 'edit')) {
671                         $r = q("SELECT * FROM clients WHERE client_id='%s' AND uid=%d",
672                                         dbesc($a->argv[3]),
673                                         local_user());
674
675                         if (!count($r)){
676                                 notice(t("You can't edit this application."));
677                                 return;
678                         }
679                         $app = $r[0];
680
681                         $tpl = get_markup_template("settings_oauth_edit.tpl");
682                         $o .= replace_macros($tpl, array(
683                                 '$form_security_token' => get_form_security_token("settings_oauth"),
684                                 '$title'        => t('Add application'),
685                                 '$submit'       => t('Update'),
686                                 '$cancel'       => t('Cancel'),
687                                 '$name'         => array('name', t('Name'), $app['name'] , ''),
688                                 '$key'          => array('key', t('Consumer Key'), $app['client_id'], ''),
689                                 '$secret'       => array('secret', t('Consumer Secret'), $app['pw'], ''),
690                                 '$redirect'     => array('redirect', t('Redirect'), $app['redirect_uri'], ''),
691                                 '$icon'         => array('icon', t('Icon url'), $app['icon'], ''),
692                         ));
693                         return $o;
694                 }
695
696                 if(($a->argc > 3) && ($a->argv[2] === 'delete')) {
697                         check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't');
698
699                         $r = q("DELETE FROM clients WHERE client_id='%s' AND uid=%d",
700                                         dbesc($a->argv[3]),
701                                         local_user());
702                         goaway($a->get_baseurl(true)."/settings/oauth/");
703                         return;
704                 }
705
706
707                 $r = q("SELECT clients.*, tokens.id as oauth_token, (clients.uid=%d) AS my
708                                 FROM clients
709                                 LEFT JOIN tokens ON clients.client_id=tokens.client_id
710                                 WHERE clients.uid IN (%d,0)",
711                                 local_user(),
712                                 local_user());
713
714
715                 $tpl = get_markup_template("settings_oauth.tpl");
716                 $o .= replace_macros($tpl, array(
717                         '$form_security_token' => get_form_security_token("settings_oauth"),
718                         '$baseurl'      => $a->get_baseurl(true),
719                         '$title'        => t('Connected Apps'),
720                         '$add'          => t('Add application'),
721                         '$edit'         => t('Edit'),
722                         '$delete'               => t('Delete'),
723                         '$consumerkey' => t('Client key starts with'),
724                         '$noname'       => t('No name'),
725                         '$remove'       => t('Remove authorization'),
726                         '$apps'         => $r,
727                 ));
728                 return $o;
729
730         }
731
732         if(($a->argc > 1) && ($a->argv[1] === 'addon')) {
733                 $settings_addons = "";
734
735                 $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
736                 if(! count($r))
737                         $settings_addons = t('No Plugin settings configured');
738
739                 call_hooks('plugin_settings', $settings_addons);
740
741
742                 $tpl = get_markup_template("settings_addons.tpl");
743                 $o .= replace_macros($tpl, array(
744                         '$form_security_token' => get_form_security_token("settings_addon"),
745                         '$title'        => t('Plugin Settings'),
746                         '$settings_addons' => $settings_addons
747                 ));
748                 return $o;
749         }
750
751         if(($a->argc > 1) && ($a->argv[1] === 'features')) {
752
753                 $arr = array();
754                 $features = get_features();
755                 foreach($features as $fname => $fdata) {
756                         $arr[$fname] = array();
757                         $arr[$fname][0] = $fdata[0];
758                         foreach(array_slice($fdata,1) as $f) {
759                                 $arr[$fname][1][] = array('feature_' .$f[0],$f[1],((intval(feature_enabled(local_user(),$f[0]))) ? "1" : ''),$f[2],array(t('Off'),t('On')));
760                         }
761                 }
762
763
764                 $tpl = get_markup_template("settings_features.tpl");
765                 $o .= replace_macros($tpl, array(
766                         '$form_security_token' => get_form_security_token("settings_features"),
767                         '$title'        => t('Additional Features'),
768                         '$features' => $arr,
769                         '$submit'   => t('Save Settings'),
770                 ));
771                 return $o;
772         }
773
774         if(($a->argc > 1) && ($a->argv[1] === 'connectors')) {
775
776                 $settings_connectors = '<span id="settings_general_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_general_expanded\'); openClose(\'settings_general_inflated\');">';
777                 $settings_connectors .= '<h3 class="connector">'. t('General Social Media Settings').'</h3>';
778                 $settings_connectors .= '</span>';
779                 $settings_connectors .= '<div id="settings_general_expanded" class="settings-block" style="display: none;">';
780                 $settings_connectors .= '<span class="fakelink" onclick="openClose(\'settings_general_expanded\'); openClose(\'settings_general_inflated\');">';
781                 $settings_connectors .= '<h3 class="connector">'. t('General Social Media Settings').'</h3>';
782                 $settings_connectors .= '</span>';
783
784                 $checked = ((get_pconfig(local_user(), 'system', 'no_intelligent_shortening')) ? ' checked="checked" ' : '');
785
786                 $settings_connectors .= '<div id="no_intelligent_shortening" class="field checkbox">';
787                 $settings_connectors .= '<label id="no_intelligent_shortening-label" for="shortening-checkbox">'. t('Disable intelligent shortening'). '</label>';
788                 $settings_connectors .= '<input id="shortening-checkbox" type="checkbox" name="no_intelligent_shortening" value="1" ' . $checked . '/>';
789                 $settings_connectors .= '<span class="field_help">'.t('Normally the system tries to find the best link to add to shortened posts. If this option is enabled then every shortened post will always point to the original friendica post.').'</span>';
790                 $settings_connectors .= '</div>';
791
792                 $checked = ((get_pconfig(local_user(), 'system', 'ostatus_autofriend')) ? ' checked="checked" ' : '');
793
794                 $settings_connectors .= '<div id="snautofollow-wrapper" class="field checkbox">';
795                 $settings_connectors .= '<label id="snautofollow-label" for="snautofollow-checkbox">'. t('Automatically follow any GNU Social (OStatus) followers/mentioners'). '</label>';
796                 $settings_connectors .= '<input id="snautofollow-checkbox" type="checkbox" name="snautofollow" value="1" ' . $checked . '/>';
797                 $settings_connectors .= '<span class="field_help">'.t('If you receive a message from an unknown OStatus user, this option decides what to do. If it is checked, a new contact will be created for every unknown user.').'</span>';
798                 $settings_connectors .= '</div>';
799
800                 $legacy_contact = get_pconfig(local_user(), 'ostatus', 'legacy_contact');
801
802                 if ($legacy_contact != "")
803                         $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.$a->get_baseurl().'/ostatus_subscribe?url='.urlencode($legacy_contact).'">';
804
805                 $settings_connectors .= '<div id="legacy-contact-wrapper" class="field input">';
806                 $settings_connectors .= '<label id="legacy-contact-label" for="snautofollow-checkbox">'. t('Your legacy GNU Social account'). '</label>';
807                 $settings_connectors .= '<input id="legacy-contact-checkbox" name="legacy_contact" value="'.$legacy_contact.'"/>';
808                 $settings_connectors .= '<span class="field_help">'.t('If you enter your old GNU Social/Statusnet account name here (in the format user@domain.tld), your contacts will be added automatically. The field will be emptied when done.').'</span>';
809                 $settings_connectors .= '</div>';
810
811                 $settings_connectors .= '<p><a href="'.$a->get_baseurl().'/repair_ostatus">'.t("Repair OStatus subscriptions").'</a></p>';
812
813                 $settings_connectors .= '<div class="settings-submit-wrapper" ><input type="submit" name="general-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div>';
814
815                 $settings_connectors .= '</div><div class="clear"></div>';
816
817                 call_hooks('connector_settings', $settings_connectors);
818
819                 if (is_site_admin()) {
820                         $diasp_enabled = sprintf( t('Built-in support for %s connectivity is %s'), t('Diaspora'), ((get_config('system','diaspora_enabled')) ? t('enabled') : t('disabled')));
821                         $ostat_enabled = sprintf( t('Built-in support for %s connectivity is %s'), t('GNU Social (OStatus)'), ((get_config('system','ostatus_disabled')) ? t('disabled') : t('enabled')));
822                 } else {
823                         $diasp_enabled = "";
824                         $ostat_enabled = "";
825                 }
826
827                 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
828                 if(get_config('system','dfrn_only'))
829                         $mail_disabled = 1;
830
831                 if(! $mail_disabled) {
832                         $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
833                                 local_user()
834                         );
835                 }
836                 else {
837                         $r = null;
838                 }
839
840                 $mail_server       = ((count($r)) ? $r[0]['server'] : '');
841                 $mail_port         = ((count($r) && intval($r[0]['port'])) ? intval($r[0]['port']) : '');
842                 $mail_ssl          = ((count($r)) ? $r[0]['ssltype'] : '');
843                 $mail_user         = ((count($r)) ? $r[0]['user'] : '');
844                 $mail_replyto      = ((count($r)) ? $r[0]['reply_to'] : '');
845                 $mail_pubmail      = ((count($r)) ? $r[0]['pubmail'] : 0);
846                 $mail_action       = ((count($r)) ? $r[0]['action'] : 0);
847                 $mail_movetofolder = ((count($r)) ? $r[0]['movetofolder'] : '');
848                 $mail_chk          = ((count($r)) ? $r[0]['last_check'] : '0000-00-00 00:00:00');
849
850
851                 $tpl = get_markup_template("settings_connectors.tpl");
852
853                 if(! service_class_allows(local_user(),'email_connect')) {
854                         $mail_disabled_message = upgrade_bool_message();
855                 }
856                 else {
857                         $mail_disabled_message = (($mail_disabled) ? t('Email access is disabled on this site.') : '');
858                 }
859
860
861                 $o .= replace_macros($tpl, array(
862                         '$form_security_token' => get_form_security_token("settings_connectors"),
863
864                         '$title'        => t('Social Networks'),
865
866                         '$diasp_enabled' => $diasp_enabled,
867                         '$ostat_enabled' => $ostat_enabled,
868
869                         '$h_imap' => t('Email/Mailbox Setup'),
870                         '$imap_desc' => t("If you wish to communicate with email contacts using this service \x28optional\x29, please specify how to connect to your mailbox."),
871                         '$imap_lastcheck' => array('imap_lastcheck', t('Last successful email check:'), $mail_chk,''),
872                         '$mail_disabled' => $mail_disabled_message,
873                         '$mail_server'  => array('mail_server',  t('IMAP server name:'), $mail_server, ''),
874                         '$mail_port'    => array('mail_port',    t('IMAP port:'), $mail_port, ''),
875                         '$mail_ssl'             => array('mail_ssl',     t('Security:'), strtoupper($mail_ssl), '', array( 'notls'=>t('None'), 'TLS'=>'TLS', 'SSL'=>'SSL')),
876                         '$mail_user'    => array('mail_user',    t('Email login name:'), $mail_user, ''),
877                         '$mail_pass'    => array('mail_pass',    t('Email password:'), '', ''),
878                         '$mail_replyto' => array('mail_replyto', t('Reply-to address:'), $mail_replyto, 'Optional'),
879                         '$mail_pubmail' => array('mail_pubmail', t('Send public posts to all email contacts:'), $mail_pubmail, ''),
880                         '$mail_action'  => array('mail_action',  t('Action after import:'), $mail_action, '', array(0=>t('None'), /*1=>t('Delete'),*/ 2=>t('Mark as seen'), 3=>t('Move to folder'))),
881                         '$mail_movetofolder'    => array('mail_movetofolder',    t('Move to folder:'), $mail_movetofolder, ''),
882                         '$submit' => t('Save Settings'),
883
884                         '$settings_connectors' => $settings_connectors
885                 ));
886
887                 call_hooks('display_settings', $o);
888                 return $o;
889         }
890
891         /*
892          * DISPLAY SETTINGS
893          */
894         if(($a->argc > 1) && ($a->argv[1] === 'display')) {
895                 $default_theme = get_config('system','theme');
896                 if(! $default_theme)
897                         $default_theme = 'default';
898                 $default_mobile_theme = get_config('system','mobile-theme');
899                 if(! $mobile_default_theme)
900                         $mobile_default_theme = 'none';
901
902                 $allowed_themes_str = get_config('system','allowed_themes');
903                 $allowed_themes_raw = explode(',',$allowed_themes_str);
904                 $allowed_themes = array();
905                 if(count($allowed_themes_raw))
906                         foreach($allowed_themes_raw as $x)
907                                 if(strlen(trim($x)) && is_dir("view/theme/$x"))
908                                         $allowed_themes[] = trim($x);
909
910
911                 $themes = array();
912                 $mobile_themes = array("---" => t('No special theme for mobile devices'));
913                 $files = glob('view/theme/*'); /* */
914                 if($allowed_themes) {
915                         foreach($allowed_themes as $th) {
916                                 $f = $th;
917                                 $is_experimental = file_exists('view/theme/' . $th . '/experimental');
918                                 $unsupported = file_exists('view/theme/' . $th . '/unsupported');
919                                 $is_mobile = file_exists('view/theme/' . $th . '/mobile');
920                                 if (!$is_experimental or ($is_experimental && (get_config('experimentals','exp_themes')==1 or get_config('experimentals','exp_themes')===false))){
921                                         $theme_name = (($is_experimental) ?  sprintf("%s - \x28Experimental\x29", $f) : $f);
922                                         if($is_mobile) {
923                                                 $mobile_themes[$f]=$theme_name;
924                                         }
925                                         else {
926                                                 $themes[$f]=$theme_name;
927                                         }
928                                 }
929                         }
930                 }
931                 $theme_selected = (!x($_SESSION,'theme')? $default_theme : $_SESSION['theme']);
932                 $mobile_theme_selected = (!x($_SESSION,'mobile-theme')? $default_mobile_theme : $_SESSION['mobile-theme']);
933
934                 $browser_update = intval(get_pconfig(local_user(), 'system','update_interval'));
935                 if (intval($browser_update) != -1)
936                         $browser_update = (($browser_update == 0) ? 40 : $browser_update / 1000); // default if not set: 40 seconds
937
938                 $itemspage_network = intval(get_pconfig(local_user(), 'system','itemspage_network'));
939                 $itemspage_network = (($itemspage_network > 0 && $itemspage_network < 101) ? $itemspage_network : 40); // default if not set: 40 items
940                 $itemspage_mobile_network = intval(get_pconfig(local_user(), 'system','itemspage_mobile_network'));
941                 $itemspage_mobile_network = (($itemspage_mobile_network > 0 && $itemspage_mobile_network < 101) ? $itemspage_mobile_network : 20); // default if not set: 20 items
942
943                 $nosmile = get_pconfig(local_user(),'system','no_smilies');
944                 $nosmile = (($nosmile===false)? '0': $nosmile); // default if not set: 0
945
946                 $first_day_of_week = get_pconfig(local_user(),'system','first_day_of_week');
947                 $first_day_of_week = (($first_day_of_week===false)? '0': $first_day_of_week); // default if not set: 0
948                 $weekdays = array(0 => t("Sunday"), 1 => t("Monday"));
949
950                 $noinfo = get_pconfig(local_user(),'system','ignore_info');
951                 $noinfo = (($noinfo===false)? '0': $noinfo); // default if not set: 0
952
953                 $infinite_scroll = get_pconfig(local_user(),'system','infinite_scroll');
954                 $infinite_scroll = (($infinite_scroll===false)? '0': $infinite_scroll); // default if not set: 0
955
956                 $no_auto_update = get_pconfig(local_user(),'system','no_auto_update');
957                 $no_auto_update = (($no_auto_update===false)? '0': $no_auto_update); // default if not set: 0
958
959                 $theme_config = "";
960                 if( ($themeconfigfile = get_theme_config_file($theme_selected)) != null){
961                         require_once($themeconfigfile);
962                         $theme_config = theme_content($a);
963                 }
964
965                 $tpl = get_markup_template("settings_display.tpl");
966                 $o = replace_macros($tpl, array(
967                         '$ptitle'       => t('Display Settings'),
968                         '$form_security_token' => get_form_security_token("settings_display"),
969                         '$submit'       => t('Save Settings'),
970                         '$baseurl' => $a->get_baseurl(true),
971                         '$uid' => local_user(),
972
973                         '$theme'        => array('theme', t('Display Theme:'), $theme_selected, '', $themes, true),
974                         '$mobile_theme' => array('mobile_theme', t('Mobile Theme:'), $mobile_theme_selected, '', $mobile_themes, false),
975                         '$ajaxint'   => array('browser_update',  t("Update browser every xx seconds"), $browser_update, t('Minimum of 10 seconds. Enter -1 to disable it.')),
976                         '$itemspage_network'   => array('itemspage_network',  t("Number of items to display per page:"), $itemspage_network, t('Maximum of 100 items')),
977                         '$itemspage_mobile_network'   => array('itemspage_mobile_network',  t("Number of items to display per page when viewed from mobile device:"), $itemspage_mobile_network, t('Maximum of 100 items')),
978                         '$nosmile'      => array('nosmile', t("Don't show emoticons"), $nosmile, ''),
979                         '$calendar_title' => t('Calendar'),
980                         '$first_day_of_week'    => array('first_day_of_week', t('Beginning of week:'), $first_day_of_week, '', $weekdays, false),
981                         '$noinfo'       => array('noinfo', t("Don't show notices"), $noinfo, ''),
982                         '$infinite_scroll'      => array('infinite_scroll', t("Infinite scroll"), $infinite_scroll, ''),
983                         '$no_auto_update'       => array('no_auto_update', t("Automatic updates only at the top of the network page"), $no_auto_update, 'When disabled, the network page is updated all the time, which could be confusing while reading.'),
984
985                         'stitle' => t('Theme settings'),
986                         '$theme_config' => $theme_config,
987                 ));
988
989                 $tpl = get_markup_template("settings_display_end.tpl");
990                 $a->page['end'] .= replace_macros($tpl, array(
991                         '$theme'        => array('theme', t('Display Theme:'), $theme_selected, '', $themes)
992                 ));
993
994                 return $o;
995         }
996
997
998         /*
999          * ACCOUNT SETTINGS
1000          */
1001
1002         require_once('include/acl_selectors.php');
1003
1004         $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
1005                 intval(local_user())
1006         );
1007         if(count($p))
1008                 $profile = $p[0];
1009
1010         $username   = $a->user['username'];
1011         $email      = $a->user['email'];
1012         $nickname   = $a->user['nickname'];
1013         $timezone   = $a->user['timezone'];
1014         $language   = $a->user['language'];
1015         $notify     = $a->user['notify-flags'];
1016         $defloc     = $a->user['default-location'];
1017         $openid     = $a->user['openid'];
1018         $maxreq     = $a->user['maxreq'];
1019         $expire     = ((intval($a->user['expire'])) ? $a->user['expire'] : '');
1020         $blockwall  = $a->user['blockwall'];
1021         $blocktags  = $a->user['blocktags'];
1022         $unkmail    = $a->user['unkmail'];
1023         $cntunkmail = $a->user['cntunkmail'];
1024
1025         $expire_items = get_pconfig(local_user(), 'expire','items');
1026         $expire_items = (($expire_items===false)? '1' : $expire_items); // default if not set: 1
1027
1028         $expire_notes = get_pconfig(local_user(), 'expire','notes');
1029         $expire_notes = (($expire_notes===false)? '1' : $expire_notes); // default if not set: 1
1030
1031         $expire_starred = get_pconfig(local_user(), 'expire','starred');
1032         $expire_starred = (($expire_starred===false)? '1' : $expire_starred); // default if not set: 1
1033
1034         $expire_photos = get_pconfig(local_user(), 'expire','photos');
1035         $expire_photos = (($expire_photos===false)? '0' : $expire_photos); // default if not set: 0
1036
1037         $expire_network_only = get_pconfig(local_user(), 'expire','network_only');
1038         $expire_network_only = (($expire_network_only===false)? '0' : $expire_network_only); // default if not set: 0
1039
1040
1041         $suggestme = get_pconfig(local_user(), 'system','suggestme');
1042         $suggestme = (($suggestme===false)? '0': $suggestme); // default if not set: 0
1043
1044         $post_newfriend = get_pconfig(local_user(), 'system','post_newfriend');
1045         $post_newfriend = (($post_newfriend===false)? '0': $post_newfriend); // default if not set: 0
1046
1047         $post_joingroup = get_pconfig(local_user(), 'system','post_joingroup');
1048         $post_joingroup = (($post_joingroup===false)? '0': $post_joingroup); // default if not set: 0
1049
1050         $post_profilechange = get_pconfig(local_user(), 'system','post_profilechange');
1051         $post_profilechange = (($post_profilechange===false)? '0': $post_profilechange); // default if not set: 0
1052
1053         // nowarn_insecure
1054
1055         if(! strlen($a->user['timezone']))
1056                 $timezone = date_default_timezone_get();
1057
1058
1059
1060         $pageset_tpl = get_markup_template('pagetypes.tpl');
1061         $pagetype = replace_macros($pageset_tpl, array(
1062                 '$user'         => t("User Types"),
1063                 '$community'    => t("Community Types"),
1064                 '$page_normal'  => array('page-flags', t('Normal Account Page'), PAGE_NORMAL,
1065                                                                         t('This account is a normal personal profile'),
1066                                                                         ($a->user['page-flags'] == PAGE_NORMAL)),
1067
1068                 '$page_soapbox'         => array('page-flags', t('Soapbox Page'), PAGE_SOAPBOX,
1069                                                                         t('Automatically approve all connection/friend requests as read-only fans'),
1070                                                                         ($a->user['page-flags'] == PAGE_SOAPBOX)),
1071
1072                 '$page_community'       => array('page-flags', t('Community Forum/Celebrity Account'), PAGE_COMMUNITY,
1073                                                                         t('Automatically approve all connection/friend requests as read-write fans'),
1074                                                                         ($a->user['page-flags'] == PAGE_COMMUNITY)),
1075
1076                 '$page_freelove'        => array('page-flags', t('Automatic Friend Page'), PAGE_FREELOVE,
1077                                                                         t('Automatically approve all connection/friend requests as friends'),
1078                                                                         ($a->user['page-flags'] == PAGE_FREELOVE)),
1079
1080                 '$page_prvgroup'        => array('page-flags', t('Private Forum [Experimental]'), PAGE_PRVGROUP,
1081                                                                         t('Private forum - approved members only'),
1082                                                                         ($a->user['page-flags'] == PAGE_PRVGROUP)),
1083
1084
1085         ));
1086
1087         $noid = get_config('system','no_openid');
1088
1089         if($noid) {
1090                 $openid_field = false;
1091         }
1092         else {
1093                 $openid_field = array('openid_url', t('OpenID:'),$openid, t("\x28Optional\x29 Allow this OpenID to login to this account."), "", "", "url");
1094         }
1095
1096
1097         $opt_tpl = get_markup_template("field_yesno.tpl");
1098         if(get_config('system','publish_all')) {
1099                 $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
1100         }
1101         else {
1102                 $profile_in_dir = replace_macros($opt_tpl,array(
1103                         '$field'        => array('profile_in_directory', t('Publish your default profile in your local site directory?'), $profile['publish'], '', array(t('No'),t('Yes'))),
1104                 ));
1105         }
1106
1107         if(strlen(get_config('system','directory'))) {
1108                 $profile_in_net_dir = replace_macros($opt_tpl,array(
1109                         '$field'        => array('profile_in_netdirectory', t('Publish your default profile in the global social directory?'), $profile['net-publish'], '', array(t('No'),t('Yes'))),
1110                 ));
1111         }
1112         else
1113                 $profile_in_net_dir = '';
1114
1115
1116         $hide_friends = replace_macros($opt_tpl,array(
1117                         '$field'        => array('hide-friends', t('Hide your contact/friend list from viewers of your default profile?'), $profile['hide-friends'], '', array(t('No'),t('Yes'))),
1118         ));
1119
1120         $hide_wall = replace_macros($opt_tpl,array(
1121                         '$field'        => array('hidewall',  t('Hide your profile details from unknown viewers?'), $a->user['hidewall'], t("If enabled, posting public messages to Diaspora and other networks isn't possible."), array(t('No'),t('Yes'))),
1122
1123         ));
1124
1125         $blockwall = replace_macros($opt_tpl,array(
1126                         '$field'        => array('blockwall',  t('Allow friends to post to your profile page?'), (intval($a->user['blockwall']) ? '0' : '1'), '', array(t('No'),t('Yes'))),
1127
1128         ));
1129
1130
1131         $blocktags = replace_macros($opt_tpl,array(
1132                         '$field'        => array('blocktags',  t('Allow friends to tag your posts?'), (intval($a->user['blocktags']) ? '0' : '1'), '', array(t('No'),t('Yes'))),
1133
1134         ));
1135
1136
1137         $suggestme = replace_macros($opt_tpl,array(
1138                         '$field'        => array('suggestme',  t('Allow us to suggest you as a potential friend to new members?'), $suggestme, '', array(t('No'),t('Yes'))),
1139
1140         ));
1141
1142
1143         $unkmail = replace_macros($opt_tpl,array(
1144                         '$field'        => array('unkmail',  t('Permit unknown people to send you private mail?'), $unkmail, '', array(t('No'),t('Yes'))),
1145
1146         ));
1147
1148         $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
1149                 ? true : false);
1150
1151         if($invisible)
1152                 info( t('Profile is <strong>not published</strong>.') . EOL );
1153
1154
1155         //$subdir = ((strlen($a->get_path())) ? '<br />' . t('or') . ' ' . $a->get_baseurl(true) . '/profile/' . $nickname : '');
1156
1157         $tpl_addr = get_markup_template("settings_nick_set.tpl");
1158
1159         $prof_addr = replace_macros($tpl_addr,array(
1160                 '$desc' => sprintf(t("Your Identity Address is <strong>'%s'</strong> or '%s'."), $nickname.'@'.$a->get_hostname().$a->get_path(), $a->get_baseurl().'/profile/'.$nickname),
1161                 '$basepath' => $a->get_hostname()
1162         ));
1163
1164         $stpl = get_markup_template('settings.tpl');
1165
1166         $expire_arr = array(
1167                 'days' => array('expire',  t("Automatically expire posts after this many days:"), $expire, t('If empty, posts will not expire. Expired posts will be deleted')),
1168                 'advanced' => t('Advanced expiration settings'),
1169                 'label' => t('Advanced Expiration'),
1170                 'items' => array('expire_items',  t("Expire posts:"), $expire_items, '', array(t('No'),t('Yes'))),
1171                 'notes' => array('expire_notes',  t("Expire personal notes:"), $expire_notes, '', array(t('No'),t('Yes'))),
1172                 'starred' => array('expire_starred',  t("Expire starred posts:"), $expire_starred, '', array(t('No'),t('Yes'))),
1173                 'photos' => array('expire_photos',  t("Expire photos:"), $expire_photos, '', array(t('No'),t('Yes'))),
1174                 'network_only' => array('expire_network_only',  t("Only expire posts by others:"), $expire_network_only, '', array(t('No'),t('Yes'))),
1175         );
1176
1177         require_once('include/group.php');
1178         $group_select = mini_group_select(local_user(),$a->user['def_gid']);
1179
1180
1181         // Private/public post links for the non-JS ACL form
1182         $private_post = 1;
1183         if($_REQUEST['public'])
1184                 $private_post = 0;
1185
1186         $query_str = $a->query_string;
1187         if(strpos($query_str, 'public=1') !== false)
1188                 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1189
1190         // I think $a->query_string may never have ? in it, but I could be wrong
1191         // It looks like it's from the index.php?q=[etc] rewrite that the web
1192         // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1193         if(strpos($query_str, '?') === false)
1194                 $public_post_link = '?public=1';
1195         else
1196                 $public_post_link = '&public=1';
1197
1198         /* Installed langs */
1199         $lang_choices = get_avaiable_languages();
1200
1201         $o .= replace_macros($stpl, array(
1202                 '$ptitle'       => t('Account Settings'),
1203
1204                 '$submit'       => t('Save Settings'),
1205                 '$baseurl' => $a->get_baseurl(true),
1206                 '$uid' => local_user(),
1207                 '$form_security_token' => get_form_security_token("settings"),
1208                 '$nickname_block' => $prof_addr,
1209
1210                 '$h_pass'       => t('Password Settings'),
1211                 '$password1'=> array('password', t('New Password:'), '', ''),
1212                 '$password2'=> array('confirm', t('Confirm:'), '', t('Leave password fields blank unless changing')),
1213                 '$password3'=> array('opassword', t('Current Password:'), '', t('Your current password to confirm the changes')),
1214                 '$password4'=> array('mpassword', t('Password:'), '', t('Your current password to confirm the changes')),
1215                 '$oid_enable' => (! get_config('system','no_openid')),
1216                 '$openid'       => $openid_field,
1217
1218                 '$h_basic'      => t('Basic Settings'),
1219                 '$username' => array('username',  t('Full Name:'), $username,''),
1220                 '$email'        => array('email', t('Email Address:'), $email, '', '', '', 'email'),
1221                 '$timezone' => array('timezone_select' , t('Your Timezone:'), select_timezone($timezone), ''),
1222                 '$language' => array('language', t('Your Language:'), $language, t('Set the language we use to show you friendica interface and to send you emails'), $lang_choices),
1223                 '$defloc'       => array('defloc', t('Default Post Location:'), $defloc, ''),
1224                 '$allowloc' => array('allow_location', t('Use Browser Location:'), ($a->user['allow_location'] == 1), ''),
1225
1226
1227                 '$h_prv'        => t('Security and Privacy Settings'),
1228
1229                 '$maxreq'       => array('maxreq', t('Maximum Friend Requests/Day:'), $maxreq ,t("\x28to prevent spam abuse\x29")),
1230                 '$permissions' => t('Default Post Permissions'),
1231                 '$permdesc' => t("\x28click to open/close\x29"),
1232                 '$visibility' => $profile['net-publish'],
1233                 '$aclselect' => populate_acl($a->user),
1234                 '$suggestme' => $suggestme,
1235                 '$blockwall'=> $blockwall, // array('blockwall', t('Allow friends to post to your profile page:'), !$blockwall, ''),
1236                 '$blocktags'=> $blocktags, // array('blocktags', t('Allow friends to tag your posts:'), !$blocktags, ''),
1237
1238                 // ACL permissions box
1239                 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1240                 '$group_perms' => t('Show to Groups'),
1241                 '$contact_perms' => t('Show to Contacts'),
1242                 '$private' => t('Default Private Post'),
1243                 '$public' => t('Default Public Post'),
1244                 '$is_private' => $private_post,
1245                 '$return_path' => $query_str,
1246                 '$public_link' => $public_post_link,
1247                 '$settings_perms' => t('Default Permissions for New Posts'),
1248
1249                 '$group_select' => $group_select,
1250
1251
1252                 '$expire'       => $expire_arr,
1253
1254                 '$profile_in_dir' => $profile_in_dir,
1255                 '$profile_in_net_dir' => $profile_in_net_dir,
1256                 '$hide_friends' => $hide_friends,
1257                 '$hide_wall' => $hide_wall,
1258                 '$unkmail' => $unkmail,
1259                 '$cntunkmail'   => array('cntunkmail', t('Maximum private messages per day from unknown people:'), $cntunkmail ,t("\x28to prevent spam abuse\x29")),
1260
1261
1262                 '$h_not'        => t('Notification Settings'),
1263                 '$activity_options' => t('By default post a status message when:'),
1264                 '$post_newfriend' => array('post_newfriend',  t('accepting a friend request'), $post_newfriend, ''),
1265                 '$post_joingroup' => array('post_joingroup',  t('joining a forum/community'), $post_joingroup, ''),
1266                 '$post_profilechange' => array('post_profilechange',  t('making an <em>interesting</em> profile change'), $post_profilechange, ''),
1267                 '$lbl_not'      => t('Send a notification email when:'),
1268                 '$notify1'      => array('notify1', t('You receive an introduction'), ($notify & NOTIFY_INTRO), NOTIFY_INTRO, ''),
1269                 '$notify2'      => array('notify2', t('Your introductions are confirmed'), ($notify & NOTIFY_CONFIRM), NOTIFY_CONFIRM, ''),
1270                 '$notify3'      => array('notify3', t('Someone writes on your profile wall'), ($notify & NOTIFY_WALL), NOTIFY_WALL, ''),
1271                 '$notify4'      => array('notify4', t('Someone writes a followup comment'), ($notify & NOTIFY_COMMENT), NOTIFY_COMMENT, ''),
1272                 '$notify5'      => array('notify5', t('You receive a private message'), ($notify & NOTIFY_MAIL), NOTIFY_MAIL, ''),
1273                 '$notify6'  => array('notify6', t('You receive a friend suggestion'), ($notify & NOTIFY_SUGGEST), NOTIFY_SUGGEST, ''),
1274                 '$notify7'  => array('notify7', t('You are tagged in a post'), ($notify & NOTIFY_TAGSELF), NOTIFY_TAGSELF, ''),
1275                 '$notify8'  => array('notify8', t('You are poked/prodded/etc. in a post'), ($notify & NOTIFY_POKE), NOTIFY_POKE, ''),
1276
1277         '$desktop_notifications' => array('desktop_notifications', t('Activate desktop notifications') , false, t('Show desktop popup on new notifications')),
1278
1279                 '$email_textonly' => array('email_textonly', t('Text-only notification emails'),
1280                                                                         get_pconfig(local_user(),'system','email_textonly'),
1281                                                                         t('Send text only notification emails, without the html part')),
1282
1283                 '$h_advn' => t('Advanced Account/Page Type Settings'),
1284                 '$h_descadvn' => t('Change the behaviour of this account for special situations'),
1285                 '$pagetype' => $pagetype,
1286
1287                 '$relocate' => t('Relocate'),
1288                 '$relocate_text' => t("If you have moved this profile from another server, and some of your contacts don't receive your updates, try pushing this button."),
1289                 '$relocate_button' => t("Resend relocate message to contacts"),
1290
1291         ));
1292
1293         call_hooks('settings_form',$o);
1294
1295         $o .= '</form>' . "\r\n";
1296
1297         return $o;
1298
1299 }
1300