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