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