mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-25 07:03:41 +00:00
Add minimum post body length setting to language filter
This commit is contained in:
parent
1f97b1f6c0
commit
ed1caffe04
2 changed files with 14 additions and 0 deletions
|
@ -36,6 +36,7 @@ function langfilter_addon_settings(&$a,&$s) {
|
||||||
$enable_checked = (intval(get_pconfig(local_user(),'langfilter','disable')) ? '' : ' checked="checked" ');
|
$enable_checked = (intval(get_pconfig(local_user(),'langfilter','disable')) ? '' : ' checked="checked" ');
|
||||||
$languages = get_pconfig(local_user(),'langfilter','languages');
|
$languages = get_pconfig(local_user(),'langfilter','languages');
|
||||||
$minconfidence = get_pconfig(local_user(),'langfilter','minconfidence')*100;
|
$minconfidence = get_pconfig(local_user(),'langfilter','minconfidence')*100;
|
||||||
|
$minlength = get_pconfig(local_user(),'langfilter','minlength');
|
||||||
if(! $languages)
|
if(! $languages)
|
||||||
$languages = 'en,de,fr,it,es';
|
$languages = 'en,de,fr,it,es';
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ function langfilter_addon_settings(&$a,&$s) {
|
||||||
'$enabled' => array('langfilter_enable', t('Use the language filter'), $enable_checked, ''),
|
'$enabled' => array('langfilter_enable', t('Use the language filter'), $enable_checked, ''),
|
||||||
'$languages' => array('langfilter_languages', t('I speak'), $languages, t('List of abbreviations (iso2 codes) for languages you speak, comma separated. For example "de,it".') ),
|
'$languages' => array('langfilter_languages', t('I speak'), $languages, t('List of abbreviations (iso2 codes) for languages you speak, comma separated. For example "de,it".') ),
|
||||||
'$minconfidence' => array('langfilter_minconfidence', t('Minimum confidence in language detection'), $minconfidence, t('Minimum confidence in language detection being correct, from 0 to 100. Posts will not be filtered when the confidence of language detection is below this percent value.') ),
|
'$minconfidence' => array('langfilter_minconfidence', t('Minimum confidence in language detection'), $minconfidence, t('Minimum confidence in language detection being correct, from 0 to 100. Posts will not be filtered when the confidence of language detection is below this percent value.') ),
|
||||||
|
'$minlength' => array('langfilter_minlength', t('Minimum length of message body'), $minlength, t('Minimum length of message body for language filter to be used. Posts shorter than this number of characters will not be filtered.') ),
|
||||||
'$submit' => t('Save Settings'),
|
'$submit' => t('Save Settings'),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -70,6 +72,12 @@ function langfilter_addon_settings_post(&$a,&$b) {
|
||||||
else if ( $minconfidence < 0 ) $minconfidence = 0;
|
else if ( $minconfidence < 0 ) $minconfidence = 0;
|
||||||
else if ( $minconfidence > 100 ) $minconfidence = 100;
|
else if ( $minconfidence > 100 ) $minconfidence = 100;
|
||||||
set_pconfig(local_user(),'langfilter','minconfidence', $minconfidence/100.0);
|
set_pconfig(local_user(),'langfilter','minconfidence', $minconfidence/100.0);
|
||||||
|
|
||||||
|
$minlength = 0+$_POST['langfilter_minlength'];
|
||||||
|
if ( ! $minlength ) $minlength = 32;
|
||||||
|
else if ( $minlength < 0 ) $minlength = 32;
|
||||||
|
set_pconfig(local_user(),'langfilter','minlength', $minlength);
|
||||||
|
|
||||||
info( t('Language Filter Settings saved.') . EOL);
|
info( t('Language Filter Settings saved.') . EOL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,6 +102,11 @@ function langfilter_prepare_body(&$a,&$b) {
|
||||||
# Don't filter if language filter is disabled
|
# Don't filter if language filter is disabled
|
||||||
if( get_pconfig($logged_user,'langfilter','disable') ) return;
|
if( get_pconfig($logged_user,'langfilter','disable') ) return;
|
||||||
|
|
||||||
|
# Don't filter if body lenght is below minimum
|
||||||
|
$minlen = get_pconfig(local_user(),'langfilter','minlength');
|
||||||
|
if ( ! $minlen ) $minlen = 32;
|
||||||
|
if ( strlen($b['item']['body']) < $minlen ) return;
|
||||||
|
|
||||||
$spoken_config = get_pconfig(local_user(),'langfilter','languages');
|
$spoken_config = get_pconfig(local_user(),'langfilter','languages');
|
||||||
$minconfidence = get_pconfig(local_user(),'langfilter','minconfidence');
|
$minconfidence = get_pconfig(local_user(),'langfilter','minconfidence');
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
{{include file="field_checkbox.tpl" field=$enabled}}
|
{{include file="field_checkbox.tpl" field=$enabled}}
|
||||||
{{include file="field_input.tpl" field=$languages}}
|
{{include file="field_input.tpl" field=$languages}}
|
||||||
{{include file="field_input.tpl" field=$minconfidence}}
|
{{include file="field_input.tpl" field=$minconfidence}}
|
||||||
|
{{include file="field_input.tpl" field=$minlength}}
|
||||||
</div>
|
</div>
|
||||||
<div class="settings-submit-wrapper" >
|
<div class="settings-submit-wrapper" >
|
||||||
<input type="submit" id="langfilter-settings-submit" name="langfilter-settings-submit" class="settings-submit" value="{{$submit}}" />
|
<input type="submit" id="langfilter-settings-submit" name="langfilter-settings-submit" class="settings-submit" value="{{$submit}}" />
|
||||||
|
|
Loading…
Reference in a new issue