]> git.mxchange.org Git - friendica.git/blob - mod/settings.php
Merge branch 'master', remote-tracking branch 'remotes/upstream/master'
[friendica.git] / mod / settings.php
1 <?php
2
3
4 function settings_init(&$a) {
5         if(local_user()) {
6                 profile_load($a,$a->user['nickname']);
7         }
8
9         // These lines provide the javascript needed by the acl selector
10
11         $a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "';" ;
12
13         $a->page['htmlhead'] .= <<< EOT
14
15         $(document).ready(function() {
16
17                 $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
18                         var selstr;
19                         $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
20                                 selstr = $(this).text();
21                                 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
22                                 $('#jot-public').hide();
23                         });
24                         if(selstr == null) { 
25                                 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
26                                 $('#jot-public').show();
27                         }
28
29                 }).trigger('change');
30
31         });
32
33         </script>
34 EOT;
35
36
37 }
38
39
40 function settings_post(&$a) {
41
42         if(! local_user())
43                 return;
44
45         if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
46                 return;
47
48         if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
49                 notice( t('Permission denied.') . EOL);
50                 return;
51         }
52
53         $old_page_flags = $a->user['page-flags'];
54
55         if(($a->argc > 1) && ($a->argv[1] === 'oauth') && x($_POST,'remove')){
56                 $key = $_POST['remove'];
57                 q("DELETE FROM tokens WHERE id='%s' AND uid=%d",
58                         dbesc($key),
59                         local_user());
60                 goaway($a->get_baseurl()."/settings/oauth/");
61                 return;                 
62         }
63
64         if(($a->argc > 2) && ($a->argv[1] === 'oauth')  && ($a->argv[2] === 'edit'||($a->argv[2] === 'add')) && x($_POST,'submit')) {
65                 
66                 $name           = ((x($_POST,'name')) ? $_POST['name'] : '');
67                 $key            = ((x($_POST,'key')) ? $_POST['key'] : '');
68                 $secret         = ((x($_POST,'secret')) ? $_POST['secret'] : '');
69                 $redirect       = ((x($_POST,'redirect')) ? $_POST['redirect'] : '');
70                 $icon           = ((x($_POST,'icon')) ? $_POST['icon'] : '');
71                 if ($name=="" || $key=="" || $secret==""){
72                         notice(t("Missing some important data!"));
73                         
74                 } else {
75                         if ($_POST['submit']==t("Update")){
76                                 $r = q("UPDATE clients SET
77                                                         client_id='%s',
78                                                         pw='%s',
79                                                         name='%s',
80                                                         redirect_uri='%s',
81                                                         icon='%s',
82                                                         uid=%d
83                                                 WHERE client_id='%s'",
84                                                 dbesc($key),
85                                                 dbesc($secret),
86                                                 dbesc($name),
87                                                 dbesc($redirect),
88                                                 dbesc($icon),
89                                                 local_user(),
90                                                 dbesc($key));
91                         } else {
92                                 $r = q("INSERT INTO clients
93                                                         (client_id, pw, name, redirect_uri, icon, uid)
94                                                 VALUES ('%s','%s','%s','%s','%s',%d)",
95                                                 dbesc($key),
96                                                 dbesc($secret),
97                                                 dbesc($name),
98                                                 dbesc($redirect),
99                                                 dbesc($icon),
100                                                 local_user());
101                         }
102                 }
103                 goaway($a->get_baseurl()."/settings/oauth/");
104                 return;
105         }
106
107         if(($a->argc > 1) && ($a->argv[1] == 'addon')) {
108                 call_hooks('plugin_settings_post', $_POST);
109                 return;
110         }
111
112         if(($a->argc > 1) && ($a->argv[1] == 'connectors')) {
113
114                 if(x($_POST['imap-submit'])) {
115                         $mail_server       = ((x($_POST,'mail_server')) ? $_POST['mail_server'] : '');
116                         $mail_port         = ((x($_POST,'mail_port')) ? $_POST['mail_port'] : '');
117                         $mail_ssl          = ((x($_POST,'mail_ssl')) ? strtolower(trim($_POST['mail_ssl'])) : '');
118                         $mail_user         = ((x($_POST,'mail_user')) ? $_POST['mail_user'] : '');
119                         $mail_pass         = ((x($_POST,'mail_pass')) ? trim($_POST['mail_pass']) : '');
120                         $mail_action       = ((x($_POST,'mail_action')) ? trim($_POST['mail_action']) : '');
121                         $mail_movetofolder = ((x($_POST,'mail_movetofolder')) ? trim($_POST['mail_movetofolder']) : '');
122                         $mail_replyto      = ((x($_POST,'mail_replyto')) ? $_POST['mail_replyto'] : '');
123                         $mail_pubmail      = ((x($_POST,'mail_pubmail')) ? $_POST['mail_pubmail'] : '');
124
125
126                         $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
127                         if(get_config('system','dfrn_only'))
128                                 $mail_disabled = 1;
129
130                         if(! $mail_disabled) {
131                                 $failed = false;
132                                 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
133                                         intval(local_user())
134                                 );
135                                 if(! count($r)) {
136                                         q("INSERT INTO `mailacct` (`uid`) VALUES (%d)",
137                                                 intval(local_user())
138                                         );
139                                 }
140                                 if(strlen($mail_pass)) {
141                                         $pass = '';
142                                         openssl_public_encrypt($mail_pass,$pass,$a->user['pubkey']);
143                                         q("UPDATE `mailacct` SET `pass` = '%s' WHERE `uid` = %d LIMIT 1",
144                                                 dbesc(bin2hex($pass)),
145                                                 intval(local_user())
146                                         );
147                                 }
148                                 $r = q("UPDATE `mailacct` SET `server` = '%s', `port` = %d, `ssltype` = '%s', `user` = '%s',
149                                         `action` = %d, `movetofolder` = '%s',
150                                         `mailbox` = 'INBOX', `reply_to` = '%s', `pubmail` = %d WHERE `uid` = %d LIMIT 1",
151                                         dbesc($mail_server),
152                                         intval($mail_port),
153                                         dbesc($mail_ssl),
154                                         dbesc($mail_user),
155                                         intval($mail_action),
156                                         dbesc($mail_movetofolder),
157                                         dbesc($mail_replyto),
158                                         intval($mail_pubmail),
159                                         intval(local_user())
160                                 );
161                                 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
162                                         intval(local_user())
163                                 );
164                                 if(count($r)) {
165                                         $eacct = $r[0];
166                                         require_once('include/email.php');
167                                         $mb = construct_mailbox_name($eacct);
168                                         if(strlen($eacct['server'])) {
169                                                 $dcrpass = '';
170                                                 openssl_private_decrypt(hex2bin($eacct['pass']),$dcrpass,$a->user['prvkey']);
171                                                 $mbox = email_connect($mb,$mail_user,$dcrpass);
172                                                 unset($dcrpass);
173                                                 if(! $mbox) {
174                                                         $failed = true;
175                                                         notice( t('Failed to connect with email account using the settings provided.') . EOL);
176                                                 }
177                                         }
178                                 }
179                                 if(! $failed)
180                                         info( t('Email settings updated.') . EOL);
181                         }
182                 }
183
184                 call_hooks('connector_settings_post', $_POST);
185                 return;
186         }
187
188
189         call_hooks('settings_post', $_POST);
190
191         if((x($_POST,'npassword')) || (x($_POST,'confirm'))) {
192
193                 $newpass = $_POST['npassword'];
194                 $confirm = $_POST['confirm'];
195
196                 $err = false;
197                 if($newpass != $confirm ) {
198                         notice( t('Passwords do not match. Password unchanged.') . EOL);
199                         $err = true;
200                 }
201
202                 if((! x($newpass)) || (! x($confirm))) {
203                         notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
204                         $err = true;
205                 }
206
207                 if(! $err) {
208                         $password = hash('whirlpool',$newpass);
209                         $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d LIMIT 1",
210                                 dbesc($password),
211                                 intval(local_user())
212                         );
213                         if($r)
214                                 info( t('Password changed.') . EOL);
215                         else
216                                 notice( t('Password update failed. Please try again.') . EOL);
217                 }
218         }
219
220         $theme            = ((x($_POST,'theme'))      ? notags(trim($_POST['theme']))        : $a->user['theme']);
221         $username         = ((x($_POST,'username'))   ? notags(trim($_POST['username']))     : '');
222         $email            = ((x($_POST,'email'))      ? notags(trim($_POST['email']))        : '');
223         $timezone         = ((x($_POST,'timezone'))   ? notags(trim($_POST['timezone']))     : '');
224         $defloc           = ((x($_POST,'defloc'))     ? notags(trim($_POST['defloc']))       : '');
225         $openid           = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url']))   : '');
226         $maxreq           = ((x($_POST,'maxreq'))     ? intval($_POST['maxreq'])             : 0);
227         $expire           = ((x($_POST,'expire'))     ? intval($_POST['expire'])             : 0);
228
229
230         $expire_items     = ((x($_POST,'expire_items')) ? intval($_POST['expire_items'])         : 0);
231         $expire_notes     = ((x($_POST,'expire_notes')) ? intval($_POST['expire_notes'])         : 0);
232         $expire_starred   = ((x($_POST,'expire_starred')) ? intval($_POST['expire_starred']) : 0);
233         $expire_photos    = ((x($_POST,'expire_photos'))? intval($_POST['expire_photos'])        : 0);
234
235         $browser_update   = ((x($_POST,'browser_update')) ? intval($_POST['browser_update']) : 0);
236         $browser_update   = $browser_update * 1000;
237         if($browser_update < 10000)
238                 $browser_update = 40000;
239
240
241         $allow_location   = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
242         $publish          = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
243         $net_publish      = (((x($_POST,'profile_in_netdirectory')) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
244         $old_visibility   = (((x($_POST,'visibility')) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
245         $page_flags       = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
246         $blockwall        = (((x($_POST,'blockwall')) && (intval($_POST['blockwall']) == 1)) ? 0: 1); // this setting is inverted!
247         $blocktags        = (((x($_POST,'blocktags')) && (intval($_POST['blocktags']) == 1)) ? 0: 1); // this setting is inverted!
248
249         $suggestme        = ((x($_POST,'suggestme')) ? intval($_POST['suggestme'])  : 0);  
250         $hide_friends     = (($_POST['hide-friends'] == 1) ? 1: 0);
251         $hidewall         = (($_POST['hidewall'] == 1) ? 1: 0);
252
253
254         $notify = 0;
255
256         if(x($_POST,'notify1'))
257                 $notify += intval($_POST['notify1']);
258         if(x($_POST,'notify2'))
259                 $notify += intval($_POST['notify2']);
260         if(x($_POST,'notify3'))
261                 $notify += intval($_POST['notify3']);
262         if(x($_POST,'notify4'))
263                 $notify += intval($_POST['notify4']);
264         if(x($_POST,'notify5'))
265                 $notify += intval($_POST['notify5']);
266         if(x($_POST,'notify6'))
267                 $notify += intval($_POST['notify6']);
268         if(x($_POST,'notify7'))
269                 $notify += intval($_POST['notify7']);
270
271         $email_changed = false;
272
273         $err = '';
274
275         $name_change = false;
276
277         if($username != $a->user['username']) {
278                 $name_change = true;
279                 if(strlen($username) > 40)
280                         $err .= t(' Please use a shorter name.');
281                 if(strlen($username) < 3)
282                         $err .= t(' Name too short.');
283         }
284
285         if($email != $a->user['email']) {
286                 $email_changed = true;
287         if(! valid_email($email))
288                         $err .= t(' Not valid email.');
289                 if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) {
290                         $err .= t(' Cannot change to that email.');
291                         $email = $a->user['email'];
292                 }
293         }
294
295         if(strlen($err)) {
296                 notice($err . EOL);
297                 return;
298         }
299
300         if($timezone != $a->user['timezone']) {
301                 if(strlen($timezone))
302                         date_default_timezone_set($timezone);
303         }
304
305         $str_group_allow   = perms2str($_POST['group_allow']);
306         $str_contact_allow = perms2str($_POST['contact_allow']);
307         $str_group_deny    = perms2str($_POST['group_deny']);
308         $str_contact_deny  = perms2str($_POST['contact_deny']);
309
310         $openidserver = $a->user['openidserver'];
311
312         // If openid has changed or if there's an openid but no openidserver, try and discover it.
313
314         if($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) {
315                 $tmp_str = $openid;
316                 if(strlen($tmp_str) && validate_url($tmp_str)) {
317                         logger('updating openidserver');
318                         require_once('library/openid.php');
319                         $open_id_obj = new LightOpenID;
320                         $open_id_obj->identity = $openid;
321                         $openidserver = $open_id_obj->discover($open_id_obj->identity);
322                 }
323                 else
324                         $openidserver = '';
325         }
326
327         set_pconfig(local_user(),'expire','items', $expire_items);
328         set_pconfig(local_user(),'expire','notes', $expire_notes);
329         set_pconfig(local_user(),'expire','starred', $expire_starred);
330         set_pconfig(local_user(),'expire','photos', $expire_photos);
331
332         set_pconfig(local_user(),'system','suggestme', $suggestme);
333         set_pconfig(local_user(),'system','update_interval', $browser_update);
334
335         $r = q("UPDATE `user` SET `username` = '%s', `email` = '%s', `openid` = '%s', `timezone` = '%s',  `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `notify-flags` = %d, `page-flags` = %d, `default-location` = '%s', `allow_location` = %d, `theme` = '%s', `maxreq` = %d, `expire` = %d, `openidserver` = '%s', `blockwall` = %d, `hidewall` = %d, `blocktags` = %d  WHERE `uid` = %d LIMIT 1",
336                         dbesc($username),
337                         dbesc($email),
338                         dbesc($openid),
339                         dbesc($timezone),
340                         dbesc($str_contact_allow),
341                         dbesc($str_group_allow),
342                         dbesc($str_contact_deny),
343                         dbesc($str_group_deny),
344                         intval($notify),
345                         intval($page_flags),
346                         dbesc($defloc),
347                         intval($allow_location),
348                         dbesc($theme),
349                         intval($maxreq),
350                         intval($expire),
351                         dbesc($openidserver),
352                         intval($blockwall),
353                         intval($hidewall),
354                         intval($blocktags),
355                         intval(local_user())
356         );
357         if($r)
358                 info( t('Settings updated.') . EOL);
359
360         $r = q("UPDATE `profile` 
361                 SET `publish` = %d, 
362                 `net-publish` = %d,
363                 `hide-friends` = %d
364                 WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
365                 intval($publish),
366                 intval($net_publish),
367                 intval($hide_friends),
368                 intval(local_user())
369         );
370
371
372         if($name_change) {
373                 q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self` = 1 LIMIT 1",
374                         dbesc($username),
375                         dbesc(datetime_convert()),
376                         intval(local_user())
377                 );
378         }               
379
380         if(($old_visibility != $net_publish) || ($page_flags != $old_page_flags)) {
381                 // Update global directory in background
382                 $url = $_SESSION['my_url'];
383                 if($url && strlen(get_config('system','directory_submit_url')))
384                         proc_run('php',"include/directory.php","$url");
385
386         }
387
388
389         require_once('include/profile_update.php');
390         profile_change();
391
392         $_SESSION['theme'] = $theme;
393         if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
394
395                 // FIXME - set to un-verified, blocked and redirect to logout
396
397         }
398
399         goaway($a->get_baseurl() . '/settings' );
400         return; // NOTREACHED
401 }
402                 
403
404 if(! function_exists('settings_content')) {
405 function settings_content(&$a) {
406
407         $o = '';
408         nav_set_selected('settings');
409
410         if(! local_user()) {
411                 notice( t('Permission denied.') . EOL );
412                 return;
413         }
414
415         if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
416                 notice( t('Permission denied.') . EOL );
417                 return;
418         }
419         
420         $tabs = array(
421                 array(
422                         'label' => t('Account settings'),
423                         'url'   => $a->get_baseurl().'/settings',
424                         'sel'   => (($a->argc == 1)?'active':''),
425                 ),      
426                 array(
427                         'label' => t('Connector settings'),
428                         'url'   => $a->get_baseurl().'/settings/connectors',
429                         'sel'   => (($a->argc > 1) && ($a->argv[1] === 'connectors')?'active':''),
430                 ),
431                 array(
432                         'label' => t('Plugin settings'),
433                         'url'   => $a->get_baseurl().'/settings/addon',
434                         'sel'   => (($a->argc > 1) && ($a->argv[1] === 'addon')?'active':''),
435                 ),
436                 array(
437                         'label' => t('Connections'),
438                         'url' => $a->get_baseurl() . '/settings/oauth',
439                         'sel' => (($a->argc > 1) && ($a->argv[1] === 'oauth')?'active':''),
440                 ),
441                 array(
442                         'label' => t('Export personal data'),
443                         'url' => $a->get_baseurl() . '/uexport',
444                         'sel' => ''
445                 )
446         );
447         
448         $tabtpl = get_markup_template("common_tabs.tpl");
449         $tabs = replace_macros($tabtpl, array(
450                 '$tabs' => $tabs,
451         ));
452                 
453         if(($a->argc > 1) && ($a->argv[1] === 'oauth')) {
454                 
455                 if(($a->argc > 2) && ($a->argv[2] === 'add')) {
456                         $tpl = get_markup_template("settings_oauth_edit.tpl");
457                         $o .= replace_macros($tpl, array(
458                                 '$tabs'         => $tabs,
459                                 '$title'        => t('Add application'),
460                                 '$submit'       => t('Submit'),
461                                 '$cancel'       => t('Cancel'),
462                                 '$name'         => array('name', t('Name'), '', ''),
463                                 '$key'          => array('key', t('Consumer Key'), '', ''),
464                                 '$secret'       => array('secret', t('Consumer Secret'), '', ''),
465                                 '$redirect'     => array('redirect', t('Redirect'), '', ''),
466                                 '$icon'         => array('icon', t('Icon url'), '', ''),
467                         ));
468                         return $o;
469                 }
470                 
471                 if(($a->argc > 3) && ($a->argv[2] === 'edit')) {
472                         $r = q("SELECT * FROM clients WHERE client_id='%s' AND uid=%d",
473                                         dbesc($a->argv[3]),
474                                         local_user());
475                         
476                         if (!count($r)){
477                                 notice(t("You can't edit this application."));
478                                 return;
479                         }
480                         $app = $r[0];
481                         
482                         $tpl = get_markup_template("settings_oauth_edit.tpl");
483                         $o .= replace_macros($tpl, array(
484                                 '$tabs'         => $tabs,
485                                 '$title'        => t('Add application'),
486                                 '$submit'       => t('Update'),
487                                 '$cancel'       => t('Cancel'),
488                                 '$name'         => array('name', t('Name'), $app['name'] , ''),
489                                 '$key'          => array('key', t('Consumer Key'), $app['client_id'], ''),
490                                 '$secret'       => array('secret', t('Consumer Secret'), $app['pw'], ''),
491                                 '$redirect'     => array('redirect', t('Redirect'), $app['redirect_uri'], ''),
492                                 '$icon'         => array('icon', t('Icon url'), $app['icon'], ''),
493                         ));
494                         return $o;
495                 }
496                 
497                 if(($a->argc > 3) && ($a->argv[2] === 'delete')) {
498                         $r = q("DELETE FROM clients WHERE client_id='%s' AND uid=%d",
499                                         dbesc($a->argv[3]),
500                                         local_user());
501                         goaway($a->get_baseurl()."/settings/oauth/");
502                         return;                 
503                 }
504                 
505                 
506                 $r = q("SELECT clients.*, tokens.id as oauth_token, (clients.uid=%d) AS my 
507                                 FROM clients
508                                 LEFT JOIN tokens ON clients.client_id=tokens.client_id
509                                 WHERE clients.uid IN (%d,0)",
510                                 local_user(),
511                                 local_user());
512                 
513                 
514                 $tpl = get_markup_template("settings_oauth.tpl");
515                 $o .= replace_macros($tpl, array(
516                         '$baseurl'      => $a->get_baseurl(),
517                         '$title'        => t('Connected Apps'),
518                         '$add'          => t('Add application'),
519                         '$edit'         => t('Edit'),
520                         '$delete'               => t('Delete'),
521                         '$consumerkey' => t('Client key starts with'),
522                         '$noname'       => t('No name'),
523                         '$remove'       => t('Remove authorization'),
524                         '$tabs'         => $tabs,
525                         '$apps'         => $r,
526                 ));
527                 return $o;
528                 
529         }
530         if(($a->argc > 1) && ($a->argv[1] === 'addon')) {
531                 $settings_addons = "";
532                 
533                 $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
534                 if(! count($r))
535                         $settings_addons = t('No Plugin settings configured');
536
537                 call_hooks('plugin_settings', $settings_addons);
538                 
539                 
540                 $tpl = get_markup_template("settings_addons.tpl");
541                 $o .= replace_macros($tpl, array(
542                         '$title'        => t('Plugin Settings'),
543                         '$tabs'         => $tabs,
544                         '$settings_addons' => $settings_addons
545                 ));
546                 return $o;
547         }
548
549         if(($a->argc > 1) && ($a->argv[1] === 'connectors')) {
550
551                 $settings_connectors = "";
552                 
553                 call_hooks('connector_settings', $settings_connectors);
554
555                 $diasp_enabled = sprintf( t('Built-in support for %s connectivity is %s'), t('Diaspora'), ((get_config('system','diaspora_enabled')) ? t('enabled') : t('disabled')));
556                 $ostat_enabled = sprintf( t('Built-in support for %s connectivity is %s'), t('StatusNet'), ((get_config('system','ostatus_disabled')) ? t('disabled') : t('enabled')));
557
558         $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
559         if(get_config('system','dfrn_only'))
560                 $mail_disabled = 1;
561
562         if(! $mail_disabled) {
563                 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
564                         local_user()
565                 );
566         }
567         else {
568                 $r = null;
569         }
570
571         $mail_server       = ((count($r)) ? $r[0]['server'] : '');
572         $mail_port         = ((count($r) && intval($r[0]['port'])) ? intval($r[0]['port']) : '');
573         $mail_ssl          = ((count($r)) ? $r[0]['ssltype'] : '');
574         $mail_user         = ((count($r)) ? $r[0]['user'] : '');
575         $mail_replyto      = ((count($r)) ? $r[0]['reply_to'] : '');
576         $mail_pubmail      = ((count($r)) ? $r[0]['pubmail'] : 0);
577         $mail_action       = ((count($r)) ? $r[0]['action'] : 0);
578         $mail_movetofolder = ((count($r)) ? $r[0]['movetofolder'] : '');
579         $mail_chk          = ((count($r)) ? $r[0]['last_check'] : '0000-00-00 00:00:00');
580
581
582         $tpl = get_markup_template("settings_connectors.tpl");
583                 $o .= replace_macros($tpl, array(
584                         '$title'        => t('Connector Settings'),
585                         '$tabs'         => $tabs,
586
587                 '$diasp_enabled' => $diasp_enabled,
588                 '$ostat_enabled' => $ostat_enabled,
589
590                 '$h_imap' => t('Email/Mailbox Setup'),
591                 '$imap_desc' => t("If you wish to communicate with email contacts using this service \x28optional\x29, please specify how to connect to your mailbox."),
592                 '$imap_lastcheck' => array('imap_lastcheck', t('Last successful email check:'), $mail_chk,''),
593                 '$mail_disabled' => (($mail_disabled) ? t('Email access is disabled on this site.') : ''),
594                 '$mail_server'  => array('mail_server',  t('IMAP server name:'), $mail_server, ''),
595                 '$mail_port'    => array('mail_port',    t('IMAP port:'), $mail_port, ''),
596                 '$mail_ssl'             => array('mail_ssl',     t('Security:'), strtoupper($mail_ssl), '', array( ''=>t('None'), 'TLS'=>'TLS', 'SSL'=>'SSL')),
597                 '$mail_user'    => array('mail_user',    t('Email login name:'), $mail_user, ''),
598                 '$mail_pass'    => array('mail_pass',    t('Email password:'), '', ''),
599                 '$mail_replyto' => array('mail_replyto', t('Reply-to address:'), '', 'Optional'),
600                 '$mail_pubmail' => array('mail_pubmail', t('Send public posts to all email contacts:'), $mail_pubmail, ''),
601                 '$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'))),
602                 '$mail_movetofolder'    => array('mail_movetofolder',    t('Move to folder:'), $mail_movetofolder, ''),
603                 '$submit' => t('Submit'),
604
605
606
607                         '$settings_connectors' => $settings_connectors
608                 ));
609                 return $o;
610         }
611
612
613         require_once('include/acl_selectors.php');
614
615         $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
616                 intval(local_user())
617         );
618         if(count($p))
619                 $profile = $p[0];
620
621         $username = $a->user['username'];
622         $email    = $a->user['email'];
623         $nickname = $a->user['nickname'];
624         $timezone = $a->user['timezone'];
625         $notify   = $a->user['notify-flags'];
626         $defloc   = $a->user['default-location'];
627         $openid   = $a->user['openid'];
628         $maxreq   = $a->user['maxreq'];
629         $expire   = ((intval($a->user['expire'])) ? $a->user['expire'] : '');
630         $blockwall = $a->user['blockwall'];
631         $blocktags = $a->user['blocktags'];
632
633         $expire_items = get_pconfig(local_user(), 'expire','items');
634         $expire_items = (($expire_items===false)?1:$expire_items); // default if not set: 1
635         
636         $expire_notes = get_pconfig(local_user(), 'expire','notes');
637         $expire_notes = (($expire_notes===false)?1:$expire_notes); // default if not set: 1
638
639         $expire_starred = get_pconfig(local_user(), 'expire','starred');
640         $expire_starred = (($expire_starred===false)?1:$expire_starred); // default if not set: 1
641         
642         $expire_photos = get_pconfig(local_user(), 'expire','photos');
643         $expire_photos = (($expire_photos===false)?0:$expire_photos); // default if not set: 0
644
645
646         $suggestme = get_pconfig(local_user(), 'system','suggestme');
647         $suggestme = (($suggestme===false)?0:$suggestme); // default if not set: 0
648
649         $browser_update = intval(get_pconfig(local_user(), 'system','update_interval'));
650         $browser_update = (($browser_update == 0) ? 40 : $browser_update / 1000); // default if not set: 40 seconds
651         
652         if(! strlen($a->user['timezone']))
653                 $timezone = date_default_timezone_get();
654
655
656
657         $pageset_tpl = get_markup_template('pagetypes.tpl');
658         $pagetype = replace_macros($pageset_tpl,array(
659                 '$page_normal'  => array('page-flags', t('Normal Account'), PAGE_NORMAL, 
660                                                                         t('This account is a normal personal profile'), 
661                                                                         ($a->user['page-flags'] == PAGE_NORMAL)),
662                                                                 
663                 '$page_soapbox'         => array('page-flags', t('Soapbox Account'), PAGE_SOAPBOX, 
664                                                                         t('Automatically approve all connection/friend requests as read-only fans'), 
665                                                                         ($a->user['page-flags'] == PAGE_SOAPBOX)),
666                                                                         
667                 '$page_community'       => array('page-flags', t('Community/Celebrity Account'), PAGE_COMMUNITY, 
668                                                                         t('Automatically approve all connection/friend requests as read-write fans'), 
669                                                                         ($a->user['page-flags'] == PAGE_COMMUNITY)),
670                                                                         
671                 '$page_freelove'        => array('page-flags', t('Automatic Friend Account'), PAGE_FREELOVE, 
672                                                                         t('Automatically approve all connection/friend requests as friends'), 
673                                                                         ($a->user['page-flags'] == PAGE_FREELOVE)),
674         ));
675
676         $noid = get_config('system','no_openid');
677
678         if($noid) {
679                 $openid_field = false;
680         }
681         else {
682                 $openid_field = array('openid_url', t('OpenID:'),$openid, t("\x28Optional\x29 Allow this OpenID to login to this account."));
683         }
684
685
686         $opt_tpl = get_markup_template("field_yesno.tpl");
687         if(get_config('system','publish_all')) {
688                 $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
689         }
690         else {
691                 $profile_in_dir = replace_macros($opt_tpl,array(
692                         '$field'        => array('profile_in_directory', t('Publish your default profile in your local site directory?'), $profile['publish'], '', array(t('No'),t('Yes'))),
693                 ));
694         }
695
696         if(strlen(get_config('system','directory_submit_url'))) {
697                 $profile_in_net_dir = replace_macros($opt_tpl,array(
698                         '$field'        => array('profile_in_netdirectory', t('Publish your default profile in the global social directory?'), $profile['net-publish'], '', array(t('No'),t('Yes'))),
699                 ));
700         }
701         else
702                 $profile_in_net_dir = '';
703
704
705         $hide_friends = replace_macros($opt_tpl,array(
706                         '$field'        => array('hide-friends', t('Hide your contact/friend list from viewers of your default profile?'), $profile['hide-friends'], '', array(t('No'),t('Yes'))),
707         ));
708
709         $hide_wall = replace_macros($opt_tpl,array(
710                         '$field'        => array('hidewall',  t('Hide your profile details from unknown viewers?'), $a->user['hidewall'], '', array(t('No'),t('Yes'))),
711
712         ));
713
714         $blockwall = replace_macros($opt_tpl,array(
715                         '$field'        => array('blockwall',  t('Allow friends to post to your profile page?'), ! $a->user['blockwall'], '', array(t('No'),t('Yes'))),
716
717         ));
718  
719
720         $blocktags = replace_macros($opt_tpl,array(
721                         '$field'        => array('blocktags',  t('Allow friends to tag your posts?'), ! $a->user['blocktags'], '', array(t('No'),t('Yes'))),
722
723         ));
724
725
726         $suggestme = replace_macros($opt_tpl,array(
727                         '$field'        => array('suggestme',  t('Allow us to suggest you as a potential friend to new members?'), $suggestme, '', array(t('No'),t('Yes'))),
728
729         ));
730
731
732         $invisible = (((! $profile['publish']) && (! $profile['net-publish']))
733                 ? true : false);
734
735         if($invisible)
736                 info( t('Profile is <strong>not published</strong>.') . EOL );
737
738         
739         $default_theme = get_config('system','theme');
740         if(! $default_theme)
741                 $default_theme = 'default';
742
743         $allowed_themes_str = get_config('system','allowed_themes');
744         $allowed_themes_raw = explode(',',$allowed_themes_str);
745         $allowed_themes = array();
746         if(count($allowed_themes_raw))
747                 foreach($allowed_themes_raw as $x)
748                         if(strlen(trim($x)))
749                                 $allowed_themes[] = trim($x);
750
751         
752         $themes = array();
753         $files = glob('view/theme/*');
754         if($allowed_themes) {
755                 foreach($allowed_themes as $th) {
756                         $f = $th;
757                         $is_experimental = file_exists('view/theme/' . $th . '/experimental');
758                         $unsupported = file_exists('view/theme/' . $th . '/unsupported');
759                         if (!$is_experimental or ($is_experimental && (get_config('experimentals','exp_themes')==1 or get_config('experimentals','exp_themes')===false))){ 
760                                 $theme_name = (($is_experimental) ?  sprintf("%s - \x28Experimental\x29", $f) : $f);
761                                 $themes[$f]=$theme_name;
762                         }
763                 }
764         }
765         $theme_selected = (!x($_SESSION,'theme')? $default_theme : $_SESSION['theme']);
766
767
768         $subdir = ((strlen($a->get_path())) ? '<br />' . t('or') . ' ' . $a->get_baseurl() . '/profile/' . $nickname : '');
769
770         $tpl_addr = get_markup_template("settings_nick_set.tpl");
771
772         $prof_addr = replace_macros($tpl_addr,array(
773                 '$desc' => t('Your Identity Address is'),
774                 '$nickname' => $nickname,
775                 '$subdir' => $subdir,
776                 '$basepath' => $a->get_hostname()
777         ));
778
779         $stpl = get_markup_template('settings.tpl');
780
781         $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
782
783         $expire_arr = array(
784                 'days' => array('expire',  t("Automatically expire posts after this many days:"), $expire, t('If empty, posts will not expire. Expired posts will be deleted')),
785                 'advanced' => t('Advanced expiration settings'),
786                 'label' => t('Advanced Expiration'),
787                 'items' => array('expire_items',  t("Expire posts:"), $expire_items, '', array(t('No'),t('Yes'))),
788                 'notes' => array('expire_notes',  t("Expire personal notes:"), $expire_notes, '', array(t('No'),t('Yes'))),
789                 'starred' => array('expire_starred',  t("Expire starred posts:"), $expire_starred, '', array(t('No'),t('Yes'))),
790                 'photos' => array('expire_photos',  t("Expire photos:"), $expire_photos, '', array(t('No'),t('Yes'))),          
791         );
792
793         $o .= replace_macros($stpl,array(
794                 '$tabs'         => $tabs,
795                 '$ptitle'       => t('Account Settings'),
796
797                 '$submit'       => t('Submit'),
798                 '$baseurl' => $a->get_baseurl(),
799                 '$uid' => local_user(),
800                 
801                 '$nickname_block' => $prof_addr,
802                 
803                 '$h_pass'       => t('Password Settings'),
804                 '$password1'=> array('npassword', t('New Password:'), '', ''),
805                 '$password2'=> array('confirm', t('Confirm:'), '', t('Leave password fields blank unless changing')),
806                 '$oid_enable' => (! get_config('system','no_openid')),
807                 '$openid'       => $openid_field,
808                 
809                 '$h_basic'      => t('Basic Settings'),
810                 '$username' => array('username',  t('Full Name:'), $username,''),
811                 '$email'        => array('email', t('Email Address:'), $email, ''),
812                 '$timezone' => array('timezone_select' , t('Your Timezone:'), select_timezone($timezone), ''),
813                 '$defloc'       => array('defloc', t('Default Post Location:'), $defloc, ''),
814                 '$allowloc' => array('allow_location', t('Use Browser Location:'), ($a->user['allow_location'] == 1), ''),
815                 '$theme'        => array('theme', t('Display Theme:'), $theme_selected, '', $themes),
816                 '$ajaxint'   => array('browser_update',  t("Update browser every xx seconds"), $browser_update, t('Minimum of 10 seconds, no maximum')),
817
818                 '$h_prv'        => t('Security and Privacy Settings'),
819
820                 '$maxreq'       => array('maxreq', t('Maximum Friend Requests/Day:'), $maxreq ,t("\x28to prevent spam abuse\x29")),
821                 '$permissions' => t('Default Post Permissions'),
822                 '$permdesc' => t("\x28click to open/close\x29"),
823                 '$visibility' => $profile['net-publish'],
824                 '$aclselect' => populate_acl($a->user,$celeb),
825                 '$suggestme' => $suggestme,
826                 '$blockwall'=> $blockwall, // array('blockwall', t('Allow friends to post to your profile page:'), !$blockwall, ''),
827                 '$blocktags'=> $blocktags, // array('blocktags', t('Allow friends to tag your posts:'), !$blocktags, ''),
828                 '$expire'       => $expire_arr,
829
830                 '$profile_in_dir' => $profile_in_dir,
831                 '$profile_in_net_dir' => $profile_in_net_dir,
832                 '$hide_friends' => $hide_friends,
833                 '$hide_wall' => $hide_wall,
834                 
835                 
836                 
837                 '$h_not'        => t('Notification Settings'),
838                 '$lbl_not'      => t('Send a notification email when:'),
839                 '$notify1'      => array('notify1', t('You receive an introduction'), ($notify & NOTIFY_INTRO), NOTIFY_INTRO, ''),
840                 '$notify2'      => array('notify2', t('Your introductions are confirmed'), ($notify & NOTIFY_CONFIRM), NOTIFY_CONFIRM, ''),
841                 '$notify3'      => array('notify3', t('Someone writes on your profile wall'), ($notify & NOTIFY_WALL), NOTIFY_WALL, ''),
842                 '$notify4'      => array('notify4', t('Someone writes a followup comment'), ($notify & NOTIFY_COMMENT), NOTIFY_COMMENT, ''),
843                 '$notify5'      => array('notify5', t('You receive a private message'), ($notify & NOTIFY_MAIL), NOTIFY_MAIL, ''),
844                 '$notify6'  => array('notify6', t('You receive a friend suggestion'), ($notify & NOTIFY_SUGGEST), NOTIFY_SUGGEST, ''),          
845                 '$notify7'  => array('notify7', t('You are tagged in a post'), ($notify & NOTIFY_TAGSELF), NOTIFY_TAGSELF, ''),         
846                 
847                 
848                 '$h_advn' => t('Advanced Page Settings'),
849                 '$pagetype' => $pagetype,
850                 
851
852                 
853                 
854
855                 
856
857
858
859
860                 
861
862         ));
863
864         call_hooks('settings_form',$o);
865
866         $o .= '</form>' . "\r\n";
867
868         return $o;
869
870 }}
871