. /** * Allows administrators to define additional profile fields for the users of a GNU social installation. * * @category Widget * @package GNU social * @author Max Shinn * @author Diogo Cordeiro * @copyright 2011-2019 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ defined('GNUSOCIAL') || die(); class ProfilefieldsAdminPanelAction extends AdminPanelAction { public function title(): string { return _m('Profile fields'); } public function getInstructions(): string { return _m('GNU Social custom profile fields'); } public function showForm(): void { $form = new ProfilefieldsAdminForm($this); $form->show(); } public function saveSettings(): void { $field = GNUsocialProfileExtensionField::getKV('id', $this->trimmed('id')); if (!$field) { $field = new GNUsocialProfileExtensionField(); $field->systemname = $this->trimmed('systemname'); if (!gnusocial_field_systemname_validate($field->systemname)) { $this->clientError(_m('Internal system name must be unique and consist of only alphanumeric characters!')); } } $field->title = $this->trimmed('title'); $field->description = $this->trimmed('description'); $field->type = $this->trimmed('type'); if ($field->id) { if ($field->validate()) { $field->update(); } else { $this->clientError(_m('There was an error with the field data.')); } } else { $field->insert(); } } } class ProfilefieldsAdminForm extends AdminForm { public function id(): string { return 'form_profilefields_admin_panel'; } public function formClass(): string { return 'form_settings'; } public function action(): string { return '/admin/profilefields'; } public function formData(): void { $title = null; $description = null; $type = null; $systemname = null; $id = null; $fieldsettitle = _m("New Profile Field"); // Edit a field if ($this->out->trimmed('edit')) { $field = GNUsocialProfileExtensionField::getKV('id', $this->out->trimmed('edit')); $title = $field->title; $description = $field->description; $type = $field->type; $systemname = $field->systemname; $this->out->hidden('id', $field->id, 'id'); $fieldsettitle = _m("Edit Profile Field"); } // Don't show the list of all fields when editing one else { $this->out->elementStart('fieldset'); $this->out->element('legend', null, _m('Existing Custom Profile Fields')); $this->out->elementStart('ul', 'form_data'); $fields = GNUsocialProfileExtensionField::allFields(); foreach ($fields as $field) { $this->li(); $this->out->elementStart('div'); $this->out->element( 'a', array('href' => '/admin/profilefields?edit=' . $field->id), $field->title ); $this->out->text(' (' . $field->type . '): ' . $field->description); $this->out->elementEnd('div'); $this->unli(); } $this->out->elementEnd('ul'); $this->out->elementEnd('fieldset'); } // New fields $this->out->elementStart('fieldset'); $this->out->element('legend', null, $fieldsettitle); $this->out->elementStart('ul', 'form_data'); $this->li(); $this->out->input( 'title', _m('Title'), $title, _m('The title of the field') ); $this->unli(); $this->li(); $this->out->input( 'systemname', _m('Internal name'), $systemname, _m('The alphanumeric name used internally for this field. Also the key used for federation (e.g. ActivityPub and OStatus) user info.') ); $this->unli(); $this->li(); $this->out->input( 'description', _m('Description'), $description, _m('An optional more detailed description of the field') ); $this->unli(); $this->li(); $this->out->dropdown( 'type', _m('Type'), array('text' => _m("Text"), 'str' => _m("String")), _m('The type of the datafield'), false, $type ); $this->unli(); $this->out->elementEnd('ul'); $this->out->elementEnd('fieldset'); } /** * Action elements * * @return void * @throws Exception */ public function formActions(): void { $this->out->submit('submit', _m('Save'), 'submit', null, _m('Save new field')); } }