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