[mailstream] Add a name to the addon settings submit button

- Now that each addon form is in their own form tag, we have to check whether the addon submit button was pressed.
- This was already done in every other addon but mailstream and this change will prevent unexpected loss of mailstream settings when saving any other addon settings.
pull/1141/head
Benjamin Lorteau 2021-06-27 22:15:11 -04:00
parent 93892fd25a
commit dd7f343d43
2 changed files with 46 additions and 36 deletions

View File

@ -494,49 +494,59 @@ function mailstream_addon_settings(&$a, &$s)
'$enabled' => [ '$enabled' => [
'mailstream_enabled', 'mailstream_enabled',
DI::l10n()->t('Enabled'), DI::l10n()->t('Enabled'),
$enabled], $enabled
],
'$address' => [ '$address' => [
'mailstream_address', 'mailstream_address',
DI::l10n()->t('Email Address'), DI::l10n()->t('Email Address'),
$address, $address,
DI::l10n()->t("Leave blank to use your account email address")], DI::l10n()->t("Leave blank to use your account email address")
],
'$nolikes' => [ '$nolikes' => [
'mailstream_nolikes', 'mailstream_nolikes',
DI::l10n()->t('Exclude Likes'), DI::l10n()->t('Exclude Likes'),
$nolikes, $nolikes,
DI::l10n()->t("Check this to omit mailing \"Like\" notifications")], DI::l10n()->t("Check this to omit mailing \"Like\" notifications")
],
'$attachimg' => [ '$attachimg' => [
'mailstream_attachimg', 'mailstream_attachimg',
DI::l10n()->t('Attach Images'), DI::l10n()->t('Attach Images'),
$attachimg, $attachimg,
DI::l10n()->t("Download images in posts and attach them to the email. " . DI::l10n()->t("Download images in posts and attach them to the email. " .
"Useful for reading email while offline.")], "Useful for reading email while offline.")
],
'$title' => DI::l10n()->t('Mail Stream Settings'), '$title' => DI::l10n()->t('Mail Stream Settings'),
'$submit' => DI::l10n()->t('Save Settings')]); '$submit' => DI::l10n()->t('Save Settings')]);
} }
/** /**
* Process data submitted to user's mailstream features form * Process data submitted to user's mailstream features form
* @param \Friendica\App $a
* @param array $post POST data
*/ */
function mailstream_addon_settings_post() function mailstream_addon_settings_post(\Friendica\App $a, array $post)
{ {
if ($_POST['mailstream_address'] != "") { if (!local_user() || empty($post['mailstream-submit'])) {
DI::pConfig()->set(local_user(), 'mailstream', 'address', $_POST['mailstream_address']); return;
}
if ($post['mailstream_address'] != "") {
DI::pConfig()->set(local_user(), 'mailstream', 'address', $post['mailstream_address']);
} else { } else {
DI::pConfig()->delete(local_user(), 'mailstream', 'address'); DI::pConfig()->delete(local_user(), 'mailstream', 'address');
} }
if ($_POST['mailstream_nolikes']) { if ($post['mailstream_nolikes']) {
DI::pConfig()->set(local_user(), 'mailstream', 'nolikes', $_POST['mailstream_enabled']); DI::pConfig()->set(local_user(), 'mailstream', 'nolikes', $post['mailstream_enabled']);
} else { } else {
DI::pConfig()->delete(local_user(), 'mailstream', 'nolikes'); DI::pConfig()->delete(local_user(), 'mailstream', 'nolikes');
} }
if ($_POST['mailstream_enabled']) { if ($post['mailstream_enabled']) {
DI::pConfig()->set(local_user(), 'mailstream', 'enabled', $_POST['mailstream_enabled']); DI::pConfig()->set(local_user(), 'mailstream', 'enabled', $post['mailstream_enabled']);
} else { } else {
DI::pConfig()->delete(local_user(), 'mailstream', 'enabled'); DI::pConfig()->delete(local_user(), 'mailstream', 'enabled');
} }
if ($_POST['mailstream_attachimg']) { if ($post['mailstream_attachimg']) {
DI::pConfig()->set(local_user(), 'mailstream', 'attachimg', $_POST['mailstream_attachimg']); DI::pConfig()->set(local_user(), 'mailstream', 'attachimg', $post['mailstream_attachimg']);
} else { } else {
DI::pConfig()->delete(local_user(), 'mailstream', 'attachimg'); DI::pConfig()->delete(local_user(), 'mailstream', 'attachimg');
} }

View File

@ -9,5 +9,5 @@
{{include file="field_input.tpl" field=$address}} {{include file="field_input.tpl" field=$address}}
{{include file="field_checkbox.tpl" field=$nolikes}} {{include file="field_checkbox.tpl" field=$nolikes}}
{{include file="field_checkbox.tpl" field=$attachimg}} {{include file="field_checkbox.tpl" field=$attachimg}}
<input type="submit" value="{{$submit}}"> <input type="submit" name="mailstream-submit" value="{{$submit}}">
</div> </div>