From 60bb66e18defa3743340e7b335294bf5e76d39b5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 21 Nov 2021 18:49:07 -0500 Subject: [PATCH] [frio] Make connector settings panels keyboard activated - Keep the connector panel open after form was submitted --- doc/Addons.md | 56 ++++++++ mod/settings.php | 31 +++-- view/templates/settings/addon/connector.tpl | 34 +++++ view/templates/settings/connectors.tpl | 71 +++++----- view/theme/frio/css/style.css | 6 +- .../templates/settings/addon/connector.tpl | 36 ++++++ .../frio/templates/settings/connectors.tpl | 121 ++++++++++-------- 7 files changed, 256 insertions(+), 99 deletions(-) create mode 100644 view/templates/settings/addon/connector.tpl create mode 100644 view/theme/frio/templates/settings/addon/connector.tpl diff --git a/doc/Addons.md b/doc/Addons.md index cf4fbdab12..578cffe7ca 100644 --- a/doc/Addons.md +++ b/doc/Addons.md @@ -298,6 +298,62 @@ $data = [ Called when the Addon Settings pages are submitted. `$b` is the $_POST array. +### connector_settings +Called when generating the HTML for a connector addon settings page. +`$data` is an array containing: + +- **connector** (output): Required. The addon folder name. +- **title** (output): Required. The addon settings panel title. +- **image** (output): Required. The relative path of the logo image of the platform/protocol this addon is connecting to, max size 48x48px. +- **enabled** (output): Optional. If set to a falsy value, the connector image will be dimmed. +- **html** (output): Optional. Raw HTML of the addon form elements. Both the `
` tags and the submit buttons are taken care of elsewhere. +- **submit** (output): Optional. If unset, a default submit button with `name="-submit"` will be generated. + Can take different value types: + - **string**: The label to replace the default one. + - **associative array**: A list of submit button, the key is the value of the `name` attribute, the value is the displayed label. + The first submit button in this list is considered the main one and themes might emphasize its display. + +#### Examples + +##### With default submit button +```php +$data = [ + 'connector' => 'diaspora', + 'title' => DI::l10n()->t('Diaspora Export'), + 'image' => 'images/diaspora-logo.png', + 'enabled' => $enabled, + 'html' => $html, +]; +``` + +##### With custom submit button label and no logo dim +```php +$data = [ + 'connector' => 'ifttt', + 'title' => DI::l10n()->t('IFTTT Mirror'), + 'image' => 'addon/ifttt/ifttt.png', + 'html' => $html, + 'submit' => DI::l10n()->t('Generate new key'), +]; +``` + +##### With conditional submit buttons +```php +$submit = ['pumpio-submit' => DI::l10n()->t('Save Settings')]; +if ($oauth_token && $oauth_token_secret) { + $submit['pumpio-delete'] = DI::l10n()->t('Delete this preset'); +} + +$data = [ + 'connector' => 'pumpio', + 'title' => DI::l10n()->t('Pump.io Import/Export/Mirror'), + 'image' => 'images/pumpio.png', + 'enabled' => $enabled, + 'html' => $html, + 'submit' => $submit, +]; +``` + ### profile_post Called when posting a profile page. `$b` is the $_POST array. diff --git a/mod/settings.php b/mod/settings.php index 54484d8a90..632517f165 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -72,7 +72,7 @@ function settings_post(App $a) $user = User::getById($a->getLoggedInUserId()); if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] == 'connectors')) { - BaseModule::checkFormSecurityTokenRedirectOnError('/settings/connectors', 'settings_connectors'); + BaseModule::checkFormSecurityTokenRedirectOnError(DI::args()->getQueryString(), 'settings_connectors'); if (!empty($_POST['general-submit'])) { DI::pConfig()->set(local_user(), 'system', 'accept_only_sharer', intval($_POST['accept_only_sharer'])); @@ -81,7 +81,7 @@ function settings_post(App $a) DI::pConfig()->set(local_user(), 'system', 'simple_shortening', intval($_POST['simple_shortening'])); DI::pConfig()->set(local_user(), 'system', 'attach_link_title', intval($_POST['attach_link_title'])); DI::pConfig()->set(local_user(), 'ostatus', 'legacy_contact', $_POST['legacy_contact']); - } elseif (!empty($_POST['imap-submit'])) { + } elseif (!empty($_POST['mail-submit'])) { $mail_server = $_POST['mail_server'] ?? ''; $mail_port = $_POST['mail_port'] ?? ''; $mail_ssl = strtolower(trim($_POST['mail_ssl'] ?? '')); @@ -133,6 +133,7 @@ function settings_post(App $a) } Hook::callAll('connector_settings_post', $_POST); + DI::baseUrl()->redirect(DI::args()->getQueryString()); return; } @@ -507,8 +508,22 @@ function settings_content(App $a) DI::page()['htmlhead'] = ''; } - $settings_connectors = ''; - Hook::callAll('connector_settings', $settings_connectors); + $connector_settings_forms = []; + foreach (DI::dba()->selectToArray('hook', ['file', 'function'], ['hook' => 'connector_settings']) as $hook) { + $data = []; + Hook::callSingle(DI::app(), 'connector_settings', [$hook['file'], $hook['function']], $data); + + $tpl = Renderer::getMarkupTemplate('settings/addon/connector.tpl'); + $connector_settings_forms[$data['connector']] = Renderer::replaceMacros($tpl, [ + '$connector' => $data['connector'], + '$title' => $data['title'], + '$image' => $data['image'] ?? '', + '$enabled' => $data['enabled'] ?? true, + '$open' => (DI::args()->getArgv()[2] ?? '') === $data['connector'], + '$html' => $data['html'] ?? '', + '$submit' => $data['submit'] ?? DI::l10n()->t('Save Settings'), + ]); + } if ($a->isSiteAdmin()) { $diasp_enabled = DI::l10n()->t('Built-in support for %s connectivity is %s', DI::l10n()->t('Diaspora (Socialhome, Hubzilla)'), ((DI::config()->get('system', 'diaspora_enabled')) ? DI::l10n()->t('enabled') : DI::l10n()->t('disabled'))); @@ -565,11 +580,11 @@ function settings_content(App $a) '$repair_ostatus_url' => DI::baseUrl() . '/repair_ostatus', '$repair_ostatus_text' => DI::l10n()->t('Repair OStatus subscriptions'), - '$settings_connectors' => $settings_connectors, + '$connector_settings_forms' => $connector_settings_forms, - '$h_imap' => DI::l10n()->t('Email/Mailbox Setup'), - '$imap_desc' => DI::l10n()->t("If you wish to communicate with email contacts using this service \x28optional\x29, please specify how to connect to your mailbox."), - '$imap_lastcheck' => ['imap_lastcheck', DI::l10n()->t('Last successful email check:'), $mail_chk, ''], + '$h_mail' => DI::l10n()->t('Email/Mailbox Setup'), + '$mail_desc' => DI::l10n()->t("If you wish to communicate with email contacts using this service \x28optional\x29, please specify how to connect to your mailbox."), + '$mail_lastcheck' => ['mail_lastcheck', DI::l10n()->t('Last successful email check:'), $mail_chk, ''], '$mail_disabled' => $mail_disabled_message, '$mail_server' => ['mail_server', DI::l10n()->t('IMAP server name:'), $mail_server, ''], '$mail_port' => ['mail_port', DI::l10n()->t('IMAP port:'), $mail_port, ''], diff --git a/view/templates/settings/addon/connector.tpl b/view/templates/settings/addon/connector.tpl new file mode 100644 index 0000000000..c06c78195b --- /dev/null +++ b/view/templates/settings/addon/connector.tpl @@ -0,0 +1,34 @@ + +

{{$title}}

+
+
+ +

{{$title}}

+
+ {{$html nofilter}} +
+{{if $submit}} + +{{/if}} +
diff --git a/view/templates/settings/connectors.tpl b/view/templates/settings/connectors.tpl index a559aaa82c..0479e99d90 100644 --- a/view/templates/settings/connectors.tpl +++ b/view/templates/settings/connectors.tpl @@ -24,36 +24,43 @@ -
- - {{$settings_connectors nofilter}} - - {{if $mail_disabled}} - - {{else}} - -

{{$h_imap}}

-
- - {{/if}} +
+ +{{if !$mail_disabled}} +
+ + +

{{$h_mail}}

+
+ +
+{{/if}} + +{{foreach $connector_settings_forms as $addon => $connector_settings_form}} +
+ + {{$connector_settings_form nofilter}} +
+
+{{/foreach}} diff --git a/view/theme/frio/css/style.css b/view/theme/frio/css/style.css index 3891f6d24e..f96239c307 100644 --- a/view/theme/frio/css/style.css +++ b/view/theme/frio/css/style.css @@ -2974,14 +2974,12 @@ details.profile-jot-net[open] summary:before { .fakelink > h3:before { padding-right: 10px; } -.widget.fakelink > h3:before, -.settings-block.fakelink > h3:before { +.widget.fakelink > h3:before { font-family: ForkAwesome; content: "\f0da"; /* Right Plain Pointer */ } .widget > .fakelink > h3:before, -#sidebar-group-header > .fakelink > h3:before, -.settings-block > .fakelink > h3:before { +#sidebar-group-header > .fakelink > h3:before { font-family: ForkAwesome; content: "\f0d7"; /* Bottom Plain Pointer */ } diff --git a/view/theme/frio/templates/settings/addon/connector.tpl b/view/theme/frio/templates/settings/addon/connector.tpl new file mode 100644 index 0000000000..aee0e28454 --- /dev/null +++ b/view/theme/frio/templates/settings/addon/connector.tpl @@ -0,0 +1,36 @@ + +
+
+ {{$html nofilter}} +
+ +
diff --git a/view/theme/frio/templates/settings/connectors.tpl b/view/theme/frio/templates/settings/connectors.tpl index 1138a9d553..069b9d3d1c 100644 --- a/view/theme/frio/templates/settings/connectors.tpl +++ b/view/theme/frio/templates/settings/connectors.tpl @@ -1,72 +1,83 @@
-

{{$title}}

+ {{include file="section_title.tpl" title=$title}}

{{$diasp_enabled}}

{{$ostat_enabled}}

-
- +
-
-
-