Filter/Cleanup

* move shared criteria enums to parent
 * define shared regex patterns filter
 * set missing enum checks
 * fixed some filters
This commit is contained in:
Sarjuuk
2023-05-23 03:23:37 +02:00
parent fcf24b3a45
commit e9622e6991
21 changed files with 283 additions and 289 deletions

View File

@@ -897,16 +897,31 @@ trait sourceHelper
abstract class Filter
{
private static $wCards = ['*' => '%', '?' => '_'];
private static $wCards = ['*' => '%', '?' => '_'];
public $error = false; // erronous search fields
public $error = false; // erronous search fields
private $cndSet = [];
private $cndSet = [];
protected $parentCats = []; // used to validate ty-filter
protected $inputFields = []; // list of input fields defined per page
protected $fiData = ['c' => [], 'v' =>[]];
protected $formData = array( // data to fill form fields
/* genericFilter: [FILTER_TYPE, colOrFnName, param1, param2]
[FILTER_CR_BOOLEAN, <string:colName>, <bool:isString>, null]
[FILTER_CR_FLAG, <string:colName>, <int:testBit>, <bool:matchAny>] # default param2: matchExact
[FILTER_CR_NUMERIC, <string:colName>, <int:NUM_FLAGS>, <bool:addExtraCol>]
[FILTER_CR_STRING, <string:colName>, <int:STR_FLAGS>, null]
[FILTER_CR_ENUM, <string:colName>, <bool:useANY>, <bool:useNONE>]
[FILTER_CR_STAFFFLAG, <string:colName>, null, null]
[FILTER_CR_CALLBACK, <string:fnName>, <mixed:param1>, <mixed:param2>]
[FILTER_CR_NYI_PH, null, <int:returnVal>, param2] # mostly 1: to ignore this criterium; 0: to fail the whole query
*/
protected $genericFilter = [];
/*
fieldId => [checkType, checkValue[, fieldIsArray]]
*/
protected $inputFields = []; // list of input fields defined per page
protected $parentCats = []; // used to validate ty-filter
protected $fiData = ['c' => [], 'v' =>[]];
protected $formData = array( // data to fill form fields
'form' => [], // base form - unsanitized
'setCriteria' => [], // dynamic criteria list - index checked
'setWeights' => [], // dynamic weights list - index checked
@@ -914,6 +929,36 @@ abstract class Filter
'reputationCols' => [] // simlar and exclusive to extraCols - added as required
);
protected const PATTERN_NAME = '/[\p{C};%\\\\]/ui';
protected const PATTERN_CRV = '/[\p{C};:%\\\\]/ui';
protected const PATTERN_INT = '/\D/';
protected const ENUM_FACTION = array( 469, 1037, 1106, 529, 1012, 87, 21, 910, 609, 942, 909, 530, 69, 577, 930, 1068, 1104, 729, 369, 92,
54, 946, 67, 1052, 749, 47, 989, 1090, 1098, 978, 1011, 93, 1015, 1038, 76, 470, 349, 1031, 1077, 809,
911, 890, 970, 169, 730, 72, 70, 932, 1156, 933, 510, 1126, 1067, 1073, 509, 941, 1105, 990, 934, 935,
1094, 1119, 1124, 1064, 967, 1091, 59, 947, 81, 576, 922, 68, 1050, 1085, 889, 589, 270);
protected const ENUM_CURRENCY = array(32572, 32569, 29736, 44128, 20560, 20559, 29434, 37829, 23247, 44990, 24368, 52027, 52030, 43016, 41596, 34052, 45624, 49426, 40752, 47241,
40753, 29024, 24245, 26045, 26044, 38425, 29735, 24579, 24581, 32897, 22484, 52026, 52029, 4291, 28558, 43228, 34664, 47242, 52025, 52028,
37836, 20558, 34597, 43589);
protected const ENUM_EVENT = array( 372, 283, 285, 353, 420, 400, 284, 201, 374, 409, 141, 324, 321, 424, 423, 327, 341, 181, 404, 398,
301);
protected const ENUM_ZONE = array( 4494, 36, 2597, 3358, 45, 331, 3790, 4277, 16, 3524, 3, 3959, 719, 1584, 25, 1583, 2677, 3702, 3522, 4,
3525, 3537, 46, 1941, 2918, 3905, 4024, 2817, 4395, 4378, 148, 393, 1657, 41, 2257, 405, 2557, 65, 4196, 1,
14, 10, 15, 139, 12, 3430, 3820, 361, 357, 3433, 721, 394, 3923, 4416, 2917, 4272, 4820, 4264, 3483, 3562,
267, 495, 4742, 3606, 210, 4812, 1537, 4710, 4080, 3457, 38, 4131, 3836, 3792, 2100, 2717, 493, 215, 3518, 3698,
3456, 3523, 2367, 2159, 1637, 4813, 4298, 2437, 722, 491, 44, 3429, 3968, 796, 2057, 51, 3607, 3791, 3789, 209,
3520, 3703, 3711, 1377, 3487, 130, 3679, 406, 1519, 4384, 33, 2017, 1477, 4075, 8, 440, 141, 3428, 3519, 3848,
17, 2366, 3840, 3713, 3847, 3775, 4100, 1581, 3557, 3845, 4500, 4809, 47, 3849, 4265, 4493, 4228, 3698, 4406, 3714,
3717, 3715, 717, 67, 3716, 457, 4415, 400, 1638, 1216, 85, 4723, 4722, 1337, 4273, 490, 1497, 206, 1196, 4603,
718, 3277, 28, 40, 11, 4197, 618, 3521, 3805, 66, 1176, 1977);
protected const ENUM_HEROICDUNGEON = array( 4494, 3790, 4277, 4196, 4416, 4272, 4820, 4264, 3562, 4131, 3792, 2367, 4813, 3791, 3789, 3848, 2366, 3713, 3847, 4100,
4809, 3849, 4265, 4228, 3714, 3717, 3715, 3716, 4415, 4723, 206, 1196);
protected const ENUM_MULTIMODERAID = array( 4812, 3456, 2159, 4500, 4493, 4722, 4273, 4603, 4987);
protected const ENUM_HEROICRAID = array( 4987, 4812, 4722);
protected const ENUM_CLASSS = array( null, 1, 2, 3, 4, 5, 6, 7, 8, 9, null, 11, true, false);
protected const ENUM_RACE = array( null, 1, 2, 3, 4, 5, 6, 7, 8, null, 10, 11, true, false);
protected const ENUM_PROFESSION = array( null, 171, 164, 185, 333, 202, 129, 755, 165, 186, 197, true, false, 356, 182, 773);
// parse the provided request into a usable format
public function __construct($fromPOST = false, $opts = [])
{
@@ -1420,9 +1465,9 @@ abstract class Filter
return $this->modularizeString([$field], (string)$value, $strFlags & STR_MATCH_EXACT, $strFlags & STR_ALLOW_SHORT);
}
private function genericNumeric($field, &$value, $op, $castInt)
private function genericNumeric($field, &$value, $op, $typeCast)
{
if (!Util::checkNumeric($value, $castInt))
if (!Util::checkNumeric($value, $typeCast))
return null;
if ($this->int2Op($op))
@@ -1471,8 +1516,8 @@ abstract class Filter
case FILTER_CR_ENUM:
if (isset($this->enums[$cr[0]][$cr[1]]))
$result = $this->genericEnum($gen[1], $this->enums[$cr[0]][$cr[1]]);
else if (intval($cr[1]) != 0)
$result = $this->genericEnum($gen[1], intval($cr[1]));
else if (($gen[2] && $cr[1] == FILTER_ENUM_ANY) || ($gen[3] && $cr[1] == FILTER_ENUM_NONE))
$result = $this->genericEnum($gen[1], $cr[1]);
break;
case FILTER_CR_CALLBACK:
$result = $this->{$gen[1]}($cr, $gen[2], $gen[3]);