[ExtendedProfile] Hide 'Extra fields' from profile when no field was created by the sysadmin

This commit is contained in:
Diogo Cordeiro 2019-08-10 20:04:43 +01:00 committed by Diogo Peralta Cordeiro
parent 9a9fa89a0c
commit 3bf010ddd8
6 changed files with 118 additions and 102 deletions

View File

@ -50,8 +50,8 @@ class ProfileDetailAction extends ShowstreamAction
$this->element( $this->element(
'a', 'a',
array('href' => common_local_url('profiledetailsettings'), array('href' => common_local_url('profiledetailsettings'),
// TRANS: Link title for link on user profile. // TRANS: Link title for link on user profile.
'title' => _m('Edit extended profile settings')), 'title' => _m('Edit extended profile settings')),
// TRANS: Link text for link on user profile. // TRANS: Link text for link on user profile.
_m('Edit') _m('Edit')
); );

View File

@ -597,7 +597,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
$user = common_current_user(); $user = common_current_user();
$profile = $user->getProfile(); $profile = $user->getProfile();
foreach ($fields as $field) { foreach ($fields as $field) {
$val = $action->trimmed('extprofile-'.$field->systemname); $val = $action->trimmed('extprofile-' . $field->systemname);
if (empty($val)) { if (empty($val)) {
continue; continue;

View File

@ -104,7 +104,7 @@ class ProfilefieldsAdminPanelAction extends AdminPanelAction
{ {
if ($this->arg('save')) { if ($this->arg('save')) {
return $this->saveField(); return $this->saveField();
} else if ($this->arg('remove')) { } elseif ($this->arg('remove')) {
return $this->removeField(); return $this->removeField();
} }
@ -221,7 +221,7 @@ class ProfilefieldsAdminForm extends AdminForm
*/ */
public function formActions(): void public function formActions(): void
{ {
$this->out->submit('save', _m('BUTTON','Save'), 'submit', null, _m('Save field')); $this->out->submit('save', _m('BUTTON', 'Save'), 'submit', null, _m('Save field'));
if ($this->out->trimmed('edit')) { if ($this->out->trimmed('edit')) {
$this->out->submit('remove', _m('BUTTON', 'Remove'), 'submit', null, _m('Remove field')); $this->out->submit('remove', _m('BUTTON', 'Remove'), 'submit', null, _m('Remove field'));
} }

View File

@ -57,7 +57,7 @@ class ExtendedProfile
$detail->profile_id = $this->profile->getID(); $detail->profile_id = $this->profile->getID();
$detail->find(); $detail->find();
$fields = array(); $fields = [];
while ($detail->fetch()) { while ($detail->fetch()) {
$fields[$detail->field_name][] = clone($detail); $fields[$detail->field_name][] = clone($detail);
@ -115,7 +115,7 @@ class ExtendedProfile
public function getPhones() public function getPhones()
{ {
$phones = (isset($this->fields['phone'])) ? $this->fields['phone'] : null; $phones = (isset($this->fields['phone'])) ? $this->fields['phone'] : null;
$pArrays = array(); $pArrays = [];
if (empty($phones)) { if (empty($phones)) {
$pArrays[] = array( $pArrays[] = array(
@ -148,7 +148,7 @@ class ExtendedProfile
public function getIms() public function getIms()
{ {
$ims = (isset($this->fields['im'])) ? $this->fields['im'] : null; $ims = (isset($this->fields['im'])) ? $this->fields['im'] : null;
$iArrays = array(); $iArrays = [];
if (empty($ims)) { if (empty($ims)) {
$iArrays[] = array( $iArrays[] = array(
@ -176,7 +176,7 @@ class ExtendedProfile
public function getWebsites() public function getWebsites()
{ {
$sites = (isset($this->fields['website'])) ? $this->fields['website'] : null; $sites = (isset($this->fields['website'])) ? $this->fields['website'] : null;
$wArrays = array(); $wArrays = [];
if (empty($sites)) { if (empty($sites)) {
$wArrays[] = array( $wArrays[] = array(
@ -207,7 +207,7 @@ class ExtendedProfile
$start = (isset($this->fields['start'])) ? $this->fields['start'] : null; $start = (isset($this->fields['start'])) ? $this->fields['start'] : null;
$end = (isset($this->fields['end'])) ? $this->fields['end'] : null; $end = (isset($this->fields['end'])) ? $this->fields['end'] : null;
$eArrays = array(); $eArrays = [];
if (empty($companies)) { if (empty($companies)) {
$eArrays[] = array( $eArrays[] = array(
@ -245,7 +245,7 @@ class ExtendedProfile
$descs = (isset($this->fields['degree_descr'])) ? $this->fields['degree_descr'] : null; $descs = (isset($this->fields['degree_descr'])) ? $this->fields['degree_descr'] : null;
$start = (isset($this->fields['school_start'])) ? $this->fields['school_start'] : null; $start = (isset($this->fields['school_start'])) ? $this->fields['school_start'] : null;
$end = (isset($this->fields['school_end'])) ? $this->fields['school_end'] : null; $end = (isset($this->fields['school_end'])) ? $this->fields['school_end'] : null;
$iArrays = array(); $iArrays = [];
if (empty($schools)) { if (empty($schools)) {
$iArrays[] = array( $iArrays[] = array(
@ -287,10 +287,12 @@ class ExtendedProfile
*/ */
public function getSections() public function getSections()
{ {
$display_extra = false;
$gsefields = GNUsocialProfileExtensionField::allFields(); $gsefields = GNUsocialProfileExtensionField::allFields();
$extra_fields = []; $extra_fields = [];
gnusocial_profile_merge($this->profile); gnusocial_profile_merge($this->profile);
foreach ($gsefields as $field) { foreach ($gsefields as $field) {
$display_extra = true;
$field_key = $field->systemname; $field_key = $field->systemname;
switch ($field->type) { switch ($field->type) {
case 'text': case 'text':
@ -298,101 +300,105 @@ class ExtendedProfile
break; break;
case 'str': case 'str':
default: default:
$extra_fields[$field_key]['type'] = 'custom-text'; $extra_fields[$field_key]['type'] = 'custom-text';
break; break;
} }
$extra_fields[$field_key]['label'] = $field->title; $extra_fields[$field_key]['label'] = $field->title;
$extra_fields[$field_key]['value'] = $this->profile->$field_key; $extra_fields[$field_key]['value'] = $this->profile->$field_key;
} }
return array(
'basic' => array( $sections = [
'basic' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Personal'), 'label' => _m('Personal'),
'fields' => array( 'fields' => [
'fullname' => array( 'fullname' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Full name'), 'label' => _m('Full name'),
'profile' => 'fullname', 'profile' => 'fullname',
'vcard' => 'fn', 'vcard' => 'fn',
), ],
'title' => array( 'title' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Title'), 'label' => _m('Title'),
'vcard' => 'title', 'vcard' => 'title',
), ],
'manager' => array( 'manager' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Manager'), 'label' => _m('Manager'),
'type' => 'person', 'type' => 'person',
'vcard' => 'x-manager', 'vcard' => 'x-manager',
), ],
'location' => array( 'location' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Location'), 'label' => _m('Location'),
'profile' => 'location' 'profile' => 'location'
), ],
'bio' => array( 'bio' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Bio'), 'label' => _m('Bio'),
'type' => 'textarea', 'type' => 'textarea',
'profile' => 'bio', 'profile' => 'bio',
), ],
'tags' => array( 'tags' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Tags'), 'label' => _m('Tags'),
'type' => 'tags', 'type' => 'tags',
'profile' => 'tags', 'profile' => 'tags',
), ],
), ],
), ],
'contact' => array( 'contact' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Contact'), 'label' => _m('Contact'),
'fields' => array( 'fields' => [
'phone' => $this->getPhones(), 'phone' => $this->getPhones(),
'im' => $this->getIms(), 'im' => $this->getIms(),
'website' => $this->getWebsites() 'website' => $this->getWebsites()
), ],
), ],
'personal' => array( 'personal' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Personal'), 'label' => _m('Personal'),
'fields' => array( 'fields' => [
'birthday' => array( 'birthday' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Birthday'), 'label' => _m('Birthday'),
'type' => 'date', 'type' => 'date',
'vcard' => 'bday', 'vcard' => 'bday',
), ],
'spouse' => array( 'spouse' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Spouse\'s name'), 'label' => _m('Spouse\'s name'),
'vcard' => 'x-spouse', 'vcard' => 'x-spouse',
), ],
'kids' => array( 'kids' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Kids\' names') 'label' => _m('Kids\' names')
), ],
), ],
), ],
'experience' => array( 'experience' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Work experience'), 'label' => _m('Work experience'),
'fields' => array( 'fields' => [
'experience' => $this->getExperiences() 'experience' => $this->getExperiences()
), ],
), ],
'education' => array( 'education' => [
// TRANS: Field label for extended profile properties. // TRANS: Field label for extended profile properties.
'label' => _m('Education'), 'label' => _m('Education'),
'fields' => array( 'fields' => [
'education' => $this->getEducation() 'education' => $this->getEducation()
), ],
), ],
'extra' => [ ];
'label' => _m('Extra fields'), if ($display_extra) {
$sections['extra'] = [
'label' => _m('Additional information'),
'fields' => $extra_fields, 'fields' => $extra_fields,
] ];
); }
return $sections;
} }
} }

View File

@ -557,7 +557,7 @@ class ExtendedProfileWidget extends Form
break; break;
case 'custom-text': case 'custom-text':
case 'custom-textarea': case 'custom-textarea':
$this->out->text(isset($field['value']) ? $field['value'] : null); $this->out->text(isset($field['value']) ? $field['value'] : null);
break; break;
case 'date': case 'date':
$value = $this->ext->getDateValue($name); $value = $this->ext->getDateValue($name);

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-08-14 15:06+0100\n" "POT-Creation-Date: 2019-08-14 15:07+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -75,72 +75,72 @@ msgid "Institution"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:310 lib/extendedprofile.php:359 #: lib/extendedprofile.php:313 lib/extendedprofile.php:362
msgid "Personal" msgid "Personal"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:314 #: lib/extendedprofile.php:317
msgid "Full name" msgid "Full name"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:320 actions/profilefieldsadminpanel.php:137 #: lib/extendedprofile.php:323 actions/profilefieldsadminpanel.php:180
msgid "Title" msgid "Title"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:325 #: lib/extendedprofile.php:328
msgid "Manager" msgid "Manager"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:331 #: lib/extendedprofile.php:334
msgid "Location" msgid "Location"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:336 #: lib/extendedprofile.php:339
msgid "Bio" msgid "Bio"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:342 #: lib/extendedprofile.php:345
msgid "Tags" msgid "Tags"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:350 #: lib/extendedprofile.php:353
msgid "Contact" msgid "Contact"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:363 #: lib/extendedprofile.php:366
msgid "Birthday" msgid "Birthday"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:369 #: lib/extendedprofile.php:372
msgid "Spouse's name" msgid "Spouse's name"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:374 #: lib/extendedprofile.php:377
msgid "Kids' names" msgid "Kids' names"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:380 #: lib/extendedprofile.php:383
msgid "Work experience" msgid "Work experience"
msgstr "" msgstr ""
#. TRANS: Field label for extended profile properties. #. TRANS: Field label for extended profile properties.
#: lib/extendedprofile.php:387 #: lib/extendedprofile.php:390
msgid "Education" msgid "Education"
msgstr "" msgstr ""
#: lib/extendedprofile.php:393 #: lib/extendedprofile.php:398
msgid "Extra fields" msgid "Additional information"
msgstr "" msgstr ""
#. TRANS: Title for extended profile entry deletion dialog. #. TRANS: Title for extended profile entry deletion dialog.
@ -196,7 +196,7 @@ msgstr ""
#. TRANS: Field label in education area of extended profile. #. TRANS: Field label in education area of extended profile.
#. TRANS: Field label in education edit area of extended profile. #. TRANS: Field label in education edit area of extended profile.
#: lib/extendedprofilewidget.php:433 lib/extendedprofilewidget.php:487 #: lib/extendedprofilewidget.php:433 lib/extendedprofilewidget.php:487
#: actions/profilefieldsadminpanel.php:153 #: actions/profilefieldsadminpanel.php:196
msgid "Description" msgid "Description"
msgstr "" msgstr ""
@ -212,7 +212,7 @@ msgid "TYPE: %s"
msgstr "" msgstr ""
#. TRANS: Button text for saving extended profile properties. #. TRANS: Button text for saving extended profile properties.
#: lib/extendedprofilewidget.php:667 #: lib/extendedprofilewidget.php:667 actions/profilefieldsadminpanel.php:224
msgctxt "BUTTON" msgctxt "BUTTON"
msgid "Save" msgid "Save"
msgstr "" msgstr ""
@ -224,128 +224,138 @@ msgid "Save details"
msgstr "" msgstr ""
#. TRANS: Title for extended profile settings. #. TRANS: Title for extended profile settings.
#: actions/profiledetailsettings.php:29 #. TRANS: %%site.name%% is the name of the site.
#: actions/profiledetailsettings.php:35
msgid "Extended profile settings" msgid "Extended profile settings"
msgstr "" msgstr ""
#. TRANS: Message given submitting a form with an unknown action. #. TRANS: Message given submitting a form with an unknown action.
#: actions/profiledetailsettings.php:53 #: actions/profiledetailsettings.php:59
msgid "Unexpected form submission." msgid "Unexpected form submission."
msgstr "" msgstr ""
#. TRANS: Success message after saving extended profile details. #. TRANS: Success message after saving extended profile details.
#: actions/profiledetailsettings.php:102 #: actions/profiledetailsettings.php:108
msgid "Details saved." msgid "Details saved."
msgstr "" msgstr ""
#. TRANS: Exception thrown when no date was entered in a required date field. #. TRANS: Exception thrown when no date was entered in a required date field.
#. TRANS: %s is the field name. #. TRANS: %s is the field name.
#: actions/profiledetailsettings.php:112 #: actions/profiledetailsettings.php:118
#, php-format #, php-format
msgid "You must supply a date for \"%s\"." msgid "You must supply a date for \"%s\"."
msgstr "" msgstr ""
#. TRANS: Exception thrown on incorrect data input. #. TRANS: Exception thrown on incorrect data input.
#. TRANS: %1$s is a field name, %2$s is the incorrect input. #. TRANS: %1$s is a field name, %2$s is the incorrect input.
#: actions/profiledetailsettings.php:124 #: actions/profiledetailsettings.php:130
#, php-format #, php-format
msgid "Invalid date entered for \"%1$s\": %2$s." msgid "Invalid date entered for \"%1$s\": %2$s."
msgstr "" msgstr ""
#. TRANS: Exception thrown when entering an invalid URL. #. TRANS: Exception thrown when entering an invalid URL.
#. TRANS: %s is the invalid URL. #. TRANS: %s is the invalid URL.
#: actions/profiledetailsettings.php:241 #: actions/profiledetailsettings.php:247
#, php-format #, php-format
msgid "Invalid URL: %s." msgid "Invalid URL: %s."
msgstr "" msgstr ""
#. TRANS: Server error displayed when a field could not be saved in the database. #. TRANS: Server error displayed when a field could not be saved in the database.
#: actions/profiledetailsettings.php:484 actions/profiledetailsettings.php:497 #: actions/profiledetailsettings.php:490 actions/profiledetailsettings.php:503
msgid "Could not save profile details." msgid "Could not save profile details."
msgstr "" msgstr ""
#. TRANS: Validation error in form for profile settings. #. TRANS: Validation error in form for profile settings.
#. TRANS: %s is an invalid tag. #. TRANS: %s is an invalid tag.
#: actions/profiledetailsettings.php:539 #: actions/profiledetailsettings.php:545
#, php-format #, php-format
msgid "Invalid tag: \"%s\"." msgid "Invalid tag: \"%s\"."
msgstr "" msgstr ""
#. TRANS: Server error thrown when user profile settings could not be saved. #. TRANS: Server error thrown when user profile settings could not be saved.
#: actions/profiledetailsettings.php:578 #: actions/profiledetailsettings.php:584
msgid "Could not save profile." msgid "Could not save profile."
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:34 #: actions/profilefieldsadminpanel.php:39
msgid "Profile fields" msgid "Profile fields"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:39 #: actions/profilefieldsadminpanel.php:49
msgid "GNU Social custom profile fields" msgid "GNU Social custom profile fields"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:55 #: actions/profilefieldsadminpanel.php:65
msgid "" msgid ""
"Internal system name must be unique and consist of only alphanumeric " "Internal system name must be unique and consist of only alphanumeric "
"characters!" "characters!"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:65 #: actions/profilefieldsadminpanel.php:75
msgid "There was an error with the field data." msgid "There was an error with the field data."
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:97 #: actions/profilefieldsadminpanel.php:87
msgid "Field not found."
msgstr ""
#: actions/profilefieldsadminpanel.php:140
msgid "New Profile Field" msgid "New Profile Field"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:106 #: actions/profilefieldsadminpanel.php:149
msgid "Edit Profile Field" msgid "Edit Profile Field"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:110 #: actions/profilefieldsadminpanel.php:153
msgid "Existing Custom Profile Fields" msgid "Existing Custom Profile Fields"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:139 #: actions/profilefieldsadminpanel.php:182
msgid "The title of the field" msgid "The title of the field"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:145 #: actions/profilefieldsadminpanel.php:188
msgid "Internal name" msgid "Internal name"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:147 #: actions/profilefieldsadminpanel.php:190
msgid "" msgid ""
"The alphanumeric name used internally for this field. Also the key used for " "The alphanumeric name used internally for this field. Also the key used for "
"federation (e.g. ActivityPub and OStatus) user info." "federation (e.g. ActivityPub and OStatus) user info."
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:155 #: actions/profilefieldsadminpanel.php:198
msgid "An optional more detailed description of the field" msgid "An optional more detailed description of the field"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:161 #: actions/profilefieldsadminpanel.php:204
msgid "Type" msgid "Type"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:162 #: actions/profilefieldsadminpanel.php:205
msgid "Text" msgid "Text"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:163 #: actions/profilefieldsadminpanel.php:206
msgid "String" msgid "String"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:164 #: actions/profilefieldsadminpanel.php:207
msgid "The type of the datafield" msgid "The type of the datafield"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:181 #: actions/profilefieldsadminpanel.php:224
msgid "Save" msgid "Save field"
msgstr "" msgstr ""
#: actions/profilefieldsadminpanel.php:181 #: actions/profilefieldsadminpanel.php:226
msgid "Save new field" msgctxt "BUTTON"
msgid "Remove"
msgstr ""
#: actions/profilefieldsadminpanel.php:226
msgid "Remove field"
msgstr "" msgstr ""
#. TRANS: Link title for link on user profile. #. TRANS: Link title for link on user profile.