]> git.mxchange.org Git - friendica.git/blob - src/Module/Settings/Account.php
Merge pull request #12020 from annando/no-boot
[friendica.git] / src / Module / Settings / Account.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Settings;
23
24 use Exception;
25 use Friendica\Core\ACL;
26 use Friendica\Core\Logger;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Search;
29 use Friendica\Core\Worker;
30 use Friendica\Database\DBA;
31 use Friendica\DI;
32 use Friendica\Model\Group;
33 use Friendica\Model\Notification;
34 use Friendica\Model\Post\UserNotification;
35 use Friendica\Model\Profile;
36 use Friendica\Model\User;
37 use Friendica\Model\Verb;
38 use Friendica\Module\BaseSettings;
39 use Friendica\Network\HTTPException;
40 use Friendica\Protocol\Activity;
41 use Friendica\Util\Network;
42 use Friendica\Util\Temporal;
43 use Friendica\Worker\Delivery;
44
45 class Account extends BaseSettings
46 {
47         protected function post(array $request = [])
48         {
49                 if (!DI::app()->isLoggedIn()) {
50                         throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
51                 }
52
53                 $redirectUrl = '/settings' . (isset($this->parameters['open']) ? '/account/' . $this->parameters['open'] : '');
54
55                 self::checkFormSecurityTokenRedirectOnError($redirectUrl, 'settings');
56
57                 $a = DI::app();
58
59                 $user = User::getById($a->getLoggedInUserId());
60
61                 if (!empty($request['password-submit'])) {
62                         $newpass = $request['password'];
63                         $confirm = $request['confirm'];
64
65                         try {
66                                 if ($newpass != $confirm) {
67                                         throw new Exception(DI::l10n()->t('Passwords do not match.'));
68                                 }
69
70                                 //  check if the old password was supplied correctly before changing it to the new value
71                                 User::getIdFromPasswordAuthentication(local_user(), $request['opassword']);
72
73                                 $result = User::updatePassword(local_user(), $newpass);
74                                 if (!DBA::isResult($result)) {
75                                         throw new Exception(DI::l10n()->t('Password update failed. Please try again.'));
76                                 }
77
78                                 DI::sysmsg()->addInfo(DI::l10n()->t('Password changed.'));
79                         } catch (Exception $e) {
80                                 DI::sysmsg()->addNotice($e->getMessage());
81                                 DI::sysmsg()->addNotice(DI::l10n()->t('Password unchanged.'));
82                         }
83
84                         DI::baseUrl()->redirect($redirectUrl);
85                 }
86
87                 if (!empty($request['basic-submit'])) {
88                         $username = trim($request['username'] ?? '');
89                         $email    = trim($request['email'] ?? '');
90                         $timezone = trim($request['timezone'] ?? '');
91
92
93                         $err = '';
94                         if ($username != $user['username']) {
95                                 if (strlen($username) > 40) {
96                                         $err .= DI::l10n()->t('Please use a shorter name.');
97                                 }
98                                 if (strlen($username) < 3) {
99                                         $err .= DI::l10n()->t('Name too short.');
100                                 }
101                         }
102
103                         if ($email != $user['email']) {
104                                 //  check for the correct password
105                                 try {
106                                         User::getIdFromPasswordAuthentication(local_user(), $request['mpassword']);
107                                 } catch (Exception $ex) {
108                                         $err .= DI::l10n()->t('Wrong Password.');
109                                         $email = $user['email'];
110                                 }
111                                 //  check the email is valid
112                                 if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
113                                         $err .= DI::l10n()->t('Invalid email.');
114                                 }
115                                 //  ensure new email is not the admin mail
116                                 if (DI::config()->get('config', 'admin_email')) {
117                                         $adminlist = explode(",", str_replace(" ", "", strtolower(DI::config()->get('config', 'admin_email'))));
118                                         if (in_array(strtolower($email), $adminlist)) {
119                                                 $err .= DI::l10n()->t('Cannot change to that email.');
120                                                 $email = $user['email'];
121                                         }
122                                 }
123                         }
124
125                         if (strlen($err)) {
126                                 DI::sysmsg()->addNotice($err);
127                                 return;
128                         }
129
130                         if (strlen($timezone) && $timezone != $user['timezone']) {
131                                 $a->setTimeZone($timezone);
132                         }
133
134                         $fields = [
135                                 'username'         => $username,
136                                 'email'            => $email,
137                                 'timezone'         => $timezone,
138                                 'default-location' => trim($request['default_location'] ?? ''),
139                                 'allow_location'   => !empty($request['allow_location']),
140                                 'language'         => trim($request['language'] ?? ''),
141                         ];
142
143                         if (!empty($request['delete_openid'])) {
144                                 $fields['openid']       = '';
145                                 $fields['openidserver'] = '';
146                         }
147
148                         if (!User::update($fields, local_user())) {
149                                 DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
150                         }
151
152                         // clear session language
153                         unset($_SESSION['language']);
154
155                         DI::baseUrl()->redirect($redirectUrl);
156                 }
157
158                 if (!empty($request['privacy-submit'])) {
159                         $maxreq       = intval($request['maxreq'] ?? 0);
160                         $publish      = !empty($request['profile_in_directory']);
161                         $net_publish  = !empty($request['profile_in_netdirectory']);
162                         $hide_friends = !empty($request['hide-friends']);
163                         $hidewall     = !empty($request['hidewall']);
164                         $blockwall    = empty($request['blockwall']); // this setting is inverted!
165                         $blocktags    = empty($request['blocktags']); // this setting is inverted!
166                         $unkmail      = !empty($request['unkmail']);
167                         $cntunkmail   = intval($request['cntunkmail'] ?? 0);
168                         $def_gid      = intval($request['group-selection'] ?? 0);
169
170                         $aclFormatter = DI::aclFormatter();
171
172                         $str_group_allow   = !empty($request['group_allow']) ? $aclFormatter->toString($request['group_allow']) : '';
173                         $str_contact_allow = !empty($request['contact_allow']) ? $aclFormatter->toString($request['contact_allow']) : '';
174                         $str_group_deny    = !empty($request['group_deny']) ? $aclFormatter->toString($request['group_deny']) : '';
175                         $str_contact_deny  = !empty($request['contact_deny']) ? $aclFormatter->toString($request['contact_deny']) : '';
176
177                         DI::pConfig()->set(local_user(), 'system', 'unlisted', !empty($request['unlisted']));
178                         DI::pConfig()->set(local_user(), 'system', 'accessible-photos', !empty($request['accessible-photos']));
179
180                         $fields = [
181                                 'allow_cid'  => $str_contact_allow,
182                                 'allow_gid'  => $str_group_allow,
183                                 'deny_cid'   => $str_contact_deny,
184                                 'deny_gid'   => $str_group_deny,
185                                 'maxreq'     => $maxreq,
186                                 'def_gid'    => $def_gid,
187                                 'blockwall'  => $blockwall,
188                                 'hidewall'   => $hidewall,
189                                 'blocktags'  => $blocktags,
190                                 'unkmail'    => $unkmail,
191                                 'cntunkmail' => $cntunkmail,
192                         ];
193
194                         $profile_fields = [
195                                 'publish'      => $publish,
196                                 'net-publish'  => $net_publish,
197                                 'hide-friends' => $hide_friends
198                         ];
199
200                         if (!User::update($fields, local_user()) || !Profile::update($profile_fields, local_user())) {
201                                 DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
202                         }
203
204                         DI::baseUrl()->redirect($redirectUrl);
205                 }
206
207                 if (!empty($request['expire-submit'])) {
208                         $expire = intval($request['expire'] ?? 0);
209
210                         $expire_items        = !empty($request['expire_items']);
211                         $expire_notes        = !empty($request['expire_notes']);
212                         $expire_starred      = !empty($request['expire_starred']);
213                         $expire_network_only = !empty($request['expire_network_only']);
214
215                         DI::pConfig()->set(local_user(), 'expire', 'items', $expire_items);
216                         DI::pConfig()->set(local_user(), 'expire', 'notes', $expire_notes);
217                         DI::pConfig()->set(local_user(), 'expire', 'starred', $expire_starred);
218                         DI::pConfig()->set(local_user(), 'expire', 'network_only', $expire_network_only);
219
220                         if (!User::update(['expire' => $expire], local_user())) {
221                                 DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
222                         }
223
224                         DI::baseUrl()->redirect($redirectUrl);
225                 }
226
227                 if (!empty($request['notification-submit'])) {
228                         $notify = 0;
229
230                         if (!empty($request['notify1'])) {
231                                 $notify += intval($request['notify1']);
232                         }
233                         if (!empty($request['notify2'])) {
234                                 $notify += intval($request['notify2']);
235                         }
236                         if (!empty($request['notify3'])) {
237                                 $notify += intval($request['notify3']);
238                         }
239                         if (!empty($request['notify4'])) {
240                                 $notify += intval($request['notify4']);
241                         }
242                         if (!empty($request['notify5'])) {
243                                 $notify += intval($request['notify5']);
244                         }
245                         if (!empty($request['notify6'])) {
246                                 $notify += intval($request['notify6']);
247                         }
248                         if (!empty($request['notify7'])) {
249                                 $notify += intval($request['notify7']);
250                         }
251                         if (!empty($request['notify8'])) {
252                                 $notify += intval($request['notify8']);
253                         }
254
255                         $notify_like     = !empty($request['notify_like']);
256                         $notify_announce = !empty($request['notify_announce']);
257
258                         $notify_type = 0;
259
260                         if (!empty($request['notify_tagged'])) {
261                                 $notify_type = $notify_type | UserNotification::TYPE_EXPLICIT_TAGGED;
262                         }
263                         if (!empty($request['notify_direct_comment'])) {
264                                 $notify_type = $notify_type | (UserNotification::TYPE_IMPLICIT_TAGGED + UserNotification::TYPE_DIRECT_COMMENT + UserNotification::TYPE_DIRECT_THREAD_COMMENT);
265                         }
266                         if (!empty($request['notify_thread_comment'])) {
267                                 $notify_type = $notify_type | UserNotification::TYPE_THREAD_COMMENT;
268                         }
269                         if (!empty($request['notify_comment_participation'])) {
270                                 $notify_type = $notify_type | UserNotification::TYPE_COMMENT_PARTICIPATION;
271                         }
272                         if (!empty($request['notify_activity_participation'])) {
273                                 $notify_type = $notify_type | UserNotification::TYPE_ACTIVITY_PARTICIPATION;
274                         }
275                         DI::pConfig()->set(local_user(), 'system', 'notify_type', $notify_type);
276
277                         if (!($notify_type & (UserNotification::TYPE_DIRECT_COMMENT + UserNotification::TYPE_DIRECT_THREAD_COMMENT))) {
278                                 $notify_like     = false;
279                                 $notify_announce = false;
280                         }
281
282                         // Reset like notifications when they are going to be shown again
283                         if (!DI::pConfig()->get(local_user(), 'system', 'notify_like') && $notify_like) {
284                                 DI::notification()->setAllSeenForUser(local_user(), ['vid' => Verb::getID(Activity::LIKE)]);
285                         }
286
287                         DI::pConfig()->set(local_user(), 'system', 'notify_like', $notify_like);
288
289                         // Reset share notifications when they are going to be shown again
290                         if (!DI::pConfig()->get(local_user(), 'system', 'notify_announce') && $notify_announce) {
291                                 DI::notification()->setAllSeenForUser(local_user(), ['vid' => Verb::getID(Activity::ANNOUNCE)]);
292                         }
293
294                         DI::pConfig()->set(local_user(), 'system', 'notify_announce', $notify_announce);
295
296                         DI::pConfig()->set(local_user(), 'system', 'email_textonly', !empty($request['email_textonly']));
297                         DI::pConfig()->set(local_user(), 'system', 'detailed_notif', !empty($request['detailed_notif']));
298                         DI::pConfig()->set(local_user(), 'system', 'notify_ignored', !empty($request['notify_ignored']));
299
300                         $fields = [
301                                 'notify-flags' => $notify,
302                         ];
303
304                         if (!User::update($fields, local_user())) {
305                                 DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
306                         }
307
308                         DI::baseUrl()->redirect($redirectUrl);
309                 }
310
311                 if (!empty($request['advanced-submit'])) {
312                         $account_type = intval($request['account-type'] ?? 0);
313                         $page_flags   = intval($request['page-flags'] ?? 0);
314
315                         // Adjust the page flag if the account type doesn't fit to the page flag.
316                         if ($account_type == User::ACCOUNT_TYPE_PERSON && !in_array($page_flags, [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_SOAPBOX, User::PAGE_FLAGS_FREELOVE])) {
317                                 $page_flags = User::PAGE_FLAGS_NORMAL;
318                         } elseif ($account_type == User::ACCOUNT_TYPE_ORGANISATION && $page_flags != User::PAGE_FLAGS_SOAPBOX) {
319                                 $page_flags = User::PAGE_FLAGS_SOAPBOX;
320                         } elseif ($account_type == User::ACCOUNT_TYPE_NEWS && $page_flags != User::PAGE_FLAGS_SOAPBOX) {
321                                 $page_flags = User::PAGE_FLAGS_SOAPBOX;
322                         } elseif ($account_type == User::ACCOUNT_TYPE_COMMUNITY && !in_array($page_flags, [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP])) {
323                                 $page_flags = User::PAGE_FLAGS_COMMUNITY;
324                         }
325
326                         $fields         = [];
327                         $profile_fields = [];
328
329                         if ($account_type == User::ACCOUNT_TYPE_COMMUNITY) {
330                                 DI::pConfig()->set(local_user(), 'system', 'unlisted', true);
331
332                                 $fields = [
333                                         'allow_cid' => '',
334                                         'allow_gid' => $page_flags == User::PAGE_FLAGS_PRVGROUP ?
335                                                         '<' . Group::FOLLOWERS . '>'
336                                                         : '',
337                                         'deny_cid'  => '',
338                                         'deny_gid'  => '',
339                                         'blockwall' => true,
340                                         'blocktags' => true,
341                                 ];
342
343                                 $profile_fields = [
344                                         'hide-friends' => true,
345                                 ];
346                         }
347
348                         $fields = array_merge($fields, [
349                                 'page-flags'   => $page_flags,
350                                 'account-type' => $account_type,
351                         ]);
352
353                         if (!User::update($fields, local_user()) || !empty($profile_fields) && !Profile::update($profile_fields, local_user())) {
354                                 DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
355                         }
356
357                         DI::baseUrl()->redirect($redirectUrl);
358                 }
359
360                 // Import Contacts from CSV file
361                 if (!empty($request['importcontact-submit'])) {
362                         if (isset($_FILES['importcontact-filename'])) {
363                                 // was there an error
364                                 if ($_FILES['importcontact-filename']['error'] > 0) {
365                                         Logger::notice('Contact CSV file upload error', ['error' => $_FILES['importcontact-filename']['error']]);
366                                         DI::sysmsg()->addNotice(DI::l10n()->t('Contact CSV file upload error'));
367                                 } else {
368                                         $csvArray = array_map('str_getcsv', file($_FILES['importcontact-filename']['tmp_name']));
369                                         Logger::notice('Import started', ['lines' => count($csvArray)]);
370                                         // import contacts
371                                         foreach ($csvArray as $csvRow) {
372                                                 // The 1st row may, or may not contain the headers of the table
373                                                 // We expect the 1st field of the row to contain either the URL
374                                                 // or the handle of the account, therefore we check for either
375                                                 // "http" or "@" to be present in the string.
376                                                 // All other fields from the row will be ignored
377                                                 if ((strpos($csvRow[0], '@') !== false) || Network::isValidHttpUrl($csvRow[0])) {
378                                                         Worker::add(Worker::PRIORITY_MEDIUM, 'AddContact', local_user(), $csvRow[0]);
379                                                 } else {
380                                                         Logger::notice('Invalid account', ['url' => $csvRow[0]]);
381                                                 }
382                                         }
383                                         Logger::notice('Import done');
384
385                                         DI::sysmsg()->addInfo(DI::l10n()->t('Importing Contacts done'));
386                                         // delete temp file
387                                         unlink($_FILES['importcontact-filename']['tmp_name']);
388                                 }
389                         } else {
390                                 Logger::notice('Import triggered, but no import file was found.');
391                         }
392
393                         DI::baseUrl()->redirect($redirectUrl);
394                 }
395
396                 if (!empty($request['relocate-submit'])) {
397                         Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, local_user());
398                         DI::sysmsg()->addInfo(DI::l10n()->t("Relocate message has been send to your contacts"));
399                         DI::baseUrl()->redirect($redirectUrl);
400                 }
401
402                 DI::baseUrl()->redirect($redirectUrl);
403         }
404
405         protected function content(array $request = []): string
406         {
407                 parent::content();
408
409                 if (!local_user()) {
410                         throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
411                 }
412
413                 $profile = DBA::selectFirst('profile', [], ['uid' => local_user()]);
414                 if (!DBA::isResult($profile)) {
415                         DI::sysmsg()->addNotice(DI::l10n()->t('Unable to find your profile. Please contact your admin.'));
416                         return '';
417                 }
418
419                 $a = DI::app();
420
421                 $user = User::getById($a->getLoggedInUserId());
422
423                 $username         = $user['username'];
424                 $email            = $user['email'];
425                 $nickname         = $a->getLoggedInUserNickname();
426                 $timezone         = $user['timezone'];
427                 $language         = $user['language'];
428                 $notify           = $user['notify-flags'];
429                 $default_location = $user['default-location'];
430                 $openid           = $user['openid'];
431                 $maxreq           = $user['maxreq'];
432                 $expire           = $user['expire'] ?: '';
433                 $unkmail          = $user['unkmail'];
434                 $cntunkmail       = $user['cntunkmail'];
435
436                 $expire_items        = DI::pConfig()->get(local_user(), 'expire', 'items', true);
437                 $expire_notes        = DI::pConfig()->get(local_user(), 'expire', 'notes', true);
438                 $expire_starred      = DI::pConfig()->get(local_user(), 'expire', 'starred', true);
439                 $expire_network_only = DI::pConfig()->get(local_user(), 'expire', 'network_only', false);
440
441                 if (!strlen($user['timezone'])) {
442                         $timezone = $a->getTimeZone();
443                 }
444
445                 // Set the account type to "Community" when the page is a community page but the account type doesn't fit
446                 // This is only happening on the first visit after the update
447                 if (
448                         in_array($user['page-flags'], [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP])
449                         && $user['account-type'] != User::ACCOUNT_TYPE_COMMUNITY
450                 ) {
451                         $user['account-type'] = User::ACCOUNT_TYPE_COMMUNITY;
452                 }
453
454                 $pageset_tpl = Renderer::getMarkupTemplate('settings/pagetypes.tpl');
455                 $pagetype    = Renderer::replaceMacros($pageset_tpl, [
456                         '$account_types'     => DI::l10n()->t("Account Types"),
457                         '$user'              => DI::l10n()->t("Personal Page Subtypes"),
458                         '$community'         => DI::l10n()->t("Community Forum Subtypes"),
459                         '$account_type'      => $user['account-type'],
460                         '$type_person'       => User::ACCOUNT_TYPE_PERSON,
461                         '$type_organisation' => User::ACCOUNT_TYPE_ORGANISATION,
462                         '$type_news'         => User::ACCOUNT_TYPE_NEWS,
463                         '$type_community'    => User::ACCOUNT_TYPE_COMMUNITY,
464                         '$account_person'    => [
465                                 'account-type',
466                                 DI::l10n()->t('Personal Page'),
467                                 User::ACCOUNT_TYPE_PERSON,
468                                 DI::l10n()->t('Account for a personal profile.'),
469                                 $user['account-type'] == User::ACCOUNT_TYPE_PERSON
470                         ],
471                         '$account_organisation' => [
472                                 'account-type',
473                                 DI::l10n()->t('Organisation Page'),
474                                 User::ACCOUNT_TYPE_ORGANISATION,
475                                 DI::l10n()->t('Account for an organisation that automatically approves contact requests as "Followers".'),
476                                 $user['account-type'] == User::ACCOUNT_TYPE_ORGANISATION
477                         ],
478                         '$account_news' => [
479                                 'account-type',
480                                 DI::l10n()->t('News Page'),
481                                 User::ACCOUNT_TYPE_NEWS,
482                                 DI::l10n()->t('Account for a news reflector that automatically approves contact requests as "Followers".'),
483                                 $user['account-type'] == User::ACCOUNT_TYPE_NEWS
484                         ],
485                         '$account_community' => [
486                                 'account-type',
487                                 DI::l10n()->t('Community Forum'),
488                                 User::ACCOUNT_TYPE_COMMUNITY,
489                                 DI::l10n()->t('Account for community discussions.'),
490                                 $user['account-type'] == User::ACCOUNT_TYPE_COMMUNITY
491                         ],
492                         '$page_normal' => [
493                                 'page-flags',
494                                 DI::l10n()->t('Normal Account Page'),
495                                 User::PAGE_FLAGS_NORMAL,
496                                 DI::l10n()->t('Account for a regular personal profile that requires manual approval of "Friends" and "Followers".'),
497                                 $user['page-flags'] == User::PAGE_FLAGS_NORMAL
498                         ],
499                         '$page_soapbox' => [
500                                 'page-flags',
501                                 DI::l10n()->t('Soapbox Page'),
502                                 User::PAGE_FLAGS_SOAPBOX,
503                                 DI::l10n()->t('Account for a public profile that automatically approves contact requests as "Followers".'),
504                                 $user['page-flags'] == User::PAGE_FLAGS_SOAPBOX
505                         ],
506                         '$page_community' => [
507                                 'page-flags',
508                                 DI::l10n()->t('Public Forum'),
509                                 User::PAGE_FLAGS_COMMUNITY,
510                                 DI::l10n()->t('Automatically approves all contact requests.'),
511                                 $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY
512                         ],
513                         '$page_freelove' => [
514                                 'page-flags',
515                                 DI::l10n()->t('Automatic Friend Page'),
516                                 User::PAGE_FLAGS_FREELOVE,
517                                 DI::l10n()->t('Account for a popular profile that automatically approves contact requests as "Friends".'),
518                                 $user['page-flags'] == User::PAGE_FLAGS_FREELOVE
519                         ],
520                         '$page_prvgroup' => [
521                                 'page-flags',
522                                 DI::l10n()->t('Private Forum [Experimental]'),
523                                 User::PAGE_FLAGS_PRVGROUP,
524                                 DI::l10n()->t('Requires manual approval of contact requests.'),
525                                 $user['page-flags'] == User::PAGE_FLAGS_PRVGROUP
526                         ],
527                 ]);
528
529                 $noid = DI::config()->get('system', 'no_openid');
530                 if ($noid) {
531                         $openid_field = false;
532                 } else {
533                         $openid_field = ['openid_url', DI::l10n()->t('OpenID:'), $openid, DI::l10n()->t("(Optional) Allow this OpenID to login to this account."), "", "readonly", "url"];
534                 }
535
536                 if (DI::config()->get('system', 'publish_all')) {
537                         $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
538                 } else {
539                         $opt_tpl        = Renderer::getMarkupTemplate("field_checkbox.tpl");
540                         $profile_in_dir = Renderer::replaceMacros($opt_tpl, [
541                                 '$field' => ['profile_in_directory', DI::l10n()->t('Publish your profile in your local site directory?'), $profile['publish'], DI::l10n()->t('Your profile will be published in this node\'s <a href="%s">local directory</a>. Your profile details may be publicly visible depending on the system settings.', DI::baseUrl() . '/directory')]
542                         ]);
543                 }
544
545                 $net_pub_desc = '';
546                 if (Search::getGlobalDirectory()) {
547                         $net_pub_desc = ' ' . DI::l10n()->t('Your profile will also be published in the global friendica directories (e.g. <a href="%s">%s</a>).', Search::getGlobalDirectory(), Search::getGlobalDirectory());
548                 }
549
550                 /* Installed langs */
551                 $lang_choices = DI::l10n()->getAvailableLanguages();
552
553                 $notify_type = DI::pConfig()->get(local_user(), 'system', 'notify_type');
554
555                 $passwordRules = DI::l10n()->t('Allowed characters are a-z, A-Z, 0-9 and special characters except white spaces, accentuated letters and colon (:).')
556                         . (PASSWORD_DEFAULT === PASSWORD_BCRYPT ? ' ' . DI::l10n()->t('Password length is limited to 72 characters.') : '');
557
558                 $tpl = Renderer::getMarkupTemplate('settings/account.tpl');
559                 $o   = Renderer::replaceMacros($tpl, [
560                         '$ptitle' => DI::l10n()->t('Account Settings'),
561                         '$desc'   => DI::l10n()->t("Your Identity Address is <strong>'%s'</strong> or '%s'.", $nickname . '@' . DI::baseUrl()->getHostname() . DI::baseUrl()->getUrlPath(), DI::baseUrl() . '/profile/' . $nickname),
562
563                         '$submit'              => DI::l10n()->t('Save Settings'),
564                         '$baseurl'             => DI::baseUrl()->get(true),
565                         '$uid'                 => local_user(),
566                         '$form_security_token' => self::getFormSecurityToken('settings'),
567                         '$open'                => $this->parameters['open'] ?? 'password',
568
569                         '$h_pass'        => DI::l10n()->t('Password Settings'),
570                         '$password1'     => ['password', DI::l10n()->t('New Password:'), '', $passwordRules, false, 'autocomplete="off"', User::getPasswordRegExp()],
571                         '$password2'     => ['confirm', DI::l10n()->t('Confirm:'), '', DI::l10n()->t('Leave password fields blank unless changing'), false, 'autocomplete="off"'],
572                         '$password3'     => ['opassword', DI::l10n()->t('Current Password:'), '', DI::l10n()->t('Your current password to confirm the changes'), false, 'autocomplete="off"'],
573                         '$password4'     => ['mpassword', DI::l10n()->t('Password:'), '', DI::l10n()->t('Your current password to confirm the changes of the email address'), false, 'autocomplete="off"'],
574                         '$oid_enable'    => (!DI::config()->get('system', 'no_openid')),
575                         '$openid'        => $openid_field,
576                         '$delete_openid' => ['delete_openid', DI::l10n()->t('Delete OpenID URL'), false, ''],
577
578                         '$h_basic'          => DI::l10n()->t('Basic Settings'),
579                         '$username'         => ['username', DI::l10n()->t('Full Name:'), $username, '', false, 'autocomplete="off"'],
580                         '$email'            => ['email', DI::l10n()->t('Email Address:'), $email, '', '', 'autocomplete="off"', 'email'],
581                         '$timezone'         => ['timezone_select', DI::l10n()->t('Your Timezone:'), Temporal::getTimezoneSelect($timezone), ''],
582                         '$language'         => ['language', DI::l10n()->t('Your Language:'), $language, DI::l10n()->t('Set the language we use to show you friendica interface and to send you emails'), $lang_choices],
583                         '$default_location' => ['default_location', DI::l10n()->t('Default Post Location:'), $default_location, ''],
584                         '$allow_location'   => ['allow_location', DI::l10n()->t('Use Browser Location:'), ($user['allow_location'] == 1), ''],
585
586                         '$h_prv'              => DI::l10n()->t('Security and Privacy Settings'),
587                         '$is_community'       => ($user['account-type'] == User::ACCOUNT_TYPE_COMMUNITY),
588                         '$maxreq'             => ['maxreq', DI::l10n()->t('Maximum Friend Requests/Day:'), $maxreq, DI::l10n()->t("(to prevent spam abuse)")],
589                         '$profile_in_dir'     => $profile_in_dir,
590                         '$profile_in_net_dir' => ['profile_in_netdirectory', DI::l10n()->t('Allow your profile to be searchable globally?'), $profile['net-publish'], DI::l10n()->t("Activate this setting if you want others to easily find and follow you. Your profile will be searchable on remote systems. This setting also determines whether Friendica will inform search engines that your profile should be indexed or not.") . $net_pub_desc],
591                         '$hide_friends'       => ['hide-friends', DI::l10n()->t('Hide your contact/friend list from viewers of your profile?'), $profile['hide-friends'], DI::l10n()->t('A list of your contacts is displayed on your profile page. Activate this option to disable the display of your contact list.')],
592                         '$hide_wall'          => ['hidewall', DI::l10n()->t('Hide your profile details from anonymous viewers?'), $user['hidewall'], DI::l10n()->t('Anonymous visitors will only see your profile picture, your display name and the nickname you are using on your profile page. Your public posts and replies will still be accessible by other means.')],
593                         '$unlisted'           => ['unlisted', DI::l10n()->t('Make public posts unlisted'), DI::pConfig()->get(local_user(), 'system', 'unlisted'), DI::l10n()->t('Your public posts will not appear on the community pages or in search results, nor be sent to relay servers. However they can still appear on public feeds on remote servers.')],
594                         '$accessiblephotos'   => ['accessible-photos', DI::l10n()->t('Make all posted pictures accessible'), DI::pConfig()->get(local_user(), 'system', 'accessible-photos'), DI::l10n()->t("This option makes every posted picture accessible via the direct link. This is a workaround for the problem that most other networks can't handle permissions on pictures. Non public pictures still won't be visible for the public on your photo albums though.")],
595                         '$blockwall'          => ['blockwall', DI::l10n()->t('Allow friends to post to your profile page?'), (intval($user['blockwall']) ? '0' : '1'), DI::l10n()->t('Your contacts may write posts on your profile wall. These posts will be distributed to your contacts')],
596                         '$blocktags'          => ['blocktags', DI::l10n()->t('Allow friends to tag your posts?'), (intval($user['blocktags']) ? '0' : '1'), DI::l10n()->t('Your contacts can add additional tags to your posts.')],
597                         '$unkmail'            => ['unkmail', DI::l10n()->t('Permit unknown people to send you private mail?'), $unkmail, DI::l10n()->t('Friendica network users may send you private messages even if they are not in your contact list.')],
598                         '$cntunkmail'         => ['cntunkmail', DI::l10n()->t('Maximum private messages per day from unknown people:'), $cntunkmail, DI::l10n()->t("(to prevent spam abuse)")],
599                         '$group_select'       => Group::displayGroupSelection(local_user(), $user['def_gid']),
600                         '$permissions'        => DI::l10n()->t('Default Post Permissions'),
601                         '$aclselect'          => ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId()),
602
603                         '$expire' => [
604                                 'label'        => DI::l10n()->t('Expiration settings'),
605                                 'days'         => ['expire', DI::l10n()->t("Automatically expire posts after this many days:"), $expire, DI::l10n()->t('If empty, posts will not expire. Expired posts will be deleted')],
606                                 'items'        => ['expire_items', DI::l10n()->t('Expire posts'), $expire_items, DI::l10n()->t('When activated, posts and comments will be expired.')],
607                                 'notes'        => ['expire_notes', DI::l10n()->t('Expire personal notes'), $expire_notes, DI::l10n()->t('When activated, the personal notes on your profile page will be expired.')],
608                                 'starred'      => ['expire_starred', DI::l10n()->t('Expire starred posts'), $expire_starred, DI::l10n()->t('Starring posts keeps them from being expired. That behaviour is overwritten by this setting.')],
609                                 'network_only' => ['expire_network_only', DI::l10n()->t('Only expire posts by others'), $expire_network_only, DI::l10n()->t('When activated, your own posts never expire. Then the settings above are only valid for posts you received.')],
610                         ],
611
612                         '$h_not'   => DI::l10n()->t('Notification Settings'),
613                         '$lbl_not' => DI::l10n()->t('Send a notification email when:'),
614                         '$notify1' => ['notify1', DI::l10n()->t('You receive an introduction'), ($notify & Notification\Type::INTRO), Notification\Type::INTRO, ''],
615                         '$notify2' => ['notify2', DI::l10n()->t('Your introductions are confirmed'), ($notify & Notification\Type::CONFIRM), Notification\Type::CONFIRM, ''],
616                         '$notify3' => ['notify3', DI::l10n()->t('Someone writes on your profile wall'), ($notify & Notification\Type::WALL), Notification\Type::WALL, ''],
617                         '$notify4' => ['notify4', DI::l10n()->t('Someone writes a followup comment'), ($notify & Notification\Type::COMMENT), Notification\Type::COMMENT, ''],
618                         '$notify5' => ['notify5', DI::l10n()->t('You receive a private message'), ($notify & Notification\Type::MAIL), Notification\Type::MAIL, ''],
619                         '$notify6' => ['notify6', DI::l10n()->t('You receive a friend suggestion'), ($notify & Notification\Type::SUGGEST), Notification\Type::SUGGEST, ''],
620                         '$notify7' => ['notify7', DI::l10n()->t('You are tagged in a post'), ($notify & Notification\Type::TAG_SELF), Notification\Type::TAG_SELF, ''],
621
622                         '$lbl_notify'                    => DI::l10n()->t('Create a desktop notification when:'),
623                         '$notify_tagged'                 => ['notify_tagged', DI::l10n()->t('Someone tagged you'), is_null($notify_type) || $notify_type & UserNotification::TYPE_EXPLICIT_TAGGED, ''],
624                         '$notify_direct_comment'         => ['notify_direct_comment', DI::l10n()->t('Someone directly commented on your post'), is_null($notify_type) || $notify_type & (UserNotification::TYPE_IMPLICIT_TAGGED + UserNotification::TYPE_DIRECT_COMMENT + UserNotification::TYPE_DIRECT_THREAD_COMMENT), ''],
625                         '$notify_like'                   => ['notify_like', DI::l10n()->t('Someone liked your content'), DI::pConfig()->get(local_user(), 'system', 'notify_like'), DI::l10n()->t('Can only be enabled, when the direct comment notification is enabled.')],
626                         '$notify_announce'               => ['notify_announce', DI::l10n()->t('Someone shared your content'), DI::pConfig()->get(local_user(), 'system', 'notify_announce'), DI::l10n()->t('Can only be enabled, when the direct comment notification is enabled.')],
627                         '$notify_thread_comment'         => ['notify_thread_comment', DI::l10n()->t('Someone commented in your thread'), is_null($notify_type) || $notify_type & UserNotification::TYPE_THREAD_COMMENT, ''],
628                         '$notify_comment_participation'  => ['notify_comment_participation', DI::l10n()->t('Someone commented in a thread where you commented'), is_null($notify_type) || $notify_type & UserNotification::TYPE_COMMENT_PARTICIPATION, ''],
629                         '$notify_activity_participation' => ['notify_activity_participation', DI::l10n()->t('Someone commented in a thread where you interacted'), is_null($notify_type) || $notify_type & UserNotification::TYPE_ACTIVITY_PARTICIPATION, ''],
630
631                         '$desktop_notifications' => ['desktop_notifications', DI::l10n()->t('Activate desktop notifications'), false, DI::l10n()->t('Show desktop popup on new notifications')],
632
633                         '$email_textonly' => [
634                                 'email_textonly',
635                                 DI::l10n()->t('Text-only notification emails'),
636                                 DI::pConfig()->get(local_user(), 'system', 'email_textonly'),
637                                 DI::l10n()->t('Send text only notification emails, without the html part')
638                         ],
639                         '$detailed_notif' => [
640                                 'detailed_notif',
641                                 DI::l10n()->t('Show detailled notifications'),
642                                 DI::pConfig()->get(local_user(), 'system', 'detailed_notif'),
643                                 DI::l10n()->t('Per default, notifications are condensed to a single notification per item. When enabled every notification is displayed.')
644                         ],
645                         '$notify_ignored' => [
646                                 'notify_ignored',
647                                 DI::l10n()->t('Show notifications of ignored contacts'),
648                                 DI::pConfig()->get(local_user(), 'system', 'notify_ignored', true),
649                                 DI::l10n()->t("You don't see posts from ignored contacts. But you still see their comments. This setting controls if you want to still receive regular notifications that are caused by ignored contacts or not.")
650                         ],
651
652                         '$h_advn'     => DI::l10n()->t('Advanced Account/Page Type Settings'),
653                         '$h_descadvn' => DI::l10n()->t('Change the behaviour of this account for special situations'),
654                         '$pagetype'   => $pagetype,
655
656                         '$importcontact'         => DI::l10n()->t('Import Contacts'),
657                         '$importcontact_text'    => DI::l10n()->t('Upload a CSV file that contains the handle of your followed accounts in the first column you exported from the old account.'),
658                         '$importcontact_button'  => DI::l10n()->t('Upload File'),
659                         '$importcontact_maxsize' => DI::config()->get('system', 'max_csv_file_size', 30720),
660
661                         '$relocate'        => DI::l10n()->t('Relocate'),
662                         '$relocate_text'   => DI::l10n()->t("If you have moved this profile from another server, and some of your contacts don't receive your updates, try pushing this button."),
663                         '$relocate_button' => DI::l10n()->t("Resend relocate message to contacts"),
664                 ]);
665
666                 return $o;
667         }
668 }