]> git.mxchange.org Git - friendica.git/blob - mod/settings.php
Merge pull request #2441 from rabuzarus/0704_doxygen_forum
[friendica.git] / mod / settings.php
1 <?php
2
3 require_once('include/group.php');
4
5 function get_theme_config_file($theme){
6         $a = get_app();
7         $base_theme = $a->theme_info['extends'];
8
9         if (file_exists("view/theme/$theme/config.php")){
10                 return "view/theme/$theme/config.php";
11         }
12         if (file_exists("view/theme/$base_theme/config.php")){
13                 return "view/theme/$base_theme/config.php";
14         }
15         return null;
16 }
17
18 function settings_init(&$a) {
19
20         if(! local_user()) {
21                 notice( t('Permission denied.') . EOL );
22                 return;
23         }
24
25         // APC deactivated, since there are problems with PHP 5.5
26         //if (function_exists("apc_delete")) {
27         //      $toDelete = new APCIterator('user', APC_ITER_VALUE);
28         //      apc_delete($toDelete);
29         //}
30
31         // These lines provide the javascript needed by the acl selector
32
33         $tpl = get_markup_template("settings-head.tpl");
34         $a->page['htmlhead'] .= replace_macros($tpl,array(
35                 '$ispublic' => t('everybody')
36         ));
37
38
39
40         $tabs = array(
41                 array(
42                         'label' => t('Account'),
43                         'url'   => 'settings',
44                         'selected'      =>  (($a->argc == 1) && ($a->argv[0] === 'settings')?'active':''),
45                         'accesskey' => 'o',
46                 ),
47         );
48
49         if(get_features()) {
50                 $tabs[] =       array(
51                                         'label' => t('Additional features'),
52                                         'url'   => 'settings/features',
53                                         'selected'      => (($a->argc > 1) && ($a->argv[1] === 'features') ? 'active' : ''),
54                                         'accesskey' => 't',
55                                 );
56         }
57
58         $tabs[] =       array(
59                 'label' => t('Display'),
60                 'url'   => 'settings/display',
61                 'selected'      => (($a->argc > 1) && ($a->argv[1] === 'display')?'active':''),
62                 'accesskey' => 'i',
63         );
64
65         $tabs[] =       array(
66                 'label' => t('Social Networks'),
67                 'url'   => 'settings/connectors',
68                 'selected'      => (($a->argc > 1) && ($a->argv[1] === 'connectors')?'active':''),
69                 'accesskey' => 'w',
70         );
71
72         $tabs[] =       array(
73                 'label' => t('Plugins'),
74                 'url'   => 'settings/addon',
75                 'selected'      => (($a->argc > 1) && ($a->argv[1] === 'addon')?'active':''),
76                 'accesskey' => 'l',
77         );
78
79         $tabs[] =       array(
80                 'label' => t('Delegations'),
81                 'url'   => 'delegate',
82                 'selected'      => (($a->argc == 1) && ($a->argv[0] === 'delegate')?'active':''),
83                 'accesskey' => 'd',
84         );
85
86         $tabs[] =       array(
87                 'label' => t('Connected apps'),
88                 'url' => 'settings/oauth',
89                 'selected' => (($a->argc > 1) && ($a->argv[1] === 'oauth')?'active':''),
90                 'accesskey' => 'b',
91         );
92
93         $tabs[] =       array(
94                 'label' => t('Export personal data'),
95                 'url' => 'uexport',
96                 'selected' => (($a->argc == 1) && ($a->argv[0] === 'uexport')?'active':''),
97                 'accesskey' => 'e',
98         );
99
100         $tabs[] =       array(
101                 'label' => t('Remove account'),
102                 'url' => 'removeme',
103                 'selected' => (($a->argc == 1) && ($a->argv[0] === 'removeme')?'active':''),
104                 'accesskey' => 'r',
105         );
106
107
108         $tabtpl = get_markup_template("generic_links_widget.tpl");
109         $a->page['aside'] = replace_macros($tabtpl, array(
110                 '$title' => t('Settings'),
111                 '$class' => 'settings-widget',
112                 '$items' => $tabs,
113         ));
114
115 }
116
117
118 function settings_post(&$a) {
119
120         if(! local_user())
121                 return;
122
123         if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
124                 return;
125
126         if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
127                 notice( t('Permission denied.') . EOL);
128                 return;
129         }
130
131         $old_page_flags = $a->user['page-flags'];
132
133         if(($a->argc > 1) && ($a->argv[1] === 'oauth') && x($_POST,'remove')){
134                 check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
135
136                 $key = $_POST['remove'];
137                 q("DELETE FROM tokens WHERE id='%s' AND uid=%d",
138                         dbesc($key),
139                         local_user());
140                 goaway($a->get_baseurl(true)."/settings/oauth/");
141                 return;
142         }
143
144         if(($a->argc > 2) && ($a->argv[1] === 'oauth')  && ($a->argv[2] === 'edit'||($a->argv[2] === 'add')) && x($_POST,'submit')) {
145
146                 check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
147
148                 $name           = ((x($_POST,'name')) ? $_POST['name'] : '');
149                 $key            = ((x($_POST,'key')) ? $_POST['key'] : '');
150                 $secret         = ((x($_POST,'secret')) ? $_POST['secret'] : '');
151                 $redirect       = ((x($_POST,'redirect')) ? $_POST['redirect'] : '');
152                 $icon           = ((x($_POST,'icon')) ? $_POST['icon'] : '');
153                 if ($name=="" || $key=="" || $secret==""){
154                         notice(t("Missing some important data!"));
155
156                 } else {
157                         if ($_POST['submit']==t("Update")){
158                                 $r = q("UPDATE clients SET
159                                                         client_id='%s',
160                                                         pw='%s',
161                                                         name='%s',
162                                                         redirect_uri='%s',
163                                                         icon='%s',
164                                                         uid=%d
165                                                 WHERE client_id='%s'",
166                                                 dbesc($key),
167                                                 dbesc($secret),
168                                                 dbesc($name),
169                                                 dbesc($redirect),
170                                                 dbesc($icon),
171                                                 local_user(),
172                                                 dbesc($key));
173                         } else {
174                                 $r = q("INSERT INTO clients
175                                                         (client_id, pw, name, redirect_uri, icon, uid)
176                                                 VALUES ('%s','%s','%s','%s','%s',%d)",
177                                                 dbesc($key),
178                                                 dbesc($secret),
179                                                 dbesc($name),
180                                                 dbesc($redirect),
181                                                 dbesc($icon),
182                                                 local_user());
183                         }
184                 }
185                 goaway($a->get_baseurl(true)."/settings/oauth/");
186                 return;
187         }
188
189         if(($a->argc > 1) && ($a->argv[1] == 'addon')) {
190                 check_form_security_token_redirectOnErr('/settings/addon', 'settings_addon');
191
192                 call_hooks('plugin_settings_post', $_POST);
193                 return;
194         }
195
196         if(($a->argc > 1) && ($a->argv[1] == 'connectors')) {
197
198                 check_form_security_token_redirectOnErr('/settings/connectors', 'settings_connectors');
199
200                 if(x($_POST, 'general-submit')) {
201                         set_pconfig(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening']));
202                         set_pconfig(local_user(), 'system', 'ostatus_autofriend', intval($_POST['snautofollow']));
203                         set_pconfig(local_user(), 'ostatus', 'default_group', $_POST['group-selection']);
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('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('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('settings' );
633         return; // NOTREACHED
634 }
635
636
637 function settings_content(&$a) {
638
639         $o = '';
640         nav_set_selected('settings');
641
642         if(! local_user()) {
643                 #notice( t('Permission denied.') . EOL );
644                 return;
645         }
646
647         if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
648                 notice( t('Permission denied.') . EOL );
649                 return;
650         }
651
652
653
654         if(($a->argc > 1) && ($a->argv[1] === 'oauth')) {
655
656                 if(($a->argc > 2) && ($a->argv[2] === 'add')) {
657                         $tpl = get_markup_template("settings_oauth_edit.tpl");
658                         $o .= replace_macros($tpl, array(
659                                 '$form_security_token' => get_form_security_token("settings_oauth"),
660                                 '$title'        => t('Add application'),
661                                 '$submit'       => t('Save Settings'),
662                                 '$cancel'       => t('Cancel'),
663                                 '$name'         => array('name', t('Name'), '', ''),
664                                 '$key'          => array('key', t('Consumer Key'), '', ''),
665                                 '$secret'       => array('secret', t('Consumer Secret'), '', ''),
666                                 '$redirect'     => array('redirect', t('Redirect'), '', ''),
667                                 '$icon'         => array('icon', t('Icon url'), '', ''),
668                         ));
669                         return $o;
670                 }
671
672                 if(($a->argc > 3) && ($a->argv[2] === 'edit')) {
673                         $r = q("SELECT * FROM clients WHERE client_id='%s' AND uid=%d",
674                                         dbesc($a->argv[3]),
675                                         local_user());
676
677                         if (!count($r)){
678                                 notice(t("You can't edit this application."));
679                                 return;
680                         }
681                         $app = $r[0];
682
683                         $tpl = get_markup_template("settings_oauth_edit.tpl");
684                         $o .= replace_macros($tpl, array(
685                                 '$form_security_token' => get_form_security_token("settings_oauth"),
686                                 '$title'        => t('Add application'),
687                                 '$submit'       => t('Update'),
688                                 '$cancel'       => t('Cancel'),
689                                 '$name'         => array('name', t('Name'), $app['name'] , ''),
690                                 '$key'          => array('key', t('Consumer Key'), $app['client_id'], ''),
691                                 '$secret'       => array('secret', t('Consumer Secret'), $app['pw'], ''),
692                                 '$redirect'     => array('redirect', t('Redirect'), $app['redirect_uri'], ''),
693                                 '$icon'         => array('icon', t('Icon url'), $app['icon'], ''),
694                         ));
695                         return $o;
696                 }
697
698                 if(($a->argc > 3) && ($a->argv[2] === 'delete')) {
699                         check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't');
700
701                         $r = q("DELETE FROM clients WHERE client_id='%s' AND uid=%d",
702                                         dbesc($a->argv[3]),
703                                         local_user());
704                         goaway($a->get_baseurl(true)."/settings/oauth/");
705                         return;
706                 }
707
708
709                 $r = q("SELECT clients.*, tokens.id as oauth_token, (clients.uid=%d) AS my
710                                 FROM clients
711                                 LEFT JOIN tokens ON clients.client_id=tokens.client_id
712                                 WHERE clients.uid IN (%d,0)",
713                                 local_user(),
714                                 local_user());
715
716
717                 $tpl = get_markup_template("settings_oauth.tpl");
718                 $o .= replace_macros($tpl, array(
719                         '$form_security_token' => get_form_security_token("settings_oauth"),
720                         '$baseurl'      => $a->get_baseurl(true),
721                         '$title'        => t('Connected Apps'),
722                         '$add'          => t('Add application'),
723                         '$edit'         => t('Edit'),
724                         '$delete'               => t('Delete'),
725                         '$consumerkey' => t('Client key starts with'),
726                         '$noname'       => t('No name'),
727                         '$remove'       => t('Remove authorization'),
728                         '$apps'         => $r,
729                 ));
730                 return $o;
731
732         }
733
734         if(($a->argc > 1) && ($a->argv[1] === 'addon')) {
735                 $settings_addons = "";
736
737                 $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
738                 if(! count($r))
739                         $settings_addons = t('No Plugin settings configured');
740
741                 call_hooks('plugin_settings', $settings_addons);
742
743
744                 $tpl = get_markup_template("settings_addons.tpl");
745                 $o .= replace_macros($tpl, array(
746                         '$form_security_token' => get_form_security_token("settings_addon"),
747                         '$title'        => t('Plugin Settings'),
748                         '$settings_addons' => $settings_addons
749                 ));
750                 return $o;
751         }
752
753         if(($a->argc > 1) && ($a->argv[1] === 'features')) {
754
755                 $arr = array();
756                 $features = get_features();
757                 foreach($features as $fname => $fdata) {
758                         $arr[$fname] = array();
759                         $arr[$fname][0] = $fdata[0];
760                         foreach(array_slice($fdata,1) as $f) {
761                                 $arr[$fname][1][] = array('feature_' .$f[0],$f[1],((intval(feature_enabled(local_user(),$f[0]))) ? "1" : ''),$f[2],array(t('Off'),t('On')));
762                         }
763                 }
764
765
766                 $tpl = get_markup_template("settings_features.tpl");
767                 $o .= replace_macros($tpl, array(
768                         '$form_security_token' => get_form_security_token("settings_features"),
769                         '$title'        => t('Additional Features'),
770                         '$features' => $arr,
771                         '$submit'   => t('Save Settings'),
772                 ));
773                 return $o;
774         }
775
776         if(($a->argc > 1) && ($a->argv[1] === 'connectors')) {
777
778                 $settings_connectors = '<span id="settings_general_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_general_expanded\'); openClose(\'settings_general_inflated\');">';
779                 $settings_connectors .= '<h3 class="connector">'. t('General Social Media Settings').'</h3>';
780                 $settings_connectors .= '</span>';
781                 $settings_connectors .= '<div id="settings_general_expanded" class="settings-block" style="display: none;">';
782                 $settings_connectors .= '<span class="fakelink" onclick="openClose(\'settings_general_expanded\'); openClose(\'settings_general_inflated\');">';
783                 $settings_connectors .= '<h3 class="connector">'. t('General Social Media Settings').'</h3>';
784                 $settings_connectors .= '</span>';
785
786                 $checked = ((get_pconfig(local_user(), 'system', 'no_intelligent_shortening')) ? ' checked="checked" ' : '');
787
788                 $settings_connectors .= '<div id="no_intelligent_shortening" class="field checkbox">';
789                 $settings_connectors .= '<label id="no_intelligent_shortening-label" for="shortening-checkbox">'. t('Disable intelligent shortening'). '</label>';
790                 $settings_connectors .= '<input id="shortening-checkbox" type="checkbox" name="no_intelligent_shortening" value="1" ' . $checked . '/>';
791                 $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>';
792                 $settings_connectors .= '</div>';
793
794                 $checked = ((get_pconfig(local_user(), 'system', 'ostatus_autofriend')) ? ' checked="checked" ' : '');
795
796                 $settings_connectors .= '<div id="snautofollow-wrapper" class="field checkbox">';
797                 $settings_connectors .= '<label id="snautofollow-label" for="snautofollow-checkbox">'. t('Automatically follow any GNU Social (OStatus) followers/mentioners'). '</label>';
798                 $settings_connectors .= '<input id="snautofollow-checkbox" type="checkbox" name="snautofollow" value="1" ' . $checked . '/>';
799                 $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>';
800                 $settings_connectors .= '</div>';
801
802                 $default_group = get_pconfig(local_user(), 'ostatus', 'default_group');
803                 $legacy_contact = get_pconfig(local_user(), 'ostatus', 'legacy_contact');
804
805                 $settings_connectors .= mini_group_select(local_user(), $default_group, t("Default group for OStatus contacts"));
806
807                 if ($legacy_contact != "")
808                         $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.$a->get_baseurl().'/ostatus_subscribe?url='.urlencode($legacy_contact).'">';
809
810                 $settings_connectors .= '<div id="legacy-contact-wrapper" class="field input">';
811                 $settings_connectors .= '<label id="legacy-contact-label" for="snautofollow-checkbox">'. t('Your legacy GNU Social account'). '</label>';
812                 $settings_connectors .= '<input id="legacy-contact-checkbox" name="legacy_contact" value="'.$legacy_contact.'"/>';
813                 $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>';
814                 $settings_connectors .= '</div>';
815
816                 $settings_connectors .= '<p><a href="'.$a->get_baseurl().'/repair_ostatus">'.t("Repair OStatus subscriptions").'</a></p>';
817
818                 $settings_connectors .= '<div class="settings-submit-wrapper" ><input type="submit" name="general-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div>';
819
820                 $settings_connectors .= '</div><div class="clear"></div>';
821
822                 call_hooks('connector_settings', $settings_connectors);
823
824                 if (is_site_admin()) {
825                         $diasp_enabled = sprintf( t('Built-in support for %s connectivity is %s'), t('Diaspora'), ((get_config('system','diaspora_enabled')) ? t('enabled') : t('disabled')));
826                         $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')));
827                 } else {
828                         $diasp_enabled = "";
829                         $ostat_enabled = "";
830                 }
831
832                 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
833                 if(get_config('system','dfrn_only'))
834                         $mail_disabled = 1;
835
836                 if(! $mail_disabled) {
837                         $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
838                                 local_user()
839                         );
840                 }
841                 else {
842                         $r = null;
843                 }
844
845                 $mail_server       = ((count($r)) ? $r[0]['server'] : '');
846                 $mail_port         = ((count($r) && intval($r[0]['port'])) ? intval($r[0]['port']) : '');
847                 $mail_ssl          = ((count($r)) ? $r[0]['ssltype'] : '');
848                 $mail_user         = ((count($r)) ? $r[0]['user'] : '');
849                 $mail_replyto      = ((count($r)) ? $r[0]['reply_to'] : '');
850                 $mail_pubmail      = ((count($r)) ? $r[0]['pubmail'] : 0);
851                 $mail_action       = ((count($r)) ? $r[0]['action'] : 0);
852                 $mail_movetofolder = ((count($r)) ? $r[0]['movetofolder'] : '');
853                 $mail_chk          = ((count($r)) ? $r[0]['last_check'] : '0000-00-00 00:00:00');
854
855
856                 $tpl = get_markup_template("settings_connectors.tpl");
857
858                 if(! service_class_allows(local_user(),'email_connect')) {
859                         $mail_disabled_message = upgrade_bool_message();
860                 }
861                 else {
862                         $mail_disabled_message = (($mail_disabled) ? t('Email access is disabled on this site.') : '');
863                 }
864
865
866                 $o .= replace_macros($tpl, array(
867                         '$form_security_token' => get_form_security_token("settings_connectors"),
868
869                         '$title'        => t('Social Networks'),
870
871                         '$diasp_enabled' => $diasp_enabled,
872                         '$ostat_enabled' => $ostat_enabled,
873
874                         '$h_imap' => t('Email/Mailbox Setup'),
875                         '$imap_desc' => t("If you wish to communicate with email contacts using this service \x28optional\x29, please specify how to connect to your mailbox."),
876                         '$imap_lastcheck' => array('imap_lastcheck', t('Last successful email check:'), $mail_chk,''),
877                         '$mail_disabled' => $mail_disabled_message,
878                         '$mail_server'  => array('mail_server',  t('IMAP server name:'), $mail_server, ''),
879                         '$mail_port'    => array('mail_port',    t('IMAP port:'), $mail_port, ''),
880                         '$mail_ssl'             => array('mail_ssl',     t('Security:'), strtoupper($mail_ssl), '', array( 'notls'=>t('None'), 'TLS'=>'TLS', 'SSL'=>'SSL')),
881                         '$mail_user'    => array('mail_user',    t('Email login name:'), $mail_user, ''),
882                         '$mail_pass'    => array('mail_pass',    t('Email password:'), '', ''),
883                         '$mail_replyto' => array('mail_replyto', t('Reply-to address:'), $mail_replyto, 'Optional'),
884                         '$mail_pubmail' => array('mail_pubmail', t('Send public posts to all email contacts:'), $mail_pubmail, ''),
885                         '$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'))),
886                         '$mail_movetofolder'    => array('mail_movetofolder',    t('Move to folder:'), $mail_movetofolder, ''),
887                         '$submit' => t('Save Settings'),
888
889                         '$settings_connectors' => $settings_connectors
890                 ));
891
892                 call_hooks('display_settings', $o);
893                 return $o;
894         }
895
896         /*
897          * DISPLAY SETTINGS
898          */
899         if(($a->argc > 1) && ($a->argv[1] === 'display')) {
900                 $default_theme = get_config('system','theme');
901                 if(! $default_theme)
902                         $default_theme = 'default';
903                 $default_mobile_theme = get_config('system','mobile-theme');
904                 if(! $mobile_default_theme)
905                         $mobile_default_theme = 'none';
906
907                 $allowed_themes_str = get_config('system','allowed_themes');
908                 $allowed_themes_raw = explode(',',$allowed_themes_str);
909                 $allowed_themes = array();
910                 if(count($allowed_themes_raw))
911                         foreach($allowed_themes_raw as $x)
912                                 if(strlen(trim($x)) && is_dir("view/theme/$x"))
913                                         $allowed_themes[] = trim($x);
914
915
916                 $themes = array();
917                 $mobile_themes = array("---" => t('No special theme for mobile devices'));
918                 $files = glob('view/theme/*'); /* */
919                 if($allowed_themes) {
920                         foreach($allowed_themes as $th) {
921                                 $f = $th;
922                                 $is_experimental = file_exists('view/theme/' . $th . '/experimental');
923                                 $unsupported = file_exists('view/theme/' . $th . '/unsupported');
924                                 $is_mobile = file_exists('view/theme/' . $th . '/mobile');
925                                 if (!$is_experimental or ($is_experimental && (get_config('experimentals','exp_themes')==1 or get_config('experimentals','exp_themes')===false))){
926                                         $theme_name = (($is_experimental) ?  sprintf("%s - \x28Experimental\x29", $f) : $f);
927                                         if($is_mobile) {
928                                                 $mobile_themes[$f]=$theme_name;
929                                         }
930                                         else {
931                                                 $themes[$f]=$theme_name;
932                                         }
933                                 }
934                         }
935                 }
936                 $theme_selected = (!x($_SESSION,'theme')? $default_theme : $_SESSION['theme']);
937                 $mobile_theme_selected = (!x($_SESSION,'mobile-theme')? $default_mobile_theme : $_SESSION['mobile-theme']);
938
939                 $browser_update = intval(get_pconfig(local_user(), 'system','update_interval'));
940                 if (intval($browser_update) != -1)
941                         $browser_update = (($browser_update == 0) ? 40 : $browser_update / 1000); // default if not set: 40 seconds
942
943                 $itemspage_network = intval(get_pconfig(local_user(), 'system','itemspage_network'));
944                 $itemspage_network = (($itemspage_network > 0 && $itemspage_network < 101) ? $itemspage_network : 40); // default if not set: 40 items
945                 $itemspage_mobile_network = intval(get_pconfig(local_user(), 'system','itemspage_mobile_network'));
946                 $itemspage_mobile_network = (($itemspage_mobile_network > 0 && $itemspage_mobile_network < 101) ? $itemspage_mobile_network : 20); // default if not set: 20 items
947
948                 $nosmile = get_pconfig(local_user(),'system','no_smilies');
949                 $nosmile = (($nosmile===false)? '0': $nosmile); // default if not set: 0
950
951                 $first_day_of_week = get_pconfig(local_user(),'system','first_day_of_week');
952                 $first_day_of_week = (($first_day_of_week===false)? '0': $first_day_of_week); // default if not set: 0
953                 $weekdays = array(0 => t("Sunday"), 1 => t("Monday"));
954
955                 $noinfo = get_pconfig(local_user(),'system','ignore_info');
956                 $noinfo = (($noinfo===false)? '0': $noinfo); // default if not set: 0
957
958                 $infinite_scroll = get_pconfig(local_user(),'system','infinite_scroll');
959                 $infinite_scroll = (($infinite_scroll===false)? '0': $infinite_scroll); // default if not set: 0
960
961                 $no_auto_update = get_pconfig(local_user(),'system','no_auto_update');
962                 $no_auto_update = (($no_auto_update===false)? '0': $no_auto_update); // default if not set: 0
963
964                 $theme_config = "";
965                 if( ($themeconfigfile = get_theme_config_file($theme_selected)) != null){
966                         require_once($themeconfigfile);
967                         $theme_config = theme_content($a);
968                 }
969
970                 $tpl = get_markup_template("settings_display.tpl");
971                 $o = replace_macros($tpl, array(
972                         '$ptitle'       => t('Display Settings'),
973                         '$form_security_token' => get_form_security_token("settings_display"),
974                         '$submit'       => t('Save Settings'),
975                         '$baseurl' => $a->get_baseurl(true),
976                         '$uid' => local_user(),
977
978                         '$theme'        => array('theme', t('Display Theme:'), $theme_selected, '', $themes, true),
979                         '$mobile_theme' => array('mobile_theme', t('Mobile Theme:'), $mobile_theme_selected, '', $mobile_themes, false),
980                         '$ajaxint'   => array('browser_update',  t("Update browser every xx seconds"), $browser_update, t('Minimum of 10 seconds. Enter -1 to disable it.')),
981                         '$itemspage_network'   => array('itemspage_network',  t("Number of items to display per page:"), $itemspage_network, t('Maximum of 100 items')),
982                         '$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')),
983                         '$nosmile'      => array('nosmile', t("Don't show emoticons"), $nosmile, ''),
984                         '$calendar_title' => t('Calendar'),
985                         '$first_day_of_week'    => array('first_day_of_week', t('Beginning of week:'), $first_day_of_week, '', $weekdays, false),
986                         '$noinfo'       => array('noinfo', t("Don't show notices"), $noinfo, ''),
987                         '$infinite_scroll'      => array('infinite_scroll', t("Infinite scroll"), $infinite_scroll, ''),
988                         '$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.'),
989
990                         'stitle' => t('Theme settings'),
991                         '$theme_config' => $theme_config,
992                 ));
993
994                 $tpl = get_markup_template("settings_display_end.tpl");
995                 $a->page['end'] .= replace_macros($tpl, array(
996                         '$theme'        => array('theme', t('Display Theme:'), $theme_selected, '', $themes)
997                 ));
998
999                 return $o;
1000         }
1001
1002
1003         /*
1004          * ACCOUNT SETTINGS
1005          */
1006
1007         require_once('include/acl_selectors.php');
1008
1009         $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
1010                 intval(local_user())
1011         );
1012         if(count($p))
1013                 $profile = $p[0];
1014
1015         $username   = $a->user['username'];
1016         $email      = $a->user['email'];
1017         $nickname   = $a->user['nickname'];
1018         $timezone   = $a->user['timezone'];
1019         $language   = $a->user['language'];
1020         $notify     = $a->user['notify-flags'];
1021         $defloc     = $a->user['default-location'];
1022         $openid     = $a->user['openid'];
1023         $maxreq     = $a->user['maxreq'];
1024         $expire     = ((intval($a->user['expire'])) ? $a->user['expire'] : '');
1025         $blockwall  = $a->user['blockwall'];
1026         $blocktags  = $a->user['blocktags'];
1027         $unkmail    = $a->user['unkmail'];
1028         $cntunkmail = $a->user['cntunkmail'];
1029
1030         $expire_items = get_pconfig(local_user(), 'expire','items');
1031         $expire_items = (($expire_items===false)? '1' : $expire_items); // default if not set: 1
1032
1033         $expire_notes = get_pconfig(local_user(), 'expire','notes');
1034         $expire_notes = (($expire_notes===false)? '1' : $expire_notes); // default if not set: 1
1035
1036         $expire_starred = get_pconfig(local_user(), 'expire','starred');
1037         $expire_starred = (($expire_starred===false)? '1' : $expire_starred); // default if not set: 1
1038
1039         $expire_photos = get_pconfig(local_user(), 'expire','photos');
1040         $expire_photos = (($expire_photos===false)? '0' : $expire_photos); // default if not set: 0
1041
1042         $expire_network_only = get_pconfig(local_user(), 'expire','network_only');
1043         $expire_network_only = (($expire_network_only===false)? '0' : $expire_network_only); // default if not set: 0
1044
1045
1046         $suggestme = get_pconfig(local_user(), 'system','suggestme');
1047         $suggestme = (($suggestme===false)? '0': $suggestme); // default if not set: 0
1048
1049         $post_newfriend = get_pconfig(local_user(), 'system','post_newfriend');
1050         $post_newfriend = (($post_newfriend===false)? '0': $post_newfriend); // default if not set: 0
1051
1052         $post_joingroup = get_pconfig(local_user(), 'system','post_joingroup');
1053         $post_joingroup = (($post_joingroup===false)? '0': $post_joingroup); // default if not set: 0
1054
1055         $post_profilechange = get_pconfig(local_user(), 'system','post_profilechange');
1056         $post_profilechange = (($post_profilechange===false)? '0': $post_profilechange); // default if not set: 0
1057
1058         // nowarn_insecure
1059
1060         if(! strlen($a->user['timezone']))
1061                 $timezone = date_default_timezone_get();
1062
1063
1064
1065         $pageset_tpl = get_markup_template('pagetypes.tpl');
1066         $pagetype = replace_macros($pageset_tpl, array(
1067                 '$user'         => t("User Types"),
1068                 '$community'    => t("Community Types"),
1069                 '$page_normal'  => array('page-flags', t('Normal Account Page'), PAGE_NORMAL,
1070                                                                         t('This account is a normal personal profile'),
1071                                                                         ($a->user['page-flags'] == PAGE_NORMAL)),
1072
1073                 '$page_soapbox'         => array('page-flags', t('Soapbox Page'), PAGE_SOAPBOX,
1074                                                                         t('Automatically approve all connection/friend requests as read-only fans'),
1075                                                                         ($a->user['page-flags'] == PAGE_SOAPBOX)),
1076
1077                 '$page_community'       => array('page-flags', t('Community Forum/Celebrity Account'), PAGE_COMMUNITY,
1078                                                                         t('Automatically approve all connection/friend requests as read-write fans'),
1079                                                                         ($a->user['page-flags'] == PAGE_COMMUNITY)),
1080
1081                 '$page_freelove'        => array('page-flags', t('Automatic Friend Page'), PAGE_FREELOVE,
1082                                                                         t('Automatically approve all connection/friend requests as friends'),
1083                                                                         ($a->user['page-flags'] == PAGE_FREELOVE)),
1084
1085                 '$page_prvgroup'        => array('page-flags', t('Private Forum [Experimental]'), PAGE_PRVGROUP,
1086                                                                         t('Private forum - approved members only'),
1087                                                                         ($a->user['page-flags'] == PAGE_PRVGROUP)),
1088
1089
1090         ));
1091
1092         $noid = get_config('system','no_openid');
1093
1094         if($noid) {
1095                 $openid_field = false;
1096         }
1097         else {
1098                 $openid_field = array('openid_url', t('OpenID:'),$openid, t("\x28Optional\x29 Allow this OpenID to login to this account."), "", "", "url");
1099         }
1100
1101
1102         $opt_tpl = get_markup_template("field_yesno.tpl");
1103         if(get_config('system','publish_all')) {
1104                 $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
1105         }
1106         else {
1107                 $profile_in_dir = replace_macros($opt_tpl,array(
1108                         '$field'        => array('profile_in_directory', t('Publish your default profile in your local site directory?'), $profile['publish'], '', array(t('No'),t('Yes'))),
1109                 ));
1110         }
1111
1112         if(strlen(get_config('system','directory'))) {
1113                 $profile_in_net_dir = replace_macros($opt_tpl,array(
1114                         '$field'        => array('profile_in_netdirectory', t('Publish your default profile in the global social directory?'), $profile['net-publish'], '', array(t('No'),t('Yes'))),
1115                 ));
1116         }
1117         else
1118                 $profile_in_net_dir = '';
1119
1120
1121         $hide_friends = replace_macros($opt_tpl,array(
1122                         '$field'        => array('hide-friends', t('Hide your contact/friend list from viewers of your default profile?'), $profile['hide-friends'], '', array(t('No'),t('Yes'))),
1123         ));
1124
1125         $hide_wall = replace_macros($opt_tpl,array(
1126                         '$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'))),
1127
1128         ));
1129
1130         $blockwall = replace_macros($opt_tpl,array(
1131                         '$field'        => array('blockwall',  t('Allow friends to post to your profile page?'), (intval($a->user['blockwall']) ? '0' : '1'), '', array(t('No'),t('Yes'))),
1132
1133         ));
1134
1135
1136         $blocktags = replace_macros($opt_tpl,array(
1137                         '$field'        => array('blocktags',  t('Allow friends to tag your posts?'), (intval($a->user['blocktags']) ? '0' : '1'), '', array(t('No'),t('Yes'))),
1138
1139         ));
1140
1141
1142         $suggestme = replace_macros($opt_tpl,array(
1143                         '$field'        => array('suggestme',  t('Allow us to suggest you as a potential friend to new members?'), $suggestme, '', array(t('No'),t('Yes'))),
1144
1145         ));
1146
1147
1148         $unkmail = replace_macros($opt_tpl,array(
1149                         '$field'        => array('unkmail',  t('Permit unknown people to send you private mail?'), $unkmail, '', array(t('No'),t('Yes'))),
1150
1151         ));
1152
1153         $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
1154                 ? true : false);
1155
1156         if($invisible)
1157                 info( t('Profile is <strong>not published</strong>.') . EOL );
1158
1159
1160         //$subdir = ((strlen($a->get_path())) ? '<br />' . t('or') . ' ' . 'profile/' . $nickname : '');
1161
1162         $tpl_addr = get_markup_template("settings_nick_set.tpl");
1163
1164         $prof_addr = replace_macros($tpl_addr,array(
1165                 '$desc' => sprintf(t("Your Identity Address is <strong>'%s'</strong> or '%s'."), $nickname.'@'.$a->get_hostname().$a->get_path(), $a->get_baseurl().'/profile/'.$nickname),
1166                 '$basepath' => $a->get_hostname()
1167         ));
1168
1169         $stpl = get_markup_template('settings.tpl');
1170
1171         $expire_arr = array(
1172                 'days' => array('expire',  t("Automatically expire posts after this many days:"), $expire, t('If empty, posts will not expire. Expired posts will be deleted')),
1173                 'advanced' => t('Advanced expiration settings'),
1174                 'label' => t('Advanced Expiration'),
1175                 'items' => array('expire_items',  t("Expire posts:"), $expire_items, '', array(t('No'),t('Yes'))),
1176                 'notes' => array('expire_notes',  t("Expire personal notes:"), $expire_notes, '', array(t('No'),t('Yes'))),
1177                 'starred' => array('expire_starred',  t("Expire starred posts:"), $expire_starred, '', array(t('No'),t('Yes'))),
1178                 'photos' => array('expire_photos',  t("Expire photos:"), $expire_photos, '', array(t('No'),t('Yes'))),
1179                 'network_only' => array('expire_network_only',  t("Only expire posts by others:"), $expire_network_only, '', array(t('No'),t('Yes'))),
1180         );
1181
1182         require_once('include/group.php');
1183         $group_select = mini_group_select(local_user(),$a->user['def_gid']);
1184
1185
1186         // Private/public post links for the non-JS ACL form
1187         $private_post = 1;
1188         if($_REQUEST['public'])
1189                 $private_post = 0;
1190
1191         $query_str = $a->query_string;
1192         if(strpos($query_str, 'public=1') !== false)
1193                 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1194
1195         // I think $a->query_string may never have ? in it, but I could be wrong
1196         // It looks like it's from the index.php?q=[etc] rewrite that the web
1197         // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1198         if(strpos($query_str, '?') === false)
1199                 $public_post_link = '?public=1';
1200         else
1201                 $public_post_link = '&public=1';
1202
1203         /* Installed langs */
1204         $lang_choices = get_avaiable_languages();
1205
1206         $o .= replace_macros($stpl, array(
1207                 '$ptitle'       => t('Account Settings'),
1208
1209                 '$submit'       => t('Save Settings'),
1210                 '$baseurl' => $a->get_baseurl(true),
1211                 '$uid' => local_user(),
1212                 '$form_security_token' => get_form_security_token("settings"),
1213                 '$nickname_block' => $prof_addr,
1214
1215                 '$h_pass'       => t('Password Settings'),
1216                 '$password1'=> array('password', t('New Password:'), '', ''),
1217                 '$password2'=> array('confirm', t('Confirm:'), '', t('Leave password fields blank unless changing')),
1218                 '$password3'=> array('opassword', t('Current Password:'), '', t('Your current password to confirm the changes')),
1219                 '$password4'=> array('mpassword', t('Password:'), '', t('Your current password to confirm the changes')),
1220                 '$oid_enable' => (! get_config('system','no_openid')),
1221                 '$openid'       => $openid_field,
1222
1223                 '$h_basic'      => t('Basic Settings'),
1224                 '$username' => array('username',  t('Full Name:'), $username,''),
1225                 '$email'        => array('email', t('Email Address:'), $email, '', '', '', 'email'),
1226                 '$timezone' => array('timezone_select' , t('Your Timezone:'), select_timezone($timezone), ''),
1227                 '$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),
1228                 '$defloc'       => array('defloc', t('Default Post Location:'), $defloc, ''),
1229                 '$allowloc' => array('allow_location', t('Use Browser Location:'), ($a->user['allow_location'] == 1), ''),
1230
1231
1232                 '$h_prv'        => t('Security and Privacy Settings'),
1233
1234                 '$maxreq'       => array('maxreq', t('Maximum Friend Requests/Day:'), $maxreq ,t("\x28to prevent spam abuse\x29")),
1235                 '$permissions' => t('Default Post Permissions'),
1236                 '$permdesc' => t("\x28click to open/close\x29"),
1237                 '$visibility' => $profile['net-publish'],
1238                 '$aclselect' => populate_acl($a->user),
1239                 '$suggestme' => $suggestme,
1240                 '$blockwall'=> $blockwall, // array('blockwall', t('Allow friends to post to your profile page:'), !$blockwall, ''),
1241                 '$blocktags'=> $blocktags, // array('blocktags', t('Allow friends to tag your posts:'), !$blocktags, ''),
1242
1243                 // ACL permissions box
1244                 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1245                 '$group_perms' => t('Show to Groups'),
1246                 '$contact_perms' => t('Show to Contacts'),
1247                 '$private' => t('Default Private Post'),
1248                 '$public' => t('Default Public Post'),
1249                 '$is_private' => $private_post,
1250                 '$return_path' => $query_str,
1251                 '$public_link' => $public_post_link,
1252                 '$settings_perms' => t('Default Permissions for New Posts'),
1253
1254                 '$group_select' => $group_select,
1255
1256
1257                 '$expire'       => $expire_arr,
1258
1259                 '$profile_in_dir' => $profile_in_dir,
1260                 '$profile_in_net_dir' => $profile_in_net_dir,
1261                 '$hide_friends' => $hide_friends,
1262                 '$hide_wall' => $hide_wall,
1263                 '$unkmail' => $unkmail,
1264                 '$cntunkmail'   => array('cntunkmail', t('Maximum private messages per day from unknown people:'), $cntunkmail ,t("\x28to prevent spam abuse\x29")),
1265
1266
1267                 '$h_not'        => t('Notification Settings'),
1268                 '$activity_options' => t('By default post a status message when:'),
1269                 '$post_newfriend' => array('post_newfriend',  t('accepting a friend request'), $post_newfriend, ''),
1270                 '$post_joingroup' => array('post_joingroup',  t('joining a forum/community'), $post_joingroup, ''),
1271                 '$post_profilechange' => array('post_profilechange',  t('making an <em>interesting</em> profile change'), $post_profilechange, ''),
1272                 '$lbl_not'      => t('Send a notification email when:'),
1273                 '$notify1'      => array('notify1', t('You receive an introduction'), ($notify & NOTIFY_INTRO), NOTIFY_INTRO, ''),
1274                 '$notify2'      => array('notify2', t('Your introductions are confirmed'), ($notify & NOTIFY_CONFIRM), NOTIFY_CONFIRM, ''),
1275                 '$notify3'      => array('notify3', t('Someone writes on your profile wall'), ($notify & NOTIFY_WALL), NOTIFY_WALL, ''),
1276                 '$notify4'      => array('notify4', t('Someone writes a followup comment'), ($notify & NOTIFY_COMMENT), NOTIFY_COMMENT, ''),
1277                 '$notify5'      => array('notify5', t('You receive a private message'), ($notify & NOTIFY_MAIL), NOTIFY_MAIL, ''),
1278                 '$notify6'  => array('notify6', t('You receive a friend suggestion'), ($notify & NOTIFY_SUGGEST), NOTIFY_SUGGEST, ''),
1279                 '$notify7'  => array('notify7', t('You are tagged in a post'), ($notify & NOTIFY_TAGSELF), NOTIFY_TAGSELF, ''),
1280                 '$notify8'  => array('notify8', t('You are poked/prodded/etc. in a post'), ($notify & NOTIFY_POKE), NOTIFY_POKE, ''),
1281
1282         '$desktop_notifications' => array('desktop_notifications', t('Activate desktop notifications') , false, t('Show desktop popup on new notifications')),
1283
1284                 '$email_textonly' => array('email_textonly', t('Text-only notification emails'),
1285                                                                         get_pconfig(local_user(),'system','email_textonly'),
1286                                                                         t('Send text only notification emails, without the html part')),
1287
1288                 '$h_advn' => t('Advanced Account/Page Type Settings'),
1289                 '$h_descadvn' => t('Change the behaviour of this account for special situations'),
1290                 '$pagetype' => $pagetype,
1291
1292                 '$relocate' => t('Relocate'),
1293                 '$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."),
1294                 '$relocate_button' => t("Resend relocate message to contacts"),
1295
1296         ));
1297
1298         call_hooks('settings_form',$o);
1299
1300         $o .= '</form>' . "\r\n";
1301
1302         return $o;
1303
1304 }
1305