diff --git a/data/help.md b/data/help.md index d1ce5997..86469481 100644 --- a/data/help.md +++ b/data/help.md @@ -40,6 +40,10 @@ Command | Description [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]imgsize:huge[/search] | either dimension has at least 2001px | `img_size`, `imagesize`, `image_size` | +[search]imgsize:large[/search] | either dimension has at least 801px and at most 2000px | `img_size`, `imagesize`, `image_size` | +[search]imgsize:medium[/search] | either dimension has at least 301px and at most 800px | `img_size`, `imagesize`, `image_size` | +[search]imgsize:small[/search] | either dimension has at most 300px | `img_size`, `imagesize`, `image_size` | [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` | diff --git a/src/Models/SearchParsers/PostSearchParser.php b/src/Models/SearchParsers/PostSearchParser.php index 1f7efc74..866a5f62 100644 --- a/src/Models/SearchParsers/PostSearchParser.php +++ b/src/Models/SearchParsers/PostSearchParser.php @@ -174,6 +174,15 @@ class PostSearchParser extends AbstractSearchParser return Sql\Functors::equalsOrLesser('post.file_size', new Sql\Binding($fileSizeMax)); } + elseif (in_array($key, ['imagesize', 'imgsize', 'image_size', 'img_size'])) + { + list ($dimensionMin, $dimensionMax) = self::parseImageSize($value); + $select = 'MAX(post.image_width, post.image_height)'; + return Sql\Functors::conjunction() + ->add(Sql\Functors::equalsOrGreater(Sql\Statements::raw($select), $dimensionMin)) + ->add(Sql\Functors::equalsOrLesser(Sql\Statements::raw($select), $dimensionMax)); + } + elseif ($key == 'special') { $activeUser = Auth::getCurrentUser(); @@ -302,6 +311,30 @@ class PostSearchParser extends AbstractSearchParser return true; } + protected static function parseImageSize($value) + { + $sizes = + [ + 'huge' => 2001, + 'large' => 801, + 'medium' => 301, + 'small' => 1 + ]; + + $value = strtolower(trim($value)); + if (isset($sizes[$value])) + { + $dimensionMin = $sizes[$value]; + $keys = array_keys($sizes); + $i = array_search($value, $keys) - 1; + $dimensionMax = $i >= 0 ? $sizes[$keys[$i]] - 1 : PHP_INT_MAX; + } + else + throw new SimpleException('Invalid format exception'); + + return [$dimensionMin, $dimensionMax]; + } + protected static function parseDate($value) { $value = strtolower(trim($value));