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