diff --git a/README.md b/README.md index ad1e2c5..8cc35b4 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ # unmarkdorn -Library for escaping all markdown symbols +Library for normalizing Zanzara (Telegram API) objects ```php -// Library for escaping all markdown symbols -use function mirzaev\unmarkdown; +// Function for normalizing images +use function mirzaev\unzanzara\images; -var_dump(unmarkdown('*Hello!*')); // "\\*Hello\\!\\*" +var_dump(images($context->getMessage()?->getPhoto() ?? []); // [id => [[small], [medium], [big]]] ``` ## Installation ```bash -composer require mirzaev/unmarkdown +composer require mirzaev/unzanzara ``` diff --git a/composer.json b/composer.json index 9b27654..0fc7c8f 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { - "name": "mirzaev/unmarkdown", - "description": "Library for escaping all markdown symbols", - "homepage": "https://git.svoboda.works/mirzaev/unmarkdown", + "name": "mirzaev/unzanzara", + "description": "Library for normalizing Zanzara (Telegram API) objects ", + "homepage": "https://git.svoboda.works/mirzaev/unzanzara", "type": "library", - "keywords": ["markdown", "escaping"], + "keywords": ["zanzara", "telegram"], "readme": "README.md", "license": "WTFPL", "authors": [ @@ -15,12 +15,12 @@ } ], "support": { - "issues": "https://git.svoboda.works/mirzaev/unmarkdown/issues" + "issues": "https://git.svoboda.works/mirzaev/unzanzara/issues" }, "require": { - "php": "^8.4" + "php": "^8.5" }, "autoload": { - "files": ["mirzaev/unmarkdown/system/unmarkdown.php"] + "files": ["mirzaev/unzanzara/system/images.php"] } } diff --git a/mirzaev/unmarkdown/system/unmarkdown.php b/mirzaev/unmarkdown/system/unmarkdown.php deleted file mode 100644 index db409eb..0000000 --- a/mirzaev/unmarkdown/system/unmarkdown.php +++ /dev/null @@ -1,49 +0,0 @@ -', - '<', - '!', - '`', - '\\\\', - '|', - '+' - ], - $exceptions - ); - - // Initializing the registry of escaped characters - $to = []; - foreach ($from as $symbol) $to[] = "\\$symbol"; - - // Escaping the text and exit (success) - return str_replace($from, $to, $text); - } diff --git a/mirzaev/unzanzara/system/images.php b/mirzaev/unzanzara/system/images.php new file mode 100644 index 0000000..38eb3a2 --- /dev/null +++ b/mirzaev/unzanzara/system/images.php @@ -0,0 +1,71 @@ +getMessage()->getPhoto()` + * to + * [ + * [ + * 'identifier' => + * [ + * [small], + * [medium], + * [big] + * ... + * ] + * ] + * ... + *] + * + * @param array $images Images from `$context->getMessage()->getPhoto()` + * + * @return array Images grouped by identifier and size + * + * @package kodorvan\neurobot\models\functions\unzanzara + * + * @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License + * @author Arsen Mirzaev Tatyano-Muradovich + */ +function images(array $images): array +{ + // Declaring the array of converted images + $converted = []; + + foreach ($images as $image) { + // Iterating over images + + // Initializing the image in the array of converted images + $converted[$image->getFileId()] ??= []; + + // Initializing the image size in the array of converted images + $converted[$image->getFileId()][$image->getFileUniqueId()] = [ + 'width' => $image->getWith(), + 'height' => $image->getHeight(), + 'size' => $image->getFileSize() + ]; + } + + foreach ($images as &$image) { + // Iterating over images + + // Sorting image sized by width + $image = usort( + $image, + fn(array $a, array $b) => match (true) { + $a['width'] < $b['width'] => -1, + $a['width'] > $b['width'] => 1, + default => 0 + } + ); + } + + // Exit (success) + return $converted; +}