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