Added support for filesizemin:X and filesizemax:X
This commit is contained in:
parent
b1ba30adcb
commit
6014609a78
3 changed files with 22 additions and 2 deletions
|
@ -38,6 +38,8 @@ Command | Description
|
|||
[search]date:2000-01-01[/search] | posted on January 1st, 2000 | - |
|
||||
[search]datemin:...[/search] | posted on `...` or later (format like in `date:`) | `date_min` |
|
||||
[search]datemax:...[/search] | posted on `...` or earlier (format like in `date:`) | `date_max` |
|
||||
[search]filesizemin:7M[/search] | has size of at least 7 megabytes | `filesize_min` |
|
||||
[search]filesizemax:30K[/search] | has size of at most 30 kilobytes | `filesize_max` |
|
||||
[search]id:1,2,3[/search] | having specific post ID | `ids` |
|
||||
[search]name:...[/search] | having specific post name (hash in full URLs) | `names`, `hash`, `hashes` |
|
||||
[search]idmin:5[/search] | posts with ID greater than or equal to @5 | `id_min` |
|
||||
|
|
|
@ -154,12 +154,18 @@ class TextHelper
|
|||
|
||||
public static function stripBytesUnits($string)
|
||||
{
|
||||
return self::stripUnits($string, 1024, ['B', 'K', 'M', 'G']);
|
||||
$string = strtoupper($string);
|
||||
if (!preg_match('/^\d+[KMG]?B?$/', $string))
|
||||
throw new SimpleException('Invalid format: ' . $string);
|
||||
return self::stripUnits(strtoupper($string), 1024, ['B', 'K', 'M', 'G']);
|
||||
}
|
||||
|
||||
public static function stripDecimalUnits($string)
|
||||
{
|
||||
return self::stripUnits($string, 1000, ['', 'K', 'M']);
|
||||
$string = strtoupper($string);
|
||||
if (!preg_match('/^\d+[KM]?$/', $string))
|
||||
throw new SimpleException('Invalid format: ' . $string);
|
||||
return self::stripUnits(strtoupper($string), 1000, ['', 'K', 'M']);
|
||||
}
|
||||
|
||||
public static function parseMarkdown($text, $simple = false)
|
||||
|
|
|
@ -162,6 +162,18 @@ class PostSearchParser extends AbstractSearchParser
|
|||
return Sql\Functors::equalsOrLesser('post.upload_date', new Sql\Binding($dateMax));
|
||||
}
|
||||
|
||||
elseif (in_array($key, ['filesizemin', 'filesize_min']))
|
||||
{
|
||||
$fileSizeMin = TextHelper::stripBytesUnits($value);
|
||||
return Sql\Functors::equalsOrGreater('post.file_size', new Sql\Binding($fileSizeMin));
|
||||
}
|
||||
|
||||
elseif (in_array($key, ['filesizemax', 'filesize_max']))
|
||||
{
|
||||
$fileSizeMax = TextHelper::stripBytesUnits($value);
|
||||
return Sql\Functors::equalsOrLesser('post.file_size', new Sql\Binding($fileSizeMax));
|
||||
}
|
||||
|
||||
elseif ($key == 'special')
|
||||
{
|
||||
$activeUser = Auth::getCurrentUser();
|
||||
|
|
Loading…
Reference in a new issue