Language check moved to a separate function
This commit is contained in:
parent
ec7e295158
commit
fc600b2dbf
|
@ -135,22 +135,8 @@ class Relay
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$languages = [];
|
if (!self::isWantedLanguage($body)) {
|
||||||
foreach (Item::getLanguageArray($body, 10) as $language => $reliability) {
|
Logger::info('Unwanted or Undetected language found - rejected', ['network' => $network, 'url' => $url, 'causer' => $causer]);
|
||||||
if ($reliability > 0) {
|
|
||||||
$languages[] = $language;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger::debug('Got languages', ['languages' => $languages, 'body' => $body, 'causer' => $causer]);
|
|
||||||
|
|
||||||
if (!empty($languages)) {
|
|
||||||
if (in_array($languages[0], $config->get('system', 'relay_deny_languages'))) {
|
|
||||||
Logger::info('Unwanted language found - rejected', ['language' => $languages[0], 'network' => $network, 'url' => $url, 'causer' => $causer]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} elseif ($config->get('system', 'relay_deny_undetected_language')) {
|
|
||||||
Logger::info('Undetected language found - rejected', ['body' => $body, 'network' => $network, 'url' => $url, 'causer' => $causer]);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +149,36 @@ class Relay
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect the language of a post and decide if the post should be accepted
|
||||||
|
*
|
||||||
|
* @param string $body
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function isWantedLanguage(string $body)
|
||||||
|
{
|
||||||
|
$languages = [];
|
||||||
|
foreach (Item::getLanguageArray($body, 10) as $language => $reliability) {
|
||||||
|
if ($reliability > 0) {
|
||||||
|
$languages[] = $language;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::debug('Got languages', ['languages' => $languages, 'body' => $body]);
|
||||||
|
|
||||||
|
if (!empty($languages)) {
|
||||||
|
if (in_array($languages[0], DI::config()->get('system', 'relay_deny_languages'))) {
|
||||||
|
Logger::info('Unwanted language found', ['language' => $languages[0]]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} elseif (DI::config()->get('system', 'relay_deny_undetected_language')) {
|
||||||
|
Logger::info('Undetected language found', ['body' => $body]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update or insert a relay contact
|
* Update or insert a relay contact
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user