diff options
Diffstat (limited to 'src/codegen/emoticons.php')
| -rw-r--r-- | src/codegen/emoticons.php | 36 | 
1 files changed, 36 insertions, 0 deletions
diff --git a/src/codegen/emoticons.php b/src/codegen/emoticons.php new file mode 100644 index 0000000..51b9ed6 --- /dev/null +++ b/src/codegen/emoticons.php @@ -0,0 +1,36 @@ +<?php + +$em_dir = SRCDIR . "/static/emoticons"; +$emoticons = array_map( +    fn($i) => [ +        pathinfo($i, PATHINFO_FILENAME), +        getimagesize($em_dir . "/" . $i)["3"] +    ], +    array_values( +        array_filter( +            scandir($em_dir), +            fn($i) => +                $i[0] !== "." && +                is_file($em_dir . "/" . $i) && +                strtolower(pathinfo($i, PATHINFO_EXTENSION)) === "gif" +        ) +    ) +); + +usort($emoticons, fn($a, $b) => strlen($b[0]) <=> strlen($a[0])); + +$emoticons_alpha_lookup = []; +foreach ($emoticons as $i => $emoticon) { +    $emoticons_alpha_lookup []= [$i, $emoticon[0]]; +} +usort($emoticons_alpha_lookup, fn($a, $b) => $a[1] <=> $b[1]); +$emoticons_alpha_lookup = array_column($emoticons_alpha_lookup, 0); + +return [ +    "emoticons.js", +    "/* auto-generated at " . date("c") . " */\nvar EMOTICONS = " . +        json_encode([ +            $emoticons, +            $emoticons_alpha_lookup, +        ], JSON_PRETTY_PRINT) . ";\n", +];  |