forked from friendica/friendica-addons
Merge pull request #954 from MrPetovan/bug/langfilter-default-form-values
[langfilter] Add default values to form parameters
This commit is contained in:
commit
49f0b0909e
|
@ -45,10 +45,13 @@ function langfilter_addon_settings(App $a, &$s)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$enable_checked = (intval(DI::pConfig()->get(local_user(), 'langfilter', 'disable')) ? '' : ' checked="checked" ');
|
$enabled = DI::pConfig()->get(local_user(), 'langfilter', 'enable',
|
||||||
|
!DI::pConfig()->get(local_user(), 'langfilter', 'disable'));
|
||||||
|
|
||||||
|
$enable_checked = $enabled ? ' checked="checked"' : '';
|
||||||
$languages = DI::pConfig()->get(local_user(), 'langfilter', 'languages');
|
$languages = DI::pConfig()->get(local_user(), 'langfilter', 'languages');
|
||||||
$minconfidence = DI::pConfig()->get(local_user(), 'langfilter', 'minconfidence') * 100;
|
$minconfidence = DI::pConfig()->get(local_user(), 'langfilter', 'minconfidence', 0) * 100;
|
||||||
$minlength = DI::pConfig()->get(local_user(), 'langfilter', 'minlength');
|
$minlength = DI::pConfig()->get(local_user(), 'langfilter', 'minlength' , 32);
|
||||||
|
|
||||||
$t = Renderer::getMarkupTemplate("settings.tpl", "addon/langfilter/");
|
$t = Renderer::getMarkupTemplate("settings.tpl", "addon/langfilter/");
|
||||||
$s .= Renderer::replaceMacros($t, [
|
$s .= Renderer::replaceMacros($t, [
|
||||||
|
@ -77,29 +80,20 @@ function langfilter_addon_settings_post(App $a, &$b)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($_POST['langfilter-settings-submit'])) {
|
if (!empty($_POST['langfilter-settings-submit'])) {
|
||||||
DI::pConfig()->set(local_user(), 'langfilter', 'languages', trim($_POST['langfilter_languages']));
|
$enable = intval($_POST['langfilter_enable'] ?? 0);
|
||||||
$enable = (!empty($_POST['langfilter_enable']) ? intval($_POST['langfilter_enable']) : 0);
|
$languages = trim($_POST['langfilter_languages'] ?? '');
|
||||||
$disable = 1 - $enable;
|
$minconfidence = max(0, min(100, intval($_POST['langfilter_minconfidence'] ?? 0))) / 100;
|
||||||
DI::pConfig()->set(local_user(), 'langfilter', 'disable', $disable);
|
$minlength = intval($_POST['langfilter_minlength'] ?? 32);
|
||||||
$minconfidence = 0 + $_POST['langfilter_minconfidence'];
|
if ($minlength <= 0) {
|
||||||
if (!$minconfidence) {
|
$minlength = 32;
|
||||||
$minconfidence = 0;
|
|
||||||
} elseif ($minconfidence < 0) {
|
|
||||||
$minconfidence = 0;
|
|
||||||
} elseif ($minconfidence > 100) {
|
|
||||||
$minconfidence = 100;
|
|
||||||
}
|
}
|
||||||
DI::pConfig()->set(local_user(), 'langfilter', 'minconfidence', $minconfidence / 100.0);
|
|
||||||
|
|
||||||
$minlength = 0 + $_POST['langfilter_minlength'];
|
DI::pConfig()->set(local_user(), 'langfilter', 'enable' , $enable);
|
||||||
if (!$minlength) {
|
DI::pConfig()->set(local_user(), 'langfilter', 'languages' , $languages);
|
||||||
$minlength = 32;
|
DI::pConfig()->set(local_user(), 'langfilter', 'minconfidence', $minconfidence);
|
||||||
} elseif ($minlength < 0) {
|
|
||||||
$minlength = 32;
|
|
||||||
}
|
|
||||||
DI::pConfig()->set(local_user(), 'langfilter', 'minlength' , $minlength);
|
DI::pConfig()->set(local_user(), 'langfilter', 'minlength' , $minlength);
|
||||||
|
|
||||||
info(DI::l10n()->t('Language Filter Settings saved.') . EOL);
|
info(DI::l10n()->t('Language Filter Settings saved.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +121,9 @@ function langfilter_prepare_body_content_filter(App $a, &$hook_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't filter if language filter is disabled
|
// Don't filter if language filter is disabled
|
||||||
if (DI::pConfig()->get($logged_user, 'langfilter', 'disable')) {
|
if (!DI::pConfig()->get($logged_user, 'langfilter', 'enable',
|
||||||
|
!DI::pConfig()->get($logged_user, 'langfilter', 'disable'))
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue