MDNodaHelpers/src/NodaBlacklistedTerms.php

162 lines
4.1 KiB
PHP

<?PHP
/**
* Contains a class of blacklists for unwanted terms.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Contains lists of disallowed terms by language.
*/
final class NodaBlacklistedTerms {
/**
* A blacklist of disallowed tags. All entries are listed in full lowercase.
*/
public const TAG_BLACKLIST = [
'de' => [
'andere',
'anderes',
'sonst',
'sonst.',
'sonstige',
'sonstiges',
'versch.',
'verschiedenes',
'unbekannt',
'weitere',
'weiteres',
'objekt',
'objekte',
'noch nicht bestimmte objekte',
'ding',
'dinge',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'nichtmünzliches',
'unbestimmt',
'-',
'?',
],
'en' => [
'other',
'others',
'unknown',
'various',
'-',
'?',
],
'hu' => [
'ism.',
'ismeretlen',
'-',
'?',
],
];
/**
* Checks if an tag name is blacklisted.
*
* @param string $lang Input language.
* @param string $name Input name to check.
*
* @return boolean
*/
public static function tagIsInBlacklist(string $lang, string $name):bool {
$toCheck = \strtolower($name);
if (!isset(self::TAG_BLACKLIST[$lang])) {
return false;
}
if (\in_array($toCheck, self::TAG_BLACKLIST[$lang], true)) {
return true;
}
return false;
}
/**
* Checks if a place name is blacklisted in the DB.
*
* @param MDMysqli $mysqli DB connection.
* @param string $lang The user's currently used language.
* @param string $name The name entered by the user.
*
* @return boolean
*/
public static function checkPlaceBlacklistedInDb(MDMysqli $mysqli, string $lang, string $name):bool {
$result = $mysqli->query_by_stmt("SELECT 1
FROM `" . DATABASENAME_NODA . "`.`orte_blacklist`
WHERE `language` = ?
AND `ort_name` = ?
LIMIT 1", "ss", $lang, $name);
if ($result->num_rows === 0) {
$result->close();
return false;
}
$result->close();
return true;
}
/**
* Checks if an actor name is blacklisted in the DB.
*
* @param MDMysqli $mysqli DB connection.
* @param string $lang The user's currently used language.
* @param string $name The name entered by the user.
*
* @return boolean
*/
public static function checkPersinstBlacklistedInDb(MDMysqli $mysqli, string $lang, string $name):bool {
$result = $mysqli->query_by_stmt("SELECT 1
FROM `" . DATABASENAME_NODA . "`.`persinst_blacklist`
WHERE `language` = ?
AND `persinst_name` = ?
LIMIT 1", "ss", $lang, $name);
if ($result->num_rows === 0) {
$result->close();
return false;
}
$result->close();
return true;
}
/**
* Checks if a time name is blacklisted in the DB.
*
* @param MDMysqli $mysqli DB connection.
* @param string $lang The user's currently used language.
* @param string $name The name entered by the user.
*
* @return boolean
*/
public static function checkTimeBlacklistedInDb(MDMysqli $mysqli, string $lang, string $name):bool {
$result = $mysqli->query_by_stmt("SELECT 1
FROM `" . DATABASENAME_NODA . "`.`zeiten_blacklist`
WHERE `language` = ?
AND `zeit_name` = ?
LIMIT 1", "ss", $lang, $name);
if ($result->num_rows === 0) {
$result->close();
return false;
}
$result->close();
return true;
}
}