Profiler/Filter

* implemented flag options when searching for strings
This commit is contained in:
Sarjuuk
2018-03-22 14:36:09 +01:00
parent 3303722bc7
commit fbcf00e0fc
6 changed files with 37 additions and 20 deletions

View File

@@ -76,6 +76,8 @@ class AjaxFilter extends AjaxHandler
{
$url = '?'.$this->page;
$this->filter->mergeCat($this->cat);
if ($this->cat)
$url .= '='.implode('.', $this->cat);

View File

@@ -96,7 +96,7 @@ abstract class BaseType
if ($x = $resolveCondition($foo, $supLink))
$sql[] = $x;
return '('.implode($subLink, $sql).')';
return $sql ? '('.implode($subLink, $sql).')' : null;
}
else
{
@@ -798,6 +798,12 @@ abstract class Filter
return ['formData'];
}
public function mergeCat(&$cats)
{
foreach ($this->parentCats as $idx => $cat)
$cats[$idx] = $cat;
}
private function &criteriaIterator()
{
if (!$this->fiData['c'])
@@ -908,13 +914,13 @@ abstract class Filter
{
$buff = [];
foreach ((array)$val as $v)
if ($v !== '' && $this->checkInput($type, $valid, $v))
if ($v !== '' && $this->checkInput($type, $valid, $v) && $v !== '')
$buff[] = $v;
if ($buff)
$this->fiData[$k][$inp] = $buff;
}
else if ($this->checkInput($type, $valid, $val))
else if ($val !== '' && $this->checkInput($type, $valid, $val) && $val !== '')
$this->fiData[$k][$inp] = $val;
}
@@ -954,7 +960,7 @@ abstract class Filter
{
$buff = [];
foreach (explode(':', $val) as $v)
if ($v !== '' && $this->checkInput($type, $valid, $v))
if ($v !== '' && $this->checkInput($type, $valid, $v) && $v !== '')
$buff[] = $v;
if ($buff)
@@ -965,7 +971,7 @@ abstract class Filter
$this->fiData[$k][$inp] = array_map(function ($x) { return strtr($x, Filter::$wCards); }, $buff);
}
}
else if ($this->checkInput($type, $valid, $val))
else if ($val !== '' && $this->checkInput($type, $valid, $val) && $val !== '')
{
if ($k == 'v')
$this->formData['form'][$inp] = $val;
@@ -997,10 +1003,10 @@ abstract class Filter
$_crs = &$this->fiData['c']['crs'];
$_crv = &$this->fiData['c']['crv'];
if (count($_cr) != count($_crv) || count($_cr) != count($_crs))
if (count($_cr) != count($_crv) || count($_cr) != count($_crs) || count($_cr) > 5 || count($_crs) > 5 /*|| count($_crv) > 5*/)
{
// use min provided criterion as basis
$min = min(count($_cr), count($_crv), count($_crs));
// use min provided criterion as basis; 5 criteria at most
$min = max(5, min(count($_cr), count($_crv), count($_crs)));
if (count($_cr) > $min)
array_splice($_cr, $min);
@@ -1155,7 +1161,7 @@ abstract class Filter
return false;
}
protected function modularizeString(array $fields, $string = '', $exact = false)
protected function modularizeString(array $fields, $string = '', $exact = false, $shortStr = false)
{
if (!$string && !empty($this->fiData['v']['na']))
$string = $this->fiData['v']['na'];
@@ -1168,9 +1174,9 @@ abstract class Filter
$parts = array_filter(explode(' ', $string));
foreach ($parts as $p)
{
if ($p[0] == '-' && mb_strlen($p) > 3)
if ($p[0] == '-' && (mb_strlen($p) > 3 || $shortStr))
$sub[] = [$f, sprintf($exPH, mb_substr($p, 1)), '!'];
else if ($p[0] != '-' && mb_strlen($p) > 2)
else if ($p[0] != '-' && (mb_strlen($p) > 2 || $shortStr))
$sub[] = [$f, sprintf($exPH, $p)];
}
@@ -1258,12 +1264,12 @@ abstract class Filter
return null;
}
private function genericString($field, $value, $localized)
private function genericString($field, $value, $strFlags)
{
if ($localized)
if ($strFlags & STR_LOCALIZED)
$field .= '_loc'.User::$localeId;
return $this->modularizeString([$field], (string)$value);
return $this->modularizeString([$field], (string)$value, $strFlags & STR_MATCH_EXACT, $strFlags & STR_ALLOW_SHORT);
}
private function genericNumeric($field, &$value, $op, $castInt)
@@ -1296,6 +1302,9 @@ abstract class Filter
$gen = $this->genericFilter[$cr[0]];
$result = null;
if(!isset($gen[2]))
$gen[2] = 0;
switch ($gen[0])
{
case FILTER_CR_NUMERIC:
@@ -1312,7 +1321,7 @@ abstract class Filter
$result = $this->genericBoolean($gen[1], $cr[1], !empty($gen[2]));
break;
case FILTER_CR_STRING:
$result = $this->genericString($gen[1], $cr[2], !empty($gen[2]));
$result = $this->genericString($gen[1], $cr[2], $gen[2]);
break;
case FILTER_CR_ENUM:
if (isset($this->enums[$cr[0]][$cr[1]]))

View File

@@ -218,6 +218,7 @@ define('CC_FLAG_APPROVED', 0x8);
define('SOUND_TYPE_OGG', 1);
define('SOUND_TYPE_MP3', 2);
define('CONTRIBUTE_NONE', 0x0);
define('CONTRIBUTE_CO', 0x1);
define('CONTRIBUTE_SS', 0x2);
define('CONTRIBUTE_VI', 0x4);
@@ -229,6 +230,10 @@ define('NUM_CAST_FLOAT', 2);
define('NUM_REQ_INT', 3);
define('NUM_REQ_FLOAT', 4);
define('STR_LOCALIZED', 0x1);
define('STR_MATCH_EXACT', 0x2);
define('STR_ALLOW_SHORT', 0x4);
/*
* Game
*/
@@ -389,6 +394,7 @@ define('SPELL_SCHOOL_NATURE', 3);
define('SPELL_SCHOOL_FROST', 4);
define('SPELL_SCHOOL_SHADOW', 5);
define('SPELL_SCHOOL_ARCANE', 6);
define('SPELL_MAGIC_SCHOOLS', 0x7E);
define('SPELL_ALL_SCHOOLS', 0x7F);
// CharacterSlot

View File

@@ -299,7 +299,7 @@ class AchievementListFilter extends Filter
protected $genericFilter = array( // misc (bool): _NUMERIC => useFloat; _STRING => localized; _FLAG => match Value; _BOOLEAN => stringSet
2 => [FILTER_CR_BOOLEAN, 'reward_loc0', true ], // givesreward
3 => [FILTER_CR_STRING, 'reward', true ], // rewardtext
3 => [FILTER_CR_STRING, 'reward', STR_LOCALIZED ], // rewardtext
4 => [FILTER_CR_NYI_PH, null, 1, ], // location [enum]
5 => [FILTER_CR_CALLBACK, 'cbSeries', ACHIEVEMENT_CU_FIRST_SERIES, null], // first in series [yn]
6 => [FILTER_CR_CALLBACK, 'cbSeries', ACHIEVEMENT_CU_LAST_SERIES, null], // last in series [yn]

View File

@@ -1811,7 +1811,7 @@ class ItemListFilter extends Filter
101 => [FILTER_CR_NUMERIC, 'is.rgdhastertng', NUM_CAST_INT, true ], // rgdhastertng
102 => [FILTER_CR_NUMERIC, 'is.splhastertng', NUM_CAST_INT, true ], // splhastertng
103 => [FILTER_CR_NUMERIC, 'is.hastertng', NUM_CAST_INT, true ], // hastertng
104 => [FILTER_CR_STRING, 'description', true ], // flavortext
104 => [FILTER_CR_STRING, 'description', STR_LOCALIZED ], // flavortext
105 => [FILTER_CR_NYI_PH, null, 1, ], // dropsinnormal [heroicdungeon-any]
106 => [FILTER_CR_NYI_PH, null, 1, ], // dropsinheroic [heroicdungeon-any]
107 => [FILTER_CR_NYI_PH, null, 1, ], // effecttext [str] not yet parsed ['effectsParsed_loc'.User::$localeId, $cr[2]]
@@ -2215,7 +2215,7 @@ class ItemListFilter extends Filter
protected function cbArmorBonus($cr)
{
if (!Util::checkNumeric($cr[2], NUM_CAST_FLOAT) || !$this->int2Op($cr[1]))
return false;
return false;
$this->formData['extraCols'][] = $cr[0];
return ['AND', ['armordamagemodifier', $cr[2], $cr[1]], ['class', ITEM_CLASS_ARMOR]];
@@ -2529,7 +2529,7 @@ class ItemListFilter extends Filter
return in_array($v, $sl);
// consumables - any; perm / temp item enhancements
else if ($c[0] == 0 && (!isset($c[1]) || in_array($c[1], [3, -6])))
else if ($c[0] == 0 && (!isset($c[1]) || in_array($c[1], [-3, 6])))
return in_array($v, $sl);
// weapons - always

View File

@@ -173,7 +173,7 @@ class ItemsetListFilter extends Filter
protected $genericFilter = array( // misc (bool): _NUMERIC => useFloat; _STRING => localized; _FLAG => match Value; _BOOLEAN => stringSet
2 => [FILTER_CR_NUMERIC, 'id', NUM_CAST_INT, true], // id
3 => [FILTER_CR_NUMERIC, 'npieces', NUM_CAST_INT ], // pieces
4 => [FILTER_CR_STRING, 'bonusText', true ], // bonustext
4 => [FILTER_CR_STRING, 'bonusText', STR_LOCALIZED ], // bonustext
5 => [FILTER_CR_BOOLEAN, 'heroic', ], // heroic
6 => [FILTER_CR_ENUM, 'e.holidayId', ], // relatedevent
8 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_COMMENT ], // hascomments