]> git.mxchange.org Git - friendica.git/blob - src/Module/Settings/Account.php
543762a7fdee5045f6b7fea0211dff16253338e1
[friendica.git] / src / Module / Settings / Account.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2024, 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\Circle;
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\Protocol\Delivery;
42 use Friendica\Util\Network;
43 use Friendica\Util\Temporal;
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(DI::userSession()->getLocalUserId(), $request['opassword']);
72
73                                 $result = User::updatePassword(DI::userSession()->getLocalUserId(), $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(DI::userSession()->getLocalUserId(), $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 (in_array(strtolower($email), User::getAdminEmailList())) {
117                                         $err .= DI::l10n()->t('Cannot change to that email.');
118                                         $email = $user['email'];
119                                 }
120                         }
121
122                         if (strlen($err)) {
123                                 DI::sysmsg()->addNotice($err);
124                                 return;
125                         }
126
127                         if (strlen($timezone) && $timezone != $user['timezone']) {
128                                 $a->setTimeZone($timezone);
129                         }
130
131                         $fields = [
132                                 'username'         => $username,
133                                 'email'            => $email,
134                                 'timezone'         => $timezone,
135                                 'default-location' => trim($request['default_location'] ?? ''),
136                                 'allow_location'   => !empty($request['allow_location']),
137                                 'language'         => trim($request['language'] ?? ''),
138                         ];
139
140                         if (!empty($request['delete_openid'])) {
141                                 $fields['openid']       = '';
142                                 $fields['openidserver'] = '';
143                         }
144
145                         if (!User::update($fields, DI::userSession()->getLocalUserId())) {
146                                 DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
147                         }
148
149                         // clear session language
150                         unset($_SESSION['language']);
151
152                         DI::baseUrl()->redirect($redirectUrl);
153                 }
154
155                 if (!empty($request['privacy-submit'])) {
156                         $maxreq       = intval($request['maxreq'] ?? 0);
157                         $publish      = !empty($request['profile_in_directory']);
158                         $net_publish  = !empty($request['profile_in_netdirectory']);
159                         $hide_friends = !empty($request['hide-friends']);
160                         $hidewall     = !empty($request['hidewall']);
161                         $blockwall    = empty($request['blockwall']); // this setting is inverted!
162                         $blocktags    = empty($request['blocktags']); // this setting is inverted!
163                         $def_gid      = intval($request['circle-selection'] ?? 0);
164
165                         $aclFormatter = DI::aclFormatter();
166
167                         $str_contact_allow = !empty($request['contact_allow']) ? $aclFormatter->toString($request['contact_allow']) : '';
168                         $str_circle_allow  = !empty($request['circle_allow'])  ? $aclFormatter->toString($request['circle_allow'])  : '';
169                         $str_contact_deny  = !empty($request['contact_deny'])  ? $aclFormatter->toString($request['contact_deny'])  : '';
170                         $str_circle_deny   = !empty($request['circle_deny'])   ? $aclFormatter->toString($request['circle_deny'])   : '';
171
172                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'unlisted', !empty($request['unlisted']));
173                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'accessible-photos', !empty($request['accessible-photos']));
174                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'default-group-gid', intval($request['circle-selection-group'] ?? $def_gid));
175
176                         $fields = [
177                                 'allow_cid'  => $str_contact_allow,
178                                 'allow_gid'  => $str_circle_allow,
179                                 'deny_cid'   => $str_contact_deny,
180                                 'deny_gid'   => $str_circle_deny,
181                                 'maxreq'     => $maxreq,
182                                 'def_gid'    => $def_gid,
183                                 'blockwall'  => $blockwall,
184                                 'hidewall'   => $hidewall,
185                                 'blocktags'  => $blocktags,
186                         ];
187
188                         $profile_fields = [
189                                 'publish'      => $publish,
190                                 'net-publish'  => $net_publish,
191                                 'hide-friends' => $hide_friends
192                         ];
193
194                         if (!User::update($fields, DI::userSession()->getLocalUserId()) || !Profile::update($profile_fields, DI::userSession()->getLocalUserId())) {
195                                 DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
196                         }
197
198                         User::setCommunityUserSettings(DI::userSession()->getLocalUserId());
199                         DI::baseUrl()->redirect($redirectUrl);
200                 }
201
202                 if (!empty($request['expire-submit'])) {
203                         $expire = intval($request['expire'] ?? 0);
204
205                         $expire_items        = !empty($request['expire_items']);
206                         $expire_notes        = !empty($request['expire_notes']);
207                         $expire_starred      = !empty($request['expire_starred']);
208                         $expire_network_only = !empty($request['expire_network_only']);
209
210                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'expire', 'items', $expire_items);
211                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'expire', 'notes', $expire_notes);
212                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'expire', 'starred', $expire_starred);
213                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'expire', 'network_only', $expire_network_only);
214
215                         if (!User::update(['expire' => $expire], DI::userSession()->getLocalUserId())) {
216                                 DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
217                         }
218
219                         DI::baseUrl()->redirect($redirectUrl);
220                 }
221
222                 if (!empty($request['notification-submit'])) {
223                         $notify = 0;
224
225                         if (!empty($request['notify1'])) {
226                                 $notify += intval($request['notify1']);
227                         }
228                         if (!empty($request['notify2'])) {
229                                 $notify += intval($request['notify2']);
230                         }
231                         if (!empty($request['notify3'])) {
232                                 $notify += intval($request['notify3']);
233                         }
234                         if (!empty($request['notify4'])) {
235                                 $notify += intval($request['notify4']);
236                         }
237                         if (!empty($request['notify5'])) {
238                                 $notify += intval($request['notify5']);
239                         }
240                         if (!empty($request['notify6'])) {
241                                 $notify += intval($request['notify6']);
242                         }
243                         if (!empty($request['notify7'])) {
244                                 $notify += intval($request['notify7']);
245                         }
246                         if (!empty($request['notify8'])) {
247                                 $notify += intval($request['notify8']);
248                         }
249
250                         $notify_like     = !empty($request['notify_like']);
251                         $notify_announce = !empty($request['notify_announce']);
252
253                         $notify_type = 0;
254
255                         if (!empty($request['notify_tagged'])) {
256                                 $notify_type = $notify_type | UserNotification::TYPE_EXPLICIT_TAGGED;
257                         }
258                         if (!empty($request['notify_direct_comment'])) {
259                                 $notify_type = $notify_type | (UserNotification::TYPE_IMPLICIT_TAGGED + UserNotification::TYPE_DIRECT_COMMENT + UserNotification::TYPE_DIRECT_THREAD_COMMENT);
260                         }
261                         if (!empty($request['notify_thread_comment'])) {
262                                 $notify_type = $notify_type | UserNotification::TYPE_THREAD_COMMENT;
263                         }
264                         if (!empty($request['notify_comment_participation'])) {
265                                 $notify_type = $notify_type | UserNotification::TYPE_COMMENT_PARTICIPATION;
266                         }
267                         if (!empty($request['notify_activity_participation'])) {
268                                 $notify_type = $notify_type | UserNotification::TYPE_ACTIVITY_PARTICIPATION;
269                         }
270                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'notify_type', $notify_type);
271
272                         if (!($notify_type & (UserNotification::TYPE_DIRECT_COMMENT + UserNotification::TYPE_DIRECT_THREAD_COMMENT))) {
273                                 $notify_like     = false;
274                                 $notify_announce = false;
275                         }
276
277                         // Reset like notifications when they are going to be shown again
278                         if (!DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'notify_like') && $notify_like) {
279                                 DI::notification()->setAllSeenForUser(DI::userSession()->getLocalUserId(), ['vid' => Verb::getID(Activity::LIKE)]);
280                         }
281
282                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'notify_like', $notify_like);
283
284                         // Reset share notifications when they are going to be shown again
285                         if (!DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'notify_announce') && $notify_announce) {
286                                 DI::notification()->setAllSeenForUser(DI::userSession()->getLocalUserId(), ['vid' => Verb::getID(Activity::ANNOUNCE)]);
287                         }
288
289                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'notify_announce', $notify_announce);
290
291                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'email_textonly', !empty($request['email_textonly']));
292                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif', !empty($request['detailed_notif']));
293                         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'notify_ignored', !empty($request['notify_ignored']));
294
295                         $fields = [
296                                 'notify-flags' => $notify,
297                         ];
298
299                         if (!User::update($fields, DI::userSession()->getLocalUserId())) {
300                                 DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
301                         }
302
303                         DI::baseUrl()->redirect($redirectUrl);
304                 }
305
306                 if (!empty($request['advanced-submit'])) {
307                         $account_type = intval($request['account-type'] ?? 0);
308                         $page_flags   = intval($request['page-flags'] ?? 0);
309
310                         // Adjust the page flag if the account type doesn't fit to the page flag.
311                         if ($account_type == User::ACCOUNT_TYPE_PERSON && !in_array($page_flags, [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_SOAPBOX, User::PAGE_FLAGS_FREELOVE])) {
312                                 $page_flags = User::PAGE_FLAGS_NORMAL;
313                         } elseif ($account_type == User::ACCOUNT_TYPE_ORGANISATION && $page_flags != User::PAGE_FLAGS_SOAPBOX) {
314                                 $page_flags = User::PAGE_FLAGS_SOAPBOX;
315                         } elseif ($account_type == User::ACCOUNT_TYPE_NEWS && $page_flags != User::PAGE_FLAGS_SOAPBOX) {
316                                 $page_flags = User::PAGE_FLAGS_SOAPBOX;
317                         } elseif ($account_type == User::ACCOUNT_TYPE_COMMUNITY && !in_array($page_flags, [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP])) {
318                                 $page_flags = User::PAGE_FLAGS_COMMUNITY;
319                         } elseif ($account_type == User::ACCOUNT_TYPE_RELAY && $page_flags != User::PAGE_FLAGS_SOAPBOX) {
320                                 $page_flags = User::PAGE_FLAGS_SOAPBOX;
321                         }
322
323                         $fields = [
324                                 'page-flags'   => $page_flags,
325                                 'account-type' => $account_type,
326                         ];
327
328                         if (!User::update($fields, DI::userSession()->getLocalUserId())) {
329                                 DI::sysmsg()->addNotice(DI::l10n()->t('Settings were not updated.'));
330                         }
331
332                         User::setCommunityUserSettings(DI::userSession()->getLocalUserId());
333                         DI::baseUrl()->redirect($redirectUrl);
334                 }
335
336                 // Import Contacts from CSV file
337                 if (!empty($request['importcontact-submit'])) {
338                         if (isset($_FILES['importcontact-filename'])) {
339                                 // was there an error
340                                 if ($_FILES['importcontact-filename']['error'] > 0) {
341                                         Logger::notice('Contact CSV file upload error', ['error' => $_FILES['importcontact-filename']['error']]);
342                                         DI::sysmsg()->addNotice(DI::l10n()->t('Contact CSV file upload error'));
343                                 } else {
344                                         $csvArray = array_map('str_getcsv', file($_FILES['importcontact-filename']['tmp_name']));
345                                         Logger::notice('Import started', ['lines' => count($csvArray)]);
346                                         // import contacts
347                                         foreach ($csvArray as $csvRow) {
348                                                 // The 1st row may, or may not contain the headers of the table
349                                                 // We expect the 1st field of the row to contain either the URL
350                                                 // or the handle of the account, therefore we check for either
351                                                 // "http" or "@" to be present in the string.
352                                                 // All other fields from the row will be ignored
353                                                 if ((strpos($csvRow[0], '@') !== false) || Network::isValidHttpUrl($csvRow[0])) {
354                                                         Worker::add(Worker::PRIORITY_MEDIUM, 'AddContact', DI::userSession()->getLocalUserId(), trim($csvRow[0], '@'));
355                                                 } else {
356                                                         Logger::notice('Invalid account', ['url' => $csvRow[0]]);
357                                                 }
358                                         }
359                                         Logger::notice('Import done');
360
361                                         DI::sysmsg()->addInfo(DI::l10n()->t('Importing Contacts done'));
362                                         // delete temp file
363                                         unlink($_FILES['importcontact-filename']['tmp_name']);
364                                 }
365                         } else {
366                                 Logger::notice('Import triggered, but no import file was found.');
367                         }
368
369                         DI::baseUrl()->redirect($redirectUrl);
370                 }
371
372                 if (!empty($request['relocate-submit'])) {
373                         Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, DI::userSession()->getLocalUserId());
374                         DI::sysmsg()->addInfo(DI::l10n()->t("Relocate message has been send to your contacts"));
375                         DI::baseUrl()->redirect($redirectUrl);
376                 }
377
378                 DI::baseUrl()->redirect($redirectUrl);
379         }
380
381         protected function content(array $request = []): string
382         {
383                 parent::content();
384
385                 if (!DI::userSession()->getLocalUserId()) {
386                         throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
387                 }
388
389                 $profile = DBA::selectFirst('profile', [], ['uid' => DI::userSession()->getLocalUserId()]);
390                 if (!DBA::isResult($profile)) {
391                         DI::sysmsg()->addNotice(DI::l10n()->t('Unable to find your profile. Please contact your admin.'));
392                         return '';
393                 }
394
395                 $a = DI::app();
396
397                 $user = User::getById($a->getLoggedInUserId());
398
399                 $username         = $user['username'];
400                 $email            = $user['email'];
401                 $nickname         = $a->getLoggedInUserNickname();
402                 $timezone         = $user['timezone'];
403                 $language         = $user['language'];
404                 $notify           = $user['notify-flags'];
405                 $default_location = $user['default-location'];
406                 $openid           = $user['openid'];
407                 $maxreq           = $user['maxreq'];
408                 $expire           = $user['expire'] ?: '';
409
410                 $expire_items        = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'expire', 'items', true);
411                 $expire_notes        = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'expire', 'notes', true);
412                 $expire_starred      = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'expire', 'starred', true);
413                 $expire_network_only = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'expire', 'network_only', false);
414
415                 if (!strlen($user['timezone'])) {
416                         $timezone = $a->getTimeZone();
417                 }
418
419                 // Set the account type to "Community" when the page is a community page but the account type doesn't fit
420                 // This is only happening on the first visit after the update
421                 if (
422                         in_array($user['page-flags'], [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP])
423                         && $user['account-type'] != User::ACCOUNT_TYPE_COMMUNITY
424                 ) {
425                         $user['account-type'] = User::ACCOUNT_TYPE_COMMUNITY;
426                 }
427
428                 $pageset_tpl = Renderer::getMarkupTemplate('settings/pagetypes.tpl');
429                 $pagetype    = Renderer::replaceMacros($pageset_tpl, [
430                         '$account_types'     => DI::l10n()->t("Account Types"),
431                         '$user'              => DI::l10n()->t("Personal Page Subtypes"),
432                         '$community'         => DI::l10n()->t("Community Group Subtypes"),
433                         '$account_type'      => $user['account-type'],
434                         '$type_person'       => User::ACCOUNT_TYPE_PERSON,
435                         '$type_organisation' => User::ACCOUNT_TYPE_ORGANISATION,
436                         '$type_news'         => User::ACCOUNT_TYPE_NEWS,
437                         '$type_community'    => User::ACCOUNT_TYPE_COMMUNITY,
438                         '$type_relay'        => User::ACCOUNT_TYPE_RELAY,
439                         '$account_person'    => [
440                                 'account-type',
441                                 DI::l10n()->t('Personal Page'),
442                                 User::ACCOUNT_TYPE_PERSON,
443                                 DI::l10n()->t('Account for a personal profile.'),
444                                 $user['account-type'] == User::ACCOUNT_TYPE_PERSON
445                         ],
446                         '$account_organisation' => [
447                                 'account-type',
448                                 DI::l10n()->t('Organisation Page'),
449                                 User::ACCOUNT_TYPE_ORGANISATION,
450                                 DI::l10n()->t('Account for an organisation that automatically approves contact requests as "Followers".'),
451                                 $user['account-type'] == User::ACCOUNT_TYPE_ORGANISATION
452                         ],
453                         '$account_news' => [
454                                 'account-type',
455                                 DI::l10n()->t('News Page'),
456                                 User::ACCOUNT_TYPE_NEWS,
457                                 DI::l10n()->t('Account for a news reflector that automatically approves contact requests as "Followers".'),
458                                 $user['account-type'] == User::ACCOUNT_TYPE_NEWS
459                         ],
460                         '$account_community' => [
461                                 'account-type',
462                                 DI::l10n()->t('Community Group'),
463                                 User::ACCOUNT_TYPE_COMMUNITY,
464                                 DI::l10n()->t('Account for community discussions.'),
465                                 $user['account-type'] == User::ACCOUNT_TYPE_COMMUNITY
466                         ],
467                         '$account_relay' => [
468                                 'account-type',
469                                 DI::l10n()->t('Channel Relay'),
470                                 User::ACCOUNT_TYPE_RELAY,
471                                 DI::l10n()->t('Account for a service that automatically shares content based on user defined channels.'),
472                                 $user['account-type'] == User::ACCOUNT_TYPE_RELAY
473                         ],
474                         '$page_normal' => [
475                                 'page-flags',
476                                 DI::l10n()->t('Normal Account Page'),
477                                 User::PAGE_FLAGS_NORMAL,
478                                 DI::l10n()->t('Account for a regular personal profile that requires manual approval of "Friends" and "Followers".'),
479                                 $user['page-flags'] == User::PAGE_FLAGS_NORMAL
480                         ],
481                         '$page_soapbox' => [
482                                 'page-flags',
483                                 DI::l10n()->t('Soapbox Page'),
484                                 User::PAGE_FLAGS_SOAPBOX,
485                                 DI::l10n()->t('Account for a public profile that automatically approves contact requests as "Followers".'),
486                                 $user['page-flags'] == User::PAGE_FLAGS_SOAPBOX
487                         ],
488                         '$page_community' => [
489                                 'page-flags',
490                                 DI::l10n()->t('Public Group'),
491                                 User::PAGE_FLAGS_COMMUNITY,
492                                 DI::l10n()->t('Automatically approves all contact requests.'),
493                                 $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY
494                         ],
495                         '$page_freelove' => [
496                                 'page-flags',
497                                 DI::l10n()->t('Automatic Friend Page'),
498                                 User::PAGE_FLAGS_FREELOVE,
499                                 DI::l10n()->t('Account for a popular profile that automatically approves contact requests as "Friends".'),
500                                 $user['page-flags'] == User::PAGE_FLAGS_FREELOVE
501                         ],
502                         '$page_prvgroup' => [
503                                 'page-flags',
504                                 DI::l10n()->t('Private Group [Experimental]'),
505                                 User::PAGE_FLAGS_PRVGROUP,
506                                 DI::l10n()->t('Requires manual approval of contact requests.'),
507                                 $user['page-flags'] == User::PAGE_FLAGS_PRVGROUP
508                         ],
509                 ]);
510
511                 $noid = DI::config()->get('system', 'no_openid');
512                 if ($noid) {
513                         $openid_field = false;
514                 } else {
515                         $openid_field = ['openid_url', DI::l10n()->t('OpenID:'), $openid, DI::l10n()->t("(Optional) Allow this OpenID to login to this account."), "", "readonly", "url"];
516                 }
517
518                 if (DI::config()->get('system', 'publish_all')) {
519                         $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
520                 } else {
521                         $opt_tpl        = Renderer::getMarkupTemplate("field_checkbox.tpl");
522                         $profile_in_dir = Renderer::replaceMacros($opt_tpl, [
523                                 '$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')]
524                         ]);
525                 }
526
527                 $net_pub_desc = '';
528                 if (Search::getGlobalDirectory()) {
529                         $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());
530                 }
531
532                 /* Installed langs */
533                 $lang_choices = DI::l10n()->getAvailableLanguages();
534
535                 $notify_type = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'notify_type');
536
537                 $passwordRules = DI::l10n()->t('Allowed characters are a-z, A-Z, 0-9 and special characters except white spaces and accentuated letters.')
538                         . (PASSWORD_DEFAULT === PASSWORD_BCRYPT ? ' ' . DI::l10n()->t('Password length is limited to 72 characters.') : '');
539
540                 $tpl = Renderer::getMarkupTemplate('settings/account.tpl');
541                 $o   = Renderer::replaceMacros($tpl, [
542                         '$ptitle' => DI::l10n()->t('Account Settings'),
543                         '$desc'   => DI::l10n()->t("Your Identity Address is <strong>'%s'</strong> or '%s'.", $nickname . '@' . DI::baseUrl()->getHost() . DI::baseUrl()->getPath(), DI::baseUrl() . '/profile/' . $nickname),
544
545                         '$submit'              => DI::l10n()->t('Save Settings'),
546                         '$uid'                 => DI::userSession()->getLocalUserId(),
547                         '$form_security_token' => self::getFormSecurityToken('settings'),
548                         '$open'                => $this->parameters['open'] ?? 'password',
549
550                         '$h_pass'        => DI::l10n()->t('Password Settings'),
551                         '$password1'     => ['password', DI::l10n()->t('New Password:'), '', $passwordRules, false, 'autocomplete="off"', User::getPasswordRegExp()],
552                         '$password2'     => ['confirm', DI::l10n()->t('Confirm:'), '', DI::l10n()->t('Leave password fields blank unless changing'), false, 'autocomplete="off"'],
553                         '$password3'     => ['opassword', DI::l10n()->t('Current Password:'), '', DI::l10n()->t('Your current password to confirm the changes'), false, 'autocomplete="off"'],
554                         '$password4'     => ['mpassword', DI::l10n()->t('Password:'), '', DI::l10n()->t('Your current password to confirm the changes of the email address'), false, 'autocomplete="off"'],
555                         '$oid_enable'    => (!DI::config()->get('system', 'no_openid')),
556                         '$openid'        => $openid_field,
557                         '$delete_openid' => ['delete_openid', DI::l10n()->t('Delete OpenID URL'), false, ''],
558
559                         '$h_basic'          => DI::l10n()->t('Basic Settings'),
560                         '$username'         => ['username', DI::l10n()->t('Display name:'), $username, '', false, 'autocomplete="off"'],
561                         '$email'            => ['email', DI::l10n()->t('Email Address:'), $email, '', '', 'autocomplete="off"', 'email'],
562                         '$timezone'         => ['timezone_select', DI::l10n()->t('Your Timezone:'), Temporal::getTimezoneSelect($timezone), ''],
563                         '$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],
564                         '$default_location' => ['default_location', DI::l10n()->t('Default Post Location:'), $default_location, ''],
565                         '$allow_location'   => ['allow_location', DI::l10n()->t('Use Browser Location:'), ($user['allow_location'] == 1), ''],
566
567                         '$h_prv'              => DI::l10n()->t('Security and Privacy Settings'),
568                         '$is_community'       => ($user['account-type'] == User::ACCOUNT_TYPE_COMMUNITY),
569                         '$maxreq'             => ['maxreq', DI::l10n()->t('Maximum Friend Requests/Day:'), $maxreq, DI::l10n()->t("(to prevent spam abuse)")],
570                         '$profile_in_dir'     => $profile_in_dir,
571                         '$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],
572                         '$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.')],
573                         '$hide_wall'          => ['hidewall', $this->t('Hide your public content from anonymous viewers'), $user['hidewall'], $this->t('Anonymous visitors will only see your basic profile details. Your public posts and replies will still be freely accessible on the remote servers of your followers and through relays.')],
574                         '$unlisted'           => ['unlisted', DI::l10n()->t('Make public posts unlisted'), DI::pConfig()->get(DI::userSession()->getLocalUserId(), '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.')],
575                         '$accessiblephotos'   => ['accessible-photos', DI::l10n()->t('Make all posted pictures accessible'), DI::pConfig()->get(DI::userSession()->getLocalUserId(), '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.")],
576                         '$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')],
577                         '$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.')],
578                         '$circle_select'      => Circle::getSelectorHTML(DI::userSession()->getLocalUserId(), $user['def_gid'], 'circle-selection', DI::l10n()->t('Default privacy circle for new contacts')),
579                         '$circle_select_group' => Circle::getSelectorHTML(DI::userSession()->getLocalUserId(), DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'default-group-gid', $user['def_gid']), 'circle-selection-group', DI::l10n()->t('Default privacy circle for new group contacts')),
580                         '$permissions'        => DI::l10n()->t('Default Post Permissions'),
581                         '$aclselect'          => ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId()),
582
583                         '$expire' => [
584                                 'label'        => DI::l10n()->t('Expiration settings'),
585                                 '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')],
586                                 'items'        => ['expire_items', DI::l10n()->t('Expire posts'), $expire_items, DI::l10n()->t('When activated, posts and comments will be expired.')],
587                                 '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.')],
588                                 '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.')],
589                                 '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.')],
590                         ],
591
592                         '$h_not'   => DI::l10n()->t('Notification Settings'),
593                         '$lbl_not' => DI::l10n()->t('Send a notification email when:'),
594                         '$notify1' => ['notify1', DI::l10n()->t('You receive an introduction'), ($notify & Notification\Type::INTRO), Notification\Type::INTRO, ''],
595                         '$notify2' => ['notify2', DI::l10n()->t('Your introductions are confirmed'), ($notify & Notification\Type::CONFIRM), Notification\Type::CONFIRM, ''],
596                         '$notify3' => ['notify3', DI::l10n()->t('Someone writes on your profile wall'), ($notify & Notification\Type::WALL), Notification\Type::WALL, ''],
597                         '$notify4' => ['notify4', DI::l10n()->t('Someone writes a followup comment'), ($notify & Notification\Type::COMMENT), Notification\Type::COMMENT, ''],
598                         '$notify5' => ['notify5', DI::l10n()->t('You receive a private message'), ($notify & Notification\Type::MAIL), Notification\Type::MAIL, ''],
599                         '$notify6' => ['notify6', DI::l10n()->t('You receive a friend suggestion'), ($notify & Notification\Type::SUGGEST), Notification\Type::SUGGEST, ''],
600                         '$notify7' => ['notify7', DI::l10n()->t('You are tagged in a post'), ($notify & Notification\Type::TAG_SELF), Notification\Type::TAG_SELF, ''],
601
602                         '$lbl_notify'                    => DI::l10n()->t('Create a desktop notification when:'),
603                         '$notify_tagged'                 => ['notify_tagged', DI::l10n()->t('Someone tagged you'), is_null($notify_type) || $notify_type & UserNotification::TYPE_EXPLICIT_TAGGED, ''],
604                         '$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), ''],
605                         '$notify_like'                   => ['notify_like', DI::l10n()->t('Someone liked your content'), DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'notify_like'), DI::l10n()->t('Can only be enabled, when the direct comment notification is enabled.')],
606                         '$notify_announce'               => ['notify_announce', DI::l10n()->t('Someone shared your content'), DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'notify_announce'), DI::l10n()->t('Can only be enabled, when the direct comment notification is enabled.')],
607                         '$notify_thread_comment'         => ['notify_thread_comment', DI::l10n()->t('Someone commented in your thread'), is_null($notify_type) || $notify_type & UserNotification::TYPE_THREAD_COMMENT, ''],
608                         '$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, ''],
609                         '$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, ''],
610
611                         '$desktop_notifications' => ['desktop_notifications', DI::l10n()->t('Activate desktop notifications'), false, DI::l10n()->t('Show desktop popup on new notifications')],
612
613                         '$email_textonly' => [
614                                 'email_textonly',
615                                 DI::l10n()->t('Text-only notification emails'),
616                                 DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'email_textonly'),
617                                 DI::l10n()->t('Send text only notification emails, without the html part')
618                         ],
619                         '$detailed_notif' => [
620                                 'detailed_notif',
621                                 DI::l10n()->t('Show detailled notifications'),
622                                 DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif'),
623                                 DI::l10n()->t('Per default, notifications are condensed to a single notification per item. When enabled every notification is displayed.')
624                         ],
625                         '$notify_ignored' => [
626                                 'notify_ignored',
627                                 DI::l10n()->t('Show notifications of ignored contacts'),
628                                 DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'notify_ignored', true),
629                                 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.")
630                         ],
631
632                         '$h_advn'     => DI::l10n()->t('Advanced Account/Page Type Settings'),
633                         '$h_descadvn' => DI::l10n()->t('Change the behaviour of this account for special situations'),
634                         '$pagetype'   => $pagetype,
635
636                         '$importcontact'         => DI::l10n()->t('Import Contacts'),
637                         '$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.'),
638                         '$importcontact_button'  => DI::l10n()->t('Upload File'),
639                         '$importcontact_maxsize' => DI::config()->get('system', 'max_csv_file_size', 30720),
640
641                         '$relocate'        => DI::l10n()->t('Relocate'),
642                         '$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."),
643                         '$relocate_button' => DI::l10n()->t("Resend relocate message to contacts"),
644                 ]);
645
646                 return $o;
647         }
648 }