]> git.mxchange.org Git - friendica-addons.git/commitdiff
Add minimum post body length setting to language filter
authorSandro Santilli <strk@kbt.io>
Sat, 1 Oct 2016 16:15:32 +0000 (18:15 +0200)
committerSandro Santilli <strk@kbt.io>
Sat, 1 Oct 2016 16:15:32 +0000 (18:15 +0200)
langfilter/langfilter.php
langfilter/templates/settings.tpl

index b29084c82d57b78944fd1704259c8492ecb1b337..d4fe942d0b23c1fe19b44461d9aaa5fe8cc3d052 100644 (file)
@@ -36,6 +36,7 @@ function langfilter_addon_settings(&$a,&$s) {
        $enable_checked = (intval(get_pconfig(local_user(),'langfilter','disable')) ? '' : ' checked="checked" ');
        $languages = get_pconfig(local_user(),'langfilter','languages');
        $minconfidence = get_pconfig(local_user(),'langfilter','minconfidence')*100;
+       $minlength = get_pconfig(local_user(),'langfilter','minlength');
        if(! $languages)
                $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, ''),
            '$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.') ),
+           '$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'),
        ));
 
@@ -70,6 +72,12 @@ function langfilter_addon_settings_post(&$a,&$b) {
                else if ( $minconfidence < 0 ) $minconfidence = 0;
                else if ( $minconfidence > 100 ) $minconfidence = 100;
                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);
        }
 }
@@ -94,6 +102,11 @@ function langfilter_prepare_body(&$a,&$b) {
     # Don't filter if language filter is disabled
     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');
     $minconfidence = get_pconfig(local_user(),'langfilter','minconfidence');
 
index 5d1fb25f409adf010d3dd4c96c61906c35cc0582..8e62ef49ec3251bd221aa9fac1d6979f22b4af7f 100644 (file)
@@ -11,6 +11,7 @@
                {{include file="field_checkbox.tpl" field=$enabled}}
                {{include file="field_input.tpl" field=$languages}}
                {{include file="field_input.tpl" field=$minconfidence}}
+               {{include file="field_input.tpl" field=$minlength}}
        </div>
        <div class="settings-submit-wrapper" >
                <input type="submit" id="langfilter-settings-submit" name="langfilter-settings-submit" class="settings-submit" value="{{$submit}}" />