From d3cc9998669def21d493aaa7b114ba5fd5f63858 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 20 Aug 2023 12:41:42 +0000 Subject: [PATCH 01/25] GPTBot added to the default robots.txt --- src/Module/RobotsTxt.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Module/RobotsTxt.php b/src/Module/RobotsTxt.php index 415a8ab47..a084c1f4a 100644 --- a/src/Module/RobotsTxt.php +++ b/src/Module/RobotsTxt.php @@ -38,6 +38,8 @@ class RobotsTxt extends BaseModule '/search', '/help', '/proxy', + '/photo', + '/avatar', ]; header('Content-Type: text/plain'); @@ -50,6 +52,10 @@ class RobotsTxt extends BaseModule echo 'User-agent: ChatGPT-User' . PHP_EOL; echo 'Disallow: /' . PHP_EOL; + echo PHP_EOL; + echo 'User-agent: GPTBot' . PHP_EOL; + echo 'Disallow: /' . PHP_EOL; + System::exit(); } } From 7e971a2ec64fe6fc276cc083da29332a83fdf076 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 11 Aug 2023 00:46:27 +0200 Subject: [PATCH 02/25] Remove DI dependency from Module\Settings\Profile\Index - Replace obsolete base settings/profile/index template by vier version - Group translation labels in settings/profile/index template variables --- src/Module/Settings/Profile/Index.php | 278 ++++++++++-------- .../Repository/PermissionSet.php | 2 +- view/templates/settings/profile/index.tpl | 218 +++++++------- .../frio/templates/settings/profile/index.tpl | 30 +- .../vier/templates/settings/profile/index.tpl | 179 ----------- 5 files changed, 283 insertions(+), 424 deletions(-) delete mode 100644 view/theme/vier/templates/settings/profile/index.tpl diff --git a/src/Module/Settings/Profile/Index.php b/src/Module/Settings/Profile/Index.php index c8b27e394..c18c72a4e 100644 --- a/src/Module/Settings/Profile/Index.php +++ b/src/Module/Settings/Profile/Index.php @@ -21,43 +21,75 @@ namespace Friendica\Module\Settings\Profile; +use Friendica\App; use Friendica\Core\ACL; use Friendica\Core\Hook; +use Friendica\Core\L10n; use Friendica\Core\Protocol; use Friendica\Core\Renderer; +use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Core\Theme; use Friendica\Database\DBA; -use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Profile; -use Friendica\Profile\ProfileField\Collection\ProfileFields; -use Friendica\Profile\ProfileField\Entity\ProfileField; +use Friendica\Module\Response; +use Friendica\Navigation\SystemMessages; +use Friendica\Profile\ProfileField; use Friendica\Model\User; use Friendica\Module\BaseSettings; use Friendica\Module\Security\Login; use Friendica\Network\HTTPException; +use Friendica\Security\PermissionSet; +use Friendica\Util\ACLFormatter; use Friendica\Util\DateTimeFormat; +use Friendica\Util\Profiler; use Friendica\Util\Temporal; use Friendica\Core\Worker; +use Psr\Log\LoggerInterface; class Index extends BaseSettings { + /** @var ProfileField\Repository\ProfileField */ + private $profileFieldRepo; + /** @var ProfileField\Factory\ProfileField */ + private $profileFieldFactory; + /** @var SystemMessages */ + private $systemMessages; + /** @var PermissionSet\Repository\PermissionSet */ + private $permissionSetRepo; + /** @var PermissionSet\Factory\PermissionSet */ + private $permissionSetFactory; + /** @var ACLFormatter */ + private $aclFormatter; + + public function __construct(ACLFormatter $aclFormatter, PermissionSet\Factory\PermissionSet $permissionSetFactory, PermissionSet\Repository\PermissionSet $permissionSetRepo, SystemMessages $systemMessages, ProfileField\Factory\ProfileField $profileFieldFactory, ProfileField\Repository\ProfileField $profileFieldRepo, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = []) + { + parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); + + $this->profileFieldRepo = $profileFieldRepo; + $this->profileFieldFactory = $profileFieldFactory; + $this->systemMessages = $systemMessages; + $this->permissionSetRepo = $permissionSetRepo; + $this->permissionSetFactory = $permissionSetFactory; + $this->aclFormatter = $aclFormatter; + } + protected function post(array $request = []) { - if (!DI::userSession()->getLocalUserId()) { + if (!$this->session->getLocalUserId()) { return; } - $profile = Profile::getByUID(DI::userSession()->getLocalUserId()); - if (!DBA::isResult($profile)) { + $profile = Profile::getByUID($this->session->getLocalUserId()); + if (!$profile) { return; } self::checkFormSecurityTokenRedirectOnError('/settings/profile', 'settings_profile'); - Hook::callAll('profile_post', $_POST); + Hook::callAll('profile_post', $request); - $dob = trim($_POST['dob'] ?? ''); + $dob = trim($request['dob'] ?? ''); if ($dob && !in_array($dob, ['0000-00-00', DBA::NULL_DATE])) { $y = substr($dob, 0, 4); @@ -79,35 +111,35 @@ class Index extends BaseSettings } } - $name = trim($_POST['name'] ?? ''); - if (!strlen($name)) { - DI::sysmsg()->addNotice(DI::l10n()->t('Profile Name is required.')); + $name = trim($request['name'] ?? ''); + if (!$name) { + $this->systemMessages->addNotice($this->t('Display Name is required.')); return; } - $about = trim($_POST['about']); - $address = trim($_POST['address']); - $locality = trim($_POST['locality']); - $region = trim($_POST['region']); - $postal_code = trim($_POST['postal_code']); - $country_name = trim($_POST['country_name']); - $pub_keywords = self::cleanKeywords(trim($_POST['pub_keywords'])); - $prv_keywords = self::cleanKeywords(trim($_POST['prv_keywords'])); - $xmpp = trim($_POST['xmpp']); - $matrix = trim($_POST['matrix']); - $homepage = trim($_POST['homepage']); + $about = trim($request['about']); + $address = trim($request['address']); + $locality = trim($request['locality']); + $region = trim($request['region']); + $postal_code = trim($request['postal_code']); + $country_name = trim($request['country_name']); + $pub_keywords = self::cleanKeywords(trim($request['pub_keywords'])); + $prv_keywords = self::cleanKeywords(trim($request['prv_keywords'])); + $xmpp = trim($request['xmpp']); + $matrix = trim($request['matrix']); + $homepage = trim($request['homepage']); if ((strpos($homepage, 'http') !== 0) && (strlen($homepage))) { // neither http nor https in URL, add them $homepage = 'http://' . $homepage; } - $profileFieldsNew = self::getProfileFieldsFromInput( - DI::userSession()->getLocalUserId(), - $_REQUEST['profile_field'], - $_REQUEST['profile_field_order'] + $profileFieldsNew = $this->getProfileFieldsFromInput( + $this->session->getLocalUserId(), + $request['profile_field'], + $request['profile_field_order'] ); - DI::profileField()->saveCollectionForUser(DI::userSession()->getLocalUserId(), $profileFieldsNew); + $this->profileFieldRepo->saveCollectionForUser($this->session->getLocalUserId(), $profileFieldsNew); $result = Profile::update( [ @@ -125,23 +157,23 @@ class Index extends BaseSettings 'pub_keywords' => $pub_keywords, 'prv_keywords' => $prv_keywords, ], - DI::userSession()->getLocalUserId() + $this->session->getLocalUserId() ); - Worker::add(Worker::PRIORITY_MEDIUM, 'CheckRelMeProfileLink', DI::userSession()->getLocalUserId()); + Worker::add(Worker::PRIORITY_MEDIUM, 'CheckRelMeProfileLink', $this->session->getLocalUserId()); if (!$result) { - DI::sysmsg()->addNotice(DI::l10n()->t('Profile couldn\'t be updated.')); + $this->systemMessages->addNotice($this->t("Profile couldn't be updated.")); return; } - DI::baseUrl()->redirect('settings/profile'); + $this->baseUrl->redirect('settings/profile'); } protected function content(array $request = []): string { - if (!DI::userSession()->getLocalUserId()) { - DI::sysmsg()->addNotice(DI::l10n()->t('You must be logged in to use this module')); + if (!$this->session->getLocalUserId()) { + $this->systemMessages->addNotice($this->t('You must be logged in to use this module')); return Login::form(); } @@ -149,147 +181,145 @@ class Index extends BaseSettings $o = ''; - $profile = User::getOwnerDataById(DI::userSession()->getLocalUserId()); - if (!DBA::isResult($profile)) { + $owner = User::getOwnerDataById($this->session->getLocalUserId()); + if (!$owner) { throw new HTTPException\NotFoundException(); } - $a = DI::app(); - - DI::page()->registerFooterScript('view/asset/es-jquery-sortable/source/js/jquery-sortable-min.js'); - DI::page()->registerFooterScript(Theme::getPathForFile('js/module/settings/profile/index.js')); + $this->page->registerFooterScript('view/asset/es-jquery-sortable/source/js/jquery-sortable-min.js'); + $this->page->registerFooterScript(Theme::getPathForFile('js/module/settings/profile/index.js')); $custom_fields = []; - $profileFields = DI::profileField()->selectByUserId(DI::userSession()->getLocalUserId()); + $profileFields = $this->profileFieldRepo->selectByUserId($this->session->getLocalUserId()); foreach ($profileFields as $profileField) { - /** @var ProfileField $profileField */ $defaultPermissions = $profileField->permissionSet->withAllowedContacts( Contact::pruneUnavailable($profileField->permissionSet->allow_cid) ); $custom_fields[] = [ - 'id' => $profileField->id, + 'id' => $profileField->id, 'legend' => $profileField->label, 'fields' => [ - 'label' => ['profile_field[' . $profileField->id . '][label]', DI::l10n()->t('Label:'), $profileField->label], - 'value' => ['profile_field[' . $profileField->id . '][value]', DI::l10n()->t('Value:'), $profileField->value], - 'acl' => ACL::getFullSelectorHTML( - DI::page(), - $a->getLoggedInUserId(), + 'label' => ['profile_field[' . $profileField->id . '][label]', $this->t('Label:'), $profileField->label], + 'value' => ['profile_field[' . $profileField->id . '][value]', $this->t('Value:'), $profileField->value], + 'acl' => ACL::getFullSelectorHTML( + $this->page, + $this->session->getLocalUserId(), false, $defaultPermissions->toArray(), ['network' => Protocol::DFRN], 'profile_field[' . $profileField->id . ']' ), ], - 'permissions' => DI::l10n()->t('Field Permissions'), - 'permdesc' => DI::l10n()->t("(click to open/close)"), + + 'permissions' => $this->t('Field Permissions'), + 'permdesc' => $this->t("(click to open/close)"), ]; - }; + } $custom_fields[] = [ - 'id' => 'new', - 'legend' => DI::l10n()->t('Add a new profile field'), + 'id' => 'new', + 'legend' => $this->t('Add a new profile field'), 'fields' => [ - 'label' => ['profile_field[new][label]', DI::l10n()->t('Label:')], - 'value' => ['profile_field[new][value]', DI::l10n()->t('Value:')], - 'acl' => ACL::getFullSelectorHTML( - DI::page(), - $a->getLoggedInUserId(), + 'label' => ['profile_field[new][label]', $this->t('Label:')], + 'value' => ['profile_field[new][value]', $this->t('Value:')], + 'acl' => ACL::getFullSelectorHTML( + $this->page, + $this->session->getLocalUserId(), false, ['allow_cid' => []], ['network' => Protocol::DFRN], 'profile_field[new]' ), ], - 'permissions' => DI::l10n()->t('Field Permissions'), - 'permdesc' => DI::l10n()->t("(click to open/close)"), + + 'permissions' => $this->t('Field Permissions'), + 'permdesc' => $this->t("(click to open/close)"), ]; - DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/profile/index_head.tpl'), [ - ]); + $this->page['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/profile/index_head.tpl')); - $personal_account = ($profile['account-type'] != User::ACCOUNT_TYPE_COMMUNITY); + $personal_account = ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY); - if ($profile['homepage_verified']) { - $homepage_help_text = DI::l10n()->t('The homepage is verified. A rel="me" link back to your Friendica profile page was found on the homepage.'); + if ($owner['homepage_verified']) { + $homepage_help_text = $this->t('The homepage is verified. A rel="me" link back to your Friendica profile page was found on the homepage.'); } else { - $homepage_help_text = DI::l10n()->t('To verify your homepage, add a rel="me" link to it, pointing to your profile URL (%s).', $profile['url']); + $homepage_help_text = $this->t('To verify your homepage, add a rel="me" link to it, pointing to your profile URL (%s).', $owner['url']); } $tpl = Renderer::getMarkupTemplate('settings/profile/index.tpl'); $o .= Renderer::replaceMacros($tpl, [ - '$personal_account' => $personal_account, - - '$form_security_token' => self::getFormSecurityToken('settings_profile'), - '$form_security_token_photo' => self::getFormSecurityToken('settings_profile_photo'), - - '$profile_action' => DI::l10n()->t('Profile Actions'), - '$banner' => DI::l10n()->t('Edit Profile Details'), - '$submit' => DI::l10n()->t('Submit'), - '$profpic' => DI::l10n()->t('Change Profile Photo'), - '$profpiclink' => '/profile/' . $profile['nickname'] . '/photos', - '$viewprof' => DI::l10n()->t('View Profile'), - - '$lbl_personal_section' => DI::l10n()->t('Personal'), - '$lbl_picture_section' => DI::l10n()->t('Profile picture'), - '$lbl_location_section' => DI::l10n()->t('Location'), - '$lbl_miscellaneous_section' => DI::l10n()->t('Miscellaneous'), - '$lbl_custom_fields_section' => DI::l10n()->t('Custom Profile Fields'), - - '$lbl_profile_photo' => DI::l10n()->t('Upload Profile Photo'), - - '$baseurl' => DI::baseUrl(), - '$nickname' => $profile['nickname'], - '$name' => ['name', DI::l10n()->t('Display name:'), $profile['name']], - '$about' => ['about', DI::l10n()->t('Description:'), $profile['about']], - '$dob' => Temporal::getDateofBirthField($profile['dob'], $profile['timezone']), - '$address' => ['address', DI::l10n()->t('Street Address:'), $profile['address']], - '$locality' => ['locality', DI::l10n()->t('Locality/City:'), $profile['locality']], - '$region' => ['region', DI::l10n()->t('Region/State:'), $profile['region']], - '$postal_code' => ['postal_code', DI::l10n()->t('Postal/Zip Code:'), $profile['postal-code']], - '$country_name' => ['country_name', DI::l10n()->t('Country:'), $profile['country-name']], - '$age' => ((intval($profile['dob'])) ? '(' . DI::l10n()->t('Age: ') . DI::l10n()->tt('%d year old', '%d years old', Temporal::getAgeByTimezone($profile['dob'], $profile['timezone'])) . ')' : ''), - '$xmpp' => ['xmpp', DI::l10n()->t('XMPP (Jabber) address:'), $profile['xmpp'], DI::l10n()->t('The XMPP address will be published so that people can follow you there.')], - '$matrix' => ['matrix', DI::l10n()->t('Matrix (Element) address:'), $profile['matrix'], DI::l10n()->t('The Matrix address will be published so that people can follow you there.')], - '$homepage' => ['homepage', DI::l10n()->t('Homepage URL:'), $profile['homepage'], $homepage_help_text], - '$pub_keywords' => ['pub_keywords', DI::l10n()->t('Public Keywords:'), $profile['pub_keywords'], DI::l10n()->t('(Used for suggesting potential friends, can be seen by others)')], - '$prv_keywords' => ['prv_keywords', DI::l10n()->t('Private Keywords:'), $profile['prv_keywords'], DI::l10n()->t('(Used for searching profiles, never shown to others)')], - '$custom_fields_description' => DI::l10n()->t("

Custom fields appear on your profile page.

+ '$l10n' => [ + 'profile_action' => $this->t('Profile Actions'), + 'banner' => $this->t('Edit Profile Details'), + 'submit' => $this->t('Submit'), + 'profpic' => $this->t('Change Profile Photo'), + 'viewprof' => $this->t('View Profile'), + 'personal_section' => $this->t('Personal'), + 'picture_section' => $this->t('Profile picture'), + 'location_section' => $this->t('Location'), + 'miscellaneous_section' => $this->t('Miscellaneous'), + 'custom_fields_section' => $this->t('Custom Profile Fields'), + 'profile_photo' => $this->t('Upload Profile Photo'), + 'custom_fields_description' => $this->t('

Custom fields appear on your profile page.

You can use BBCodes in the field values.

Reorder by dragging the field title.

Empty the label field to remove a custom field.

-

Non-public fields can only be seen by the selected Friendica contacts or the Friendica contacts in the selected circles.

", - 'profile/' . $profile['nickname'] . '/profile' - ), +

Non-public fields can only be seen by the selected Friendica contacts or the Friendica contacts in the selected circles.

', + 'profile/' . $owner['nickname'] . '/profile' + ), + ], + + '$personal_account' => $personal_account, + + '$form_security_token' => self::getFormSecurityToken('settings_profile'), + '$form_security_token_photo' => self::getFormSecurityToken('settings_profile_photo'), + + '$profpiclink' => '/profile/' . $owner['nickname'] . '/photos', + + '$nickname' => $owner['nickname'], + '$name' => ['name', $this->t('Display name:'), $owner['name']], + '$about' => ['about', $this->t('Description:'), $owner['about']], + '$dob' => Temporal::getDateofBirthField($owner['dob'], $owner['timezone']), + '$address' => ['address', $this->t('Street Address:'), $owner['address']], + '$locality' => ['locality', $this->t('Locality/City:'), $owner['locality']], + '$region' => ['region', $this->t('Region/State:'), $owner['region']], + '$postal_code' => ['postal_code', $this->t('Postal/Zip Code:'), $owner['postal-code']], + '$country_name' => ['country_name', $this->t('Country:'), $owner['country-name']], + '$age' => ((intval($owner['dob'])) ? '(' . $this->t('Age: ') . $this->tt('%d year old', '%d years old', Temporal::getAgeByTimezone($owner['dob'], $owner['timezone'])) . ')' : ''), + '$xmpp' => ['xmpp', $this->t('XMPP (Jabber) address:'), $owner['xmpp'], $this->t('The XMPP address will be published so that people can follow you there.')], + '$matrix' => ['matrix', $this->t('Matrix (Element) address:'), $owner['matrix'], $this->t('The Matrix address will be published so that people can follow you there.')], + '$homepage' => ['homepage', $this->t('Homepage URL:'), $owner['homepage'], $homepage_help_text], + '$pub_keywords' => ['pub_keywords', $this->t('Public Keywords:'), $owner['pub_keywords'], $this->t('(Used for suggesting potential friends, can be seen by others)')], + '$prv_keywords' => ['prv_keywords', $this->t('Private Keywords:'), $owner['prv_keywords'], $this->t('(Used for searching profiles, never shown to others)')], '$custom_fields' => $custom_fields, ]); - $arr = ['profile' => $profile, 'entry' => $o]; + $arr = ['profile' => $owner, 'entry' => $o]; Hook::callAll('profile_edit', $arr); return $o; } - private static function getProfileFieldsFromInput(int $uid, array $profileFieldInputs, array $profileFieldOrder): ProfileFields + private function getProfileFieldsFromInput(int $uid, array $profileFieldInputs, array $profileFieldOrder): ProfileField\Collection\ProfileFields { - $profileFields = new ProfileFields(); + $profileFields = new ProfileField\Collection\ProfileFields(); // Returns an associative array of id => order values $profileFieldOrder = array_flip($profileFieldOrder); // Creation of the new field if (!empty($profileFieldInputs['new']['label'])) { - $permissionSet = DI::permissionSet()->selectOrCreate(DI::permissionSetFactory()->createFromString( + $permissionSet = $this->permissionSetRepo->selectOrCreate($this->permissionSetFactory->createFromString( $uid, - DI::aclFormatter()->toString($profileFieldInputs['new']['contact_allow'] ?? ''), - DI::aclFormatter()->toString($profileFieldInputs['new']['circle_allow'] ?? ''), - DI::aclFormatter()->toString($profileFieldInputs['new']['contact_deny'] ?? ''), - DI::aclFormatter()->toString($profileFieldInputs['new']['circle_deny'] ?? '') + $this->aclFormatter->toString($profileFieldInputs['new']['contact_allow'] ?? ''), + $this->aclFormatter->toString($profileFieldInputs['new']['circle_allow'] ?? ''), + $this->aclFormatter->toString($profileFieldInputs['new']['contact_deny'] ?? ''), + $this->aclFormatter->toString($profileFieldInputs['new']['circle_deny'] ?? '') )); - $profileFields->append(DI::profileFieldFactory()->createFromValues( + $profileFields->append($this->profileFieldFactory->createFromValues( $uid, $profileFieldOrder['new'], $profileFieldInputs['new']['label'], @@ -302,15 +332,15 @@ class Index extends BaseSettings unset($profileFieldOrder['new']); foreach ($profileFieldInputs as $id => $profileFieldInput) { - $permissionSet = DI::permissionSet()->selectOrCreate(DI::permissionSetFactory()->createFromString( + $permissionSet = $this->permissionSetRepo->selectOrCreate($this->permissionSetFactory->createFromString( $uid, - DI::aclFormatter()->toString($profileFieldInput['contact_allow'] ?? ''), - DI::aclFormatter()->toString($profileFieldInput['circle_allow'] ?? ''), - DI::aclFormatter()->toString($profileFieldInput['contact_deny'] ?? ''), - DI::aclFormatter()->toString($profileFieldInput['circle_deny'] ?? '') + $this->aclFormatter->toString($profileFieldInput['contact_allow'] ?? ''), + $this->aclFormatter->toString($profileFieldInput['circle_allow'] ?? ''), + $this->aclFormatter->toString($profileFieldInput['contact_deny'] ?? ''), + $this->aclFormatter->toString($profileFieldInput['circle_deny'] ?? '') )); - $profileFields->append(DI::profileFieldFactory()->createFromValues( + $profileFields->append($this->profileFieldFactory->createFromValues( $uid, $profileFieldOrder[$id], $profileFieldInput['label'], @@ -322,22 +352,20 @@ class Index extends BaseSettings return $profileFields; } - private static function cleanKeywords($keywords) + private static function cleanKeywords($keywords): string { $keywords = str_replace(',', ' ', $keywords); $keywords = explode(' ', $keywords); $cleaned = []; foreach ($keywords as $keyword) { - $keyword = trim(strtolower($keyword)); + $keyword = trim($keyword); $keyword = trim($keyword, '#'); if ($keyword != '') { $cleaned[] = $keyword; } } - $keywords = implode(', ', $cleaned); - - return $keywords; + return implode(', ', $cleaned); } } diff --git a/src/Security/PermissionSet/Repository/PermissionSet.php b/src/Security/PermissionSet/Repository/PermissionSet.php index 58cf6e42f..5abfb9305 100644 --- a/src/Security/PermissionSet/Repository/PermissionSet.php +++ b/src/Security/PermissionSet/Repository/PermissionSet.php @@ -211,7 +211,7 @@ class PermissionSet extends BaseRepository } /** - * Selects or creates a PermissionSet based on it's fields + * Selects or creates a PermissionSet based on its fields * * @param Entity\PermissionSet $permissionSet * diff --git a/view/templates/settings/profile/index.tpl b/view/templates/settings/profile/index.tpl index 69812c5a8..6540ab3c6 100644 --- a/view/templates/settings/profile/index.tpl +++ b/view/templates/settings/profile/index.tpl @@ -1,121 +1,131 @@ -

{{$banner}}

+ -{{$default nofilter}} +

{{$l10n.banner}}

-
-
+ + + + +
+

{{$l10n.picture_section}} »

+ +
+
+ +
-
- - -
-
-
- - -
-
-
- {{$dob nofilter}} -
-
- {{$hide_friends nofilter}} -
- -
-
-
- - -
-
-
- - -
-
-
- - -
-
-
- - -
-
-
- - -
-
-
- -
-
-
- - -
-
{{$homepage.3}}
-
-
- - -
-
{{$xmpp.3}}
-
-
- - -
-
{{$matrix.3}}
-
-
- - -
-
{{$pub_keywords.3}}
-
-
- - -
-
{{$prv_keywords.3}}
-
-
- -
-
+ +
+

{{$l10n.personal_section}} »

+ + +
+

{{$l10n.location_section}} »

+ +
+ +
+

{{$l10n.custom_fields_section}} »

+
-
- -

{{$banner}}

- - - - -
-
- - - -
-

{{$lbl_picture_section}} »

- -
-
- -
- - - -
-

{{$lbl_personal_section}} »

- -
- -
-

{{$lbl_location_section}} »

- -
- -
-

{{$lbl_custom_fields_section}} »

- -
-
-
- From e31d90eadb8321f82513d9f64c7ec8ed2fa9c8bf Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 11 Aug 2023 01:05:02 +0200 Subject: [PATCH 03/25] Replace references to profile.name by user.username --- src/Model/Contact.php | 6 ++--- src/Model/Profile.php | 10 ++++----- src/Model/User.php | 22 ++++--------------- src/Module/Settings/Account.php | 2 +- src/Module/Settings/Profile/Index.php | 9 ++++---- view/templates/settings/profile/index.tpl | 2 +- .../frio/templates/settings/profile/index.tpl | 2 +- 7 files changed, 19 insertions(+), 34 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index d91abe9bc..35ca4e49e 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -788,10 +788,10 @@ class Contact /** * Updates the self-contact for the provided user id * - * @param int $uid - * @param bool $update_avatar Force the avatar update + * @param int $uid + * @param bool $update_avatar Force the avatar update * @return bool "true" if updated - * @throws HTTPException\InternalServerErrorException + * @throws \Exception */ public static function updateSelfFromUserID(int $uid, bool $update_avatar = false): bool { diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 0602df10a..c1a350673 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -37,6 +37,7 @@ use Friendica\DI; use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPException; +use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Protocol\Activity; use Friendica\Protocol\Diaspora; use Friendica\Security\PermissionSet\Entity\PermissionSet; @@ -93,10 +94,11 @@ class Profile /** * Update a profile entry and distribute the changes if needed * - * @param array $fields Profile fields to update - * @param integer $uid User id + * @param array $fields Profile fields to update + * @param integer $uid User id * * @return boolean Whether update was successful + * @throws \Exception */ public static function update(array $fields, int $uid): bool { @@ -116,10 +118,6 @@ class Profile return false; } - if ($old_owner['name'] != $owner['name']) { - User::update(['username' => $owner['name']], $uid); - } - $profile_fields = ['postal-code', 'dob', 'prv_keywords', 'homepage']; foreach ($profile_fields as $field) { if ($old_owner[$field] != $owner[$field]) { diff --git a/src/Model/User.php b/src/Model/User.php index 18da3e956..af7a81a15 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -37,6 +37,7 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Module; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Security\TwoFactor\Model\AppSpecificPassword; use Friendica\Network\HTTPException; use Friendica\Object\Image; @@ -1328,33 +1329,18 @@ class User /** * Update a user entry and distribute the changes if needed * - * @param array $fields + * @param array $fields * @param integer $uid * @return boolean + * @throws Exception */ public static function update(array $fields, int $uid): bool { - $old_owner = self::getOwnerDataById($uid); - if (empty($old_owner)) { - return false; - } - if (!DBA::update('user', $fields, ['uid' => $uid])) { return false; } - $update = Contact::updateSelfFromUserID($uid); - - $owner = self::getOwnerDataById($uid); - if (empty($owner)) { - return false; - } - - if ($old_owner['name'] != $owner['name']) { - Profile::update(['name' => $owner['name']], $uid); - } - - if ($update) { + if (Contact::updateSelfFromUserID($uid)) { Profile::publishUpdate($uid); } diff --git a/src/Module/Settings/Account.php b/src/Module/Settings/Account.php index 1039b92e2..8ff00addb 100644 --- a/src/Module/Settings/Account.php +++ b/src/Module/Settings/Account.php @@ -573,7 +573,7 @@ class Account extends BaseSettings '$delete_openid' => ['delete_openid', DI::l10n()->t('Delete OpenID URL'), false, ''], '$h_basic' => DI::l10n()->t('Basic Settings'), - '$username' => ['username', DI::l10n()->t('Full Name:'), $username, '', false, 'autocomplete="off"'], + '$username' => ['username', DI::l10n()->t('Display name:'), $username, '', false, 'autocomplete="off"'], '$email' => ['email', DI::l10n()->t('Email Address:'), $email, '', '', 'autocomplete="off"', 'email'], '$timezone' => ['timezone_select', DI::l10n()->t('Your Timezone:'), Temporal::getTimezoneSelect($timezone), ''], '$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], diff --git a/src/Module/Settings/Profile/Index.php b/src/Module/Settings/Profile/Index.php index c18c72a4e..38d816833 100644 --- a/src/Module/Settings/Profile/Index.php +++ b/src/Module/Settings/Profile/Index.php @@ -111,8 +111,8 @@ class Index extends BaseSettings } } - $name = trim($request['name'] ?? ''); - if (!$name) { + $username = trim($request['username'] ?? ''); + if (!$username) { $this->systemMessages->addNotice($this->t('Display Name is required.')); return; } @@ -141,9 +141,10 @@ class Index extends BaseSettings $this->profileFieldRepo->saveCollectionForUser($this->session->getLocalUserId(), $profileFieldsNew); + User::update(['username' => $username], $this->session->getLocalUserId()); + $result = Profile::update( [ - 'name' => $name, 'about' => $about, 'dob' => $dob, 'address' => $address, @@ -279,7 +280,7 @@ class Index extends BaseSettings '$profpiclink' => '/profile/' . $owner['nickname'] . '/photos', '$nickname' => $owner['nickname'], - '$name' => ['name', $this->t('Display name:'), $owner['name']], + '$username' => ['username', $this->t('Display name:'), $owner['name']], '$about' => ['about', $this->t('Description:'), $owner['about']], '$dob' => Temporal::getDateofBirthField($owner['dob'], $owner['timezone']), '$address' => ['address', $this->t('Street Address:'), $owner['address']], diff --git a/view/templates/settings/profile/index.tpl b/view/templates/settings/profile/index.tpl index 6540ab3c6..64c9daee0 100644 --- a/view/templates/settings/profile/index.tpl +++ b/view/templates/settings/profile/index.tpl @@ -48,7 +48,7 @@

{{$l10n.personal_section}} »